games.nim.agent¶
Agent for playing Nim.
This module defines the Nim agent, which uses language models to generate moves and analyze positions in the game.
Classes¶
Agent for playing Nim. |
Functions¶
|
Ensure input is converted to NimState. |
Module Contents¶
- class games.nim.agent.NimAgent(config=NimConfig())¶
Bases:
haive.games.framework.base.agent.GameAgent
[haive.games.nim.config.NimConfig
]Agent for playing Nim.
Initialize the Nim agent.
- Parameters:
config (NimConfig) – The configuration for the game.
- analyze_player1(state)¶
Analyze position for player1.
- Parameters:
state (NimState) – The current game state.
- Returns:
The command to analyze the position.
- Return type:
Command
- analyze_player2(state)¶
Analyze position for player2.
- Parameters:
state (NimState) – The current game state.
- Returns:
The command to analyze the position.
- Return type:
Command
- analyze_position(state, player)¶
Analyze the current position for the specified player.
- extract_move(response)¶
Extract move from engine response.
- Parameters:
response (Any) – The response from the engine.
- Returns:
The move from the engine.
- Return type:
Any
- initialize_game(state)¶
Initialize a new Nim game with configured pile sizes.
- make_move(state, player)¶
Make a move for the specified player.
- make_player1_move(state)¶
Make a move for player1.
- Parameters:
state (NimState) – The current game state.
- Returns:
The command to make the move.
- Return type:
Command
- make_player2_move(state)¶
Make a move for player2.
- Parameters:
state (NimState) – The current game state.
- Returns:
The command to make the move.
- Return type:
Command
- prepare_analysis_context(state, player)¶
Prepare context for position analysis.
- prepare_move_context(state, player)¶
Prepare context for move generation.
- run_game(visualize=True)¶
Run a complete Nim game with optional visualization.
- run_game_with_ui(show_analysis=True)¶
Run a complete Nim game with Rich UI.
This method runs a Nim game with Rich UI visualization, showing the game state after each move. It optionally includes analysis.
- setup_workflow()¶
Set up the game workflow.
- Returns:
None
- Return type:
None
- games.nim.agent.ensure_game_state(state_input)¶
Ensure input is converted to NimState.
This helper function ensures that the input state is properly converted to a NimState object, handling various input types (dict, NimState, Command).