Grade 7/8 Math Circles Game Theory - Solutions Chomp

Faculty of Mathematics
Waterloo, Ontario N2L 3G1
Centre for Education in
Mathematics and Computing
Grade 7/8 Math Circles
Game Theory - Solutions
October 27/28, 2015
Chomp
Chomp is a simple 2-player game. There is a grid, and in the bottom-left corner of the grid
is a poison square. Players alternate turns, and on each turn, the player selects a square and
’eats’ that square and all of the squares above and to the right of it (see example below).
The player who is forced to eat the poison square loses.
Try playing a few games of Chomp with the people around you using the game boards below.
Change who goes first in each game. Is there one player who always wins? If so, why do you
think that is?
1
Rooks
Another simple game is called Rooks. In this game, a rook is placed in the bottom right
corner of a rectangular board. Players take turns moving the rook either straight up any
number of squares, or straight left any number of squares (but not both in one turn). The
rook cannot move down or to the right. The player who places the rook in the top left corner
of the board wins. Play a few games against those around you on the boards below.
Is there anything you noticed about this game? Are the certain points in the game where
you know you will win?
Both Rooks and Chomp are examples of impartial combinatorial games. These are
games are usually two-player games. For our purposes, these are games where any move
available to one player is also available to another, there is perfect information (everyone
knows everything about the game), there is a limited number of possible moves (so the game
eventually ends), and nothing in the game is left to chance. usually, the first player who
cannot move loses (or equivalently, the player who makes the last move wins).
It has been shown that all games of this type can be simplified to a version of a special game
called Nim. We will be exploring the game of Nim and developing a strategy for it.
2
Nim
Nim is a relatively simple game to play. There are a number of piles (or heaps) of chips. On
each turn, a player removes chips from one of these piles. A player can only remove chips
from one pile on each turn, and they must remove at least one chip. The player who takes
the last chip(s) wins.
Nim Notation
We will denote each pile of chips in a Nim game as ∗x where x is the number of chips in a
pile. Games with multiple piles will be denoted as ∗x1 + ∗x2 + · · · + ∗xn where each of the
∗xi represent a different pile.
For example, a game with one pile of 2 chips, and another pile of 3 chips would be written
as ∗2 + ∗3. We write ∗0 to represent a game or pile with no chips.
We will call player 1 the player whose turn it is to move (i.e. the player who will make the
next move)
Winning and Losing Games
In Nim, one player will always win, and one player will always lose. We know this because
there are only so many chips on the board, and on each turn some chips are removed. This
means that eventually all of the chips will be gone, and clearly only one person can pick up
the last chip.
We says that a game is a winning game for a player if they can guarantee that they will
win the game. This means that if the player makes a specific move on each of their turns,
they will always win.
In contrast, a losing game is a game or position where a player will lose no matter what.
In other words, a player can make any move, and the other player will still be able to win
the game.
Exercise 1: What is the relationship between winning and losing games? If it possible for a
game to be a winning game and a losing game for one player at the same time?
In the games we are considering there will always be one winner, and one loser. This means
that is a game is winning for player 1 (i.e. player 1 can guarantee a win if the play the
optimal moves) then it is a losing game for player 2.
Exercise 2: Is ∗0 a winning or losing game for player 1? What about for player 2?
∗0 is a losing game for player 1 as they cannot remove any chips. This means they cannot
make a valid move, and so they lose. In contrast, it is a winning game for player 2
Basic Nim Strategies
Single Pile Nim
The simplest Nim games involve just a single pile of chips. This leads to a very simple
strategy to win the game. Clearly, if there are no chips in the pile, then the player whose
turn it is (we will call them player 1) loses. If there are chips in the pile, then player 1 can
always win. All that they have to do is take all the chips. Then player 2 won’t have any
chips to take.
3
2-Heap Nim
The next simplest form of Nim is with two heaps. To examine games with two heaps, we
will break our analysis into two cases: when the piles are the same size, and when they are
different sizes.
2-Heaps of the same size - In this case both of the piles have the same number of chips.
On each turn, a player can only remove chips from one pile. This leads to a simple copycat
strategy that enables player 2 to always win. All player has to do is watch player 1 and then
take the same number of chips as player 1 did, but take them from the other pile. That way,
both piles will still have the same amount in them after each of player 2’s turns.
2-Heaps of different sizes - In this scenario player 1 can exploit what we already know
about Nim with two heaps of the same size. In that case, the player who moves second
wins. Knowing this, player 1 can create a situation where there are two piles with the same
amount of chips in it and where they move second in that instance. To do this they simply
remove enough chips from the first pile to make the piles even. Then, the game is exactly
like our previous case and the player can employ the copycat strategy.
Strategy is complex Nim games
These strategies work in simple games. Can we develop a strategy in more complex games?
How can we know that player 2 can always win in the game ∗1 + ∗2 + ∗3 or that player 1
can always win in the game ∗1 + ∗2 + ∗3 + ∗7 + ∗7 + ∗9 + ∗1?
The answer to this lies in the binary representation of each of these numbers. Each integer
can be written as a unique sum of powers of two. For example, 13 can be written as
20 + +22 + 23 = 1 + 4 + 8 and 6 can be written as 21 + 22 . Notice that each power only
appears once in the sum (if power i appeared twice, we would have 2 × 2i = 2i+1 and we
could just write it as a new power of 2.
But how does this help us build a strategy in Nim? It turns out, that a Nim game with
one pile, is equivalent to the Nim game with multiple piles where the number of chips in
each pile is equal to one of the powers of 2 in the binary representation. In other words,
∗13 ≡ ∗1 + ∗4 + ∗8 and ∗6 ≡ ∗2 + ∗4. But equivalence doesn’t just work in one direction.
If we have a game with multiple piles where each pile has a unique power of two number of
chips, we could combine them to make a game with a single pile which we know how to win.
The method to make a complex game simpler then is to:
1. For each pile in the original game, determine what its binary representation is.
2. Replace each simple pile in the original game with multiple piles, each with a power of
two number of chips
3. Cross out pairs of the same powers of two
4. When there are no pairs left, add the total number of chips up and replace the multiple
piles with one pile with the total number of chips in it.
To see exactly how this process works, consider the game ∗1 + ∗3 + ∗5:
4
1. The binary representations of each number are:
1 = 20
3 = 2 0 + 21
5 = 2 0 + 22
2. We replace each pile in our original game as:
∗1 + ∗3 + ∗5 ≡ ∗20 + ∗20 + ∗21 + ∗20 + ∗22 ≡ ∗1 + ∗1 + ∗1 + ∗2 + ∗4
3. Eliminate pairs of the same power of two:
(∗1 + ∗1) + ∗ 1 + ∗2 + ∗4
4. Add the total number of chips. We have 7 total chips. This means:
∗1 + ∗3 + ∗5 ≡ ∗20 + ∗21 + ∗22 ≡ ∗1 + ∗2 + ∗4 ≡ ∗7
As a second example, consider the game ∗1 + ∗2 + ∗3
1. The binary representations of each number are:
1 = 20
2 = 21
3 = 20 + 21
2. Replace each pile:
∗1 + ∗2 + ∗3 ≡ ∗20 + ∗21 + ∗20 + ∗21 ≡ ∗1 + ∗1 + ∗2 + ∗2
3. Cancel out pairs of powers of two:
(∗1 + ∗1) + (∗2 + ∗2)
4. Since we have no more chips left, we know ∗1 + ∗2 + ∗3 ≡ ∗0. This means that it is a
losing game
If a game has chips left after we simplify it (like the first example) then it is a winning game.
Otherwise, it is a losing game. If a game is winning, how can we determine what move to
make? That answer again involves binary representations.
If a game that simplifies to ∗0 or a game with no chips is a losing game, then that is the
position we want to leave our opponents. In single pile Nim, we would just take all of the
chips from the pile, so this seems like a logical place to start.
5
Unfortunately, just removing the number of chips left won’t work. Instead we have to add
that many chips to one of the piles and re-simplify that pile. This will tell us how many
chips to leave in that pile, and conversely how many chips to remove.
Let’s consider the first example of the game ∗1 + ∗3 + ∗5. We said that the simplified game
had ∗20 + ∗21 + ∗22 as its binary representation. The biggest power of 2 in this is 2. If we
look at the binary representation of each pile in the original game, the pile that has 22 in it
is ∗5. This means we are going to add chips to this pile.
Originally, the binary representation of ∗5 is ∗20 + ∗22 . We are going to add ∗20 + ∗21 + ∗22
to it. This gives us ∗20 + ∗22 + ∗20 + ∗21 + ∗22
We then eliminate each the pairs of similar powers as follows:
(∗20 + ∗20 ) + ∗ 21 + (∗22 + ∗22 ) ≡ ∗21 ≡ ∗2
This means that we need to change ∗5 to ∗2. We do this by removing 3 chips from that pile.
This means we started with ∗1 + ∗3 + ∗5 and moved to ∗1 + ∗3 + ∗2. The result is that we
have put our opponent into a losing position as we showed above.
This strategy for determining the correct move will work for any Nim game. However, if the
initial simplified game is ∗0 your opponent will always be able to win - unless the make a
mistake.
Converting other games to Nim values
It has been shown that all impartial combinatorial games are equivalent to a Nim game. We
will look at converting the Rooks game to its Nim values.
The easiest square to convert to a Nim value is the ending square. If the rook is in the top
left corner and it is your turn to move (i.e. your opponent just put it there) then you lost.
Losing is equivalent to ∗0.
For each other square, we look at where it could move to. The Nim value is then the smallest
number (at least 0) that is not in any of the squares that you could move to. For example, if
we pick the square directly below the top left, then the only move is into the top left corner.
This square has value ∗0 and so the smallest positive integer that we can’t move to is 1. This
means the Nim value for this square is ∗1. We can continue doing this for every square until
we have the whole grid filled in. This results in the following Nim values for each square:
6
Problem Set
1. We said that an impartial game is a game where each player can make the exact same
moves. Are chess and checkers impartial games? Why or why not?
Chess and checkers are not impartial games as each player can only move one colour
of pieces. This means that the two players do not have access to the exact same moves
2. Think back to the game Chomp from the beginning of this lesson. Who can always
guarantee a win if it is played on a 2x2 board? What about a 3x2 board? (Boards are
illustrated below).
(a) Play a few games with a friend on each board to determine who you think should
win.
Player 1 should always win
(b) Determine a strategy (or a set of moves) that will guarantee that that player will
win.
Player 1 can guarantee a win if they take the top right square in either situation.
In the first game (2x2), by taking the top right square, player 1 has left 2 nonpoisonous squares remaining. Player 2 must take one of them, but they cannot
take both. This allows player 1 to take the last non-poisonous square and winning
the game.
3. Dominoes is another game played on a rectangular board. In this game, players take
turn placing dominoes (which are 1x2 rectangles) onto the board. The dominoes cannot
overlap each other, and the first person who cannot play loses. A sample game on a
2x3 board where player 1 loses is shown below.
(a) On a 3x3 game board (provided below) who should always win?
Player 2 should always win
7
(b) Why should that player always in? What strategy should they follow?
Player 2 can always win because they can always create a 2x2 square with the
played dominoes. This leaves a five space ‘L’ that is uncovered by dominoes
(shown below). Since there are 5 spaces in the L, and a domino can only cover
2 space, there will always be a space for player 2 to play. However, player 1 will
never be able to make a third move (because there are only 9 squares on the grid
and a third move would put a 5th domino on the grid which would require 10
square. This means that player 2’s second move is the last move and so they win
4. For each Nim game below:
(a) Determine what simplified single heap Nim game it is equivalent to
(b) Determine whether the game is a winning or losing game for player 1
(c) If it is a winning game, find one possible winning move
(d) Play each game with a friend and see if you can guarantee a win!
I ∗3 + ∗5 + ∗7
(a) ∗3 + ∗5 + ∗7 ≡ ∗20 + ∗21 + ∗20 + ∗22 + ∗20 + ∗21 + ∗22 ≡ ∗20 ≡ ∗1
(b) This is a winning game for player 1 as it is equivalent to a single pile game
with more than 0 chips.
(c) Removing 1 chip from any pile is a winning move. We can see this as the
highest power of two remaining in the simplified game is 20 . When we look
for a pile which has a 20 in it when written as a power of two, we see that all
of them have this. This means we can pick any pile. We then add 20 chips to
that pile. This then cancels out the 20 in that pile and we are left with one
fewer chip in that pile. For example, if we picked the pile of three:
∗3 ≡ ∗20 + ∗21 add the remaining 20 from the simplification to get
∗20 + ∗20 + ∗ 21 ≡ ∗21 ≡ ∗2 and this means we want to leave 2 chips in this
pile
II ∗2 + ∗3 + ∗5 + ∗7
(a) ∗2+∗3+∗5+∗7 ≡ ∗21 +∗20 +∗21 +∗20 +∗22 +∗20 +∗21 +∗22 ≡ ∗20 +∗21 ≡ ∗3
(b) This is a winning game for player 1 as it is equivalent to a game with more
than zero chips.
8
(c) The highest power of two that remains in the simplified game is 1. This means
we pick a pile that has 21 in it. We notice that both the first and second piles
(of 2 and 3 respectively) have this power. While we could choose either pile,
in this case we will choose the second pile.
To determine the number of chips to leave in this pile, we add the remaining
20 + 21 from our simplification to the 20 + 21 from the original pile of 3. This
results in:
∗20 + ∗21 + ∗20 + ∗21 ≡ ∗20 + ∗20 + ∗21 + ∗21 ≡ ∗0 This means we want to
leave 0 chips in the pile, so our winning move is to take all 3 chips from the
second pile.
III ∗2 + ∗4 + ∗10 + ∗12
(a) ∗2 + ∗4 + ∗10 + ∗12 ≡ ∗21 + ∗22 + ∗21 + ∗23 + ∗22 + ∗23 ≡ ∗0
(b) This is a losing game for player 1.
(c) Since this is a losing game for player 1, there are no winning moves.
IV ∗1 + ∗1 + ∗1 + ∗1 + ∗36
(a) ∗1 + ∗1 + ∗1 + ∗1 + ∗36 ≡ ∗20 + ∗20 + ∗20 + ∗20 + 822 + ∗25 ≡ ∗22 + ∗25 ≡ ∗36
(b) This is a winning game for player 1.
(c) The highest power remaining in the simplified game is 5. The only pile with a
power of 5 is the final pile of 36 chips. This means we leave ∗22 + ∗25 + ∗22 +
∗25 ≡ ∗0 chips in the last pile. This means the winning move is to take all of
the chips from the last pile.
5. The Queens game is very similar to the Rooks game we played before. However, this
time, the piece can also move diagonally up and to the left. Once again, the first player
who cannot move loses. This means that if the Queen is in the top left corner of the
board, then the player whose turn it is loses.
On the board below, fill in the Nim values for each square. The top left square has
been done for you.
9
Challenge Problems
1. Suppose we modified the game Nim by introducing a new rule. In addition to the chips
in the piles on the board, there is now a bag containing x additional chips. On their
turn, a player can either remove chips from any pile (a normal Nim move) or they can
take chips from the bag and add them to any one pile.
(a) Using the bag, can a player change a losing position in a normal Nim game into
a winning game for them?
No, a player cannot turn a losing game into a winning game.
(b) Why or why not?
If a player is in a losing position, then any regular Nim game will not change it
to a winning position. Thus, for a game to change from losing to winning, they
would need to use the bag to add chips to one pile. However, if a player does this,
then their opponent could just remove the newly added chips. This would leave
the exact same situation as the players were in before (except with fewer chips in
the bag). This means the player in the losing position would still be in a losing
position.
2. In Chomp, if the starting board is strictly larger than a 1x1 rectangle (i.e. it has more
than one square) who can always guarantee a win? (Think back to who won in the
2x2 and 3x2 cases from question 2 in the problem set). Prove that this player always
has a winning strategy.
Player 1 can always win.
The following is a non-constructive proof. This means that we will not explicitly
describe a strategy that player 1 can follow. Instead, we will show that such a strategy
must exist.
To begin with, we will assume that player 1 is in a losing position. If player 1 were
in a winning position then clearly a strategy would exist, because our definition of a
winning position is that a strategy exists to guarantee a win. Our next step will be to
show why player 1 cannot be in a losing position.
If player 1 is in a losing position, then player 2 would be in a winning position. This
means that no matter what move player 1 makes, player 2 will have a winning move.
Now, suppose that player 1’s move is to select the top right corner square of the grid.
Then, the only square that will be removed is that top right square. Player 2 now
makes a winning move. Again, this winning move exists because player 2 is in a winning position (since player 1 is, by assumption, in a losing position).
Let’s examine player 2’s move further. Suppose player 1 had made that move instead of selecting the top right square? Then the board would be in the exact same
position after that move as it is after player 2’s move in our first case. this is because
any move will remove the top right corner square.
10
But if player 2 plays this move as a winning move, then, after the move player 1
must still be in a losing position. But then player 1 could have played the same square
that player 2 did first instead of their original move. This would put player 2 in a losing situation since it would be in the same situation as player 1 was with the original
moves. But this means that player 1 can force player 2 into a losing situation - and
this means that player 1 must have been in a winning position all along! This means
that no matter what, player 1 will have a winning strategy.
11
Download PDF