Download as pdf or txt
Download as pdf or txt
You are on page 1of 25

Submitted for the Degree of MEng in

Computer Science, 2017-2018

Combinatorial Games
STEI01

”Except where explicitly stated all the work in this


report, including appendices, is my own and was
carried out during my 4th year. It has not been
submitted for assessment in any other context.”

Disclaimer: ”I agree to this material being made available in whole or in


part to benefit the education of future students.”

Signature: Q. Legˆnthc

By Christos Legantis
Registration Number: 201415575
April 2, 2018
Contents

1 Abstract . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 4
3 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1 Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.2 Outcomes . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.3 Report Structure . . . . . . . . . . . . . . . . . . . . . . . 5
4 Related Work . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
5 Problem Description and Specification . . . . . . . . . . . 7
5.1 Problem Description . . . . . . . . . . . . . . . . . . . . . 7
5.2 Games’ Description . . . . . . . . . . . . . . . . . . . . . . 7
5.2.1. Grundy’s Game . . . . . . . . . . . . . . . . . . . . 7
5.2.2. Differences Game . . . . . . . . . . . . . . . . . . . 7
5.2.3. RemoveDigits Game . . . . . . . . . . . . . . . . . 7
5.2.4. MoveAnyMatches Game . . . . . . . . . . . . . . . 7
5.3 Requirements . . . . . . . . . . . . . . . . . . . . . . . . . 8
6 System Design . . . . . . . . . . . . . . . . . . . . . . . . . . 9
7 Detailed Design and Implementation . . . . . . . . . . . . 10
7.1 Grundy’s Game . . . . . . . . . . . . . . . . . . . . . . . . 10
7.2 Differences Game . . . . . . . . . . . . . . . . . . . . . . . 10
7.3 RemoveDigits Game . . . . . . . . . . . . . . . . . . . . . . 11
7.4 MoveAnyMatches Game . . . . . . . . . . . . . . . . . . . 11
8 Results and Evaluation . . . . . . . . . . . . . . . . . . . . . 12
8.1 Grundy’s Game . . . . . . . . . . . . . . . . . . . . . . . . 12
8.1.1. Results . . . . . . . . . . . . . . . . . . . . . . . . . 12
8.1.2. Analysis . . . . . . . . . . . . . . . . . . . . . . . . 12
8.2 Differences Game . . . . . . . . . . . . . . . . . . . . . . . 12
8.2.1. Results . . . . . . . . . . . . . . . . . . . . . . . . . 12
8.2.2. Analysis . . . . . . . . . . . . . . . . . . . . . . . . 13
8.3 RemoveDigits Game . . . . . . . . . . . . . . . . . . . . . . 15
8.3.1. Results . . . . . . . . . . . . . . . . . . . . . . . . . 15
8.3.2. Analysis . . . . . . . . . . . . . . . . . . . . . . . . 16
8.4 MoveAnyMatches Game . . . . . . . . . . . . . . . . . . . 16
8.4.1. Results . . . . . . . . . . . . . . . . . . . . . . . . . 16
8.4.2. Analysis . . . . . . . . . . . . . . . . . . . . . . . . 17
9 Verification and Validation . . . . . . . . . . . . . . . . . . 22
10 Summary and Conclusions . . . . . . . . . . . . . . . . . . 23
10.1 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
10.2 Future Work . . . . . . . . . . . . . . . . . . . . . . . . . 23
10.3 Conclusion . . . . . . . . . . . . . . . . . . . . . . . . . . 23
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
1. Abstract
COMBINATORIAL GAMES

CHRISTOS LEGANTIS

Abstract. Combinatorial game theory, a study field of mathe-


matics and theoretical computer science, typically studies combi-
natorial games. This paper is about implementing and analysing
various known and unknown impartial combinatorial games. These
are the finite games where two players alternate turns, have per-
fect information, chance is not involved and all the possible moves
from any position of the game are the same for all players. A gen-
eral algorithm is used to generate a value for each position of the
game. These values are then examined to analyse the different game
states, to identify the game’s winning and losing positions and to
discover any possible winning strategies to be followed.
2. Acknowledgements

I am very grateful to my supervisor, Prof. Einar Steingrı́msson, for his in-


valuable support and guidance throughout the course of this project. His
many useful suggestions and frequent constructive feedback have led to a
significant improvement of the presentation of this report. I would also like
to thank Dr. Sergey Kitaev for his valuable suggestions and feedback for
this project on poster day.

4
3. Introduction

