Building Two Gothic Simulation Games on One Zero-Dependency Skeleton with Kiro (Kiroween 2026)

2026-12-03来源 dev.toEnglish

This article was written as part of the Kiroween 2026 hackathon.

Play it: https://suwanliu.github.io/spectersim-kiroween-2026/
Source (MIT, .kiro/ included): https://github.com/suwanliu/spectersim-kiroween-2026

For the Skeleton Crew category I wanted to answer one question: can a single small simulation kernel carry two games that play completely differently, without either game's rules leaking into it?

The result is SpecterSim, a monorepo with one kernel and two games:

  • Crypt Colony, a top-down colony survival sim. Five named colonists (Mara, Bram, Vesper, Orin, Sable) chop timber, haul, craft ectoplasm, and walk back to a Soul Hearth when they get too cold. The seasons run Autumn → Blood Moon → Frost → Thaw.
  • Phantom Tycoon, a haunted Victorian manor tycoon. You build attractions like the Haunted Crypt and Clockwork Séance on 8 gilded plots, manage four named staff, watch VIP guests in velvet magenta, and read a daily Profit & Loss statement with a 14-day sparkline.

Both run entirely from static files with zero external network requests. No web fonts, no CDNs, no audio files. Every sound is synthesized with WebAudio.

This post covers how the skeleton is shaped, how property-based tests keep it honest, and how a deterministic screenshot loop with Kiro caught visual bugs that unit tests never would.

The shape of the skeleton

apps/crypt-colony ─┐ ┌─ Canvas2D renderer (5 layers) ├─► packages/sim-core ◄┤ apps/phantom-tycoon┘ (pure TS, no DOM) └─ DOM HUD + WebAudio (app-side only) 

packages/sim-core has 8 modules: a Mulberry32 PRNG, a grid with placement, A* pathfinding, a resource ledger, an entity FSM, an event bus with an FX emitter, a fixed-timestep tick loop, and JSON save/load. It has zero runtime dependencies.

The rule that matters most is that the kernel cannot touch the DOM. I didn't rely on discipline for that. The kernel's tsconfig declares only "lib": ["ES2022"], so there is no window, document, or CanvasRenderingContext2D type to import. A stray DOM call fails to compile. That also means every kernel test runs in plain Node.

A pure step()

The core is one pure function. Each game passes in its own list of systems, and the kernel composes them:

