extremely claude-assisted go game based on atproto! working on cleaning up and giving a more unique design, still has a bit of a slop vibe to it.
1/**
2 * ELO rating system utilities for Cloud Go
3 */
4
5const DEFAULT_RATING = 1200;
6const K_FACTOR = 32; // Standard K-factor for chess-like games
7
8/**
9 * Calculate expected score for a player
10 * @param playerRating - Player's current rating
11 * @param opponentRating - Opponent's current rating
12 * @returns Expected score (0-1)
13 */
14function calculateExpectedScore(playerRating: number, opponentRating: number): number {
15 return 1 / (1 + Math.pow(10, (opponentRating - playerRating) / 400));
16}
17
18/**
19 * Calculate new ELO rating after a game
20 * @param currentRating - Player's current rating
21 * @param opponentRating - Opponent's rating
22 * @param actualScore - Actual game result (1 = win, 0.5 = draw, 0 = loss)
23 * @returns New rating
24 */
25export function calculateNewRating(
26 currentRating: number,
27 opponentRating: number,
28 actualScore: number
29): number {
30 const expectedScore = calculateExpectedScore(currentRating, opponentRating);
31 const ratingChange = K_FACTOR * (actualScore - expectedScore);
32 return Math.round(currentRating + ratingChange);
33}
34
35/**
36 * Get the default rating for players without a profile
37 */
38export function getDefaultRating(): number {
39 return DEFAULT_RATING;
40}