Skip to content

Instantly share code, notes, and snippets.

@bastienrobert
Last active March 5, 2022 00:29
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bastienrobert/8aeb260d3691809abac8ffb1a25a6cd8 to your computer and use it in GitHub Desktop.
Save bastienrobert/8aeb260d3691809abac8ffb1a25a6cd8 to your computer and use it in GitHub Desktop.
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