games.chess.state¶
Chess game state models.
- This module defines the state schema for chess games, including:
Board state representation using FEN notation
Move history tracking
Game status management
Position analysis storage
Player turn tracking
The state schema provides a complete representation of a chess game state that can be used by the agent and state manager.
Classes¶
State schema for the chess game. |
Module Contents¶
- class games.chess.state.ChessState(/, **data)¶
Bases:
haive.core.schema.state_schema.StateSchema
State schema for the chess game.
This class extends StateSchema to provide a comprehensive representation of a chess game, including board state, move history, game status, and analysis information.
- Parameters:
data (Any)
- current_player¶
Color of the player making the current move.
- Type:
Literal[“white”, “black”]
- turn¶
Current turn color.
- Type:
Literal[“white”, “black”]
- game_status¶
Current status of the game.
- Type:
Literal[“ongoing”, “check”, “checkmate”, “stalemate”, “draw”]
Examples
>>> from haive.games.chess import ChessState >>> state = ChessState() >>> state.board_fen 'rnbqkbnr/pppppppp/8/8/8/8/PPPPPPPP/RNBQKBNR w KQkq - 0 1' >>> board = state.get_board() >>> board.is_check() False
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.
- get_board()¶
Get a chess.Board object for the current position.
Creates a Python-chess Board object initialized with the current FEN position.
- Returns:
Board object representing the current position.
- Return type:
chess.Board
- Raises:
ValueError – If the FEN string is invalid or cannot be parsed.
Example
>>> state = ChessState() >>> board = state.get_board() >>> board.is_game_over() False