🎮

Nim

Loading game...

Nim Game Guide

📖 About

Nim is one of the oldest mathematical games in history, dating back centuries! Multiple piles of stones sit before you—take any number from one pile each turn. In the standard version, the player who takes the last stone loses. Despite simple rules, Nim contains deep mathematical theory using binary XOR operations. Perfect information, no luck—pure strategic thinking!

🎯 Objectives

Force your opponent to take the last stone (or be the one to take it in misère version). Plan your moves to leave your opponent in losing positions. Master the mathematical theory for guaranteed wins against suboptimal play!

🎮 How to Play

Select a row, then choose how many stones to remove. You must take at least 1 stone. The player forced to take the last stone loses the game.

⌨️ Controls

Click on a pile to select it, then choose how many stones to remove. You can take any number from 1 to all stones in that pile. Players alternate turns until someone takes the last stone.

⚙️ Game Mechanics

  • Take 1 or more stones from one pile
  • Cannot take from multiple piles
  • Player taking last stone loses
  • No hidden information
  • Perfect play is calculable

Features

  • Pure Strategy - No luck involved
  • Mathematical Theory - XOR-based solution
  • Multiple Difficulties - Easy to hard AI
  • Educational - Learn game theory

💡 Tips

  • In Hard mode, the AI uses optimal XOR strategy
  • Try to leave your opponent with equal rows
  • Control the total stone count
  • Learn the mathematical theory for perfect play

Frequently Asked Questions

What's the XOR strategy in Nim?
Calculate the XOR (exclusive or) of all pile sizes in binary. If the result is 0, you're in a losing position with perfect play. If non-zero, there's always a move to put your opponent in a losing position.
Is Nim always winnable for one player?
Yes! With perfect play, the winner is determined by the starting position. If the initial XOR is 0, the second player wins. If non-zero, the first player wins. This is mathematically proven!
What's misère Nim?
Misère is the standard version where taking the last stone loses. Normal play (taking last wins) is actually easier to analyze. The strategies differ slightly near the endgame.
How old is the game of Nim?
Nim's origins are unclear but it's certainly centuries old, possibly ancient Chinese. It was studied mathematically in 1901 by Charles Bouton, who discovered the XOR winning strategy.

Share this Game

Embed this Game on Your Site

Copy the code below to embed this game on your website or blog:

<iframe src="https://ruleword.com/embed/nim/" width="600" height="400" frameborder="0" style="border-radius:12px"></iframe>