This paper was converted on www.awesomepapers.org from LaTeX by an anonymous user.
Want to know more? Visit the Converter page.

A PSPACE-complete Graph Nim

Kyle G. Burke
Colby College
paithanq@gmail.com
   Olivia C. George
oliviacgeorge@yahoo.com
monkey
Abstract

We build off the game NimG [9] to create a version named Neighboring Nim. By reducing from Geography, we show that this game is PSPACE\mathord{\rm PSPACE}-hard. The games created by the reduction share strong similarities with Undirected (Vertex) Geography and regular Nim, though these are both solvable in polynomial-time. This application of graphs can be used as a form of game sum with any rulesets, not only Nim.

1 Background

1.1 Algorithmic Combinatorial Game Theory

Most of the results here revolve around the computational complexity of determining which player has a winning strategy from a given game position. There exist faster algorithms to solve this problem for some rulesets than for others. For each ruleset, we consider the computational problem that could be solved by such an algorithm. We will refer to both the ruleset and problem by the same name.

We strongly encourage readers unfamiliar with these topics to refer to [1].

1.2 Terminology

There is a small amount of non-standard terminology used in this paper.

  • We use the word sticks to refer to the objects in nim heaps. Thus, a nim heap of size six contains six sticks.

  • An optimal sequence set is a set of sequences of plays for both players such that any move deviating from one of the sequences results in an N-position. No move in that sequence should be non-optimal for either player. Thus, if a player does not know whether they have a winning strategy, adhering to an optimal sequence is at least as good as any other move.

1.3 Nim

Nim is an impartial game played on a collection of heaps, each with a non-negative number of sticks. On a player’s turn, they choose a non-empty pile and remove as many sticks as desired (at least one) from that pile. A player loses when they cannot remove sticks (all piles are empty).

Nim is a classic impartial game, being the basis of Nimbers and Sprague-Grundy theory[8][5]. Nim has lots of nice properties, from easy evaluation of games to obvious composition of two Nim games (the sum is just a new Nim game).

1.4 NimG

Nim has been extended to incorporate graphs so that nim heaps are assigned to either edges or vertices. There are three different versions of the game named NimG. In all three versions, a turn consists of both traversing an edge of the graph and removing sticks from a visited element.

1.4.1 Edge-heap NimG

Fukuyama describes NimG where nim heaps are embedded into the edges of the graph[4]. On each turn, the current player chooses an edge to traverse (which has at least 1 stick on it) and removes any number of sticks from that edge. The next player then starts on the vertex on the other end of that edge and must choose an adjacent edge for their move. When there are no more edges with sticks adjacent to the current vertex, the current player loses. Many results for this game are known on complete graphs[2].

1.4.2 Vertex-heap NimG

In Vertex NimG, players similarly move from one vertex to another, but heaps are connected to the vertices instead of edges[9]. The two variants can be easily described here as: “remove sticks, then move” and “move, then remove sticks”. In both cases, a player loses if they cannot complete their turn. The main topic of this paper is a variant of “move, then remove”.

1.5 Geography

We will use Geography to show the PSPACE\mathord{\rm PSPACE}-hardness of Neighboring Nim. There are many flavors of Geography; we use the term to refer to Directed Vertex Geography. This impartial game is played on a directed graph; each turn begins with a vertex chosen. The current player’s turn consists of choosing an outgoing arc that leads to a vertex that hasn’t been visited yet. The next player then starts their turn with the resulting vertex selected. We formally describe the ruleset as follows:

Definition 1.1 (Geography)

(Directed Vertex) Geography positions are described by: G=(V,E)G=(V,E) and vVv\in V. Move options for (G,v)(G,v) are all (G,v)(G^{\prime},v^{\prime}) where:

  • (v,v)E(v,v^{\prime})\in E,

  • V=V{v}V^{\prime}=V\setminus\{v\},

  • EE^{\prime} is the subset of EE induced by VV^{\prime}, and

  • G=(V,E)G^{\prime}=(V^{\prime},E^{\prime}).

Geography is known to be PSPACE\mathord{\rm PSPACE}-complete[7].

2 Neighboring Nim

