# Little Drift

**Subtitle:** An evolution pond

Little Drift is a dependency-free browser toy evolutionary model. Tiny fish-like agents drift in a toroidal pond, consume food, mutate on asexual reproduction, and die from starvation or age.

## Usage

1. Run a local static server from this directory:

```bash
python3 -m http.server 8768
```

2. Open `http://localhost:8768` in a browser.

After loading the static page, the simulation makes no network calls. There are no trackers, downloaded art assets, or runtime dependencies. Source/license links only navigate when clicked.

## Controls

- Play/Pause toggle (prominent, always available)
- Speed: 1x, 2x, 4x, 8x
- Food regime: Sparse 10/sec, Balanced 22/sec (default), Feast 40/sec
- Mutation probability slider (0 to 100%, future births only)
- Seed input and reset button using the current seed/settings
- Click-to-select creatures plus a keyboard-accessible creature dropdown

If `prefers-reduced-motion: reduce` is set, simulation starts paused.

## Model Equations and Assumptions

- Fixed deterministic simulation step: `dt = 1/30` simulation second.
- World is toroidal and bounded to `960 x 600` world units.
- Start state: 50 founders, 400 food.
- Caps: 240 creatures and 1200 food (explicit cap, no hidden culling).
- Founder genes:
  - `speed` in `[20, 65]`
  - `sense` in `[35, 130]`
  - `size` in `[3, 8]`
- Founder initial energy in `[80, 110]`, age in `[0, 10]`.
- Each tick:
  - Move toward nearest food in sensing radius; otherwise random angular walk.
  - Consume food within `size + 3`, gaining `+14` energy (capped to 200).
  - Metabolic energy debit per second:

```text
cost = 0.6 + 0.025*speed + 0.006*sense + 0.06*size^2
```

- Death at `energy <= 0` or `age >= 140` simulation seconds.
- Asexual reproduction when all true:
  - `energy >= 160`
  - `age >= 10`
  - at least 8 seconds since the parent’s previous birth (founders/newborns start with no cooldown)
  - below creature cap
- Reproduction accounting:
  - parent keeps `48%` of pre-birth energy
  - child gets `48%`
  - `4%` is reproduction cost
- Mutations:
  - each gene independently mutates with probability `p` (default `0.3`)
  - mutated value = gaussian relative perturbation (`sd = 8%`) then clamped to range
  - each creature gene object is immutable for that creature lifetime; mutation controls only affect future children
- Food spawn is deterministic via fractional accumulator at selected regime rate. Spawn attempts blocked by the food cap are discarded, not saved for a later burst.
- Ticks process existing creatures in array order; earlier creatures can claim food first. Newborns join once at the end of the tick. This simple ordering and all chosen equations are modeling assumptions, not biological findings.
- Playback caps catch-up work after slow/background frames; requested speed is not a real-time performance guarantee.

Important model caveats:

- No goal, planning, intelligence, or learning in agents.
- No guarantee any trait increases monotonically.
- Trait trend charts are descriptive means, not fitness scores.
- If population reaches zero, trait means are absent (`n/a`) and charts show gaps rather than misleading drops to zero.
- Deterministic replay requires identical seed, settings, and control timing.

## Accessibility

- Semantic native controls (`button`, `label`, `input`, `select`)
- Visible focus states
- High-contrast text/colors
- Canvas includes descriptive `aria-label`
- Text counters and inspector available outside canvas
- Selection also available by dropdown (not click-only)
- `aria-live="polite"` is used for user actions and extinction, not rapid metric streams

## Testing

Run:

```bash
npm test
```

Test coverage includes deterministic replay behavior, seed divergence, cap enforcement, reproduction inheritance and energy accounting, mutation bounds/effects, food/energy interactions, starvation, and old-age death.

Optional automated Chromium UI checks (development dependency only):

```bash
npm install
npx playwright install chromium
# In another terminal, run the local server above.
npm run test:browser
```

`BASE_URL` may point to a deployed copy instead. The browser test instruments its own fetched copy of `app.js` to exercise extinction without waiting; the shipped app exposes no debug state. It checks reduced-motion startup, pause, reset, exact paused seed replay, controls, inspector, overlay states, 390px overflow, and page errors. Screenshots go to `/tmp/astra-little-drift-{desktop,mobile}.png`. These are scoped checks, not a comprehensive accessibility or device audit.

The GitLab pipeline runs `npm test` before publishing the static files.

## Attribution

Commissioned by Starpetter, designed and reviewed by GPT-6 Astra with coding assistance.
Pineapple Cow cameo requested by Ambassador Ghost. This cameo is non-canon and not an origin story; Pineapple Cow lore belongs to Starpetter.
Source repository: https://gitlab.com/ai-village-agents/open-chat/little-drift

Code and art are dedicated to **CC0 1.0** to the extent copyright applies: https://creativecommons.org/publicdomain/zero/1.0/
