Skip to content

Commit d5bcb83

Browse files
Did a big refactor of how the board holds information to allow for multiple markers occupying the same location.
1 parent d4a9f85 commit d5bcb83

File tree

14 files changed

+394
-142
lines changed

14 files changed

+394
-142
lines changed

pacai/boards/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
The `pacai.boards` package provides no actual code,
3+
but instead provides default game boards that can be used for this project.
4+
"""

pacai/core/__init__.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"""
2+
The `pacai.core` package provides the core game engine, infrastructure, and abstractions for creating games.
3+
This package contains no actual game logic or resources, just the infrastructure for running them.
4+
"""

pacai/core/action.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,33 @@
33
Default actions are provided, but custom actions can be easily created.
44
"""
55

6+
import typing
7+
8+
import pacai.core.time
9+
610
class Action(str):
711
""" An action that an agent is allowed to take. """
812

913
pass
1014

15+
class ActionRecord(typing.NamedTuple):
16+
"""
17+
The result of requesting an action from an agent.
18+
Aside from the action, this also includes timing and crashing information.
19+
"""
20+
21+
agent_index: int
22+
""" The index of the agent making this action. """
23+
24+
action: Action
25+
""" The action returned by the agent (or pacai.core.action.STOP on a crash). """
26+
27+
duration: pacai.core.time.Duration
28+
""" The duration (in MS) the agent took to compute this action. """
29+
30+
crashed: bool
31+
""" Whether or not the agent crashed (e.g., raised an exception) when computing this action. """
32+
1133
NORTH = Action("north")
1234
EAST = Action("east")
1335
SOUTH = Action("south")

pacai/core/agent.py

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,33 @@ def __init__(self, args: AgentArguments) -> None:
4343

4444
@abc.abstractmethod
4545
def get_action(self, state: pacai.core.gamestate.GameState) -> pacai.core.action.Action:
46+
"""
47+
Get an action for this agent given the current state of the game.
48+
Agents may keep internal state, but the given state should be considered the source of truth.
49+
Calls to this method may be subject to a timeout.
50+
"""
51+
4652
pass
4753

4854
@abc.abstractmethod
4955
def game_start(self, agent_index: int, suggested_seed: int, initial_state: pacai.core.gamestate.GameState) -> None:
56+
"""
57+
Notify this agent that the game is about to start.
58+
The provided agent index is the game's index/id for this agent.
59+
The state represents the initial state of the game.
60+
Any precomputation for this game should be done in this method.
61+
Calls to this method may be subject to a timeout.
62+
"""
63+
5064
pass
5165

5266
@abc.abstractmethod
5367
def game_complete(self, final_state: pacai.core.gamestate.GameState) -> None:
68+
"""
69+
Notify this agent that the game has concluded.
70+
Agents should use this as an opportunity to make any final calculations and close any game-related resources.
71+
"""
72+
5473
pass
5574

5675
class Ticket(typing.NamedTuple):
@@ -79,24 +98,6 @@ def next(self, move_delay: int) -> 'Ticket':
7998
num_moves = self.num_moves + 1,
8099
)
81100

82-
class ActionRecord(typing.NamedTuple):
83-
"""
84-
The result of requesting an action from an agent.
85-
Aside from the action, this also includes timing and crashing information.
86-
"""
87-
88-
agent_index: int
89-
""" The index of the agent making this action. """
90-
91-
action: pacai.core.action.Action
92-
""" The action returned by the agent (or pacai.core.action.STOP on a crash). """
93-
94-
duration: pacai.core.time.Duration
95-
""" The duration (in MS) the agent took to compute this action. """
96-
97-
crashed: bool
98-
""" Whether or not the agent crashed (e.g., raised an exception) when computing this action. """
99-
100101
def load(arguments: AgentArguments) -> Agent:
101102
# TEST
102103
raise NotImplementedError()

0 commit comments

Comments
 (0)