We define the ruleset Neighboring Nim to be similar to the “move then remove” version of NimG, but also allow players to choose to play on the same vertex as the last move as though each vertex has a self-loop. Note that standard Nim is equivalent to a game of Neighboring Nim on a complete graph with each heap on a separate vertex. A more formal definition follows.

Definition 2.1 (Neighboring Nim)

Neighboring Nim positions are described by G=(V,E)G=(V,E), w:Vw:V\rightarrow\mathbb{N}, and xVx\in V. The options for (G,w,x)(G,w,x) are all (G,w,x)(G,w^{\prime},x^{\prime}) where w:Vw^{\prime}:V\rightarrow\mathbb{N} and

  • x=xx^{\prime}=x or {x,x}E\{x,x^{\prime}\}\in E,

  • w(x)<w(x)w^{\prime}(x^{\prime})<w(x^{\prime}), and

  • vV{x}:w(v)=w(v)\forall v\in V\setminus\{x^{\prime}\}:w^{\prime}(v)=w(v).

Our main result for this paper is that Neighboring Nim is PSPACE\mathord{\rm PSPACE}-hard. Since our analysis uses graphs with a small number of sticks on each vertex, we define a version of the game with a bounded number of sticks per vertex.

Definition 2.2 (kk-Neighboring Nim)

kk-Neighboring Nim is the same ruleset as Neighboring Nim, except that the weight function, ww, has bounded range: [0,k][0,k].

We are able to show that 2-Neighboring Nim is PSPACE\mathord{\rm PSPACE}-complete, and thus cc-Neighboring Nim is also PSPACE\mathord{\rm PSPACE}-complete for any constant c2c\geq 2. The case for 1-Neighboring Nim is solvable in polynomial time, since this game is equivalent to Undirected (Vertex) Geography [3]. Thus, if PPSPACE\mathord{\rm P}\neq\mathord{\rm PSPACE}, allowing a second stick on some vertex-heaps can greatly increase the computational hardness of determining the winning player!

3 Computational Complexity of Neighboring Nim

3.1 PSPACE\mathord{\rm PSPACE}-hardness

The following is the main result of this paper.

Theorem 3.1 (Hardness)

Neighboring Nim is PSPACE\mathord{\rm PSPACE}-hard.

We will show the hardness of this problem by reducing from the game Geography, which is PSPACE\mathord{\rm PSPACE}-hard[6].

Proof. Given any Geography position, we will give an algorithm to construct an equivalent Neighboring Nim state, meaning that there is a win in the Geography position exactly when there is a win in corresponding Neighboring Nim position. First we will describe the method for generating these positions, then prove their equivalence.

Let GGGG be a Geography position on the directed and unweighted graph G=(V,E)G=(V,E). We define a new undirected graph, G=(V,E)G^{\prime}=(V^{\prime},E^{\prime}) with weights on the vertices w:Vw:V^{\prime}\rightarrow\mathbb{N} in the following way. vV:\forall v\in V: let XvVX_{v}\in V^{\prime} and set w(X)=1w(X)=1. Also, (y,z)E:\forall(y,z)\in E: (edge directed from yy to zz) let ay,z,by,z,cy,z,dy,z,ey,z,fy,z,gy,zVa_{y,z},b_{y,z},c_{y,z},d_{y,z},e_{y,z},f_{y,z},g_{y,z}\in V^{\prime} where, ignoring the (y,z)(y,z)-subscripts, w(a)=w(b)=w(c)=w(e)=w(f)=w(g)=1w(a)=w(b)=w(c)=w(e)=w(f)=w(g)=1, w(d)=2w(d)=2 and,

(Xy,a),(a,b),(b,c),(c,d),(b,e),(e,f),(d,f),(d,g),(f,g),(g,Xz)E(X_{y},a),(a,b),(b,c),(c,d),(b,e),(e,f),(d,f),(d,g),(f,g),(g,X_{z})\in E^{\prime}.

See Figure 1 for a visual description.

Refer to caption
Figure 1: Our main gadget: reduce each directed edge from yy to zz to the undirected weighted graph shown here.

The resulting GG^{\prime} is the graph for our Neighboring Nim position equivalent to GGGG. The only final step is to declare that if GGGG has a starting vertex, vv, then XvVX_{v}\in V^{\prime} is the starting vertex (where the previous play had been made) in our game and w(Xv)w(X_{v}) is set to 0 instead of 1.

