haive.games.go.state¶
Go game state management.
- This module provides state tracking and management for Go games, including:
Game state representation
Move validation and application
Board state tracking in SGF format
Capture counting
Game status management
Example
>>> from haive.games.go.state import GoGameState, GoGameStateManager
>>>
>>> # Initialize a new game
>>> state = GoGameStateManager.initialize(board_size=19)
>>>
>>> # Apply moves
>>> state = GoGameStateManager.apply_move(state, (3, 4)) # Black's move
>>> state = GoGameStateManager.apply_move(state, (15, 15)) # White's move
>>>
>>> # Check game status
>>> print(state.game_status) # 'ongoing'
>>> print(state.captured_stones) # {'black': 0, 'white': 0}
Classes¶
A model representing the complete state of a Go game. |
Module Contents¶
- class haive.games.go.state.GoGameState(/, **data)[source]¶
Bases:
pydantic.BaseModel
A model representing the complete state of a Go game.
- This class tracks all aspects of a Go game’s state, including:
Board configuration and size
Move history
Captured stones
Game status and result
Error conditions
- Parameters:
data (Any)
Example
>>> state = GoGameState( ... board_sgf=sente.sgf.dumps(sente.Game(19)), ... turn="black", ... captured_stones={"black": 0, "white": 0} ... ) >>> state.validate_turn("black", {"board_sgf": state.board_sgf}) 'black'
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.
- classmethod validate_turn(v, info)[source]¶
Validate that the turn matches the board state.
This validator ensures the turn field matches the actual board state by checking against the SGF representation.
- Parameters:
v (str) – The turn value to validate.
info (ValidationInfo) – Validation context with other field values.
- Returns:
The validated turn value.
- Return type:
- Raises:
ValueError – If turn doesn’t match the board state.