# Input movies and the tool-assisted player A movie is everything the player did, frame by frame from power-on. The board is deterministic, so replaying a movie reproduces the run exactly, down to every byte of RAM. Movies hold only the DIP switches and control bits (`src/galaga/movie.rs`), never ROM or RAM contents, so they can be shared and committed. ## Format JSON, `"format": "galaga-remix movie 1"`: | Field | What | |---|---| | `dsw_a`, `dsw_b` | MAME's DSWA and DSWB bytes, set before the first frame | | `frames` | length of the run | | `changes` | `[frame, in0, in1]` whenever the pressed-control bits change; the bits of frame f are held while the board runs frame f (`Machine::set_controls` before `run_frame`); active high, bit layout as `machine::CONTROLS` | | `final_ram_crc32` | CRC-32 of video RAM and the three work RAMs after the last frame | | `note` | how it was made and what happens in it | A replay that ends on a different `final_ram_crc32` is not the recorded run. `tests/movie.rs` replays every movie in `movies/` and checks it. ## The tool-assisted player: `galaga-tas` ``` cargo run --release --bin galaga-tas -- --frames 72000 --seed 1 --out movies/tas-seed1.json ``` Free play, 3 lives, easy. The player itself is a heuristic: chase an enemy (often the lowest one in flight), dodge a bomb or an attacker coming down close in line, fire as often as a rocket can be in the air, with random variation in all of it. What makes it good is the search around it: - Every 30 frames it saves a checkpoint (a full board snapshot). - From each checkpoint it tries up to 16 candidate futures of 180 frames (3 s) with different random choices, and keeps the first 30 frames of the first one in which no life is lost. - If no candidate survives even 30 frames, it rewinds to an earlier checkpoint, further back each time the same stretch fails again. A life is lost when the fighter's slot (0x31) enters state 0x08 or the reserve count at 0x9820 drops (a capture); see [ram-map.md](ram-map.md). Nothing else is steered: the score, the stages and the bonus lives are whatever the survival search produces. At the end the whole movie is replayed on a fresh board from power-on and its RAM compared with the searched board's; the tool refuses to write a movie that does not reproduce. `movies/tas-seed1.json` (seed 1, re-recorded 2026-10-02 with legal fire and the MAME-faithful scheduler): 72,000 frames (19 min 48 s), stage 30 reached without losing a life, 115 rewinds. On MAME it stays identical through frame 9,060 (docs/mame-oracle.md). The player fires as fast as a cabinet can: the 51xx counts a press only after two frames down and two up (docs/custom-io.md), so it presses for frames 0-1 of every 4. Movies recorded before 2026-10-02 fired on alternate frames, which the corrected 51xx ignores; all were re-recorded, and again when the board took MAME's scheduler (the same inputs play out differently once shared-RAM races resolve as MAME resolves them). ### The dual fighter: `--dual` ``` cargo run --release --bin galaga-tas -- --dual --mod mods/remix.paths --out movies/tas-remix-dual.json ``` Gets the dual fighter the way a player does, then keeps it. Three phases, read from RAM (docs/ram-map.md, capture and rescue): with no captive, the player stands under diving bosses and spares them, and a capture is the goal; with a captive, it chases the boss that dives with it and shoots it, never firing up at a captive in the formation; with the pair, losing either ship is a loss. A candidate future that reaches the next phase is preferred and committed through that moment. Only explosions and lost phases count as losses here, since a capture costs a reserve ship by design. `movies/tas-remix-dual.json` (seed 1, re-recorded 2026-10-02 with legal fire, re-recorded again with the MAME-faithful scheduler): captured at frame 3960, the pair from frame 4710 to the end, through every challenging stage; stage 37 in 72,000 frames, no other ship lost, 25 rewinds. ## Watching a movie As a video with sound (needs ffmpeg): ``` cargo run --release --bin galaga-movie -- movies/tas-seed1.json --video target/movies/tas-seed1.mp4 [--from F --to F] [--scale 3] [--paths] ``` `--paths` draws each enemy's current flight and each rocket and bomb as a thin line over the arcade picture, in the neon look's colours: the quickest way to see what a path mod does. In the page: `scripts/build-dist.sh` copies `movies/` into `dist/movies/`, and `?movie=movies/tas-seed1.json` replays it once the ROM set is loaded (or drop a movie file on the page). The strip at the top shows the replay clock; **F** cycles 1x, 2x, 4x, 8x, 16x (silent above 1x); pressing any game control takes over from that frame. `node web/check-replay.mjs` replays a movie in headless Chromium at 16x and checks the page's board ends on the movie's `final_ram_crc32`.