This Python project provides a simple implementation logic of a Tetris game engine. The code allows you to simulate the decent of Tetris blocks in a grid and calculate the occupied height of the blocks.
- Initialized an empty grid of size 10x10.
- Supported Tetris block shapes -> "q," "z," "s," "t," "i," "l," and "j"
- Calculates the max height of Tetris blocks in the grid after every row.
- Completed rows vanishes from the grid.
- Processes multiple lines of input, each representing a sequence of pieces entering the grid.
- Outputs the resulting height of the remaining blocks within the grid for each line of input.
- Clone the https://github.com/kaustubh285/tetris_python repository.
- Navigate to the project directory:
cd tetris_python - Run the script with the following command
python tetris.py < input.txt > output.txt.
The script gets the input data from the input.txt and prints out the occupied height which is written to the output.txt.
- The code defines a dictionary
self.valuesthat maps shape letters to their corresponding block configurations represented as lists of lists. - The
check_topmost_occupantfunction is responsible for placing a new piece into the grid by iteratively moving it down until it reaches the bottom or collides with another resting block. - The
update_gridfunction updates the grid by setting the cells corresponding to the final coordinates of the new piece to 1 (occupied). - The
check_if_row_completefunction checks if any rows in the grid are completely filled and removes those rows, inserting new empty rows at the top. - The
check_and_update_heightfunction calculates the height of the occupied blocks in the grid.
- GitHub: kaustubh285