description:str=f'Robocode (Tank Royale) is a programming game where your code is the tank: each turn your bot sends intents—speed plus body/gun/radar turn rates and firepower—based on the game state it perceives via radar.Yourprogramdecideshowtomove,aim,andfireinadeterministic,turn-basedarenatooutlastotherbots.YourbotlogicmustbewritteninJavaandlocatedinthe`robots/custom/`directory.Keepthemainbotclassnamed`{str(RC_FILE)}`,butyoucanincludeadditionalJavafilesifyou'd like.'
defexecute_round(self,agents:list[Player]):foragentinagents:# Copy the agent codebase into the game codebase and compile itforcmdin[f"mkdir -p robots/{agent.name}",f"cp -r /{agent.name}/robots/custom/* robots/{agent.name}/",f"find robots/{agent.name}/ -name '*.java' -exec sed -i 's/custom/{agent.name}/g' {{}} +",f'javac -cp "libs/robocode.jar" robots/{agent.name}/*.java',]:self.environment.execute(cmd)# Create .battle fileselected_robots=",".join([f"{agent.name}.{RC_FILE.stem}*"foragentinagents])# Use timestamp for unique battle file name since rounds are managed by tournamentbattle_file=f"{self.game_id}-battle{int(time.time())}.battle"battle_content=f"""#Battle Properties{self._get_battle_config()}robocode.battle.selectedRobots={selected_robots}"""create_file_in_container(self.environment,content=battle_content,dest_path=f"battles/{battle_file}")# Run battle with results output to filecmd=f"{self.run_cmd_round} -battle {battle_file}"self.logger.info(f"Running game: {cmd}")withThreadPoolExecutor(5)asexecutor:# Submit all simulations to the thread poolfutures=[executor.submit(self._run_single_simulation,agents,idx,cmd)foridxinrange(self.game_config.get("sims_per_round",100)//SIMS_PER_RUN)]# Collect results as they completeforfutureintqdm(as_completed(futures),total=len(futures)):future.result()
Source code in codeclash/arenas/robocode/robocode.py
148149150151152153154155156157158159160161162163
defvalidate_code(self,agent:Player)->tuple[bool,str|None]:if"robots"notinagent.environment.execute("ls")["output"]:returnFalse,"There should be a `robots/` directory"if"custom"notinagent.environment.execute("ls robots")["output"]:returnFalse,"There should be a `robots/custom/` directory"ifstr(RC_FILE)notinagent.environment.execute("ls robots/custom")["output"]:returnFalse,(f"There should be a `robots/custom/{RC_FILE}` file. "f"You can include additional files, but the primary tank logic must be in `robots/custom/{RC_FILE}`")response=agent.environment.execute('javac -cp "libs/robocode.jar" robots/custom/*.java')ifresponse["returncode"]!=0:returnFalse,f"Compilation error:\n{response['output']}"iff"{RC_FILE.stem}.class"notinagent.environment.execute("ls robots/custom")["output"]:returnFalse,f"`{RC_FILE.stem}.class` not found after compilation"returnTrue,None