"""Single-player game agent base class.This module provides the SinglePlayerGameAgent base class for implementing single-playergame agents in the Haive framework."""fromtypingimportTypeVarfromhaive.games.base.agentimportGameAgentfromhaive.games.framework.base.configimportGameConfigT=TypeVar("T",bound=GameConfig)
[docs]classSinglePlayerGameAgent(GameAgent[T]):"""Base class for single-player game agents. This class extends GameAgent to provide specific functionality for single-player games where an LLM can act as the player, assistant, or game engine. Single-player games differ from multiplayer games in that they: - Don't require turn management between multiple players - Often involve puzzles, challenges, or solo adventures - May use the LLM as a game master or narrator Example: >>> from haive.games.single_player import SinglePlayerGameAgent >>> class WordleAgent(SinglePlayerGameAgent): ... def __init__(self, config): ... super().__init__(config) ... self.state_manager = WordleStateManager Attributes: config: Configuration for the single-player game state_manager: Manager for game state transitions """def__init__(self,config:T):"""Initialize the single-player game agent. Args: config: Game-specific configuration """super().__init__(config)
[docs]defsetup_single_player_workflow(self)->None:"""Set up the workflow specific to single-player games. This method can be overridden by subclasses to customize the workflow for specific single-player game mechanics. """# Default implementation uses the base game workflowself.setup_workflow()
[docs]defhandle_player_action(self,action:str)->dict:"""Handle a player action in the game. Args: action: The player's action as a string Returns: dict: Result of the action including any state changes """raiseNotImplementedError("Subclasses must implement handle_player_action")
[docs]defgenerate_game_response(self,state:dict)->str:"""Generate the game's response to the current state. Args: state: Current game state Returns: str: Game's response or narration """raiseNotImplementedError("Subclasses must implement generate_game_response")