
There’s a card game I love playing with friends and family: simple to learn, but surprisingly hard to put down. I wanted to play it with people who weren’t sitting at my table, so in 2022 I started building it. Then I stopped. Three and a half years later I picked it back up, and within days it turned into something I’m genuinely proud of: Strato, a free web game you can play against bots, pass around one phone, or play online with friends, with no account and no server.
This is the story of how it got here, including the part where the thing I was proudest of in 2022 turned out to be exactly what I had to replace.
The game in sixty seconds
If you’ve never played, here’s all you need for the rest of this post:
- Everyone gets twelve cards face down in a 3×4 grid.
- Each round starts with everyone flipping two of their cards, so you know a little about your grid before you play. In the first round, whoever flipped the highest pair goes first; after that, whoever ended the last round does.
- Cards run from −2 to 12. Lower is better.
- On your turn you draw from the deck or take the top of the discard pile. Then you either swap it into your grid, or (if you drew it) discard it and flip one of your hidden cards.
- If you can get three matching cards in a column, then the whole column disappears.
- When someone flips the last card in their grid, everyone else gets one last turn. If the person who went out doesn’t have the lowest score (and scored above zero), their score doubles. Going out early is a gamble.
- The rounds continue until someone reaches 100. Lowest total wins.

That doubling rule bites. In this round Parker went out first with 21, but the Master bot, Nova, finished on 2, so 21 became 42:

Chapter 1 (2022): the game engine, and a shuffle algorithm that felt human
In 2022 I was mostly building frontend and backend web services, and I wanted a side project that broke from the norm. A card game in Rust felt like the perfect fit: lots of rules, lots of state, and a type system that could make illegal moves hard to even express.
The first version had three parts:
strato, the rules engine, as a plain Rust library.- A web client written in Rust too, using Dioxus, which compiles to WebAssembly and runs in the browser. (It’s the same framework I used for Concentric Time that spring.)
- A small Rocket server that would push “something changed” events to everyone in a game.

Shuffling like a person
The part of this initial game engine I’m fondest of is the shuffle. Most code shuffles a deck with one line that calls a library. I wanted mine to feel like a real person shuffling a real deck, because a real shuffle isn’t perfect, and I liked the idea that the game would have that same texture.
So I wrote down what my hands actually do:
- Cut the deck roughly in half. Not exactly in half: somewhere within 10% of the middle.
- Riffle the halves together. Your thumbs don’t alternate perfectly; one to three cards drop from each side at a time.
- Do that a few times. Somewhere between four and seven.
- Then a few random card swaps, until it “feels” right.
Here’s the 2022 code, lightly condensed, with a few comments added for this post. The doc comment and its emoji are original:
/// Mimic human shuffle by splitting (sort of) in half and then zipping together (imperfectly), repeated
/// a loose number of times. Then do some swaps until it feels right. 😄
pub fn shuffle(&mut self) {
let mut rng = rand::thread_rng();
let times_to_shuffle = rng.gen_range(4..=7);
let middle = self.size() / 2;
let max_variance_from_middle = self.size() / 10;
let mut left_hand = self.0.clone();
for _ in 0..times_to_shuffle {
// Cut near, but not exactly at, the middle.
let variance_from_middle = rng.gen_range(0..max_variance_from_middle);
let guess_at_middle = if rng.gen_bool(1.0 / 2.0) {
middle.checked_add(variance_from_middle).unwrap_or(middle)
} else {
middle.checked_sub(variance_from_middle).unwrap_or(middle)
};
let mut right_hand = left_hand.split_off(guess_at_middle);
// Let one to three cards fall from each thumb until both hands are empty.
let mut shuffled: Vec<Card> = Vec::new();
while !(left_hand.is_empty() && right_hand.is_empty()) {
for _ in 0..rng.gen_range(1..4) {
if let Some(card) = left_hand.pop() { shuffled.push(card); }
}
for _ in 0..rng.gen_range(1..4) {
if let Some(card) = right_hand.pop() { shuffled.push(card); }
}
}
left_hand = shuffled;
}
// A few random swaps to finish.
for _ in 0..rng.gen_range(4..12) {
let first = rng.gen_range(0..self.size());
let second = rng.gen_range(0..self.size());
left_hand.swap(first, second);
}
self.0 = left_hand;
}
To see what that does, I ran it on a deck sorted from lowest to highest. Each strip below is all 150 cards, left to right, colored by value:

