# Adaptive Loop A calm, deterministic microfluidic strategy puzzle. Rotate three concentric glass rings to align six radial gates, route nutrient inward, grow a microbial ecosystem, and provoke — then exploit — its counter-adaptations. Built for the Agentic Labs one-prompt challenge. - **Stack:** Vite + TypeScript + Vitest + Playwright (the smallest boring stack that satisfies SPEC §14). - **Determinism:** one pure transition `nextState(state, action)` owns every rule; preview and commit call the same function on a cloned state. No runtime randomness, no floating-point simulation — all quantities are capped integers. - **No backend, no engine, no downloaded assets.** All visuals are procedural SVG/CSS. ## Play Open the built game in a browser, or run the dev server: ```sh npm install npm run dev # http://localhost:5173 ``` Or build and preview the production bundle: ```sh npm run build npm run preview # http://localhost:4173 ``` ### Controls - **Mouse/touch:** click a rotation control (Inner/Middle/Outer ⟳/⟲) to **preview** the exact one-turn outcome, then **Commit**. The selection persists until you commit, pick a different rotation, or press **Esc** — Commit never greys out just because the pointer left the control. - **Keyboard:** `1`–`6` select the six rotations, `Enter`/`Space` commits, `Esc` cancels. - **Menu:** New Campaign, Continue (resume exact saved run), Replay Standalone (any unlocked scenario with clean baseline lineages), Save & Quit, Retry, Help/Legend. ### Objective loop Each scenario has a specific win condition (see the objective panel) and the universal loss conditions: **ecosystem collapse** (total producer + grazer = 0) or **turn-limit expiry**. Collapse takes precedence over win, which takes precedence over expiry. Win a scenario to unlock the next and preserve **one** newly-unlocked lineage trait (a gift *and* a cost) for later scenarios. ## Develop & verify ```sh npm run typecheck # tsc --noEmit npm test # vitest unit + behavior + solver/replay + campaign tests npm run e2e # Playwright black-box browser tests against the production build ``` The full aggregate (typecheck + build + unit tests + e2e) is the freeze gate. ### Tests - `test/behavior.test.ts` — literal worked tests for every pipeline phase, both rotation directions on all rings, gate alignment, tangential + radial flow, caps, all four adaptations (benefit/cost/spillover), immutability, canonical determinism, terminal precedence, preview/commit equality, replay. - `test/solver-fixtures.test.ts` — replays the solver-verified winning **and** losing route for each scenario, checks exploit/avoid adaptation routes, and verifies campaign inheritance reachability. - `test/campaign.test.ts` — campaign progression, inheritance carry, retry snapshot, standalone baseline. - `tests/e2e.spec.ts` — black-box browser proof via public controls only. ## Repository layout ``` src/domain/ types, core (canonical/clone/gates), scenarios, transition (nextState), solver src/persistence/ versioned localStorage save/load + validation src/ui/ board geometry, procedural SVG glyphs, render, app (views/controls/preview) test/ vitest suites tests/ Playwright e2e SPEC.md authoritative spec docs/ board-layout + brainstorming context CONTEXT-MANIFEST.md disclosure boundary (prompt, context, versions, session log path) TUNING.md documented §9 scenario-data adjustments ASSETS.md procedural-asset disclosure RECORDING.md deterministic recording route from verified solver actions ``` ## Scenario tuning Three scenarios required minimal SPEC §9 data adjustments to be provably solvable under the deterministic 1-unit/phase flow/migration model; no simulation rules were changed. See [`TUNING.md`](./TUNING.md) for the exact changes, reasons, and preserved invariants. ## Session / submission The authoritative prompt and session-log boundary are recorded in [`CONTEXT-MANIFEST.md`](./CONTEXT-MANIFEST.md). The exact session JSONL is an operator-owned post-exit artifact and is not copied during the run.