//! Challenging-stage proofs: every movie in proofs/ (made by //! `galaga-gallery` from `galaga-tas --dual` movies) replays from power-on to //! its recorded RAM and ends a challenging stage the game calls PERFECT: its //! hit counter at 0x9288 reads 40 and exactly 40 enemies exploded after the //! counter's reset. The second check matters because the counter can count //! one enemy twice (docs/ram-map.md). The replay needs rom/galaga; it skips //! without it. use std::path::Path; use emu_galaga::galaga::movie::{ram_crc32, Movie}; use emu_galaga::galaga::objects::{objects, state}; use emu_galaga::galaga::roms::load_directory; use emu_galaga::galaga::Machine; #[test] fn every_proof_ends_a_perfect_challenging_stage() { let root = Path::new(env!("CARGO_MANIFEST_DIR")); let Ok(roms) = load_directory(&root.join("rom/galaga")) else { eprintln!("skipped: no extracted set at rom/galaga"); return; }; let mut checked = 0; for entry in std::fs::read_dir(root.join("proofs")).unwrap() { let path = entry.unwrap().path(); if path.extension().is_none_or(|e| e != "json") { continue; } let name = path.file_name().unwrap().to_string_lossy().to_string(); let movie = Movie::from_json(&std::fs::read_to_string(&path).unwrap()).unwrap(); let mut machine = Machine::new(&roms); movie.setup(&mut machine).unwrap(); let mut counter = machine.shared.borrow().ram2[0x288]; let mut before = objects(&machine.shared.borrow()); // Explosions since the counter last went back to 0. let mut exploded = 0; for c in movie.inputs() { machine.set_controls(c); machine.run_frame(); let now = objects(&machine.shared.borrow()); let k = machine.shared.borrow().ram2[0x288]; if k < counter { exploded = 0; } counter = k; exploded += (0..0x30) .filter(|&i| { now[i].state == state::EXPLODING && before[i].state != state::EXPLODING }) .count(); before = now; } assert_eq!( ram_crc32(&machine), movie.final_ram_crc32, "{name}: the replay differs" ); assert_eq!(counter, 40, "{name}: the game counts {counter} hits"); assert_eq!(exploded, 40, "{name}: {exploded} enemies exploded"); assert_ne!( machine.shared.borrow().ram3[0x27], 0, "{name}: not the dual fighter" ); checked += 1; } assert!(checked > 0, "no proofs in proofs/"); }