API Reference¶
Game logic¶
-
class
game_of_life.logic.GameMatrix(rows=200, columns=200)¶ Representation of Game of Life’s grid
Object of this class allows to check whether or not certain cell is alive, add and remove alive cells, and update a grid according to game’s rules
Attributes: - rows: int
Number of rows in a grid
- columns: int
Number of columns in a grid
- alive: dict
Dictionary of all alive cells in a grid with their positions as keys and their colors as values
- dead: set
Set of all dead cells that died during the latest game step
- all_dead_neighbours: set
Set of all dead cells which are neighbours of some of alive cells
Methods
make_step() Makes one step of a game neighbours(cell) Returns a set of all neighbours of a cell alive_neighbours(cell) Returns a set of all alive neighbours of a cell dead_neighbours(cell) Returns a set of all dead neighbours of a cell -
__getitem__(self, position)¶ Parameters: - position: tuple of int
Position (row, column) of a cell
-
__init__(self, rows=200, columns=200)¶ Parameters: - rows: int
Number of rows in a grid
- columns: int
Number of columns in a grid
-
__setitem__(self, position, value)¶ Parameters: - position: tuple of int
Position (row, column) of a cell
- value: str or False
Value to assign to a cell with specified position
-
alive_neighbours(self, cell)¶ Parameters: - cell: tuple of int
Cell coordinates (row, column)
Returns: - set of tuples of int
Set of all alive neighbours of specified cell
-
dead_neighbours(self, cell)¶ Parameters: - cell: tuple of int
Cell coordinates (row, column)
Returns: - set of tuples of int
Set of all dead neighbours of specified cell
-
make_step(self)¶ Process one step of a game changing sets of alive and dead cells
-
neighbours(self, cell)¶ Parameters: - cell: tuple of int
Cell coordinates (row, column)
Returns: - set of tuples of int
Set of all neighbours of specified cell