Skip to content

kaustubh285/tetris_python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tetris Coding Challenge

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.

Features

  • 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.

Usage

  1. Clone the https://github.com/kaustubh285/tetris_python repository.
  2. Navigate to the project directory: cd tetris_python
  3. 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.

Implementation Details

  • The code defines a dictionary self.values that maps shape letters to their corresponding block configurations represented as lists of lists.
  • The check_topmost_occupant function 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_grid function updates the grid by setting the cells corresponding to the final coordinates of the new piece to 1 (occupied).
  • The check_if_row_complete function 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_height function calculates the height of the occupied blocks in the grid.

Author

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages