A simulator for Tetris that takes in a comma separated list of Tetris pieces and positions and return the height of the final board.
The pieces take the following shape:
An example input could be
Q0,I2,I6,I0,I6,I6,Q2,Q4
Meaning in the game we first add shape T where its left column is positioned at column with index 0, then adding shape Z where its left column is positioned at column with index 2, and so on ...
Here, the board has 10 columns. There is no height limit.
After the first three pieces drop, the result is as follows:
The bottom line is cleared, and after the next five pieces drop, here is the result:
The second line clears, and the final result is as follows:
Hence, the simulator returns height "3".
Running in command line
$ ./tetris < input.txt > output.txt
Where input.txt
contains sequences of pieces inputs:
Q0
Q0,Q2,Q4,Q6,Q8,Q1
Q0,I2,I6,I0,I6,I6,Q2,Q4
And output.txt
should contain the corresponding resulting heights:
0
2
2
3
To run the unit tests you will have to install pytest. Then simply:
cd tests
python -m pytest ./test_tetris.py