LaserTank is NP-complete
aa r X i v : . [ c s . CC ] A ug LaserTank is NP-complete
Per Alexandersson and Petter Restadh
KTH The Royal Insitute of Technology, 100 44 Stockholm, Sweden [email protected]@kth.se
Abstract.
We show that the classical game
LaserTank is NP -complete, even whenthe tank movement is restricted to a single column and the only blocks appearingon the board are mirrors and solid blocks. We show this by reducing -SAT in-stances to LaserTank puzzles. Keywords:
NP-completeness · LaserTank · 3-SAT
From Wikipedia: “
LaserTank (also known as Laser Tank) is a computer puzzle gamerequiring logical thinking to solve a variety of levels ”. It was first released on the Win-dows platform in 1995, and a similar game was released in 1998 for the graphing cal-culator Texas Instruments Ti-83, under the name
Laser Mayhem . To our knowledge,the complexity of LaserTank has not been studied before, while several other classicalgames have been shown to be NP-complete, NP-hard or PSPACE-complete. For exam-ple, Sokoban [2],
Tetris [3],
Rush Hour [4], and
Minesweeper [5] to list a few.In this short note, we prove the following.
Theorem 1.
LaserTank is NP -complete. It should be noted that one can perhaps apply more general meta-theoretical ap-proaches for puzzle games and planning games in particular, to prove NP-completeness.It is likely that the framework by G. Viglietta [6] — which can be applied to games suchas
Boulder Dash , Pipe Mania and
Starcraft — can successfully be applied to Laser-Tank as well. We opted for a self-contained hands-on approach where 3-SAT is reducedto LaserTank. Furthermore, we only use a small subset of the available pieces in theoriginal game, as well as restrict the movement of the tank in two directions. Theserestrictions have the benefit that they imply that the
Laser Mayhem variant is also NP-complete. A -SAT expression 𝐸 is a conjunction of clauses, where each clause involves exactlythree distinct literals. A literal is either a boolean variable, or its negation. The -SATproblem states: Determine if 𝐸 is satisfiable — that is, there is an assignment of truth values to the variables that makes 𝐸 true. For example, 𝐸 = ( 𝑥 ∨ 𝑦 ∨¬ 𝑧 )∧(¬ 𝑥 ∨¬ 𝑦 ∨¬ 𝑧 )∧( 𝑥 ∨ ¬ 𝑦 ∨ 𝑧 ) is such a conjunction, and the assignment 𝑥, 𝑧 = 𝚝𝚛𝚞𝚎 , 𝑦 = 𝚏𝚊𝚕𝚜𝚎 showsthat 𝐸 is satisfiable. Determining satisfiability of a -SAT expression is an NP-completeproblem [1]. LaserTank is a turn-based single-player puzzle game played on a -dimensional grid(the board ), where in each turn, the player either moves the tank, or fires a laser fromthe tank. The laser interacts with different pieces on the board, and the goal is to hita certain piece with the laser. The pieces we use are mirrors { ◺ , ◹ , ◿ , ◸ } , solidblocks ■ , movable blocks ⊡ , the tank ⌲ , and the goal ⨁ . The tank is the only piecedirectly controlled by the player, and the laser exits the tank from the front, which is thepointy end of ⌲ . In our version, the tank is restricted to sideways movement only, seeExample 1 The tank can fire a laser from the front. If the laser hits a mirror on a slantededge it is reflected. When a mirror is hit on one of the two (non-reflective) short edgesby the laser, the mirror is pushed in the direction of the laser. A movable block is pushedone step if it is hit by the laser. A movable block or a mirror is only pushed if the tiledirectly behind it is empty. The aim of the puzzle is to hit the goal piece with the laser.The solid blocks do not allow lasers or the tank to pass through and they do not movewhen hit by the laser. The following example shows all game mechanics in action. Example 1.
Here is a small instance of the problem, with a step-by-step solution. Thetank fires a laser which moves a mirror (1), then takes one step sideways, (2). It thenshoots a laser at the movable block (3), and finally moves in position to have a clear shotof the goal (4). ■ ■ ■ ■ ■⌲ ◸ ◹ ⊡ ⨁ ◿ ■ ■ ■ ■ ■ (1) ←←←←←←←←←←←→ ■ ■ ■ ■ ■⌲ ◸ ◹ ⊡ ⨁ ◿ ■ ■ ■ ■ ■ (2) ←←←←←←←←←←←→ ■ ■ ■ ■ ■ ◸ ◹ ⌲ ⊡ ⨁ ◿ ■ ■ ■ ■ ■ (3) ←←←←←←←←←←←→ ■ ■ ■ ■ ■ ◸ ◹ ⌲ ⊡ ⨁ ◿ ■ ■ ■ ■ ■ (4) ←←←←←←←←←←←→ ■ ■ ■ ■ ■ ◸ ◹ ⊡ ⨁ ⌲ ◿ ■ ■ ■ ■ ■ Our goal is now to construct puzzles which imitates an instance of -SAT. We em-ploy so called gadgets that emulate boolean operations. Below, we let ⤑ , ⤑ indicate theinputs to the gadgets (considered as boolean variables), and { ⤑ ∗ , ⤑ ∗ } indicate inputs thatare always available as clear shots from the tank. The latter are used for producing theoutput of the gadget. The and gadget . The configuration in Figure 1a serves as our and -gadget. We needto shoot through both 𝐴 and 𝐵 in order to allow for 𝐴 ∧ 𝐵 = 𝑋 as output. Notice thatthe two movable blocks can only be moved up, right and down. If we want the gadget toproduce an output through 𝑋 , all movable blocks must be moved out of the way. Thiscan only be accomplished if the movable block must have been moved to the right viaactivation from both 𝐴 and 𝐵 , which shows that the gadget is indeed an and -gadget. The and -gadget can easily be generalized to more than two inputs. For a complete list of pieces available in the official game, seehttps://lasertanksolutions.blogspot.com/p/in-my-opinionlaser-tank-is-best-logic.htmlaserTank is NP-complete 3 ■ ■ ■■ ◸ → 𝑋 ■ ■ 𝐵 ⤑ ⊡ ■■ ■ 𝐴 ⤑ ⊡ ■■ ■ ⤑ ∗ ◿ ■■ ■ ■ (a) AND 𝐴 𝐵 𝐶 ■ ⤑ ■ ⤑ ■ ⤑ ■■ ◸ ■ ◸ ■ ◸ ■■ → 𝑋 ⤑ ∗ ◿ ■ ⤑ ∗ ◿ ■ ⤑ ∗ ◿ ■ ■ ■ ■ ■ (b) THREE-OR ■ ■ ■ ■ 𝑋 ⤑ ∗ ◹ ■ ■■ ■ ◸ → ¬ 𝑋 ¬ 𝑋 ⤑ ∗ ⊡ ◿ ■■ ■ ■■ ◺ → 𝑋 ■ ■ ■ ■ (c) LITERAL ⤑ ∗ ■ ◹ 𝑋 ⤑ ◸ ◿ ↓ (d) SWITCH Fig. 1.
The and-gadget, three-or-gadget, literal-gadget, and switch-gadget.
The three-or gadget is depicted in Figure 1b. If either of the inputs 𝐴 , 𝐵 or 𝐶 areavailable, then 𝑋 allows for output. The only way to produce output from 𝑋 is to movea ◸ to the same row as 𝑋 . The ◸ can only be moved into that row from above and thuswe must have some input from 𝐴 , 𝐵 or 𝐶 in order for a laser to pass out through 𝑋 . Thusthe three-or gadget works the way intended. The literal gadget is depicted in Figure 1c. This gadget emulates a literal, withtwo different mutually exclusive outputs depending on the choice of value of the literal.To unlock 𝑋 as output, fire once through ¬ 𝑋 first. This moves the movable block out ofthe way but prevents ¬ 𝑋 from being available as output. Similarly for ¬ 𝑋 . The switch gadget is depicted in Figure 1d. The switch -gadget is our main build-ing block for encoding an instance of a -SAT problem. It allows for the input 𝑋 to beavailable first as output to the right, then redirected down. This allows 𝑋 to be used inmultiple or -clauses. Example 2.
In the puzzle in Figure 2, only a single “input”, 𝑋 , is available. However,with the switches we can redirect input 𝑋 to activate the and gadget. Notice the two ◹ pieces that are required to activate the switches and that the rightmost switch gadgetmust be used first in order to solve the puzzle. This is also true in the general setup,where switches should be used from right to left. A 3-SAT expression may now be encoded as a LaserTank puzzle as follows. There is one literal -gadget for each variable appearing in the expression, a three-or-gadget foreach or -clause, and a single and -gadget with multiple inputs is used to bind all together.The puzzle is designed such that the output of the and -gadget is the only way to hit thegoal. The general layout of such a puzzle is shown in Figure 2. For each three-or-clause inthe -SAT expression, three switches are placed on the board corresponding to the threeliterals involved. In other words, the clauses of the -SAT expression are encoded via switch -gadgets. The switches can always be activated via the ◹ pieces at the top of theboard as in Figure 2. As a concrete example, the expression ( 𝐴 ∨ 𝐵 ∨ ¬ 𝐶 ) ∧ ( 𝐴 ∨ ¬ 𝐵 ∨ 𝐶 ) is encoded as the puzzle shown in Figure 3. P. Alexandersson, P. Restadh ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■⌲ ◹ ■ ■ ◹ ■ ■■ ■ ■ ■■ ■ ■ ■ ◹ ■ ◹ ■ 𝑋 ⤑ ∗ ■■ ■ ■ ◸ ◿ ◸ ◿ ■ ◹ ■ ■■ ■ ■ ■ ■ ■ ■■ ◺ ⊡ ⊡ ◹ ■■ ■ ■ ■ ■ ■ ■■ ■ ■ ⨁ ■■ ■ ■ ■ ■ ■ ■ ■ ■ ■ ■ 𝑋 𝑋 ⋮ 𝑋 𝑛 𝙾𝚁 𝙾𝚁 ⋱ 𝙾𝚁𝙰𝙽𝙳 ⌲ ◹◹◹◹◹◹ ⨁ Fig. 2.
Left: A small puzzle showing the use of two switch -gadgets and one and -gadget. Right:Layout of a general -SAT puzzle. Above each or -gadget are three switches, corresponding to thethree literals involved on the or-clause. The following lemma shows that solving LaserTank puzzles can be done in polyno-mial time with a non-deterministic Turing machine. Hence LaserTank is in NP . Lemma 1.
A solution consisting of 𝑘 steps to a LaserTank puzzle on a board of size 𝑛 can be verified in time 𝑂 ( 𝑘𝑛 ) .Proof. It is straightforward to show that the laser movement is time-reversible. Thisimplies that it is impossible for a laser shot by the tank to end up in an “infinite loop”while being reflected by mirrors. Remember also that the laser stops as soon as it hits asolid block, a movable block, or moves a mirror. It follows that after firing the laser, ittakes less than 𝑛 steps before the laser finds its final destination, where 𝑛 is the numberof tiles on the board. Simulating a sequence of 𝑘 moves thus requires 𝑂 ( 𝑘𝑛 ) time.From our construction, it is a straightforward calculation to see that given a -SATexpression with 𝑉 variables and 𝐶 clauses gives a puzzle contained on a board with size (7 𝑉 + 9 𝐶 + 4)(7 𝐶 + 9) . This is evidently polynomial in the size of the expression. Proof (of Theorem 1). A -SAT problem can be converted to a LaserTank puzzle inpolynomial time since the board size is a polynomial in the number of variables andclauses. Furthermore, a solution to such a LaserTank puzzle can easily be translated backto a solution of the original -SAT problem in polynomial time, by simply performingall the steps. Note that a LaserTank puzzle solution might not decide the truth valueof some variables (see caption of Figure 3), in which case, one may simply let thesevalues be true . According to Lemma 1, the translation of a puzzle solution to a -SATsolution only requires a polynomial time in the input (number of steps). This shows thatLaserTank is at least as hard as -SAT. Finally, Lemma 1 shows that a solution can beverified in polynomial time and hence LaserTank is NP-complete.Notice that in both the and – and literal -gadget, each movable block can be re-placed with a ◸ -mirror without changing the behavior of the gadget. Thus Theorem 1 is aserTank is NP-complete 5 ■■■■■■■■■■■■■■■■■■■■■■■■ ⌲ ◹ ◹ ◹ ◹ ◹ ◹ ■■■■ 𝐴 ⤑ ◹ ■■ ■■ ◸ ¬ 𝐴 ⤑ ⊡ ◿ ■ ■■■■ ◹ ■ ◹ ■ ◺ ■■■■ ◸◿◸◿ ■■■■ 𝐵 ⤑ ◹ ■■■ ◹ ■■ ◸ ¬ 𝐵 ⤑ ⊡ ◿ ■ ◸◿ ■■■■ ◹ ■ ◺ ■■■■ ◸◿ ■■■■ 𝐶 ⤑ ◹ ■■■ ◹ ■■ ◸ ¬ 𝐶 ⤑ ⊡ ◿ ■ ◸◿ ■■■■ ◹ ■ ◺ ■■■■ ◸◿ ■■■■■ ■■■■■ ◸ ⨁ ■ ■ ◸ ■ ◸ ■ ◸ ■■■■■ ■ ⊡ ■ ◿ ■■■ ◿ ■■■ ◿ ■■■■■■■ ■■■■■■ ■ ◸ ■ ◸ ■ ◸ ■■■ ■ ⊡ ■ ◿ ■■■ ◿ ■■■ ◿ ■■■■■■■ ◿ ■ ■■■ ■■■■■■■■■■■■■■■■■■■■■■■■ Fig. 3.
The puzzle corresponding to the expression ( 𝐴 ∨ 𝐵 ∨ ¬ 𝐶 ) ∧ ( 𝐴 ∨ ¬ 𝐵 ∨ 𝐶 ) . Note that if 𝐴 = 𝚝𝚛𝚞𝚎 , the expression is satisfied. Thus this particular puzzle can be solved without decidingtruth values for the variables 𝐵 and 𝐶 , and the movable blocks in the 𝐵 and 𝐶 variable gadgedsdo not need to be moved. valid even in the case when restricting to puzzles without movable blocks. Furthermore,we can extend Theorem 1 to the case where the tank can turn and move in all four di-rections. To do so, we need to make sure the tank only has access to the same inputs asin the previous setup. This can be done by inserting additional rows in the puzzle suchthat every other row is empty, and then inserting two columns in with the pattern ◹◸◺◿ between the initial position of the tank and the rest of the board. We leave the details tothe reader. References
1. Cook, S.A.: The complexity of theorem-proving procedures. In: Proceedings of the Third An-nual ACM Symposium on Theory of Computing. pp. 151–158. STOC ’71, ACM, New York,NY, USA (1971). https://doi.org/10.1145/800157.8050472. Dor, D., Zwick, U.: SOKOBAN and other motion planning problems. Computational Geome-try (4), 215–228 (Oct 1999). https://doi.org/10.1016/s0925-7721(99)00017-63. Erik D. Demaine, S.H., Liben-Nowell, D.: Tetris is hard, even to approximate. Tech. Rep. MIT-LCS-TR-865, MIT, Cambridge (2002), https://arxiv.org/abs/cs/02100204. Flake, G.W., Baum, E.B.: Rush Hour is PSPACE-complete, or “Why you should generouslytip parking lot attendants”. Theoretical Computer Science (1-2), 895–911 (Jan 2002).https://doi.org/10.1016/s0304-3975(01)00173-65. Kaye, R.: Minesweeper is NP-complete. The Mathematical Intelligencer (2), 9–15 (Mar2000). https://doi.org/10.1007/bf030253676. Viglietta, G.: Gaming is a hard job, but someone has to do it! Theory of Computing Systems54