Tiny Adventure
A seeded tabletop campaign: a Go server owns every rule, a Three.js client in web/ renders it. API in docs/api.md, harness in docs/verification.md, player-facing rules in README.md.
Layout
cmd/server: flags and boot.internal/model: wire and state types only. No logic beyond tiny helpers.internal/rng: the one RNG (math/rand/v2PCG),Sub(seed, tag)streams,Pick,Shuffled,Between, six-digitNewSeed.internal/world: hex math, noise, terrain bytes, pathfinding.internal/gen: builds aWorldfrom a seed: terrain, factions, POIs, spawns, bands, loot, landmarks, missions, party, encounters.internal/sim: game rules that are pure functions: classes, roles, ability pools and growth (classes.go), the ability catalog andDraw(abilities.go), items (BuildItem,RollItem), traits, guards andEdgeOf, the battle loop (combat.go), damage and healing (damage.go), one-turn effects (effects.go), targeting and ability choice (choice.go),Forecastodds, XP.internal/server: HTTP and the stateful game: move, bands, hazards, landmarks, clock and camping, shops, threat view, fights.actions.gois the one switch every POST goes through,store.gothe per-game action logs and replay,server.goplayers, seats and routes,limit.gorate limits,feedback.goits gate,run.goandcard.gothe share page and PNG card (fonts ininternal/server/fonts, lining numerals frozen in).web/js: one concern per file.main.jswires the flow.kit.jsis the canvas-texture UI layer,frames.jsits widgets,text.jsfonts and text,theme.jscolour roles,layout.jswidget rects. Board and art:board.js,flora.js,props.js,figures.js,minis.js,beasts.js,sky.js. Feedback:combat.jsplays the server log one turn at a time,levelup.jscelebrates level gains above the hero cards,route.jsdraws the/api/pathpreview,playback.jsapplies one combat event to shown hp (shared with the harness),abilities.jsnames an ability from its id,medallions.jsrenders each hero's mini into its card.life.jsis wind, banners, smoke, fireflies and birds.feedback.jsis the feedback form.screens.jsthe title and end cards.deploy: the systemd unit and Caddy block for tiny-adventure.xonecas.io. Steps indocs/deploy.md.scripts: the harness.serve.shstarts a server,driver.mjsdrives the browser,bot.mjsis the careful player policy shared by verify and playthrough,fights.mjsreplays fight logs throughweb/js/playback.jsand checks them against the server,layout.mjschecks rects.
Commands
- Play:
go run ./cmd/server --seed 7, then open http://localhost:8080. - Check:
go vet ./... && go test ./.... - Harness:
scripts/verify.sh <outdir> [seed],scripts/playthrough.sh <outdir> <seed>.AGENT_BROWSER_HEADED=0keeps the browser off the desktop. Use it when the user is at the machine. - Frame time: open the game in a normal GPU browser and read
__game.perf(). The harness uses SwiftShader, so its frame rate means nothing.
Rules
- No code comments.
- The server decides; the client renders. Odds, wounds, edge, clock, shop stock and every rule live in Go. The client may format and aggregate for display, never re-derive a rule.
- One generator per thing: classes, items and abilities live in
sim, worlds ingen, randomness inrng. Do not add a second. - All game UI is drawn on canvas textures through
kit.jsandframes.js: HUD, panels, buttons, menus, title and end screens, floating numbers. The only DOM elements are the canvas and the#fatalfallback. - Text goes through
drawTextwith a box heighth: it centres the cap height in the box. Never place text with magic offsets. MedievalSharp (display: true) is for titles, headings, place labels and odds words only; Alegreya with lining numerals is the body. Fonts are vendored inweb/fontsand load before the first draw. - Colours come from roles in
theme.js: a grey ramp, one amber accent for state and the primary action, red only for danger. Radius at most 4. No gradients. - The one exception to canvas-only UI is the hidden
textareainfeedback.js. It takes the typing, including paste, IME and mobile keyboards, and the form is drawn on canvas. Add no other DOM. - A game is its seed plus its action log. Every rule must give the same result when the log is replayed: no wall clock, no
math/randoutsiderng, no map iteration order in rules. The action's own time isg.now. - Bump
model.Versionin any change that alters what a seed generates or how an action resolves. Saved boards from another version, and any log that fails to replay, give the player a fresh campaign. The old log stays on disk. window.__game(web/js/debug.js) must keep working:mode,busy,state(),rects()viasetRects,tileScreen,focusTile,pickAt,perf(). The harness reads layout only fromrects().- Scripts import
web/js/stats.jsandweb/js/hex.js; keep those free of browser APIs. - Generated art: the
openrouterskill can make images when a texture or icon is needed.
Gotchas
- Instanced board meshes start with zero matrices, so their bounding spheres are degenerate. Keep
frustumCulled = falseon them. - Defeat ends the campaign. Any harness setup that fights through the API can end the run; pin the seed and check
phase. - Never kill processes with
pkill -f; it matches the agent's own shell. Find a server by port:ss -ltnpH 'sport = :PORT'. - Seeds above 2^53 lose precision in JS.
rng.NewSeedstays below a million. - Balance is measured with the careful bot over seeds 1 to 20 through the API. Expect about 19 wins in about 12 days.
TestCarefulPlayWinsMostCampaignsis the fast Go guard. - The client walks one hex per
/api/move {steps: 1}so the player can change course. Keeptrack.busytrue for the whole walk; the harness waits on it. - Every request without a player id gets a new board. The harness sends one id per process as
X-Playerfrom node and plants it as thetacookie in the browser (driver.mjs). A script that calls the API without it plays alone. - The client reads each combat event's
kindfrom the server. Never classify an event from the unit's own ability list: gear grants abilities too, and a heal played as damage shows a hero hit by a teammate. - Rate limits skip loopback requests without
X-Forwarded-For. Caddy always sets that header, so public traffic is limited and the harness is not.
Definition of done
"Done" for any change that touches gameplay, rendering or UI requires all of:
scripts/verify.sh <outdir>was run on the final code and its output is attached. Fix every failure or list each one as known and explained.- A human-style review of the captured frames: open the PNGs (and the recording) with the image reader, and write down what looks broken, ugly, clipped, overlapping, unreadable or empty. Say it plainly. Stating "looks fine" without naming what you checked is not a review.
- The interaction log in the report shows the game state changing after inputs (party moved, fight resolved, panel opened, end screen reached).
One screenshot is never evidence that something is done. A screenshot of a broken UI that is called a success is a failed task. See docs/verification.md.