IMPARTIAL GAMES

KENNETH MAPLES

In the theory of zero-sum and general-sum games, we studied games where each player made their moves simultaneously. Equivalently, we can think of the moves of the alternate player as hidden until both have made their decision. In this part of the course, we will instead consider games that have complete information; that is, both players know the entire state of the game. This means that players move sequentially and there are no unknown or random factors in the game. We will first consider the theory of impartial games. An impartial game is one where two players move alternately according to a set of rules. If either player has no available moves when it is her turn, that player loses. We also require that both players have the same set of moves from a position. The theory of game of complete information where the players have different sets of moves available is called the theory of partizan games, which we will cover in the next week of the course. For our analysis the following definition is very convenient. Definition. An impartial game is a set. We will call the elements of a game A the options of the game, where they represent the resulting game after the move. Thus the game {}, denoting the empty set, is a game where the player-to-move loses, and the game {{}}, denoting a set containing the empty set, is a game where the player-to-move wins (as after her move, teh opponent is given a losing game). We will call any element A1 ∋ ⋅ ⋅ ⋅ ∋ A of a finite sequence of options to be a position of the game. Equivalently, positions are games that are reachable in a finite number of moves from the given game. We will use the notion of set from the Zermelo-Fraenkel (ZF) theory. In particular, our games will obey the axiom of regularity which says that for every non-empty game A, there is an option B of A that is disjoint from A. This in particular implies that no option of a game is the game itself; i.e. there is no passing, and that there is not an infinite sequence of options A1 ∋ A2 ∋ A3 ∋ ⋅ ⋅ ⋅ that does not terminate. We would like our games to end!

1. Subtraction games and N/P positions The first type of game we will consider is the . In this game, we have a pile of n stones where players alternate removing stones

Date: 6/28/11. 1 2 KENNETH MAPLES from the pile. A legal move removes a number of stones that lies in the set S, where S is some (possibly infinite) set of allowed moves. For example, we could have the game where n = 4 and S = {1, 2, 3}. Then the first player has the option of removing one, two, or three stones from the pile, leaving three, two, and one, respectively. Then the second player could eliminate the pile (as in all three cases, the number of remaining stones lies in S), which would leave the first player with the game {}, a losing game. Thus the second player wins in each case. To make later analysis easier, we define a P-position to be one where the previous player has a winning strategy (or, if it is the first move of the game, the second player), and we define an N-position to be one where the next player has a winning strategy. Our theory of impartial games lets us cleanly split games into P-positions and N-positions. We first observe that we can deduce whether a game is an N-position or a P-position if we know whether all of its options are N-positions or P-positions. Proposition. A game G is an N-position if one of its options is a P- positions. A game G is a P-position if all of its (possibly empty) options are N-positions. Proof. If a game has a P-position, a winning strategy for the first player is to choose the option that makes the game a P-position. Likewise, if all options available to the current player are N-positions, the second player has a winning strategy regardless of the current player’s choice. □ Note that {} is a P-position. Proposition. There is a unique labeling of the positions of a game into N-positions and P-positions. Proof. We know that {} is a P-position. For any game G, we can assume by induction and the axiom of regularity that it is known whether each of its options is an N-position or a P-position. But then Proposition 1 shows that the game must be either an N- or P-position. □ This is typical of the proofs we will employ: because we have an explicit hierarchy of games, we can prove statements for all games using induction. Now lets return to subtraction games. If we let (n) denote the subtrac- tion game on n stones with S = {2, 3, 4} (notice that S has changed!). Thus we have, for example, (7) = {(3), (4), (5)}. We can quickly compute which of (n) is N or P depending on the smaller values; see Table 1. Table 1 has a clear pattern: if n ≡ 0 or 1 mod 6 then (n) is a P-position, and otherwise it is an N-position. (Can you prove this?)

2. , , and sums of games We will now consider the classic game of nim. Nim is a game played with several heaps of stones. On any turn, a player may choose one heap IMPARTIAL GAMES 3

Table 1. Some N and P values in the subtraction game with S = {2, 3, 4}

(0) : P (6) : P (12) : P (1) : P (7) : P (13) : P (2) : N (8) : N (14) : N (3) : N (9) : N (15) : N (4) : N (10) : N (16) : N (5) : N (11) : N (17) : N and remove any number of stones from that heap, as long as she removes at least one. For example, if we have two heaps of size (3, 4), then the first player may remove 4 stones from the second heap and be left with one heap of size 3. This is not an advisable move: the opponent can immediately take all of the stones from the heap of size 3, and since there are no more stones remaining, the first player loses! In this section we will write (n1, ..., nk) to indicate a game of nim with k piles, where there are nj stones in the jth pile. We will have a much better notation by the end. In general, we define the sum of games G1 and G2 to be the game with options defined recursively by

G1 + G2 = {A1 + G2,G1 + A2}A1∈G1,A2∈G2

