Bash.tv → GitHub → itch.io

Match players into fair games and manage sessions. A tested queue with a skill window that widens the longer players wait, parties kept together, team balancing, optional regions, backfill for matches that lost players, queue position, and Elo and team Elo rating updates; plus when matchmaking is worth it (player counts), bots for empty queues, showing wait times, and match lifecycle from queue...

Download skill (.zip) Files on GitHub

Matchmaking system

Do you need it? Matchmaking needs players waiting at the same time. A small browser game rarely has that: with fewer than about 50 people online at once, use quick join (multiplayer-lobbies, fills the fullest open room) plus invite codes, and fill empty seats with bots. Add rating-based matchmaking when queues are busy.

assets/matchmaker.js

import { createMatchmaker, elo, teamElo } from "./matchmaker.js";
const mm = createMatchmaker({ size: 4, teams: 2, window: 100, widenPerSec: 25, maxWindow: 600, regionStrict: true, maxWaitSec: 45 });
mm.enqueue({ id: "p1", rating: 1200, region: "eu" });
mm.enqueue({ id: "party9", members: ["p2", "p3"], rating: 1350 });   // parties stay together
setInterval(() => { for (const m of mm.tick()) createMatch(m); }, 1000);   // m = { players, teams: [[..],[..]], rating, waited }
mm.cancel("p1"); mm.position("p1"); mm.backfill(1, matchRating, { region });
const [a2, b2] = elo(a, b, 1);    // 1 = a won, 0.5 draw, 0 = a lost

Session lifecycle

queued → found (show "Match found!") → room created (lobbies.create + join for each) → playing → results → ratings updated → back to menu or requeue

Ratings

Tested

Node tests: closest rating paired first, no match outside the window, the window widening over time, parties kept on one team, party too big refused, team balancing, Elo and team Elo values, backfill picking the closest player.

Pitfalls

Matchmaking for a game with 5 players online (use quick join), ratings computed in the browser, long waits with no feedback, and parties split across teams.