Holder

Queue

class tetris_gymnasium.components.tetromino_holder.TetrominoHolder(size=1)[source]

A holder can store one or more tetrominoes for later use in a game of Tetris.

Tetrominoes can be swapped in- and out during the game.

Parameters:

size – The number of tetrominoes to store. Defaults to 1.

Methods

TetrominoHolder.swap(tetromino: Tetromino) Tetromino | None[source]

Swap the given tetromino with the one in the holder.

This implementation uses a queue to store the tetrominoes. Tetrominoes are only returned once the queue is full. If this is not the case, the provided tetromino is stored in the queue and None is returned.

Parameters:

tetromino – The tetromino to store in the holder.

Returns:

The oldest tetromino that’s stored in the queue, if the queue is full. Otherwise, None.

TetrominoHolder.reset()[source]

Reset the holder to its initial state. This involves clearing the queue.

TetrominoHolder.get_tetrominoes()[source]

Get all the tetrominoes currently in the holder.