| 14 | |
| 15 | |
| 16 | class ChessArena(CodeArena): |
| 17 | name: str = "Chess" |
| 18 | description: str = """Chess is a strategic board game where you improve a chess engine (Kojiro) to compete against other engines. |
| 19 | Your engine is written in C++ and uses the UCI (Universal Chess Interface) protocol. |
| 20 | You can modify the evaluation function, search algorithms, move ordering, and other aspects of the engine to improve its strength. |
| 21 | The engine source code is located in the `src/` directory, and you compile it using `make native`. |
| 22 | IMPORTANT: Do not modify the executable name in the Makefile (keep `EXE = kojiro`). The executable must be named `kojiro`.""" |
| 23 | submission: str = "src/" |
| 24 | default_args: dict = { |
| 25 | "time_control": "1+0.01", |
| 26 | } |
| 27 | |
| 28 | def __init__(self, config, **kwargs): |
| 29 | super().__init__(config, **kwargs) |
| 30 | |
| 31 | # Get time control from config |
| 32 | time_control = self.game_config.get("args", self.default_args).get( |
| 33 | "time_control", self.default_args["time_control"] |
| 34 | ) |
| 35 | |
| 36 | # Build base Fastchess command |
| 37 | self.run_cmd_base = f"fastchess -each tc={time_control}" |
| 38 | |
| 39 | # Store time control for reference |
| 40 | self.time_control = time_control |
| 41 | |
| 42 | self.logger.debug(f"Initialized ChessArena with time control: {time_control}") |
| 43 | |
| 44 | def validate_code(self, agent: Player) -> tuple[bool, str | None]: |
| 45 | """ |
| 46 | Validate that agent's Kojiro codebase compiles successfully. |
| 47 | """ |
| 48 | # Check that src/ directory exists |
| 49 | ls_result = agent.environment.execute("ls") |
| 50 | if "src" not in ls_result["output"]: |
| 51 | return False, "There should be a `src/` directory in the workspace" |
| 52 | |
| 53 | # Compile the engine |
| 54 | self.logger.debug(f"Compiling Kojiro for agent {agent.name}") |
| 55 | compile_result = agent.environment.execute( |
| 56 | "cd src && make native", |
| 57 | timeout=120, # 2 minute timeout for compilation |
| 58 | ) |
| 59 | |
| 60 | if compile_result["returncode"] != 0: |
| 61 | error_output = compile_result.get("output", "Unknown compilation error") |
| 62 | # Truncate very long error messages |
| 63 | if len(error_output) > 1000: |
| 64 | error_output = error_output[:1000] + "\n... (truncated)" |
| 65 | return False, f"Compilation failed:\n{error_output}" |
| 66 | |
| 67 | # Verify executable was created |
| 68 | kojiro_check = agent.environment.execute("ls src/kojiro") |
| 69 | if kojiro_check["returncode"] != 0 or "kojiro" not in kojiro_check["output"]: |
| 70 | return False, "Compilation succeeded but executable 'kojiro' not found in src/" |
| 71 | |
| 72 | self.logger.info(f"Agent {agent.name} passed validation: Kojiro compiles successfully") |
| 73 | return True, None |
nothing calls this directly
no outgoing calls
no test coverage detected