the game of nim
DESCRIPTION
Benjamin Casey C S 329 E Spring 2009. The Game of Nim. Background. Variants played since ancient times; resemblance to Chinese “Jianshizi” or “picking stones” Current name and theory developed by C. Bouton of Harvard in 1901; name taken from German nimm meaning “take” - PowerPoint PPT PresentationTRANSCRIPT
Benjamin CaseyC S 329 ESpring 2009
Variants played since ancient times; resemblance to Chinese “Jianshizi” or “picking stones”
Current name and theory developed by C. Bouton of Harvard in 1901; name taken from German nimm meaning “take”
Fundamental to Sprague-Grundy thm., combinatorial game theory
Consists of a number of “nim-heaps”, each containing one or more objects
2 Players alternate taking 1 or more objects from any nim-heap
Normal play: Player who takes the last object wins
Misère play: player who takes the last object loses
Other variants
http://www.youtube.com/watch?v=oxBghtQ8McA
http://en.wikipedia.org/wiki/Nimrod_(computing)
Player 1 takes 1 from heap 2
Player 2 takes 1 from heap 2
Player 1 takes 1 from heap 1
Player 2 loses
Theory completely solved for any number of heaps/objects by C. Bouton
Based upon binary digital sum of heap sizes also known as “nim-sum”▪ write the size of each heap in binary▪ add the sizes without carrying▪ simple rule of thumb:
column w/ even # of 1’s = 0 column w/ odd # of 1’s = 1
1 01 1
= 0 1
1 01 0
= 0 0
Nim-sum obeys commutative and associative laws of addition
Also obeys another property: x + x = 0
Winning strategy: finish each move such that the nim-sum is zero if the nim-sum is non-zero upon your
move, it is always possible to move such that the resulting nim-sum is zero (but also possible to have a non-zero result)
if the nim-sum is zero upon your move, it is impossible to move such that the resulting nim-sum is zero
Nim-sum = 01 + 10
= 11
Nim-sum = 01 + 01
= 00
Nim-sum = 01
Nim-sum = 00
Let {x1, …, xn} = sizes of nim-heaps before move
Let {y1, …, yn} = sizes of nim-heaps after move
Let S = nim-sum of x1, …, xn Let T = nim-sum of y1, …, yn
If move was made in heap k: xi = yi for all i ≠ k
xk > yk
To determine which nim-heap k to play in: Calculate xi + S for in; call this Xi
The heap with Xi < xi is the heap you want to play in
To determine how many items to remove from heap k Move such that yi = Xi
S = 10 + 11 + 100 = 101X1 = x1 + S = 10 + 101 = 111X2 = x2 + S = 11 + 101 = 110X3 = x3 + S = 100 + 101 = 001
Thus k = x3 and you want to remove items such that y3 = X3 = 001
T = 10 + 11 + 01 = 00
T = 0 + TT = (S + S) + TT = S + (x1 + … + xn) + (y1 + … +
yn)T = S + (x1 + y1) + … + (xn + yn)T = S + 0 + … + (xk + yk) + … + 0
T = S + xk + yk
If S = 0 T = 0 + xk + yk ≠ 0, regardless of move
If S ≠ 0 Let d be the position of the most
significant non-zero bit in S Choose k such that the value of xk in
position d is also non-zero (such a k must exist)
Move such that yk = S + xk
S = 101x1 = 010x2 = 011x3 = 100
101100001 = S + xk
y3 = 001
T = S + xk + yk
T = S + xk + (S + xk)T = (S + S) + (xk + xk)
T = 0
When the next move will result in no remaining heaps of size ≥ 2 Normal play: Move such that an even
number of heaps of size 1 remain Misère play: Move such that an odd
number of heaps of size 1 remain
Player 1 can move so that an even number of heaps of size 1 remain
(Note that this still follows the strategy that T = 0. )
Player 2 loses again.
Player 1 can move so that an odd number of heaps of size 1 remain
Now T = 1. This is the only point where misère strategy differs from normal strategy.
Player 2 is forced to take the last object, losing the misère game.