Skip to content

Commit 462294f

Browse files
committed
Fix CI; ensure agents have different names
1 parent 5d72d99 commit 462294f

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

codeclash/games/battlesnake/battlesnake.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ def _run_single_simulation(self, player2port: dict[str, int], idx: int) -> str:
7070
return output["output"]
7171

7272
def execute_round(self, agents: list[Player]):
73+
assert len(agents) > 1, "Battlesnake requires at least two players"
7374
self.logger.debug("Starting game servers")
7475
player2port = {}
7576
for idx, agent in enumerate(agents):
@@ -87,9 +88,9 @@ def execute_round(self, agents: list[Player]):
8788

8889
if len(available_ports) == 1:
8990
missing_ports = set(player2port.values()) - set(available_ports)
90-
player = next(player for player, port in player2port.items() if port in missing_ports)
91-
self.logger.warning(f"Player {player} failed to start")
92-
self._failed_to_start_player.append(player)
91+
missing_player = next(player for player, port in player2port.items() if port in missing_ports)
92+
self.logger.warning(f"Player {missing_player} failed to start")
93+
self._failed_to_start_player.append(missing_player)
9394
return
9495

9596
if len(available_ports) < len(agents):

codeclash/games/game.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,9 @@ def run_round(self, agents: list[Player], round_num: int) -> RoundStats:
212212
Returns the log output, result output, and winner name. All bookkeeping should be
213213
handled by the tournament class.
214214
"""
215+
all_names = {agent.name for agent in agents}
216+
assert len(all_names) == len(agents), "All agents must have unique names"
217+
215218
random.shuffle(agents) # Shuffle to ensure fairness in case of positional advantages
216219
stats = RoundStats(round_num, agents)
217220
validated: list[Player] = []

codeclash/tournaments/single_player.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ 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_dummy_agent(self) -> Player:
65+
def get_dummy_agent(self, player_config: dict) -> Player:
6666
"""Create a dummy agent that does nothing."""
6767
return Dummy(
68-
self.config["player"],
68+
player_config,
6969
environment=self.game.get_environment(f"{self.game.game_id}.dummy"),
70-
game_context=self.get_game_context(self.config["player"], round=0),
70+
game_context=self.get_game_context(player_config, round=0),
7171
)
7272

7373
def run(self):
@@ -128,11 +128,11 @@ def evaluate(self, n_repetitions: int = 3) -> None:
128128
"""
129129
p1_config = self.config["player"].copy()
130130
p1_config["name"] = "p1"
131-
p1 = self.get_dummy_agent()
131+
p1 = self.get_dummy_agent(p1_config)
132132

133133
p2_config = self.config["player"].copy()
134134
p2_config["name"] = "p2"
135-
p2 = self.get_dummy_agent()
135+
p2 = self.get_dummy_agent(p2_config)
136136
matrix = {
137137
p1_round: {p2_round: [] for p2_round in range(0, self.rounds + 1)} for p1_round in range(0, self.rounds + 1)
138138
}

0 commit comments

Comments
 (0)