After one riffle you can still see big runs of the same color, exactly like a real deck after one pass. A few more and it looks thoroughly mixed. (Mathematicians have studied this for real cards: about seven riffles is the magic number for a 52-card deck.)
I loved this code. It’s the kind of thing you can explain to anyone with a deck of cards in their hands.
Then life happened
In spring of 2023 I came back for a burst of work on the rules: turns, scoring, figuring out who goes first, clearing columns. The engine told the outside world what happened through “subscribers”, little callbacks that fired on every event, which the server would forward to the other players.
I knew the engine was still missing some big pieces before anyone could actually play a game on it. My last test from that era was a full scripted game between two players, and it was commented out, with a note halfway through: // TODO: figure out who goes first. Finishing those pieces was the next job, but instead the project got put to the side, and it stayed there for three and a half years.
Chapter 2 (2026): a table for friends and bots
When I came back to Strato, I came back with a fresh perspective, and I knew which feature I wanted most: a full game table, whoever’s around. Friends on their own phones, one phone passed around the couch, or bots to mix it up.
That one goal shaped the rebuild. Bots and people had to be interchangeable seats, the rules had to run the same way on every phone, and I didn’t want a game server in the middle.
Rust for the rules, Svelte for the table
The 2022 plan had the whole app in Rust. This time I split it along a different line: the rules are Rust, everything you see and touch is SvelteKit.

The engine is a pure state machine. It has no idea it’s in a browser. It doesn’t read the clock, touch the network, or draw anything. You give it a move; it gives you back what happened.
// Validate on a copy, and only commit if the move was legal.
pub fn apply(&mut self, player: PlayerId, action: Action) -> Result<Vec<Event>, RuleError>
A few design choices that paid off over and over:
- A bad move changes nothing.
applyworks on a clone of the game and only keeps it if the move was legal. There’s no half-applied state to clean up, ever. - Events, not diffs. The engine returns a list like
card_flipped,swapped,column_cleared,round_ended. The app plays sounds and animations straight from that list instead of comparing before-and-after states. - A view that can’t cheat.
view()returns only what players are allowed to see. Face-down cards are just “hidden”. The bots get this same view, so the type system guarantees they can’t peek at the deck. legal_actions(). The engine can list every move that would work right now. Bots choose from it, tests fuzz with it, and the app uses it to highlight what you can tap.
WebAssembly is the bridge. wasm-pack compiles the engine into a 460 KB WebAssembly file (about 120 KB compressed). The wrapper is intentionally boring: every call takes JSON and returns JSON. On the TypeScript side there’s a thin typed layer, and one firm rule for the codebase: the web app never re-implements a game rule. If the UI wants to know something, it asks the engine.
The app is a static site. SvelteKit builds it to plain files that GitHub Pages serves. It’s also an installable app (a PWA): a service worker caches everything, including the engine, so once you’ve opened Strato it works offline (so you can play it on your next flight!). On phones that support haptics, like Android, you’ll feel a little buzz when you flip, clear a column, or win.
The other rule I held myself to: no scrolling, on any screen. A card table should fit the device you’re holding, from a small 360×640 phone through foldables to a laptop. On phones the other players shrink to avatars you can tap to peek at; on wider screens everyone’s grid is laid out across the top.

