Board

class core.board.Board(gamestring: str = '')[source]

Bases: object

Game Board.

NEIGHBOR_DELTAS: Final[tuple[Position, Position, Position, Position, Position, Position]] = ((1, 0), (1, -1), (0, -1), (-1, 0), (-1, 1), (0, 1))

Offsets of every neighboring tile in each direction.

ORIGIN: Final[Position] = (0, 0)

Position of the first piece played.

bugs_from_pos(position: Position) list[Bug][source]

Retrieves the list of bug pieces from the given position.

Parameters:

position (Position) – Tile position.

Returns:

The list of bug pieces at the given position.

Return type:

list[Bug]

calculate_valid_moves() set[Move][source]

Calculates the set of valid moves for the current player.

Returns:

set of valid moves.

Return type:

set[Move]

property current_opponent_has_won: bool

Checks whether the current player’s opponent has won.

Parameters:

color (PlayerColor) – Player color.

Returns:

Whether the current player’s opponent has won.

Return type:

bool

property current_player_has_won: bool

Checks whether the current player has won.

Parameters:

color (PlayerColor) – Player color.

Returns:

Whether the current player has won.

Return type:

bool

property current_player_queen_in_play: bool

Whether the current player’s queen bee is in play.

Return type:

bool

property current_player_turn: int

Turn number of the current player.

Return type:

int

hash() int[source]

Returns the current Zobrist Hash value.

Returns:

Zobrist Hash value.

Return type:

int

pieces_in_play(color: PlayerColor) int[source]

Returns how many pieces are in play for the specified player.

Parameters:

color (PlayerColor) – Player color.

Returns:

Amount of pieces in play.

Return type:

int

play(move_string: str)[source]

Plays the given move.

Parameters:

move_string (str) – MoveString of the move to play.

Raises:

ValueError – If the game is over.

play_parsed(move: Move | None, move_string: str | None = None)[source]

Plays the given move.

Parameters:
  • move (Optional[Move]) – Move to play.

  • move_string (Optional[str]) – MoveString of the move to play.

Raises:

ValueError – If the game is over.

pos_from_bug(bug: Bug | None) Position | None[source]

Retrieves the position of the given bug piece.

Parameters:

bug (Bug) – Bug piece to get the position of.

Returns:

Position of the given bug piece.

Return type:

Optional[Position]

queen_neighbors_by_color(color: PlayerColor) int[source]

Returns how many neighbors does the queen of the specified player have.

Parameters:

color (PlayerColor) – Player color.

Returns:

Amount of queen neighbors.

Return type:

int

stringify_move(move: Move | None) str[source]

Returns a MoveString from the given move.

Parameters:

move (Optional[Move]) – Move.

Returns:

MoveString.

Return type:

str

undo(amount: int = 1) None[source]

Undoes the specified amount of moves.

Parameters:

amount (int, optional) – Amount of moves to undo, defaults to 1.

Raises:
  • ValueError – If there are not enough moves to undo.

  • ValueError – If the game has yet to begin.

property valid_moves: str

Current possible legal moves in a joined list of MoveStrings.

Return type:

str

class core.board.QueenNeighbors(neighbors: set[core.game.Position], count: int = 0)[source]

Bases: object

count: int = 0
neighbors: set[Position]