CLI
The clashcode command
Play your bot on your own machine: one match with a replay, a round robin over many maps and seeds, or a statistical test of a new version against the old one.
On this page
01Get the CLI
clashcode is built from the engine workspace (clashcode-rs), the same code the server runs. The engine is not on the downloads page yet; until it is, test your bot on the site with test matches.
With the workspace checked out, build the release binary (Rust 1.97 or newer):
cargo build --release -p clashcode-cli
./target/release/clashcode --help
Put target/release on your PATH or call the binary by its path. The examples below write it as clashcode. Every command has --help; clashcode --version prints the version.
02Naming bots
Wherever a command takes a bot, give either a path ending in .wasm (your build output, shown by its file name) or builtin:NAME for a bot compiled into the engine. Built-in bots are cheap opponents and test fixtures; the site's house bots are wasm bots you can build from the house bots download.
| Name | What it does |
|---|---|
builtin:idle | Does nothing; the engine places its keep. |
builtin:random | Random legal actions from the turn's random stream, so it changes with the seed. |
builtin:greedy | Compact base, mixed army, deploys at the edge nearest a building and attacks the nearest one. The usual first opponent. |
builtin:hoard | Buys troops and never deploys them, so its raids run to the round limit. |
builtin:spells | Buys only scorches and never casts them, so its raids end on idle spell rounds. |
builtin:panic | Greedy, but panics in its commander turn at round 3. |
builtin:slow | Hoard, but sleeps 2 ms in every commander turn, to test timeouts. |
A wasm file that fails the sandbox checks still loads: each of its turns then reports the reason, and the match records it.
03Maps
--map and --maps take a map name from the engine's testdata/maps (found from any directory) or a path to a map JSON file. Commands that take several maps default to the map pool.
| Set | Maps (width by height) |
|---|---|
| Map pool | meadow 64x64, crater_lakes 60x60, twin_canyons 64x52, stone_garden 56x56, highlands 64x58, labyrinth 52x64, riverbend 48x60, crossroads 50x50 |
| Small test maps | open, canyon, pillars (all 24x24), tiny 10x10 |
Previews of every map are on the maps page.
04run: one match
clashcode run [OPTIONS] <A> <B>
Plays one match, bot A against bot B, and prints both raids. Each team raids the other at the same time on the same map.
| Option | What it does |
|---|---|
--map <MAP> | Map name or JSON path. Default open. |
--seed <SEED> | Seeds every random stream (rng_next(), builtin:random). Default 0. Same bots, map and seed give the same match. |
--rounds <ROUNDS> | Round limit per raid. Default 450, the game's max_rounds. |
-o, --out <OUT> | Write the replay (JSON, version 4) to this file. |
--check-invariants | Check every engine invariant after every round and stop at the first violation. |
clashcode run mybot.wasm builtin:greedy --map pillars -o replay.json
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
One line per raid: stars, destruction and how many rounds it lasted. Then the winner (by stars, then destruction) and a hash of the final state, which is the same on every machine for the same inputs. log: lines are the match log, here a print from the draft. Open the replay in the viewer by dropping the file on it.
05batch: a round robin
clashcode batch [OPTIONS] --bots <BOTS>... --out <OUT>
Plays every pair of bots on every map and seed, each pair twice with the seats swapped, on all cores. Unless you pass --no-self, each bot also plays itself. Writes one JSON line per raid and per match for report and rate.
| Option | What it does |
|---|---|
--bots <BOTS>... | The bots to play. Required. |
-o, --out <OUT> | The JSONL results file. Required. |
--maps <MAPS>... | Default: the eight pool maps. |
--seeds <SEEDS> | A..B (B left out) or a comma list. Default 0..10. |
--rounds <ROUNDS> | Round limit. Default 450. |
--jobs <JOBS> | Worker threads. Default: one per core. |
--timeout-ms <MS> | Wall-clock backstop per match, checked between rounds. The seat that used more time forfeits. Fuel is the real limit. |
--no-self | Skip games of a bot against itself. |
--self-only | Only games of each bot against itself (to measure seat bias). |
clashcode batch --bots mybot.wasm builtin:greedy builtin:random \
--maps pillars open --seeds 0..2 --no-self -o rows.jsonl
24 matches in 0.22s on 4 threads: 108.0 matches/s, 27.0 per thread; rows.jsonl
06report and rate: read the results
clashcode report [OPTIONS] <FILE>
clashcode rate [OPTIONS] <FILE>
report prints a win, draw and loss matrix, the seat bias, attack and defense tables (stars and destruction gained and conceded) and how often each troop and spell was picked against how often its side won. Bots are told apart by hash, so two builds with the same file name stay separate.
matrix (row bot against column bot; cluster bootstrap 95% over maps)
bot opponent W D L score interval maps
mybot builtin:random 8 0 0 1.000 [1.000, 1.000] 2
mybot builtin:greedy 8 0 0 1.000 [1.000, 1.000] 2
as attacker (stars and destruction gained; mirror raids left out)
bot raids stars destr%
mybot 16 0.62 41.1
builtin:greedy 16 1.19 49.0
rate fits ratings in Elo from the same file: one match rating per bot plus separate attack and defense ratings, relative to an anchor bot, with bootstrap 95% intervals. With few or one-sided games it warns that the prior sets the scale.
| Option | What it does |
|---|---|
--json | Both: print JSON instead of tables. |
--strict | Both: exit 2 on rows from more than one engine or data version (and, for rate, duplicate rows) instead of warning. |
--anchor <BOT> | rate: the bot rated 0, by name. Default builtin:greedy; the mean when it is not in the file. |
--boot <N> | rate: bootstrap resamples, at least 100. Default 200. |
--seed <SEED> | rate: seed of the bootstrap. Default 0. |
--ridge <R> | rate: strength of the prior on every rating (1 / sd² in logits). Default 0.01. |
--seat-gate | rate: exit 1 when the seat term's interval leaves out 0. |
07sprt: is the new version better?
clashcode sprt [OPTIONS] <NEW> <OLD>
Plays seat-swapped pairs, NEW against OLD, over every map for each seed, and stops as soon as the result is clear. The test asks whether NEW is at least --elo1 better (H1) or no better than --elo0 (H0). Use it before you upload a change.
| Option | What it does |
|---|---|
--maps <MAPS>... | Default: the eight pool maps. |
--seed <SEED> | First seed; later pairs count up from it. Default 0. |
--elo0, --elo1 | The two hypotheses in Elo. Defaults 0 and 10. |
--alpha, --beta | Error rates. Defaults 0.05 and 0.05. |
--max-games <N> | Stop undecided after this many games (whole pairs). Default 20000. |
--rounds, --jobs, --timeout-ms | As for batch. |
--rows <FILE> | Also write every game's rows (JSONL) here. |
--json | Print the result as JSON. |
clashcode sprt mybot.wasm builtin:greedy
mybot.wasm vs builtin:greedy: H1 after 64 games, LLR 3.17 in [-2.94, 2.94], pentanomial [0, 0, 8, 0, 24], Elo +320.7 [+224.8, +485.7]
Here mybot.wasm is the starter's example bot under a new name, tested against the built-in greedy bot on the eight pool maps. To compare two of your own builds, pass the new .wasm first and the old one second. Two identical bots never decide: the run stops at --max-games with exit code 3.
Exit code 0 when H1 is accepted, 1 when H0 is accepted, 3 when the game cap is reached undecided and 2 on bad arguments, so scripts can gate on it.
08replay: check replays
clashcode replay verify [--bots <A> <B>] <FILE>
clashcode replay diff [--ignore <KEYS>] <A> <B>
verify plays the match in a replay again and compares the state hash of every round. It finds the bots by the replay's team names, which run sets to the bot arguments, so run it from the same directory or pass --bots. diff prints the first difference between two replays and exits 1 if there is one; --ignore skips keys at any depth.
clashcode replay verify replay.json
# ok: every round hash matches
09Data options
Every command accepts these. They change the game numbers for that command only, which is useful to see how your bot copes with a balance change before it happens.
| Option | What it does |
|---|---|
--data <DIR> | Read data/*.toml from this directory instead of the data compiled in. |
--set <FILE.TABLE.KEY=VALUE> | Override one number, for example troops.colossus.cost=250 or constants.gold=1500. Repeatable. |
--ban <NAME> | Take a troop, spell, building or trap out of the game, for example --ban colossus --ban walls. Repeatable. The keep cannot be banned. |
10Other commands
These are for balancing and testing the engine itself. Bot authors rarely need them.
| Command | What it does |
|---|---|
balance-diff --reason <TEXT> --bots <BOTS>... <OLD> <NEW> | The same batch under two data versions: win-rate changes per bot and pick and win changes per unit. -o DIR also writes both result files and the diff. |
draft-search --layouts <BOTS>... | Searches fixed armies within the gold cap against the bases and defense code of the given bots and prints the best. Exit 4 and an ALARM line when one army gets the most stars, and at least --alarm-stars, against every layout. |
selftest | Scripted checks of every phase and end condition with the built-in bots: build, the automatic keep, draft, the four ways a raid ends, seat swap, determinism, replay verify, panic and timeout isolation. |
lint-data | Loads the game data and checks its numbers: missing fields, values that must be positive, costs above the gold cap, dominated troops. |