Skip to content

Commit e05deb8

Browse files
committed
Fixing single player mode after moving diff
1 parent c787e66 commit e05deb8

1 file changed

Lines changed: 11 additions & 3 deletions

File tree

codeclash/tournaments/single_player.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,14 @@ def get_agent(self, agent_config: dict, round: int) -> Player:
6262
game_context = self.get_game_context(agent_config, round=round)
6363
return get_agent(agent_config, game_context, environment)
6464

65+
def _get_round_diff(self, player_name: str, round_num: int) -> str:
66+
"""Read diff data from changes_r{round}.json file, fallback to metadata."""
67+
if round_num == 0:
68+
return ""
69+
changes_file = self.game.log_local / "players" / player_name / f"changes_r{round_num}.json"
70+
changes_data = json.loads(changes_file.read_text())
71+
return changes_data.get("full_diff", "")
72+
6573
def get_dummy_agent(self, player_config: dict) -> Player:
6674
"""Create a dummy agent that does nothing."""
6775
return Dummy(
@@ -114,7 +122,7 @@ def run_main_agent(self, round_num: int):
114122

115123
def set_mirror_state_to_round(self, round_num: int):
116124
"""Update mirror agent's codebase with the main agent's changes."""
117-
full_diff = self.agent.get_metadata()["diff"][round_num]
125+
full_diff = self._get_round_diff(self.agent.name, round_num)
118126
full_diff = filter_git_diff(full_diff)
119127
self.mirror_agent.reset_and_apply_patch(full_diff)
120128

@@ -143,8 +151,8 @@ def evaluate(self, n_repetitions: int = 3) -> None:
143151
for p1_round in range(0, self.rounds + 1):
144152
for p2_round in range(0, self.rounds + 1):
145153
self.logger.info(f"Evaluating agent at round {p1_round} against agent at round {p2_round}")
146-
p1_patch = self.agent.get_metadata()["diff"][p1_round] if p1_round > 0 else ""
147-
p2_patch = self.agent.get_metadata()["diff"][p2_round] if p2_round > 0 else ""
154+
p1_patch = self._get_round_diff(self.agent.name, p1_round)
155+
p2_patch = self._get_round_diff(self.agent.name, p2_round)
148156
p1.reset_and_apply_patch(p1_patch)
149157
p2.reset_and_apply_patch(p2_patch)
150158
for i_repetition in range(n_repetitions):

0 commit comments

Comments
 (0)