/** * ELO rating system utilities for Cloud Go */ const DEFAULT_RATING = 1200; const K_FACTOR = 32; // Standard K-factor for chess-like games /** * Calculate expected score for a player * @param playerRating - Player's current rating * @param opponentRating - Opponent's current rating * @returns Expected score (0-1) */ function calculateExpectedScore(playerRating: number, opponentRating: number): number { return 1 / (1 + Math.pow(10, (opponentRating - playerRating) / 400)); } /** * Calculate new ELO rating after a game * @param currentRating - Player's current rating * @param opponentRating - Opponent's rating * @param actualScore - Actual game result (1 = win, 0.5 = draw, 0 = loss) * @returns New rating */ export function calculateNewRating( currentRating: number, opponentRating: number, actualScore: number ): number { const expectedScore = calculateExpectedScore(currentRating, opponentRating); const ratingChange = K_FACTOR * (actualScore - expectedScore); return Math.round(currentRating + ratingChange); } /** * Get the default rating for players without a profile */ export function getDefaultRating(): number { return DEFAULT_RATING; }