Rebuilding the 1987 Empire in Rust and WebAssembly
from a human
Inspired by all I saw with getting Halo running, I had Claude rework a game my dad used to play all of the time. Claude was concerned about licensing issues and we did have a pretty faithful reproduction at first, but, switched up quite a bit when I wanted to put it online
I had Claude rebuild Empire, the turn-based wargame Walter Bright and Mark Baldwin sold through Interstel in 1987, as it looked on an IBM PC in CGA mode. It's Rust compiled to WebAssembly, about 15,000 lines across four crates plus a 345-line JavaScript host, and you can play it at dzoba.github.io/empire. The source is at github.com/dzoba/empire.
Claude wrote all of the code. I picked the version, ruled out patching an emulator, played it, and asked for changes. The commit history covers two days. A lot of the second day went to a licensing problem, and then to finding out how hard it is to write a computer opponent that beats the old one.

Finding the right version
Empire has been rewritten many times since the 1970s, and the versions you find online weren't the one I remembered. What I remembered was four colors: black, white, blue and purple. Claude pulled every archive from classicempire.com (the FTP root turned out to be a Digital Mars compiler mirror, but the HTTP index listed eight zips), looked through the GitHub ports, and matched my four colors to CGA palette 1, which is black, cyan, magenta and white. That narrowed it to the Interstel DOS release. It ran the original in an emulator and showed me the CGA title picture, and that was the one.
I said no to patching or wrapping the emulator. The point was a codebase I could change. So it's a reimplementation, with the emulator used only as a visual reference, and the rules come from the Interstel manual and its README errata. One example: the README says cruisers take 36 turns to build, not the 35 in the manual's table.
Two changes were mine from the start. The copy protection is gone. The original asks you to find word N on line L of page P of a manual nobody has anymore. And the old hardware limits are gone: the original world was fixed at 100 by 60 squares on a 320 by 200 screen, and now the world can be any size and a bigger window shows more of it.
How it's put together
There are four crates. core is the rules engine: map, units, combat, fog of war, standing orders, the computer opponent, the world generator, saves. It does no I/O. app is the interface, drawn into an indexed-color framebuffer. web exposes it to the browser through a plain C ABI, with no wasm-bindgen and no npm. cli runs headless games and renders screenshots.
The engine is driven by one loop. Game::advance runs computer players and standing orders until a person has to decide something, then returns what it's waiting for: a unit needs orders, a city needs production, the next player in a hot-seat game has to come to the screen. The interface answers with a command and calls it again. A game is reproducible from its seed, and a save holds the random generator's state.
Making it readable
The first build was the 320 by 200 picture scaled up, and it was faithful and close to unreadable. The fix was to keep the original layout grid, where every text cell is 4 by 8 and every map square is 8 by 8, but draw it at the screen's real resolution. Text is rasterized from IBM Plex Mono at a size where each character fills exactly one cell, so every screen laid out for the original still fits. Icons are enlarged with Scale2x, which rounds diagonal edges without adding colors. The terrain dithers are drawn as a fine checker at device resolution, closer to how they blurred on a CRT. A full 2880 by 1800 redraw takes about 12 ms.

The original picture is still there, pixel for pixel, under Misc, Display.

