Rules

How a match works

Same base, same gold, blind plans. Your bot builds a base, drafts an army, then commands every troop and every tower while two raids play out at once.

Contents

01Overview

Gold1,200per team, for troops and spells
Raid length450 roundsat most, both raids at once
Shop10 + 5troop types + spells
Base68 piecesidentical for both teams

Imperial Battlecode is a programming game. Both teams get the same buildings, the same gold and the same shop. Your bot, written in Rust and compiled to WebAssembly, lays out a base and buys an army without seeing the other side. Then both raids run at the same time: your army attacks their base while their army attacks yours, and your code drives every troop you send and every tower that defends you.

Nobody clicks anything during a match. Matches are deterministic: the same two bots on the same map with the same seed play the same match, which is what makes replays and local testing useful.

02Match flow

  1. Build

    Place the fixed inventory on your own copy of the map. You never see the enemy base.

  2. Draft

    Spend 1,200 gold on troops and spells. Still blind.

  3. Raids

    A raids B and B raids A, round by round, up to 450 rounds.

  4. Score

    Stars first, then destruction, then speed. The better raid wins.

The engine calls your bot through three entry points: build once, draft once, then turn for each of your robots in every round of the raids. Each call has its own bytecode budget (see Bytecode and fuel). The API reference shows the code.

03The map

Loading
  • Deploy zone. The outer ring, 2 tiles wide. No buildings; attackers land troops here.
  • Scouted at raid start. Every tile less than 6 tiles from the edge is explored before the first round. Buildings here are seen at once.
  • The rest of the base area. Hidden from the commander until troops or spells explore it.
  • Rocks. Nothing builds on them and ground troops cannot enter them; flyers pass over.

The test map pillars. Coordinates start at (0, 0) in the bottom-left corner.

  • Coordinates. (0, 0) is the bottom-left tile and north is +y. Robots move in eight directions.
  • Distances are squared. Every range is a squared Euclidean distance (r²). A range of 16 reaches (4, 0) and (2, 3) away, but not (3, 3), which is 18. A building's distance is measured to its nearest tile.
  • One map, two bases. Both teams build on the same map, each on its own copy. Each raid is fought on the defender's copy.
  • The pool. 8 maps from 48 to 64 tiles a side, plus small 24 by 24 test maps (open, canyon, pillars). Every bundled map is mirrored on both axes, keeps rocks out of the deploy zone, has room for a keep, and lets ground troops reach every open tile from the deploy zone. Browse them on the maps page.

04Build

build runs once per team with 200,000 bytecode. Every team gets exactly this inventory:

  • You give each piece its bottom-left tile. A 2x2 building also covers the tiles one step east, north and northeast of it.
  • Every tile it covers must be on the map, outside the deploy zone, free, and not a rock. is_buildable and can_place check this for you.
  • Traps are placed the same way as buildings, from the same inventory.
  • Whatever you do not place is lost for the match.
  • If you place no keep, the engine puts it on the free spot nearest the centre. If your own buildings leave no such spot, it goes to the spot nearest the centre that only rocks and the deploy zone allow, and your pieces under it are removed.
Design for the unknown

You build before you know what is coming. A base that only stops ground troops loses to flyers, and one long wall line loses to sappers.

05Draft

draft runs once with 20,000 bytecode. You have 1,200 gold and one shop for both troops and spells; can_buy(kind, n) tells you whether you can afford n of something, buy(kind, n) pays for them.

  • Troops wait in reserve until your commander deploys them. Spells wait for the commander to cast them.
  • Gold you do not spend is not worth anything.
  • The draft is blind too: the same army has to work against a base you have never seen.

06Raids

Both raids share one round clock. Team A's army attacks team B's base and team B's army attacks team A's base, independently: nothing in one raid changes the other. Each round of a raid goes in this order:

  1. Cooldowns of every troop and every defense go down by 1.
  2. Every living troop explores the tiles in its vision (fog of war).
  3. The attacker's commander runs (10,000 bytecode): deploy troops, cast a spell.
  4. Each living attacking troop runs, in id order (2,500 bytecode each).
  5. Each living defense of the defending base runs, in id order (2,500 bytecode each), as long as an attacking troop is alive.

