DWITE Online Computer Programming Contest

Tetris!

February 2008
Problem 5

You are working on a part of a Tetris!-playing AI that figures out the best move for the current piece. One part of the information required for this decision is knowing the maximum number of lines that the current piece can score on a given board.

The board size is 10 units in width and 6 in height. A line is complete when all 10 units across are filled with a game piece. The board is made up of 2 possible characters:

Pieces in play are standard Tetris pieces, and the current game piece will be described in a 4-by-4 matrix at the beginning of each data set. The pieces can rotate, and thus can be presented in any orientation. The same character map as the board applies. For example:

....
.##.
##..
....

The input file DATA5.txt will come in 5 sets, repeating the following pattern: 4 lines, 4 characters each, describing the current piece in play. This is followed by 6 lines, 10 characters each, describing the current board.

The output file OUT5.txt will contain 5 lines – the maximum number of lines that the piece can score.

Note: The piece starts dropping from above the supplied 6×10 board, and cannot be moved sideways during the fall. That is, you need to concern yourself only with the vertical drop.

Sample Input (only one set shown):
....
.#..
.###
....
..........
..........
..........
#####..###
##.##.####
#####.####
Sample Output (only one set shown):
2