MCPcopy Create free account
hub / github.com/CodeClash-ai/CodeClash / execute_round

Method execute_round

codeclash/arenas/robocode/robocode.py:92–125  ·  view source on GitHub ↗
(self, agents: list[Player])

Source from the content-addressed store, hash-verified

90 # Always record one representative battle (idx 0) per round so the model and the replay
91 # viewer get behavioral traces; record extra battles only if record_ratio is raised.
92 # Each recorded battle's raw XML is later parsed into compact sim/trace files and deleted.
93 if idx == 0 or random.random() < self.game_config.get("record_ratio", 0):
94 cmd = f"{cmd} -recordXML {rc_record}"
95 try:
96 output = self.environment.execute(cmd, timeout=120)
97 except subprocess.TimeoutExpired:
98 self.logger.warning(f"RoboCode simulation {idx} timed out: {cmd}")
99 return ""
100 if output["returncode"] != 0:
101 self.logger.warning(
102 f"RoboCode simulation {idx} failed with exit code {output['returncode']}:\n{output['output']}"
103 )
104 return output["output"]
105
106 def execute_round(self, agents: list[Player]):
107 for agent in agents:
108 pkg = _java_pkg(agent.name) # valid Java package (agent.name may contain hyphens)
109 # Copy the agent codebase into the game codebase and compile it
110 for cmd in [
111 f"mkdir -p robots/{pkg}",
112 f"cp -r /{agent.name}/robots/custom/* robots/{pkg}/",
113 f"find robots/{pkg}/ -name '*.java' -exec sed -i 's/custom/{pkg}/g' {{}} +",
114 f'javac -cp "libs/robocode.jar" robots/{pkg}/*.java',
115 ]:
116 self.environment.execute(cmd)
117
118 # Create .battle file (robot fully-qualified name uses the sanitized package)
119 selected_robots = ",".join([f"{_java_pkg(agent.name)}.{RC_FILE.stem}*" for agent in agents])
120 # Use timestamp for unique battle file name since rounds are managed by tournament
121 battle_file = f"{self.game_id}-battle{int(time.time())}.battle"
122 battle_content = f"""#Battle Properties
123{self._get_battle_config()}
124robocode.battle.selectedRobots={selected_robots}
125"""
126 create_file_in_container(self.environment, content=battle_content, dest_path=f"battles/{battle_file}")
127
128 # Run battle with results output to file

Callers

nothing calls this directly

Calls 4

_get_battle_configMethod · 0.95
create_file_in_containerFunction · 0.90
getMethod · 0.80
executeMethod · 0.45

Tested by

no test coverage detected