UNPKG

tiebreak

Version:

Calculation of chess tournament tiebreaks compliant with FIDE regulations

75 lines (74 loc) 2.32 kB
export type Score = 0 | 0.5 | 1; /** * Unique identifier for a player. Exact format is up to the caller. */ export type PlayerId = string | number; /** * Results of a tournament round. */ export type RoundResults = { /** * Pairings for this round. */ pairings: Pairing[]; /** * IDs of players who were allocated a bye by the pairing algorithm. This is usually * one player if the number of players is odd and no player if the number of players * is even. */ pairingAllocatedByes?: PlayerId[]; /** * Some tournaments have a half-point bye system where players can request a bye and receive * half a point. */ halfPointByes?: PlayerId[]; }; export type Pairing = { white: PlayerId; black: PlayerId; scoreWhite: Score; scoreBlack: Score; forfeited: boolean; }; export declare enum TournamentType { SWISS = "SWISS" } /** * Immutable representation of a tournament's pairings and results. */ export declare class Results { readonly tournamentType: TournamentType; private pairings; constructor(tournamentType: TournamentType, results: RoundResults[]); private addToMap; /** * Returns the result for the given player and round. */ get(playerId: PlayerId, round: number): PlayerResult; /** * Returns results for a player for each round up to the given maxRound. */ getAll(playerId: PlayerId, maxRound: number): PlayerResult[]; allPlayers(): PlayerId[]; } /** * Pairing from the view of the player. */ export interface PlayerPairing { score: Score; opponentScore: Score; opponent: PlayerId; forfeited: boolean; } /** * A round's result from the view of the player. */ export type PlayerResult = PlayerPairing | "allocated-bye" | "half-point-bye" | "unpaired"; export declare function isPaired(result: PlayerResult): result is PlayerPairing; export declare function isPlayed(result: PlayerResult): result is PlayerPairing; export declare function isForfeitLoss(result: PlayerResult): boolean; /** * Voluntarily Unplayed Rounds (VUR) are defined in the FIDE regulations and in some cases * handled differently from rounds in which the player was "available to play". */ export declare function isVoluntarilyUnplayedRound(result: PlayerResult): boolean;