Presentation is loading. Please wait.

Presentation is loading. Please wait.

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

Similar presentations


Presentation on theme: "The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera."— Presentation transcript:

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

2 The Game of Nim 2 players n piles of disks, with a 1, a 2, … a n disks on each pile Players take turns removing disks from each pile A player loses when there are no disks left

3 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

4 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) x ywz

5 1 1 0 11 00 Grundy Numbers (cont.) Let a 1, a 2, … a n 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 a i ‘s Example: 1 01 11 The Grundy number is 0 so this is a winning position! 00

6 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

7 Example of Vertex NimG 9 21 15 6 13 10 4 7 5 2 88 655 21

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

9 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 a 1, a 2, … a n disks on each edge Contains Undirected Edge Geography  1 disk on each edge

10 The game from now on:  Vertex NimG  Moves to empty vertices allowed Notation for Vertex NimG on a path of length N  ( a 0,a 1,…,a n-1,a n ):0 represents:  Where is the piece being moved The Game: Vertex NimG v0v0 v n-1 a 0 disks a 1 disks a n disks a n-1 disks vnvn … v1v1

11 Theorem 1: Vertex NimG on path of length 2

12 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 forand  Easy to see that is a child and  Rest omitted for brevity 0 xx 0 0 x 000 x 0

13 Will prove that given a,b   such that a>b then Because with NimG on a Path of Length 3 (cont.) (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 0ab0

14 Take a   and we want to know the value of Examine the children of that position in the game tree and find NimG on a Path of Length 3 (cont.) a +1 1 a 1

15 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 a +2 221

16 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,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+1 2 (0,1,b,0):0 0

17 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 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 )< A ( v ) add node ( G, A ’): u as a child to ( G, A ): v where  Repeat once for each node added to T v x u y (G, A):v (G, A’):u

18 c v a Example: Create T b v a d bf e c h 4 9 65 2 3 1 12 Player P1 starts with setup (G,A):v v ba c h v abc

19 c v a Example: Create T d b b v a d bf e c h 4 8 65 2 3 1 12 Start with setup (G,A’):a d b v a bd

20 c v a Example: Create T d b b v a d bf e c h 4 8 55 2 3 1 12 Start with setup (G,A’’):b a d

21 c v a Example: Create T d b b ef v a d bf e c h 4 8 55 2 3 1 12 Start with setup (G,A’’):b a e v b ef f

22 c v a Example: Create T d b b e f f v a d bf e c h 4 8 54 2 3 1 12 Start with setup (G,A’’’):e b c e f f

23 c v a Example: Create T d b b e f f v a d bf e c h 4 8 54 1 3 1 12 Start with setup (G,A’’’):e b e c f

24 ee c e f v a Example: Create T df b f fb e f f v a d bf e c h 4 9 54 1 3 1 12 f f e f f

25 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 n  V(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

26 ff e c e f v a Example: Labeling T df b f fb ef w f a P1 P2 P1 P2 P1 b v w fe w w a v b e b v fe bdd ac e c e f f f ef c f ef 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-level or n on a P1-level and at least one child of n labeled P1 or n on a P2-level and all children of n labeled P1 P2 n a leaf and on a P1-level or n on a P2-level and at least one child of n labeled P2 or n on a P1-level and all children of n labeled P2 n a leaf and on a P1-level or n on a P2-level and at least one child of n labeled P2 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 all children of n labeled P2

27 f ef c f ef b f fe bd 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 ? vP1 P2 P1 P2 P1 vvv v a d bf e c h 4 9 65 2 3 1 12 v 8 11 6 10 52 8 P1 still loses!

28 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 (G, A):v (G, A’):u (G, A):v

29 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 ) (G, A):w (G, A’):x

30 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 n d 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 root of T  n -1 nodes 1 node  n -2 nodes  n - d nodes

31 Questions???


Download ppt "The Game of Nim on Graphs: NimG Gwendolyn Stockman Alan Frieze and Juan Vera."

Similar presentations


Ads by Google