ai-code-battle/starters/rust
jedarden b60b103c0f fix(starter-rust): fix compilation errors in Rust starter kit
- Add Clone derive to AppState for axum compatibility
- Import Digest trait from sha2 for hash computation
- Use String instead of &str in response headers for lifetime safety
- Add Position import to grid.rs module
- Make Position Copy for easier cloning
- Replace constant_time_eq with custom hmac_equal function
- Add musl-dev to Dockerfile for Alpine build compatibility

The Rust starter kit now compiles and builds successfully with
cargo check and Docker, matching the requirements from plan §5.3
and §12 (Phase 2).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-08 10:18:11 -04:00
..
.github/workflows feat(starters,web): add 6-language bot starter kits per §6 2026-04-21 13:58:27 -04:00
src fix(starter-rust): fix compilation errors in Rust starter kit 2026-05-08 10:18:11 -04:00
Cargo.toml feat(starters,web): add 6-language bot starter kits per §6 2026-04-21 13:58:27 -04:00
Dockerfile fix(starter-rust): fix compilation errors in Rust starter kit 2026-05-08 10:18:11 -04:00
README.md feat(evolver): persist cross-pollination state to Postgres per §10.2 2026-04-22 16:04:15 -04:00

acb-starter-rust

Rust starter kit for AI Code Battle — a competitive bot programming platform.

Uses axum for the HTTP server with serde for JSON and hmac/sha2 for authentication.

Quick Start

# Run locally
export BOT_SECRET=dev-secret
cargo run

# Run with Docker
docker build -t my-bot .
docker run -e BOT_SECRET=your-secret -p 8080:8080 my-bot

Your bot listens on port 8080 and responds to POST /turn with move commands.

Register Your Bot

Once your bot is deployed and accessible via HTTPS:

curl -X POST https://api.aicodebattle.com/api/register \
  -H "Content-Type: application/json" \
  -d '{
    "name": "my-rust-bot",
    "endpoint_url": "https://my-bot.example.com",
    "owner": "your-name",
    "description": "My awesome bot"
  }'

Save the bot_id and shared_secret from the response — the secret is shown only once.

Project Structure

src/main.rs  # HTTP server, HMAC auth, game types, and strategy entry point
src/grid.rs  # Grid utilities (toroidal distance, BFS, neighbors)
Cargo.toml   # Rust dependencies
Dockerfile   # Multi-stage container build

Grid Helpers

src/grid.rs provides utility functions for the toroidal grid:

  • toroidal_manhattan(a, b, rows, cols) — Manhattan distance with wrap-around
  • toroidal_chebyshev(a, b, rows, cols) — Chebyshev distance with wrap-around
  • neighbors(pos, rows, cols) — 8-directional neighbors with wrap
  • bfs(start, goal, passable, rows, cols) — BFS pathfinding, returns Option<Vec<Position>>

Customization

Edit compute_moves() in src/main.rs to implement your strategy. The GameState struct provides:

  • bots — all visible bots (yours and enemies)
  • energy — visible energy pickup locations
  • cores — visible core positions
  • walls — visible wall positions
  • you.energy — your current energy count
  • you.score — your current score
  • config — match parameters (grid size, etc.)

Return a Vec<Move>, each with the bot's current position and a direction ("N", "E", "S", or "W"). Bots not included in the response stay in place.

Protocol

  • Endpoint: POST /turn — receives game state JSON, returns moves JSON
  • Health: GET /health — must return 200
  • Timeout: 3 seconds per turn
  • Auth: HMAC-SHA256 via X-ACB-Signature header