Tetris is NP-hard even with O(1) rows or columns
Sualeh Asif, Michael Coulombe, Erik D. Demaine, Martin L. Demaine, Adam Hesterberg, Jayson Lynch, Mihir Singhal
TTetris is NP-hard even with O (1) rows or columns Sualeh Asif ∗ Michael Coulombe ∗ Erik D. Demaine ∗ Martin L. Demaine ∗ Adam Hesterberg ∗ Jayson Lynch ∗ Mihir Singhal ∗ Abstract
We prove that the classic falling-block video game
Tetris (both survival and board clearing) remainsNP-complete even when restricted to columns, or to rows, settling open problems posed over 15 yearsago [BDH + , similar to the previous reduction for unrestrictedboard sizes, but with a better packing of buckets. On the positive side, we prove that 2-column Tetris(and 1-row Tetris) is polynomial. We also prove that the generalization of Tetris to larger k -ominopieces is NP-complete even when the board starts empty, even when restricted to 3 columns or 2 rowsor constant-size pieces. Finally, we present an animated Tetris font. Tetris is among the best-selling [Wik19a], and perhaps best-known, video games ever. Since its inventionby Alexey Pajitnov 35 years ago in 1984, over 80 versions have been developed on nearly every platform[Wik19b]. Perhaps most famous is the Nintendo Game Boy edition, which was bundled with the Game Boyin the USA, resulting in 35 million copies sold [Spa14]. The most recent editions — Tetris Effect for PS4 andPC including VR (2018) and Tetris 99 for Nintendo Switch (2019) — prove Tetris’s sustained popularity.In standard Tetris, tetromino pieces ( , , , , , , ) are chosen at (pseudo)randomand fall from the top of a 10-wide 20-tall rectangular playfield. While 10 is the typical width of most Tetrisimplementations, the height varies between 16 and 24, and some editions change the width to anywherebetween 6 and 20 [Tet19a]. The player can rotate each piece by ± ◦ and/or slide it left/right as it fallsdown, until the piece “hits” another piece beneath it and the piece freezes. If any rows are completely full,they get removed (shifting higher rows down), and then the next piece starts falling from the top.To make this game easier to analyze from a computational complexity perspective, the perfect-information Tetris problem [BDH +
04] asks, given an initial board state of filled cells and a sequence of pieces that willarrive, whether the pieces can be played in sequence to either survive (not go above the top row) or clear theentire board. (See Section 2 for precise game rules.) This problem was proved NP-hard for arbitrary boardsizes in 2002 [BDH + k -omino pieces for various k [DDE + Our results.
In this paper, we analyze the following special cases of
Tetris ; refer to Table 1.1. c -column Tetris , where the playfield has exactly c columns (and an arbitrary number of rows).The original Tetris paper [BDH +
04] asked specifically about the complexity of c -column Tetris for c = O (1) , motivated by standard Tetris where c = 10 .In Section 4, we prove that it is NP-complete to survive or clear the board in c -column Tetris for any c ≥ . This result includes the width of most Tetris variants, including the already small TetrisJr. ( c = 8 ), but excludes one variant, Tetris Wristwatch ( c = 6 ) [Tet19a]. As an extra feature, thisresult immediately implies NP-hardness of Tetris where the player can make only a bounded numberof moves between each unit piece fall (“bounded reaction speed”).Complementarily, in Section 3, we prove that c -column Tetris can be solved in polynomial timefor c ≤ . The case c = 2 was claimed without proof in the conclusion of [BDH + O ( n ) -tris , by reducing to nondeterministic pushdownautomata. The critical hardness threshold for c is thus between and . ∗ Massachusetts Institute of Technology, Cambridge, MA, USA a r X i v : . [ c s . CC ] S e p ows Columns Empty? Piece Sizes Complexity Reference O ( n ) no O ( n ) strongly NP-hard Proposition 5.131 O ( n ) yes O ( n ) linear Proposition 6.41 O ( n ) no k linear Proposition 3.12 O ( n ) yes O ( n ) strongly NP-hard Theorem 6.33 O ( n ) no 4 OPEN4 O ( n ) no 4 strongly NP-hard Theorem 5.1 O ( n ) O ( n ) linear Proposition 3.1 O ( n ) O ( n ) polynomial Theorem 3.2 O ( n ) O ( n ) strongly NP-hard Theorem 6.2 O ( n ) O ( n )
8+ no 4 strongly NP-hard Theorem 4.1 O ( n ) ≤ strongly NP-hard Theorem 6.1 Table 1:
Summary of our results. Each row of the table specifies the supported board size (numbers ofrows and columns), whether the board starts empty or from an adversarial position (empty is stronger forhardness, while nonempty is stronger for algorithms), the allowed piece polyomino sizes (4 for Tetris), thecomplexity result for this case (red for hardness, blue for algorithm, and yellow for open), and where weprove the result.2. r -row Tetris , where the playfield has exactly r rows (and an arbitrary number of columns). Theoriginal Tetris paper [BDH +
04] also asked about the complexity of r -row Tetris for r = O (1) .In Section 5, we prove that it is NP-complete to survive or clear the board in r -row Tetris forany r ≥ .Complementarily, we observe the trivial result that r -row Tetris can be solved in polynomialtime for r = 1 . The critical hardness threshold for r is thus between and .Both the O (1) -row and O (1) -column NP-hardness results are based on more efficient packings of the“buckets” in the original reduction from [BDH + c = 8 columns); the previous “reservoir” approach [BDH +
04, Section 4.2]required an odd number of columns.3.
Empty Tetris , where the playfield starts empty instead of having a specified configuration. Theoriginal Tetris paper [BDH +
04] highlighted the complexity of this variant as a “major open question”,as all existing Tetris hardness proofs (including those in this paper) rely on a high-complexity initialconfiguration.In Section 6, we solve this problem for the generalization of
Tetris to k -omino pieces, denoted k -tris , as implemented in the video games Pentris and ntris , and previously analyzed from a complexityperspective [DDE + ( ≤ -tris is NP-hard.(b) O ( n ) -tris is NP-hard. This result is tight against our polynomial-time algo-rithm for O ( n ) -tris mentioned above.(c) O ( n ) -tris is NP-hard.In Section 7, we present a Tetris font where each letter is made from exactly one copy of each tetrominopiece. The font has several variants, including a puzzle font and an animated font, demonstrated in acompanion web app. http://erikdemaine.org/fonts/tetris/ Rules of Tetris
We give a brief summary of the rules of Tetris and its generalization k -tris , referring the reader to [BDH + +
17, Section 2] respectively for a complete description of the rules. There are in factmany real-world variations of the rules, eventually formalized by The Tetris Company into a modern rule set[Blu09]. The rules we give here are consistent with some, but not all, implementations of Tetris, as detailedbelow.Tetris consists of a rectangular board or playfield [Tet19a], which is rectangular in shape. Each cell is filled or unfilled . In the initial state and after each move, no row is completely filled.In Tetris , there are seven tetromino piece types (distinguished by reflection), labeled with letters thatresemble their shape: ( O ) , ( J ) , ( L ) , ( S ) , ( Z ) , ( T ) , ( I ) . In k -tris , the piece typesconsist of all k -ominoes, i.e., all connected shapes made by k unit squares joined along edges. We also define ≤ k -tris , where the piece types are all polyominoes made from ≤ k unit squares. In a game instance, n pieces arrive in a fixed order p , p , . . . , p n . Each piece p i falls, starting above the top row of the board, andthe player can rotate by ± ◦ , and translate left and/or right, as the piece drops down one unit at a time.When the piece tries to drop but would collide with another piece, then it stops moving (“locks down”). Ifa locked-down piece extends above the top row of the board, then the player immediately loses the game.This rule is called partial lock out [Tet19c], and applies to older versions of Tetris (e.g., Atari and NES),though modern Tetris rules [Blu09] end the game only when a locked-down piece is entirely above the board;see Section 8. Finally, if any row is now entirely filled, then that row gets removed, and all rows above shiftdown, creating one new empty row at the top.Like [BDH +
04, Section 2], we allow any model of piece rotation that satisfies two “reasonable” restrictions.First, a piece cannot “jump” from one connected component of the unfilled space to another. Second, anypiece that is not × k (in particular, not ) cannot “squeeze through” a single-cell choke point. Precisely,if cell (cid:104) i, j (cid:105) is unfilled and either (cid:104) i ± , j (cid:105) are both filled or (cid:104) i, j ± (cid:105) are both filled, and the filling of cell (cid:104) i, j (cid:105) would partition the unfilled space into two connected components, then a piece that is not × k cannot jumpbetween these two connected components. This model is a slight strengthening of the one in [BDH + (cid:104) i, j ± (cid:105) case because it only had to consider vertical passage; in our O (1) -rowproof, we need to also consider horizontal passage. Notably, this rotation model includes the Classic RotationSystem where each piece rotates about a center interior to the piece, and the operation fails if that rotationwould overlap a filled square [Blu09]; and it includes the more-complex Super Rotation System (SRS) thatis now standard to Tetris [Tet19b, Blu09], which adds a series of possible translation checks that attempt toavoid collisions via “wall kicks”.The ( ≤ ) k -tris problem is the following decision problem: given a starting configuration of filled cells,and the sequence p , p , . . . , p n of ( ≤ ) k -omino pieces that will arrive, can the player maneuver the piecesto avoid pieces freezing above the top row, and optionally, reach a state where the entire board is unfilled? Tetris is the special case . These problems are trivially in NP: a certificate is the sequence of playermoves (a linear number of translations and/or rotations) between each unit piece drop. As a result, so arethe following special cases considered in this paper:1. c -column ( ≤ ) k -tris , where the board has c columns.2. r -row ( ≤ ) k -tris , where the board has r rows.3. Empty ( ≤ ) k -tris , where the board’s initial configuration is entirely unfilled. For completeness, we start with an easy result about one row or column:
Proposition 3.1. ≤ k -tris and k -tris are solvable in linear time.Proof. In ≤ k -tris , only × j pieces (e.g., ) are valid. (Any other piece does not fit inthe board.) Every such piece immediately fills any rows it occupies, so immediately disappears. Thus everysequence of pieces that fit in the board is a trivial win for the player.3n k -tris , any piece that is not × k results in an immediate loss for the player. If there are only × k pieces in the sequence, then we can follow a greedy strategy: place each piece in the leftmost positionwhere it fits. If there is any way to clear the initial row configuration, then this algorithm will produceone. If there is any way to fill a then-empty row (i.e., k divides the board width), then we claim that thisalgorithm will produce one. Furthermore, if the row cannot be cleared, then we claim that this algorithmwill make the most moves possible before getting stuck. These claims follow from a simple greedy argument:take any strategy, sort its piece placements between line clears from left to right, and if a piece placement isnot maximally left, shift it so. Thus, this algorithm will play for as long as is possible. Theorem 3.2. O ( n ) -tris is solvable in polynomial time.Proof. We reduce to A P DA , the acceptance problem for nondeterministic pushdown automata, which isknown to be in P by reduction to the acceptance problem for CNF Context-Free Grammars [Sip06] and theCYK algorithm that solves it [You67]. Given a set Σ of ≤ k -omino pieces, a piece sequence p of length n over Σ , the initial board configuration B , and board height h , we output ( M, p ) , where M is a PDA thatrecognizes piece sequences from Σ that permit staying under h rows starting from board B , and optionallyclearing the board.The constructed pushdown automaton M represents the board state in its stack, with the topmostoccupied row at the top. Its stack alphabet Γ = { (cid:4)(cid:3) , (cid:3)(cid:4) } represents the two possible configurations of a2-column row (as (cid:4)(cid:4) is invalid and (cid:3)(cid:3) is invalid below the topmost occupied row). Each piece p i ∈ Σ isdescribed by a string over { (cid:4)(cid:3) , (cid:3)(cid:4) , (cid:4)(cid:4) } , as wider pieces cannot fit within two columns.When a piece p i comes in, it would suffice for M to pop and observe the top | p i | ≤ k rows to determinehow each placement choice changes the board state. Because a move can either delete or add up to k occupiedrows at the top of the board, at most k new rows need to be pushed to realize the outcome of a chosenplacement. This locality of updates may not seem true for × j pieces with pattern ( (cid:3)(cid:4) ) ∗ like thetetromino, because they can descend arbitrarily far below the topmost row; but observe that each row itpasses through and clears must be identical, either all (cid:4)(cid:3) or all (cid:3)(cid:4) , so the resulting board state would bethe same as if the top j rows were cleared instead.However, while this implementation would be sufficient, it will not be efficient for large k : there are k possible sequences of k rows, so if M always popped k rows into its finite state space, we would haveexponential blowup. We can fix this issue by noticing that there are only two possible row patterns that M needs to handle, ( (cid:4)(cid:3) ) ∗ ( (cid:3)(cid:4) )? and its mirror image ( (cid:3)(cid:4) ) ∗ ( (cid:4)(cid:3) )? , as (by the reasonable rotation assumption)no piece can pass through two unequal rows or affect any rows below them. This reduces the number ofpossibilities to O ( k ) , keeping M ’s state space small. Figures 1, 2, and 3 show how to handle the standardtetromino pieces. (a) onto (cid:4)(cid:3) (b) onto (cid:3)(cid:4) (c) onto (cid:4)(cid:3) (d) onto (cid:3)(cid:4) Figure 1:
Possible 2-column outcomes for placing or pieces. and flipped cases aresymmetric.The execution of M starts by pushing B onto the stack before reading any input, initializing the board.For each piece p i , M nondeterministically chooses which orientation to place p i on the board. As it runs, M enforces the maximum row constraint by keeping a stack height counter in its state, which is incrementedand decremented appropriately as M pushes and pops rows. If M places a piece over the height limit h ,then M enters an inescapable rejecting state on that branch, whereas all other states (or optionally onlythose with an empty stack) are accepting states. With these finite-state implementable rules, M performsa correct simulation which recognizes winning games, therefore (Σ , p, B, h ) is in ≤ k -tris if andonly if ( M, p ) is in A P DA . 4 a) onto (cid:4)(cid:3) (or (cid:3)(cid:4) ) (b) flipped onto (cid:4)(cid:3) (c) flipped onto (cid:3)(cid:4) , (cid:4)(cid:3) (d) flipped onto (cid:3)(cid:4) , (cid:3)(cid:4) Figure 2:
Possible 2-column outcomes for placing pieces. cases are symmetric. (a) on any board. (b) on top of (cid:3)(cid:4) (c) into ( (cid:4)(cid:3) ) ( (cid:3)(cid:4) ) (d) into ( (cid:4)(cid:3) ) ( (cid:3)(cid:4) ) (e) into ( (cid:4)(cid:3) ) ( (cid:3)(cid:4) ) (f) into ( (cid:4)(cid:3) ) ( (cid:4)(cid:3) ) ∗ ( (cid:3)(cid:4) ) Figure 3:
Possible 2-column outcomes for placing and pieces. Mirrored cases are symmetric.To bound the running time, note that we may assume h ≤ | B | + kn , as otherwise it would be impossibleto reach the top row and lose. Because producing M is dominated by the computation of its transitionfunction — enumerating and simulating the outcomes of the O ( | Σ | × h × k ) scenarios of placing every piecein each orientation at all legal heights with every pattern of the top k rows — the size of M and the timerequired to produce it is polynomial in the input size. In this section, we prove the following theorem:
Theorem 4.1.
It is NP-complete to survive or clear the board in c -column Tetris for any c ≥ . Like [BDH + problem. Definition 4.2.
The problem is defined as follows:
Input:
A set of nonnegative integers { a , a , . . . , a s } and a nonnegative integer T satisfying the con-straints (cid:80) si =1 a i = sT and T < a i < T for all ≤ i ≤ s .5 utput: Whether { a , a , . . . , a s } can be partitioned into s (disjoint) sets of size 3, each of which sumto exactly T .For the reduction, we exhibit a mapping from instances to Tetris instances so that thefollowing is satisfied:
Lemma 4.3 ( c -column Tetris ⇐⇒ ) . For a “yes” instance of , there is away to drop the pieces that clears the entire board without triggering a loss. Conversely, if the board can becleared, then the instance has a solution.Proof sketch.
The initial board, illustrated in Figure 4(a) (where filled cells are grey and the rest of the cellsare unfilled), has sT + 48 s + 17 rows. The reduction is polynomial size.The piece sequence is as follows. First, for each a i , we send the following a i sequence (see Figures 4(i–m)): (cid:104) , (cid:104) , , (cid:105) a i , , (cid:105) . After all these pieces, we send the following clearing sequence (see Figures 4(n) and (b–h)): (cid:104)(cid:104) , , (cid:105) s , , (cid:104) (cid:105) sT +24 s +6 , , , (cid:104) (cid:105) sT +12 s +4 (cid:105) . Figures 4(b–n) illustrate that a solution to clears the Tetris board. To show the otherdirection, we progressively constrain any
Tetris solution to a form that directly encodes a solution. Because the area of the pieces sent is exactly equal to sT + 48 s + 13) , no cell can be left empty.We enumerate all possible cases to show that this goal is impossible to meet (some cell must be left empty)if there is no solution. Figures 4(o–w) show some of the cases. In this section, we detail our polynomial reduction from an instance P = (cid:104){ a , a , . . . , a s } , T (cid:105) of to an instance G = G ( P ) of Tetris . In later sections, we prove that P and G have the sameanswer, i.e., there exists a valid 3-partition if and only if there is a sequence of moves that survives or thatclears the Tetris board. The initial board, illustrated in Figure 4(a) (where filled cells are grey and the rest of the cells are unfilled),has columns and sT + 48 s + 17 rows. The columns are numbered 1 to 8 from left to right. (To provehardness for c > columns, we simply fill all columns beyond the 8th.) The unfilled cells consist of five mainparts: • The corridor , which consists of a × (12 sT + 48 s + 12) rectangle, as well as a 3-square cut out on thebottom left. • The buckets (of which there are s ), which branch off the corridor to its left. These are similar in shapeto the buckets used in [BDH + T + 20 , and contains T + 3 notches (thepairs of adjacent empty cells in column 5, not including the 3 empty cells at the top). • The
T-lock , which is in the shape of a piece. The buckets are each separated by two rows. • The alley , which is a × (12 sT + 48 s + 16) rectangle which is “unlocked” by the T-lock.We also define the horizon , which is the horizontal line separating the empty rows at the top of the boardfrom the topmost filled cell. When a row is cleared, the horizon moves down by one row per row that iscleared. We also define the bucket line as the horizontal line immediately below the bottommost cell of thebottommost bucket. 6 ll e y bu c k e t bu c k e t c o rr i d o r (a) (b) (c) (d) (e) (f) (g) (h)(i) (j) (k) (l) (m) (n) Figure 4: (a) shows the initial board. (b–h) demonstrate filling and clearing the board in the final clearingsequence. (i–m) show a valid sequence of moves for a i = 5 . (n) shows our bucket terminator.7 .1.2 Piece sequence The pieces arrive in the following order.First, for each a i , the following pieces arrive in the following order, called the a i -sequence . This part isidentical to the reduction in [BDH + • The initiator , which is a single piece. • The filler , which consists of the pieces (cid:104) , , (cid:105) a i (which we take to mean the sequence (cid:104) , , (cid:105) repeated a i times). • The terminator , which consists of the pieces (cid:104) , (cid:105) .After all the a i -sequences, we then have the following pieces in the following order, called the closingsequence : • The bucket closers , which consists of the pieces (cid:104) , , (cid:105) s . • A single (note this is the first to arrive). • The corridor closer , which consists of the pieces (cid:104)(cid:104) (cid:105) sT +24 s +6 , (cid:105) . • A single (note this is the first to arrive). • The clearer , which consists of the pieces (cid:104) (cid:105) sT +12 s +4 .The total size of the board is sT + 48 s + 17) and the total number of pieces is s (cid:88) i =1 (3 + 3 a i ) + 3 s + 1 + (6 sT + 24 s + 6) + 1 + 1 + (3 sT + 12 s + 4) = 12 sT + 48 s + 13 , which are both polynomial in the size of the instance. solvable ⇒ Tetris solvable
In this section, we show one side of the bijection: for a “yes” instance of , we can clear the gameboard.
Theorem 4.4.
For a “yes” instance of , there is a trajectory sequence Σ that clears the entiregameboard of G ( P ) without triggering a loss.Proof. Since P is a “yes” instance, there is a partitioning of { , , . . . , s } into sets A , A , . . . , A s so that (cid:80) i ∈ A j a i = T We have ensured that | A j | = 3 for all j . All pieces associated with set A j = { x, y, z } shouldbe placed into the j th bucket of the gameboard.We place the a x -sequence into bucket j as in Figures 4(i–l). After all pieces associated with the number a x have been placed into bucket j , the bucket has a x + 1 fewer notches, but otherwise still has the shape ofa bucket. Similarly, a y , a z are placed in bucket j , for a total of ( a x + 1) + ( a y + 1) + ( a z + 1) = T + 3 notchesbeing filled, so each bucket has 0 notches left and may then be filled by the bucket closers, as in Figure 4(n).After all the a i -sequences arrive, then, we fill all the buckets with the bucket closers.Next, now that the buckets are all filled, the remaining moves are straightforward. We drop a intothe corridor to fill the bottom 4 cells of the corridor. Now we use the sT + 24 s + 6 s in the corridorcloser to fill the corridor, as depicted in Figure 4(d). We then drop the into the T-lock, which fillsthe top row immediately below the horizon and clears it, opening the alley. Now we drop a sequence of sT + 12 s + 4 s which clear all the rows of the board since they clear sT + 12 s + 4) = 12 sT + 48 s + 16 rows, as shown in Figures 4(f–h). This clears the whole board, as desired.8 .3 Tetris solvable ⇒ solvable Here we show that if G ( P ) has a sequence of moves that survive, then the instance P must alsohave a solution (i.e., a valid partition). Suppose there is such a surviving sequence of moves. By a sequenceof claims, we progressively constrain this survival strategy into a form that directly encodes a solution. Claim 4.5.
The top row must be the first row to be cleared.
Proof.
Every row except the top has an empty square in the alley. The alley is completely surrounded bypieces, and thus no part of the alley can be filled until a row is filled.
Claim 4.6.
Only a can go in the T-lock.
Proof.
By the previous claim, no rows can be cleared before the top row, and thus the T-lock will remainat the top of the board until it is filled. There are only four empty cells in the connected component of theT-lock within the board, so any piece placed other than a will have at least one block above the board,causing a loss by partial lock out.
Claim 4.7.
No rows can be cleared before the is given.
Proof.
Follows from the prior two claims.
Claim 4.8.
All squares not in the alley and T-lock must be completely filled before the arrives.
Proof.
Cells in the alley and cells above the horizon cannot be filled before the arrives by Claim 4.7.Cells in the T-lock cannot be filled before the arrives by Claim 4.6. The total number of empty cellsoutside those two areas is sT + 192 s + 52 = 4(12 sT + 48 s + 13) , which is exactly four times the number ofpieces that arrive before the . Each piece fills four cells, so every cell not in the alley and T-lock mustbe filled; otherwise, some piece will extend above the board, causing a loss by partial lock out.By Claim 4.8, the surviving trajectory sequence cannot leave any unfillable holes behind when placingpieces. Henceforth, we focus on the prefix of the surviving trajectory sequence that places the a i -sequenceswithout such holes; we only need the surviving trajectory sequence for the closing sequence in order toguarantee Claim 4.8. Claim 4.9.
During the a i -sequences, no piece other than an can be placed first in the corridor. Proof.
The casework in Figure 5 shows that any , , , or placed in the bottom of thecorridor will leave empty squares, which is not allowed by Claim 4.8. No , , or arrives duringthe a i -sequences, leaving just .Any piece placed higher up in the corridor creates a choke point of width 1 through which no pieces butcan pass. Since an placed at the bottom of the corridor leaves empty squares, this makes thebottom of the corridor unfillable.Next we show that the buckets must be filled in the manner given by Section 4.2. We define prepped andunprepped buckets as in [BDH + unprepped bucket is one that takes the form of a bucket in the initialboard, but possibly with fewer notches, as shown in Figure 6(a). The height of an unprepped bucket is thenumber of notches in the bucket; the buckets all initially have height T + 3 . A special case is an unpreppedbucket of height 0; this is also shown in Figure 6(b).We also define a prepped bucket as one in which all cells below some notch are filled, as in Figure 7(a).The height of a prepped bucket is again its number of notches. Again, there is the special case of a preppedbucket of height 0, also shown in Figure 7(b). Claim 4.10.
None of , , may be placed in an unprepped bucket.
Proof.
Figures 8 and 9 show all possible placements, and the crosses show cells that cannot be filled. InFigure 9(q), there are two cells with crosses; these two cells cannot both be filled (noting that there is noin the piece sequence). Thus we have a contradiction by Claim 4.8, since all the crossed cells must befilled eventually. 9 a) (b) (c) (d) (e) (f)(g) (h) (i) (j)(k) (l) (m)
Figure 5:
Possibilities for placing various pieces other than and into the corridor, all of whichmake the puzzle unsolvable. (a) (b)
Figure 6:
Unprepped buckets of heights 1 and0, respectively (a) (b)
Figure 7:
Prepped buckets of heights 1 and 0,respectively (a) (b) (c) (d) (e) (f) (g)(h) (i) (j) (k) (l) (m)
Figure 8:
Possibilities for placing an , , or into an unprepped bucket of height 0. All leavethe puzzle unsolvable. 10 a) (b) (c) (d) (e) (f) (g)(h) (i) (j) (k) (l) (m) (n)(o) (p) (q) (r)
Figure 9:
Possibilities for placing an , , or in an unprepped bucket of positive height. Allleave the puzzle unsolvable.
Claim 4.11.
If an is placed in an unprepped bucket, it must form a prepped bucket of the same height.
Proof.
We do casework on the possible placements of the , showing that in each other case, there is acell that can never be filled before any row is cleared. This would contradict Claim 4.8.All possible placements are shown in Figures 10 and 11, where we have split into cases based on whetheror not the bucket has height 0. (The cases where the bucket does not have height 0 are essentially the sameeven as the height varies). Most cases are marked with a cross, which indicates a cell which can never befilled, making that placement invalid. In the only valid cases, Figures 10(d) and 11(d), an unprepped bucketof the same height results.
Claim 4.12.
An cannot be placed in a prepped bucket of height 0.
Proof.
There is only one possible placement of an in a prepped bucket of height 0, shown in Figure 12.The cross marks an unfillable cell; hence, this is not permissible.
Claim 4.13.
When the sequence (cid:104) , , (cid:105) is placed in a prepped bucket of height h , the bucket mustend up as an prepped bucket of height h − . (We know h ≥ by Claim 4.12.)11 a) (b) (c) (d) (e) (f) (g) Figure 10:
Possibilities for placing an into an unprepped bucket of height 0. All but the first leavethe puzzle unsolvable. (a) (b) (c) (d) (e) (f) (g)(h) (i) (j) (k)
Figure 11:
Possibilities for placing an into an unprepped bucket of positive height. All but the firstleave the puzzle unsolvable.
Figure 12:
The only way to place an in a prepped bucket of height 0. This leaves the puzzle unsolvable.
Proof.
Here we show that each of the parts of the sequence must be placed in a specific way. First, Figure 13shows all the ways an can be placed. Only Figure 13(b) shows a valid placement.After the has been placed as in Figure 13(b), Figure 14 shows all the ways the can be placedafterward. Again, only Figure 14(c) shows a valid placement.Finally, after the has been placed as in 14(c), Figure 15 shows all the ways the second can beplaced. In the only valid case, Figure 15(a), what remains is a bucket of height h − , as desired. Claim 4.14.
When the sequence (cid:104) , (cid:105) is placed in a prepped bucket of height h , the bucket mustend as an unprepped bucket of height h − . (We know h ≥ by Claim 4.12.) Proof.
By the exact same cases as in Claim 4.13, the must be placed as in 13(b).12 a) (b) (c) (d) (e)
Figure 13:
Possibilities for placing the first in (cid:104) , , (cid:105) . All but the first leave the puzzleunsolvable. (a) (b) (c) (d) (e) (f) (g)(h) (i) (j) (k) (l) (m)
Figure 14:
Possibilities for placing the in (cid:104) , , (cid:105) . All but the first leave the puzzle unsolvable. (a) (b) (c) (d)
Figure 15:
Possibilities for placing the second in (cid:104) , , (cid:105) . All but the first leave the puzzleunsolvable. 13ow, Figure 16 shows all possible placements of the afterward, where again crosses show unfillablecells. (In this case, it is necessary to split between the h = 1 and h > cases.) Again, in Figure 16(e), thereare two cells with crosses, which cannot both be filled since there is no in the sequence. In the onlyvalid placements, Figures 16(a) and 16(d), the result is a prepped bucket of height h − . (a) (b) (c) (d) (e) (f) Figure 16:
Possibilities for placing the . All but the first leave the puzzle unsolvable.The following corollary follows directly from Claims 4.11, 4.10, 4.12, 4.13, and 4.14:
Corollary 4.15.
Suppose that before the a i -sequence arrives, all buckets are unprepped. If thestarting the a i -sequence is placed into a bucket, then the entire a i -sequence must be placed into that bucket.Furthermore, the height of that bucket decreases by a i + 1 ; or if the height were to become negative, thenthese placements are impossible.We can now remove the assumption that the starting the a i -sequence is placed into a bucket: Claim 4.16.
The starting each a i -sequence must be placed into a bucket. Proof.
By the definition of the a i -sequence, the is immediately followed by an . Consider for acontradiction the first from an a i -sequence that is placed into the corridor. We claim that that thefollowing cannot be placed. By Claim 4.9 and by induction, no piece other than the just-placedhas been placed in the corridor. If the piece is placed in the corridor, the casework in Figure 17 showsthat it would create an unfillable hole. However, by Corollary 4.17, before each a i -sequence, all buckets areunprepped, so by Claim 4.10, the also cannot be placed in a bucket, a contradiction. (a) (b) (c) (d) (e) Figure 17:
Possibilities for placing into the corridor and then into the corridor.Combining Corollary 4.15 with Claim 4.16, we obtain the following:
Corollary 4.17.
Suppose that before the a i -sequence arrives, all buckets are unprepped. Then the entire a i -sequence must be placed into that bucket. Furthermore, the height of that bucket decreases by a i + 1 ; orif the height were to become negative, then these placements are impossible.We are finally ready to prove the other direction of the bijection. Theorem 4.18. If G ( P ) has a surviving trajectory sequence, then the instance P has a solu-tion. roof. Numbering the buckets , , . . . , s , let S b be the set of i such that the a i -sequence is placed in bucket b .By the first half of Corollary 4.17, the S b ’s form a partition of { a , a , . . . , a s } . By the second half ofCorollary 4.17, the sum (cid:80) i ∈ S b ( a i + 1) is at most the original height of each bucket, which is T + 3 . However, (cid:80) si =1 ( a i + 1) = s ( T + 3) , so equality must hold.Thus, we have (cid:80) i ∈ S b ( a i + 1) = T + 3 for each bucket b . But the condition T / < a i < T / means thatthis sum cannot have at most 2 or at least 4 terms, so it must have 3 terms, and thus | S b | = 3 . Then thecondition simplifies to (cid:80) i ∈ S b a i = T , and thus the S b represent a valid 3-partition. Theorem 5.1.
It is NP-complete to survive or clear the board in r -row Tetris for any r ≥ . The proof by reduction from . Given an instance P of with elements { a , a , . . . , a s } and target T , we create an instance G = G ( P ) of r -row Tetris which has a valid 3-partition if and onlyif there is a sequence of moves to survive, and an extension of such a surviving sequence to leave the Tetrisboard empty.The initial board, illustrated in Figure 18 for r = 6 (where filled cells are grey and the rest of the cellsare unfilled), has sT + 8 s + 8 + 4 r columns and r rows, containing the following unfilled cells: • A number s of buckets , which branch off the corridor to its right. These are similar in shape to thebuckets used for the proof of c -column Tetris except for the first few and last few columns. Eachbucket has a total width of T + 6 , and contains T notches (the pairs of adjacent empty cells in row5, counting rows from the top). Buckets are separated by columns. • A T-lock in the shape of a piece in the top two rows. • An O-lock in the shape of a piece in the next two rows. • Right filler: in each row below the top four, there are exactly four empty spaces, to the right of anycolumns empty in any higher row.The piece sequence is as follows. First, for each a i , we send the following a i sequence (see Figures 4(i–m)): (cid:104) , (cid:104) , , (cid:105) a i − , , (cid:105) . After all these pieces, we send the following clearing sequence (seeFigures 4(n) and (b–h)): (cid:104)(cid:104) , , , , , (cid:105) s , , (cid:105) . Finally, if r > , we send (cid:104) (cid:105) r − .The total size of the board is r (15 sT + 8 s + 8 + 4 r ) and the total number of pieces is s (cid:88) i =1 (3 + 3(3 a i − s which are both polynomial in the size of the instance (recalling that is stronglyNP-hard). Lemma 5.2 ( r -row Tetris ⇐⇒ ) . For a “yes” instance of , there is a wayto drop the pieces that survives and clears the entire board. Conversely, if the piece sequence can be survived,then the instance has a solution.
Figure 19 illustrates that a solution to survives and clears the Tetris board.
Figure 18:
Shows the initial board for r = 6 To show that if G ( P ) has a sequence of moves that survives, then the instance P mustalso have a solution (i.e., a valid partition), we progressively constrain any Tetris solution to a form thatdirectly encodes a solution. 15 a)(b)(c)(d)(e)(f)(g)(h)
Figure 19: (a) shows the initial board for r = 4 . (b) shows a correctly filled board. After (c), there aremany ways to survive; (c–h) show the clearing sequence. Claim 5.3.
Nothing may be placed in the T-lock except a .
Proof.
No row can be cleared until some cell of the T-lock is filled and we also note that there is only onein the complete piece sequence. However, the only piece that can fill any cell of the T-lock withoutfilling a cell above the horizon (causing a loss by partial lock out) is a , so the claim follows from Claim5.6.
Corollary 5.4.
Nothing may be placed in the O-lock except an .
Proof.
The first two rows cannot be cleared until T-lock is filled with an by Claim 5.3. This meansthat no piece may reach the O-lock since it is covered by the first two rows. The only piece that follows theis an which must go into the O-lock as desired.So we have the following corollary which follows directly from Claim 5.4:
Corollary 5.5.
No row may be cleared until the first has arrived.We implicitly use Corollary 5.5 throughout this paper, since it implies that the buckets must maintaintheir shape until after the arrives.
Claim 5.6.
No cell above the horizon may ever be filled.
Proof.
The area of the pieces sent up to the first is exactly equal to sT + 6 s + 1) , the area of the unfilled cells in the first four rows outside the lock is s (36 T + 24) + 4 = 4(9 sT + 6 s + 1) , a) (b) Figure 20:
Prepped buckets of heights 1 and 0,respectively (a) (b)
Figure 21:
Unprepped buckets of heights 1 and0, respectivelyso when the first arrives, every cell in the first four rows outside the lock must be full for survival,and no cell can ever be placed in an empty row.If we survive until the first by filling all cells in the first four rows except the lock, then theremaining and pieces clear the board. Hence it suffices to show that for r = 4 , the given Tetrisgame is clearable if and only if the instance of is solvable. Henceforth we assume r = 4 .Now, to complete the proof, we show that the buckets must be filled in the manner shown in Figure 19, sosome cell must be left empty if there is no solution. Define prepped (Figure 21) and unprepped (Figure 20) buckets as in Section 4.3. We define the height in the same manner by the number of notches.We can now prove an analogue of Claim 4.11: Claim 5.7.
If an is placed in an unprepped bucket of height at least 1, it must form a prepped bucketof the same height.
Proof.
In Figure 22, we show all cases that don’t leave the leftmost cell disconnected from the outside. Thefirst one works; in the others, we attempt to place an incorrectly, and mark some cell that can neverthereafter be filled. (a) (b) (c) (d)
Figure 22:
Ways to place an into an unprepped bucket of positive height. Cases in which the leftmostempty cell is neither filled nor connected by a path of empty cells to the outside are not shown.
Claim 5.8.
None of , , may be placed in an unprepped bucket of height at least . Proof.
In Figure 23, we show all possible cases. In every one, we attempt to place an incorrectly, andmark some set of cells (usually exactly one) that can never thereafter be simultaneously filled. For instance,in Figure 23(p), the only piece (of the ones we ever use) that can fill the bottom marked cell is , butonce a is placed, no piece can fill the top marked cell.
Proof.
There are only eight empty cells in an unprepped bucket of height 0, less than the 12 needed.
Claim 5.9.
When the sequence (cid:104) , , (cid:105) is placed in a prepped bucket of height h ≥ , the bucketmust end up as a prepped bucket of height h − . Proof.
In Figure 24, we show all possible cases. In every one, we attempt to place a , , . The firstone works. For every other one, we show some cell that cannot be filled by the next piece.
Claim 5.10.
When the sequence (cid:104) , (cid:105) is placed in a prepped bucket of height h ≥ , the bucket mustend as an unprepped bucket of height h − . Proof.
In Figure 25, we show all possible cases. In every one, we attempt to place a , . The firstone works. For every other one, we show some cell that cannot be filled by the next piece.17 a) (b) (c) (d)(e) (f) (g) (h)(i) (j) (k) (l)(m) (n) (o) (p)(q) (r) (s) (t)(u) (v) Figure 23:
Ways to place an , , or into an unprepped bucket.The following corollary follows from Claims 5.7, 5.8, 5.9, and 5.10:
Corollary 5.11.
Suppose that before the a i -sequence arrives, all buckets are unprepped and have height . Then, the entire a i -sequence must be placed in one bucket, and the height of that bucket decreasesby a i (the height cannot go below 0) and is unprepped at the end. Proof.
The initial of the a i -sequence must go in some bucket; say it has height h + 1 . By Claim 5.7,the bucket is now prepped with height h + 1 . By Claim 5.8, all pieces of the a i -sequence must go into thisbucket. Now, we have that the total area of pieces remaining in the a i -sequence is a i − , while the totalarea remaining in the bucket is h + 20 . Thus, since the total area of the pieces cannot exceed the areaof the bucket, we must have a i − ≤ h + 20 , and therefore (since a i , h are integers), a i ≤ h . Now, byClaim 5.9, each (cid:104) , , (cid:105) sequence must decrease the height of the bucket by 1, so after all of thesethe bucket is now prepped and has height h − a i + 2 (note that at each step the bucket had height atleast 2). Now, the height of the bucket is still at least 2, so we can apply Claim 5.10. Thus, after the final (cid:104) , (cid:105) , the bucket must become an unprepped bucket of height h − a i + 1 , as desired. Theorem 5.12. If G ( P ) has a clearing trajectory sequence, then the instance P has a solution.Proof. Numbering the buckets , , . . . , s , let S b be the set of i such that the a i -sequence is placed in bucket b , so the S b form a partition of { a , a , . . . , a s } . By Corollary 5.11, the sum (cid:80) i ∈ S b a i is at most the originalwidth of each bucket, which is T + 1 . But note that the sum is a multiple of 3, so it must in fact be atmost T . However, (cid:80) si =1 a i = 3 sT , so equality must hold for each individual sum.Thus, we have (cid:80) i ∈ S b a i = 3 T for each b . Dividing out by 3, (cid:80) i ∈ S b a i = T , and thus the S b represent avalid 3-partition. 18 a) (b) (c) (d)(e) (f) (g) (h)(i) (j) (k) (l)(m) (n) (o) (p)(q) (r) Figure 24:
Ways to place an , then a , then an into a prepped bucket, where the following pieceis an . (a) (b) (c) (d) (e) (f)(g) (h) (i) (j) (k) (l)(m) (n)
Figure 25:
Ways to place an and then an into a prepped bucket, where the following piece isan .
As a transition to the next topic, which considers ≤ k -tris , we point out that even just one row is triviallyNP-hard when we allow k (cid:29) : Proposition 5.13. ≤ k -tris is strongly NP-hard.Proof. We reduce from . The board is s ( T + 1) units wide, with an initially filled square every T + 1 spaces, leaving s gaps of length exactly T . The first s pieces are × a i for i = 1 , , . . . , s . The linecan clear if and only if has a solution. A final × s ( T + 1) piece forces a loss otherwise.19 Starting from an empty board is NP-hard O (1) -size pieces, 8 columns Theorem 6.1. c -column Empty ( ≤ c + 1) -tris is NP-complete for any c ≥ . In particular, -columnEmpty ( ≤ -tris is NP-complete.Proof. We force the player to build the board initial configuration B from Theorem 4.1’s proof, startingfrom an empty board, using pieces of size at most c + 1 . We build B from the bottom up using pieces ofheight c + 1 (so they cannot be rotated) and width c (so they also cannot be translated). Specifically, if wewant to add a cell in column i of the top row that already has a cell, we send a c × c square with an extracell in column i below it (in the bottom ( c + 1) st row); the c × c square lands above the top existing rowand clears, leaving just a cell in column i in the previous top row. To start a new row with a cell in column i , we send a c × c square with an extra cell in column i above it (in the top ( c + 1) st row); the c × c squarelands above the top existing row and clears, leaving just a cell in column i in its own row.These two operations suffice to create any legal board configuration, until we get near the top of theboard in which case the partial lock out would cause the player to lose. When we fill the last pixel in the ( c + 1) st row of the board, we send a different piece: instead of putting a c × c square above that pixel, weput the desired board configuration for the top c rows. By modifying the construction of Theorem 4.1 tohave a lot of rows after the first two where just the first, seventh, and eighth columns are empty, we canguarantee the additional property that this piece shape is a connected polyomino.Then we proceed as in the reduction of Theorem 4.1. Theorem 6.2. O ( n ) -tris is NP-complete.Proof. The problem is in NP because checking whether a sequence of Tetris piece placements clears theboard can be done in polynomial time, so it suffices to prove that 3-column Tetris with polynomially sizedpieces is NP-hard.As in the previous section, we reduce from to perfect-information Tetris.Given an instance of with target sum T and integers { a , . . . , a s } , we construct an instanceof 3-column Tetris as follows, and as pictured in Figure 26:1. The board is 3 columns wide and (3 t + 1) s rows tall.2. In the left column, the cells whose row is a multiple of t + 1 are filled (starting with the bottom one,row ).3. The middle column is empty.4. In the right column, the cells whose row is not a multiple of t + 1 are filled.5. The sequence of pieces is an a i sequence , a right filling sequence , and a clearing sequence :(a) The a i sequence is, for each a i , a a i × rectangle.(b) The right filling sequence is s × squares.(c) The clearing sequence is a single (3 T + 1) s × rectangle.This initial position can be reached by normal Tetris play, by placing pieces, pieces, and one × piece at the top. If, as in Section 6, all lines clear (and lines above descend), before the game checkswhether the player lost by breaching the ceiling, then we can force this position from an empty board, bysending pieces consisting of a × square and one extra cell, which can’t rotate and therefore add a pixel.If the instance has a solution, then the constructed Tetris problem has a solution: for eachtriple { a i , a j , a k } with sum T in the solution, we’ll fill one of the empty blocks of size t in theleft column by moving the rectangles of size a i × , a j × , and a k × down the empty middle column andthen left. Then use the s squares of the right filling sequence to fill the s empty cells in the right column,20 igure 26: The initial board when T = 3 and s = 3 .which are again accessible by the middle column. Finally, place the (3 T + 1) s × rectangle in the middlecolumn, which clears the puzzle.If the Tetris problem has a solution, we can construct a solution to the instance.First, there are T + 1) s empty cells in the starting board, so at least T + 1) s cells from the givenpieces must fill those empty cells. The total number of cells in the given sequence of pieces is T + 1) s : (3 T ) s from the a i sequence, s from the right filling sequence, and (3 T + 1) s from the clearing sequence,so every cell from the given pieces must fill one of the empty cells in the (3 T + 1) s rows that are initiallynonempty. The final (3 T + 1) s × rectangle puts pieces in (3 T + 1) s rows, so those must be exactly theinitially nonempty rows; that is, no rows can be cleared before the final piece, and no pieces can be placedin the center column before the final piece.The T empty cells in the right column can be filled only by × rectangles, so the T pieces of the rightfilling sequence must be placed there.Finally, the pieces of the a i sequence can only go in the left column and fill the s empty spaces of size × T , so the assignment of a i blocks to those spaces gives a solution to the problem.If we relax the constraint that the initial position can be reached by normal Tetris play, then essentiallythe same proof shows that Tetris is hard even with only 2 columns: just delete the right column and theright filling sequence. More interestingly, we can apply this idea to the regular game with two rows: Theorem 6.3. O ( n ) -tris is NP-complete.Proof. We reduce from . If the instance of has s triples and target sum t , theTetris board has 2 rows and s (4 t + 1) + 2 columns. We first send a piece of width s (4 t + 1) + 1 columns;on the bottom row, with every cell present in on the bottom row and only the multiples of t + 1 (startingwith 0, for a total of s + 1 of them) present on the top row. This piece can only be placed in two positions,and either of them leaves s buckets of size t on the top row and a single × hole at the side. We thensend, for each a i , a × a i rectangle; these can’t fill the × hole without losing, so they must be placed inthe buckets on the top row. If there’s a solution to the instance, the buckets can be filled bythe × a i rectangles exactly by filling the buckets according to such a solution; if there is no solution, theTetris game is lost. Finally, we send a × piece, which can go in the hole at the side to clear the Tetrisboard and survive.This result is tight: 21 roposition 6.4. O ( n ) -tris can be solved in linear time.Proof. In ≤ k -tris , any piece that is not × k results in an immediate loss for the player (asin the proof of Proposition 3.1). If there are only × k pieces in the sequence, we proceed in rounds betweenline clears. For each round except the last, we compute the number m of pieces before the next round byfinding the prefix of remaining pieces whose total area is exactly the board width. If such an m exists, wecan place those m pieces greedily from left to right in the initially empty row, and the row clears. If no such m exists, then we attempt to place the remaining pieces greedily from left to right; if we run out of space,then no strategy could have survived. To demonstrate the versatility of Tetris constructions, we designed an 8-row font where each letter of thealphabet is constructed as a stacking of exactly one copy of each tetromino (treating reflections as distinct,as in Tetris). Figure 27 shows the fully assembled font. Crucially, these letters can actually be constructedin Tetris by stacking the pieces one at a time in some order (dependent on the letter), while being supportedby the previously stacked pieces according to Tetris physics. Figure 28 illustrates the stacking order in apuzzle version of the font, where the pieces are spread out vertically according to their fall order, but placedcorrectly horizontally; letting the pieces fall straight down reveals the letters in Figure 27. A companion webapp allows you to type a custom message, and animate the stacking. Figure 29 shows a sample animation. Figure 27:
Tetris font: each 8-row letter can be made by stacking each of the seven tetrominoes exactlyonce in some order.
The main open problems are to determine the critical threshold for the minimum number c ∗ of columnsand the minimum number r ∗ of rows for which c ∗ -column Tetris and c ∗ -row Tetris are NP-complete,respectively. We proved here that c ∗ ∈ [3 , and r ∗ ∈ [2 , . We conjecture that r ∗ = 2 , i.e., that http://erikdemaine.org/fonts/tetris/ etris is NP-complete. These problems are open even for c ∗ -column O (1) -tris and r ∗ -row O (1) -tris ,i.e., allowing constant-size pieces.Our hardness proof for c -column Tetris survival relies on the partial lock out rule, which has beenchanged in modern versions of Tetris [Blu09]. We can avoid this assumption, and also allow constant reactiontimes for the player, by adding many rows on top and using the reservoir trick from [BDH +
04, Section 4.2].However, this approach works only for c odd. Is survival NP-hard without the partiallock out rule?Modern versions of Tetris also have a “holding” function, where the player can put one piece aside forlater use. Can existing results be re-established, or existing open problems be solved, with the addition ofthis feature?Many other questions posed in prior papers on Tetris still remain open. For example, does Tetris remainhard from an empty board? What is the complexity of Tetris with imperfect information or randomness?Are there guaranteed loss sequences in n -tris for all n ? Acknowledgments
This work was initiated during open problem solving in the MIT class on Algorithmic Lower Bounds:Fun with Hardness Proofs (6.892) in Spring 2019. We thank the other participants of that class — inparticular, Joshua Ani, Jonathan Gabor, and Claire Tang — for related discussions and providing an inspiringatmosphere. We also thank the anonymous referees for helpful comments.
References [BDH +
04] Ron Breukelaar, Erik D. Demaine, Susan Hohenberger, Hendrik Jan Hoogeboom, Walter A.Kosters, and David Liben-Nowell. Tetris is hard, even to approximate.
International Journal ofComputational Geometry and Applications , 14(1–2):41–68, 2004.[Blu09] Blue Planet Software. . March 2009. https://tetris.fandom.com/wiki/Tetris_Guideline.[DDE +
17] Erik D. Demaine, Martin L. Demaine, Sarah Eisenstat, Adam Hesterberg, Andrea Lincoln, JaysonLynch, and Y. William Yu. Total Tetris: Tetris with monominoes, dominoes, trominoes, pentomi-noes, . . . .
Journal of Information Processing , 25:515–527, 2017.[Sip06] Michael Sipser.
Introduction to the Theory of Computation , volume 2. Cengage learning, 2006.[Spa14] Matthew Sparkes. Tetris at 30: a history of the world’s most successful game.
TheTelegraph n . Information andcontrol , 10(2):189–208, 1967. 23 igure 28:
Tetris puzzle font: if each piece falls vertically, the result is Figure 27.24 igure 29:igure 29: