โ† Devlog

A bot that plays Ember Colony

By the middle of October, Ember Colony had seasons, a research tree, workshops, and a storyteller that throws traders, sickness and bandit raids at you. What we didn't know was whether you could win it. A few games played by hand don't tell you much, because each one plays out differently. So the last systems slice, F2g, was about measuring: a scripted player, an unattended run, and a stress test, all in one test file that we run in release mode.

Playing through the front door

The bot is a Rust test that drives a normal GameSession, the same thing the native player and the MCP server use. It doesn't edit the world to build things. To place a building it moves the camera over a free lot, enters build mode, converts the lot's world position to a screen position with the real camera, and clicks there. To accept a wanderer or buy food from a trader, it finds the ui button whose label starts with "Accept" or "Buy 15 food" and clicks it. If a placement doesn't produce a blueprint, the bot counts it as a failure, so the run also checks the camera and the build cursor.

Its strategy is a short list of rules, checked every 120 frames (two seconds of game time):

It's not a good player. It's a predictable one, and that's what makes its runs worth comparing.

Who killed the colonists

Knowing that a colony died isn't enough to balance it. We needed to know why. The harness keeps a snapshot of every colonist every ten frames: hunger, warmth, health, whether they're sick, their current state, and their distance to the nearest wolf and bandit. When a colonist disappears, it classifies the death from the last snapshot, checking in order:

CauseRule
Bandita bandit within 2 units
Wolfa wolf within 2 units
Starvationhunger at 100
Coldwarmth at 0
Sicknesssick
Othernone of the above, printed in full so we can look at it

Each in-game day prints one line with the deaths by cause. The answer was obvious after a few seeds: wolves caused about 80% of deaths.

Too many wolves

The reason was one line. From day 2, every nightfall spawned as many wolves as the day number. That's fine in the first week. By day 15, fifteen wolves arrive every night, and nothing the colony can build keeps up. The storyteller's wolf packs and bandit raids also grew without a limit, and its tension, the budget it spends on events, kept building as the colony got richer.

nightfall wolves, before and afterNAL
// before: one more wolf every night
for i in 0..Colony.day { /* spawn a wolf at a map edge */ }

// after: one more every three days, at most six
for i in 0..min(1.0 + floor(Colony.day / 3.0), 6.0) { /* ... */ }

The rest of the pass:

After that, the bot wins on three of five seeds, between days 21 and 26. To win you need the Colonial Charter and 30 colonists. The other two seeds still end without a win. The bot only follows fixed rules, so the next real test is people playing it.

The stress test

The design target is 60 FPS with about 60 colonists and 500 models. The third test builds that world directly (about ten houses, some of each workshop, then trees and props up to roughly 500 models) and measures frame times against the default world.

It pointed straight at the engine. Every frame, the interpreter was making a deep copy of every system, state machine, UI definition and user function before running them, and it copied each function's body again on every call. Nothing changed them, so there was nothing to copy. They're now built once and shared. Frame time dropped by 60% on the default world and by 38% under the stress load, and seeded runs came out exactly the same as before.

With that fixed, the simulation alone (no rendering) averages 2.76 ms a frame in the stress world, 3.72 ms at the 99th percentile, and 0.87 ms in the default world. Rendering got a similar pass a day later, when animated characters went in. Re-uploading geometry for every draw had pushed the stress scene to 35.8 ms a frame. Uploading it once per frame and sharing it between the shadow and lighting passes brought that down to 8.2 ms. We still need to check 60 FPS on a real machine in a release build, and that's on the list for the downloadable builds.

It keeps finding things

The harness has kept earning its place since then. When dawn autosaves went in, the balance loop was the first thing to break: Game.save had nowhere to write in the test, so every run filled up with script errors and stopped. Each session now gets its own temporary save folder. When we added sound, we gave it a fourth test that counts how often each sound effect plays over a long run, to check that no single sound plays more than about once a second on average.

None of this says whether Ember Colony is fun. A bot can tell us that wolves are unfair. It can't tell us whether the first night is tense or just annoying. That's what the human playtest before the alpha is for.