Research PlaygroundSøren Riis · ideas you can play with

Research game 03 · 7–10 min

Counterplay

A good score. A better question.

Optional advanced workshop: Nimbers · calculate the value from legal moves ↓

Optional advanced workshop · Nimbers · calculate the value from legal moves
What is happening? · The idea and the research

A weak opponent can let you win from a position that perfect play would lose. A rule can fit every familiar example and still fail on a new one. Counterplay lets you experience both before revealing a structural rule.

Nim’s rule is classical: write the heap sizes in binary. A position is losing for the next player exactly when every column contains an even number of 1s. Equivalently, the bitwise XOR of the heap sizes is zero.

The invariant, the opponent, and the audit

Normal play: reduce exactly one heap to a smaller nonnegative integer. No passing; whoever removes the last counter wins. The terminal position has no moves and is losing for the next player.

A legal move from XOR zero makes the XOR nonzero. From XOR x ≠ 0, take a heap h containing the highest set bit of x and reduce it to h XOR x. The new XOR is zero and the new heap is smaller. These two facts prove the strategy by induction on the number of counters.

The Collector always clears the leftmost nonempty heap. It has no learned parameters. The later opponent chooses a zero-XOR move when one exists, otherwise the first legal move. Both algorithms are deterministic.

The audit measures classification accuracy on six displayed two-heap cards and every nonterminal ordered three-heap board with heap sizes 0–7 (511 cases). These sets have different shapes; they are a transparent generalisation illustration, not a training experiment. Accuracy can conceal class imbalance, so the app exposes an actual counterexample. Our separate tests compare the XOR oracle with recursive win/loss search that does not use XOR.

Research connection and credits

Bei Zhou and Søren Riis distinguish champion performance and expert mastery in their study of AlphaZero-style learning in impartial-game settings. Counterplay borrows the question, not their agents or experimental data. It makes no claim about the ability of every reinforcement-learning system.

Impartial Games: A Challenge for Reinforcement Learning, Machine Learning 115, article 54 (6 March 2026).

Nim’s binary solution is due to Charles L. Bouton (1901–1902). The broader connection from finite normal-play impartial games to Nim is classical Sprague–Grundy theory. We use ordinary Nim only.

Follow the idea