Last active
March 5, 2022 00:29
-
-
Save bastienrobert/8aeb260d3691809abac8ffb1a25a6cd8 to your computer and use it in GitHub Desktop.
Simple implementation of Elo rating system in typescript
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// https://en.wikipedia.org/wiki/Elo_rating_system | |
const K = 32 | |
export enum EloStatus { | |
LOOSE = 0, | |
DRAW = 0.5, | |
WIN = 1 | |
} | |
const delta = (score: number, opponent: number, status: EloStatus) => { | |
const probability = 1 / (1 + Math.pow(10, (opponent - score) / 400)) | |
return Math.round(K * (status - probability)) | |
} | |
export default (score: number, opponent: number, status: EloStatus) => { | |
return score + delta(score, opponent, status) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment