22048 IS (PSPACE) H ARD , BUT S OMETIMES E ASY
Rahul Mehta ∗ Princeton University [email protected]
August 28, 2014
Abstract
We prove that a variant of 2048, a popular online puzzle game, is PSPACE-Complete. Ourhardness result holds for a version of the problem where the player has oracle access to the computerplayer’s moves. Specifically, we show that for an n × n game board G , computing a sequence ofmoves to reach a particular configuration C from an initial configuration C is PSPACE-Complete.Our reduction is from Nondeterministic Constraint Logic (NCL).We also show that determining whether or not there exists a fixed sequence of moves S ∈ {⇑ , ⇓ , ⇐ , ⇒} k of length k that results in a winning configuration for an n × n game board is fixed-parameter tractable (FPT). We describe an algorithm to solve this problem in O (4 k n ) time.
1. Introduction
The online video game 2048 [1] (read as “twenty-forty-eight”) has recently gained a great deal of pop-ularity. Played on a × game board with tiles containing positive powers of 2, the goal of the game isto combine equally-valued tiles to reach the 2048 tile.More specifically, the game board begins with an initial configuration of two tiles, of value or ,placed at arbitrary locations on the grid. The player then selects to move UP , DOWN , LEFT , or
RIGHT (denoted as {⇑ , ⇓ , ⇐ , ⇒} ). Each move shifts all tiles on the grid in the direction chosen. If two adjacenttiles have the same value (i.e. i for some i > ), they combine, and the single resulting tile after thecombination will have value i +1 . Following the player’s move, the computer places a tile of value or at a random free location on the board. Figure 1 outlines the first six moves of a game of 2048.Observe that if a tile’s row or column in the direction of the move x ∈ {⇑ , ⇓ , ⇐ , ⇒} is unobstructed,the tile will slide as far as possible on the grid.Sliding tile games of a similar variety have been well-studied, both in the realm of puzzles as well asin algorithmic motion planning. Most recently, Demaine and Hearn ([4, 2]) proved that several problemsincluding solving sliding-block puzzles, Rush Hour, Sokoban, and Push-2-F are all PSPACE-Complete.To accomplish this, they developed the Nondeterministic Constraint Logic (NCL) model of computationas a generic framework for PSPACE-Hardness results (see [4]). We first define some basic concepts and terms that we will use throughout the paper, and then proceedto outline the two problems that will be studied in subsequent sections. When we refer to a game board G , we are referring to an n × n grid that can take on particular configurations, as described below; ∗ Department of Computer Science, 35 Olden St., Princeton University, Princeton, NJ, 08540. a r X i v : . [ c s . CC ] A ug nitial State ⇓ ⇒⇓ ⇒ ⇒ Figure 1: The first six moves of a game of 2048.
Definition 1.
Given a game board G , a configuration of the board C : [ n ] × [ n ] → { (cid:96) | (cid:96) ∈ Z > } ∪ { } is a function that maps each of the n locations on the game board to a positive power of , or . For aparticular configuration C , a location ( i, j ) is empty if C ( i, j ) = 0 .We describe locations in row-major order; for example, in the final (lower-right) configuration inFigure 1, the tile of value 4 is located at (1 , , the two tiles of value at (3 , and (4 , , and the tile ofvalue at (4 , .We study two variants of 2048; first, we examine the complexity of computing a sequence of movesto reach a particular configuration C from an initial configuration C , and second, we exhibit an efficientalgorithm for determining whether a winning sequence of moves of length k exists, starting from aparticular initial configuration C . In order to formalize these two variants of the problem, we firstrecast 2048 as a two-player game between the human player A and the computer adversary B ; Definition 2 (The Game) . Given an initial configuration C of an n × n game board G , consider thefollowing game between adversaries A and B , with a goal configuration C f . The game is played asfollows;(1) A makes a move x ∈ {⇑ , ⇓ , ⇐ , ⇒} . (2) B places one or more tiles of value (cid:96) , . . . , (cid:96) k ( (cid:96) , . . . , (cid:96) k ∈ Z > ) at locations ( i , j ) , . . . , ( i k , j k ) . This game is played until one of two conditions occur; (1) the goal configuration C f is reached, and A wins, or (2) there are no more moves that A can make (i.e. for any x ∈ {⇑ , ⇓ , ⇐ , ⇒} , applying x willnot change the configuration of the game board). In this case, B wins. Such a configuration is shown inFigure 2 We now introduce the two problems that will be studied in this paper. Both variants that we study giveplayer A perfect knowledge ; that is, given a configuration C and a move x ∈ {⇑ , ⇓ , ⇐ , ⇒} , A has oracleaccess to B ’s move if x is applied to a board G with configuration C . This is denoted as B ( C , x ) . Theresponse is a set of 3-tuples of the form { ( i , j , (cid:96) ) , . . . , ( i k , j k , (cid:96) k ) } , where for index t , ( i t , j t ) is thelocation of the added tile of value (cid:96) t . Accordingly, an instance of 2048-G AME is uniquely determined2igure 2: An example of a configuration satisfying (2) (game over).by (1) the initial configuration C , and (2) the responses of the computer B . In a sense, this is an easierversion of the more general problem – it is interesting to note that our hardness result still holds despitethe additional information available to A . Problem 1 (2048-G
AME ) . Given an n × n game board G and an oracle B to the computer player, doesthere exist a sequence of moves S ∈ {⇑ , ⇓ , ⇐ , ⇒} ∗ such that C is reached from C ?In Section 3, we prove the following theorem: Claim 1 (Theorem 1) . AME is PSPACE-Complete.
We then examine the related problem of determining whether or not there exists a fixed-length se-quence of moves that results in a winning configuration.
Problem 2 (2048- k -M OVES ) . Given an n × n game board G , an oracle B to the computer player, anda goal tile m (for some m > ), does there exist a sequence of moves S ∈ {⇑ , ⇓ , ⇐ , ⇒} k of length k such that after k moves, the board is in a winning configuration C f (that is, C f ( i, j ) = 2 m , for some i and j )?When the problem is paramaterized in this manner (limiting the number of moves to some constant k > ), we show that in fact 2048- k -M OVES is fixed-parameter tractable (FPT). In Section 4, we provethe following theorem:
Claim 2 (Theorem 2) . Given an n × n game board G , k -M OVES is solvable in O (4 k n ) time. Before concluding the section, we show that the value of the maximum tile is monotonically nonde-creasing. For a configuration C , we denote the tile of maximum value as max( C ) . Lemma 1.
For a game board G , a configuration C i , and the subsequent configuration C i +1 , max( C i ) ≤ max( C i +1 ) .Proof. Immediate from the combination rule of the game. When adjacent tiles of value (cid:96) combine, theyform a single tile of value (cid:96) +1 . Consider two cases; (1) the maximum tile does not change value, or(2) the maximum valued tile does change value. If (1) occurs, then we have equality, since max( C i ) isleft unchanged. For (2), let max( C i ) = 2 (cid:96) , for some (cid:96) > . The only case in which the tile in questionchanges is if it combines with a tile of the same value. By our previous observation, two adjacent tilesof value (cid:96) will combine to form a single tile of value (cid:96) +1 . Thus, we have max( C i +1 ) = 2 (cid:96) +1 > (cid:96) =max( C i ) , which completes the proof. 3he remainder of the paper is organized as follows; Section 2 describes the Nondeterministic Con-straint Logic (NCL) model of computation due to Demaine and Hearn [4], and specifically, the frame-work it provides for PSPACE-Hardness reductions. Section 3 describes in detail our reduction fromNCL to 2048-G AME . Finally, Section 4 describes an efficient algorithm to solve 2048- k -M OVES ,which establishes that it is fixed-parameter tractable (FPT).
2. Nondeterministic Constraint Logic (NCL)
We will now outline the Nondeterministic Constraint Logic (NCL) model of computation, which was de-veloped by Demaine and Hearn [4] as a general framework for proving PSPACE-Completeness results.All of their PSPACE-Completeness results are reductions from Quantified Boolean Formula (QBF), awell-known PSPACE-Complete problem [3].An NCL machine consists of a constraint graph , which is an arbitrary undirected graph G = ( V, E ) with edge weights w : E → { , } (all edges have weight 1 or 2). A configuration of the machine is anorientation of the edges of G . A configuration is valid if for each vertex v ∈ V , the sum of incomingedge weights is at least . A move is made by reversing a single edge in the network such that theconfiguration remains valid.A natural question to ask is whether or not a particular edge can be reversed after a sequence ofmoves (C ONFIG - TO -E DGE ), or alternately, whether there exists a sequence of moves to reach a partic-ular configuration from some initial configuration (C
ONFIG - TO -C ONFIG ). Both of these problems arePSPACE-Complete (see [4]). This hardness result still holds when we restrict the vertices to those withincident edge weights 1,1, and 2, and those with 1, 1, and 1. These vertices are illustrated in Figure 3(taken from [4]): (a) A ND (b) O R Figure 3: NCL A ND and O R VerticesRed edges have weight 1, and blue edges have weight 2. For an orientation of the edges, observethat for vertex (a), the blue edge can point out if and only if the two red edges are pointing in (to satisfythe previously-mentioned constraint that the in-flow on all vertices must be at least 2). Similarly, for (b),the top blue edge can point outward if and only if one of the bottom edges is pointing in. Thus, we canclearly see that (a) functions as an A ND gate of sorts and (b) as an O R gate.Demaine and Hearn in fact strengthen this result even further, and show that C ONFIG - TO -E DGE and C
ONFIG - TO -C ONFIG both remain PSPACE-Complete when the constraint graph G is planar. Thus,proving a game to be PSPACE-Hard reduces to simply constructing NCL A ND and O R gadgets fromthe problem in question, and then demonstrating how to use them to construct arbitrary planar constraintgraphs.
3. The Reduction
In this section, we outline the reduction from planar NCL to 2048-G
AME . We begin by constructingNCL A ND and O R vertex gadgets with × subinstances of 2048-G AME , and then demonstrate how to4
B C (a) j -A ND Gadget
A B C (b) j -O R Gadget (c) (2 , Lattice
Figure 4: NCL A ND and O R Vertices. Tiles with labels j , j + 1 , etc. correspond to values j , j +1 , etc.In both gadgets, connections A and B are facing out , while connection C is facing in .connect them together to make arbitrary planar constraint graphs. This section will prove the followingtheorem; Theorem 1.
AME is PSPACE-Complete.
Before outlining the reduction, however, we must show that 2048-G
AME is in fact contained inPSPACE. A rigorous proof of this fact is given below;
Lemma 2.
AME ∈ PSPACE.Proof.
We begin by giving an NPSPACE algorithm to decide 2048-G
AME . For an n × n game board G ,we clearly can represent the current configuration of the game board in polynomial space. Starting withan initial configuration C and a goal configuration C f , we can nondeterministically select a move x ∈{⇑ , ⇓ , ⇐ , ⇒} at each step (without consulting the oracle to B ), and update the previous configurationwith the current one. We repeat the above procedure until one of the following conditions occurs;(1) The goal configuration C f is reached, in which case output YES .(2) There are no possible moves from the current configuration C , and it is not the goal configuration(game over); output NO .(3) For the current configuration C , max( C ) > max( C f ) , in which case output NO .Checking for these three conditions guarantees that the algorithm will terminate. Specifically, forcondition (3), if there is a tile of value greater than the maximum-valued tile in the goal configuration C f ,then C f is unreachable from the current configuration C . This is immediate from Lemma 1. Thus, wehave an NPSPACE algorithm for deciding 2048-G AME . This is easily converted to a PSPACE algorithmdue to Savitch’s Theorem [7], completing our proof. ND and O R Gadgets
In order to prove Theorem 1, we first construct NCL A ND and O R gadgets from small instances of2048-G AME , and then show how to connect them into arbitrary planar graphs.Figure 4 shows two examples of A ND and O R vertex gadgets. Since the tiles in 2048 are assigneda numerical value, an added difficulty presents itself when connecting vertex gadgets together (sincethe gadgets rely on adjacent tiles containing specific powers of 2, including the connectors to “activate”each vertex gadget). Thus, we introduce the notion of a j -O R and j -A ND gadget, as is shown in Figure5. The labels A, B, and C refer to the connection points for each gadget; these labels correspond to theedges for the NCL vertices in Figure 3.A connection A or B is considered to be activated for a j -A ND or j -O R gadget if the tile has valuenot equal to j – this directly corresponds to reversing an edge in an NCL constraint graph. For bothA ND and O R gadgets, A and B are facing in if the corresponding tile is activated, and out otherwise.The tile labeled C is also considered to be activated if its value has increased; thus, for a j -A ND gadget, C is activated if the tile a value not equal to j +5 or greater, and for a j -O R gadget, if the tile hasnot equal to j +4 . Accordingly, C is facing out if it is activated, and in otherwise.Before proving the correctness of the two gadgets, we outline the use for the gadget in Figure 4(c);the (2 , Lattice. This structure has an important property; for any move x ∈ {⇑ , ⇓ , ⇐ , ⇒} , theconfiguration remains unchanged. Thus, it is perfectly rigid. We will embed all of the other gadgets andconnection pieces into the (2 , lattice so as to prevent large portions of the game board shifting whena move is made by A .Additionally, whenever a square of the game board is uncovered by a move, the oracle B , in thisconstruction, will respond by placing a tile t ∈ { , } in the vacant location, depending on which tilecorrectly continues the (2 , lattice pattern. This is where the perfect knowledge comes into play; weare allowed to “program” player B ’s responses to various moves, which greatly simplifies parts of thereduction. Lemma 3.
For a j - A ND vertex gadget, C can face out if and only if A and B are facing in.Proof. First, we observe that the tiles in the j -A ND gadget will not shift at all unless either A or B isactivated, for any move x ∈ {⇑ , ⇓ , ⇐ , ⇒} , since there are no adjacent tiles of the same value.Next, we demonstrate that for any sequence of moves which results in C activating, A and B mustboth be activated. We claim that for C to be activated in configuration C i , C i − (3 ,
2) = 2 j +3 . That is,location (3 , must contain j +3 before C can be activated. This is summarized in the diagram below; C = C i (4 ,
4) = 2 j +6 C i − (4 ,
3) = 2 j +5 C i − (4 ,
2) = 2 j +4 C i − (3 ,
2) = 2 j +3 → → → Correctness of the diagram can be shown inductively, by assuming that the value in C k − is nec-essary for the specified value in C k to appear. Thus, proving the lemma reduces to determining theconditions under which there is a C such that C (3 ,
2) = 2 j +3 .Since we have already shown that A or B must be activated for any movement within the gadget tooccur, it suffices to prove that only activating A or B does not suffice. Without loss of generality, assumethat A is activated but not B (the proof of the opposite assumption follows the exact same reasoning). Ifonly A is activated, then for some C , C (3 ,
1) = 2 j +1 , and there exists a sequence of moves such thatfor some subsequent C (cid:48) , C (cid:48) (3 ,
1) = 2 j +2 . However, C (cid:48) (3 ,
2) = 2 j +1 , so no combination is possible toachieve C (cid:48)(cid:48) (3 ,
2) = 2 j +3 , as is desired. Thus, A and B must be activated for C to be activated, whichconcludes the proof.An example of a sequence of moves to activate C for a -A ND vertex gadget is in Appendix A(Figure 12). Now, we turn our attention to the j -O R vertex. The proof closely follows that of Lemma 3. Lemma 4.
For a j - O R vertex gadget, C can face out if and only if A or B are facing in.Proof. Again, we see that tiles in the j -O R gadget will not shift unless A or B are activated, for x ∈ {⇑ , ⇓ , ⇐ , ⇒} , since no adjacent tiles in the gadget’s initial configuration are of the same value.Next, we show that for any sequence of moves resulting in the activation of C , either A or B mustbe activated. Suppose C is activated in configuration C i . Backtracking along the tiles in the gadget,we show that for C to be activated in C i , then in C i − , A or B must be activated. The diagram below6escribes the required configurations. The correctness of the diagram is proven inductively by assumingthat the value(s) described in C k − is a necessary condition for the value(s) in C k to be reached. C = C i (4 ,
4) = 2 j +5 C i − (4 ,
3) = 2 j +4 C i − (3 ,
3) = 2 j +3 C i − (3 ,
2) = 2 j +2 C i − (2 ,
3) = 2 j +2 C i − (3 ,
1) = 2 j +1 = A C i − (1 ,
3) = 2 j +1 = B → → →→ → → The validity of the moves in the diagram can be verified by inspection of the j -O R gadget in Figure4(b). The fact that C i − ( A ) = 2 j +1 or C i − ( B ) = 2 j +1 must hold for C i ( C ) = 2 j +5 is immediate fromthe diagram; we conclude that C can be activated, and thus face out, if and only if A or B is activated,and therefore facing in.An example of a sequence of moves to activate C for a -O R vertex gadget is in Appendix A (Figure13). ND /O R Gadget
Now that we have described the NCL A ND and O R gadgets, we have one final vertex gadget left todefine. Observe that for either the NCL j -A ND or j -O R gadget, once it is activated, the configurationcannot be reversed; that is, once a gadget is set in a particular configuration, it cannot be altered. Thus,if the initial configuration of an NCL machine C contains an activated A ND vertex, and the goal is toreverse one of the incoming edges to the vertex, then this is impossible in our vertex gadget constructionbut possible in NCL.To alleviate this, we construct a final gadget, namely the Reversible j -A ND /O R gadget. This gadgetis placed in an instance of 2048-G AME when an A ND vertex in the original NCL constraint graph isactivated, or when both edges of weight 1 are entering an O R vertex. The conditions under which aReversible j -A ND /O R gadget is used are outlined in Figure 5. AB C AB C
Activated
And
Activated Or (2 incoming edges) Figure 5: The conditions under which a Reversible j -A ND /O R is used in place of a normal vertex gadget.We now introduce the gadget. A and B are considered to be activated if their value is not equalto j +4 . Thus, in the initial configuration they are facing in , and when activated, are facing out . C isactivated when its value is not equal to j ; when it is activated, it is facing in , and when it is not, it isfacing out . The gadget is defined in Figure 6.One specific that we note about the gadget is it’s behavior after the tile at location (2 , (in theinitial configuration, j +2 ) is shifted from that location, the computer player B places a new tile of value j +3 at (2 , . That way, both A and B can be activated, and therefore face out. However, it is alsopossible for either A or B to face out, but not the other. In fact, we prove that all possible configurationsof the vertex gadgets in Figure 5 are reachable with the Reversible j -A ND /O R gadget. These reachableconfigurations are listed in Figure 7 below;We now prove that these configurations are reachable by exhibiting sequences of moves;7 AB Figure 6: The Reversible j -A ND /O R vertex gadget. AB C AB C AB C AB C (a) (b) (c) (d)
Figure 7: Possible configurations reachable by Activated A ND and O R vertices with two incomingedges. Lemma 5.
The configurations listed in Figure 7 are reachable for any given Reversible j - A ND / O R gadget.Proof. The following diagram depicts the Reversible j -A ND /O R gadget in the four configurations listedin Figure 7. The proof of the lemma below contains the sequences of moves necessary to reach eachconfiguration; this can be verified by inspection. The diagram shows the configurations for a Reversible j -A ND /O R gadget.(a) (b) (c) (d)We now give sequences of moves to achieve the given configurations. The sequences can easily beverified by inspection of the gadget; (a) ⇒ , ⇐ , ⇐ (b) ⇒ , ⇒ , ⇒ , ⇑ , ⇒ , ⇑ , ⇑ (c) ⇒ , ⇒ , ⇒ , ⇓ , ⇓ (d) ⇒ , ⇒ , ⇒ , ⇑ , ⇒ , ⇓ , ⇓ . Thus, the configurations in Figure 7 are all reachable by the Reversible j -A ND /O R vertex, completing the proof. We now describe how to construct arbitrary planar graphs from the NCL vertex gadgets. The vertexgadgets, as well as the connection pieces described in this section, are embedded in an arbitrarily largegame board G comprised of × sub-instances. Such a layout is shown in Figure 88 .. ... Figure 8: An arbitrarily large game board G comprised of × sub-instances of 2048-G AME .There is also a second issue that we must navigate. Due to the vertex gadgets’ connection tiles ( A , B , and C ) containing numerical values of , connecting arbitrary vertices is not as simple as in otherreductions from NCL.We address this by turning to the famed Four Color Theorem (see [5] for more detail regardingseveral proofs). Since we are constructing planar NCL constraint graphs, we can turn to the FourColor Theorem, and in particular, an O ( n ) algorithm by Robertson, et. al. [6] to find a four coloring.By assigning colors to the vertices in the constraint graph, we are able to specify the value of j forthe j -A ND , j -O R , and Reversible j -A ND /O R gadgets. For each of the four colors, let j = 4 , , , respectively. Note that the diagrams in Appendix A are for NCL gadgets with j = 4 . The k - k (cid:48) -C ONNECTION
Gadget
We now describe a connection piece to connect gadgets with differingvalues of j . We call this a k - k (cid:48) -C ONNECTION piece, and its layout in our context of the × sub-instanceof 2048-G AME . The diagram is contained in Figure 9Figure 9: The k - k (cid:48) -C ONNECTION gadget.The gadget is attachable to a gadget that will terminate with value k on any one of its output edges( C for normal A ND /O R gadgets, and A and B for the Reversible A ND /O R gadget). We note that thisgadget can be shifted vertically within the × sub-instance to yield connection pieces for output tilesat varying locations.The major “trick,” so to speak, lies in the gadget’s activation sequence. When the tile with initialvalue of k + 4 at (3 , vacates that location, the computer player B will place a tile of value k (cid:48) − at (3 , . Then, the tile is free to combine with the second tile of value k (cid:48) − at (3 , , which will result in (3 , having the value k (cid:48) , which in turn implies that it will activate a gadget with j = k (cid:48) .9 emma 6. The k - k (cid:48) - C ONNECTION gadget contains an activation sequence such that an outgoing tileof value k will activate a gadget with j = k (cid:48) .Proof. We will exhibit an activation sequence of the gadget to demonstrate that it indeed fulfills itspromise, namely that it will activate an NCL vertex gadget with j = k (cid:48) if the outgoing tile of the previ-ous gadget has value k . This is exhibited with values k = 7 and k (cid:48) = 14 . Initial State ⇒ ⇒ ⇒ ⇓⇒
The k -L INE and k -C ORNER
Pieces
We finally describe two additional connection pieces which willfinish our construction of arbitrary planar graphs. These are the k -L INE and k -C ORNER gadgets, andare outlined below in Figure 10; (a) k -L INE (b) k -C ORNER
Figure 10: k -L INE and k -C ORNER connection pieces.
Now that we have finished describing the components of the reduction, we are ready to prove the maintheorem (that 2048-G
AME is PSPACE-Complete);
Proof of Theorem 1.
Immediate from the construction described in Section 3. Specifically, we first finda valid four-coloring of the NCL constraint graph G using the algorithm due to Robertson, et. al. [6],and then follow the procedure outlined in Section 3.3 to connect the NCL vertex gadgets together usinga combination of k - k (cid:48) -C ONNECTION , k -L INE , and k -C ORNER pieces.Next, we must orient the edes of the constraint graph G according to its current configuration. Weset the tiles in the vertex gadgets accordingly; if an edge corresponds to an activated configuration, theappropriate tile value is set on the vertex gadget (either at A , B , or C ).10e have now shown how to convert an orientation of an arbitrary planar constraint graph into an in-stance of 2048-G AME ; if we can decide 2048-G
AME , then we can decide C
ONFIG - TO -C ONFIG . Thus,2048-G
AME is PSPACE-Hard, and by Lemma 2, 2048-G
AME ∈ PSPACE. Therefore, we concludethat 2048-G
AME is PSPACE-Complete.
4. An FPT Algorithm for 2048- k -M OVES
On one hand, our paper shows that the most natural problem that emerges from 2048 is intractable.However, we show in this section that another variant of the game is fixed-parameter tractable (FPT).Recall that 2048- k -M OVES is the problem of deciding whether or not there exists a sequence of movesof length k S ∈ {⇑ , ⇓ , ⇐ , ⇒} k such that after each of the moves is executed, the board will be in awinning configuration.This problem is decidable in polynomial time due to the fact that the number of moves is constant.While the constant may be quite large, it does not change the asymptotic running time of our algorithm.First, we introduce the notion of a game tree ; C C C C C C k C k C k C k C k C k C k C k C k − k C k − k C k − k C k k ⇑ ⇓ ⇐ ⇒⇑ ⇓ ⇐ ⇒ ⇑ ⇓ ⇐ ⇒ ⇑ ⇓ ⇐ ⇒ ... ... . . . Figure 11: A game tree for an instance of 2048- k -M OVES of depth k .Each vertex of the tree that can be reached by a path of length (cid:96) represents a possible configurationof the game after (cid:96) moves. The tree can be constructed in O (4 k ) time by querying the oracle for the k possible sequences of moves S ∈ {⇑ , ⇓ , ⇐ , ⇒} k . Our algorithm, in essence, traverses the vertices ofthe game tree and halts when a winning configuration is found, or if there are none. We are now readyto prove the second result of our paper; Theorem 2.
Given an n × n game board G , k -M OVES is solvable in O (4 k n ) time.Proof. The algorithm can perform any recursive traversal of the game tree to explore the leaf nodes. Wefirst observe that the game tree is in fact a -ary tree. It is well-known that for a d -ary tree of depth (cid:96) ,the number of leaf nodes is d (cid:96) . Thus, for our -ary tree of depth k , there are k leaf nodes.When each leaf is visited, the value of each of the n tiles on the game board is compared to m , thegoal tile. If they are equal, halt and output YES and the configuration C f . If a game board is in a gameover configuration (i.e. the subsequent configurations of the four children nodes are precisely equal tothe current configuration), terminate the recursion for that branch of the tree.Since we check each of the n tiles of G at each of the k leaf nodes, the worst-case running time ofthe procedure is O (4 k n ) , showing that 2048- k -M OVES ∈ FPT.11 eferences [1] Gabriele Cirulli, , http://gabrielecirulli.github.io/2048/ , Accessed: 2014-07-02.[2] Erik D. Demaine, Robert A. Hearn, and Michael Hoffmann, Push-2-f is pspace-complete , CCCG,2002, pp. 31–35.[3] Michael R. Garey and David S. Johnson,
Computers and intractability: A guide to the theory ofnp-completeness , W. H. Freeman & Co., New York, NY, USA, 1979.[4] Robert A. Hearn and Erik D. Demaine,
Pspace-completeness of sliding-block puzzles and otherproblems through the nondeterministic constraint logic model of computation , Theor. Comput. Sci. (2005), no. 1-2, 72–96.[5] Jir´ı Matousek and Jaroslav Nesetril,
Invitation to discrete mathematics (2. ed.) , Oxford UniversityPress, 2009.[6] Neil Robertson, Daniel P. Sanders, Paul D. Seymour, and Robin Thomas,
The four-colour theorem ,J. Comb. Theory, Ser. B (1997), no. 1, 2–44.[7] Walter J. Savitch, Relationships between nondeterministic and deterministic tape complexities , J.Comput. Syst. Sci. (1970), no. 2, 177–192. A. Activation Sequences for A ND and O R Gadgets
Initial State ⇓ ⇒ ⇓⇓ ⇒ ⇓ ⇒⇒