To complete the reduction, we must show that the structure in Figure 1 “acts” like a directed edge in Geography. Thus, we must prove:

  • Moving “backwards” is a losing play. If the previous play was at XzX_{z}, then a backwards play would be to remove the only stick at g(y,z)g_{(y,z)}. A backwards play results in an 𝒩{\cal N}-position.

  • The same player moving into the gadget should also move out. If a player moves from XyX_{y} to a(y,z)a_{(y,z)}, then in an optimal sequence of plays, the same player will move from g(y,z)g_{(y,z)} to XzX_{z}.

We prove the former in Lemma 3.2 and the latter in Lemma 3.3. The result is that each of these gadgets (as in Figure 1) in the Neighboring Nim position works just like a (directed) edge in Geography. Trying to go backwards will result in losing and, if players play optimally, they both might as well continue through each gadget.

Lemma 3.2 (Don’t Go Backwards)

Any play from (Xz)(X_{z}) to g(y,z)g_{(y,z)} (for all yy) results in an 𝒩{\cal N}-position.

(See Appendix A for a proof of this claim.) This implies that our gadgets are directed: if a player tries to go “backwards”: from an XX-vertex to an ii-vertex, the opponent will have a winning strategy.

To finish showing that our gadget acts like a directed edge, we must prove that “nothing can go wrong” during a regular forward traversal of the structure. To this end, we find two sequences that constitute an optimal sequence set through the gadget, thus showing that neither player benefits from deviating from the sequence. In order to get from one end of the gadget (as in Figure 1) to the other, the following sequence of moves suffices (let Alice and Bob be our two players; we will again ignore subscripts): Alice “takes” aa, Bob takes bb, Alice takes ee, Bob takes ff, Alice decrements dd by 1, Bob takes gg, Alice takes XzX_{z}. Note that the same player (in this example, Alice) who chooses to take aa also moves to XzX_{z}. The other sequence is where Bob takes cc instead of gg—here Alice will take the remaining object at dd and Bob will be forced to take gg, rejoining with the first sequence. See Figure 2 for a visual description of the safe sequences. We must prove that neither player benefits from deviating from these sequences. To do this, we show that any deviation is a losing move.

Refer to caption
Figure 2: This sequence of moves is “safe” for both players to traverse the gadget. The two gray arrows indicate the potential additional moves in the second sequence. Each move assumes that exactly one object is taken from a vertex.
Lemma 3.3 (Stick to the Script)

Let the notation k(p)k(p) denote taking pp objects from vertex kk in a turn. Then, after the plays (,Xy(1),a(1))(\ldots,X_{y}(1),a(1)) any play deviating from the following sequences is a losing move:
(b(1),e(1),f(1),d(1),g(1),Xz(1))(b(1),e(1),f(1),d(1),g(1),X_{z}(1))
(b(1),e(1),f(1),d(1),c(1),d(1),g(1),Xz(1))(b(1),e(1),f(1),d(1),c(1),d(1),g(1),X_{z}(1)).

(See Appendix B for the proof of this claim.) This implies that once a player makes an appropraite move onto the gadget (playing on an aa-node) any “safe” sequence of moves in the gadget results in that same player making the play at the opposite XX node. The two above claims combined show that our gadget correctly models a directed edge in a graph just between the XX nodes.

Thus, for any edge (y,z)(y,z) in our Geography position, GGGG, the move to a(y,z)a_{(y,z)} will result in the same player moving to XzX_{z} as desired. Also, since we proved players shouldn’t go backwards, this game is equivalent to GGGG; the first player has a winning strategy in GGGG exactly when the first player has a winning strategy in this Neighboring Nim position.

Thus, Neighboring Nim is PSPACE\mathord{\rm PSPACE}-hard. \Box

The hardness of Vertex NimG follows directly.

Corollary 3.4 (Vertex NimG hardness)

Vertex NimG is PSPACE\mathord{\rm PSPACE}-hard.

Proof. Neighboring Nim is a special case of Vertex NimG where all vertices have self-loops. Thus, Vertex NimG is also PSPACE\mathord{\rm PSPACE}-hard. \Box

3.2 Speculation on Completeness

