Getting started

From an empty folder to the ladder

Nine steps: install Rust, build the starter bot, make it yours, test it, upload it and let it play ranked matches.

Steps

01Install Rust

Bots are Rust compiled to WebAssembly. You need Rust 1.97 or newer, installed with rustup, and the wasm target:

shell
rustup update stable
rustup target add wasm32-unknown-unknown
rustc --version   # 1.97 or newer

02Get the starter bot

Download starter-bot.zip and unzip it anywhere. It holds the game SDK, a shared bot core and one complete example bot:

files · clashcode-starter/
README.md
Cargo.toml
crates/clashcode-sdk/       the game API (clashcode_sdk::game)
bots/                       a workspace of bots: build here
  Cargo.toml                members, release profile
  .cargo/config.toml        the linker flag the sandbox needs
  common/                   shared bot core (crate clashcode-botcore)
  examplebot/               the example: base, army, spells, defense

Want more to read? Downloads also has the source of the six house bots you will meet on the site.

03Build it

shell
cd clashcode-starter/bots
cargo build --release --target wasm32-unknown-unknown
ls target/wasm32-unknown-unknown/release/*.wasm

Each bot in the workspace becomes one .wasm file, here examplebot.wasm. That file is your submission. The workspace already sets what the sandbox needs:

  • crate-type = ["cdylib"] in the bot's [lib];
  • panic = "abort" in the release profile;
  • -C link-arg=--export=__stack_pointer in .cargo/config.toml, so the sandbox can reset the stack after a trap;
  • one clashcode_sdk::entry!(MyBot) in the crate, which exports the entry points.

04Make it yours

  1. Copy bots/examplebot to bots/mybot and set name = "mybot" in its Cargo.toml.
  2. Add "mybot" to members in bots/Cargo.toml.
  3. Build again: you get mybot.wasm next to the example.

Then pick a route:

Route A

Change the strategy

Keep the shared core and edit the example's Strategy: build places the base, draft buys the army, and priority, deploy_plan and cast_spells run the raid. Quickest way to a working bot.

Route B

Start from the SDK

Drop the core and implement clashcode_sdk::Bot yourself. The API reference walks through a complete small bot, phase by phase, that you can paste in as a start.

Every robot runs its own copy

Your commander, each troop and each tower is a separate instance of your module, with its own memory and a small budget per round. They share only a 64-slot integer array. Read the rules before you design anything that needs teamwork.

05Play a local match

You need the engine for this step

Local matches use the clashcode command, which is built from the engine workspace (clashcode-rs). The engine is not on the downloads page yet. Without it, skip to step 7 and test on the site: test matches against the house bots run on the same engine.

With the engine checked out, build the CLI once, then play your bot against a built-in one and save the replay:

shell
# in clashcode-rs/
cargo build --release -p clashcode-cli

# anywhere
clashcode run mybot.wasm builtin:greedy --map pillars -o replay.json
output
      mybot.wasm raids builtin:greedy   0 stars  47.3% 96 rounds
  builtin:greedy raids mybot.wasm       0 stars  15.7% 43 rounds
winner: mybot.wasm  state b67b1690802ed2ed
  log: draft mybot.wasm: gold left: 2
replay: replay.json

Both raids happen at once: the first line is your attack, the second is your defense. Here neither side earned a star, so the higher destruction won. Try other maps with --map and other seeds with --seed. When you have two versions, clashcode sprt new.wasm old.wasm tells you whether the new one is really better. The CLI reference has every command.

06Watch the replay

Open the replay viewer and drop replay.json on it, or click to pick the file. Nothing is uploaded: the file is read in your browser. Matches played on the site open in the same viewer from their match page.

Click a troop, a tower or the commander to see its health, cooldowns, bytecode use, indicator string and everything it printed. Keys:

Viewer keys
KeyDoes
Space or KPlay or pause
Left RightOne round back or forward
Up DownTen rounds
Home EndFirst or last round
+ -Speed
V3D or flat view
FFit the map
1 2 BShow raid 1, raid 2 or both
hold TabScoreboard
Ctrl + FSearch the logs

07Upload

You need an account and a team. Register, then create a team on your dashboard or join one with an invite code from a teammate.

On the dashboard, upload the .wasm file (up to 2 MiB) with an optional label. The server checks it: it loads the module and plays one short match. Status goes from queued to validating to ok, or to rejected with the reason.

Your first upload that passes becomes the team's active bot by itself. Later uploads wait until you press Make active, so you can test a new version before it plays ranked games.

08Test matches and scrimmages

Neither changes your rating.

  • Test matches pit your bot against a house bot, or against your own team so you can play a new upload against the active one. Only your team sees them.
  • Scrimmages are requests to another team. They play once the other team accepts; house teams accept at once. Both teams see the result.

The six house bots are examplebot, fortress, skyrush, swarm, siege and arcane: fortress hides behind walls, skyrush attacks from the air, swarm sends many cheap troops, siege shells towers with catapults, arcane leans on mages and spells, and examplebot mixes a bit of each. Beat all six before you count on a ranking. Every match opens in the viewer.

09The ladder

While ranked play is on, the server runs ladder rounds that play the teams' active bots against each other. Ranked matches are public. Ratings use Glicko: every team starts at 1500 with a deviation of 350, which shrinks as you play (to 30 at least), so early results move you a lot and later ones less.

The leaderboard shows the standings and when the next ladder round runs. Upload often: only your active bot plays, and you can switch it at any time.

10Next