Title: The Game of Nim on Graphs: NimG
1The Game of Nim on Graphs NimG
- Gwendolyn Stockman
- Alan Frieze and Juan Vera
2The Game of Nim
- 2 players
- n piles of disks, with a1, a2, an disks on each
pile - Players take turns removing disks from each pile
- A player loses when there are no disks left
3Impartial Games
- Geography, Nim, and NimG are impartial games
- A game in which the only difference between the
two players is which one goes first - Every position of an impartial game has a Grundy
Number or Nim-Value
4Sprague-Grundy Numbers (Nim-Sums)
- Used to represent wining and losing positions
- Given a game tree T (V,E)
- Recursively define
- with
- A player is in a winning position if at the end
of his/her turn the playing piece is on
such that
5Grundy Numbers (cont.)
- Let a1, a2, an be the binary representations of
the number of disks on each of the n piles - In the game of Nim the Grundy number for a setup
is the bit-wise sum (mod 2) of the ais - Example
1
1
1
0
0
1
1
1
1
1
0
0
0
0
The Grundy number is 0 so this is a winning
position!
6Proposed Versions of NimG
- 2 players
- 1 piece is moved along an undirected graph with
no self-loops, and discs are removed - If discs on vertices
- Could move first and then remove discs
- Could remove discs and then move
- Possibly allow moves to empty verticies
- If discs on edges
- Remove discs as you go along an edge
- Players take turns removing disks from piles
- How to win
- The other player cant complete their turn
7Example of Vertex NimG
7
15
9
6
6
5
5
4
21
21
10
10
8
8
5
13
2
8Geography
- Two players alternately move a piece on a graph
until one loses by being unable to make an legal
moves - Directed or Undirected
- Edge Geography
- No edge repeated
- Vertex Geography
- No vertex repeated
- Undirected Vertex Geography
- Contained in a version of Vertex NimG with
- 1 chip on each vertex
- Not allowed to move to empty vertices
- Solvable in polynomial Time
- Second player has a winning strategy IFF the
graph has a perfect matching (Fraenkel 1993) - Undirected Edge Geography
- PSPACE-complete (Fraenkel 1993)
9Previous Work Nim on Graphs
- In A Nim game played on Graphs I and II (Fukuyama
2003) Edge NimG was examined - Proved that the Grundy Numbers can be found
completely on - Bipartite Graphs
- Trees
- Cycles
- Main Method matchings on graphs
- Contains normal Nim
- 2 vertices with n edges with a1, a2, an disks
on each edge - Contains Undirected Edge Geography
- 1 disk on each edge
10The Game Vertex NimG
- The game from now on
- Vertex NimG
- Moves to empty vertices allowed
- Notation for Vertex NimG on a path of length N
- (a0,a1,,an-1,an)0 represents
- Where is the piece being moved
11Theorem 1 Vertex NimG on path of length 2
12NimG on a Path of Length 3
- Not so simple on longer paths
- Grundy Numbers bounded by a function of d, the
number of disks on the graph - First note that ?x ???
- Easy to see that
- is a child for and
- Easy to see that
- is a child and
- Rest omitted for brevity
13NimG on a Path of Length 3 (cont.)
- Will prove that given a,b??? such that agtb then
- Because
- with
14NimG on a Path of Length 3 (cont.)
- Take a??? and we want to know the value of
- Examine the children of that position in the game
tree and find
a1
a
1
1
15NimG on a Path of Length 3 (cont.)
- Take a??? and we want to know the value of
- Examine the children of that position in the game
tree and find
a1
a2
2
2
1
16NimG on a Path of Length 3 (cont.)
- So given a,b??? such that agtb then
- And
- Further suppose we have a,b,c,e ???0 such that
- then
1
2
3
4
b1
0
17Vertex NimG on Any Graph
- Represent positions of NimG as (G, A)v where G
is the graph, A is the amount function for G, and
marker is at vertex v?V(G) - A reduced game tree is used to find if a winning
strategy exists from a given position, and if one
does, what it is - Create the reduced game tree, T, where each node
is a position, by - making (G,A)v the root
- For each u?N(v) such that A(u)lt A(v) add node
(G,A) u as a child to (G,A)v where - Repeat once for each node added to T
18Example Create T
- Player P1 starts with setup (G,A)v
12
4
9
3
2
1
6
5
19Example Create T
12
4
8
3
2
1
6
5
20Example Create T
12
4
8
3
2
1
5
5
21Example Create T
12
4
8
3
2
1
5
5
22Example Create T
12
4
8
3
2
1
5
4
23Example Create T
12
4
8
3
1
1
5
4
24Example Create T
12
4
9
3
1
1
5
4
25Labeling T
- If it is player P1s turn then label all even
levels, including 0, of T, P1, and all odd levels
P2 - Label each node either P1 or P2
- Player P1 has a winning strategy from nodes
labeled P1 - Player P2 has a winning strategy from nodes
labeled P2 - Label all n?V(T), with labeling function
LV(T)?P1,P2, using a depth first labeling
starting with the nroot of V(T) - Apply the depth first labeling to all children of
n in T - Label n with L(n)
- The root of T is labeled P1 IFF there is a
winning strategy for player P1
26Example Labeling T
- Depth First Labeling of T
P1 does NOT have a winning strategy from (G,A)v!
n a leaf and on a P2-level
n a leaf and on a P2-level
or n on a P1-level and at least one child of n
labeled P1
or n on a P1-level and at least one child of n
labeled P1
P1
or n on a P2-level and all children of n labeled
P1
L(n)
n a leaf and on a P1-level
n a leaf and on a P1-level
P1
or n on a P2-level and at least one child of n
labeled P2
or n on a P2-level and at least one child of n
labeled P2
P2
or n on a P1-level and all children of n labeled
P2
or n on a P1-level and all children of n labeled
P2
P2
A node labeled P2
A node labeled P1
P1
A node whose subtree is being labeled
P2
The node currently being examined
P1
27Why P1 cant win
- Assume that players will always follow a winning
strategy if one exists - If P1 moves to a, b, or c then P2 will win
- What if P1 moves to h?
P1 still loses!
P1
12
11
10
8
P2
4
9
3
8
6
5
2
P1
2
1
6
5
P2
P1
28The Winning Strategy Case 1
- If player P2 just moved from vertex u to vertex
v, creating setup (G, A)v, and (G, A)u is a
child of (G, A) v labeled P1 - Remove r?1, A(v)- A(u) disks from vertex v and
move to vertex u, creating setup
with - Replace the sub-tree with root (G, A)u with the
tree of root created as described
before
(G, A)v
29The Winning Strategy Case 2
- Otherwise, given setup (G, A)v pick any child
(G, A)u of node (G, A)v in T that is labeled
P1 - remove r?1, A(v)- A(u) disks from vertex v and
move to vertex u, creating setup
with - Replace the sub-tree with root (G, A)u with the
tree of root created as described
before - The alterations to T insure that T maintains the
property that for any node y(G, A)w ?V(T)
30NimG on any Graph Analysis
- Tree T is exponential in size
- What if there is a maximum number of disks
allowed on each vertex? - Polynomial at most nd number of nodes, where d
is the maximum number of disks allowed on a
vertex and n?V(G)? - There does not exist any path starting from the
root with a node (G,A)v and a node
for any amount functions A and
31Questions???