Spaces:
Running
Running
Download src/lib/elo.ts from risenetup/chess-monolith: direct link, hf CLI and curl.
- Browser
- Download file 696 Bytes
-
https://huggingface.co/spaces/risenetup/chess-monolith/resolve/main/src/lib/elo.ts
- Command line
-
hf download hf://spaces/risenetup/chess-monolith/src/lib/elo.ts
-
curl -L -o elo.ts https://huggingface.co/spaces/risenetup/chess-monolith/resolve/main/src/lib/elo.ts
696 Bytes
| export function calculateNewRatings( | |
| ratingA: number, | |
| ratingB: number, | |
| scoreA: number, | |
| ) { | |
| const expectedA = 1 / (1 + Math.pow(10, (ratingB - ratingA) / 400)); | |
| const expectedB = 1 - expectedA; | |
| const getK = (r: number) => (r < 1200 ? 40 : r > 2400 ? 16 : 32); | |
| const kA = getK(ratingA); | |
| const kB = getK(ratingB); | |
| let newRatingA = Math.round(ratingA + kA * (scoreA - expectedA)); | |
| let newRatingB = Math.round(ratingB + kB * (1 - scoreA - expectedB)); | |
| const FLOOR = 100; | |
| newRatingA = Math.max(newRatingA, FLOOR); | |
| newRatingB = Math.max(newRatingB, FLOOR); | |
| return { | |
| newRatingA, | |
| newRatingB, | |
| diffA: newRatingA - ratingA, | |
| diffB: newRatingB - ratingB, | |
| }; | |
| } | |