Bot players
Strato has three bot difficulties to choose from: Novice, Intermediate, and Master. The bots were the first thing I built on top of the new engine. To the engine, a bot is just another seat. It gets the same view() a person gets, chooses from the same legal_actions(), and its move goes through the same apply(). So a bot can sit anywhere: fill out a table when you’re playing alone, play alongside friends sharing one phone, or take over an online seat when someone drops out.
The levels differ in how carefully they play. Novice makes plenty of mistakes on purpose, Intermediate makes a few, and Master makes none: it plays the best move it can find, every time. I’ll get into how they actually decide on a move, and how I made them tougher, later on.
Chapter 3: the feature that required sacrificing my favorite code 😓
With people and bots sharing a table, the next feature I wanted was a daily deal like Wordle, but for cards. Everyone in the world gets the exact same cards each day, plays one round against the same two bots, and compares scores.
There’s no server in this picture: Strato is a static website. So every phone or computer has to get the same shuffled cards and starting grid on its own, with no external communication.
My lovely human shuffle couldn’t do that.
The problem is the first line of that 2022 code: rand::thread_rng(). That asks the device for fresh randomness every time. My phone and your phone would shuffle differently, every single time. That’s what you want from a shuffle, until you want two phones to agree.
Seeds, explained without the math
The fix is a seeded random number generator. A seed is a number you start from, and from that number a generator produces a long sequence that looks random but is completely determined by the seed. If you provide the same seed, then you get the same sequence, every time, on every device.
Think of it like a recipe. “Shuffle randomly” is a cook improvising. “Shuffle with seed 1682863344” is a recipe card: anyone who follows it ends up with exactly the same dish.
So the daily deal works like this:
- Take today’s date, like
2026-12-04. - Turn it into a number with a hash function (FNV-1a, a tiny one that’s easy to write in a few lines).
- Use that number to seed the shuffle.
export function dailySeed(date: string): number {
let h = 0x811c9dc5;
for (const ch of `strato-daily-${date}`) {
h ^= ch.charCodeAt(0);
h = Math.imul(h, 0x01000193);
}
return h >>> 0;
}

Why I didn’t just seed the human shuffle
I could have kept the riffle and fed it a seeded generator. But the shuffle was now load-bearing in a way it never was before:
- It has to be fair, provably. If one seat got slightly better cards on average, a daily leaderboard would quietly reward whoever sat there. A human-style riffle is meant to be imperfect; a small number of riffles leaves patterns behind.
- It has to be boring to reason about. Every other feature I had in mind (saves, replays, online play) was going to lean on “same seed, same game”. I wanted the shuffle to be the last thing I’d ever have to doubt.
So the engine now uses the textbook approach: a Fisher–Yates shuffle over all 150 cards, driven by a seeded ChaCha8 generator. Fisher–Yates gives every possible order of the deck exactly the same chance. To check the deal, there’s a test that deals 20,000 four-player games and checks that every seat averages the expected grid total (60.8) and the expected number of cards at zero or below (2.4).
The best part: the human shuffle didn’t really die. It became an animation. When a round starts, you see the deck cut in two and riffle back together before the cards fly out. The math is Fisher–Yates; the feeling is still my 2022 shuffle.

One decision, many features
Making the whole game reproducible turned out to be the most important decision in the project. The engine’s entire state, including the random generator itself, is one value that can be saved and loaded. A seed plus a list of moves rebuilds a game exactly.
That one property ended up powering:
| Feature | Why determinism makes it easy |
|---|---|
| Daily deal | Same date → same seed → same cards for everyone |
| Saving | The game saves itself after every move; close the tab and come back |
| Online play | Phones only send moves, not the game, and stay in sync |
| Replays | Re-run the moves to rebuild any moment of any game |
| Bot testing | Thousands of seeded matches that replay identically when a test fails |
Chapter 4: online play with no game server
I didn’t want to run a server. Servers cost money, need accounts, and eventually get turned off. I wanted Strato to keep working long after I stop paying attention to it. So online play is peer-to-peer: the phones talk directly to each other.

Finding each other
Two phones on the internet can’t just find each other. They need an introduction. Strato uses Trystero, which borrows public Nostr relays as a meeting point. Your phone posts a sealed note that says, roughly, “I’m in room KMTZ”. Another phone looking for KMTZ finds it, and the two set up a direct, encrypted WebRTC connection. After that, the relays are out of the picture.
From the player’s side, it’s a four-letter code (no look-alike letters like O and 0), a QR code, or an invite link.

