import { volatilityArgs } from './algorithms/volatility'; import { Player } from './structs/player'; import { Team } from './structs/team'; /** * The class for a Race which is a match that includes more than 2 competitors */ declare class Race { /** * Array of the matches and outcomes based on the race results */ matches: [Player, Player, number][]; /** * @param results An ordered array of the race results with the winner in index 0, for all the players who tied on result they go into the same array * @example * ```ts * const race = new Race([[player1], [player2, player3], [player4]]) * ``` */ constructor(results: Player[][]); /** * @returns An array of the matches within the race in the format [{@link Player}, {@link Player}, placement][] */ getMatches(): [Player, Player, matchResult | number][]; /** * Turns an array of race results to an array of matches and outcomes * @param results An ordered array of the race results with the winner in index 0 * @returns An array of matches and outcomes based on the race results. [{@link Player}, {@link Player}, {@link matchResult}][] */ computeMatches(results: Player[][]): [Player, Player, matchResult | number][]; } /** * The main class of the rating system */ declare class Glicko2 { /** * Internal default tau value for new players */ private _tau; /** * Internal default rating in glicko format for new players */ private _default_rating; /** * Internal default rating deviation for new players */ private _default_rd; /** * Internal default volatility for new players */ private _default_vol; /** * An object of all the players cached with their key as their id * @default {} */ private players; /** * The number of players in the record * @default 0 */ private players_index; /** * The internal default volatility algorithm used by the Glicko2 object when making new players */ private _volatilityAlgorithm; constructor(settings?: { /** * The system constant, which constrains the change in volatility over time * @default 0.5 */ tau: number; /** * Base rating * @default 1500 */ rating: number; /** * Base volatility * The volatility measure indicates the degree of expected fluctuation in a player’s rating * @default 0.06 */ vol: number; /** * Base rating deviation * @default 350 */ rd: number; /** * The algorithm to calculate the volatility * @default {@link newProcedure} */ volatilityAlgorithm: (v: number, delta: number, { vol, tau, rd, rating }: volatilityArgs) => number; }); /** * @returns A {@link Race} object from the results */ makeRace(results: Player[][]): Race; /** * Removes all the players from the cache */ removePlayers(): void; /** * @returns A object with the player index id as the key and the {@link Player} object as the member */ getPlayers(): Record; /** * Removes all of the previous matches from each of the players objects */ cleanPreviousMatches(): void; /** * Updates the ratings for all the players */ calculatePlayersRatings(): void; /** * Creates players and match result to be taken in account for the new rankings calculation * players must have ids, they are not created if it has been done already. * @param player1 The first player * @param player2 The second player * @param outcome The outcome for the first player: 0 = defeat, 1 = victory, 0.5 = draw * @returns An object of the new player objects */ addMatch(player1: { rating: number; rd: number; vol: number; id: number; }, player2: { rating: number; rd: number; vol: number; id: number; }, outcome: matchResult | number): { pl1: Player; pl2: Player; }; /** * Creates a new {@link Player} and adds it to the cache * We do not expose {@link Glicko2._createInternalPlayer} directly in order to prevent the assignation of a custom player id whose uniqueness could not be guaranteed * @returns A {@link Player} object of the new player */ makePlayer(rating?: number, rd?: number, vol?: number): Player; private _createInternalPlayer; /** * Add a match result to be taken in account for the new rankings calculation * @param player1 The first player * @param player2 The second player * @param outcome The outcome of the first player : 0 = defeat, 1 = victory, 0.5 = draw */ addResult(player1: Player, player2: Player, outcome: matchResult | number): void; /** * Gets all the matches from the race(if is an instance of one), calculates player ratings * @example * ```ts * Glicko2.updateRatings([ * [Player1, Player2, 1], * [Player2, Player4, 0], * [Player3, Player1, 1], * [Team1, Team2, 0], * race * ]); * ``` */ updateRatings(matches: (playerMatch | Race | teamMatch)[]): void; /** * Gets an array of matches between 2 teams and their composite player object */ getTeamMatches(match: teamMatch): playerMatch[]; } declare type playerMatch = [Player, Player, matchResult | number]; declare type teamMatch = [Team, Team, matchResult | number]; declare enum matchResult { WIN = 1, LOSS = 0, DRAW = 0.5 } export { Glicko2 as G, Race as R, matchResult as m, playerMatch as p, teamMatch as t };