3.1. Objectives.
The main aims of this project were to get familiar with impartial (or sym-
metric) combinatorial games, to implement and to mathematically analyse
some of them, known and unknown. There are games in the field of Combi-
natorial game theory that have been already mathematically analysed such
as the game of Nim. However, there are still games that either have not
been mathematically analysed fully yet or they remain unsolved. Some un-
known games, which will be described in detail later in the report, have been
mathematically analysed for this project.
As described in the initial Project scope and Outline plan document, there
were smaller tasks/objectives that had to be met so as to be able to achieve
the main objectives of the project. These were:
• Understand how the general algorithm works and how it can be
applied in different games.
• Implement the general algorithm in an elegant and efficient way to
return correct results fast for big values.
• Choose and implement games from a given list of unknown games
and try to adjust the algorithm to fit the games chosen.
• Explore and find more about the various games by observing the
results of my programs and come up with strict mathematical proofs
of any facts/patterns observed.

3.2. Outcomes.
During the course of this project, fully functional piece of software that gen-
erates all values of positions of a known impartial game and three unknown
games have been implemented. Additionally, strict mathematical proofs have
been written to justify any interesting facts/patterns discovered from the
positions’ values generated from my programs.

3.3. Report Structure.


In the following chapters of this report the methods and processes followed
during the project will be discussed. A reference to any related work that has
been already done around impartial combinatorial games will be introduced.
Then, a description for each game implemented will be given as well as any
interesting facts/patterns will be reported and mathematically proved. More
details about the implementation of the games will follow. Finally, results
and findings are reviewed and conclusions are drawn.

5
4. Related Work

As the game of Nim is one of the most popular impartial combinatorial games
it is already implemented and can be found online in different websites such
as:
Archimedes Lab [1]:
Anyone can play the game of Nim online on the Archimedes Laboratory
website. It is implemented a bit differently as the one who picks the last
match loses the game.
Goobix Online Games [2]:
The game of Nim can also be played online on the Goobix website. This is
an implementation of normal play of the game, the player who picks the last
match wins the game.
Cut-The-Knot [3]:
It is an educational website, which deals with different mathematical puzzles
and games. More specifically, in addition to other games it includes many
combinatorial games, some of them being the game of Nim and Grundy’s
game. The games are explained analytically and can be played on the web-
site.
Also, there is some related work in terms of analysing some impartial com-
binatorial games:
Combinatorial Game Theory by Aaron N. Siegel [4]:
In this book a lot of known impartial games such as Nim, Wythoff’s game
and Grundy’s game are analysed. Additionally, it includes the fundamentals
of Combinatorial game theory.
Games of No Chance by Richard J. Nowakowski [5]:
This series of books deals with combinatorial games, gives more informa-
tion and analyses different impartial games. Also, it talks about unsolved
problems in the category of combinatorial games.
Regarding the novel games analysed in this project, there is no related work
specified to these as they are unknown.

6
5. Problem Description and Specification

5.1. Problem Description.


As briefly described in the introduction, this project deals with various im-
partial combinatorial games, known and unknown. The aim is to implement
software that generates values for every position of the games. Then, use
this data for experimental purposes; observe any interesting facts/patterns
of the results and try to prove them with rigorous mathematical proofs.

5.2. Games’ Description.


A full description of the games to be researched and implemented for this
project will follow in this section of the report.

5.2.1. Grundy’s Game.


Grundy’s game is a very well-known breaking game where the only valid
move is to split a single pile of objects into two piles of different sizes.
The two players take turns splitting single piles into two of different sizes.
Eventually, all the piles will have size of 1 or 2 objects, which can not be
split any further. In normal play, the player who splits the last pile making
the last valid move is the winner of the game.

5.2.2. Differences Game.


Differences Game is an unknown impartial game. It starts with two piles of
different sizes. A player can either remove the size of the smaller pile from the
bigger one or remove the difference of the two piles from the smaller one (if
the difference is at most that big). The two players take turns making valid
moves. Eventually, the two piles will become equal at some point meaning
the end of the game, as there will be no further valid moves to be done. The
player making the last valid move is the winner of the game.

5.2.3. RemoveDigits Game.


RemoveDigits Game is an unknown impartial subtraction game. It is played
with a single pile of objects. A player can remove from the pile a number
of objects, which is twice the value of any non-zero digits of the pile size. If
the doubled value of a digit is bigger than the pile size then the player can
remove all the objects of the pile. The two players take turns making valid
moves. The game ends when there is no object left in the pile. The player
making the last valid move wins the game.

5.2.4. MoveAnyMatches Game.