Who’s in charge
One phone is the host. It runs the real game. Guests send their moves to the host, the host checks them with the engine, and then tells everyone what happened.
Here’s the bit I like most. Because the engine is deterministic, the host doesn’t need to send the whole game after every move. Every guest keeps its own copy of the engine and replays each move itself. The host only sends a tiny message, about 100 bytes: a running number, the move, and a checksum of what the game should look like afterwards.
(A quick sidenote: a checksum is a short number worked out from a bigger piece of data, a bit like a fingerprint. Change even one card and the number comes out different, so two phones can compare checksums instead of comparing the whole game.)
If a guest notices a gap in the numbers, or its checksum doesn’t match, it simply asks for the whole game again. Messages stay tiny no matter how long the game runs, and every phone always has a complete copy.
When people leave
Sometimes people’s phones lock, apps get closed, or your Wi-Fi signal is lost. An online game such as this has to survive that.
- A guest leaves: their seat shows away. If the game is waiting on them, the host can tap “Bot takes over”. The bot keeps their cards and score, and hands the seat back the moment they rejoin.
- The host leaves: guests wait ten seconds in case it was just a reload. Then the next person in seat order gets their copy of the game promoted to the host engine, and they become the new host. Nothing is rolled back, because everyone already had the whole game.
- The old host comes back: it notices someone newer is in charge, steps down, and takes its seat back.
Using cryptography to prove who’s who
No accounts means no passwords, so how does the host know a move really came from Jess?
Each device makes its own key pair the first time it opens Strato. The private key never leaves the phone. When a guest joins, the host sends it a one-time challenge; the guest signs it, and that signature proves which seat it owns. The host decides whose move it is from that proof, never from what the message claims.
You’ve probably used this exact idea without realizing it. Passkeys, the “sign in with Face ID or your fingerprint” option a lot of apps and websites now offer, work the same way: your phone makes a key pair for that site, keeps the private key to itself, and proves it’s you by signing a challenge. No password ever gets sent. Strato does the same thing, just without a sign-in screen.
Some trade-offs
- Because any phone might need to take over, every phone holds the whole game, deck order and chat history included. A determined friend with developer tools could peek at the next card. With a central game server, hidden cards could stay truly hidden, since only the server would ever know what’s in the deck and under each face-down card, but among friends it’s a trade-off I’m happy with.
- Some strict networks (often mobile data) block direct connections, and there’s no relay server to fall back on.
Chapter 5: the features that came after initial launch
Once Strato was in friends’ hands, the to-do list stopped coming from me.
”The bots are too easy”
Players told me the bots weren’t hard enough: the Master bot just wasn’t a master.
To explain how I made them harder, I need to confess how they work: the bots aren’t actually smart. There’s no machine learning and no searching ahead through future turns. Every bot follows the same handful of rules of thumb. For each card it could swap or flip, it adds up what its grid is expected to be worth afterward, counting every face-down card as an average card from the deck, and picks the move that lowers that number the most. Only Master tracks which cards have already been played (more on that below), and only Intermediate and Master chase matching columns.
What separates the levels is mostly a dice roll. Before every decision, the bot rolls to see whether it’ll ignore its strategy and pick a random legal move instead:
// Simplified from strato/src/bot.rs
let options = legal_moves(view, me);
if rng.gen_bool(difficulty.blunder_rate()) { // 0.25, 0.07, or 0.0
return options.choose(rng); // any legal move, good or bad
}
Brain::new(view, me, difficulty).choose(&options)
A random move might be a sensible one, or it might be swapping out a lovely −2 for the 12 it just drew. Novice blunders on a quarter of its decisions, Intermediate on 7%, and Master never does. A turn is usually two decisions (draw or take, then where to put the card), so close to half of Novice’s turns have a blunder in them. That’s what makes it feel like a beginner rather than a machine: mostly reasonable play, with the occasional move that leaves you wondering what it was thinking.
Before changing anything, I wanted a way to measure “harder”. So I froze a copy of the original bots and used it as a yardstick: put a bot at a three-seat table against two copies of the old Master, play 3,000 matches, and count points per round. Lower is better.
Then I made the bots smarter:
- Master now counts cards. It knows which cards are still unseen, so it can weigh a sure card on the discard pile against the expected value of drawing from the deck.
- Master estimates its odds of being doubled before going out, accounting for how many hidden cards its rivals still have.
- Intermediate half-listens to that doubling risk, and Novice makes fewer random blunders (one in four decisions instead of one in three).

