Notes on Sprague

Notes on Sprague-Grundy theorem
Shuying Sun
A game is a two-player game of perfect information impartial game satisfying the ending
condition (all games come to an end: there are no infinite moves of play) and the normal
play condition (a player who cannot move loses). An impartial game is one in which each
player has exactly the same available moves as the other player in any position.
Theorem 1 (Sprague-Grundy Theorem). An impartial perfect information game (i.e. a
game which follows the normal play convention and ends at finite steps) is equivalent to
the Nimber Game.
What is a Nimber Game?
Define ∗0 = {}, and for any n ≥ 1, ∗n = ∗(n − 1) ∪ {∗(n − 1)}. In particular,
∗0 = {}
∗1 = {{}}
∗2 = { {}, {{}} }
∗3 = { {}, {{}}, { {}, {{}} } }
It is not hard to find that ∗n = {∗0, ∗1, · · · , ∗(n − 1)}. The rules of the Nimber Game, is
that you and your opponent are given some set ∗n, and both of you are allowed to move
to any of the element of this set, unless there is no element in this set. The last player who
cannot move loses. Therefore, if a player is given ∗m for some m > 0, then he or she could
move to ∗0 to make the other player cannot move anymore.
1
Claim 2. Any state of an impartial perfect information game falls into two outcome categories: either (F) the first player has a winning strategy or (S) the second player has a
winning strategy.
(It can be proved by induction on the longest number of moves to the end of the game)
Proof. Suppose the current state has already no valid move, then that is the end of the
game. So it belongs to (S).
Now suppose that for any state with at most k moves to the end of the game belongs to
either (F) or (S). For the state G with at most k + 1 moves to the end of the game, the first
player of G has several moves to substates G1 , · · · , Gn . And for any Gi , it has at most k
moves to the end of the game, by induction hypothesis, it is either (F) or (S). If some Gi is
(S), then the first player of G will become the second player of Gi , and he will win, which
means that G is (F). On the other hand, if all of Gi is (F), then no matter the first player
of G moves, the second player has winning strategy to win. So in this case, G is (S).
By using this classification, we can see that for the Nimber game,
Claim 3. ∗n is (F) ⇔ n 6= 0.
Definition 4. Let G and G0 be two states of some impartial games. G is said to be
congruent to G0 , denoted by G ∼
= G0 , if for any state of some impartial game H, (G, H)
and (G0 , H) belongs to the same outcome category.
Here (G, H) represents a state of a new impartial game, where you can either move
in G, or move in H, and the move in one game will not make any change to the state of
another game, the last player who could not move loses. In other words, you can view G
and H as two independent games, but you are allowed to make move in any of them.
Some properties of congruence:
1. If G ∼
= G0 and G0 ∼
= G00 , then G ∼
= G00 .
2. If G ∼
= G0 , then G and G0 belongs to the same outcome category.
Definition 5 (Map from any impartial game to Nimber Game). For any state G
of an impartial perfect information game, we define a map φ in the following recursive way
such that
1. If G has no moves, then φ(G) = ∗0.
2
2. If G1 , . . . , Gk are all the states by making one move from G, and suppose that φ(Gi ) =
∗ni , 1 ≤ i ≤ k, then φ(G) = ∗n where n is the smallest nonnegative integer such that
n 6= ni for any 1 ≤ i ≤ k.
Theorem 6. G ∼
= φ(G).
To prove Theorem 6, we need the following lemmas.
Lemma 7. If A is (S), then (G, A) ∼
= G for any G.
Proof. We will show that for any H, (G, H) and ((G, A), H) belongs to the same outcome
category.
If (G, H) is (S), then the second player has a winning strategy for (G, H). Consider the
game ((G, A), H) which is the same as (A, (G, H)). If the first player moves in A, then
the second player can move according to the winning strategy of A (since A is (S)). If the
first player now switch the move to (G, H), then the second player can move according
to the winning strategy of (G, H) (since (G, H) is (S)). In this way, the second player of
(A, (G, H)) is always the second player of A and the second player of (G, H). Therefore,
((G, A), H) is (S).
If (G, H) is (F), then the first player has a winning strategy for (G, H). Consider the game
(A, (G, H)). The first player moves in (G, H) according to the winning strategy of (G, H)
(since (G, H) is (F)), and does not change game unless the second player switches to the
game A. And when the second player switches to the game A, then the first player will
also switch to the game A, and moves according to the winning strategy of A (since A is
(S)). In this way, the first player of (A, (G, H)) is always the first player of (G, H) and the
second player of the game A. Therefore, ((G, A), H) is (F).
Remark 8. In the winning strategies of the game ((G, A), H) = (A, (G, H) described above,
the winner always sticks to the game the other player chose.
Lemma 9. G ∼
= G0 if and only if (G, G0 ) is (S).
Proof. First, we claim that for any G, (G, G) is (S). Indeed, as long as the first player can
move in (G, G), the second player can always mimic the move of the first player and moves
to (G0 , G0 ) no matter the first player moves (G, G) to (G, G0 ) or (G0 , G).
If G ∼
= G0 , then by choosing H = G, we have (G, G) has the same outcome category as
0
(G , G). Therefore, (G0 , G) is (S).
Now suppose that (G, G0 ) is (S). By Lemma 7, we have,
(G, H) ∼
= ((G, H), (G, G0 )) = ((G0 , H), (G, G)) ∼
= (G0 , H),
for any H.
Now we are ready to prove Theorem 6.
3
Proof of Theorem 6. We will prove it by induction on the maximum number of moves
from G to the end of the game. If G has no valid moves, by definition, φ(G) = ∗0. And
it is obvious that G ∼
= ∗0. Now suppose that G1 , . . . , Gk are all the states by making one
move from G. By inductive hypothesis, we have
G1 ∼
= ∗n1 , · · · , Gk ∼
= ∗nk .
By definition, we have φ(G) = ∗n where n is the smallest nonnegative integer such that
n 6= ni for any 1 ≤ i ≤ k.
First consider the game state G0 whose valid next states are ∗n1 , · · · , ∗nk . We will show
that G ∼
= G0 . Indeed, consider the game state (G, G0 ),
1. If the first player moves in G to the next state Gi , then the second player could move
in G0 to ∗ni . Then the state is (Gi , ∗ni ).
2. If the first player moves in G0 to some ∗ni , then the second player could move in G
to Gi . Then the state is (Gi , ∗ni ).
In either case, after two moves, we are at the state (Gi , ∗ni ). Since Gi ∼
= ∗ni , we have
0
0
∼
(Gi , ∗ni ) is (S) by Lemma 9. Therefore (G, G ) is (S) and hence, G = G again by Lemma
9.
Next, we will show that (G0 , ∗n) is (S). Suppose if n = 0, then ni > 0 for any 1 ≤ i ≤ k.
The first player of (G0 , ∗n) could only move in G0 to some ∗ni which makes the current
state (∗ni , ∗0), and then the second player could move to (∗0, ∗0), which is the end of the
game. If n 6= 0, we have the following two cases,
1. If the first player of (G0 , ∗n) moves ∗n to some ∗n0 with n0 < n. Since n is the
smallest number which is not n1 , · · · , nk , it follows that n0 must be equal to some
ni . Now the second player could move in G0 to ∗ni , which makes the current state
(∗ni , ∗n0 ) = (∗ni , ∗ni ) which is (S).
2. If the first player of (G0 , ∗n) moves in G0 to some ∗ni , then the current state is
(∗ni , ∗n). By definition, n 6= ni . Now the second player could move ∗n to ∗ni if
n > ni , or move ∗ni to ∗n if n < ni , which makes the current state either (∗ni , ∗ni )
(which is (S)) or (∗n, ∗n) (which is also (S)).
So we have proved that in either case (G0 , ∗n) is (S), which implies that G0 ∼
= ∗n by Lemma
9. Since G0 ∼
= G, it follows that G ∼
= ∗n. This completes the proof of Theorem 6.
The following corollary is an immediate consequence of Theorem 6.
Corollary 10. If G ∼
= G0 , then φ(G) = φ(G0 ).
4
We also have the following useful corollary.
Corollary 11. (G, G0 ) ∼
= (φ(G), φ(G0 )).
Proof. By Theorem 6, we have G ∼
= φ(G) and G0 ∼
= φ(G0 ). By Lemma 9, we have (G, φ(G))
and (G0 , φ(G0 )) are (S). Therefore,
(G, G0 ) ∼
= ((G, G0 ), (G, φ(G)))
by Lemma 7
0
= ((G , φ(G)), (G, G))
∼
= (G0 , φ(G))
∼
= ((G0 , φ(G)), (G0 , φ(G0 )))
0
0
by Lemma 7 and the fact that (G, G) is (S)
by Lemma 7
0
= ((φ(G), φ(G )), (G , G ))
∼
= (φ(G), φ(G0 )).
by Lemma 7 and the fact that (G0 , G0 ) is (S)
By Corollary 11, we know that (G, G0 ) ∼
= (φ(G), φ(G0 )). A natural question is: what is
(∗n1 , ∗n2 ), and how can we determine (∗n1 , ∗n2 ) is (S) or (F)? The next theorem answers
this question.
Theorem 12. (∗n1 , ∗n2 ) ∼
= ∗(n1 ∧ n2 ). Furthermore, (∗n1 , ∗n2 ) is (F) if and only if
n1 ∧ n2 6= 0.
Remark 13. Here n1 ∧ n2 is the binary XOR. For example, n1 = 3 and n2 = 4, then in
binary representation, n1 is 112 , and n2 is 1002 , therefore, n1 ∧ n2 is 1112 = 7.
To prove Theorem 12, we need the following lemma.
Lemma 14. (∗x1 , ∗x2 , · · · , ∗xn ) is (F) if and only if x1 ∧ x2 ∧ · · · ∧ xn 6= 0.
Proof. We could prove it by induction on the maximum number of moves to the end of the
game. If there is no move already, then x1 = x2 = · · · = xn = 0 and it is (S). Now suppose
that there are valid moves for (∗x1 , . . . , ∗xn ), and let (∗y1 , ∗y2 , · · · , ∗yn ) be the state after
the first move, where yk < xk and yj = xj for j 6= k. Let s = x1 ∧ x2 ∧ · · · ∧ xn , and
t = y1 ∧ y2 ∧ · · · ∧ yn . Then the following holds,
t=0∧t
=s∧s∧t
= s ∧ (x1 ∧ · · · ∧ xn ) ∧ (y1 ∧ · · · ∧ yn )
= s ∧ (x1 ∧ y1 ) ∧ · · · ∧ (xn ∧ yn )
= s ∧ 0 ∧ · · · ∧ 0 ∧ xk ∧ yk ∧ 0 · · · ∧ 0
= s ∧ xk ∧ yk .
5
If s = 0, then t = xk ∧ yk 6= 0 since xk > yk . Hence the state (∗y1 , ∗y2 , · · · , ∗yn ) is (F)
by the inductive hypothesis. Therefore, the second player have a winning strategy if s = 0.
Now suppose that s 6= 0. If the first player could make a move such that t = 0, then
the state (∗y1 , ∗y2 , · · · , ∗yn ) is (S) by the inductive hypothesis, and hence the first player
has a winning strategy. Indeed, there is such move for the first player which makes t = 0,
and it is chosen as follows:
Let d be the position of the leftmost nonzero bit in the binary representation of s,
choose k such that the d-th bit of xk is also nonzero (such k exists since the d-th digit of
s is nonzero). Let yk = xk ∧ s. Since the digits whose positions are left of d in s are zero
and the d-th digit of yk is 0, we have yk < xk .
Proof of Theorem 12. Since n1 ∧ n2 ∧ (n1 ∧ n2 ) = 0, we have (∗n1 , ∗n2 , ∗(n1 ∧ n2 )) is
(S) by Lemma 14. Therefore by Lemma 9, we have (∗n1 , ∗n2 ) ∼
= ∗(n1 ∧ n2 ). It completes
the proof of Theorem 12.
As a consequence of Corollary 10, Corollary 11, Theorem 12 and Lemma 14, we have
the following,
Corollary 15. φ((G1 , G2 , · · · , Gk )) = ∗(n1 ∧ n2 ∧ · · · ∧ nk ), where φ(Gi ) = ∗ni for any
1 ≤ i ≤ k. Furthermore, (G1 , G2 , · · · , Gk ) is (F) if and only if n1 ∧ · · · ∧ nk 6= 0.
6