sneks.engine.core.cell module

class sneks.engine.core.cell.Cell(x: int, y: int)

Bases: object

Represents a single cell on the game board. They can be used as reference points for getting neighboring cells, like:

>>> cell = Cell(1, 1)
>>> cell.get_left()
Cell(0, 1)
>>> cell.get_relative_neighbor(2, 3)
Cell(3, 4)
>>> cell.get_neighbor(Direction.DOWN)
Cell(1, 0)

Finally, it can be used to calculate distance between cells:

>>> cell_a = Cell(0, 0)
>>> cell_b = Cell(1, 0)
>>> cell_a.get_distance(cell_b)
1.0
x: int
y: int
get_relative_neighbor(x_offset: int, y_offset: int) Cell

Returns the cell with coordinates offset by the specified parameters.

Parameters:
  • x_offset – the amount to offset this cell’s x by

  • y_offset – the amount to offset this cell’s y by

Returns:

the cell at (self.x + x_offset, self.y + y_offset)

get_neighbor(direction: Direction) Cell

Gets a Cell’s neighbor in the specified direction.

Parameters:

direction – the direction of the neighbor

Returns:

cell in the specified direction

get_up() Cell
Returns:

cell in the up direction

get_down() Cell
Returns:

cell in the down direction

get_left() Cell
Returns:

cell in the left direction

get_right() Cell
Returns:

cell in the right direction

get_distance(other: Cell) float

Gets the distance between this cell and another.

Parameters:

other – cell to get distance to

Returns:

distance between the two cells