Skip to content

Commit f6b1d7b

Browse files
committed
Fixes #55: Shuffle agents in case of positional advantages
1 parent bba4174 commit f6b1d7b

2 files changed

Lines changed: 2 additions & 2 deletions

File tree

codeclash/games/battlecode/battlecode.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import random
21
import re
32
from pathlib import Path
43

@@ -29,7 +28,6 @@ def execute_round(self, agents: list[Player]):
2928
for agent in agents:
3029
src, dest = f"/{agent.name}/src/{BC_FOLDER}/", str(DIR_WORK / "src" / agent.name)
3130
self.environment.execute(f"cp -r {src} {dest}")
32-
random.shuffle(agents) # Start position matters in BattleCode! Shuffle to be fair.
3331
args = [f"--p{idx + 1}-dir src --p{idx + 1} {agent.name}" for idx, agent in enumerate(agents)]
3432
cmd = f"{self.run_cmd_round} {' '.join(args)}"
3533
self.logger.info(f"Running game: {cmd}")

codeclash/games/game.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import os
2+
import random
23
import subprocess
34
import time
45
from abc import ABC, abstractmethod
@@ -205,6 +206,7 @@ def run_round(self, agents: list[Player], round_num: int) -> RoundStats:
205206
Returns the log output, result output, and winner name. All bookkeeping should be
206207
handled by the tournament class.
207208
"""
209+
random.shuffle(agents) # Shuffle to ensure fairness in case of positional advantages
208210
stats = RoundStats(round_num, agents)
209211
validated = []
210212
for agent in agents:

0 commit comments

Comments
 (0)