Nim — Classic Stone Removal Game vs Computer
Take 1-3 stones from a pile. The player who takes the last stone wins. Play vs an optimal AI.
How to play
- You and the AI take turns removing 1, 2, or 3 stones from the pile.
- The player who takes the very last stone WINS.
- Optimal strategy: always leave a multiple of 4 stones after your turn.
- Click 'Take 1', 'Take 2', or 'Take 3' to make your move.
- Click 'New Game' to start with a fresh random pile.
Take 1, 2, or 3 stones from a pile of 15–21. The player who takes the last stone wins. The AI plays optimally — can you find the winning strategy?
Frequently asked questions
- What is the winning strategy?
- Always leave a number of stones that is a multiple of 4 after your turn. If your opponent plays optimally, the player who inherits a multiple of 4 is in a losing position.
- Does the AI always win?
- The AI plays the optimal Nim strategy. You can still win if you start in a position where the stone count mod 4 is not 0 — i.e., immediately take the right number.