chessai.core.isolation.isolator
1import abc 2import random 3 4import chessai.core.agentaction 5import chessai.core.agentinfo 6import chessai.core.gamestate 7 8class AgentIsolator(abc.ABC): 9 """ 10 An isolator isolates an agent instance from the game being played. 11 This "isolation" allows the game to hide or protect state from a agent. 12 For example, without isolation an agent can just directly modify the state 13 to get all the points and end the game. 14 15 All communication between the game engine and agent should be done via the isolator. 16 """ 17 18 @abc.abstractmethod 19 def init_agents(self, agent_infos: dict[chessai.core.types.Color, chessai.core.agentinfo.AgentInfo]) -> None: 20 """ 21 Initialize the agents this isolator will be responsible for. 22 """ 23 24 @abc.abstractmethod 25 def game_start(self, 26 rng: random.Random, 27 initial_state: chessai.core.gamestate.GameState, 28 timeout: float, 29 ) -> dict[chessai.core.types.Color, chessai.core.agentaction.AgentActionRecord]: 30 """ 31 Pass along the initial game state to each agent and all them the allotted time to start. 32 """ 33 34 @abc.abstractmethod 35 def game_complete(self, 36 final_state: chessai.core.gamestate.GameState, 37 timeout: float, 38 ) -> dict[chessai.core.types.Color, chessai.core.agentaction.AgentActionRecord]: 39 """ 40 Notify all agents that the game is over. 41 """ 42 43 @abc.abstractmethod 44 def get_action(self, 45 state: chessai.core.gamestate.GameState, 46 timeout: float, 47 ) -> chessai.core.agentaction.AgentActionRecord: 48 """ 49 Get the current agent's next action. 50 User inputs may be provided by the UI if available. 51 """ 52 53 @abc.abstractmethod 54 def close(self) -> None: 55 """ 56 Close the isolator and release all owned resources. 57 This call should not communicate with agents and forcibly release any agent resources. 58 """
9class AgentIsolator(abc.ABC): 10 """ 11 An isolator isolates an agent instance from the game being played. 12 This "isolation" allows the game to hide or protect state from a agent. 13 For example, without isolation an agent can just directly modify the state 14 to get all the points and end the game. 15 16 All communication between the game engine and agent should be done via the isolator. 17 """ 18 19 @abc.abstractmethod 20 def init_agents(self, agent_infos: dict[chessai.core.types.Color, chessai.core.agentinfo.AgentInfo]) -> None: 21 """ 22 Initialize the agents this isolator will be responsible for. 23 """ 24 25 @abc.abstractmethod 26 def game_start(self, 27 rng: random.Random, 28 initial_state: chessai.core.gamestate.GameState, 29 timeout: float, 30 ) -> dict[chessai.core.types.Color, chessai.core.agentaction.AgentActionRecord]: 31 """ 32 Pass along the initial game state to each agent and all them the allotted time to start. 33 """ 34 35 @abc.abstractmethod 36 def game_complete(self, 37 final_state: chessai.core.gamestate.GameState, 38 timeout: float, 39 ) -> dict[chessai.core.types.Color, chessai.core.agentaction.AgentActionRecord]: 40 """ 41 Notify all agents that the game is over. 42 """ 43 44 @abc.abstractmethod 45 def get_action(self, 46 state: chessai.core.gamestate.GameState, 47 timeout: float, 48 ) -> chessai.core.agentaction.AgentActionRecord: 49 """ 50 Get the current agent's next action. 51 User inputs may be provided by the UI if available. 52 """ 53 54 @abc.abstractmethod 55 def close(self) -> None: 56 """ 57 Close the isolator and release all owned resources. 58 This call should not communicate with agents and forcibly release any agent resources. 59 """
An isolator isolates an agent instance from the game being played. This "isolation" allows the game to hide or protect state from a agent. For example, without isolation an agent can just directly modify the state to get all the points and end the game.
All communication between the game engine and agent should be done via the isolator.
19 @abc.abstractmethod 20 def init_agents(self, agent_infos: dict[chessai.core.types.Color, chessai.core.agentinfo.AgentInfo]) -> None: 21 """ 22 Initialize the agents this isolator will be responsible for. 23 """
Initialize the agents this isolator will be responsible for.
25 @abc.abstractmethod 26 def game_start(self, 27 rng: random.Random, 28 initial_state: chessai.core.gamestate.GameState, 29 timeout: float, 30 ) -> dict[chessai.core.types.Color, chessai.core.agentaction.AgentActionRecord]: 31 """ 32 Pass along the initial game state to each agent and all them the allotted time to start. 33 """
Pass along the initial game state to each agent and all them the allotted time to start.
35 @abc.abstractmethod 36 def game_complete(self, 37 final_state: chessai.core.gamestate.GameState, 38 timeout: float, 39 ) -> dict[chessai.core.types.Color, chessai.core.agentaction.AgentActionRecord]: 40 """ 41 Notify all agents that the game is over. 42 """
Notify all agents that the game is over.
44 @abc.abstractmethod 45 def get_action(self, 46 state: chessai.core.gamestate.GameState, 47 timeout: float, 48 ) -> chessai.core.agentaction.AgentActionRecord: 49 """ 50 Get the current agent's next action. 51 User inputs may be provided by the UI if available. 52 """
Get the current agent's next action. User inputs may be provided by the UI if available.
54 @abc.abstractmethod 55 def close(self) -> None: 56 """ 57 Close the isolator and release all owned resources. 58 This call should not communicate with agents and forcibly release any agent resources. 59 """
Close the isolator and release all owned resources. This call should not communicate with agents and forcibly release any agent resources.