Rust for the rules engine, the game server and the web engine
Context and problem
Friends in different houses have to play together, so there has to be a game server, and it has to know the rules: it is the one place that sees every hand. Under 0001 each platform writes its own logic, so the server gets its own copy of the rules, written to the same spec. The repo skeleton (#9) had only Swift and Kotlin cores.
Options considered
- Two platforms only, Swift and Kotlin. The starting point of the skeleton, with no copy of the rules for a server.
- A third copy in Rust, mirrored like the other two, that later backs the game server.
The records name no other server language being compared. The reason given is a personal one as well as a technical one: Rust was a new language for Eduardo, and he wanted to learn it.
Decision
We chose option 2. Rust joined on day 1 as the third mirrored platform (#12, #13):
rust/canasta-rulesholds the rules only, with the same type, case and JSON field names asRuleSet.swiftandRuleSet.kt. Rust’s snake_case files, fields and tests are the one accepted difference from the other platforms.canasta-clispeaks the same CLI protocol as the Swift and Kotlin tools.canasta-server(Axum) runs one task per table on top of the rules crate. Each player receives only their own view; other hands, the stock order and the shuffle seed never leave the server.canasta-wasmwraps the same code for the browser (0004).
Consequences
Good
- One language covers the server, a CLI and the web engine, so the web needed no fourth copy of the rules.
- The server’s game logic is held to the same scenarios and parity vectors as the apps: the same seed deals the same hands on iPhone, Android and the server.
- The rules crate has no file, clock or OS-randomness access, which is what let it compile to WebAssembly without changes.
Bad
- A third copy of every rule, with the cost described in 0001.
- Rust is the language Eduardo knows least, and it is the one that runs on the server, where the sign-in and permission code lives.
- More toolchain to keep in step:
cargo fmtandclippy -D warningsin every gate, awasm-bindgen-clithat must matchCargo.lock, and a Vercel build that installs Rust before it can build the web game (bin/vercel-install-web).
More information
- Rust joins: #13; Rust deal: #18; server spike: #25.
- Diary: Day 1, “Copying Shopify on purpose”; Day 2, “Playing online”.
- The server: docs/server.md; the Vercel build: docs/deploy.md.