(self, agents: list[Player])
| 90 | if output["returncode"] != 0: |
| 91 | self.logger.warning( |
| 92 | f"RoboCode simulation {idx} failed with exit code {output['returncode']}:\n{output['output']}" |
| 93 | ) |
| 94 | return output["output"] |
| 95 | |
| 96 | def execute_round(self, agents: list[Player]): |
| 97 | for agent in agents: |
| 98 | # Copy the agent codebase into the game codebase and compile it |
| 99 | for cmd in [ |
| 100 | f"mkdir -p robots/{agent.name}", |
| 101 | f"cp -r /{agent.name}/robots/custom/* robots/{agent.name}/", |
| 102 | f"find robots/{agent.name}/ -name '*.java' -exec sed -i 's/custom/{agent.name}/g' {{}} +", |
| 103 | f'javac -cp "libs/robocode.jar" robots/{agent.name}/*.java', |
| 104 | ]: |
| 105 | self.environment.execute(cmd) |
| 106 | |
| 107 | # Create .battle file |
| 108 | selected_robots = ",".join([f"{agent.name}.{RC_FILE.stem}*" for agent in agents]) |
| 109 | # Use timestamp for unique battle file name since rounds are managed by tournament |
| 110 | battle_file = f"{self.game_id}-battle{int(time.time())}.battle" |
| 111 | battle_content = f"""#Battle Properties |
| 112 | {self._get_battle_config()} |
| 113 | robocode.battle.selectedRobots={selected_robots} |
| 114 | """ |
| 115 | create_file_in_container(self.environment, content=battle_content, dest_path=f"battles/{battle_file}") |
| 116 | |
| 117 | # Run battle with results output to file |
| 118 | cmd = f"{self.run_cmd_round} -battle {battle_file}" |
| 119 | self.logger.info(f"Running game: {cmd}") |
| 120 | with ThreadPoolExecutor(self.game_config.get("sim_concurrency", 5)) as executor: |
| 121 | # Submit all simulations to the thread pool |
| 122 | futures = [ |
| 123 | executor.submit(self._run_single_simulation, agents, idx, cmd) |
| 124 | for idx in range(self.game_config.get("sims_per_round", 100) // SIMS_PER_RUN) |
| 125 | ] |
| 126 | |
| 127 | # Collect results as they complete |
| 128 | for future in tqdm(as_completed(futures), total=len(futures)): |
nothing calls this directly
no test coverage detected