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

GridSpace

A space on a grid-based board.

HexSpace

A space on a hexagonal board.

Space

A space on a game board where pieces can be placed.

SpaceProtocol

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.

Returns:

Tuple of (row, col)

Return type:

tuple[int, int]

property coordinates: str

Get human-readable coordinates for this space.

Returns:

String like “A1”, “B2”, etc.

Return type:

str

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.

property coordinates: tuple[int, int, int]

Get the hex coordinates of this space.

Returns:

Tuple of (q, r, s) in cube coordinates

Return type:

tuple[int, int, int]

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.

Parameters:

space_id (str) – ID of the space to check

Returns:

True if connected, False otherwise

Return type:

bool

is_occupied()

Check if this space is occupied by a piece.

Returns:

True if the space has a piece, False otherwise

Return type:

bool

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:

bool

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

set_property(key, value)

Set a property value.

Parameters:
  • key (str) – Property name

  • value (Any) – Property value

Return type:

None

class haive.games.core.game.core_space.SpaceProtocol

Bases: Protocol, Generic[P, T]

Protocol defining the required interface for board spaces.