# Nim https://nim-game.skillsafe.ai/ A browser implementation of three impartial games — Nim, Kayles and the S={1,2,3} subtraction game — in normal or misere play, against an opponent that plays perfectly, together with a Sprague-Grundy lens that shows the single Nim heap any position is equal to. ## What it is Runs entirely client-side. No account, no network requests, no model calls, no credits. Settings and a win/loss tally are kept in this browser's localStorage and nowhere else. ## The mechanism it exists to show Every impartial game is equivalent to one Nim heap (Sprague-Grundy). A Kayles row of 12 pins is a Nim heap of 4. A subtraction heap of 15 is a Nim heap of 3. The position's whole future collapses to one number, and zero means the player about to move has already lost. The lens draws that number, the per-component values it comes from, and the binary columns that XOR into it. ## Sources - Nim's theory: Charles L. Bouton, "Nim, A Game with a Complete Mathematical Theory", Annals of Mathematics, 2nd series, 3 (1901-1902), 35-39. - Kayles: Henry Dudeney, The Canterbury Puzzles (1908), puzzle 73; analysed by R. K. Guy and C. A. B. Smith, "The G-values of various games", Proc. Cambridge Philos. Soc. 52 (1956) 514-526. Nim-values: OEIS A002186. - Sprague-Grundy theorem: R. P. Sprague (1935/36), P. M. Grundy (1939). ## What it measured The claim "Nim is about taking the last object, so the winning idea is to count how many are left" is false as a general rule and exactly right on one set. Predicting the outcome from the parity of the total is 64.81% accurate over 540 enumerated positions (95% CI 60.70-68.73%), and 100% accurate on the 12 positions whose every heap holds 0 or 1 counters - because there the nim-sum IS the parity of the count. Handed an already-won position against perfect defence, a perfect player converts 2738 of 2738; a counting player converts 52 of 2775 (1.87%, 95% CI 1.43-2.45%) against random play's 13 of 2750 (two-proportion z = 4.83). Misere and normal play differ in outcome on exactly the positions whose every heap holds 0 or 1 counters, and in winning MOVES on exactly the non-empty positions with at most one heap holding more than one counter. Over 500 perfectly played misere games, all 500 passed through such a position; 18.75% of all moves played were ones where the two conventions disagree (95% CI 17.78-19.76%). The Kayles nim-values are recomputed from the move rule and match both published sources for all 105 terms. Period 12; 14 exceptional values; the last at n = 70, so the minimal preperiod is 71, not the 72 usually quoted. ## Credits Independent reimplementation. Not affiliated with any publisher. See /CREDITS.txt for full sources and a list of what differs from the originals.