This is a puzzle based on Tetris. In this puzzle we are given the sequences of next n pieces that are going to fall from top. Our job is to maximize the score before its GameOver. There is no polynomial time algorithm known for the general Tetris but in this puzzle only the I (straight) tetrominoes are allowed. Though its not allowed to rotate them.
So here are the constraints:
- The board is a W x H rectangle
- We are given the sequences of next n tetrominoes
- Only I tetrominoes are allowed (horizontal or vertical)
- Piece rotation is not allowed
- Rows are cleared as they are filled up
- Board is initially empty
- 1 point is awarded per row cleared.
- Game is over when tetrominoes stack up to the top of the playing field.
Find the maximum score that can be obtained.
Example:
8 x 6 board. Next 7 tetrominoes are [——,|,|,——,|,——,|]
where '——'
represents horizontal I tetramino and |
represents vertical I tetramino.
Maximum possible score in this case is 3 using following strategy ('.'
represents empty board, '#'
represents part of tetramino piece).
Initially:
........
........
........
........
........
........
1st move:
........
........
........
........
........
####....
2nd Move:
........
........
.......#
.......#
.......#
####...#
3rd Move:
........
........
......##
......##
......##
####..##
4th Move:
........
........
......##
......##
####..##
####..##
5th Move:
........
........
.....###
.....###
####.###
####.###
6th Move:
........
........
.....###
####.###
####.###
####.###
7th Move:
........
........
....####
########
########
######## // bottom 3 rows are cleared so score is 3
final state:
........
........
........
........
........
....####
Even the best algorithm I could come up with takes exponential time where I am saving the state of the top layer of the current board (i.e. how high each column is). So this algorithm will take O((H^W)*n)
time since for each column there are H possibilities for height.
Can this be solved in polynomial time using dynamic programming or some greedy algorithm?