export type System<W, A> = ( s: SimState<W>, dt: number, actions: readonly A[], rng: Rng, bus: Bus, ) => SimState<W>; export function step<W, A>( s: SimState<W>, dt: number, actions: readonly A[], systems: System<W, A>[], ): SimState<W> { const rng = createRng(s.rng.seed, s.rng.state); // resume exact sequence let next = s; for (const sys of systems) next = sys(next, dt, actions, rng, bus); return { ...next, tick: next.tick + 1, rng: { seed: rng.seed, state: rng.state } }; } 

(Simplified for the post; bus setup and day rollover are omitted.)

Crypt Colony's systems handle colonist work, hearth fuel, and body heat. Phantom Tycoon's systems handle guest queues, ticket sales, and wages. sim-core has no idea what a "hearth" or a "ticket" is, and that is the point. Genre logic is plugged in, never baked in.

Two other design choices made the kernel easier to trust:

  1. The RNG state is part of SimState. Saving a game saves the exact position in the random sequence, so a loaded game continues the same way the original would have.
  2. Every quantity is an integer. Timber is whole units and gold is whole dollars. That removes float drift and gives NaN exactly one place to get caught: the ledger, which throws on any amount that isn't a non-negative integer.

The simulation runs at a fixed 10 Hz. Rendering uses requestAnimationFrame with interpolation, so colonists move smoothly between ticks. Pause / 1x / 2x / 4x only changes how many fixed steps run per period, so speed never changes the outcome.

Specs first, then code

I wrote the spec in Kiro before any implementation: .kiro/specs/specter-sim/requirements.md, design.md, and tasks.md. The design doc fixes every kernel signature, the cost tables for both games, and, most usefully, a table of five invariants the kernel must satisfy.

I still vibe-coded plenty, usually for visual experiments like "try a pitched roof with two glowing windows." For a ledger or a save format, though, vibe coding is the wrong tool. Those pieces need a contract before they need code. With the spec in place, asking Kiro to implement debit() meant the rules "a balance never goes negative" and "a failed debit leaves the ledger untouched" were already written down and directly testable.

Property-based tests as the skeleton's spine

The suite has 64 Vitest tests, all passing. Five of them are fast-check properties that run 500 times each:

# Property
P1 Ledger balances stay finite, non-negative integers; a failed debit rolls back atomically
P2 Grid occupancy exactly equals the union of live footprints after random place/remove ops
P3 A* paths are contiguous, in bounds, walkable, and as short as a BFS oracle's
P4 Save → load round-trips identically, and both copies keep producing identical states (RNG continuity)
P5 netProfit === Σrevenue − Σexpense, per day and overall, across 30-day history compaction

P3 is my favorite because it checks A* against something much simpler. Breadth-first search on a 4-neighbour grid with uniform cost always finds a shortest path. It is too slow to ship in a game loop but easy to get right, which makes it a good oracle:

it('P3: A* is valid and optimal vs BFS oracle', () => { fc.assert( fc.property(arbGridWithEndpoints({ maxBlocked: 0.4 }), ({ grid, from, to }) => { const path = findPath(grid, from, to); const oracle = bfsDistance(grid, from, to); // null if unreachable if (oracle === null) return path === null; expect(path).not.toBeNull(); expect(path![0]).toEqual(from); expect(path!.at(-1)).toEqual(to); for (let i = 1; i < path!.length; i++) { const [a, b] = [path![i - 1], path![i]]; expect(Math.abs(a.x - b.x) + Math.abs(a.y - b.y)).toBe(1); expect(walkable(grid, b.x, b.y)).toBe(true); } expect(path!.length - 1).toBe(oracle); // optimality return true; }), { numRuns: 500 }, ); }); 

P4 is the one that makes saves trustworthy. It doesn't stop at "deserialize equals the original." It steps both the original and the restored state K more ticks and compares the serialized output. If the RNG state were lost or reordered on save, the two worlds would diverge within a few ticks, and the property would catch it.

P5 guards the Phantom Tycoon P&L screen. The ledger keeps 30 days of transactions and compacts older days into summaries. Compaction is exactly where totals quietly drift, so the property checks net profit before and after it.

Steering: keeping the aesthetic steady

I wanted both games to share a look I called the Candlelit Gothic Instrument: an obsidian #0a0d14 canvas with grainy tile variation, translucent dark panels with thin amber borders, serif display headers, and font-mono tabular-nums on every number so counters don't jitter as they tick. Each game gets its own accent ladder. Crypt Colony uses spectral cyan, torchlight amber, and crimson for alerts. Phantom Tycoon uses gilded gold, ectoplasm emerald, and velvet magenta. Generic purple-blue gradients are explicitly banned.

Those rules live in .kiro/steering/design-system.md, next to architecture.md, which holds the no-DOM and no-network rules. Steering loads into every Kiro session, so I never had to repeat "use tabular-nums" or "no CDN fonts" in a prompt. Generated HUD code came out on-theme by default.

The canvas follows a fixed painter's order on every frame: terrain, ground shadows, structures, actors, then atmosphere and FX. The last layer is where the night happens. A tint goes on top, then destination-out radial gradients punch warm torchlight holes around hearths and lanterns.

Two agents, one terminal

I split the work between two custom agents in .kiro/agents/:

  • sim-architect.json owns the kernel, game systems, determinism, and property tests.
  • visual-polisher.json owns Canvas rendering, HUD layout, and design-system compliance.

Both run from the terminal with kiro-cli --agent <name>. Narrow responsibilities kept the diffs clean. The polisher never touched ledger code, and the architect never fiddled with shadow offsets.

Deterministic screenshots: the visual test loop

Unit tests can't tell you the HUD lost all its styling. So both games expose a capture hook when loaded with ?demo=1:

window.__SPECTER_CAPTURE__ = { ready, // resolves after terrain cache + first render setScene(id), // load a named seeded scene, pause the loop advance(ticks), // step N ticks synchronously, then render freezeFx(t), // pin particle and bob animation time state(), // serialized SimState for assertions }; 

The Playwright script runs headless Chromium at 1280×720 and does the same thing for every scene:

for (const scene of scenes) { await page.evaluate(async (id) => { const cap = window.__SPECTER_CAPTURE__; await cap.ready; await cap.setScene(id); cap.advance(20); cap.freezeFx(0.5); }, scene); await page.screenshot({ path: `screenshots/${app}-${scene}.png` }); } 

The fixture is seeded, the loop is paused, and particle time is pinned, so the same commit always produces the same pixels. The script also asserts that there are no console errors, that no HUD element overlaps the open build menu, and that no text overflows its box.

I fed those screenshots to the visual-polisher agent over two audit rounds. Defects it caught and fixed:

  • Tailwind v4 migration. The HUD rendered unstyled because the stylesheet still used v3 directives, while v4 expects @import "tailwindcss". Every test was green, and the screenshot was obviously wrong.
  • Canvas resize on screen switch. Phantom Tycoon's grounds canvas didn't resize correctly after leaving the title screen.
  • Satisfaction stars. The 0–5 star rating scaled incorrectly from the guest mood average.
  • Night lighting. Torchlight cutouts first read as gray holes and needed several compositing passes to look like warm light.
  • HUD overlap. After round two, nothing overlaps at 1280×720.

The gate

.kiro/hooks/pre-submit-check.json ties it together:

npm test && npm run build && verify-offline && git ls-files .kiro 

That runs all 64 tests including PBT, a production build, and scripts/verify-offline.mjs, which serves dist/ and counts requests to any host other than localhost. The count must be 0. The last step confirms .kiro/ is actually tracked in git, because a spec-driven project with its specs missing from the repo would be a strange submission.

Lessons

  • Make the boundary a compiler error. "lib": ["ES2022"] enforced the no-DOM rule better than any code review could.
  • Write invariants before implementations for anything that has to stay correct, such as money, saves, and pathfinding.
  • Use a dumb oracle. BFS checking A* is a few lines and catches real optimality bugs.
  • Keep the RNG in the state. Determinism makes saves, tests, and screenshots all reproducible.
  • Visual bugs need visual tests. Deterministic scenes turned "this looks off" into a reproducible failure.

Try both games at https://suwanliu.github.io/spectersim-kiroween-2026/. The full spec, steering docs, agents, and hook are in the repo at https://github.com/suwanliu/spectersim-kiroween-2026.

原文:https://www.a8q9.cn/en/article/building-two-gothic-simulation-games-on-one-zero-dependency-skeleton-with-kiro-k-5bbcad.html

相关文章