MoveAnyMatches Game is another unknown impartial game. It can be
played with any number of piles. A player can move any number of ob-
jects from a pile to a strictly larger pile. The two players take turns making
valid moves. The game ends when all piles are equal or there is only one pile
left in the game and thus there is no further move to be made at this point.
As in the previous games, the player making the last valid move wins the
game.
7
5.3. Requirements.
The predefined requirements for this project include the use of a generic
algorithm in order to generate values mapped to each position of every im-
partial game. Software which incorporates this algorithm should be imple-
mented for each of the games described above. Most importantly, the results
should be analysed and any interesting facts should be justified with strict
mathematical proofs.

8
6. System Design

In terms of software, four autonomous helping Java classes have been im-
plemented, one for each game. These generate values for all positions of the
games to help me identify any facts/patterns of the results and in this way
assist my research.
This is an experimental project and as such there is no big system im-
plemented. As aforementioned, a few programs have been constructed to
compute values in the games studied.

9
7. Detailed Design and Implementation

In this section of the report a detailed description of how the games were
implemented will be given.
All four games have a common factor that is taken into account in order to
generate values of all positions. As the Sprague-Grundy theorem states all
impartial games in normal play are equivalent to nimbers, which are the val-
ues of nim piles in the game of Nim.[6][7] Thus, pile sizes in the games should
be mapped to equivalent nim pile sizes. In order to find the value-nimber
of the positions of the games a method called ”minimal excludent”(mex)
is introduced. Mex gets a subset of the values of the positions that can be
reached in a single move from a given position and returns the smallest value
that does not belong to the subset. The value returned is the value of the
position.

7.1. Grundy’s Game.


In order to be able to generate Grundy’s values for all pile sizes, firstly the
base cases of the game had to be identified. For piles up to 2 the game cannot
be continued any further as the pile cannot be split into two piles of different
sizes. Thus, positions 0, 1 and 2 are final/losing positions with a value of 0.
In the code a collection named values is introduced to keep all the Grundy’s
values and the values for positions 0-2 are added to it. Then, for every pile
greater than 2 a collection of booleans named seen is introduced, which will
hold the values of the next possible positions in a move from each position.
In order to find the values of the next possible moves, I xor (exclusive or)
the previously calculated values of piles that the possible positions consist
of. The seen collection is set to true for each value of the possible positions
seen in a move with index the value seen. In the end, the mex() method is
implemented, which calculates and returns the value of the exact position.
The way it works is: it takes the seen collection as a parameter, goes through
it and finds the first element where seen is false. The index of this element
is the minimal excludent and thus the value of the actual position. For each
pile size greater than 2 the mex(seen) method which returns the value of the
position is called in order to populate the values collection with all values.

7.2. Differences Game.


In order to generate the values for all positions of the game first of all a max-
imum size for the two piles of the game is given as well as a 2-dimensional
collection named values which will hold the values of all positions is created.
Then, for each position a collection of booleans named seen which will hold
the values of the next possible positions after one move is introduced. To get
the values of the next possible moves the method checkPosition() is called,
which takes the two pile sizes k and n and the collection seen as parame-
ters and checks if any of the two moves of the game can be done from the
position given. In this method a copy of k and n is created so as to be able
to check if both moves are allowed from the specific position. If the move
is valid the seen collection with index the value of the valid move is set to
true. In this way, I can keep track of the values of the next possible positions
10
in a move. Then, as discussed above, the mex() method is implemented and
seen collection is passed to it in order to get the value of the actual posi-
tion back. This value is stored in the values collection at the correct index.
Finally, printPositionValues() method is called to print out all the values of
positions up to size-size.

7.3. RemoveDigits Game.


Firstly, to generate the values for all positions of the game a maximum num-
ber up to which we will calculate values for is given and a collection named
values with number positions which will hold the values of all positions is
created. Then, the findPositionValues() method is called. This method for
every number from 1 up to but not including number uses a collection of
booleans named seen, which will hold the values of the next possible po-
sitions after one move. Also, it calls a helping method getDigits(n), which
gets a number n as a parameter and a list of all the distinct digits of this
number from 1-9 is returned. By having all the unique non-zero digits of
the number a check if any of the moves of the game are possible from each
digit of the number can be done. If the move is valid the seen collection with
index the value of the valid move is set to true, as in the previous games.
The mex() method is implemented and the seen collection is passed to it
in order to get the value of the actual position back. This value is stored
in the values collection at the correct index. Finally, printPositionValues()
method is called to print out all the values of numbers up to number -1.

7.4. MoveAnyMatches Game.