Equivalently, each player chooses one of the games G1 and G2 and makes a single move on that game. Thus we can think of the general nim game (n1, ..., nk) as the sum of subtraction games, where the jth game has nj stones and S = {0, 1, 2, ...} = ℕ. Before we can effectively analyze nim, we need to introduce new tools. We define the of a set of natural numbers to be the least natural number not contained in that set, i.e. mex(A) := min a ≥ 0 : a∈ / A. For example, mex(1, 2, 3) = 0 and mex(0, 1, 3) = 2. We can then define the Grundy value G to be a function on games that assigns to any game A the value G(A) := mex(G(B) ∣ B ∈ A) i.e. the mex of the options of A. This function is well-defined: we can assume that G is defined for all options of A by induction, whence the mex is well-defined. We can find the Grundy value of a nim game (n) (i.e. a single pile with n stones) quickly enough: we have (n) = {(0), (1), ..., (n − 1)}, since the first player may remove any number of stones from the pile, so by induction we have G((n)) = n. At this point is is convenient to define new notation: we will define a finite to be the Grundy value of a finite nim pile, and write ∗n for the value of the pile with n stones. We will also abbreviate 4 KENNETH MAPLES

∗0 = 0 and ∗1 = ∗. Thus we think of the Grundy value as being a nim pile and will henceforth always write Grundy values in the form ∗n. This is to prevent confusion when we introduce partizan games. Grundy values tell us whether a game is a win for the first or second player. Proposition. If A is a game with Grundy value G(A) = 0 then A is a P-position. If G(A) = ∗n for n ∕= 0 then A is a N-position. Proof. We proceed by induction. For the empty game we have G({}) = mex({}) = 0 which verifies the Proposition. For a general game, if A is an N-position then A has an option B which is a P-position. By induction, G(B) = 0 so G(A) = mex(∗0, ...) ∕= ∗0. Likewise, if A is a P-position then all of the options of A are N-positions, so by induction G(A) = mex(∗n1, n2, ...) where each nj ∕= 0, hence G(A) = ∗0. □ Nimbers have an addition operation, which we will denote by + but some- times by +∗. This is not the same as integer addition. Nimbers can be added using the following two rules. Proposition. Finite nimbers have an addition operation with identity 0 = ∗0 with the following two properties. (1) ∗n + ∗n = 0 for all n (i.e. nimbers have characteristic 2) (2) If n = 2k + m for some 2k > m, then ∗n = ∗(2k) + ∗m. This allows us to compute an arbitrary nim sum: decompose each sum- mand into a sum of (distinct!) powers of two, cancel equal powers in pairs, and rewrite the result. An example is in order: If we want to compute ∗53 + ∗13, we have ∗53 = ∗32 + ∗16 + ∗4 + ∗1 and ∗13 = ∗8 + ∗4 + ∗1 by rule 2, whence ∗53 + ∗13 = ∗32 + ∗16 + ∗4 + ∗1 + ∗8 + ∗4 + ∗1 = ∗32 + ∗16 = ∗48 by rule 1. Here are two applications of rule 1: ∗+∗+∗ = ∗, while ∗+∗+∗+∗ = ∗ + ∗ = 0. This addition operation is interesting because of the following relationship between sums of games and sums of nimbers. Theorem. If A and B are games, G(A + B) = G(A) +∗ G(B). Here we wrote +∗ to emphasize that we are thinking of Grundy values as nimbers. We can now solve nim by writing each nim pile as a nimber and computing their sum according to Proposition 2. For example, we can write (5, 4, 3) = ∗5 + ∗4 + ∗3 = (∗4 + ∗1) + ∗4 + (∗2 + ∗1) = ∗2. Furthermore, this tells us how to find our winning move: we need to play so that the resulting Grundy value of the sum is 0, so we should reduce 3 to 1 by removing two stones. IMPARTIAL GAMES 5

Table 2. Some Grundy values for the subtraction game with S = {2, 3, 4}

(0) : 0 (6) : 0 (12) : 0 (1) : 0 (7) : 0 (13) : 0 (2) : ∗ (8) : ∗ (14) : ∗ (3) : ∗ (9) : ∗ (15) : ∗ (4) : ∗2 (10) : ∗2 (16) : ∗2 (5) : ∗2 (11) : ∗2 (17) : ∗2

We can also analyze more general sums of games. If we compute the Grundy values of each of the component games in a sum, then the Grundy value of the sum can be computed using the nimber addition rules. Note that we will not always be able to decompose our games into nice sums of other games. In these cases, nimber values must be computed by hand from simpler positions using the mex rule. For example, Table 2 gives the Grundy values of the subtraction game with S = {2, 3, 4}. Here we computed the table using the mex rule: we have G((0)) = G((1)) = ∗0 because they are P-positions. We then can compute each of the other positions by knowing its constituent values; i.e. G((5)) = mex(G((1)), G((2)), G((3))) = ∗2.