pacai.agents.scripted
1import typing 2 3import pacai.core.action 4import pacai.core.agent 5import pacai.core.gamestate 6 7ACTION_DELIM: str = ',' 8 9class ScriptedAgent(pacai.core.agent.Agent): 10 """ 11 An agent that has a specific set of actions that they will do in order. 12 Once the actions are exhausted, they will just stop. 13 This agent will take a scripted action even if it is illegal. 14 15 This agent is particularly useful for things like replays. 16 """ 17 18 def __init__(self, 19 actions: list[pacai.core.action.Action] | list[str] | str | None = None, 20 **kwargs: typing.Any) -> None: 21 super().__init__(**kwargs) 22 23 if (actions is None): 24 actions = [] 25 26 if (isinstance(actions, str)): 27 actions = actions.split(ACTION_DELIM) 28 29 clean_actions = [] 30 for action in actions: 31 clean_actions.append(pacai.core.action.Action(action)) 32 33 self._actions: list[pacai.core.action.Action] = clean_actions 34 """ The scripted actions this agent will take. """ 35 36 def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action: 37 if (len(self._actions) > 0): 38 return self._actions.pop(0) 39 40 return pacai.core.action.STOP
ACTION_DELIM: str =
','
10class ScriptedAgent(pacai.core.agent.Agent): 11 """ 12 An agent that has a specific set of actions that they will do in order. 13 Once the actions are exhausted, they will just stop. 14 This agent will take a scripted action even if it is illegal. 15 16 This agent is particularly useful for things like replays. 17 """ 18 19 def __init__(self, 20 actions: list[pacai.core.action.Action] | list[str] | str | None = None, 21 **kwargs: typing.Any) -> None: 22 super().__init__(**kwargs) 23 24 if (actions is None): 25 actions = [] 26 27 if (isinstance(actions, str)): 28 actions = actions.split(ACTION_DELIM) 29 30 clean_actions = [] 31 for action in actions: 32 clean_actions.append(pacai.core.action.Action(action)) 33 34 self._actions: list[pacai.core.action.Action] = clean_actions 35 """ The scripted actions this agent will take. """ 36 37 def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action: 38 if (len(self._actions) > 0): 39 return self._actions.pop(0) 40 41 return pacai.core.action.STOP
An agent that has a specific set of actions that they will do in order. Once the actions are exhausted, they will just stop. This agent will take a scripted action even if it is illegal.
This agent is particularly useful for things like replays.
ScriptedAgent( actions: list[pacai.core.action.Action] | list[str] | str | None = None, **kwargs: Any)
19 def __init__(self, 20 actions: list[pacai.core.action.Action] | list[str] | str | None = None, 21 **kwargs: typing.Any) -> None: 22 super().__init__(**kwargs) 23 24 if (actions is None): 25 actions = [] 26 27 if (isinstance(actions, str)): 28 actions = actions.split(ACTION_DELIM) 29 30 clean_actions = [] 31 for action in actions: 32 clean_actions.append(pacai.core.action.Action(action)) 33 34 self._actions: list[pacai.core.action.Action] = clean_actions 35 """ The scripted actions this agent will take. """
37 def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action: 38 if (len(self._actions) > 0): 39 return self._actions.pop(0) 40 41 return pacai.core.action.STOP
Get an action for this agent given the current state of the game. This is simplified version of get_action_full(), see that method for full details.