games.core.game.core_board¶

Board models for the game framework.

This module defines the base Board class and specific implementations for different types of game boards.

Classes¶

Board

Base class for all game boards.

GridBoard

A grid-based board (Chess, Checkers, Scrabble).

Module Contents¶

class games.core.game.core_board.Board(/, **data)¶

Bases: pydantic.BaseModel, Generic[S, P, T]

Base class for all game boards.

A Board represents the playing surface in a game, containing spaces where pieces can be placed. It manages the spatial relationships between spaces.

Create a new model by parsing and validating input data from keyword arguments.

Raises [ValidationError][pydantic_core.ValidationError] if the input data cannot be validated to form a valid model.

self is explicitly positional-only to allow self as a field name.

Parameters:

data (Any)

add_space(space)¶

Add a space to the board.

Parameters:

space (S) – The space to add

Returns:

ID of the added space

Return type:

str

connect_spaces(space1_id, space2_id)¶

Connect two spaces bidirectionally.

Parameters:
  • space1_id (str) – ID of the first space

  • space2_id (str) – ID of the second space

Raises:

ValueError – If either space doesn’t exist on the board

Return type:

None

get_all_pieces()¶

Get all pieces currently on the board.

Returns:

Dictionary mapping piece IDs to pieces

Return type:

dict[str, T]

get_connected_spaces(space_id)¶

Get all spaces connected to the given space.

Parameters:

space_id (str) – ID of the space to get connections for

Returns:

List of connected spaces

Raises:

ValueError – If the space doesn’t exist on the board

Return type:

list[S]

get_player_pieces(player_id)¶

Get all pieces belonging to a specific player.

Parameters:

player_id (str) – ID of the player

Returns:

List of pieces owned by the player

Return type:

list[T]

get_property(key, default=None)¶

Get a board property.

Parameters:
  • key (str) – Property name

  • default (Any) – Default value if property doesn’t exist

Returns:

Property value or default

Return type:

Any

abstractmethod get_space_at_position(position)¶

Get the space at the specified position.

This is an abstract method that must be implemented by subclasses to provide position-based lookup.

Parameters:

position (P) – The position to look up

Returns:

The space at the position, or None if no space exists there

Return type:

S | None

is_position_valid(position)¶

Check if a position is valid on this board.

Parameters:

position (P) – Position to check

Returns:

True if the position is valid, False otherwise

Return type:

bool

place_piece(piece, position)¶

Place a piece at the specified position.

Parameters:
  • piece (T) – The piece to place

  • position (P) – Position to place the piece at

Returns:

True if placement was successful, False otherwise

Return type:

bool

remove_piece(position)¶

Remove a piece from the specified position.

Parameters:

position (P) – Position to remove the piece from

Returns:

The removed piece, or None if no piece was at the position

Return type:

T | None

set_property(key, value)¶

Set a board property.

Parameters:
  • key (str) – Property name

  • value (Any) – Property value

Return type:

None

class games.core.game.core_board.GridBoard¶

Bases: Board[haive.games.core.game.core.space.GridSpace[P, T], P, T]

A grid-based board (Chess, Checkers, Scrabble).

This represents a rectangular grid of spaces.

get_column(col)¶

Get all spaces in a column.

Parameters:

col (int) – Column index

Returns:

List of spaces in the column, ordered by row

Return type:

list[haive.games.core.game.core.space.GridSpace[P, T]]

get_row(row)¶

Get all spaces in a row.

Parameters:

row (int) – Row index

Returns:

List of spaces in the row, ordered by column

Return type:

list[haive.games.core.game.core.space.GridSpace[P, T]]

get_space_at(row, col)¶

Get the space at the specified grid coordinates.

Parameters:
  • row (int) – Row index

  • col (int) – Column index

Returns:

The space at the position, or None if no space exists there

Return type:

haive.games.core.game.core.space.GridSpace[P, T] | None

get_space_at_position(position)¶

Get the space at the specified grid coordinates.

Parameters:

position (P) – Grid position to look up

Returns:

The space at the position, or None if no space exists there

Return type:

haive.games.core.game.core.space.GridSpace[P, T] | None

initialize_grid(space_factory=None)¶

Initialize a standard grid with the specified dimensions.

Parameters:

space_factory (collections.abc.Callable[[int, int], haive.games.core.game.core.space.GridSpace[P, T]] | None) – Optional factory function to create spaces

Return type:

None

is_position_valid(position)¶

Check if a position is within the grid bounds.

Parameters:

position (P) – Position to check

Returns:

True if the position is valid, False otherwise

Return type:

bool

classmethod validate_dimensions(v)¶

Ensure board dimensions are positive.

Parameters:

v (int)

Return type:

int

property size: int¶

Get the total number of spaces on the board.

Returns:

Total number of spaces

Return type:

int