the game of nim on graphs: nimg gwendolyn stockman alan frieze and juan vera

31
The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera

Post on 19-Dec-2015

214 views

Category:

Documents


0 download

TRANSCRIPT

The Game of Nim on Graphs: NimG

Gwendolyn Stockman

Alan Frieze and Juan Vera

The Game of Nim

2 playersn piles of disks, with a1, a2, … an disks on

each pilePlayers take turns removing disks from

each pileA player loses when there are no disks left

Impartial 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

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

Sprague-Grundy Numbers (Nim-Sums)

otherwise

sink a is

))((

0)(

xmex

xxg

VxEyxVyygx s.t. ),(:)()(

Vx0)( xg

x

y w z

11011

00

Grundy 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 ai‘s

Example:10111

The Grundy number is 0 so this is a winning position!

00

Proposed 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 can’t complete their turn

Example of Vertex NimG

9

21

15

6

13

10

4

7

5

2

1088

655

21

Geography

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)

Previous 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

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

The Game: Vertex NimG

v0 vn-1

a0 disks

a1 disks

an disks

an-1 disks

vn…v1

Theorem 1: Vertex NimG on path of length 2

otherwise

or

and

otherwise

or

and and

otherwise

or

and

1

10

001

00

)2:),,((

0

2

0001

00

)1:),,((

1

10

001

00

)0:),,((

babc

bc

c

cbag

bcba

bca

b

cbag

bcba

ba

a

cbag

:,, integers negative-nonGiven cba

NimG 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

01:0,,,0 xxg 21:0,,,0 xxg

0:0,,,0 xx 00:0,,,0 xxg]1,0[ xx

11:0,,,0 xxg 2:0,,0,0 x 12:0,,0,0 xg

0 x x 0

0 x 0x 0 0 x 0

Will prove that given a,b such that a>b then

Because

with

NimG on a Path of Length 3 (cont.)

],0[1:0,,,02:0,,,0 bababag

ba

21:0,,,0 bbag

(0,a,b,0):1

(0,0,b,0):2 (0,1,b,0):2 (0,2,b,0):2 (0,b-1,b,0):2 (0,b,b,0):2

0 a b 0

Take a and we want to know the value of

Examine the children of that position in the game tree and find

12:0,1,0,0 g 22:0,1,1,0 g

31:0,1,1,0 ag 1:0,1,1,0 ag

NimG on a Path of Length 3 (cont.)

a+11

1:0,1,1,0 a

a

00:0,1,,0 ag 1:0,1,1,00 a 1:0,1,1,01 a

1

1:0,1,1,02 a

22:0,2,2,0 g 32:0,2,1,0 g 00:0,2,1,0 ag

a+1

12:0,2,0,0 g

41:0,2,2,0 ag

NimG 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

1:0,2,2,0 ag

a+22

1:0,2,2,0 a

1:0,2,2,00 a 1:0,2,2,01 a

2

1:0,2,2,02 a

1

1:0,2,2,03 a

NimG on a Path of Length 3 (cont.)

So given a,b such that a>b then

And Further suppose we have a,b,c,e {0} such that

then

],0[1:0,,,02:0,,,0 bababag

021:0,,,0 babbag if

12

1:,,,max

d

ecbag

disks of numbermax decba

(0,a,b,0):1

(0,0,b,0):2 (0,1,b,0):2 (0,2,b,0):2 (0,b-1,b,0):2 (0,b,b,0):2

1 3 4 b+12

(0,1,b,0):0 0

Vertex 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 vV(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 uN(v) such that A(u)< A(v) add node (G,A’): u as a

child to (G,A):v where

Repeat once for each node added to T

)()(

1)(:)(' GVw

wA

vwwAwA

otherwise

v

x

u

y(G, A):v

(G, A’):u

c

v

a

Example: Create T

b

v

a

d

b f

e

c

h

49

6 5

2

3

1

12

Player P1 starts with setup (G,A):v

v

ba

c

h

v

a b c

c

v

a

Example: Create T

d

b

b

v

a

d

b f

e

c

h

48

6 5

2

3

1

12

Start with setup (G,A’):a

d

b

v

a

b d

c

v

a

Example: Create T

d

b

b

v

a

d

b f

e

c

h

48

5 5

2

3

1

12

Start with setup (G,A’’):b

a

d

c

v

a

Example: Create T

d

b

b

e f

v

a

d

b f

e

c

h

48

5 5

2

3

1

12

Start with setup (G,A’’):b

a

e

v

b e ff

c

v

a

Example: Create T

d

b

b

e

f

f

v

a

d

b f

e

c

h

48

5 4

2

3

1

12

Start with setup (G,A’’’):e

b

c

e

f

f

c

v

a

Example: Create T

d

b

b

e

f

f

v

a

d

b f

e

c

h

48

5 4

1

3

1

12

Start with setup (G,A’’’):e

b

e

c

f

ee

c

e

f

v

a

Example: Create T

d f

b

f

fb

e

f

f

v

a

d

b f

e

c

h

49

5 4

1

3

1

12

f

f

e

f

f

Labeling T

If it is player P1’s 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 nV(T), with labeling function L:V(T){P1,P2}, using a depth first labeling starting with the n=root 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

ff

e

c

e

f

v

a

Example: Labeling T

d f

b

f

fb

e fw

f

a

P1

P2

P1

P2

P1

b

v

w

fe

w

wa

v

b

e

b

v

fe

b dd

a c

e

c

e

f

f

f

e f

c

f

e f

b

Depth First Labeling of T :

= A node labeled P2

= A node labeled P1

= A node whose subtree is being labeled

= The node currently being examined

P1 does NOT have a winning strategy from

(G,A):v!L(n):=

P1

n a leaf and on a P2-levelor n on a P1-level and at least one child of n labeled P1or n on a P2-level and all children of n labeled P1

P2

n a leaf and on a P1-levelor n on a P2-level and at least one child of n labeled P2or n on a P1-level and all children of n labeled P2

n a leaf and on a P1-levelor n on a P2-level and at least one child of n labeled P2

n a leaf and on a P2-levelor n on a P1-level and at least one child of n labeled P1

or n on a P1-level and all children of n labeled P2

f

e f

c

f

e f

b

f

fe

b d

a

Why P1 can’t 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?

v P1

P2

P1

P2

P1

vvv

v

a

d

b f

e

c

h

49

6 5

2

3

1

12

v8

11

6

10

52

8

P1 still loses!

The 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

)()(

)(:)(' GVw

wA

vwrwAwA

otherwise

uAG :)',(

uAG :)',((G, A):v

(G, A’):u

(G, A):v

uAG :)',(

The 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)

TyxAGzxAwA in of children :)',()()(

)()(

)(:)(' GVw

wA

vwrwAwA

otherwise

uAG :)',(

uAG :)',(

(G, A):w

(G, A’):x

NimG 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

vAG :)~

,(

root of T

vAG :),(

vAG :)~

,(

n-1 nodes

1 node

n-2 nodes

n-d nodes

A~

Questions???