For this game the implemented version generates values for up to four piles.
However, this can be easily changed to more piles by adding another dimen-
sion to the collection values that holds the values of the positions.
Firstly, a size is given, which is the maximum pile size the positions shown
can have. Also, a 4-dimensional collection values to store the values of the
positions is introduced. Then, the method generatePositions() is called. This
method uses for all positions a collection of booleans named seen, which will
hold the values of the next possible positions after one move. The seen
collection as well as the 4 piles are passed to checkPosition(); a check of
which moves are possible is done and the seen collection with index the
value of the valid move(s) is set to true. The mex() is implemented and
the seen collection is passed to it in order to get the value of the actual
position back. This value is stored in the values collection at the correct
index. Finally, the printPositionValues() method is called to print out all
the values of positions up to size-size-size-size.

11
8. Results and Evaluation

In this section of the report all the facts/patterns observed from the pro-
grams implemented will be listed and proved for each game. First, a de-
scription of the rules of the game will be given. A description of the results
generated and strict mathematical proofs of any facts observed will follow.
As stated before, impartial games in normal play are equivalent to the values
of nim piles in the game of Nim according to the Sprague-Grundy theorem.
Thus, pile sizes in the games are to be mapped to equivalent nim pile sizes.
In order to find these values of the positions of the games the ”minimal
excludent”(mex) method is used. Considering the results of the mex() func-
tion, a value of 0 indicates a losing position for the associated game, while
any positive value indicates a winning position.

8.1. Grundy’s Game.


Rules of the game: In this game the player can split a single pile into two
smaller ones of different sizes.

8.1.1. Results.
The program implemented to generate the values of each pile size can gen-
erate values for very big pile size such as 100.000 in seconds. Below, in table
1 the first 16 values generated by the program can be seen.

Pile Size 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Value 0 0 0 1 0 2 1 0 2 1 0 2 1 3 2 1 3

Table 1. Grundy’s game values up to pile size 16

8.1.2. Analysis.
Grundy’s game is a very well-known impartial combinatorial ”take and
break” game that has been analysed by a lot of mathematicians. Presently,
the first 235 values have been computed by the German mathematician
Achim Flammenkamp.[8] However, the question whether the sequence of the
Grundy’s values ever becomes periodic is still unanswered and it remains an
unsolved problem.[9] As the main purpose of this project is to research and
analyse unknown impartial games, which have never been analysed before,
no further analysis of the Grundy’s game has been carried out.

8.2. Differences Game.


Rules of the game: In this game the two possible moves that a player can
make are either a) remove the size of the smaller pile from the bigger pile or
b) remove the difference of the two piles from the smaller if the difference is
at most that big.

8.2.1. Results.
The program implemented generates the values of each position k:n of the
game in seconds. Below, in table 2 a sample of values up to position 10:10
generated by the program can be observed.
12
Piles k,n 1 2 3 4 5 6 7 8 9 10
1 0 1 0 1 0 1 0 1 0 1
2 1 0 2 1 0 0 1 1 0 0
3 0 2 0 2 1 1 0 0 0 1
4 1 1 2 0 0 2 1 1 1 0
5 0 0 1 0 0 1 1 0 1 1
6 1 0 1 2 1 0 0 2 2 1
7 0 1 0 1 1 0 0 1 0 1
8 1 1 0 1 0 2 1 0 2 0
9 0 0 0 1 1 2 0 2 0 1
10 1 0 1 0 1 1 1 0 1 0

Table 2. Differences game values sample up to position 10:10

In table 2, it can be seen that the diagonal is consisted of 0 values. It is


something expected as these are positions with the same pile size. Positions
with same pile sizes are final positions of the game as no further moves can
be done from this point.
In table 3 the values of positions 1:n are shown, which have an interesting
property that will be described and proved below.

1:n 1 2 3 4 5 6 7 8 9 10
1 0 1 0 1 0 1 0 1 0 1

Table 3. Differences game values sample of positions 1:n

8.2.2. Analysis.
Analysis for positions 1:n

We define three sets of positions as follows:


F : the positions where piles are equal.
L: the positions where n is odd.
W : the positions where n is even.
Positions with two piles of the same size are final positions and therefore
losing positions because there is no bigger or smaller pile and no move can
be made.
We now prove by induction that for 1:n positions when n is odd this is a
losing position and when n is even this is a winning position.
Theorem 8.1. Positions 1:n with odd n are in L and with even n are in
W.

Proof. Base cases:


For n = 1: position 1:1 is a final position because no moves can be made
and therefore is a losing position.
13
For n = 2: in position 1:2 there are two possible moves available; a) remove
the size of the smaller pile form the bigger and go to position 1:1, which is
a losing position since the pile sizes are the same b) remove their difference
from the smaller pile and go to 0:2, which is again a losing position since no
move is possible. Giving a losing position to the opponent is making 1:2 a
winning position.
Inductive hypothesis:
Assume that for all k < n, where n > 2:
• 1:k is a losing position if k is odd.
• 1:k is a winning position if k is even.
Inductive step:
For n > 2: in positions 1:n there will only be one move acceptable since
the difference of the two piles will always be bigger than 1, to remove the
size of the smaller pile from the bigger one; to move the game to position
1:(n − 1). Position 1:(n − 1) is covered by the above inductive hypothesis
since for k = n − 1: n − 1 < n, where n > 2.
According to our hypothesis for k = n − 1, n > 2:
• If (n−1) is odd, this makes the position 1:(n−1) a losing position. If
1:(n−1) is a losing position, then the position that leads to it (1 : n)
is a winning position. If (n − 1) is odd that means that n is even
and therefore a position 1:n with an even n is a winning position.
• If (n−1) is even, this makes the position 1:(n−1) a winning position.
If 1:(n − 1) is a winning position, then the position that leads to it
(1 : n) is a losing position. If (n − 1) is even that means that n is
odd and therefore a position 1:n with an odd n is a losing position.


Analysis for positions k:n

Theorem 8.2. The sequence of the values of positions k:n is periodic with
period 2k.

Proof. For k:n positions with different n we can analyse which moves are
possible:
For n > 2k: In position k:n the difference of the two piles (n − k) will always
be bigger than k if n > 2k. Thus, there is only one possible move; to remove
the size of the smaller pile from the bigger one and therefore to move the
game to position k:(n − k). The fact that there is only one possible move to
be made from this position means that the value of k:n must be less than
2. Namely, since there is only one position available, only one value arises.
If this value is 0 then the value of the original position is 1, otherwise it is
0. Thus, the value of position k:n where n > 2k, is either 0 or 1.
For n = 2k: In position k:2k there are two possible moves available; a)
remove the size of the smaller pile from the bigger (2k −k) and go to position
14
k:k, which is a final and losing position (and has value 0) since no move can
be made b) remove their difference from the smaller pile and go to position
0:2k, which is again a losing position since no move is possible and has a
value of 0. Thus, position k:2k will always be a winning position with a value
of 1 as it would always move the game to a position with value 0.
If n ≥ 3k this means that as mentioned above, there is only one possible
move to be made from position k:n since 3k > 2k; to move the game from
position k:n to k:(n − k). Since there is only one possible position, only one
value arises. If the value of position k:(n − k) is 0 that means that the value
of the original position k:n is 1. In the same way of thinking, since there is
only one possible move, if the value of k:(n − k) is 1, that means that the
value of the original position k:n should be 0.
For n ≥ 4k the value of position k:n will be either 0 or 1 and the value
of k:(n − k) will be the ”opposite” of the value of k:n as explained above.
The only acceptable move from k:(n − k) is to move the game to k:(n − 2k).
Again, depending on the value that k:(n − k) has, the value of k:(n − 2k) will
be the ”opposite” of it. However, the ”opposite” of the value of k:(n − k)
is the same as the value of k:n. Thus, the value of k:n equals the value of
k:(n − 2k).
As observed above, the values are the same every 2k. Therefore, this implies
that the pattern of the values of positions k:n is periodic with a period of
2k. 

The values of k:n for k < n < 2k could be 0, 1 or 2. This is because for this
range of n there are two possible moves to be made, since the difference of
the sizes of the two piles (n − k) is always smaller than the size of the small
pile. Thus, the two moves which are always possible from k:n are to move
the game to positions k:(n − k) and (2k − n):n. Every position of the game
has a value. The fact that the next possible moves are two, means that not
all the three values could be included in the set of values of the next possible
positions and that the smallest value not included will be the value of k:n.
Thus, a position with two possible moves can only have values 0, 1 or 2.

8.3. RemoveDigits Game.


Rules of the game: The possible moves that someone can make in this game
are either: a) subtract 2k from position n, where k is any of its non-zero
digits or b) subtract n if 2k > n.

8.3.1. Results.
The program implemented generates the values of each pile size. It can
generate values for very big pile sizes such as 100.000 in seconds. Below, in
table 4 the first 16 values generated by the program can be observed. In
table 5 there is an interesting property that will be discussed and tried to
be proved in the analysis of the game.
15
Pile Size 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
Value 0 1 1 1 1 1 1 1 1 1 0 0 2 2 0 0 2

Table 4. RemoveDigits values up to pile size 16