Unfortunately, Neighboring Nim is not automatically PSPACE\mathord{\rm PSPACE}-complete as games could take a number of moves exponential in the size of the description of the game. For example, a vertex can have a number of sticks exponential in the amount of bits needed to express that number and the rest of the graph. We leave this unsolved as Open Problem 6.1. There are good arguments to conjecture either way.

On one hand, it seems to not be inside PSPACE\mathord{\rm PSPACE}. Games can last an exponential number of turns, so the game trees are extremely tall. A straight-forward brute-force traversal can’t be performed in polynomial space.

On the other hand, it might be inside PSPACE\mathord{\rm PSPACE}. Although there are many EXPTIME\mathord{\rm EXPTIME}-hard rulesets, the authors know only of loopy examples. This means they can have positions that repeat during the course of a game, which cannot occur in Neighboring Nim. Additionally, Nim heaps are well-understood, perhaps increasing the size of the heaps doesn’t greatly increase the difficulty of finding strategies.

3.3 PSPACE\mathord{\rm PSPACE}-complete versions

We can sidestep this problem a bit by using our bounded-heap-size version of the game.

Corollary 3.5 (2-Neighboring Nim Completeness)

   kk-Neighboring Nim is PSPACE\mathord{\rm PSPACE}-complete for any k2k\geq 2.

Proof. The result of the reduction from Theorem 3.1 is always a 2-Neighboring-Nim position. Thus, the PSPACE\mathord{\rm PSPACE}-hardness holds for this subset of positions as well. The positions are in PSPACE\mathord{\rm PSPACE} because kk bounds the maximum number of moves per vertex. \Box

4 Generalization

This graph-embedding technique works with games other than Nim. Given a graph, assign different game states to the vertices, and use similar rules: players may make one move legal in the game in any vertex neighboring the last play. We define this formally.

Definition 4.1 (Neighboring-RR)

Given any ruleset RR, Neighboring-RR has positions of the form G=(V,E)G=(V,E), w:Vpositions(R)w:V\rightarrow positions(R), and xVx\in V. The left options for (G,w,x)(G,w,x) are (G,w,x)(G,w^{\prime},x^{\prime}) where w:Vpositions(R)w^{\prime}:V\rightarrow positions(R) and:

  • x=xx^{\prime}=x or {x,x}E\{x,x^{\prime}\}\in E,

  • w(x)w^{\prime}(x^{\prime}) is a left option of w(x)w(x^{\prime}), and

  • vV{x}:w(v)=w(v)\forall v\in V\setminus\{x^{\prime}\}:w^{\prime}(v)=w(v).

The right options are defined analagously: w(x)w^{\prime}(x^{\prime}) must be a right option of w(x)w(x^{\prime}).

4.1 Inequivalent Positions

This new definition allows a Neighboring Nim vertex to contain multiple heaps instead of only a single heap. Although each Nim position is equivalent to a single heap, that equivalence doesn’t carry over in the Neighboring situation. Consider the two Neighboring Nim games in figure 3. (The previous move was made on the left-most vertex in both cases.) The values of the games embedded in the left vertices are both 0, the values on the middle vertices are both 0, and the values of the rightmost games are both *. However, the overall value of the positions are not equivalent.

Refer to caption
Figure 3: Two Neighboring Nim positions. In both, the last move was made on the dashed vertex. The value of the above game is zero, the value of the bottom game is *.

In the top game, there are no move options, so the value is 0. In the bottom position, the next player can move to the middle vertex, even though the value of the Nim game there is also zero. After that move there are exactly two moves remaining. Thus, the initial game has exactly three moves remaining and has a value of *.

4.2 Generalized Hardness

The next result allows us to say something about the hardness of graph-embedded versions of many impartial games.

Theorem 4.2 (Neighboring-RR Hardness)

For any ruleset, RR, which has positions identical to 0,0,*, and 2*2, Neighboring-RR is PSPACE\mathord{\rm PSPACE}-hard.

Proof. Two positions are identical if they have isomorphic game trees. Replacing the nim heaps of size 1 and 2 with * and 2*2, respectively, in the reduction of theorem 3.1 doesn’t change the winnability of the resulting games. Thus, the reduction applies to RR. \Box

5 Conclusions

