BattleCode24 arena implementation. Lifecycle: 1. validate_code() - Source-level structural checks only (in agent container) 2. execute_round() - Compile and run simulations (in game container) 3. get_results() - Parse logs and determine winner Failure handling: - If one age
| 38 | |
| 39 | |
| 40 | class BattleCode24Arena(CodeArena): |
| 41 | """BattleCode24 arena implementation. |
| 42 | |
| 43 | Lifecycle: |
| 44 | 1. validate_code() - Source-level structural checks only (in agent container) |
| 45 | 2. execute_round() - Compile and run simulations (in game container) |
| 46 | 3. get_results() - Parse logs and determine winner |
| 47 | |
| 48 | Failure handling: |
| 49 | - If one agent fails to compile, the other wins automatically |
| 50 | - If both fail to compile, round is a no-contest (tie) |
| 51 | - Individual simulation failures don't count toward either player |
| 52 | """ |
| 53 | |
| 54 | name: str = "BattleCode24" |
| 55 | description: str = """Battlecode 2024: Breadwars is a real-time strategy game where your Java bot controls a team of robots competing to capture the opponent's flags. |
| 56 | Your mission: capture all 3 of the opponent's flags before they capture yours. Robots can attack, heal, build traps, dig/fill terrain, and specialize in different skills through experience. |
| 57 | The game features a setup phase (first 200 rounds) where teams are separated by a dam, followed by open combat. Robots gain experience and level up their attack, build, and heal specializations.""" |
| 58 | default_args: dict = { |
| 59 | "maps": "DefaultSmall", |
| 60 | } |
| 61 | submission: str = "src/mysubmission" |
| 62 | |
| 63 | def __init__(self, config, **kwargs): |
| 64 | super().__init__(config, **kwargs) |
| 65 | assert len(config["players"]) == 2, "BattleCode24 is a two-player game" |
| 66 | |
| 67 | # Build base run command |
| 68 | self.run_cmd_base: str = "./gradlew --no-daemon run" |
| 69 | for arg, val in self.game_config.get("args", self.default_args).items(): |
| 70 | if isinstance(val, bool): |
| 71 | if val: |
| 72 | self.run_cmd_base += f" -P{arg}=true" |
| 73 | else: |
| 74 | self.run_cmd_base += f" -P{arg}={val}" |
| 75 | |
| 76 | # Round state (set by execute_round, used by get_results) |
| 77 | self._round_result: RoundResult | None = None |
| 78 | |
| 79 | def validate_code(self, agent: Player) -> tuple[bool, str | None]: |
| 80 | """Validate source structure. No compilation - that happens in execute_round. |
| 81 | |
| 82 | Checks: |
| 83 | 1. src/mysubmission/ directory exists |
| 84 | 2. RobotPlayer.java file exists |
| 85 | 3. run(RobotController rc) method signature present |
| 86 | 4. Correct package declaration |
| 87 | """ |
| 88 | # Check for mysubmission directory |
| 89 | ls_output = agent.environment.execute("ls src")["output"] |
| 90 | if BC24_FOLDER not in ls_output: |
| 91 | return False, f"There should be a `src/{BC24_FOLDER}/` directory" |
| 92 | |
| 93 | # Check for RobotPlayer.java file |
| 94 | ls_mysubmission = agent.environment.execute(f"ls src/{BC24_FOLDER}")["output"] |
| 95 | if "RobotPlayer.java" not in ls_mysubmission: |
| 96 | return False, f"There should be a `src/{BC24_FOLDER}/RobotPlayer.java` file" |
| 97 |
no outgoing calls