The new Master scores 22% fewer points per round and wins 56% of matches at a table where a fair share is 33%. That yardstick lives in the test suite now, so if a future change ever makes a bot weaker, the build fails.
Table talk (AKA chat)
After one online game with family members where we weren’t also on a phone call, it was obvious what was missing. The best part of playing cards in person is the groaning when someone flips a 12, and the game was silent.
So I added table talk: a chat plus emoji reactions (😂 😭 😁 😢 😱) that float up from the sender’s avatar on everyone’s screen. Chat pops up for a moment as a speech bubble pointing at whoever said it.


These chat messages travel the same way that moves do: through the host, which knows who’s speaking from their signed seat, applies a rate limit, and cleans up the text. The feed slots each message between the moves it came after, so you can scroll back and see that someone said “nooo” right after they got doubled.
Replays
Then there were the moments worth keeping. Something wild would happen mid-game and I’d want a screenshot of it, or just to remember how it went, but there was never time to stop playing and grab one. By the end of the game, the details were gone.
So now every finished game can be watched back like a video, with a seek bar split into rounds, play and pause, step forward and back, and 1×, 2×, and 4× speed. Drag the bar and the table jumps to that moment, with a label showing the round and whose move it was:

The results screen shows how everyone’s totals moved round by round, right above the Watch replay button.


Under the hood, the engine keeps a compact log of every accepted move. Each move is a few characters: 2s13 means seat 2 swapped into row 1, column 3. To jump to any moment, the replay starts from the nearest checkpoint (one every 32 moves) and re-runs the moves from there, so seeking stays instant. The last ten games are kept on your device.
My favorite detail: the replay is drawn by the same table component as the live game, from your own seat, so it looks exactly like you remember. And table talk replays too: the chat bubbles and reactions pop up at the moment they happened.
Making it feel whole
It would be easy to read this post as a feature list. That’s not how it felt to build. Most of the work was in the small stuff that makes a game feel like one cohesive experience rather than a pile of features:
- The cards move. Cards fly from the deck to your hand and into your grid. Cleared columns float away. The deal riffles before it starts.
- Sound and touch. A two-note chime (and a double buzz, on phones that support it) when it’s your turn, and a horn with a full-width LAST ROUND banner when someone goes out.
- Words matter. The two choices for a drawn card read Keep + swap and Discard + flip, with a slanted “or” between them, so each button is congruent. The prompt always tells you exactly what you can do next: “Draw or take the 6.”
- Small kindnesses. It remembers your name. Other players’ opening flips play quietly so they don’t steal your attention. Nobody, bots included, can move until the deal animation finishes.
- Your history. Stats and win streaks per player, a daily-deal streak, and a Share button for bragging.

None of these show up in a list of features. All of them together are hopefully a reason to keep playing.
What I’d tell 2022 me
- Your favorite code might not survive, and that’s fine. The human shuffle was the right answer to the question I had in 2022. The daily deal asked a different question. And it still lives on, as the animation.
- Make the core deterministic early. Being able to say “a seed plus a list of moves is the whole game context” made saves, online play, replays, and testing dramatically simpler. I’d start there next time.
- Keep the rules in one place. Because the app never re-implements a rule, adding bots, online play, and replays never meant chasing a rule bug in two languages.
- Measure before you tune. “Make the bots harder” became a number I could move, and a test that won’t let it slide back.
- The best features came from playing with people. Stronger bots, table talk, and replays all came from real games where something felt missing.
Play it
Strato is free at strato.parker-codes.dev. Try today’s daily deal and see if you can beat the Master bot. Or grab a few friends, tap Create game, and share the code.
The code is public on GitHub at parker-codes/strato, if you’d like to see how any of it works.
If you love it or have ideas, tag me in a tweet at @parker_codes.