The operator's decision of 2026-09-29, chosen over a pad rule that would have withheld a stat move once used: pay the fly for the HP its own attack removes from the Pokemon it is fighting, so the move that deals damage is worth more than the one that does not. Row 67: the live fly lost the Pewter Gym's Jr. Trainer 29 times running with TAIL WHIP 155, BUBBLE 23, TACKLE 0, and nothing in the catalog paid for anything inside a battle it did not win. `damage`, the twelfth kind, 80 ms. 0.20 per whole enemy Pokemon's max HP, paid in proportion on the sample the HP drops; +0.05 when the fly's hit knocks out a trainer's Pokemon; at most 0.50 a battle (the trainer rule's own value, which two Pokemon reach exactly). A wild battle pays at the wild-KO rule's scale, 1, 1/2, 1/3, for its first three battles per (map, species, level) that paid any damage, then nothing, and a rollback blocks every key that has paid (damageCounts, replay-blocked damage:<key>). Trainer battles keep no lifetime ledger: a trainer is fought again only after losing to it. The fly's attack is a drop in wEnemyMonHP on a sample where hWhoseTurn ($FFF3, counted from the hJoyLast anchor to the end of HRAM) reads 0 and wPlayerMoveNum is not STRUGGLE. ApplyDamageToEnemyPokemon runs in ExecutePlayerMove with it 0; the enemy's poison, burn and Leech Seed ticks (HandlePoisonBurnLeechSeed picks the enemy's HP because it is 1), its recoil, confusion self-hit, Explosion and Substitute all land with it 1. Every drop moves the target's mark, so a tick is never paid later as part of a hit. A target is (wEnemyMonPartyPos, species, level) and keeps its lowest HP for the battle, so a heal is never paid twice and a switch back keeps its mark; it is marked when it first reads full HP, because InitBattleVariables leaves the last battle's wEnemyMon in place -- in the row 67 ring that is the same trainer's Diglett at the HP it won with. v7 -> v8. STATE_VERSION stays 4: damageCounts and battle.damage are optional and absent in a v7 state, which restores with no wild key paid and a battle in flight marked where it stands, so nothing lost before the restore is paid. MIGRATES_FROM is [v7, v6]: the chain composes, since v7's own migration (the item seed) still runs in this build on the first sample without items:seeded. Feed: `damage` has no counter (RewardKind::from_adapter -> None). On `wildwin` the stage would fold every hit into "N wild wins", false of a trainer battle and of one the fly goes on to lose. A hit reaches the page as a reward event with its own label, HIT #<species> FOR <n> HP[ KO]; the feed's closed kind set does not move. The compatibility string differs from main's in exactly one segment: pokered-unique8-v7 -> pokered-unique8-v8. Tests: the rule (fly's turn vs the enemy's, Struggle, heal, switch, twin slots, stale enemy, restored battle, cap, knockout, wild scale, round trip); the adapter (proportional pay, TAIL WHIP nothing, poison then hit, the ring's second battle, wild scale and rollback, one read per address, checkpoint round trip, a v7 state mid-battle); compat_migration (v7 and v6 FLYSIM01 envelopes refused without their own opt-in and restored with it; the v7 one mid-battle pays only what follows); rom_damage (FLY_ROW67_CHECKPOINT: the live v7 string and ledger migrate; from the live state BUBBLE and TACKLE are paid on every drop they cause and TAIL WHIP never, the fly's hits land with hWhoseTurn 0 and the enemy's with 1). |
||
|---|---|---|
| .forgejo/workflows | ||
| .github/workflows | ||
| apps/stage | ||
| data/fafb-v783 | ||
| docs | ||
| infra | ||
| packages | ||
| services | ||
| tools | ||
| .gitignore | ||
| CLAUDE.md | ||
| CONTRIBUTING.md | ||
| LICENSE | ||
| LICENSES.md | ||
| Makefile | ||
| NOTICE | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| ROM-POLICY.md | ||
flybrain
A simulated fruit-fly brain that plays video games. A connectome-constrained spiking network reads the screen, its population rates become controller inputs, and a scalar reward nudges a bounded set of Kenyon-cell to MBON gains.
The library is @flybrain/brain in packages/brain. It holds the connectome dataset format, the
LIF kernel, the plasticity rule, the population-rate readout and the activity-map geometry. It
holds no game, no emulator and no reward rules: those belong to whatever embeds it.
Workspace layout
| Path | Contents |
|---|---|
packages/brain |
the library (@flybrain/brain) |
data/fafb-v783 |
FlyWire-derived browser artifacts (CC BY-NC 4.0) |
tools/ |
the Python builder that regenerates data/ from official Codex exports |
docs/ |
overview, dataset format, model, plasticity, readout, integration, limitations, verification |
services/flysim |
the Rust service: brain, emulator, snapshot feed, control API, checkpoints |
apps/ |
planned: one directory per game demo |
infra/ |
planned: deployment for the 24/7 stream (see docs/streaming-plan.md) |
Quick start
npm ci
npm test
npm run typecheck
76 tests, about 7 seconds. There is no build step. npx tsx packages/brain/examples/node-random-frames.ts 60
runs the full 139,255-neuron brain with the Game Boy readout on noise frames in plain Node
(about 0.9x Game Boy real time single-threaded on a WSL laptop).
Usage
import { NeuralAgent, gameboyDecoderConfig, toButtonMask } from '@flybrain/brain';
import { loadBrainDatasetFromDir } from '@flybrain/brain/node';
const dataset = await loadBrainDatasetFromDir('data/fafb-v783');
const agent = new NeuralAgent(dataset, { decoder: gameboyDecoderConfig() });
agent.warmup(firstFrame); // 2,500 ms with plasticity off, then calibrate
// every emulator frame:
const { active } = agent.tick(framebuffer, { // RGBA 160x144 by default; any size via config
rewards: [{ value: 0.5 }], // scalar rewards your game adapter detected
boot: !inGame, // relaxes Start/Select throttling on title screens
});
emulator.setButtons(toButtonMask(active));
const checkpoint = agent.exportState(); // bit-exact resume, validated on import
The lower layers (LifNetwork, RewardModulatedStdp, PopulationDecoder) are exported too for
hosts that want to run the loop themselves.
integration.md has the full per-frame loop, the fractional frame timing and the checkpoint contract.
Documentation
- Overview: the pipeline, the layer map and the design principles.
- Dataset format: artifacts, CSR layout, weight encoding, every role and its count, fingerprinting, regeneration, license.
- Model: the 1-ms LIF kernel step by step, every default constant, the retina projection, the RNG, state export and version strings.
- Plasticity: edge selection, the eligibility and reinforcement equations, statistics, topology hash and the explicit non-claims.
- Readout: scores, exclusive groups, pulse channels, the blocked-direction cooldown, the Game Boy preset table and checkpoint versions.
- Integration: what a game must provide, the Pokemon Red integration as a worked example, and a sketch of a platformer adapter.
- Limitations: what is not claimed, what is unproven, measured throughput.
- Verification: the oracle-test strategy and what each test file covers.
- Streaming plan: headless capture, Twitch, VM design and the phased plan for a 24/7 stream.
- Artifact builder: how to regenerate and verify
data/fafb-v783. - Data attribution: source, license and citations.
Provenance
The network, plasticity rule, readout, FlyWire pipeline and activity viewer were extracted from
the fly-plays-pokemon prototype so several game demos can share one core. The default
configuration reproduces that prototype's kernel bit for bit, and verbatim copies of its modules
live in packages/brain/tests/legacy/ as oracles. Built with Astra.
Licensing
The data/fafb-v783 artifacts are derived from the FlyWire FAFB public Codex v783 exports and are
licensed CC BY-NC 4.0. That is a
non-commercial license, so a commercial demo needs a different data source or separate permission.
Citations and the list of modifications are in
data/fafb-v783/ATTRIBUTION.md.
No license has been chosen for the code in this repository yet.
ROMs and save states never enter this repository.