haive.games.core.game.core_space¶
Space models for the game framework.
This module defines the base Space class and specific implementations for different types of board spaces.
Classes¶
A space on a grid-based board. |
|
A space on a hexagonal board. |
|
A space on a game board where pieces can be placed. |
|
Protocol defining the required interface for board spaces. |
Module Contents¶
- class haive.games.core.game.core_space.GridSpace¶
Bases:
Space
[P
,T
]A space on a grid-based board.
Used for games like Chess, Checkers, Scrabble, etc.
- get_grid_position()¶
Get the grid coordinates of this space.
- class haive.games.core.game.core_space.HexSpace¶
Bases:
Space
[P
,T
]A space on a hexagonal board.
Used for games like Catan, hex-based war games, etc.
- class haive.games.core.game.core_space.Space(/, **data)¶
Bases:
pydantic.BaseModel
,Generic
[P
,T
]A space on a game board where pieces can be placed.
A Space represents a location on a board that can hold a game piece. It has a position and can be connected to other 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_connection(space_id)¶
Add a connection to another space.
- Parameters:
space_id (str) – ID of the space to connect to
- Return type:
None
- get_property(key, default=None)¶
Get a property value.
- Parameters:
key (str) – Property name
default (Any) – Default value if property doesn’t exist
- Returns:
Property value or default
- Return type:
Any
- is_connected_to(space_id)¶
Check if this space is connected to another space.
- is_occupied()¶
Check if this space is occupied by a piece.
- Returns:
True if the space has a piece, False otherwise
- Return type:
- place_piece(piece)¶
Place a piece on this space.
- Parameters:
piece (T) – The piece to place
- Returns:
True if placement was successful, False otherwise
- Return type:
- remove_connection(space_id)¶
Remove a connection to another space.
- Parameters:
space_id (str) – ID of the space to disconnect from
- Return type:
None
- remove_piece()¶
Remove and return the piece on this space.
- Returns:
The removed piece, or None if no piece was on the space
- Return type:
T | None
- class haive.games.core.game.core_space.SpaceProtocol¶
Bases:
Protocol
,Generic
[P
,T
]Protocol defining the required interface for board spaces.