games.base.utils¶

Utility functions for game agents.

This module provides utility functions for running and managing game agents, including game execution and state visualization.

Example

>>> agent = ChessAgent(config)
>>> run_game(agent)  # Run a new game
>>> run_game(agent, initial_state=saved_state)  # Continue from a saved state
Typical usage:
  • Use run_game to execute a complete game with an agent

  • Provide optional initial state to continue from a specific point

  • Monitor game progress through visualization and status updates

Functions¶

run_game(agent[, initial_state])

Run a complete game with the given agent.

Module Contents¶

games.base.utils.run_game(agent, initial_state=None)¶

Run a complete game with the given agent.

This function executes a game from start to finish using the provided agent. It handles game initialization, move execution, state visualization, and error reporting. The game can optionally start from a provided initial state.

Parameters:
  • agent (GameAgent) – The game agent to run the game with.

  • initial_state (Optional[Dict[str, Any]], optional) – Initial game state. If not provided, a new game will be initialized. Defaults to None.

Example

>>> agent = ChessAgent(ChessConfig())
>>> # Start a new game
>>> run_game(agent)
>>>
>>> # Continue from a saved state
>>> run_game(agent, saved_state)

Note

  • The function will print game progress to the console

  • Game visualization depends on the agent’s visualize_state method

  • Game history will be saved using the agent’s save_state_history method