pacai.core.isolation.isolator

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

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.

@abc.abstractmethod
def init_agents(self, agent_infos: dict[int, pacai.core.agentinfo.AgentInfo]) -> None:
20    @abc.abstractmethod
21    def init_agents(self, agent_infos: dict[int, pacai.core.agentinfo.AgentInfo]) -> None:
22        """
23        Initialize the agents this isolator will be responsible for.
24        """

Initialize the agents this isolator will be responsible for.

@abc.abstractmethod
def game_start( self, rng: random.Random, initial_state: pacai.core.gamestate.GameState, timeout: float) -> dict[int, pacai.core.agentaction.AgentActionRecord]:
26    @abc.abstractmethod
27    def game_start(self,
28            rng: random.Random,
29            initial_state: pacai.core.gamestate.GameState,
30            timeout: float,
31            ) -> dict[int, pacai.core.agentaction.AgentActionRecord]:
32        """
33        Pass along the initial game state to each agent and all them the allotted time to start.
34        """

Pass along the initial game state to each agent and all them the allotted time to start.

@abc.abstractmethod
def game_complete( self, final_state: pacai.core.gamestate.GameState, timeout: float) -> dict[int, pacai.core.agentaction.AgentActionRecord]:
36    @abc.abstractmethod
37    def game_complete(self,
38            final_state: pacai.core.gamestate.GameState,
39            timeout: float,
40            ) -> dict[int, pacai.core.agentaction.AgentActionRecord]:
41        """
42        Notify all agents that the game is over.
43        """

Notify all agents that the game is over.

@abc.abstractmethod
def get_action( self, state: pacai.core.gamestate.GameState, user_inputs: list[pacai.core.action.Action], timeout: float) -> pacai.core.agentaction.AgentActionRecord:
45    @abc.abstractmethod
46    def get_action(self,
47            state: pacai.core.gamestate.GameState,
48            user_inputs: list[pacai.core.action.Action],
49            timeout: float,
50            ) -> pacai.core.agentaction.AgentActionRecord:
51        """
52        Get the current agent's next action.
53        User inputs may be provided by the UI if available.
54        """

Get the current agent's next action. User inputs may be provided by the UI if available.

@abc.abstractmethod
def close(self) -> None:
56    @abc.abstractmethod
57    def close(self) -> None:
58        """
59        Close the isolator and release all owned resources.
60        This call should not communicate with agents and forcibly release any agent resources.
61        """

Close the isolator and release all owned resources. This call should not communicate with agents and forcibly release any agent resources.