Pile Size 1 12 123 1234 12345 123456 1234567 12345678 123456789


Value 1 2 3 4 5 6 7 8 9

Table 5. Values of positions 123. . . k

8.3.2. Analysis.
Lemma 8.3. The maximum possible value of a position n is equal to the
number of different non-zero digits of n.

Proof. If n is a single digit from 1 to 9 there is only one possible move to


be made; to remove the number n and move to position 0 since 2k > n for
all single digit cases of n. The fact that there is only one possible move to
be made from these positions means that the value of position n must be
less than 2. If there is only one possible move, only one value arises. In this
specific case, all 1-digit n positions will have a value of 1 since they all can
only lead to position 0, which is a final position since no further move can
be done.
If n has d > 1 different digits then d different moves are possible, and the
resulting positions can have at most d different values. If these values are
0, 1, . . . , d − 1 then the original position has value d, but otherwise a smaller
value. 
Theorem 8.4. The maximum value of a position is 9. The smallest number
with value k is 123. . . k.

Proof. By Lemma 8.3, the maximum value of a position n is the number


of the different non-zero digits of n. As these distinct digits could be up to
9 (from 1 to 9 inclusive) the highest value of a position is 9. The smallest
number containing all the digits 1, 2, . . . , k is 123. . . k. It has been verified
by computer that the position 123. . . k does have value k for k = 1, 2, . . . , 9
and so is the least such number where value k appears. 

8.4. MoveAnyMatches Game.


Rules of the game: In this game there are any number of piles. A player can
move any number of matches from a pile to a strictly larger pile.

8.4.1. Results.
The program implemented generates values of positions for up to 4 piles and
it can be easily adjusted to generate values for positions with more piles, if
needed. In table 6, one can see the first values generated for positions with
2 piles in the game.
16
Piles k,n 1 2 3 4 5 6 7 8 9 10
1 0 1 1 1 1 1 1 1 1 1
2 0 2 2 2 2 2 2 2 2
3 0 3 3 3 3 3 3 3
4 0 4 4 4 4 4 4
5 0 5 5 5 5 5
6 0 6 6 6 6
7 0 7 7 7
8 0 8 8
9 0 9
10 0

Table 6. Game values for 2-pile positions up to 10-10

It can be easily observed that the values of 2-pile positions are the same as
the size of the smaller of the two piles of each 2-pile position. From a position
k-n with k < n, exactly k moves can be made. The possible positions after
a move are on the right diagonal of the specific position in table 6. Thus, all
possible next positions include all values up to but not including k, making k
the smallest value not included in the set of the next possible moves’ values
and therefore the actual value of the position.
The next two theorems 8.5 and 8.6 are introduced in this section and will
be described further and proved later in the 3-pile and 4-pile analysis of the
game respectively.
Theorem 8.5. A position of the form x-y-y is a position with value 0.

All the 3-pile positions with at least 2 equal piles have a value of 0. Firstly,
all 3-pile positions with 2 equal piles have a value of 0 because they only
lead to positions with non-zero values such as those of the form k-n and
k-n-`, where k < n < `. Also, 3-pile positions with 3 equal piles have a value
of 0 as they are final positions and no further move can be done from this
point.
Theorem 8.6. A position of the form k-k-n-n is a position with value 0.

All the 4-pile positions with pairs of equal pairs of piles have a value of 0. A
position k-k-n-n, where k 6= n can only lead the game to positions k-n-`-o
with all different piles sizes. These positions only have non-zero values and
as such k-k-n-n will have a value of 0. Positions with 4 equal piles have also
a value of 0 as they are final positions and no further move can be made.

8.4.2. Analysis.
1-pile positions:

In this game, all 1-pile positions are final positions since there is no further
move to be made according to the rules.

17
Analysis for 2 piles:

We define three sets of positions as follows:


F , L: the positions where two pile sizes are equal or one pile is left.
W : the positions that have two different pile sizes.
We now prove that F , L and W are, respectively, the final, losing and
winning positions of the game.
Lemma 8.7. From any W -position there is a move to some L-position.

Proof. In a W -position such as k-n where k > n, a player has always the
choice to move the game to a state where only one pile is left; move all
matches from pile n to the larger pile k. This is a position described in F ,
L.
Therefore, there is always a move to some L-position from any W -position.


The fact that F and L are the exact same sets means that every time the
game ends up to a position in L it automatically finishes.
Therefore, the following theorem follows from Lemma 8.7 together with the
obvious fact that positions in F belong to L:
Theorem 8.8. F , L and W are, respectively, the final, losing and winning
positions of the game.

Analysis for 3 piles:

We define three sets of positions as follows:


F : the positions where all pile sizes are equal.
L: the positions that have at least 2 equal pile sizes and can lead to a 2-pile
position with 2 different piles.
W : the positions that have all different pile sizes.
We now prove that F , L and W are, respectively, the final, losing and
winning positions of the game.
Lemma 8.9. From any W -position there is a move to some L-position.

Proof. In a W -position such as k-n-` where k > n > `, a player has always
the choice to move the game to a state where two piles have the same size;
move to position (k + m)-(n − m)-` where (n − m) = ` by moving m matches
from pile n to larger pile k. Since the piles ` and (n − m) are equal, position
(k + m)-(n − m)-` is in L. The exceptional case where only two equal piles
remain and ` = 0, which is a F -position, is also a L-position as F is a subset
of L.
Therefore, there is always a move to some L-position from any W -position.

