1 / 22

The Game of Nim

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”

talor
Download Presentation

The Game of Nim

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Benjamin Casey C S 329 E Spring 2009 The Game of Nim

  2. 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” • Fundamental to Sprague-Grundy thm., combinatorial game theory

  3. Basics • 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

  4. The Amazing Dr. Nim http://www.youtube.com/watch?v=oxBghtQ8McA

  5. Nimrod http://en.wikipedia.org/wiki/Nimrod_(computing)

  6. Simple Example Player 1 takes 1 from heap 2 Player 1 takes 1 from heap 1    Player 2 takes 1 from heap 2 Player 2 loses 

  7. Theory • 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

  8. Binary Digital Sum 1 0 1 1 = 0 1 1 0 1 0 = 0 0

  9. Binary Digital Sum • Nim-sum obeys commutative and associative laws of addition • Also obeys another property: • x + x = 0

  10. Strategy • 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

  11. Simple Example Nim-sum = 01 + 10 = 11 Nim-sum = 01    Nim-sum = 01 + 01 = 00 Nim-sum = 00

  12. Proof • 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

  13. Strategy • To determine which nim-heap k to play in: • Calculate xi + S for in; 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

  14. Example  S = 10 + 11 + 100 = 101 X1 = x1 + S = 10 + 101 = 111 X2 = x2 + S = 11 + 101 = 110 X3 = x3 + S = 100 + 101 = 001 Thus k = x3 and you want to remove items such that y3 = X3 = 001 T = 10 + 11 + 01 = 00

  15. Proof • T = 0 + T • T = (S + S) + T • T = S + (x1 + … + xn) + (y1 + … + yn) • T = S + (x1 + y1) + … + (xn + yn) • T = S + 0 + … + (xk + yk) + … + 0 • T = S + xk + yk

  16. Therefore…. • 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

  17. Example  S = 101 x1 = 010 x2 = 011 x3 = 100 101 100 001 = S + xk y3 = 001

  18. Proof • T = S + xk + yk • T = S + xk + (S + xk) • T = (S + S) + (xk + xk) • T = 0

  19. Endgame • 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

  20. Example: Normal endgame    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.

  21. Example: Misère endgame     Now T = 1. This is the only point where misère strategy differs from normal strategy. Player 1 can move so that an odd number of heaps of size 1 remain Player 2 is forced to take the last object, losing the misère game.

  22. Any Questions?

More Related