matchmaking-system
Covers skill-based matchmaking for multiplayer games: picking a rating system (Elo, Glicko-2 or TrueSkill), skill brackets that widen with wait time, claiming…
от fcsouza★ 29 звёзд на GitHub
Установить matchmaking-system в Claude Code и Claude Desktop
Зарегайся, чтобы установить скилл
Создай бесплатный аккаунт, чтобы открыть команду установки и сохранить скилл в библиотеку.
- Открой команду установки в одну строку
- Сохраняй скиллы в синхронизируемую библиотеку
- Уведомления, когда скиллы обновляются
Об этом скилле
Matchmaking System
Pairs players by skill from a Redis sorted set, widens the skill bracket as they wait, claims each pair atomically, and runs the lobby until the match ends.
Choose the rating system
| System | Pick it when | What it tracks |
|---|---|---|
| Elo | Matches are plentiful and you can keep matchmaking tight | One number. Menke: needs more matches to converge than Glicko or TrueSkill. |
| Glicko-2 | Players compete alone and you want an uncertainty that grows while a player is away (RD rises in a rating period with no games) | Rating, rating deviation (RD), volatility; a draw scores 0.5. Menke, on Glicko: converges faster than Elo, not naturally adapted to teams. |
| TrueSkill | Team modes, more than two teams, or draws | Mean mu and uncertainty sigma per player; team skill is the sum of its players. Menke: designed for teams and draws, converges in the fewest matches of the three. |
Starting values with a source:
- Glicko-2: unrated players start at rating 1500, RD 350, volatility 0.06. Set the system constant tau between 0.3 and 1.2 and test which predicts best. Rating periods work best with 10-15 games per player.
- TrueSkill: new players start at mu 25, sigma 8.333. Rank on the conservative estimate mu - 3 sigma, not on mu.
- A Glicko-2 player's strength sits in rating plus or minus 2 RD with 95% confidence.
No Elo K-factor is given here because no source was checked. Pick one and tune it against your own win-prediction data.
Persist ratings in Postgres after each match (postgres-game-schema) and cache them in Redis for the queue.
Procedure
- Split pools by game mode and region. One sorted set per pool, score = rating. A player only searches their own pool unless they opt in to cross-region.
- Enqueue: write the sorted-set member and a hash with rating, deviation, games played and
queuedAt, with a TTL so a crashed client does not stay queued forever. - Add one BullMQ search job per player. The job calls
findMatch; if nothing fits, it adds a delayed copy of itself, so the search runs again with a wider bracket. - Bracket width comes from wait time:
initial + floor(wait / interval) * step, capped at a maximum. Derive it fromqueuedAton every search; do not store it, so it cannot go stale and needs no separate "widen" job. - A pair fits when the rating gap is inside the wider of the two players' brackets, so the player who waited longer decides.
- Claim the pair in one Lua script: if both members are still in the sorted set, remove both and delete both hashes; otherwise remove nothing and try the next candidate. See "Atomic dequeue" below.
- Create the lobby. Players ready up; the last ready-up moves the lobby to COUNTDOWN.
- When the countdown ends, check every player's presence (WebSocket heartbeat). If all are there, the lobby goes IN_PROGRESS. If anyone dropped, the lobby is short of its match size, so it dissolves:
startMatchdeletes it, unmaps every player and returns the connected ones inrequeue. Requeue them with their originalqueuedAtso their bracket stays wide. A leave before IN_PROGRESS dissolves the lobby the same way;leaveLobbyreturns the ids to requeue. - On match end, mark the lobby COMPLETE, update ratings, and let the lobby expire after the results screen.
Build the queue from boilerplate/matchmaker.ts.
Build the lobby from boilerplate/lobby-manager.ts.
import { Redis } from 'ioredis';
import { MatchmakingEngine, startMatchmaking } from './matchmaker';
import { LobbyManager } from './lobby-manager';
const url = process.env.REDIS_URL ?? 'redis://localhost:6379';
// Request path: by default ioredis holds a command through 20 reconnect
// attempts (maxRetriesPerRequest: 20); 1 fails the request fast when Redis is
// down, as `bullmq-game-queues` does for producers.
const redis = new Redis(url, { maxRetriesPerRequest: 1 });
// Worker connection: BullMQ requires maxRetriesPerRequest: null here.
const workerRedis = new Redis(url, { maxRetriesPerRequest: null });
const engine = new MatchmakingEngine(redis);
const lobbies = new LobbyManager(redis);
const { queue } = startMatchmaking(workerRedis, engine, async (match) => {
await lobbies.createLobby(match);
});
await engine.enqueue({
playerId: 'player_123',
rating: 1500,
deviation: 350,
gamesPlayed: 0,
gameMode: 'ranked-1v1',
region: 'eu-west',
queuedAt: Date.now(),
});
await queue.add(
'search',
{ gameMode: 'ranked-1v1', region: 'eu-west', playerId: 'player_123' },
{ removeOnComplete: true },
);
Atomic dequeue
Reading candidates and then removing them in separate calls lets two workers pick the same opponent, and both matches go ahead. A MULTI/EXEC of two ZREMs does not fix this: if one member is already gone, the other is still removed, and Redis transactions have no rollback.
The boilerplate's claim script checks both members with ZSCORE, then ZREMs both and DELs both hashes, all inside one script. Redis runs a script atomically, s
Разрешённые инструменты
Инструменты, которые скиллу разрешено вызывать.
Без ограничений — скилл может использовать любой инструмент.
Вложенные файлы
- boilerplate/lobby-manager.ts
- boilerplate/matchmaker.ts
- references/sources.md
FAQ
Что делает скилл matchmaking-system?
Covers skill-based matchmaking for multiplayer games: picking a rating system (Elo, Glicko-2 or TrueSkill), skill brackets that widen with wait time, claiming a matched pair from the queue without double-booking a player, and the lobby lifecycle from ready-up to match end. Use when players need to be paired or grouped by skill, a queue matches the same player twice or leaves players waiting too long, new players keep losing to veterans, or a lobby breaks when someone leaves during the countdown. Redis and BullMQ are the reference implementation.
Как установить скилл matchmaking-system?
Скопируй папку скилла в ~/.claude/skills (вкладка Claude Code выше делает это одной командой), либо поставь как плагин.
Скилл matchmaking-system запускает скрипты?
Да, скилл несёт исполняемые скрипты. Проверь исходник перед установкой.
Похожие скиллы
theme-factory
AnthropicToolkit for styling artifacts with a theme. These artifacts can be slides, docs, reportings, HTML landing pages, etc. There are 10 pre-set themes with…
access
AnthropicManage Discord channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…
configure
AnthropicSet up the Discord channel — save the bot token and review access policy. Use when the user pastes a Discord bot token, asks to configure Discord, asks "how…
access
AnthropicManage iMessage channel access — approve pairings, edit allowlists, set DM/group policy. Use when the user asks to pair, approve someone, check who's allowed…