ai-code-battle/starters/go
jedarden 7a0de02059 feat(evolver): persist cross-pollination state to Postgres per §10.2
Add crosspoll_state table to persist per-island generation counters
across evolver restarts. Load state on startup and save after each
cross-pollination check. Add persistence pattern and translation
structure tests.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-04-22 16:04:15 -04:00
..
.github/workflows feat(starters,web): add 6-language bot starter kits per §6 2026-04-21 13:58:27 -04:00
Dockerfile feat(evolver): persist cross-pollination state to Postgres per §10.2 2026-04-22 16:04:15 -04:00
go.mod feat(starters,web): add 6-language bot starter kits per §6 2026-04-21 13:58:27 -04:00
grid.go feat(evolver): persist cross-pollination state to Postgres per §10.2 2026-04-22 16:04:15 -04:00
main.go feat(evolver): persist cross-pollination state to Postgres per §10.2 2026-04-22 16:04:15 -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-go

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

Quick Start

# Run locally
export BOT_SECRET=dev-secret
go run main.go

# 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-go-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

main.go     # HTTP server, HMAC auth, game types, and strategy entry point
grid.go     # Grid utilities (toroidal distance, BFS, neighbors)
go.mod      # Go module definition
Dockerfile  # Multi-stage container build

Grid Helpers

grid.go provides utility functions for the toroidal grid:

  • ToroidalManhattan(a, b, rows, cols) — Manhattan distance with wrap-around
  • ToroidalChebyshev(a, b, rows, cols) — Chebyshev distance with wrap-around
  • Neighbors(p, rows, cols) — 8-directional neighbors with wrap
  • BFS(start, goal, passable, rows, cols) — BFS pathfinding, returns path or nil

Customization

Edit computeMoves() in main.go 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, attack range, etc.)

Return a slice of Move structs, 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