Quantcast
Channel: mkoconnor – XOR’s Hammer
Viewing all articles
Browse latest Browse all 50

How to Show that Games are Hard

$
0
0

Peg Solitaire is a pretty popular game, often found in restaurants (including Cracker Barrel, if I remember correctly). It’s also NP-complete (by which I mean determining a winning strategy given the initial set-up is an NP-complete problem). You may have also heard of computational complexity results for Minesweeper (see here, for example). There are a number of other results showing that various popular games are complete for some complexity class.

But what if you come across a new game, which no computer scientist has heard of yet? Well, you’re in luck, as Robert Hearn, in his thesis, formulated a framework called Constraint Logic intended to make it easy to prove complexity results for games.

Games are classified by Hearn by whether they are zero-, one-, or two-player, and further by whether or not their length is polynomially bounded by their initial setup. (Hearn also covers team games, which I’ll cover in a later post.)

Recall that by saying a game is in a complexity class I mean that the problem of, given an initial setup for the game, determining whether or not there is a winning strategy for a given player (if any) and, if so, what that strategy is, is in that complexity class. Thus, when we talk about a game being in a particular complexity class, we are always implicitly talking about a way of generalizing the game to different initial setups. For example, the statement that Go is in EXPTIME means that the problem of, given n, determining a winning strategy for Go on an n \times n board is in EXPTIME.

  • An example of a zero-player bounded-length game is the game Clock Solitaire. Once the cards are dealt, the game is completely deterministic (this makes it zero-player), and furthermore, each card is turned over at most once (this makes it bounded). Games of this sort are in the complexity class P.
  • An example of a zero-player unbounded game is Conway’s Game of Life. Games of this sort tend to be in PSPACE. Conway’s game of life is PSPACE-complete.
  • An example of a one-player bounded-length game is Peg Solitaire, mentioned above. It is bounded since each move removes a peg, and there is no way to get a peg back. Games of this sort are in NP. Peg Solitaire, as mentioned above, is NP-complete.
  • Examples of one-player unbounded games include Rubik’s Cube and Rush Hour. Games of this sort tend to be in PSPACE. Rush Hour is PSPACE-complete. (There are a couple of different ways of generalizing the Rubik’s Cube to higher dimensions, but I’m not aware of complexity results for any of them. If you know, please leave a comment.)
  • Examples of two-player bounded-length games include Tic-Tac-Toe, John Nash’s game Hex, and Othello. In both cases, the game is of bounded-length since once a player marks a space on the board, it can never be unmarked or marked again. Games of this sort are in PSPACE. Hex and Othello are PSPACE-complete. (As with the Rubik’s cube, there are a couple of different ways to generalize Tic-Tac-Toe to higher dimensions, but I don’t know of any complexity results for them. If you know, please leave a comment.)
  • Examples of two-player unbounded games include many familiar games such as checkers, chess, and go. Games of this type tend to be in EXPTIME. Each of the three games mentioned is EXPTIME-complete.
  • Hearn also defines “team” games, which I will skip in this post.

So what is constraint logic? It’s a single setup which naturally gives examples of games of each of the six types listed above, and furthermore is in each case complete with respect to the associated complexity class. Thus, if you can reduce constraint logic to whichever game you’re interested in, you have a completeness result.

The setup for constraint logic is as follows: The game board is an undirected graph with weights of 1 or 2 on the edges and non-negative integers assigned to the vertices (these non-negative integers are called the minimum inflow of the vertex). A position of the board is an assignment of direction to each edge. The position is legal if, for each vertex, the sum of all the weights of the edges directed towards the vertex is at least the minimum inflow of the vertex. A move is generally reversing the direction of an edge (to give another legal position), and the goal of the game is generally to reverse the direction of a specified edge.

How does this give us each of the six types?

  • To form a zero-player bounded-length game: Suppose given a board position G, and a goal edge E (i.e., G is a directed graph with weights assigned to the edges and non-negative integers assigned to the vertices, and E is an edge of G, and the game is won if the direction of E is reversed). Then let R_0 be the set of edges E_0 such that it’s legal to reverse the direction of E_0. Reverse the direction of all of these edges to get a new position G_1. Let R_1 be the set of all edges E_1 such that it’s legal to reverse the direction of E_1 and E_1 hasn’t been reversed before. Reverse all of those, and so on. Since an edge is reversed at most once, the game is bounded length. (Notice that it might be the case that in reversing some edge in R_i, you make it so that some other edge in R_i can no longer be legally reversed. This can indeed happen, but it is possible to restrict to a subclass of games where this never happens). This game is P-complete.
  • To form a zero-player unbounded length, you essentially do the same thing as above, but remove the restriction that an edge can be reversed at most once. There are some technicalities however, which are too ensure that every time you try to reverse an edge, it is a legal move. This game is PSPACE-complete
  • To form a one-player bounded game: On each turn the player reverses the direction of edge (to form a legal position). Each edge can be reversed at most once. The player wins if he is able to reverse the direction of the pre-specified goal edge. This game is NP-complete.
  • To form a one-player unbounded game: Just as above, except that each edge may be reversed as many times as necessary. This game is PSPACE-complete.
  • To form a two-player bounded-game: Each player has a set of edges which only they may reverse. Each player also has their own target edge. They take turns reversing edges and each edge may be reversed at most once. The first player to reverse their target edge wins. This game is PSPACE-complete
  • To form a two-player unbounded game: Just as above, except that each edge may be reversed an unlimited number of times. This game is EXPTIME-complete.

Part II of Hearn’s thesis (linked above) contains a large number of complexity proofs for games based on these results. Furthermore, he has results which make this endeavor easier: a priori, you would have to reduce any graph to the game in question to prove that it’s complete with respect to the appropriate complexity class. Hearn proves that it suffices to reduce planar graphs which consist solely of AND vertices, which are those of minimum inflow 2 and with exactly three adjacent edges, one of which has weight 2 and two of which have weight 1, and OR vertices, which are those of minimum inflow 2 and with exactly three adjacent edges, all of which have weight 2. (You can interpret games built up from these vertices as a kind of a non-deterministic circuit computation, which is where they get their name.)

For example, consider sliding block puzzles: In a sliding block puzzle, you are given a number of rectangular blocks in a rectangular box. The goal is to slide the blocks around to get one particular block in one particular case. Using Constraint Logic, Hearn, together with his advisor, Erik Demaine (who is amazing, by the way), showed that this was PSPACE-complete. The proof is shown in this figure, reproduced from this paper by Demaine and Hearn:

constraintOn the left is the translation of an AND vertex; on the riht is the translation of an OR vertex. In each case, the three yellow blocks on the border represent the three edges adjacent to the vertex. Reversing the direction of an edge corresponds to either pushing the block in to the square, or pulling it out. The squares are designed so that it is possible to slide the blocks in the interior around so that pushing a yellow block inside is possible iff the corresponding edge reversal is legal.

For more information, see Hearn’s thesis and the paper by Demaine and Hearn linked above, as well as this additional paper by Demaine and Hearn on the subject.


Viewing all articles
Browse latest Browse all 50

Trending Articles