Skip to content

Instantly share code, notes, and snippets.

@bastienrobert
Last active Mar 5, 2022
Embed
What would you like to do?
Simple implementation of Elo rating system in typescript
// 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