18
Lemma 8.10. From any L-position, every move leads to a W -position.

Proof. In a L-position such as k-n-n, where k > n there are up to n possible


moves to be made; move m matches from 1 up to n from a pile with size
n to larger pile k. All possible moves lead to positions (k + m)-n-(n − m),
where all piles have different sizes and therefore to W -positions.
In a L-position such as k-n-n, where n > k there are up to k possible moves
to be made; move m matches from 1 up to k from a pile with size k to larger
pile n. All possible moves lead to positions (k − m)-n-(n + m), where all
piles have different sizes and therefore to W -positions.
In a F -position such as k-k-k, there are no possible next moves to be made.
Positions in F also belong to L as F is a subset of L.
Thus, all next possible moves of any L-position are moving the game state
only to positions in W . 

Therefore, the following theorem follows from Lemmas 8.9 and 8.10, together
with the obvious fact that positions in F belong to L:
Theorem 8.11. F , L and W are, respectively, the final, losing and winning
positions of the game.

As the positions included in theorem 8.5 are also included in the 3-pile
L positions proved in theorem 8.11, these positions have a value of 0 and
therefore theorem 8.5 is proved.
Strategy: When in any position in W , the player has to move m matches
from n to k, as described in Lemma 8.9, to lead the game to a position in
L.

Analysis for 4 piles:

We define three sets of positions as follows:


