A registry-driven choose-your-own-adventure engine (Archipelago: Voyages)
narrativecyoagame-engineregistriessave-migrationsettingseconomy
Archipelago: Voyages (justinahampton.com/fun/experiments/voyages/) is a sailing choose-your-own-adventure built in plain ES modules on top of a procedural island map. Justin's brief for v1 was "designed for extensibility: anticipate more decision complexity, more mission variety, more game controls", and five follow-up versions in two days tested that. The design patterns held up.
World from a seed, forked faithfully
The map comes from the Archipelago wave-function-collapse island generator, forked into a pure module that consumes the same sequence of rand() calls, so a seed yields the same map, names and ports as the original toy. Unplayable seeds (fewer than four ports in one sea) fall through deterministically to seed~1, seed~2. See Deterministic seeds for procedural worlds.
Registries instead of code paths
Content lives in registries: Stats, Conditions, Effects, Scenes, Encounters, MissionTypes, Endings, Actions, later Characters, Upgrades, Goods, News, Arrivals, Tags and Quests. A choice declares:
- requires (shown disabled with the reason) or hideUnless;
- effects, or weighted outcomes (with showOdds, the percentage appears on the button);
- run for custom logic; next for where to go (@continue resumes the scene queue, then the voyage).
The game never touches the DOM; the UI listens through onChange. Upgrades are rule modifiers read through one Game.rule() accessor, so a shipwright refit is data.
Things that made later versions easy
- Recurring characters with memory (a bosun who reacts to choice tags and tells trust-gated yarns, a rival captain, a corsair who remembers you) made the game less repetitive than more random encounters would. Add anti-repetition weighting to encounter draws.
- One settings schema (
FIELDS, plus fields generated from the Encounters registry so a new encounter gets a slider automatically) drives the dialog, validation (clamping plus repair of an instalment schedule, with notes), reset to defaults, built-in presets, saved presets and share codes (VOY1.<base64 of the diff from defaults>). - Versioned saves with migrations (
SAVE_VERSION+MIGRATIONS, and back-filling new default rule keys into old saves). The v1 to v2 migration converted a single debt into instalments paid so far. - Riddles from real geography: quest clues are generated from each seed's actual islands (the unique extreme or only island with a property among reachable islands of at least 8 cells), so they are always solvable by reading the map.
Multi-denomination money
Gold, silver and copper with exchange rates and a moneychanger fee. The canon design: merchants, taverns, wagers and bribes take any coin at par (pay smallest first, change from bigger); the Guild and shipwright take gold coin only; some jobs pay in silver. Represent value internally in the smallest unit. A 20,000-purse fuzz test with odd rates checked the arithmetic is exact.
Engine bugs the bots found
- A
run()returning a number was treated as a scene to jump to; redirect only on a real destination. - "Pay the Guild 0 gold" was enabled with only silver in the purse.
- A voyage to the current cell hung forever; arrive at once.