# battlecode-bot
A C++ game-AI bot for Cambridge Battlecode 2026, built by a team of four over the autumn. Bots play each other on a ranked Elo ladder, then in tournaments on maps nobody has seen before.
- final rank
- #77 / 831 teams
- in the UK
- #17
- tier
- Diamond · 2,111
- peak
- #28 · 2,151 Elo
- team
- WYYL · 4 people
- stack
- C++ · Python
## the problem
Each side's champions farm gems, fight, and bank gems at altars; first to 1,000 banked gems wins. The ladder runs on nine known maps, but tournaments use maps nobody has seen. Our early bot knew each ladder map by heart, which meant that on tournament day almost none of that work would run.
## what we built
- The bot (C++): drafting, farming, banking, shopping and fighting logic, with map-specific tuning on the ladder and a general strategy for unseen maps.
- A local lab: fixed-seed matches against strong opponents, so every change could be judged game for game.
- A replay pipeline: pulls ranked games from the public API and turns them into numbers: deaths, idle time, when each team banks.
- An overnight loop: automated runs that trained a general bot on randomly generated maps, a stand-in for the unseen tournament maps.
## what I figured out
I studied the #1 team's replays to work out why they beat us. The biggest gap was banking. We banked at a fixed 40 gems; they banked when the risk of carrying outweighed the trip. I wrote it up as an optimal-stopping rule:
// bank now if λ · g · T > Δ · r λ chance of dying per round while carrying g gems carried T rounds until the next altar on the route Δ extra rounds the trip costs r gems farmed per round
- Champion time is the real currency. A death costs 60 rounds plus the walk back. On one map, our 13 deaths added up to about one and a half champions sitting out the whole game.
- A test is only as good as its opponents. One version won 88.7% of 2,880 local games, then lost 5 of 5 to the top team. Our sparring partners were our own older bots, so they never punished the mistakes the ladder did.
## how we worked
None of us knew much C++, so we leaned on AI tools to write it while we focused on strategy and testing. That made our job deciding what to try and proving whether it worked:
- Every change went behind its own switch, off by default, in a new version, so any experiment could be undone and any upload traced.
- Games are deterministic, so we judged changes with exact rematches: same map, same side, before and after.
- We asked for evidence from replays, not guesses, and pushed back on any claim the data didn't support.
## reflections
There was never a eureka moment. We kept chugging along, improving the bot bit by bit, and that steady grind got us into Diamond.
what worked
- Training on randomly generated maps and testing on a separate held-out set. The general bot went from 71% to 87% on maps it had never seen, and its deaths roughly halved.
- Replays gave us numbers instead of guesses: 95% of our deaths were to enemy champions, and whoever hit first won about 5 to 1.
- Going after one specific, well-understood failure worked every time we tried it.
what didn't
- Too much per-map tuning. None of it runs on unseen maps, and we won only 41% on new ladder maps.
- We reused our held-out maps until they weren't held out any more, so some gains turned out to be overfitting.
- We spotted the real problem early (losing fights we could see coming) but never fully fixed it.
next time
- Check the test setup for noise before testing anything.
- Keep a final map set that is played exactly once.
- Write each idea's pass mark before writing its code.
- General rules over map-specific profiles.