@echecs/tournament - v2.1.1
    Preparing search index...

    Class Tournament

    Stateful chess tournament orchestrator. Drives any pairing system through a common lifecycle: create, pair, record results, standings, repeat.

    The pairing system is injected as a function parameter — the consumer provides it from @echecs/swiss, @echecs/round-robin, or a custom implementation.

    import { Tournament } from '@echecs/tournament';
    import { dutch } from '@echecs/swiss';

    const t = new Tournament({
    pairingSystem: dutch,
    players: [{ id: 'alice' }, { id: 'bob' }, { id: 'carol' }, { id: 'dave' }],
    rounds: 3,
    });

    const r1 = t.pairRound();
    for (const p of r1.pairings) {
    t.recordResult({ black: p.black, result: 1, white: p.white });
    }
    const standings = t.standings();
    Index

    Constructors

    Accessors

    • get currentRound(): number

      The current round number (1-based), or 0 if no round has been paired yet.

      Returns number

    • get games(): readonly (readonly Game[])[]

      All recorded games, grouped by round. Returns a defensive copy.

      Returns readonly (readonly Game[])[]

    • get isComplete(): boolean

      Whether all rounds have been paired and all results recorded.

      Returns boolean

    • get rounds(): number

      Total number of rounds in the tournament.

      Returns number

    • get tiebreaks(): readonly string[]

      Ordered list of tiebreak identifiers. Returns a defensive copy.

      Returns readonly string[]

    Methods

    • Removes a previously recorded result from the specified round. The game is identified by the player pair (checked in both color orderings).

      After clearing, the round becomes incomplete and the pairing can be re-recorded via recordResult.

      Parameters

      • round: number

        The 1-based round number.

      • white: string

        One of the two player identifiers.

      • black: string

        The other player identifier.

      Returns void

      If the round is invalid or no matching result exists.

    • Generates pairings for the next round using the injected pairing system.

      Returns PairingResult

      The pairings and byes for the new round.

      If the tournament is complete or the current round has unrecorded results.

    • Records a game result for the current round.

      When kind is provided, the result must be consistent with it (e.g. forfeit-win requires result: 1).

      Parameters

      • game: { black: string; kind?: GameKind; result: Result; white: string }

        The game result to record.

      Returns void

      If no round has been paired, the players don't match any pairing, or kind and result are inconsistent.

    • Returns players ranked by score descending, with optional tiebreaks applied in order. Tied players (same score and all tiebreak values) share the same rank.

      Parameters

      • tiebreaks: Tiebreak[] = []

        Ordered array of tiebreak functions. Each receives (playerId, games, players) and returns a number. Higher values rank higher.

      Returns Standing[]

      Sorted standings array.

    • Replaces an existing result in any round. The game is identified by the white/black player pair (checked in both orderings). The stored game retains its original color assignment.

      Parameters

      • round: number

        The 1-based round number.

      • game: { black: string; kind?: GameKind; result: Result; white: string }

        The updated game data.

      Returns void

      If the round is invalid, no matching result exists, or kind and result are inconsistent.