A raid ends as soon as one of these is true:

  • every scored building of the base is destroyed;
  • round 450 has been played;
  • the attacker has no troops on the map and none in reserve, and either holds no damage spell (scorch, bolt) or has cast nothing for 3 rounds in a row.

07Commander and spells

The commander is your attacking team's general. It never stands on the map. Every round it may:

  • Deploy up to 3 troops from the reserve onto deploy-zone tiles. Flyers may land anywhere in the zone, ground troops not on rocks.
  • Cast up to 1 spell, centred on any tile of the map, explored or not. It takes effect at once.
  • Read the scouting report: the living enemy buildings that have at least one explored tile, your troops on the map, the reserve, the spells left and the destruction so far.

Spells hit everything in their radius², walls included. Hidden traps are never hit.

Scorch
Damage to every building in range.
Bolt
Damage to every building in range, and the defenses in range are stunned: they miss the next 3 rounds.
Stasis
No damage. The defenses in range miss the next 5 rounds.
Mend
Your troops in range regain up to 150 health each.
Fury
For 8 rounds your troops in range have cooldowns of max(1, ceil(base / 2)) and deal damage * 130 // 100.

Radii, damage and costs are in the spell codex. A cast also explores every tile in the spell's radius².

08Troops

Each troop on the map runs your code once per round. It moves one tile in one of eight directions when its movement is ready and acts when its action is ready; moving and acting restart the matching cooldown (move cooldown and action cooldown in the codex).

  • Attacking. attack(loc) hits the building that covers tile loc. The range is measured from the troop to that tile, so aim at the tile nearest you. Walls take the troop's wall damage.
  • Ground and air. Ground troops cannot enter rocks or building tiles, walls included. Troops may share a tile. Flyers ignore walls, rocks and ground traps; only the longbow post, the spire, the arc pylon and the sky mine can hurt them.
  • Sight. A troop sees buildings within r² 20, or within its attack radius if that is bigger. It never sees traps. It also senses your other troops.
  • Sapper. Cannot attack. explode() damages every building within its radius² (walls take its wall damage), then the sapper dies.
  • Mage. Its attack splashes every building within its splash r² of the target tile.
  • Mender. Cannot attack. mend() restores health to every friendly troop within its radius², itself included.

09Defenses

The seven defense types (bombard, longbow post, lobber, spire, arc pylon, ballista, flame tower) run the defending team's code. While your base is raided, each of your living defenses gets a turn every round, as long as an enemy troop is alive on the map.

  • A defense senses enemy troops within its range and attacks a tile. The tile must be within its range and, for the lobber and the ballista, not closer than its minimum range.
  • Each type hits ground troops, air troops or both. A shot without splash hits the lowest-id valid troop on the tile; splash hits every valid troop within the splash r² of the tile.
  • A stunned defense (bolt, stasis) misses its turns until the stun runs out.
Towers do not fire by themselves

If your turn ignores defenses, your base has none. The smallest useful defense code is a few lines: see the example.

10Traps

Traps are placed in the build and stay hidden. The attacker cannot sense them, they do not block movement, spells do not touch them, and they do not count toward destruction. Moving a trap changes nothing the attacker can sense until it fires.

Spike trap
The first ground troop to step on it sets it off: damage to every ground troop within its splash r². Single use.
Blast charge
The same, with more damage and a wider splash. Single use.
Sky mine
The first air troop within its radius² takes the damage. Single use.
Tar pit
Never used up. Every ground troop that steps on it gets 3 rounds added to its movement cooldown.

11Fog of war

Each raid keeps the set of tiles the attacker has explored. An explored tile stays explored.

  • At raid start: every tile less than 2 + 4 tiles from the edge.
  • At the start of each round, after cooldowns and before the commander: every tile within the vision of each living troop.
  • When a spell is cast: every tile within its radius² of the cast tile.

Fog only limits the commander's view: its building list holds just the buildings with an explored tile, and is_explored(loc) tells you what has been seen. Troop and defense sensing are unchanged, spells may be cast blind on any tile, the destruction count is exact, and rocks are public map data. The shared array is how the scouting report reaches your troops.

12Scoring

Destruction is counted in per-mille over the scored buildings: everything except walls and traps, which makes 19 per base. It is 1000 * destroyed // scored, rounded down, and shown as a percent with one decimal.

50% destruction, which takes 10 of the 19 scored buildings.

