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¶
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:
- connect_spaces(space1_id, space2_id)¶
Connect two spaces bidirectionally.
- Parameters:
- Raises:
ValueError – If either space doesn’t exist on the board
- Return type:
None
- get_all_pieces()¶
Get all pieces currently on the board.
- 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.
- 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:
- 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:
- 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
- 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.
- get_row(row)¶
Get all spaces in a row.
- get_space_at(row, col)¶
Get the space at the specified grid coordinates.
- 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:
- classmethod validate_dimensions(v)¶
Ensure board dimensions are positive.