Class representing a tournament.

See TournamentValues for detailed descriptions of properties.

Constructors

Properties

colored: boolean

If order of players in matches matters

id: string

Unique ID of the tournament

matches: Match[]

All matches of the tournament

meta: {
    [key: string]: any;
}

Any extra information

name: string

Name of the tournament

players: Player[]

All players in the tournament

round: number

Current round of the tournament

scoring: {
    bestOf: number;
    bye: number;
    draw: number;
    loss: number;
    tiebreaks: (
        | "median buchholz"
        | "solkoff"
        | "sonneborn berger"
        | "cumulative"
        | "versus"
        | "game win percentage"
        | "opponent game win percentage"
        | "opponent match win percentage"
        | "opponent opponent match win percentage")[];
    win: number;
}

Details regarding scoring

Type declaration

  • bestOf: number

    Number of possible games. Used to determine number of wins in a bye.

  • bye: number

    Points awarded for receiving a bye.

  • draw: number

    Points awarded for drawing a match.

  • loss: number

    Points awarded for losing a match.

  • tiebreaks: (
        | "median buchholz"
        | "solkoff"
        | "sonneborn berger"
        | "cumulative"
        | "versus"
        | "game win percentage"
        | "opponent game win percentage"
        | "opponent match win percentage"
        | "opponent opponent match win percentage")[]

    Array of tiebreakers being used.

  • win: number

    Points awarded for winning a match.

sorting: "none" | "ascending" | "descending"

Sorting method, if players are rated/seeded

stageOne: {
    consolation: boolean;
    format:
        | "single-elimination"
        | "double-elimination"
        | "stepladder"
        | "swiss"
        | "round-robin"
        | "double-round-robin";
    initialRound: number;
    maxPlayers: number;
    rounds: number;
}

Details regarding the tournament

Type declaration

  • consolation: boolean

    If there is a third place match for single elimination.

  • format:
        | "single-elimination"
        | "double-elimination"
        | "stepladder"
        | "swiss"
        | "round-robin"
        | "double-round-robin"

    Format for the first stage.

  • initialRound: number

    Number of the first round.

  • maxPlayers: number

    Maximum number of players who can be enrolled. There is no maximum if this is zero.

  • rounds: number

    Number of rounds in the first stage.

stageTwo: {
    advance: {
        method: "points" | "rank" | "all";
        value: number;
    };
    consolation: boolean;
    format: "single-elimination" | "double-elimination" | "stepladder";
}

Details regarding playoffs

Type declaration

  • advance: {
        method: "points" | "rank" | "all";
        value: number;
    }

    Determines how players advance from stage one to stage two.

    • method: "points" | "rank" | "all"

      The type of value to use if players advance.

    • value: number

      The breakpoint value for advancing players (greater than or equal to if method: 'points' and less than or equal to if method: 'rank').

  • consolation: boolean

    If there is a third place match for single elimination.

  • format: "single-elimination" | "double-elimination" | "stepladder"

    Format for the second stage. If null, then there is no stage two.

status:
    | "setup"
    | "stage-one"
    | "stage-two"
    | "complete"

Current state of the tournament

Accessors

Methods

  • Assigns a bye to a player in a specified round.

    Throws an error if it is not actively Swiss pairings, no player has the ID specified, if the player is already inactive, or if the player already has a match in the round.

    Parameters

    • id: string

      The ID of the player

    • round: number

      The round number

    Returns void

  • Assigns a loss to a player in a specified round.

    Throws an error if it is not actively Swiss pairings, no player has the ID specified, or if the player is already inactive.

    If the player has a match in the specified round, it is removed, they are assigned a loss, and the opponent is assigned a bye.

    Parameters

    • id: string

      The ID of the player

    • round: number

      The round number

    Returns void

  • Clears the results of a match.

    Throws an error if no match has the ID specified or if the match is still active.

    In elimination and stepladder formats, it reverses the progression of players in the bracket.

    Parameters

    • id: string

      The ID of the match

    Returns void

  • Create a new player.

    Throws an error if ID is specified and already exists, if the specified maximum number of players has been reached, if the tournament is in stage one and not Swiss format, or if the tournament is in stage two or complete.

    Parameters

    • name: string

      Alias of the player

    • id: string = undefined

      ID of the player (randomly assigned if omitted)

    Returns Player

    The newly created player

  • Updates the result of a match.

    Throws an error if no match has the ID specified or any player scores more than half the best of value

    In elimination and stepladder formats, moves players to their appropriate next matches.

    Parameters

    • id: string

      ID of the match

    • player1Wins: number

      Number of wins for player one

    • player2Wins: number

      Number of wins for player two

    • draws: number = 0

      Number of draws

    Returns void

  • Progress to the next round in the tournament.

    Throws an error if there are active matches, if the current format is elimination or stepladder, or when attempting to create matches for stage two and there are an insufficient number of players.

    Returns void

  • Remove a player.

    Throws an error if no player has the ID specified or if the player is already inactive.

    In active elimination and stepladder formats, adjusts paths for any matches that interact with the match the player is in.

    In active round-robin formats, replaces the player in all future matches with a bye.

    Parameters

    • id: string

      ID of the player

    Returns void

  • Computes tiebreakers for all players and ranks the players by points and tiebreakers.

    Parameters

    • activeOnly: boolean = true

      If the array contains only active players

    Returns StandingsValues[]

    A sorted array of players with scores and tiebreaker values

  • Start the tournament.

    Throws an error if there are an insufficient number of players (4 if double elimination, otherwise 2).

    Returns void