Follow Slashdot blog updates by subscribing to our blog RSS feed

 



Forgot your password?
typodupeerror
×
Games Entertainment

Tetris Is Hard: NP-Hard 345

bughunter writes "Analysts at MIT Laboratory for Computer Science, who have been busy translating, rotating and dropping, have demonstrated what the rest of us suspected: Tetris is hard. Technically, it's 'NP-hard,' meaning that there is no efficient way to calculate the necessary moves to "win," even if you know in advance the complete order of pieces, and are given all the time you need to make each move. At least there's one geek classic that refuses to fall to the scrutiny of mathematicians."
This discussion has been archived. No new comments can be posted.

Tetris Is Hard: NP-Hard

Comments Filter:
  • Winning (Score:3, Interesting)

    by scotch ( 102596 ) on Friday October 25, 2002 @02:23AM (#4527798) Homepage
    How the hell do you win at tetris? I remember it getting faster and faster but never ending. Maybe I just sucked at the game, or was playing a clone.
  • Re:Winning (Score:3, Interesting)

    by kjd ( 41294 ) on Friday October 25, 2002 @02:34AM (#4527830)
    In the Game Boy version (1989), you got little audiovisual rewards for breaking certain point barriers. If you broke 50,000, you'd get to see a little rocket launch. 100,000 lines (I think this is the right number) would net you a takeoff of the Space Shuttle.
  • Re:Poll (Score:2, Interesting)

    by MrMetlHed ( 518539 ) on Friday October 25, 2002 @02:37AM (#4527839) Homepage
    Level 30 on Tetris DX for the Gameboy color. But only because it stops getting faster at level 30. All told I had over a thousand lines, something like 2.2 million points. At that speed you basically end up playing the game in the Next Piece window and hoping you tap the buttons fast enough to make it fall properly.

    Charlie

  • by Flakeloaf ( 321975 ) on Friday October 25, 2002 @02:41AM (#4527855) Homepage
    Next we'll see occultists studying Pacman.

    At least Pacman has a perfect solution [twingalaxies.com]. No fancy math required, just a good hot meal beforehand and a little patience.
  • by fireboy1919 ( 257783 ) <rustyp AT freeshell DOT org> on Friday October 25, 2002 @02:42AM (#4527860) Homepage Journal
    Now whenever I lose the latest new game I can just say, "I have just determined that this game is very hard. Its NP-Hard, in fact." I'm sure that'll impress all the lady-geeks around that would otherwise have thought me intellectually inferior for losing the game.

    Interesting thing about NP-hard stuff, though, especially when it comes to things like video games. There are a group of techniques that work to solve NP-hard problems SOME of the time based around searching. Because there are multiple winning solutions for Tetris, and there is are several quite obvious heuristics to aid in the search (such as planning so that you leave indentations that will fit the next piece(s), and attempting to fill lower lines before higher ones), it's probably still solvable in polynomial time MOST of the time.

    Of course, solvable is relative. The optimal solution (highest score) for a finite number of moves cannot be proven without trying all combinations of states, but to simply finish, there are lots of solutions.
  • memory optimization (Score:2, Interesting)

    by fat32 ( 620360 ) on Friday October 25, 2002 @02:46AM (#4527877)

    It seems to me that this would have some applicability to memory stacks. After all, Tetris is a stack that doesn't need to be emptied in order for the rows above it to be used efficiently.

    First I was thinking that Tetris is just a recursive problem; if a certain subset of pieces can be used to achieve a Tetris (4-row removal) then they can be removed from consideration. But then I realized that this would affect one's options for clearing rows below that, or pieces to come. It sounds like the only way to do this is by considering all (n_pieces*rotation)! possible plays.

    Is this perhaps proof that memory usage cannot be optimized beyond a certain point?
  • Re:Tetris "ends"? (Score:5, Interesting)

    by fireboy1919 ( 257783 ) <rustyp AT freeshell DOT org> on Friday October 25, 2002 @02:52AM (#4527898) Homepage Journal
    Depends on the version. For the original gameboy version, in the count up mode (starting at level 1 and going up), you got to see images of a spaceship every 10 levels (if I remember right).

    It launched when you reached the final level, I think. I did it once, and was very happy, but it sure wasn't as much fun as the game itself.

    If you play the countdown mode (start with 40 pieces at a constant level and eliminate all of them) at the highest level (9, I think, or maybe 10), then when you finish you got to hear all of the instruments playing together (each of the other levels had instruments playing).

    The ending of Dr. Mario was a lot more interesting.
  • Re:Winning (Score:3, Interesting)

    by stevey ( 64018 ) on Friday October 25, 2002 @02:59AM (#4527917) Homepage

    You also win if all your opponents are dead in the multiplayer games, like Tetrinet [tetrinet.org]. (There's a good client out for Linux too - gTetrinet [sourceforge.net]).

    Unfortuntately there is a limit of six players to the game; but it's still been taking my workplace by storm for the past two weeks.

  • Wait a second... (Score:5, Interesting)

    by Chemical ( 49694 ) <nkessler2000&hotmail,com> on Friday October 25, 2002 @03:00AM (#4527918) Homepage
    A lot of Tetris and Tetris type games had a two player mode that had the option for CPU controlled player two if you didn't have any friends. If you set the AI to the maximum level, you would be instantly crushed no matter how good you were. The CPU could instantly decide where to place the blocks, and never made a bad move. Try setting Tetris Attack for the SNES to play against itself for a while. It's kind of impressive.

    My question is this: How is it Nintendo et. al. can program an incredibly skilled Tetris AI, but scientists at MIT cannot?

  • by Boss, Pointy Haired ( 537010 ) on Friday October 25, 2002 @03:56AM (#4528053)
    Just a warning to those becoming or already hooked on Tetris.

    I used to be a serious Tetris junkie, and played on many different versions on different platforms.

    Playing so much, I became "quite good", and this meant that blocks were falling extremely rapidly.

    To play tetris at high speed, you glance very quickly at the arriving piece, then move your gaze back to the pile to asses the position - moving the piece without looking at it. Repeat until bored.

    Then my eyes packed up. I basically developed something like "RSI" in both eyes - my eyes would twitch repeatedly up and down in the exact movements used in high speed tetris. This whilst not even playing tetris.

    I diagnosed the problem myself and quit playing, but it took a few months to clear up.

    Just a warning. I still play it on and off.
  • by Find love Online ( 619756 ) on Friday October 25, 2002 @04:22AM (#4528115) Homepage
    Tetris is all about putting things where they fit, not some grand master strategy.

    Actually, Tetris is all about risk management. See my other post on the subject. Once you get good at fitting the pieces together, the game becomes a question of figuring how risky building (and destroying) certain structures is, based on the probability of getting a long, or L shape.

    And us biological constructs have an advantage, where we can more or less decide on the fly if X piece will fit decently enough in Y hole without having to go through a bajillion IF-THEN logic loops.

    Hrm... What is an "if-then" loop?

    Seriously though, in this case it shouldn't take more then a handful of loops and conditionals to figure out if a piece fits somewhere.

    Playing Tetris is not actually a hard problem for a computer. NP-Hard and 'hard for a computer' are totally different things.

    In general, the only reason human brains are better at some kinds of problems then computers is because computers are simply more limited in processing power. It would take thousands upon thousands of PCs hooked together to equal one human brain in terms of raw processing power.

    (I've heard estimates that PCs will equal the human mind in 20 years, figuring with Moore's law, that would mean the human brain is about 2^13 times more powerful then a PC, or 8192 times)

    Computational theory applies to all computing devices, including brains and other neural networks.

    If something is NP-hard for a circuit, its NP hard for a brain too.
  • by Stephen ( 20676 ) on Friday October 25, 2002 @04:39AM (#4528149) Homepage
    It's also the case that Tetris is unwinnable against a malevolent machine, which chooses a nasty sequence of pieces. In the sense that even if you know the pieces in advance, you will eventually fill any tower of finite height.

    I've seen two independent proofs of this (and other people have surely done it too) but I can't find an online proof. But I think that one way for the machine to win is to drop S and Z pieces in any irrational proportion.
  • by Keev ( 573393 ) on Friday October 25, 2002 @04:47AM (#4528166)
    Some little-known related references: A CS student at Univ of BC, John Brzustowski, did his Master's thesis on the problem of winning at Tetris if the computer is aware of your moves and reacting to them. He apparently proved that there is a finite sequence of tetrominos, which, if the machine selects them, you must lose. His work is cited in this later paper by H. Burgiel called "How to Lose at Tetris", which proves more generally that the computer can always produce a sequence of lose-forcing tetrominos, whether or not it's aware of your moves: paper is here [nec.com].
  • by Plug ( 14127 ) on Friday October 25, 2002 @05:50AM (#4528304) Homepage
    Chronic Logic [chroniclogic.com], the people who brought you the cool Pontifex bridge builder game, have a game called Triptych, which can loosely be defined as 'Tetris meets Columns with physics'.

    When you drop blocks, gravity affects them, and you can move blocks around with other blocks. (If your blocks aren't placed square, they don't land square! V shaped blocks tend to sit upside down etc) You get rid of blocks not by making lines, but by getting 3 of the same colour in a row, which then 'energize' and let you eat other blocks of the same colour.

    And the best part - it's written in the Simple DirectMedia Layer [libsdl.org], so it runs on Windows, Mac or Linux. Check it out [chroniclogic.com]. (The main site is in Flash; this site takes you straight to it.

    (Disclaimer - I am nothing to do with Chronic Logic - I just like the game.)
  • Re:Winning (Score:1, Interesting)

    by Anonymous Coward on Friday October 25, 2002 @06:31AM (#4528385)
    NP-hard maybe, but damn these players make tetris look easy!

    These are from Tetris the Grandmasters 2 Plus arcade machine playing on Death mode.

    At least there's an end to Death mode. :p

    http://homepage2.nifty.com/arika_download/mpeg/dea th_800.mpg [nifty.com] http://homepage2.nifty.com/arika_download/mpeg/Dea th-Gm02.mpg [nifty.com] http://homepage2.nifty.com/arika_download/mpeg/Dea th-Gm05.mpg [nifty.com]
  • bastion strategy (Score:3, Interesting)

    by Animaether ( 411575 ) on Friday October 25, 2002 @07:31AM (#4528498) Journal
    The reason you'd leave it open in the center is because.. if a beam block appears, you...

    1. Won't die immediately, when the block is vertical and Your stacks are high, as it'll slot into the gap.
    2a. can drop it immediately, making a tetris.
    2b. have to only rotate once to make it vertical, followed by 2a.
  • by yerricde ( 125198 ) on Friday October 25, 2002 @07:48AM (#4528535) Homepage Journal
    Here's a Europop version of "Korobeyniki" [mp3s.com], which many players think of as "the Tetris song".
  • by frleong ( 241095 ) on Friday October 25, 2002 @08:33AM (#4528717)
    There is a difference between a solution and an optimal solution. The fact that you don't lose doesn't mean that you're getting the best score. Finding the best way to fit a "T" block, for example, is simply much harder than just finding a place to place it.
  • by Vegan Pagan ( 251984 ) <deanasNO@SPAMearthlink.net> on Friday October 25, 2002 @09:10AM (#4528922)
    If Nintendo is to be believed, Tetris is hard for computers and Dr. Mario is hard for humans.

    They published a SNES game with both Tetris and Dr. Mario on one cartrige. I'm assuming both were programmed by the same team, since it let both games run simultaneously.

    In either game you could play against the AI. You could choose the AI player's smarts, piece drop speed, and starting clutter. When I played against the smartest AI in Tetris, and made all else equal for it and me, I could just beat it, especially when starting with a clear field where I guess the player must be most "creative". But in Dr. Mario the AI was nearly perfect! As fast as possible and the best possible moves! Even on top speed and max clutter the AI almost never caved in! And to me, Dr. Mario is a more complicated game than Tetris.

    How could this be?
  • Time Out! (Score:3, Interesting)

    by kiwifr00t ( 620461 ) on Friday October 25, 2002 @09:35AM (#4529056)
    I'm either missing something or the boys at the MIT lab are thinking too hard.
    Years ago I wrote a program to play tetris and it did just fine! I know because it played directly against the tetris I had on my computer.
    I'll explain how it worked:
    In 1989 I lived in England and had lots of spare time to tinker with my computer (it was an old PC running at 4.77Mhz).
    I thought DOS Tetris was the coolest thing since mini skirts and was also dabbling with TSR programs at the time (TSR = Terminate and Stay Resident). These would let you run one program in the background while another program runs.
    So, naturally, I wrote a TSR program to play Tetris.
    I would start the TSR and then start the game. The TSR would look in the video buffer and analyze tetris as it ran. It would look at the layout of the board and look at the next piece. With some relatively simple logic and a series of rules it weighed the merits of various positions for the piece. To make the move it would stuff keystrokes in the keyboard buffer, such as Rotate, Rotate, Left, Left, Left, Drop. Then it simply waited till the keyboard buffer was empty (the piece had been moved) and look for the next piece.
    I could just sit back and watch...
    At first it wasn't very good but with some tweaking of rules it improved drastically.
    It would do much better than I could do manually, with pieces spinning, moving and dropping like crazy until the game really sped up. Then, with the limitations of a slow computer it couldn't analyze the best move and get the keystrokes in the buffer in time. Once it hit this threshold the pieces would start to stack up and it would be 'game over'.
    I think at the time and the version I had I personally could get a score of around 8000. The TSR could get scores up to around 15000.

    Just something to think about.....
    --
    Geoff
  • Re:Hey... (Score:4, Interesting)

    by athmanb ( 100367 ) on Friday October 25, 2002 @10:22AM (#4529491)
    If you leve the open column in the center, you have an even count of blocks on the left side, and an odd count on the right side. This means you have more possibilities to stack different classes of blocks.

    Plus, you can use both right- and left-handed L blocks as a makeshift solution if your stack gets too high.
  • by terrab0t ( 559047 ) on Friday October 25, 2002 @01:55PM (#4531430)
    How about another challenge? Try scoring as many points as possible without getting a single line [disflux.net].

Top Ten Things Overheard At The ANSI C Draft Committee Meetings: (5) All right, who's the wiseguy who stuck this trigraph stuff in here?

Working...