One detour: after the readability fix I told Claude I wasn't seeing any difference on localhost. The browser was serving a cached build. The fix was a no-cache dev server, a cache-busting import of the main script, and no-cache fetches for the wasm file.
The licensing problem
When I asked about putting it on GitHub Pages, Claude raised two problems.
The first was the Interstel files: icons, font, title picture and the built-in maps are commercial. That was easy to keep out. The repository ships its own CGA-style icons and font, and an importer converts files from your own copy of the game into a folder git ignores. The published game uses only the built-in art.
The second was the code. Walter Bright later published his own Empire source in D, and every file starts with "You may use this source for personal use only." The first working version's computer opponent was ported from his, and the README described the whole engine as a port and said to ask Digital Mars before distributing builds. I had emailed Digital Mars before and never heard back. So we went it alone: Claude rewrote the computer opponent from scratch and went through the rest of the engine. It also checked the ship names against the original program's strings. Of our 103 names, 18 were on the original's list, so it replaced them. "Wargame of the Century" came off the title card, the credits say the project is not affiliated with the authors or the publisher, and the public repository started from a fresh single-commit history. The old history with the port stays on my machine.
A new computer opponent
The new opponent plans from its own fog-of-war view, not the true map. Each turn it reads that view, splits the known land into continents, and works out how many armies each one can still use: two per neutral city, three per enemy city, one per enemy army, plus scouts for unexplored ground. Spare armies walk to a pickup point and wait for a transport. Fighters get a distance field to the nearest friendly city, so they never fly past the point of no return unless they're sent on purpose. Then units pick targets one at a time by searching outward from where they stand and scoring what they find. It's about 2,100 lines.
There are two skill levels. Expert computes exact combat odds before attacking, escorts loaded transports, sends damaged ships home for repair and remembers where it saw enemy ships. Standard plays a plainer game and carries a hidden 10% efficiency handicap.
To know whether the new one was any good, Claude kept the old ported opponent on a local-only branch and wrote an arena: both play the same random 100 by 60 worlds, every map from both starting positions, up to 400 turns, and if nobody has won by then the one with more cities wins.
The first result was 27.5% for the new Expert over 40 games. Most of the gains after that came from finding bugs, not from new ideas.
The worst one was armies sitting in their home port. The planner would decide a continent had one more army than it needed, and then every army on that continent treated itself as the spare one and waited for a ship instead of exploring. Fixing that took the score to 45% on the same 40 games.
Another: at turn 200 of one game, 37 armies were aboard transports headed for an 11-square island that needed 3. Every transport picked the same landing because none of them counted the others.
Then exploration. At turn 120, 77% of one map was still unexplored to the new opponent, and in another game it knew of no neutral cities while the old one knew of 15. The old opponent builds a lot of fighters and sends some of them out with no way back. Those fighters crash, but they see a lot of the map on the way. So Claude added one-way scouting flights. The first version made things worse in a way that took a while to see: when a scout ran out of places to look, it stopped moving, and fuel only burns when you move, so it hovered forever. In the games Claude inspected, by turn 100 every fighter the new opponent owned was a hovering scout. Once scouts went back to normal duty, scouting was worth about 13 points: 33.8% without it, 46.6% with it, 160 games each.
Several ideas did nothing measurable. Keeping loaded transports away from enemy fighter bases changed nothing. Building twice as many fighters changed nothing. Having cities reconsider their production less often was within the noise. With 160 games one standard error is about 4 points, so a lot of what looked like progress at 40 games was noise.
The final numbers:
| Matchup, 160 games each | Won | Drew | Lost | Score |
|---|---|---|---|---|
| New Expert vs the old ported opponent | 71 | 2 | 87 | 45.0% |
| New Expert vs new Standard | 136 | 0 | 24 | 85.0% |
So the opponent you can play online is about 5 points weaker than the one it replaced. I had asked for a smarter opponent, and against the old one this isn't it. The clearest gap in the data is the air war: by turn 150, across those games, the old opponent's fighters had sunk 81 of the new one's transports and the new one's fighters had sunk 11 of the old one's. Each sunk transport takes up to six armies with it. Tuning stopped there partly because the arena was using all 16 cores of a machine I needed for other things, and I asked Claude to back off. The arena is in the repo, so someone else can pick it up.
Smaller things
Saves were plain JSON in localStorage. They're now deflated, base64 encoded behind a version tag, and stored in IndexedDB, and old saves get moved over on startup. A 100 by 60 game at turn 200 went from 217 KB to 17 KB, and a 200 by 120 game from 545 KB to 30 KB.
Saving turned up a determinism bug. A loaded game is supposed to continue exactly like the original, and a test checks that. With the new opponent it didn't: the two games diverged at turn 98. Each map square keeps a list of the units on it, the list isn't saved, and its order depended on the history of moves. A transport leaving a crowded port takes the first six armies in that list, so after a load it took different armies. The lists are now kept sorted by unit id.
The map now zooms independently of the text size, with the bracket keys. Tab skips to the next unit, and Shift+Space ends the turn, leaving units without orders where they are. It asks first if that would skip more than ten.
The first GitHub Pages deploy failed at the link step. The JavaScript host provides a host_log function, and the Rust side declared it without saying which import module it came from. Rust 1.95 on my machine let that through. The newer stable Rust on GitHub's runner refused to link it. The fix was one #[link(wasm_import_module = "env")] line on the extern block.
The whole thing is 35 commits over two days, with 58 tests.