pacai.agents.testing
1import time 2import typing 3 4import pacai.agents.dummy 5import pacai.core.action 6import pacai.core.gamestate 7 8class TimeoutAgent(pacai.agents.dummy.DummyAgent): 9 """ 10 A testing agent that will wait a specific amount of time before completing specific tasks 11 (starting up, getting an action, etc). 12 By default the agent will wait no extra time before these action, 13 but will use agent arguments to decide how long to wait. 14 All wait times are in floating seconds. 15 """ 16 17 def __init__(self, 18 game_start_wait: float = 0.0, 19 game_complete_wait: float = 0.0, 20 get_action_wait: float = 0.0, 21 **kwargs: typing.Any) -> None: 22 super().__init__(**kwargs) 23 24 self._game_start_wait: float = float(game_start_wait) 25 """ The amount of time to wait before acknowledging the start of the game. """ 26 27 self._game_complete_wait: float = float(game_complete_wait) 28 """ The amount of time to wait before acknowledging the completion of the game. """ 29 30 self._get_action_wait: float = float(get_action_wait) 31 """ The amount of time to wait before returning an action. """ 32 33 def game_start(self, initial_state: pacai.core.gamestate.GameState) -> None: 34 time.sleep(self._game_start_wait) 35 super().game_start(initial_state) 36 37 def game_complete(self, final_state: pacai.core.gamestate.GameState) -> None: 38 time.sleep(self._game_complete_wait) 39 super().game_complete(final_state) 40 41 def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action: 42 time.sleep(self._get_action_wait) 43 return super().get_action(state)
9class TimeoutAgent(pacai.agents.dummy.DummyAgent): 10 """ 11 A testing agent that will wait a specific amount of time before completing specific tasks 12 (starting up, getting an action, etc). 13 By default the agent will wait no extra time before these action, 14 but will use agent arguments to decide how long to wait. 15 All wait times are in floating seconds. 16 """ 17 18 def __init__(self, 19 game_start_wait: float = 0.0, 20 game_complete_wait: float = 0.0, 21 get_action_wait: float = 0.0, 22 **kwargs: typing.Any) -> None: 23 super().__init__(**kwargs) 24 25 self._game_start_wait: float = float(game_start_wait) 26 """ The amount of time to wait before acknowledging the start of the game. """ 27 28 self._game_complete_wait: float = float(game_complete_wait) 29 """ The amount of time to wait before acknowledging the completion of the game. """ 30 31 self._get_action_wait: float = float(get_action_wait) 32 """ The amount of time to wait before returning an action. """ 33 34 def game_start(self, initial_state: pacai.core.gamestate.GameState) -> None: 35 time.sleep(self._game_start_wait) 36 super().game_start(initial_state) 37 38 def game_complete(self, final_state: pacai.core.gamestate.GameState) -> None: 39 time.sleep(self._game_complete_wait) 40 super().game_complete(final_state) 41 42 def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action: 43 time.sleep(self._get_action_wait) 44 return super().get_action(state)
A testing agent that will wait a specific amount of time before completing specific tasks (starting up, getting an action, etc). By default the agent will wait no extra time before these action, but will use agent arguments to decide how long to wait. All wait times are in floating seconds.
18 def __init__(self, 19 game_start_wait: float = 0.0, 20 game_complete_wait: float = 0.0, 21 get_action_wait: float = 0.0, 22 **kwargs: typing.Any) -> None: 23 super().__init__(**kwargs) 24 25 self._game_start_wait: float = float(game_start_wait) 26 """ The amount of time to wait before acknowledging the start of the game. """ 27 28 self._game_complete_wait: float = float(game_complete_wait) 29 """ The amount of time to wait before acknowledging the completion of the game. """ 30 31 self._get_action_wait: float = float(get_action_wait) 32 """ The amount of time to wait before returning an action. """
34 def game_start(self, initial_state: pacai.core.gamestate.GameState) -> None: 35 time.sleep(self._game_start_wait) 36 super().game_start(initial_state)
Notify this agent that the game is about to start. The provided agent index is the game's index/id for this agent. The state represents the initial state of the game. Any precomputation for this game should be done in this method. Calls to this method may be subject to a timeout.
38 def game_complete(self, final_state: pacai.core.gamestate.GameState) -> None: 39 time.sleep(self._game_complete_wait) 40 super().game_complete(final_state)
Notify this agent that the game has concluded. Agents should use this as an opportunity to make any final calculations and close any game-related resources.
42 def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action: 43 time.sleep(self._get_action_wait) 44 return super().get_action(state)
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.