Building on algorithmic work analyzing different versions on NimG, we present Neighboring Nim, a new PSPACE\mathord{\rm PSPACE}-hard game.

An interesting aspect of the hardness of Neighboring Nim is the juxtaposition with Vertex Geography. 1-Neighboring Nim is the same ruleset as Undirected Vertex Geography, which is solvable efficiently[3]. However, by adding an extra stick to just a few vertices, we can push the game into PSPACE\mathord{\rm PSPACE}-hardness!

Furthermore, we can replace Nim and apply the graph-embedding concept to any other ruleset, RR, to create Neighboring-RR.

6 Future Work

There are many extensions to the work described here. The most prominent is certainly the unknown completeness of Neighboring Nim.

Open Problem 6.1

Neighboring NimPSPACE\textsc{Neighboring Nim}\in\mathord{\rm PSPACE}?

Additionally, there is still work to be done on the computational hardness of other flavors of NimG.

Open Problem 6.2

What is the computational complexity of Edge NimG?

Open Problem 6.3

What is the computational complexity of Vertex NimG on graphs without self-loops?

Other explorable problems include the hardness of other versions of Neighboring-RR.

Open Problem 6.4

Is Neighboring-RR PSPACE\mathord{\rm PSPACE}-hard if RR includes any positions equivalent to * and 2*2?

Note that open problem 6.4 is a stronger statement than shown here because equivalent does not necessarily mean identical.

Open Problem 6.5

For which other computationally easy rulesets, RR, is Neighboring-RR hard?

Open Problem 6.6

Are there strictly partisan positions of a ruleset, RR, that can be used to show Neighboring-RR is hard? How small can the game trees be to get a hard game?

7 Acknowledgments

The authors would like to thank those who played Neighboring Nim with them, including three excellent Wittenberg University students: Deanna Fink, Dang Mai and Ernie Heyder, as well as Professor Doug Andrews who defeated the first author over and over again. We would also like to thank Adam Parker for listening to initial versions of the hardness proof and proofreading this paper.

References

  • [1] Erik D. Demaine and Robert A. Hearn. Playing games with algorithms: Algorithmic combinatorial game theory. In Michael H. Albert and Richard J. Nowakowski, editors, Games of No Chance 3, volume 56 of Mathematical Sciences Research Institute Publications, pages 3–56. Cambridge University Press, 2009.
  • [2] Lindsay Erickson. Nim on complete graphs. Ars Combinatoria, Accepted for publication in 2009.
  • [3] Aviezri S. Fraenkel, Edward R. Scheinerman, and Daniel Ullman. Undirected edge geography. Theor. Comput. Sci., 112(2):371–381, 1993.
  • [4] Masahiko Fukuyama. A nim game played on graphs. Theor. Comput. Sci., 1-3(304):387–399, 2003.
  • [5] P. M. Grundy. Mathematics and games. Eureka, 2:198—211, 1939.
  • [6] David Lichtenstein and Michael Sipser. Go is polynomial-space hard. J. ACM, 27(2):393–401, 1980.
  • [7] C. H. Papadimitriou. Computational Complexity. Addison Wesley, Reading, Massachsetts, 1994.
  • [8] R. P. Sprague. Über mathematische Kampfspiele. Tôhoku Mathematical Journal, 41:438—444, 1935-36.
  • [9] Gwendolyn Stockman. Presentation: The game of nim on graphs: NimG, 2004. Available at http://www.aladdin.cs.cmu.edu/reu/mini_probes/papers/final_stockman.ppt%.

Appendix A Proof of Lemma 3.2

Lemma A.1 (Don’t Go Backwards)

Any play from (Xz)(X_{z}) to g(y,z)g_{(y,z)} (for all yy) is suboptimal.

We will refer to the player who moves from XzX_{z} to gg (we will leave out the subscript for the internal vertices) as the “foe” while the other player is the “hero”. We will show that the hero has a winning strategy after a backwards move. We can now look at two cases, each depending on the state of the game outside the gadget.

