tetris_complete module

This module simulates the surface growth by Tetris pieces. It includes functions to generate random Tetris pieces, calculate their landing positions on a substrate, and simulate a game of Tetris for a given number of steps and a defined grid size.

By Ian Ruau (iir0001@auburn.edu) and Mauricio Montes (mauricio.montes@auburn.edu) Date: 12/2023

tetris_complete.Tetris_Choice()

Randomly selects a Tetris piece and its orientation.

There are 7 Tetris pieces:

  • 0 : the square;

  • 1 : the line;

  • 2 : the L;

  • 3 : the J;

  • 4 : the T;

  • 5 : the S;

  • 6 : the Z.

There are 4 orientations for each piece:

  • 0 is the original orientation;

  • 1 is the 90 degree rotation;

  • 2 is the 180 degree rotation;

  • 3 is the 270 degree rotation.

Returns:

A 2-element array: the first element is the piece type (0-6); the second element is the orientation (0-3).

Return type:

numpy.ndarray

To-Do’s

  • Add input file to specify the probability of each piece.

tetris_complete.Tetris_RD(width, height, steps)

This function simulates the Tetris Decomposition model on a substrate.

Parameters:
  • width (int) – The width of the substrate.

  • height (int) – The height of the matrix.

  • steps (int) – The steps to simulate.

Returns:

Filename of the output file.

Return type:

string

tetris_complete.ffnz(matrix, height, column)

Finds the first non-zero entry in a specified column of a matrix.

Parameters:
  • matrix (numpy.ndarray) – The matrix to search.

  • height (int) – The height of the matrix.

  • column (int) – The column index to search in.

Returns:

The index of the first non-zero entry.

Return type:

int

tetris_complete.main()

To use the script from terminal, the following options are expected:

-w, --width

: Width of the substrate (default: 100)

-e, --height

: Maximum height of the substrate (default: 60)

-s, --steps

: Number of particles to drop (default: 5000)

It returns:

  1. A text file representing the substrate state.

Example

> ptyhon3 tetris_complete.py -w 100 -e 60 -s 5000

In this example, the script will simulate Tetris Decomposition on a substrate of size 100x60 for 5000 steps.