22C:2 From CAT Scans to Google: Great Ideas in Computing
Homework 9. Due November 30, 2006
Nim is the name of a family of two-player games where a players alternate removing
some sticks from one or more piles. There are many varieties of Nim. We'll consider
one simple one here.
In this version, the game starts with one pile of sticks, and at each turn a player
may remove 1, 2, or 3 sticks. The person who removes the final stick is the loser.
- Draw (you might need an extra large piece of paper) the complete game tree
for Nim, assuming the game starts with 7 sticks. Thus, the root/top of the
tree will represent the pile having all 7 sticks. Since the first player can
remove 1, 2, or 3, stick, there will be 3 nodes underneath the game tree's root,
one for the situation with 4 sticks remaining, one for 5 sticks, remaining, and
one for 6 sticks remaining. The "leaves" at the bottom of the tree represent
game-ending situations where there is just one stick remaining.
Use the minimax process to label your game tree nodes with +1 (win for first player)
and -1 (loss for first player). Remember to start at the bottom, the leaf nodes
(where, since there's just one stick left, the winner is known), and then
assign scores to the nodes above (parents/ancesters) based on max (when it's
player one's turn) or min (when it's player two's turn) of the child nodes.
Based on the score eventually assigned to the root node, should player 1 win or lose
this 7-stick Nim. And what move does the minimax process say Player 1 should make?
- Based on what you might have learned in question 1, can you come up with a general strategy/rule for
winning a Nim game that starts with more than a certain small number of sticks (you determine the number -
question 1 will help with this). That is, is there a simple rule or set of stick-taking rules that will
ensure either the first or second player always wins.
Explain your answer.