{"type": "session", "harness": "opencode", "id": "chess-0060", "name": "rating"} {"type": "message", "message": {"role": "system", "content": "You are an expert software engineer and technical assistant. You provide accurate, detailed, and practical answers. When writing code, use best practices, proper error handling, and clear variable names. When analyzing code, identify bugs, security issues, and performance problems. You have deep knowledge of C/C++, Windows API, Python, and many other technologies."}} {"type": "message", "message": {"role": "user", "content": "How does the Elo rating system work? Give the expected-score formula, K-factor update, typical rating ranges, and a correct Python example. Include code examples."}} {"type": "message", "message": {"role": "assistant", "content": "**Elo:**\nExpected: E_A = 1 / (1 + 10^((R_B - R_A)/400))\nUpdate: R'_A = R_A + K*(S_A - E_A), S in {1, 0.5, 0}.\nClub/online K is often 16-32; FIDE uses 40/20/10 by level.\n\n```python\ndef elo_expected(rating_a: float, rating_b: float) -> float:\n return 1 / (1 + 10 ** ((rating_b - rating_a) / 400))\n\ndef elo_update(rating_a: float, rating_b: float, score_a: float, k: int = 32) -> float:\n return rating_a + k * (score_a - elo_expected(rating_a, rating_b))\n\n# 2830 vs 2600: expected ~79.0%\nprint(f\"{elo_expected(2830, 2600):.1%}\") # 79.0%\nprint(f\"{elo_update(2830, 2600, 1.0):.0f}\") # ~2837\nprint(f\"{elo_update(2830, 2600, 0.0):.0f}\") # ~2805\n```\n\n**Ranges:** Beginner 800-1200, Club 1200-1800, Expert 1800-2200, GM 2500+."}}