side project
Leer en españolTerraforming Mars guide
An animated, step-by-step guide to the rules of the Terraforming Mars board game. It also has a printable cheat sheet and a guided first generation against three scripted opponents.
What it is
I built this as an animated, step-by-step guide to the rules of the Terraforming Mars board game, with a printable one-page cheat sheet for the table. A walkthrough also lets you play a first generation as the fourth player, against three scripted opponents.
It is an unofficial, fan-made guide, not affiliated with the publisher.
How it's built
An animated, step-by-step guide to the rules of Terraforming Mars, with a printable one-page cheat sheet and a guided first generation where you sit in seat 4 against three scripted opponents. It is plain HTML, CSS and JavaScript, with no build step and no framework. D3 is the only library, and I vendor it. It is an unofficial fan-made guide.
highlights
D3 scenes for the steps that need motion
Each screen that needs motion registers a D3 scene, such as the board with its tiles and the global parameters. The app gives the scene a fresh layer, runs it on entry and on Replay, and stops it when you leave. All timing goes through one helper, so with reduced motion every transition jumps straight to its end state. Every number drawn comes from the rulebook.
A scripted engine where Back is a replay
The walkthrough plays one 4-player generation, one event at a time, on an engine in plain JavaScript with no DOM code. It builds the whole script for the choices you make, says what you may do and why not, and the screen only draws the state at the current event. To go back I don’t undo anything: I rebuild the state from the first event to the one you want. That keeps Back simple and always right, and a choice the rules don’t allow fails before the script is built.
Tests with numbers worked out by hand
The engine has 24 tests on Node’s built-in test runner. The expected values come from the rulebook by hand, not from the engine, so a mistake in the engine can’t hide in the test. They cover production totals, award costs, city and ocean placement rules and the Back replay. I didn’t need a test framework or a bundler.
No build step, and still safe to update offline
There is no bundler: the pages load the vendored D3 and three small scripts. A service worker precaches the guide, the cheat sheet, the walkthrough and their assets, so everything works offline. HTML, JavaScript, CSS and JSON go network first, so a deploy shows up on the next visit, while images and D3 go cache first. It only caches a response whose content type fits the request.
Cache stamping at deploy time
The custom domain forces a four-hour browser cache on JavaScript and CSS, which overrides my headers. So the deploy script exports the committed tree into a temporary folder and replaces the development version markers with the git short hash, in that copy only. It fails if a marker is missing and refuses to run on a dirty tree. Every deploy gets new asset URLs and a new cache name, and the old cache is deleted when the new service worker takes over.
A cheat sheet that prints, and a “Try it” you can break
The cheat sheet is one HTML page with a print stylesheet: three columns, no animation, black on white and small margins, so it fits one sheet for the table. On step 7, “Try it” lets you turn 8 plants into a greenery yourself, with the same D3 helpers as the scenes. It is one self-contained file that switches itself off when you leave the step.
- HTML & CSS
- JavaScript
- D3 v7
- Service worker
- Node test runner
- Cloudflare Pages
- Bash