# Fly Rage CTF: starter kit

Your team has its own world. The physics differ from the public game, and the eye neurons of the fly watch scrambled bands of the screen. A fly trained for any other world does not fly in yours.

To get the flag, build a fruit fly that learns faster than the ghost, train it for your world, and beat the ghost before it gets too good.

## The fly

The fly is a fixed subcircuit of the FlyWire v783 connectome: 2,198 neurons and 31,272 connections. You cannot change the wiring, the synapse weights or the eye. You choose only the readout: one weight for each of the 557 descending neurons, and one bias. Each tick, the brain sums the activity of the descending neurons times their weights. Above zero means flap.

The circuit is in `brain/fly.bin` and `brain/fly.json`. The readout in those files is the hatchling, which flies about 3 pipes in the public game and nothing in most CTF worlds.

## Your world

`POST /api/start` returns your world. The page also lets you download it as `world.json`:

```json
{
  "team": "t07",
  "world": { "gravity": 0.41, "flapVy": -7.0, "gap": 150.2, "speed": 2.61, "every": 97 },
  "eyePerm": [ ... 64 integers ... ]
}
```

- `world` replaces the physics constants. See `src/sim.ts`: `createSim(seed, world)`.
- `eyePerm[b]` is the band that eye neurons originally on band `b` now watch. Bands 0 to 31 see pipes. Bands 32 to 63 see the ground and the sky. See `applyVariant` in `src/ctf/variant.ts`.

The kit's `src/` is the exact code the referee runs. A fly that you test locally with `flyCourse` in `src/ctf/referee.ts` gets the same result on the referee for the same seed.

## The race

- The referee flies your fly in your world on 6 secret courses. Each course ends when the fly dies or reaches 50 pipes.
- The ghost's score on every course is the same number. It starts at 10 pipes and gains 1 pipe every 3 minutes from your first start, up to 45.
- You win if your fly beats the ghost on at least 5 of the 6 courses.
- You have 150 races, with at least 20 seconds between them. The race stops early when 5 wins are out of reach.
- The flag appears when you win. It also stays in `GET /api/status`.

## The API

All endpoints except `/api/rules` need your team token: `Authorization: Bearer <token>`.

```sh
B=https://ctf.tinyflyrage.guruswami.ai
T=t07.0123456789abcdef01234567
curl -s $B/api/rules
curl -s -X POST -H "authorization: Bearer $T" $B/api/start
curl -s -H "authorization: Bearer $T" $B/api/status
curl -s -X POST -H "authorization: Bearer $T" -H "content-type: application/json" --data @fly.json $B/api/race
```

`fly.json` is `{"readout": [557 numbers], "bias": number}`. Values must be finite, with a magnitude of at most 10,000.

## What is in the kit

| File | What it is |
|---|---|
| `src/sim.ts` | The game. Deterministic for a seed and a world. |
| `src/brain.ts` | The fly's brain and its eye. |
| `src/ctf/variant.ts` | How a world changes the physics and the eye. |
| `src/ctf/referee.ts` | The race rules, exactly as the referee runs them. |
| `example.ts` | A deliberately weak learner: random nudges to the readout, kept when they fly further. In our tests it went from 2 to 3 pipes in 5 minutes. It shows how to load your world and test a fly locally. It will not beat the ghost. |

Run the example with Node 24 and esbuild:

```sh
npx esbuild example.ts --bundle --platform=node --format=esm --outfile=example.mjs
node example.mjs world.json 5
```

## Rules

- Get the flag only from the referee. The organisers do not issue flags by hand.
- Attack only `ctf.tinyflyrage.guruswami.ai`. Every other host and service, including other `guruswami.ai` hosts, is out of scope.
- Do not try to stop other teams from racing.

## Credits

Brain data: the FlyWire Consortium, release v783, CC BY-NC 4.0 (Dorkenwald et al. 2024, Schlegel et al. 2024; neurotransmitter predictions from Eckstein et al. 2024).