The first is the case where the move from aa to XyX_{y} would be a winning play. In this case, the hero can next move from gg to dd and take both of the objects there. The foe has two options, both of which, we show, allow the hero to win.

  • 1.

    The foe moves to cc. In this case the hero must choose to go to bb. The foe can now either choose to move to aa—in which case the hero will gladly move to XyX_{y} and win as we assumed—or to ee. Then the hero simply takes the object at ff and, as there are no more moves, the hero has won.

  • 2.

    The foe moves to ff. The hero must then take ee and the foe must take bb. The hero can then move to cc and win the game.

The second major case assumes that the move from aa to XyX_{y} is a losing play. Here, the hero can still move to dd (from gg) but will take only one of the objects. Now the foe has three options: taking the other object at dd, moving to cc or moving to ff. We show all to be losses.

  • 1.

    Foe moves to cc. Now the hero should take the remaining object at dd. The following sequence must occur: foe must take ff, hero at ee, foe at bb, hero at aa, followed by the foe at XyX_{y}, a losing move by our assumption.

  • 2.

    Foe takes the remaining object at dd. The hero will choose to take cc, so the foe must take bb. The hero can then take aa, forcing the foe to take XyX_{y}, a losing move by our assumption.

  • 3.

    Foe takes ff. The hero should then take ee so the foe must take bb. Again, the hero can take aa, so the foe must move to XyX_{y}, a losing move by our assumption.

Thus, it is a losing play to move from an XX-vertex to a gg-vertex.

Appendix B Proof of Lemma 3.3

Lemma B.1 (Stick to the Script)

Let the notation k(p)k(p) denote taking pp objects from vertex kk in a turn. Then, after the plays (,Xy(1),a(1))(\ldots,X_{y}(1),a(1)) any play deviating from the following sequences is a losing move:
(b(1),e(1),f(1),d(1),g(1),Xz(1))(b(1),e(1),f(1),d(1),g(1),X_{z}(1))
(b(1),e(1),f(1),d(1),c(1),d(1),g(1),Xz(1))(b(1),e(1),f(1),d(1),c(1),d(1),g(1),X_{z}(1)).

We continue by analyzing all possible deviations from these sequences and show that they result in a loss. In this claim, we will refer to the deviating player as the foe and the other player as the hero. We will show that the foe loses in each case. It may be helpful to refer to Figure 2 during these case descriptions.

  • 1.

    c(1)c(1) instead of e(1)e(1). Here we have two subcases: either moving from gg to XzX_{z} is a winning (result is a 𝒫{\cal P}-position) or losing (a 𝒩{\cal N}-position) move. If it’s in 𝒩{\cal N}, then the hero can respond to c(1)c(1) with d(1)d(1). If the foe then chooses g(1)g(1), the hero can take the remaining stick in dd with d(1)d(1). f(1)f(1) and e(1)e(1) must follow with the hero winning. If the foe instead chooses f(1)f(1), the hero can win instantly by choosing e(1)e(1). For the foe’s last chance, they could select d(1)d(1), removing the other stick from dd. The hero should respond with g(1)g(1). The foe will lose by selecting f(1)f(1), because the hero will win at e(1)e(1), but the foe will also lose with Xz(1)X_{z}(1), an 𝒩{\cal N}-position as assumed.

    If Xz(1)X_{z}(1) is instead leaves the board in 𝒫{\cal P}, the hero should respond to c(1)c(1) with d(2)d(2). The foe could choose f(1)f(1), but the hero can then win with e(1)e(1). Instead, the foe can choose g(1)g(1) in which case the hero can choose Xz(1)X_{z}(1) and win, as assumed.

  • 2.

    d(2)d(2) instead of (the first) d(1)d(1). Here the hero has a simple move to win. By taking c(1)c(1) there are no further moves and the foe has lost.

  • 3.

    g(1)g(1) instead of (the first) d(1)d(1). The hero can respond with d(1)d(1). This leaves two different adjacent vertices with 1 object apiece and no other adjacent non-empty vertices. Either move by the foe results in one remaining move and a win for the hero.

  • 4.

    d(1)d(1) instead of c(1)c(1). The hero can respond with c(1)c(1) and win.

  • 5.

    d(1)d(1) instead of Xz(1)X_{z}(1). This cannot happen in the second sequence, but if it happens in the first, the hero can respond with c(1)c(1) and win.

Thus, any deviation from the two sequences specified in the claim puts the game in an 𝒩{\cal N}-position.