haive.games.go.models¶

Go game data models.

This module provides Pydantic models for representing Go game concepts:
  • Move coordinates and validation

  • Player decisions

  • Position analysis and evaluation

  • Territory control tracking

Example

>>> from haive.games.go.models import GoMoveModel, GoAnalysis
>>>
>>> # Create and validate a move
>>> move = GoMoveModel(move=(3, 4), board_size=19)
>>> move.to_tuple()
(3, 4)
>>>
>>> # Create a position analysis
>>> analysis = GoAnalysis(
...     territory_control={"black": 45, "white": 40},
...     strong_positions=[(3, 3), (15, 15)],
...     weak_positions=[(0, 0)],
...     suggested_strategies=["Strengthen the center group"]
... )

Classes¶

GoAnalysis

A model for storing Go position analysis.

GoMoveModel

A model representing a move in Go.

GoPlayerDecision

A model representing a player's move decision.

Module Contents¶

class haive.games.go.models.GoAnalysis(/, **data)[source]¶

Bases: pydantic.BaseModel

A model for storing Go position analysis.

This model captures a comprehensive analysis of a Go position, including territory control, key positions, and strategic advice.

Parameters:

data (Any)

territory_control¶

Estimated territory for each player.

Type:

Dict[str, int]

strong_positions¶

List of strong positions.

Type:

List[Tuple[int, int]]

weak_positions¶

List of vulnerable positions.

Type:

List[Tuple[int, int]]

suggested_strategies¶

List of strategic recommendations.

Type:

List[str]

Example

>>> analysis = GoAnalysis(
...     territory_control={"black": 45, "white": 40},
...     strong_positions=[(3, 3), (15, 15)],
...     weak_positions=[(0, 0)],
...     suggested_strategies=[
...         "Strengthen the center group",
...         "Consider invading the top right"
...     ]
... )

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.

class haive.games.go.models.GoMoveModel(/, **data)[source]¶

Bases: pydantic.BaseModel

A model representing a move in Go.

This model validates and stores move coordinates, ensuring they are within the bounds of the game board.

Parameters:

data (Any)

move¶

The (row, col) coordinates of the move.

Type:

Tuple[int, int]

board_size¶

Size of the game board (default 19x19).

Type:

int

Example

>>> move = GoMoveModel(move=(3, 4))
>>> move.validate_move((3, 4), {"board_size": 19})
(3, 4)
>>> move.to_tuple()
(3, 4)
>>>
>>> # Invalid move raises error
>>> GoMoveModel(move=(19, 19))  # Out of bounds
ValueError: Move (19, 19) is out of bounds for a 19x19 board.

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.

to_tuple()[source]¶

Convert the move to a simple coordinate tuple.

Returns:

The move coordinates as (row, col).

Return type:

Tuple[int, int]

classmethod validate_move(move, values)[source]¶

Validate that a move is within board bounds.

Parameters:
  • move (Tuple[int, int]) – The move coordinates to validate.

  • values (dict) – Dictionary containing model field values.

Returns:

The validated move coordinates.

Return type:

Tuple[int, int]

Raises:

ValueError – If move coordinates are outside board bounds.

class haive.games.go.models.GoPlayerDecision(/, **data)[source]¶

Bases: pydantic.BaseModel

A model representing a player’s move decision.

This model encapsulates a player’s decision about their next move, including validation of the move coordinates.

Parameters:

data (Any)

move¶

The chosen move coordinates and validation.

Type:

GoMoveModel

Example

>>> decision = GoPlayerDecision(
...     move=GoMoveModel(move=(3, 4))
... )
>>> decision.move.to_tuple()
(3, 4)

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.