The keep destroyed, at any destruction.

100% destruction: every scored building.

Each raid scores its attacker. The match goes to the team whose raid has:

  1. more stars, then
  2. more destruction (each scored building is worth about 5.3%), then
  3. fewer rounds, but only when both raids destroyed every scored building.

If all of that is equal, the match is a draw.

13Bytecode and fuel

Every call into your bot runs on a budget. The rules state it in bytecode, one unit per instruction:

Budget per call
CallWhenBytecodeWasm fuel
buildonce per team200,0004,000,000
draftonce per team20,00050,000
turn commanderevery round of your raid10,000120,000
turn troop, defenseevery round, each robot2,50015,000

Your Rust bot runs as WebAssembly, metered in fuel: about one unit per wasm instruction, with the budgets in the last column. Every call to the game costs 1 fuel, plus its API cost below times 6. The replay converts what each robot used back into bytecode units, so the numbers there match the rules.

  • A robot that runs out stops at once. Its turn is over, actions it already took stand, and it plays again next round. A panic or trap does the same: it ends that turn, not the match.
  • A refused action (one whose can_* check is false) still pays its cost.
  • Setup work, such as your bot's Default, is charged to the first call that runs it.
  • Printed lines are kept per robot per round (the first 8 lines of 160 characters), and each kept byte costs 1 fuel. Indicator strings, dots and lines cost nothing beyond the call and show up in the replay. A string stays until you set a new one; dots and lines last one round.

API costs

On top of the instructions themselves, these calls cost extra. Everything not listed (map size, cooldowns, location helpers, type stats) costs only the call.

The sandbox

  • A bot is a WebAssembly module for wasm32-unknown-unknown, up to 2 MiB. Its only import is the game call; no WASI, no threads, no SIMD.
  • Each robot may use up to 64 MiB of memory. A call that runs longer than one second of wall-clock time is stopped as a backstop; fuel is the real limit.
  • Memory survives a failed call, so a half-finished update stays half finished.

14Shared array

Every robot is its own instance of your module: one planner for build and draft, one commander per raid, one per troop and one per defense. Globals and struct fields are never shared between them.

To talk, teammates in one raid share an array of 64 integers, each from 0 to 65,535: read_shared_array(i) and write_shared_array(i, v), 1 bytecode each. A write outside those bounds is refused. The attackers and the defenders of a raid have separate arrays.

The commander runs first each round, so what it writes is there for the troops in the same round. A common pattern: the commander posts targets from its scouting report, the troops read them.

15Codex

Every number in the game, straight from the data files. Pick a category, switch between cards and a comparison table, and link to an entry with #codex-colossus style anchors. Ranges are r²; cooldowns are rounds.

Loading the codex

16Constants

The match constants, with what each one controls.

17Ladder and ratings

Your team's active bot plays ranked matches on its own, in rounds, all season. You never schedule them: upload a bot that passes validation and it is in the next round.

  • Rounds. A round queues every ranked match at once. The next one starts when every match of the last round has finished and the ladder interval has passed since it began (the ladder page shows the next start). An admin can also start a round early.
  • Opponents. Each team gets 4 to 8 matches a round, never the same opponent twice. Nine picks in ten favour games the ladder learns most from: close ratings, or a rating that is still uncertain. One pick in ten is anyone, so the field stays mixed. Maps come from the ranked pool, spread so a team's matches in a round are on different maps.
  • Ratings. Glicko: every team starts at 1500 with a deviation of 350, shown as 1500 ± 350. A win scores 1, a draw 0.5, a loss 0, and beating a stronger team gains more. Every game shrinks the deviation, down to 30; it does not grow while you wait.
  • Provisional. A deviation above 110 marks the rating provisional: too few games to say much yet (about 10 for a new team). Provisional teams are ranked like everyone else.
  • A new bot. Activating another bot keeps your rating but raises the deviation to at least 200, so the rating catches up with the new bot in a few rounds. Matches your old bot still had queued count for the opponent only.

One example: a team at 1620 ± 80 loses to a team at 1540 ± 150. The winner gains about 66 and the loser drops about 19: one game says more about the less certain team.

Not rated: scrimmages, test matches, matches that failed with a server error, and your side of a match played by a bot that is no longer active. A match that runs past the server's time limit is not an error: the side that used more time forfeits.