The simulation core of fruitfly.world — the dish world, the escape circuit, and a slot for a brain.
Zero dependencies. Zero build. Plain ES modules that run in the browser and, unchanged, in Node 22 — the same files the live game at fruitfly.world/play executes in production. This repository is the source of truth for the numbers; the game vendors these files.
| Module | What it holds |
|---|---|
js/sim.js |
The deterministic dish world: seeded RNG (makeRng), the mutation draft (draftCards, draftSeed), the escape assay and the real-vs-swapped wiring check (runExperiment) |
js/dmath.js |
Deterministic math kernels: dsin/dcos/dexp/datan built only from IEEE-pinned operations, because Math.sin/cos/exp/atan differ in the last ulp across CPU architectures (~3%–5.6% of inputs, arm64 vs x64). The sim lane runs on these; render code may keep Math.* |
js/world.js |
The whole autopilot lane as a pure Node module (runLineage): food, predator, drafts, brains, generations — no DOM, no Phaser, byte-faithful to the browser including its cross-generation artifacts. WORLD_VERSION tracks world semantics (currently dish/3) |
js/gf-neuron.js |
The brainstem: a leaky integrate-and-fire Giant Fiber driven by LC4 (angular velocity) and LPLC2 (looming) — the two visual neurons that dominate the real fruit fly's escape command cell |
js/cx-circuit.js |
FFW-CX/0.1 — a 24-neuron spiking circuit with connectome-inspired structure. All randomness is at construction time, which is what makes it examinable |
js/brain.js |
The brain contract: signals in → behavior distribution + confidence out, every decision sealed with a FNV-1a contentHash |
js/brain-circuit.js |
Wraps FFW-CX into the brain contract |
js/brain-local.js |
A free local heuristic brain — the default judgment layer |
js/brain-jev.js |
A System One-compatible judgment brain: pinned model, same-origin proxy, hard-fails on floating aliases |
js/brain-driver.js |
The metronome: steps synchronous brains on a clock, lets async brains fly solo, expires and drops stale answers, flags degradation |
Each .js ships with a sibling .d.ts.
These are not aspirations; they are assertions. npm test (38 tests, Node 22's built-in
runner — no install step) fails if any of them drift:
| Fact | Value | Source |
|---|---|---|
| Real connectivity escapes telegraphed lunges | 100% of 200 (runExperiment(1337)) |
tests/gf-neuron.test.ts |
| Swapped connectivity escapes | 68% of 200 | same wiring check, same seed |
| FFW-CX behavior trace, seed 42 | contentHash = 9fb9e0d0 |
tests/cx-circuit.test.ts |
| FFW-CX hunger assay, bucket 1 | 274 of 300 ticks | tests/cx-circuit.test.ts |
| Mutation draft golden vector | contentHash = 0f4d39c3 |
tests/sim-cards.test.ts |
| Rival genes, seed 1337 | contentHash = e9b1d202 |
tests/sim-cards.test.ts |
| Escape trial seed 12345, real | {escaped: true, lead: 0.1833…} |
tests/gf-neuron.test.ts |
60-case golden baseline vs world.js |
1260/1260 field checks identical (3 brains × 20 seeds × 3 gens, arm64 Chrome vs x64 Node) | tests/world-parity.test.ts + tests/golden/baseline-dish3.json |
The 100/68 pair is a simplified two-channel wiring check, not a control experiment on
the connectome: within this model, real-beats-swapped holds by construction, and the escape
rates are a function of hand-set parameters. (The code identifier stays "shuffled" — the
pinned golden vectors hash it.)
import { makeRng, draftCards, makeGFState, runExperiment } from "./js/sim.js";
runExperiment(1337); // { n: 200, realEscape: 100, shufEscape: 68, ... }
makeRng(42) === makeRng(42); // same seed, same sequence, foreverimport { createCircuitBrain } from "./js/brain-circuit.js";
const brain = createCircuitBrain(42, 100); // seed, interval ms
const record = await brain.decide({ // the whole brain contract
tick: 0,
signals: { food: 0.7, threat: 0.1, light: 0.5, novelty: 0.2 },
energy: 60, timeLeft: 40,
});
// record.behavior, record.confidence, record.distribution, record.contentHashAbove the brainstem, everything is a slot. A brain is anything that fulfills one contract: given four signals (food proximity, threat, light, novelty), energy and a clock, return one behavior (approach / avoid / explore / freeze) and a confidence. The brain chooses; the brainstem jumps — the escape reflex is not pluggable, because that is the biology the project is built around.
- The circuits are connectome-inspired, not simulations of a real fly brain, not FlyWire or MaleCNS runtimes, and not claims about animal behavior.
- One seed is one row of a table, not a theorem.
| Repository | What it holds |
|---|---|
| fruit-fly-world | The full site: game, exam room, missions, Passport contract |
| game | The playable game (Phaser), with this core vendored |
| bench | The reproducible double-run exam harness |
Vulnerabilities are reported privately through the main repository's security policy, not in public issues.
MIT © 2026 Fruit Fly World