Swarmfront: a real-time strategy game that fits in a phone
Swarmfront is a 3D real-time strategy game built for a thumb first, on a simulation that is deterministic to the tick. Here is one whole match, filmed a frame at a time with two AIs in the seats, and how it was built: determinism before gameplay, an AI that is just another player, a fun pass that got rejected, and the parts that are built but not switched on yet.
Swarmfront is a real-time strategy game that fits in a phone. Each side starts with an HQ, two Harvesters and 400 scrap, and wins by destroying the other HQ. There is one resource, eight units you can train, a handful of structures, four powers, and, once a match gets going, a draft of Titans. You steer swarms with gestures: drag from your selected units in a line and they spread along it, loop around an enemy and they ring it, flick and they go in as a wedge. Below is one whole match, start to finish, with the game's own AI in both seats.
0:44. Gameplay is the real game, played by a script and filmed a frame at a time. No sound: the game makes its own in your browser. Play it, or watch it on the Films channel.
Determinism before gameplay
The plan put the simulation first, before there was anything to play, because the features I wanted most all depend on it. A replay is only a replay if the same commands make the same match. Online play over lockstep is only possible if two browsers stay identical without sending the world back and forth. And both break quietly the first time floating point rounds differently on two engines.
So src/sim has rules a lint step enforces. No Math.random, no Date.now, no native sine or cosine, no for...in. It uses ordinary doubles but only the operations that round the same everywhere (add, subtract, multiply, divide, square root), with sine, cosine and atan2 written out as polynomials. Randomness is a seeded 32-bit generator. The world changes only through step(world, commands), twenty times a second.
The proof is a golden test: 10,000 ticks of 200 units on the default map from one seed, hashed, and the hash has to come out the same in Node, Chromium and WebKit. A pull request that changes the hash has to say why. An early review found that a command carrying negative zero or NaN could split two hashes that should agree, so commands became canonical JSON before they ever reach the sim.
// The only door into the world. Humans, the AI, replays and network peers
// are all just producers of these commands.
const events = step(world, commands); // 20 times a second, deterministic
// A replay is a seed and the command log. 1,080 of 1,080 playbacks of
// 180 recorded matches ended on the recorded tick, with the recorded hash.The AI is just another player
The skirmish AI does not get to reach into the world. It reads its own fog-limited view, keeps its own random numbers, and submits orders through the same bus the touch controls use. There are three personalities (rush, boom and air) at three levels, and a fix for one leak taught a good lesson: entity ids gave away hidden spawns, so a seat that cannot see now gets masked ids.
Because the AI is just a producer of commands, it can sit in either seat. That is how the film was shot. The address asks for the rush AI in the player's seat and the air AI in the other, seed 9, which I picked by playing six seed and personality pairs to the end and keeping the one that finishes in seven minutes with the player's side ahead. The filming script then holds the clock still and moves it one frame at a time, the same way the Tin Road film was made.
A fun pass that got rejected
The balance targets were simple: fewer than 2 percent of AI-against-AI matches still undecided at 25 minutes, and at least 40 percent won by the side that had been behind. The first submission hit both. Review rejected it anyway, because it hit them by construction: from the fifteenth minute every HQ burned three hit points a second, so a stall was impossible no matter how the game played.
The replacement is a drain on the map's Uplinks, plus help for whoever is behind. That help is strength (better fire, faster production) rather than free scrap, because free income only closes the gap on paper. The rejected version left a useful number behind: with overtime turned off entirely, 27.2 percent of matches stalled, because the comeback help was also keeping the losing side alive. Over 1,000 matches the shipped rules come out at 0.2 percent stalled and 53.6 percent comebacks.
Triangles are cheap, pixels on large structures are not.
Titans, checked in pairs
Titans arrived later, in daily batches. Each side bans one and picks two from a grid of nine; six are live, from the Myriad (thirty to sixty Mites fused into one) to the Hive Carrier, an air drone carrier that began as the plan's signature unit. The Hive Carrier went design-first, and its own self-critique changed seven of its rules before a line of code, including keeping its launch range below the Lancer's and the Flak Nest's.
The balance check for Titans is paired: the same seeds played with and without the draft, because "the side with a Titan won" mostly measures who could afford one. In the latest pass a Titan is fielded in 95 percent of matches, the first at about six minutes, and the drafted win rates stay inside the undrafted ones. The side that fields a Hive Carrier wins 52.0 percent of the time, against a target of 45 to 55.
Built, and not switched on yet
Two things are finished in code and waiting on the world. Online play runs on lockstep: a few ticks of input delay, every tick's inputs sent even when empty, a hash checkpoint every twenty ticks, and a report naming the first tick two machines disagree on. A 20-minute soak over a fake network that lost 5,166 of 48,142 messages finished with no desyncs, and 20 of 20 matches through a real relay, forced drops and restarts included, ended with equal hashes. The relay itself, a small Python server, is not deployed yet, so online play does not work on this site today.
The other is an audio modem, in the spirit of ggwave: two phones trading match data as tones. It is capped at 30 percent volume, opens with a headache warning, and moves about 40 bytes a second in a simulated room. No two real phones have been measured yet. One finding made it worth building anyway: 8-bit sequence numbers wrapped and stalled the link for good, so they are 16-bit now.
Why it runs in a frame here
Swarmfront lives in its own repository and keeps its own engine (Three.js over that simulation), its own sound and its own look. The site copies in a static build, records a hash for every file and the commit it came from, and a test fails if the copy drifts. One change is made on the way in, and it is recorded: the game's service worker names its own page instead of its folder, because this site answers a folder address with a redirect, and a browser will not use a redirect to serve a page offline. The game's page frames the build full screen and passes room, replay and seed links through to it. A portfolio census noticed that Swarmfront and The Tin Road each rebuild an engine, a synthesizer and a style. Whether they should share one is still open. Being in the games library and on your Console was not.
What is next
The roadmap has three more Titans (Leviathan, Weaver and Echo), a visual and sound identity pass for all of them, and then a front door: a profile, a main menu, a cold open and a dive into the tutorial. Deploying the relay comes before any of that matters for online play, and the modem needs two real phones in one room. Until then the Films channel has the match above, and the rest of the arcade is one tap away.
Get the next one
An occasional note when something genuinely new ships here — essays, free tools, projects. No schedule, no filler, easy out.
Hiring for an AI implementation role?
I make software work inside real organizations, and now that means AI systems a team can check: the buying, the guardrails, the training and the build. If you are filling a role like that, twenty minutes is the quickest way to see whether we fit.
