|
| 1 | +from pathlib import Path |
| 2 | + |
| 3 | +from codeclash.agents.player import Player |
| 4 | +from codeclash.games.game import CodeGame, RoundData, RoundStats |
| 5 | + |
| 6 | + |
| 7 | +class HuskyBenchGame(CodeGame): |
| 8 | + name: str = "HuskyBench" |
| 9 | + |
| 10 | + def __init__(self, config, *, tournament_id: str, local_output_dir: Path): |
| 11 | + super().__init__(config, tournament_id=tournament_id, local_output_dir=local_output_dir) |
| 12 | + self.run_cmd_round: str = ( |
| 13 | + f"python engine/main.py --port 8000 --sim --sim-rounds {self.game_config['sims_per_round']}" |
| 14 | + ) |
| 15 | + for arg, val in self.game_config.get("args", {}).items(): |
| 16 | + if isinstance(val, bool): |
| 17 | + if val: |
| 18 | + self.run_cmd_round += f" --{arg}" |
| 19 | + else: |
| 20 | + self.run_cmd_round += f" --{arg} {val}" |
| 21 | + |
| 22 | + def get_stats(self, result_outputs: list[str], agents: list[Player]) -> RoundStats: |
| 23 | + return RoundStats(winner="N/A", scores={}) |
| 24 | + |
| 25 | + def execute_round(self, agents: list[Player]) -> RoundData: |
| 26 | + try: |
| 27 | + self.logger.debug("Starting game servers") |
| 28 | + self.environment.execute(self.run_cmd_round + " > engine/output/std_out.log &") |
| 29 | + for agent in agents: |
| 30 | + self.environment.execute("python client/main.py --port 8000 &", cwd=f"/{agent.name}") |
| 31 | + |
| 32 | + # Save logs to response |
| 33 | + self.logger.info(self.environment.execute("cat engine/output/std_out.log")["output"]) |
| 34 | + |
| 35 | + return RoundData(logs=[], results=[]) |
| 36 | + finally: |
| 37 | + # Kill all python servers when done |
| 38 | + self.environment.execute("pkill -f 'python client/main.py' || true") |
| 39 | + self.environment.execute("pkill -f 'python engine/main.py' || true") |
0 commit comments