Skip to content

Commit 444a312

Browse files
committed
Add on_round_update to communicate game state to agent
1 parent 033a82b commit 444a312

3 files changed

Lines changed: 9 additions & 3 deletions

File tree

codeclash/agents/abstract.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ def __init__(
2121
self.name = f"{template_vars['game_id']}_{config['name']}"
2222
self.environment = environment
2323
self.template_vars = template_vars
24-
self.round = 1 # TODO: This is disconnected from game.round right now
2524

2625
def commit(self):
2726
"""Commit changes to the agent's codebase."""
@@ -32,7 +31,10 @@ def commit(self):
3231
]:
3332
assert_zero_exit_code(self.environment.execute(cmd))
3433
print(f"Committed changes for {self.name} for round {self.round}/{rounds}")
35-
self.round += 1 # TODO: This is disconnected from game.round right now
34+
35+
def on_round_update(self, new_round: int):
36+
"""Update the agent's round to match the game round."""
37+
self.round = new_round
3638

3739
def push(self):
3840
"""Push codebase to a branch on the game's remote repository."""

codeclash/agents/minisweagent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ def run(self):
9393
save_traj(
9494
self.agent, # type: ignore
9595
DIR_LOGS
96-
/ f"{self.template_vars['game_id']}/{player_id}_r{self.template_vars['round']}.traj.json",
96+
/ f"{self.template_vars['game_id']}/{player_id}_r{self.round}.traj.json",
9797
exit_status=exit_status,
9898
result=result,
9999
)

codeclash/games/abstract.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ def get_environment(self, branch_name: str | None = None) -> DockerEnvironment:
9393
def _pre_round_setup(self, agents: list[Player]):
9494
"""Copy agent codebases into game's container and make round log file"""
9595
self.round += 1
96+
# Notify agents of round update
97+
for agent in agents:
98+
if hasattr(agent, "on_round_update"):
99+
agent.on_round_update(self.round)
96100
print(f"▶️ Running {self.name} round {self.round}...")
97101

98102
# Copy agent codebases into game's container

0 commit comments

Comments
 (0)