Skip to content

Commit f60b391

Browse files
author
Player
committed
Minor BattleCode edge case
1 parent 94ccfaa commit f60b391

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

codeclash/arenas/battlecode/battlecode.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def _run_single_simulation(self, agents: list[Player], idx: int, cmd: str) -> st
4949
def execute_round(self, agents: list[Player]):
5050
for agent in agents:
5151
src, dest = f"/{agent.name}/src/{BC_FOLDER}/", str(DIR_WORK / "src" / agent.name)
52-
self.environment.execute(f"cp -r {src} {dest}")
52+
self.environment.execute(f"rm -rf {dest}; cp -r {src} {dest}")
5353
args = [f"--p{idx + 1}-dir src --p{idx + 1} {agent.name}" for idx, agent in enumerate(agents)]
5454
cmd = f"{self.run_cmd_round} {' '.join(args)}"
5555
self.logger.info(f"Running game: {cmd}")
@@ -69,8 +69,10 @@ def get_results(self, agents: list[Player], round_num: int, stats: RoundStats):
6969
for idx in range(self.game_config["sims_per_round"]):
7070
with open(self.log_round(round_num) / BC_LOG.format(idx=idx)) as f:
7171
lines = f.read().strip().split("\n")
72+
if len(lines) < 3:
73+
# Game likely crashed, skip this simulation
74+
continue
7275
# Get the third-to-last line which contains the winner info
73-
assert len(lines) >= 3, "Log file does not contain enough lines to determine winner"
7476
winner_line = lines[-3]
7577
reason_line = lines[-2]
7678
match = re.search(r"\s\((.*)\)\swins\s\(", winner_line)

0 commit comments

Comments
 (0)