F : positions where all pile sizes are equal (e.g k-k-k-k).
W:
• positions with two equal piles and two that are different from each
other (e.g k-k-n-`, k-k-k-`).
• positions with all different piles k-n-`-o:
– where the sum of two piles is equal to one of the other two
piles.
– where the difference of two piles is the same as the difference
of the other two piles.
– of the form k-n-2-1 when n > 4.
L:
• positions with two pairs of equal piles (e.g k-k-n-n).
• positions of the form n-4-2-1 when n > 6.
19
We now prove that F , L and W are, respectively, the final, losing and
winning positions of the game.
Lemma 8.12. From any W -position there is a move to some L-position.

Proof. In a W -position such as k-k-n-` where k > n > ` , a player always


has the choice to move the game to a 3 pile losing position, where at least
two piles are equal; move all matches from pile ` to pile n and go to position
k-k-(n + `). When k < n < ` the player can move all matches from n to `
and go to position k-k-(` + n).
W-positions with 2 equal piles and 2 that are different from each other also
include positions with 3 equal piles and 1 different pile such as k-k-k-`, since
k 6= `. In k-k-k-` where k > ` , a player always has the choice to move the
game to a 3 pile losing position, where at least two piles are equal; move all
matches from pile ` to pile k and go to position k-k-(k + `). When k < ` the
player can move all matches from k to ` and go to position k-k-(` + k).
In a W -position with all different piles such as k-n-`-o where k > n > ` > o
and:
• the sum of two piles is equal to one of the other two piles: the
player can move all matches from the smaller of the two piles to the
bigger one so as to lead the game to a position like k-n-(` + o) where
n=(` + o). As proved above and according to Theorem 8.11, 3 pile
positions with at least two equal piles are L-positions.
• (k − n) = (` − o): the player can move (` − o) matches from ` to n
and lead the game to a position of the form k-k-o-o where there are
two pairs of equal piles, which is a L-position.
• of the form k-n-2-1 when n > 4, the player can always move m
matches from n to k to move the game to position x-4-2-1, which is
a L-position.
Therefore, there is always a move to some L-position from any W -position.

Lemma 8.13. From any L-position, every move leads to a W -position.

Proof. In a L-position such as k-k-n-n, where k > n there are up to n


possible moves to be made; move m matches from 1 up to n from a pile with
size n to larger pile k. All possible moves lead to positions of the form (k+m)-
k-n-(n − m). These are all W -positions since ((k + m) − k) = (n − (n + m)).
In the case where m = n, this results to a position of the form (k + m)-k-n
with all three different piles, which is also a W -position by Theorem 8.11.
In a L-position such us n-4-2-1 ,where n > 6 all 3 pile positions that can be
reached in a move are in W (Theorem 8.11), since there are always three
different piles ((n + 4)-2-1, (n + 2)-4-1, (n + 1)-4-2, n-6-1, n-4-3, n-5-2 ).
Moving 1 match from the pile with 2 matches to either 4 or n leads to
positions with two equal piles and two that are different from each other,
which are also W -positions. Moving 1 match from 4 to n lead to position
x-3-2-1, which is also in W as two pairs are adding up to a third pile. Moving
20
more than 1 match from 4 also moves the game to a W position with two
equal and two different piles.
In a F -position such as k-k-k-k, there are no possible next moves to be
made. Positions in F also belong to L as F is a subset of L.
Thus, all next possible moves of any L-position are moving the game state
only to positions in W . 

Therefore, the following theorem follows from Lemmas 8.12 and 8.13, to-
gether with the obvious fact that positions in F belong to L:
Theorem 8.14. F , L and W are, respectively, the final, losing and winning
positions of the game.

As the positions included in theorem 8.6 are also included in the 4-pile
L positions proved in theorem 8.14, these positions have a value of 0 and
therefore theorem 8.6 is proved.
In addition to the losing positions described above there are some more
0-positions that arise for 4 piles. For example, some of them are positions
such as n-5-3-1 when n > 8 and n-6-3-2 when n > 9. There are also some
0-positions which cannot be described and a more general rule about them
could not be found. Examples of these are positions like 9-8-5-2, 10-9-5-2,
8-6-5-4 and 9-7-6-5.

21
9. Verification and Validation

The software implemented is supposed to be used only for experimenta-


tion purposes. As the results conjectured based on this experimentation are
proved rigorously, there is no reason for any further testing of the software.
This project is experimental and is mostly based on strict mathematical
proofs of the results generated by software. Thus, due to the nature of this
project there is no verification and validation to be carried out.

22
10. Summary and Conclusions

10.1. Summary.
Over the course of this project four different impartial combinatorial games
have been introduced and researched. Software that generates values for all
positions of each game has been implemented. Strict mathematical proofs of
interesting facts/patterns observed from the data generated from the soft-
ware have been written.

10.2. Future Work.


The initial goals of this project have been accomplished, given the time they
had to be fulfilled. However, sometimes research is open-ended and new facts
might be identified given more time. Moreover, as described above, there
are still some unsolved problems in the games studied such as finding out
complete formulas for computing the exact values of positions and giving a
general description to some of the positions of the games. Additionally, more
unknown games could be analysed in the future and added to this research
work.

10.3. Conclusion.
In conclusion, various impartial combinatorial games have been explored. As
a result, many interesting facts about unknown impartial games have been
identified and proved during the process of this experimental project.

23
References
[1] Archimedes-lab.org (2018). Play nim game online [online] Available at: http:
//www.archimedes-lab.org/game_nim/play_nim_game.html, [Accessed 10
Mar. 2018].
[2] Goobix.com (2018). Nim. [online] Available at: http://www.goobix.com/
games/nim/, [Accessed 10 Mar. 2018].
[3] Cut-the-knot.org. (2018) Bogomolny, A. Grundy’s Game from Interactive
Mathematics Miscellany and Puzzles. [online] Available at: https://www.
cut-the-knot.org/Curriculum/Games/Grundy.shtml, [Accessed 10 Mar.
2018].
[4] Siegel, A. (2013). Combinatorial Game Theory. Trovidence (Rhode Island):
American Mathematical Society.
[5] Nowakowski, R. (1996). Games of no chance. Cambridge: Cambridge University
Press.
[6] Grundy, P. M. (1939). Mathematics and games, Eureka. 2, 6-8; reprint Eureka
27 (1964) , 9-11
[7] Sprague, R. P. (1935–36). Über mathematische Kampfspiele, Tohoku Mathe-
matical Journal 41: 438-444
[8] Sprague-Grundy Values of Grundy’s Game (2002). Grundy’s Game. [on-
line] Available at: http://wwwhomes.uni-bielefeld.de/achim/grundy.
html [Accessed 6 Mar. 2018].
[9] E. Berlekamp, J. H. Conway, R. Guy. (1982). Winning Ways for your Mathe-
matical Plays, 96. Academic Press.

24

You might also like