Adaptive Loop — a deterministic microfluidic strategy puzzle. Pure serializable nextState(state,action) owns every committed turn; previews call the same function on a clone. 5 handcrafted scenarios, bounded solver with verified win/lose routes + shared-ownership counterfactual, exact localStorage persistence/replay, accessible SVG interface, Vitest truth/solver/persistence tests, and Playwright black-box browser proof. Scenarios 3 and 4 retuned per SPEC §9 (provably unwinnable as originally specified); proofs and exact changes in docs/scenario-tuning.md. Invariants preserved. See CONTEXT-MANIFEST.md for the disclosure boundary and residual risks. Aggregate verified: tsc --noEmit, vitest (59), vite build, playwright (10).
96 lines
3.8 KiB
Markdown
96 lines
3.8 KiB
Markdown
# Adaptive Loop
|
||
|
||
A calm, deterministic microfluidic strategy puzzle. Rotate three overlapping
|
||
loops to move chamber payloads and re-route nutrient/toxin flow, provoking and
|
||
exploiting the ecosystem's counter-adaptations. Built for the Agentic Labs
|
||
one-prompt challenge.
|
||
|
||
- **Stack:** Vite + TypeScript + Vitest + Playwright. No framework, no engine,
|
||
no downloaded assets. SVG/CSS only.
|
||
- **Determinism:** one pure transition `nextState(state, action)` owns every
|
||
committed turn; previews call the same function on a clone, so preview always
|
||
equals commit. No runtime randomness anywhere.
|
||
|
||
## Install
|
||
|
||
```bash
|
||
npm install
|
||
```
|
||
|
||
Node 20+ recommended (developed on Node 26). Playwright's Chromium browser is
|
||
fetched on first e2e run via `npx playwright install chromium` (already cached on
|
||
the build machine).
|
||
|
||
## Run (development)
|
||
|
||
```bash
|
||
npm run dev # Vite dev server with HMR
|
||
```
|
||
|
||
Open the printed local URL.
|
||
|
||
## Play (production build)
|
||
|
||
```bash
|
||
npm run build # type-check-free bunde into dist/
|
||
npm run preview # serve the production build at http://localhost:4173
|
||
```
|
||
|
||
### How to play
|
||
|
||
- **New Campaign** starts Scenario 1. **Continue** resumes a saved run.
|
||
**Replay Standalone** replays any unlocked scenario with clean baseline traits.
|
||
- Each turn, focus or hover one of the six rotation buttons (Loop A/B/C × CW/CCW)
|
||
to see an exact one-turn **preview** (chamber deltas, flow arrows, predicted
|
||
outcome). Press **Commit rotation** (or Enter on a focused rotation) to play it.
|
||
**Escape** cancels a preview.
|
||
- A rotation moves that loop's six chambers, sets its flow direction, and claims
|
||
its shared slots — changing where nutrient/toxin flow next.
|
||
- Pressures build toward 3, at which point a lineage **adapts** (benefit + cost +
|
||
spillover). Win by meeting the scenario objective before the turn limit or
|
||
ecosystem collapse. After a campaign win you may preserve one adapted trait
|
||
(gift and burden) into the next scenario.
|
||
- **Save & Quit** persists to `localStorage`; closing and reopening the page then
|
||
**Continue** restores the exact state. **Retry** resets the current scenario to
|
||
its campaign-entry inheritance snapshot.
|
||
|
||
### Controls & accessibility
|
||
|
||
Real buttons for every action, visible focus, semantic headings/landmarks,
|
||
screen-reader live region announcing each turn, non-color encodings (glyphs +
|
||
text for species/pressures), keyboard operation, `prefers-reduced-motion` support,
|
||
responsive down to 390 CSS px, and readable at 200% zoom.
|
||
|
||
## Test
|
||
|
||
```bash
|
||
npm run typecheck # tsc --noEmit (strict)
|
||
npm run test # Vitest unit/behavior/solver/persistence (fast, in Node)
|
||
npm run e2e # Playwright black-box browser tests against the build
|
||
npm run verify # typecheck + unit + build + e2e
|
||
```
|
||
|
||
## Project layout
|
||
|
||
```
|
||
src/
|
||
domain/ types, constants, serialize, scenario (state/win), pipeline (nextState), solver
|
||
content/ scenarios.ts — immutable declarative scenarios + win specs
|
||
persistence/ save.ts — versioned localStorage envelope, validation, replay
|
||
presentation/ geometry.ts — interlocking-ring board coordinates
|
||
session.ts campaign/session controller (pure)
|
||
main.ts presentation controller + SVG rendering
|
||
tests/ pipeline.test.ts (truth), solver.test.ts (routes), persistence.test.ts
|
||
tests/fixtures/ solver-results.json — verified win/lose routes + counterfactual evidence
|
||
e2e/ smoke.spec.ts — black-box browser proof
|
||
docs/ scenario-tuning.md, brainstorming-summary.md
|
||
SPEC.md authoritative spec (unchanged)
|
||
CONTEXT-MANIFEST.md disclosure boundary for the one-prompt run
|
||
```
|
||
|
||
## Scenario tuning
|
||
|
||
Two baseline scenarios were provably unwinnable as originally specified and were
|
||
minimally retuned (SPEC §9). See `docs/scenario-tuning.md` for proofs and exact
|
||
changes. All invariants (topology, turn order, caps, trait semantics) preserved.
|