elo-rating-system
v1.2.0
Published
elo calculator in javascript
Readme
The Elo rating system is a method for calculating the relative skill levels of players in zero-sum games such as chess. It is named after its creator Arpad Elo, a Hungarian-American physics professor - wikipedia
npm install elo-rating-systemUsage
const { Elo } = require('elo-rating-system');
const elo = new Elo({ k: 20, rating: 2000 }); // override the defaults (k: 20, rating: 1200).change() - rating change based on opponentRating and result
const { change, newRating } = elo.change(2200, 1); // { change: 15.19..., newRating: 2015 }.probability() - decimal probability of winning vs opponentRating
const probability = elo.probability(2200); // 0.24 (or 24%).performance() - performance rating from an array of game results
const perf = elo.performance([
{ opponentRating: 2200, result: 1 },
{ opponentRating: 2100, result: 0.5 },
{ opponentRating: 2600, result: 0 },
]);
// { games: 3, change: [...], ratings: [...], tpr: 2233.33 }Results use 1 for a win, 0.5 for a draw, and 0 for a loss.
Dynamic K-Factor
Pass a function as k to vary the K-factor based on the player's rating:
const elo = new Elo({
rating: 2000,
k: (rating) => {
if (rating < 2400) return 40;
return 10;
},
});Tests
npm test