games.base.modelsΒΆ
Base models for game agents.
This module provides the foundational data models used across game agents. It includes models for game state, player state, moves, and other common game-related data structures.
Examples
>>> board = Board(size=(8, 8))
>>> player = Player(id="p1", name="Player 1")
>>> state = GameState(board=board, players=[player])
- Typical usage:
Use these models as base classes for game-specific models
Inherit from these models to add game-specific functionality
ClassesΒΆ
Module ContentsΒΆ
- class games.base.models.Board(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Represents a generic game board.
This class provides a basic representation of a game board with dimensions and optional grid-based structure.
- Parameters:
data (Any)
Examples
>>> board = Board(size=(8, 8)) >>> chess_board = Board(size=(8, 8), grid=[["R", "N", "B", ...]])
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 games.base.models.Cell(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Represents a cell on the 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.
- Parameters:
data (Any)
- class games.base.models.GameState(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Represents the state of a generic game.
Core game state model that can be extended for specific games.
- Parameters:
data (Any)
- game_statusΒΆ
Current game status.
- Type:
Literal[βongoingβ, βendedβ]
Examples
>>> state = GameState( ... board=Board(size=(8, 8)), ... players=[Player(id="p1", name="Player 1")], ... current_player=player, ... game_status="ongoing" ... )
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 games.base.models.MoveModel(/, **data)ΒΆ
Bases:
pydantic.BaseModel
,Generic
[TMove
],abc.ABC
Generic model for game moves.
This class represents a move in the game, generic over the specific type of move (TMove) used in the game.
- Parameters:
data (Any)
- moveΒΆ
The actual move data.
- Type:
TMove
Examples
>>> class ChessMove(BaseModel): ... from_pos: str ... to_pos: str >>> move = MoveModel[ChessMove]( ... move=ChessMove(from_pos="e2", to_pos="e4"), ... player_id="p1" ... )
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_move(move, info)ΒΆ
Override in game-specific models to validate the move.
- Return type:
Any
- class games.base.models.Piece(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Represents a piece on the 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.
- Parameters:
data (Any)
- class games.base.models.Player(/, **data)ΒΆ
Bases:
pydantic.BaseModel
Represents a player in the game.
Base player model with essential player information and state.
- Parameters:
data (Any)
Examples
>>> player = Player(id="p1", name="Player 1", score=0)
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.