Implement ChessUp server, vanilla TS UI, Stockfish analytics, and Docker/Cloudflared setup
This commit is contained in:
commit
e2e085b341
52 changed files with 15730 additions and 0 deletions
49
tests/glicko2.test.ts
Normal file
49
tests/glicko2.test.ts
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
import assert from 'node:assert/strict';
|
||||
import test from 'node:test';
|
||||
import {
|
||||
INITIAL_RATING,
|
||||
INITIAL_RD,
|
||||
INITIAL_VOLATILITY,
|
||||
PROVISIONAL_RD_THRESHOLD,
|
||||
isProvisionalRd,
|
||||
updateGlicko2,
|
||||
updateGlicko2Pair
|
||||
} from '../src/server/glicko2';
|
||||
|
||||
test('Glicko-2 matches Mark Glickman official paper worked example', () => {
|
||||
// Paper example: player rating 1500, RD 200, vol 0.06
|
||||
// Opponents: (1400, 30, win=1), (1550, 100, loss=0), (1700, 300, loss=0)
|
||||
const res = updateGlicko2(
|
||||
{ rating: 1500, rd: 200, volatility: 0.06, gamesPlayed: 5 },
|
||||
[
|
||||
{ rating: 1400, rd: 30, score: 1 },
|
||||
{ rating: 1550, rd: 100, score: 0 },
|
||||
{ rating: 1700, rd: 300, score: 0 }
|
||||
]
|
||||
);
|
||||
|
||||
assert.ok(Math.abs(res.rating - 1464.06) < 0.05, `Expected ~1464.06, got ${res.rating}`);
|
||||
assert.ok(Math.abs(res.rd - 151.52) < 0.05, `Expected ~151.52, got ${res.rd}`);
|
||||
assert.ok(Math.abs(res.volatility - 0.05999) < 0.0005, `Expected ~0.05999, got ${res.volatility}`);
|
||||
assert.equal(res.gamesPlayed, 8);
|
||||
});
|
||||
|
||||
test('Glicko-2 pair update symmetry and RD decay', () => {
|
||||
const p1 = { rating: INITIAL_RATING, rd: INITIAL_RD, volatility: INITIAL_VOLATILITY, gamesPlayed: 0 };
|
||||
const p2 = { rating: INITIAL_RATING, rd: INITIAL_RD, volatility: INITIAL_VOLATILITY, gamesPlayed: 0 };
|
||||
|
||||
const out = updateGlicko2Pair(p1, p2, 1);
|
||||
assert.ok(out.whiteDiff > 0);
|
||||
assert.equal(out.whiteDiff, -out.blackDiff);
|
||||
assert.ok(out.nextWhite.rd < INITIAL_RD);
|
||||
assert.ok(out.nextBlack.rd < INITIAL_RD);
|
||||
|
||||
// Draw between equal players yields 0 rating change
|
||||
const drawOut = updateGlicko2Pair(p1, p2, 0.5);
|
||||
assert.equal(drawOut.whiteDiff, 0);
|
||||
assert.equal(drawOut.blackDiff, 0);
|
||||
|
||||
// Provisional threshold
|
||||
assert.equal(isProvisionalRd(PROVISIONAL_RD_THRESHOLD + 1), true);
|
||||
assert.equal(isProvisionalRd(PROVISIONAL_RD_THRESHOLD), false);
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue