Document directory
- Sums of games
- The SD-Grundy Function
- The game of Nim
- Games that decompose into sums of themselves
AnImpartial gameIs a two-player game in which both players have complete information, no chance is involved, and the legal moves from each position are the same for both players. We will deal withNormal playRule, in which the last player to move is the winner.
An impartial game can be named actly represented byDirected Acyclic Graph, In which each vertex corresponds to a position, and each directed edge represents a legal move from one position to another.
We can imagine that a token is initially placed on some vertex, and the two players take turns moving the token from its current vertex to one of its direct followers. the game ends when the token reachesSink, Which is a vertex with no outgoing edges, and then the last player to have moved is the winner.
P-And
N-Positions
We can classify each position in the game according to whether it is a first-or a second-player win, if both players play optimally starting from that position. A first-player-win position is known asN-Position(BecauseNEXT player is to win), while a second-player-win position is known asP-Position(BecausePRevious player is to win ).
TheP-AndN-Positions can be characterized inductively as follows:
- A vertexVIsP-Position if and only if all its direct followers areN-Positions.
- A vertexVIsN-Position if and only if it has someP-Position follower.
The induction starts at the sinks, which areP-Positions because they vacuously satisfyP-Position requirement.
Knowledge ofP-AndN-Positions of a game provides the winning strategy for it: if it is our turn and the game is inN-Position, we shoshould move intoP-Position. Then our opponent will be forced to move intoN-Position, and so on. Eventually we will move into a sink and win.
Sums of games
IfG1 andG2 are impartial games, then theirSum G1 +G2 is another impartial game, which is played as follows: On each turn, a player chooses oneG1,G2 (whichever he wants) and plays on it, leaving the other game untouched. The game ends when no moves are possible onG1 nor onG2.
Formally, ifG1 = (V1,E1) andG2 = (V2,E2) are game-graphs, then their sumGSum = (VSum,ESum) is given:
VSum =V1 ×V2,
ESum = {(V1V2,W1V2) | (V1,W1)E1} else {(V1V2,V1W2) | (V2,W2)E2 }.
Now, suppose we are given two gamesG1 andG2. Can we correctly play their sumG1 +G2 If we just knowP-AndN-Positions of the individual games? It turns out that the answer is no. It is not hard to see that the sum of twoP-Positions is alwaysP-Position, and the sum ofP-Position andN-Position is alwaysN-Position. But the sum of twoN-Positions can either beP-OrN-Position. Therefore, just knowingP-AndN-Positions of the individual games is not enough.
To play sums of games correctly we need a generalization of the notionP-AndN-Positions, which is known asSD-Grundy Function(OrGrundy FunctionFor short ).
The SD-Grundy Function
LetN= {0, 1, 2, 3 ,...} be the set of natural numbers. the SD-Grundy function assigns to each position in a game a natural number. the Grundy value of a vertexVEquals the smallest natural number that does not appear among the Grundy valuesV'S direct followers.
Formally: Given a finite subsetSBytesN, Let MEXS(Minimum excluded Value) Be the smallest natural number not inS:
MEXS= Min (N/S).
Now, given a game-graphG= (V,E), Its SD-Grundy FunctionG:V→NIs defined inductively
G(V) = Mex {G(W) | (V,W)E}.
This induction starts at the sinksG, Which receive a Grundy value of 0.
The SD-Grundy function satisfies two important properties:
- A vertexVIsP-Position if and only ifG(V) = 0.
- IfG=G1 +G2 andV=V1V2 is a position inG, ThenG(V) Is the bitwise XOR of the binary representationsG(V1) andG(V2 ):
G(V) =G(V1) beginG(V2 ).
The operation is also calledNim sum. For example, 3 rows 5 = 0112 rows 1012 = 1102 = 6. Similarly, 3 rows 6 = 5 and 5 rows 6 = 3.
It is not hard to prove the above two properties by induction.
From these properties it follows thatV=V1V2 is a P-position if and only ifG(V1) = g (V2), since this is the only way the NIM sum can come out 0.
Clearly, the sum of games is a commutative and associative operation, as is the NIM sum operation. therefore, we can correctly play the sum of any number of games by knowing the Grundy function of each individual game.
Our strategy is as follows: if it is our turn and the games 'grundy values give a nonzero Nim-sum, then there must exist a move in some component game that causes the NIM sum to become 0. we shoshould make that move, and then our opponent will be forced to make the NIM sum nonzero again. eventually, we will be the ones to make the last move in the last game, bringing the NIM sum to 0 for the final time.
The game of Nim
The most fundamental impartial game isNim Pile. A Nim pile consists of a certain number of tokens. on each turn, a player removes from the pile any number of tokens between one token and the entire pile. the player who empties the pile wins.
This game by itself is of course trivial: the first player can just take all the tokens and win immediately! But if we add together Nim piles of various sizes, we get the famous gameNim.
The Grundy value of a nim pile of sizeNIsN. Therefore, the Grundy value of a position in Nim is the NIM sum of its pile sizes.
Games that decompose into sums of themselves
The most natural application of the SD-Grundy theory is for games that naturally decompose into sums of themselves.
Consider the following game: There is a checkerboard of sizeM×N, And there is an unlimited supply of polyominoes of a certain shape. on each turn, a player places a polyomino on an empty place on the board, and the player who cannot make a move is the loser:
During the course of the game, the Board will gradually split into separate regions, for which we can calculate their Grundy values independently:
For another example considerGrundy's game. A position in this game consists of a number of piles of tokens of various sizes, and a move consists of taking one pile and splitting it into two unequal piles. the game ends when there are only piles of sizes 1 and 2 left, which cannot be split further.
LetG(N) Be the Grundy value of a single pile of sizeN. The sequenceG(N) Starts as follows:
N: |
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
... |
G(N): |
0 |
0 |
1 |
0 |
2 |
1 |
0 |
2 |
1 |
0 |
2 |
1 |
3 |
2 |
1 |
3 |
2 |
4 |
3 |
0 |
Although these values have been calculated to aroundN= 235, this sequence is still not completely understood. it is possible that the sequence will eventually become periodic, although this has not been seen to happen yet. see the following page by Achim flammenkamp for more information.
The theory of impartial Games was discovered independently by Roland P. SD in 1936 and P. M. Grundy in 1939.