Nim

Take the final counter by leaving the computer a losing combination of heap sizes.

Loading game

Stats on this device

Your unfinished game is saved only in this browser.

Played
0
Wins
0
Win rate
Fastest win
Fewest moves
Best score
Current streak
0 days
Best streak
0 days

How to play

Take the final counter by leaving the computer a losing combination of heap sizes.

  • Choose one non-empty heap.
  • Remove any positive number of counters from that heap only.
  • Alternate turns until one player takes the final counter and wins.

Strategy tips

  • Compare the binary parity of the heaps instead of always taking the largest group.
  • Try to return the position to a zero nim-sum after each computer move.
  • Near the end, count exactly who will receive the last available move.

Complete guide

Rules, scoring, and strategy

Nim is a complete-information subtraction game. Several heaps begin on the table, each move removes any positive number of counters from exactly one heap, and the player taking the final counter wins.

One heap per move

A legal move changes only one non-empty heap. You may remove one counter or the entire selected heap, but you cannot split a take between heaps. Empty heaps remain out of play while the other heaps continue.

Why binary parity matters

The strategic value of a position is the bitwise exclusive-or, or nim-sum, of its heap sizes. A zero nim-sum gives the next player no move that preserves zero; a nonzero position normally has a move that returns zero to the opponent.

Do not merely balance heap sizes

Two visually similar heaps are not automatically safe. Binary place values determine the useful reduction, so the best move may leave unequal heaps. Count the exact counters removed and re-evaluate after every computer reply.

A practical endgame

When only one heap remains, take it and win. With two heaps, equalizing them usually hands a zero position to the opponent. Earlier in the game, inspect the high binary bits before committing a large removal.

Questions players ask

Can I remove counters from two heaps?

No. Every turn selects exactly one heap and removes one or more counters from it.

What is the nim-sum?

It is the bitwise XOR of all heap sizes. It is a compact way to identify the losing positions in normal-play Nim.

Does the computer move randomly?

No. It uses a deterministic legal strategy, so the same position always produces the same reply.