Combinatorial Game Theory

We are in the framework of games with perfect information. [add]

As a guiding example we consider the game of Nim, or to be more precise 3-Nim. We have three heaps of objects (say coins) and two players. On each turn, a player has to remove a positive number of coins from one heap. If a player is not able to move (that is, there is no coin left), that player loses and the other one wins.

There are two things to notice here. On one hand, the formulation given here is not equivalent to saying that the last one to pick is the winner, since we want to be able to consider the case (0,0,0). On the other hand, there are several variants of Nim, including one where the one left with the last coin is the one who loses.

As already hinted in the previous paragraph, there is a nice representation of each turn of the game, as a vector in \mathbb{N}^3. Also, notice that each move decreases the sum of the components, so we know that the game ends, and we also know that one of the two has to lose (and one has to win, no ties are possible).

Question: is it possible, given the initial state (n_1,n_2,n_3), to determine if a player has a winning strategy and, in case, which is this strategy?

We can start with some examples: (0,0,0) is clearly a losing state for the player about to take its turn. Similarly, (1,0,0) (as well as rearrangements: states are always equivalent under permutations) and in general (n,0,0) for n>0 is a winning state for the player about to move. Notice moreover that with (1,0,0) the player cannot lose, even if they wanted, whereas with (n,0,0) with n>1 the player has to play well not to lose. But we assume that both players are rational and play their best strategy. Moving on, (1,1,0) is clearly losing for the player about to move, as is any (n,n,0) state with n>0, while (n,1,0) il winning for the player about to move, as is (1,1,1).

Proceeding by examples, we cannot really find a general strategy, so let’s try a different approach. In particular, since each move can be on a single heap/coordinate, we can consider the 3-heap game as a combination of three different games, each with a single pile. This opens up an interesting perspective but requires us to formally state what we mean by “combination” of multiple games. Given two games G_1 and G_2, their sum G_1\oplus G_2 is a game in which at each turn the player can decide whether to move in the game G_1 or in the game G_2. In particular, we can see the 3-Nim as a sum of three 1-Nims, each corresponding to a column.

In order to harness what we have defined (that is, an operation), we want to associate to every (Nim) game a number, called nimber. We proceed in the following way. The Nim game (0) has nimber 0. Given a game, we list all the possible moves (each of these provides a different game, with less coins) and we list all the corresponding nimber; the nimber of the game we started with is the smallest nimber not in the list.

If we consider only games of 1-Nim, nimbers are quite boring: they are just the number of coins in the heap. However, things start to be interesting when we move to k-Nims with k>1. Take for example the 2-Nim game (1,1). There is only one move possible (up to the choice of the heap): remove one coin and be left with the game (1,0). This game is the same as the game (1), so it has nimber equal to 1. Hence the nimber of (1,1), that is the smallest nimber not on the list, is 0.

How is this related to the sum of Nim games? Well, we can see that the nimber of the Nim sum of two games as the Nim sum of the nimbers of the two games. For example: \mathop{nim}(1,0)=\mathop{nim}(1)\circleplus\mathop{nim}(0)=1. Also, as seen earlier, \mathop{nim}(1,1)=\mathop{nim}(1)\circleplus\mathop{nim}(1)=0. We can construct the table of the Nim sum of nimbers:

The Nim sum table for the first 8 nimbers

How do we fill this table? Since n\oplus m is the nimber of the 2-Nim (n,m), we can use the definition, and look at all possible moves in that game. What are these moves? We can reduce the number of coins in one of the two heaps (but not both), so we are moving either up along the column or left along the row. The nimber we have to write at the intersection of the row labelled m and column labelled n is the smallest that does not show up neither in the leftmost n cells of the (m+1)-th row nor in the first m cells from above in the (n+1)-th column.

This operation might look familiar: it can be written in a different way as the logical XOR of the nimbers written in binary. For example 5\oplus 3=101 \mathop{XOR} 011=110=6.

Notice that we have defined the operation for two games, but since the sum of two games has a nimber and can be considered equivalent to the 1-Nim with that nimber, we can go on and sum an additional game, and so on. We can also check that the operation is commutative and associative.

Now we can finally go back to the problem we had: which player has a winning strategy? We can now state the answer as a theorem.

Theorem: A Nim game is losing for the first player if and only if its nimber is 0.

To prove this result, we can go through two lemmas.

Lemma: If the nimber of a Nim game is 0 before a move, any legal move will result in a Nim game with nimber greater than 0.

Remember that any move takes us either left or up from where we are. We can be in a 0 only if there are no zeros left or up, because of the way we defined the nim sum.

Lemma: If the nimber of a Nim game is greater than 0 before a move, there exists always a move that will result in a Nim game with nimber 0.

This is specular to the previous one: if we were not able to put a 0 in the intersection of row and column, it means that there is at least a zero, either up or left.

The two lemmas give us not only the theorem, but they also tell us the winning strategy (if possible): always end your move on a 0, so that the other player has no winning move.

As a nice aside, we can also define a product between nimbers, the Nim product \odot. The Nim product n\odot m of two nimbers is the smallest nimber that is not in the list

    \[\tilde{n}\odot m\oplus n\odot \tilde{m}\oplus \tilde{n}\odot \tilde{m}, \quad \tilde{n}<n, \tilde{m}<m.\]

The construction of the table of \odot for the nimbers smaller than 8 is a nice exercise.