Delo is a TypeScript implementation of the Elo rating system for the Deno runtime.
import {
Period,
Player,
Outcome,
} from "https://deno.land/x/delo@v0.1.0/mod.ts";
const players: { [key: string]: Player } = {
Alice: new Player(1915),
Bob: new Player(1453),
Charlie: new Player(1375),
Doug: new Player(1991),
Earl: new Player(),
};
const period = new Period();
period.addGame(players.Alice, players.Bob, Outcome.LOSS);
period.addGame(players.Doug, players.Charlie, Outcome.DRAW);
period.addGame(players.Earl, players.Bob, Outcome.WIN);
period.addGame(players.Charlie, players.Alice, Outcome.WIN);
period.addGame(players.Doug, players.Earl, Outcome.LOSS);
period.calculate();
for (const name in players) {
console.log(`${name}: ${players[name].rating.toFixed(0)}`);
}Alice: 1870
Bob: 1465
Charlie: 1409
Doug: 1957
Earl: 1533
Outcome provides three constants to represent possible game results.
WIN- 1DRAW- 0.5LOSS- 0
id: string- A unique identifier for the Player object (UUID v4 by default).
rating: number- The Player's Elo rating.
A new Player has a default rating of 1500.
new Player();Pass a positive number for a different initial rating.
new Player(1800);Additionally pass a string to uniquely identify the player. By default, a v4 UUID is generated internally to keep track of players. You may want to pass an ID if, for example, you already maintain a database of players keyed by unique IDs.
new Player(1924, "jimmy23");length: number- The number of games played during the period.
addGame(player1: Player, player2: Player, score: Outcome)- Adds a game between
player1andplayer2, withscorerepresenting whetherplayer1won, drew, or lost againstplayer2.
- Adds a game between
reset()- Clears all games from the period. Does not affect player ratings.
calculate()- Updates the rating of all players who played games during this period.
New periods have a default K-factor of 24. The K-factor represents the maximum possible rating adjustment per game.
new Period();Pass a positive number to adjust the K-factor.
new Period(40);