How TACG is built: Rust, WASM, and Workers
EngineeringDec 5, 2026Updated Dec 6, 20268 min read
TACG is my browser version of That Arknights Card Game, a fan-made card game for two players. One Rust rules engine, compiled to WebAssembly, runs in the page for matches against the computer and in a Cloudflare Durable Object for online play. It had 1,470+ multiplayer matches as of Dec 5, 2026.
1,470+ multiplayer matches as of Dec 5, 2026
~25 KB to 1.3 KB median data sent per step, per player scripted test match, Oct 18, 2026
20,000 seeded random matches, 0 failed board checks Nov 15, 2026
How this was builtCoding agents wrote the code: Claude Code and OpenAI Codex from the start, and Google Antigravity on recent releases. I direct the architecture, the game rules work, and the releases, and I chose the hosting and the cost limit. Tests, seeded match runs, and reviewer agents that did not write the change check each release. Production releases go out on my go or under standing rules I set for when I am away. The rules and card texts come from the original card game, and the source code is private.
Contents9 sections
01A fan card game, rebuilt for the browser
That Arknights Card Game is an unofficial, fan-made card game for two players, themed around Arknights. The rules and the card texts come from the original game. My part is the browser version: the rules engine, the 3D table, the computer opponent, online play, and the site around it.
Both players draw from one shared deck, 182 cards as of Dec 5, 2026, and a match ends when a player goes from 20 HP to 0. It runs in desktop browsers and needs no account.
From the first commit to open play
- Oct 12, 2026
First commit
The card data came first. Separate agents transcribed the 170 cards of the first card set twice, and the two passes had 0 disagreements.
- Oct 18, 2026
Online play goes live
Six days after the first commit, behind a shared login for testers.
- Oct 19, 2026
Release stages set
Changes since then move through a lab, an offline build, staging, and production.
- Early Nov 2026
Login removed
Anyone can open the site and play.
02One rules engine, compiled once
The rules live in one Rust crate with three dependencies: serde, serde_json, and wasm-bindgen. It compiles to a single WebAssembly file, about 1.29 MB as of Dec 5, 2026, and the build fails if the file reaches 1.5 MB.
In the browser
The page runs the engine for matches against the computer and for replays. The computer opponent is the engine's own bot, at three levels.
On the server
A Durable Object runs the engine for every online match. The page never applies an online move itself.
Both sides load the same file, byte for byte. A rule cannot behave one way against the computer and another way online, because there is only one implementation of it.
The engine is deterministic. A match is a seed, a starting player, and a list of actions, and replaying that list on the same engine gives the same board. That keeps a saved match small, and it means a reported bug can be replayed move by move.
Every engine reports a version: the crate version plus a 64-bit hash of the four data files it loaded (cards, mechanics, rulings, and rules). One changed byte of card text changes the version, and a saved match refuses to load on any version but its own.
03The server runs the rules
Online play is one Cloudflare Worker with two Durable Object classes. A single Lobby object lists open rooms, pairs players, and keeps a usage meter. Each room gets its own Room object, which holds the engine, both WebSockets, the clock, and its own SQLite storage.
- BrowserA player's move
- RoomCheck
- Rules engineApply
- Room SQLiteSave
- Seat 1View patchSeat 2View patch
- Check
- A move is one entry from the list of legal actions the room sent, plus the next step number. The room refuses a wrong step number, a move out of turn, and any action that is not on the list.
- Apply
- The engine applies the move and returns the events it caused. Nothing else changes the board.
- Save
- The step, the engine state, and the next clock alarm are written to the room's SQLite storage in one transaction.
- Send
- Each player gets the step as a patch of their own view of the board, with the events to animate.
The page sends intent and draws what comes back. A socket that sends more than 10 messages in a second, or one message over 50 KiB, is dropped.
A load test on staging on Oct 18, 2026 ran 9 rooms at once, each playing a match and a rematch. A move took 64 ms to round-trip at the median and 105 ms at p95. The usage that one more match adds was priced at under a tenth of a cent.
04Hidden cards, and a seed that got out
An online card game has to keep secrets. Each player receives only their own view of the board. The other hand arrives as a count with no cards in it, and a card revealed by an effect reaches a player only when the engine shows it to that seat.
On Nov 14, 2026 a reviewing agent found a hole. The message that starts a match sent the shuffle seed to both players, in the build under review and in the live game. The engine is deterministic and every browser has a copy of it, so a modified page could have replayed the shuffle and read the deck order and the other hand.
The fix keeps the seed inside the room, which still needs it for the match record. It was committed on Nov 15 and went live on Nov 16, 2026. Before the release, a probe played 60 matches and read all 7,393 messages for the seed or a hidden card. It found none.
There is no spectator mode, so during a match nothing outside the two seats receives a hand. The saved record of a finished match shows both hands when an admin opens it.
05Sending the change, not the whole board
The first online build sent each player their whole view of the board after every step, about 25 KB at the median. On Oct 18, 2026, before the game went live, that became a patch that holds only what changed since the previous step.
Measured over one scripted match in the room tests.
A page that misses a step does not apply the next patch to a stale board. It reconnects with the last step number it drew, and the room answers with the whole view and the events of up to the last 50 steps, so the animation can catch up.
06Restarts, dropped connections, and deploys
A Durable Object can restart at any time, and every deploy restarts it. Each step is saved before it is sent, so a match picks up from its last saved step. On Nov 8, 2026 one live match ran through a production deploy and another through a Durable Object restart five minutes later, and both finished normally.
If the room throws while handling a move, even after the engine has applied it, the room keeps nothing from that input. It rebuilds itself from the last saved step and sends both players the board as it stands. The player whose move was lost is told it was not sent and gets the decision back. The page never resends a move on its own.
A player whose connection drops keeps the seat for 3 minutes. The page retries after 1, 2, 4, and 8 seconds, then every 15 seconds.
One kind of deploy was not covered. On Nov 15, 2026 two testers were mid-match on staging when a deploy changed the rules data. The engine version changed, the saved match refused to load, and both pages landed back on the home screen. The room now reads the saved version before it restores a match. If the version differs, the match ends at once with no winner and this message: "This match ended because the game was updated. It does not count as a win or a loss."
07How the rules are checked
I decide what a change has to pass, and these checks hold the engine and the rooms to it.
- Seeded matches. A runner plays 20,000 matches of random legal moves and checks the board after every action: no card lost or duplicated, every card in a valid zone, no negative HP, and the hand limit at the end of each turn. The run on Nov 15, 2026 covered the rules version released the next day and had 0 failures. 136 matches ended in a draw and 7 hit the 80-turn cap.
- Scripted boards. Each card and ruling has small set-up boards with an expected result, about 2,100 of them for the live card set as of Dec 5, 2026.
- Mutation testing. A tool changes the battle, turn, and damage code on purpose, and the tests have to notice.
- A full local gate before staging. A run on Nov 18, 2026 covered 433 engine tests, 4,070 client tests, and 1,595 server tests in under 8 minutes.
- A fresh reviewer. An agent that did not write the change reviews it and tries to break it. That is how the seed was found.
08Lab, offline build, staging, production
By Nov 10, 2026 the game was past its 60th numbered release round. Since Oct 19, 2026 a change passes three stages before it reaches production. A single clear change skips the lab, and I can skip a stage for an urgent fix.
| Stage | What it is | How a change leaves it |
|---|---|---|
| Lab | Several versions of one idea, built side by side and reviewed by an agent | I play them and pick one, or none |
| Offline build | The full game on my machine, with unit, end-to-end, and browser checks | I play it and approve each change |
| Staging | A private copy of the live setup, behind a login | The release checks pass, and I give the go or a standing rule I set covers it |
Before a production deploy, a banner in the game tells players an update is coming, and after it an agent watches the live logs. The server keeps at least the three newest client builds, plus any build replaced in the last 48 hours, up to a file limit. A page that was open during a deploy keeps loading files from its own build and never gets a mix of old and new code.
09What it does not do
- It runs in desktop browsers only. Phones and tablets are not supported.
- There is no spectator mode and there are no accounts. A seat belongs to a random token kept in the browser.
- A deploy that changes the rules or the engine would still end running online matches with no winner, so those deploys wait until no online room is playing.