// Pure derivations for the statistics screen, extracted so they are unit-testable. import type { Stats } from './model'; /** gamesPlayed is the total finished games (wins + losses + draws). */ export function gamesPlayed(s: Stats): number { return s.wins + s.losses + s.draws; } /** winRate is the percentage of finished games won, rounded; 0 when none played. */ export function winRate(s: Stats): number { const n = gamesPlayed(s); return n > 0 ? Math.round((s.wins / n) * 100) : 0; } /** hintSharePercent is the share of the player's plays that drew on a hint * (hints used / plays × 100), unrounded; 0 when no plays. The screen formats it to one * decimal in the active locale. */ export function hintSharePercent(s: Stats): number { return s.moves > 0 ? (s.hintsUsed / s.moves) * 100 : 0; }