diff --git a/services/flysim/crates/flybrain-gb/src/adapter.rs b/services/flysim/crates/flybrain-gb/src/adapter.rs index d1d75f8..5b4d7c9 100644 --- a/services/flysim/crates/flybrain-gb/src/adapter.rs +++ b/services/flysim/crates/flybrain-gb/src/adapter.rs @@ -202,6 +202,15 @@ pub enum PlaceKind { Person, /// Something to press A at: the starter's Pokéball, an item ball, a sign. Object, + /// An errand in one room, step by step: its people first, and once none is left to talk to, + /// the things in it -- objects, signs, and the cartridge's own hidden events, such as the PC + /// a Bill's-house cell separator is started from (row 73, `docs/design/macros.md` 12.35). + /// + /// Not a list of steps, and no step is named: the room's state says which step is next, because + /// the cartridge shows and hides the people as the errand moves on. A person who has had their + /// conversation is in the talked ledger; a thing pressed is too; and what is left is the next + /// step. + Errand, } impl MapPlace { @@ -224,6 +233,11 @@ impl MapPlace { pub const fn object(map: u8) -> Self { Self { map, tile: None, warp: None, edge: None, target: Some(PlaceKind::Object) } } + + /// A place that is an errand in one room: its people, then its things ([`PlaceKind::Errand`]). + pub const fn errand(map: u8) -> Self { + Self { map, tile: None, warp: None, edge: None, target: Some(PlaceKind::Errand) } + } } /// Reasons an adapter refuses a checkpoint. diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs index 80ee959..2e90aca 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/cartridge.rs @@ -286,6 +286,8 @@ pub enum TalkTarget { Sprite(u8), /// A sign, by its text id. Sign(u8), + /// A hidden event of the cartridge's own table, by its position in this map's list (row 73). + Hidden(u8), } /// One thing a macro can be *aimed at*, as the session's target ledgers name it. diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/geography.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/geography.rs index 21057bf..43e2789 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/geography.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/geography.rs @@ -173,6 +173,12 @@ const LINKS: &[(u8, u8)] = &[ // which from the back door's arrival is the back door. Which piece each door opens onto is // [`SPLIT`]'s business. (maps::CERULEAN_BADGE_HOUSE, maps::CERULEAN_CITY), + // The trashed house (row 73): its front door is the town's, the hole in its back wall the + // south's ([`SPLIT`]). It is the only road from the town to Route 5, rung 17's. + (maps::CERULEAN_TRASHED_HOUSE, maps::CERULEAN_CITY), + // Bill's house, rung 16's room (row 73): Route 25's door at (45, 3), and the house's two + // doormats back to the route (`LAST_MAP`). + (maps::BILLS_HOUSE, maps::ROUTE_25), (maps::ROCK_TUNNEL_1F, maps::ROUTE_10), (maps::INDIGO_PLATEAU_LOBBY, maps::INDIGO_PLATEAU), ]; @@ -252,6 +258,9 @@ const B2F_SOUTH: u8 = 2; const CERULEAN_TOWN: u8 = 0; #[cfg(test)] const CERULEAN_YARD: u8 = 1; +/// [`SPLIT`]'s third piece of Cerulean: the ground behind the trashed house (row 73). +#[cfg(test)] +const CERULEAN_SOUTH: u8 = 2; /// Every map whose ground is in pieces, with each piece's doors and neighbours. /// @@ -383,21 +392,33 @@ const SPLIT: &[Split] = &[ (3, 30, 19), (4, 13, 25), (5, 25, 25), - (7, 27, 9), (8, 9, 11), ], next: &[ Region::whole(maps::ROUTE_24), - Region::whole(maps::ROUTE_5), Region::piece(maps::ROUTE_4, EAST_SIDE), - Region::whole(maps::ROUTE_9), Region::whole(maps::CERULEAN_POKECENTER), Region::whole(maps::CERULEAN_GYM), Region::whole(maps::CERULEAN_MART), Region::whole(maps::CERULEAN_BADGE_HOUSE), + Region::whole(maps::CERULEAN_TRASHED_HOUSE), ], }, Piece { doors: &[(9, 9, 9)], next: &[Region::whole(maps::CERULEAN_BADGE_HOUSE)] }, + // Row 73: everything behind the trashed house. The town's own ground ends at row 28 -- + // the gap at (16, 28) and (17, 28) opens onto a wall and the trainer-tips sign -- and + // the south of the map, the road down to Route 5, and the east edge onto Route 9 are + // reached through the house: in by the front door at (27, 11), out by the hole in its + // back wall, which lands on (27, 9) in the Rocket's yard, and from there east and down + // (scout B3 flooded the grid: 378 of the map's 801 walkable tiles are the town's). + Piece { + doors: &[(7, 27, 9)], + next: &[ + Region::whole(maps::ROUTE_5), + Region::whole(maps::ROUTE_9), + Region::whole(maps::CERULEAN_TRASHED_HOUSE), + ], + }, ], }, ]; @@ -977,6 +998,31 @@ mod tests { assert!(warp_on(west, 1) && !warp_on(west, 2) && !edge_on(west, maps::CERULEAN_CITY)); } + #[test] + fn the_road_south_out_of_cerulean_is_through_the_trashed_house() { + // Row 73. The town's ground ends at row 28; Route 5 and Route 9 are on the ground behind + // the trashed house, reached in by its front door (Cerulean's warp 0) and out by the hole + // in its back wall, which lands on (27, 9) (warp 7). Scout B3: 0 of 6 seeds past the + // town's south edge in 43 brain minutes each while the house was off the graph. + let town = Region::piece(maps::CERULEAN_CITY, CERULEAN_TOWN); + let south = Region::piece(maps::CERULEAN_CITY, CERULEAN_SOUTH); + let house = Region::whole(maps::CERULEAN_TRASHED_HOUSE); + assert_eq!(arrival_by_warp(maps::CERULEAN_CITY, 0), Some(town), "the front door is the town's"); + assert_eq!(arrival_by_warp(maps::CERULEAN_CITY, 7), Some(south), "the hole lands behind the house"); + assert_eq!(arrival_by_edge(maps::CERULEAN_CITY, maps::ROUTE_5), Some(south)); + assert_eq!(arrival_by_edge(maps::CERULEAN_CITY, maps::ROUTE_9), Some(south)); + assert_eq!(next_step(town, maps::ROUTE_5), Some(house)); + assert_eq!(next_step(house, maps::ROUTE_5), Some(south)); + assert_eq!(next_step(south, maps::ROUTE_5), Some(Region::whole(maps::ROUTE_5))); + assert_eq!(next_step(house, maps::CERULEAN_GYM), Some(town)); + assert_eq!(region_at(maps::CERULEAN_CITY, 27, 9), south); + assert_eq!(region_at(maps::CERULEAN_CITY, 27, 12), town); + assert!(!edge_on(town, maps::ROUTE_5) && edge_on(south, maps::ROUTE_5)); + assert!(warp_on(south, 7) && !warp_on(town, 7) && !warp_on(south, 0)); + // Rung 17's road from Bill's house is now one the graph knows end to end. + assert!(hops(Region::whole(maps::BILLS_HOUSE), maps::VERMILION_CITY).is_some()); + } + #[test] fn the_road_from_pewter_to_cerulean_is_through_mt_moon_one_chamber_at_a_time() { // Row 59. Every step of the road, as the pieces the fly stands in, measured from the diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs index 23e40fc..a039154 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/palette.rs @@ -2021,6 +2021,9 @@ pub fn facing_target(state: &mut dyn MacroState) -> Option { if let Some(target) = path::target_at(state, ahead) { return Some(target); } + if let Some(target) = objective_hidden_ahead(state, ahead, player.facing) { + return Some(target); + } // **Over a counter**, which is the symmetric half of [`counter_aims`] and was missing from it // (2026-09-17, measured on the cartridge in the Viridian mart). The game doubles its own // talking range over the tileset's counter tiles, so a fly standing at a counter facing the @@ -2111,7 +2114,17 @@ pub fn objective_goals(state: &mut dyn MacroState) -> Vec { // to walk to: `GO OBJECTIVE` walked to him, then back to the leader, and `TALK` was // the one press it never made room for. A fly facing a person the rung is waiting on // has nothing left for a walk to do. - if targets.iter().any(|(tile, _)| Some(*tile) == ahead) { + // A hidden event is faced only from the side it answers (row 73): beside Bill's PC + // facing it sideways is not the arrival, and the walk goes on to the tile below it. + let mut arrived = false; + for (tile, target) in &targets { + if Some(*tile) == ahead + && required_facing(state, *target).is_none_or(|need| need == player.facing) + { + arrived = true; + } + } + if arrived { return Vec::new(); } let mut ranked: Vec<(u32, Tile, TalkTarget)> = targets @@ -2120,8 +2133,12 @@ pub fn objective_goals(state: &mut dyn MacroState) -> Vec { .collect(); ranked.sort_unstable(); let Some((_, tile, target)) = ranked.first().copied() else { return Vec::new() }; + let need = required_facing(state, target); let mut aims = Vec::with_capacity(4); for facing in FACINGS { + if need.is_some_and(|need| need != opposite(facing)) { + continue; + } let Some(stand) = tile.step(facing) else { continue }; // Not a tile a script pushes the fly off (row 37); `approach` excludes the same. if state.pushed_tile(stand.x, stand.y) { @@ -2235,7 +2252,34 @@ pub fn objective_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)> // Not objects: every item ball in the game is a toggleable object, so a ball the run has // picked up and one out of sight read alike from outside the window. PlaceKind::Object => path::interactable_targets(state), + // Row 73: an errand in one room is its people first, and its things -- sprites, signs and + // the cartridge's hidden events -- once no person is left to talk to. Bill's house is the + // case: Bill (a Pokémon) asks for the cell separator and walks into the machine, the + // separator is a PC no sprite or sign stands for, and Bill comes out of the machine to + // hand over the ticket. The cartridge hides and shows the people as the errand moves, so + // the room's own state says which step is next; nothing here names a step. + // + // People first, because a thing pressed out of turn is in the talked ledger for the + // session: Bill's PC pressed before Bill has asked prints "the monitor" and does nothing, + // and a PC recorded as talked to would never be the errand's next step again. + PlaceKind::Errand => { + let mut people = path::person_targets(state); + people.extend(path::offscreen_person_targets(state)); + let people = open_targets(state, people); + if !people.is_empty() { + return people; + } + let mut things = path::interactable_targets(state); + things.extend(path::hidden_targets(state).into_iter().map(|(tile, target, _)| (tile, target))); + things + } }; + open_targets(state, targets) +} + +/// Whichever of `targets` the objective is still waiting on: not talked to, and not resting in +/// the blocked ledger. [`objective_targets`]' own filter, for each list it builds. +fn open_targets(state: &mut dyn MacroState, targets: Vec<(Tile, TalkTarget)>) -> Vec<(Tile, TalkTarget)> { targets .into_iter() .filter(|(_, target)| { @@ -2244,6 +2288,37 @@ pub fn objective_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)> .collect() } +/// The one side the objective's `target` is pressed from, when the cartridge names one: a hidden +/// event whose routine checks the player's facing (row 73, Bill's PC). `None` for every sprite and +/// sign, which answer from any side. +fn required_facing(state: &mut dyn MacroState, target: TalkTarget) -> Option { + let TalkTarget::Hidden(_) = target else { return None }; + path::hidden_targets(state) + .into_iter() + .find(|(_, hidden, _)| *hidden == target) + .and_then(|(_, _, facing)| facing) +} + +/// The objective's hidden event on the tile ahead, faced from the side it answers (row 73). +/// +/// The half of [`facing_target`] that is not the map's sprites and signs. Only the objective's +/// own next step is reported, never any other hidden event: a poster faced on the way past is not +/// a reason for `TALK`, and a PC pressed out of turn would retire the errand's own step +/// ([`objective_targets`]). +fn objective_hidden_ahead(state: &mut dyn MacroState, ahead: Tile, facing: Facing) -> Option { + // Most tiles of most maps are no hidden event's, and this is asked on every overworld frame. + if !path::hidden_targets(state).iter().any(|(tile, _, _)| *tile == ahead) { + return None; + } + let (_, target) = objective_targets(state) + .into_iter() + .find(|(tile, target)| *tile == ahead && matches!(target, TalkTarget::Hidden(_)))?; + match required_facing(state, target) { + Some(need) if need != facing => None, + _ => Some(target), + } +} + /// The exits the ledger has already recorded, for the log line. pub fn visited_exits(state: &mut dyn MacroState) -> Vec { path::exits(state) diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/path.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/path.rs index 3350784..f7603e4 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/path.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/path.rs @@ -366,6 +366,24 @@ pub fn interactable_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget out } +/// The map's hidden events with the key the talked ledger records them under, and the one side +/// each is pressed from when the cartridge names one (row 73). +/// +/// Kept apart from [`interactable_targets`] on purpose, which is `GO ITEM`'s list: a hidden event +/// is every PC, poster, trash can and hidden item in Kanto, and a fly sent to each of them is a +/// fly reading posters. The one reader is the ladder's own errand list +/// ([`super::palette::objective_targets`]), which needs the one the rung is waiting on. +pub fn hidden_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget, Option)> { + let mut out: Vec<(Tile, TalkTarget, Option)> = state + .hidden_events() + .iter() + .map(|event| (Tile::new(event.x, event.y), TalkTarget::Hidden(event.index), event.facing)) + .collect(); + out.sort_unstable_by_key(|(tile, target, _)| (*tile, *target)); + out.dedup_by_key(|(tile, _, _)| *tile); + out +} + /// Every person on the map with the key the talked ledger records them under. pub fn person_targets(state: &mut dyn MacroState) -> Vec<(Tile, TalkTarget)> { let mut out: Vec<(Tile, TalkTarget)> = state diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/state.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/state.rs index 2558e4b..498a049 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/state.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/state.rs @@ -413,6 +413,31 @@ pub struct Sign { pub text_id: u8, } +/// One hidden event on the current map: a tile the cartridge answers an A press at from its own +/// ROM table (`HiddenEventMaps` / `HiddenEventPointers`, `data/events/hidden_events.asm`) rather +/// than from a sprite or a sign (row 73, `docs/design/macros.md` 12.35). +/// +/// Bill's cell-separator PC, the Pokémon Center PCs, posters, bookshelves of one room, trash cans +/// and hidden items are all this. Nothing about one reaches WRAM until it has been pressed +/// (`CheckForHiddenEvent` searches the table on every A in the overworld), so the tile is read from +/// the cartridge image and the tile named here is the one to *face*, like a [`Sign`]'s. +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct HiddenEvent { + pub x: u8, + pub y: u8, + /// The entry's position in this map's list, which is the identity the cartridge gives it + /// (`wHiddenEventIndex` counts the same way) and nothing more. + pub index: u8, + /// The one side the cartridge answers the press from, when the entry names one. + /// + /// The table's third byte is the routine's argument, and where it is a `SPRITE_FACING_*` + /// value it is the side the routine checks before it does anything (`BillsHousePC` returns at + /// once unless the player faces up). `None` for any other argument -- an item id, a text id, + /// `ANY_FACING` -- which leaves all four sides. An argument that is an item or a text id and + /// happens to equal a facing value only narrows the approach to one side; it never adds one. + pub facing: Option, +} + /// Whether a tile can be walked onto. /// /// `Unknown` is load-bearing: the tile ids a walkability test needs live in the screen buffer, so @@ -774,6 +799,14 @@ pub trait GameState { /// is visible, and not inherit it from here. fn signs(&mut self) -> Vec; + /// The current map's hidden events, from the cartridge's own table (row 73). + /// + /// Defaulted to none, which narrows: a seam with no cartridge image behind it knows the + /// sprites and the signs and nothing more, which is what every reader had before row 73. + fn hidden_events(&mut self) -> Vec { + Vec::new() + } + /// Whether the player could stand on this tile of the current map. fn walkable(&mut self, x: u8, y: u8) -> Walkable; diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs index 0188ebb..ca89a17 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/macros/tests.rs @@ -40,7 +40,8 @@ use super::super::maps; use super::plan; use super::state::{ Battle, BattleKind, BattleMenu, Connections, Cursor, EnemyMon, Facing, GameState, MapSize, - Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu, Status, TextBox, + HiddenEvent, Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu, + Status, TextBox, Walkable, Warp, }; @@ -95,6 +96,8 @@ struct World { /// Sprites the cartridge is not drawing only because they are off the screen (row 58). offscreen: Vec, signs: Vec, + /// The map's hidden events, as the cartridge's own table lists them (row 73). + hidden: Vec, list: List, cursor: u8, @@ -276,6 +279,7 @@ impl World { npcs: Vec::new(), offscreen: Vec::new(), signs: Vec::new(), + hidden: Vec::new(), list: List::None, cursor: 0, cursor_max: 0, @@ -791,6 +795,10 @@ impl GameState for World { self.signs.clone() } + fn hidden_events(&mut self) -> Vec { + self.hidden.clone() + } + fn walkable(&mut self, x: u8, y: u8) -> Walkable { let tile = Tile::new(x, y); let offscreen = self.window && { @@ -6615,3 +6623,99 @@ fn row69_confirm_on_a_keyboard_that_does_not_close_is_blocked() { world.glue_naming = true; assert_eq!(run(&mut world, MacroKind::Confirm).unwrap(), MacroAbort::Blocked); } + +/// Bill's house on the step the live ring never got past (row 73): the fly on the doormat, Bill +/// (a Pokémon, a person sprite) at (6, 5), the cell separator's PC a hidden event at (1, 4) that is +/// pressed facing up, and rung 16's place the house as an errand. +fn bills_house() -> World { + let mut world = World::room().at(2, 7); + world.map = maps::BILLS_HOUSE; + world.size = MapSize { width: 8, height: 8 }; + world.facing = Facing::Up; + // The back wall, the PC's own tile with it. + world = world.wall(&[(0, 3), (1, 3), (2, 3), (3, 3), (4, 3), (5, 3), (6, 3), (7, 3), (1, 4)]); + world.warps = vec![ + Warp { x: 2, y: 7, destination_warp: 0, destination_map: LAST_MAP }, + Warp { x: 3, y: 7, destination_warp: 0, destination_map: LAST_MAP }, + ]; + world.npcs = vec![Npc { slot: 1, picture: 0x2a, x: 6, y: 5, facing: Facing::Down }]; + world.hidden = vec![HiddenEvent { x: 1, y: 4, index: 0, facing: Some(Facing::Up) }]; + world.objective = Some(Objective { + map: world.map, + tile: None, + warp: None, + edge: None, + target: Some(PlaceKind::Errand), + }); + world +} + +#[test] +fn an_errand_is_its_people_first_and_the_room_is_not_left_while_one_is_waiting() { + // Row 73, live on v0.7.5: rung 16 was `at(ROUTE_25)`, so inside Bill's house `GO OBJECTIVE` + // and `GO OUT` were both the door, 30 to 60 times per ten brain minutes. As an errand, Bill is + // the target and the ways out are withheld while he is waiting (12.5's rule). + let mut world = bills_house(); + assert_eq!(super::palette::objective_targets(&mut world), vec![(Tile::new(6, 5), TalkTarget::Sprite(1))]); + assert!(on_the_pad(&mut world, MacroKind::GoObjective)); + assert!(!on_the_pad(&mut world, MacroKind::GoOut), "the house is not left while Bill is waiting"); + + // The PC is not the errand's step yet: faced out of turn it is not `TALK`'s, because a PC + // pressed before Bill has asked prints the monitor and would be in the talked ledger for good. + let mut world = bills_house().at(1, 5); + world.facing = Facing::Up; + assert!(!on_the_pad(&mut world, MacroKind::Talk)); + assert_eq!(super::palette::facing_target(&mut world), None); +} + +#[test] +fn a_hidden_event_is_the_errands_next_step_once_no_person_is_left_and_it_is_faced_from_its_side() { + // Bill has asked and walked into the machine: the cartridge has hidden his sprite and nobody + // else is in the room. The next step is the cell separator's PC, which no sprite or sign + // stands for -- the hidden event the scout pressed by hand on the cartridge (row 73). + let mut world = bills_house().at(3, 5); + world.npcs.clear(); + world.talked.insert(TalkTarget::Sprite(1)); + assert_eq!(super::palette::objective_targets(&mut world), vec![(Tile::new(1, 4), TalkTarget::Hidden(0))]); + assert!(!on_the_pad(&mut world, MacroKind::GoOut), "still not left: the PC is waiting"); + // `BillsHousePC` answers only a player facing up, so the walk's one aim is the tile below it. + let aims: Vec<(Tile, Option)> = + objective_goals(&mut world).iter().map(|aim| (aim.tile, aim.face)).collect(); + assert_eq!(aims, vec![(Tile::new(1, 5), Some(Facing::Up))]); + + // Beside it, facing it sideways, is not the arrival: nothing would answer the press. + let mut beside = bills_house().at(2, 4); + beside.npcs.clear(); + beside.talked.insert(TalkTarget::Sprite(1)); + beside.facing = Facing::Left; + assert!(!on_the_pad(&mut beside, MacroKind::Talk)); + assert!(on_the_pad(&mut beside, MacroKind::GoObjective)); + + // Below it, facing up: `TALK` is the press and the walk is done. + let mut below = bills_house().at(1, 5); + below.npcs.clear(); + below.talked.insert(TalkTarget::Sprite(1)); + below.facing = Facing::Up; + assert_eq!(super::palette::facing_target(&mut below), Some(TalkTarget::Hidden(0))); + assert!(on_the_pad(&mut below, MacroKind::Talk)); + assert!(!on_the_pad(&mut below, MacroKind::GoObjective)); + + // Pressed: Bill steps out of the machine, and he is the errand's last step. + below.talked.insert(TalkTarget::Hidden(0)); + below.npcs = vec![Npc { slot: 2, picture: 0x13, x: 4, y: 4, facing: Facing::Down }]; + assert_eq!(super::palette::objective_targets(&mut below), vec![(Tile::new(4, 4), TalkTarget::Sprite(2))]); +} + +#[test] +fn a_hidden_event_is_nobody_elses_target() { + // A hidden event is every PC, poster and trash can in Kanto. Outside the errand that names it + // no macro aims at one and `TALK` is not dealt in front of one: `GO ITEM` is what it was. + let mut world = bills_house().at(1, 5); + world.npcs.clear(); + world.facing = Facing::Up; + world.objective = Some(Objective { map: maps::ROUTE_25, tile: None, warp: None, edge: None, target: None }); + assert!(super::palette::untalked_objects(&mut world).is_empty()); + assert!(!on_the_pad(&mut world, MacroKind::GoItem)); + assert!(!on_the_pad(&mut world, MacroKind::Talk)); + assert_eq!(super::palette::facing_target(&mut world), None); +} diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/maps.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/maps.rs index e752ac3..6f15bb7 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/maps.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/maps.rs @@ -84,12 +84,22 @@ pub const MT_MOON_1F: u8 = 0x3b; pub const MT_MOON_B1F: u8 = 0x3c; pub const MT_MOON_B2F: u8 = 0x3d; pub const CERULEAN_POKECENTER: u8 = 0x40; +/// The house the Rockets robbed (row 73): the id before `CERULEAN_TRADE_HOUSE` and +/// `CERULEAN_POKECENTER` `$40`, and confirmed by the cartridge rather than by counting -- Cerulean +/// City's warp table names `$3e` at (27, 11) and at (27, 9), its front door and the hole in its +/// back wall. +pub const CERULEAN_TRASHED_HOUSE: u8 = 0x3e; pub const CERULEAN_GYM: u8 = 0x41; pub const CERULEAN_MART: u8 = 0x43; /// Route 4's Pokémon Center, the one beside Mt. Moon's mouth: the id straight after /// `CERULEAN_MART` `$43`, and confirmed by the cartridge rather than by counting -- Route 4's warp /// table names `$44` at (11, 5) (`tests/rom_macros_mode.rs`, row 59's door survey). pub const MT_MOON_POKECENTER: u8 = 0x44; +/// Bill's house on Route 25, where rung 16 (the S.S. Ticket) is earned (row 73). Confirmed by the +/// cartridge rather than by counting: Route 25's warp table names `$58` at (45, 3), and the +/// cartridge's own hidden-event map list (`HiddenEventMaps`) carries `$58` at the position the +/// disassembly lists `BILLS_HOUSE` in (`tests/rom_macros_mode.rs`, row 73). +pub const BILLS_HOUSE: u8 = 0x58; pub const ROCK_TUNNEL_1F: u8 = 0x52; pub const INDIGO_PLATEAU_LOBBY: u8 = 0xae; /// The house beside Cerulean's west road whose back door is the one way into the closed yard at diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/mod.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/mod.rs index b8f533f..8d6e2e6 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/mod.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/mod.rs @@ -222,6 +222,10 @@ const RUNG_PLACES: [Option; RANK_LADDER.len()] = { const fn object(map: u8) -> Option { Some(MapPlace::object(map)) } + /// A rung earned by an errand in one room: its people, then its things. + const fn errand(map: u8) -> Option { + Some(MapPlace::errand(map)) + } [ None, // 0 BOOT: nowhere. at(maps::REDS_HOUSE_2F), // 1 BEDROOM @@ -244,7 +248,12 @@ const RUNG_PLACES: [Option; RANK_LADDER.len()] = { at(maps::CERULEAN_CITY), // 13 CERULEAN CITY person(maps::CERULEAN_GYM), // 14 CASCADE BADGE, likewise at(maps::ROUTE_24), // 15 NUGGET BRIDGE, north out of Cerulean - at(maps::ROUTE_25), // 16 MET BILL, whose house is on Route 25 + // 16 MET BILL: the S.S. Ticket is Bill's thanks for an errand in his house -- talk to + // him (he is a Pokémon), press the cell separator's PC (a hidden event, not a sprite), + // talk to him again. One room, people then things: an errand (row 73). It was + // `at(ROUTE_25)`, and a fly on Route 25 was already "there", so inside the house + // `GO OBJECTIVE` was the door out to the route. + errand(maps::BILLS_HOUSE), at(maps::VERMILION_CITY), // 17 VERMILION CITY at(maps::VERMILION_CITY), // 18 HM CUT, on the S.S. Anne at Vermilion's dock None, // 19 THUNDER BADGE: Vermilion Gym, id not derived diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs index 69f1c35..93773ef 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/state.rs @@ -33,7 +33,7 @@ use super::macros::geography::Amenity; use super::mapgrid::{self, MapGrids}; use super::macros::state::{ BagItem, Battle, BattleKind, BattleMenu, Connections, Cursor, EnemyMon, Facing, GameState, - MapGrid, MapSize, Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu, + HiddenEvent, MapGrid, MapSize, Mon, Move, Naming, Npc, Party, Pc, Player, Scene, Shop, ShopScreen, Sign, StartMenu, Status, TextBox, Walkable, Warp, }; use super::symbols::ram; @@ -350,6 +350,30 @@ pub mod poke { /// The cartridge's item-use dispatch and the ids that name its routines (row 63, /// `docs/design/macros.md` 12.27). + /// The cartridge's hidden-event tables (row 73, `docs/design/macros.md` 12.35). + /// + /// `engine/overworld/hidden_events.asm`: `CheckForHiddenEvent` walks `HiddenEventMaps`, one + /// map id per byte to a `$ff`, and with the index it found there reads a little-endian pointer + /// out of `HiddenEventPointers` to that map's list. Both tables and every list are in the + /// routine's own `SECTION "Hidden Events Core"`, which `layout.link` places in ROM bank `$11`. + /// At the pinned commit the two tables are at `$11:$6A40` and `$11:$6A96`: read from the + /// operands of the routine's `ld hl, HiddenEventMaps` and `ld hl, HiddenEventPointers` on the + /// cartridge, and pinned by the ROM-gated test that reads them back from there. A list entry is + /// six bytes (`hidden_event`): y, x, the routine's argument, and the routine as `dba`. + pub mod hidden { + pub const TABLE_BANK: u8 = 0x11; + pub const MAPS_ADDRESS: u16 = 0x6a40; + pub const POINTERS_ADDRESS: u16 = 0x6a96; + pub const ENTRY_BYTES: u16 = 6; + /// More maps than the table has (85 at the pinned commit), and more entries than any one + /// map's list (Silph Co.'s and the Game Corner's are the long ones): a walk that runs past + /// either is not walking the table the disassembly describes, and answers nothing. + pub const MAX_MAPS: u16 = 128; + pub const MAX_ENTRIES: u16 = 32; + /// `SPRITE_FACING_DOWN`, `_UP`, `_LEFT`, `_RIGHT` (`constants/sprite_data_constants.asm`). + pub const FACINGS: [u8; 4] = [0x00, 0x04, 0x08, 0x0c]; + } + pub mod items { /// `engine/items/item_effects.asm`: `UseItem_` jumps through `ItemUsePtrTable`, one /// little-endian pointer per item id from `MASTER_BALL` (1) to `MAX_ELIXER` (`$53`), in @@ -2055,6 +2079,60 @@ pub fn signs(memory: &mut dyn MemoryReader) -> Vec { signs } +/// The current map's hidden events, read from the cartridge's own table ([`poke::hidden`]). +/// +/// Empty on a map the table does not list, when the seam has no cartridge image behind it, and +/// when the bytes are not the shape the disassembly describes -- a map list with no end, a pointer +/// outside the bank's window, a list longer than any map's, a tile off the loaded map. A table +/// this module cannot read is not one it reports, so a wrong address narrows (`GO OBJECTIVE` has +/// one less thing to aim at) and never invents a tile. +pub fn hidden_events(memory: &mut dyn MemoryReader) -> Vec { + hidden_events_inner(memory).unwrap_or_default() +} + +fn hidden_events_inner(memory: &mut dyn MemoryReader) -> Option> { + use poke::hidden::*; + let size = map_size(memory)?; + let map = read(memory, ram::wCurMap); + let mut index = None; + for position in 0..MAX_MAPS { + let id = memory.read_rom(TABLE_BANK, MAPS_ADDRESS + position)?; + if id == 0xff { + break; + } + if id > poke::MAX_MAP_ID || position + 1 == MAX_MAPS { + return None; + } + if id == map && index.is_none() { + index = Some(position); + } + } + let Some(position) = index else { return Some(Vec::new()) }; + let at = POINTERS_ADDRESS + 2 * position; + let list = u16::from_le_bytes([memory.read_rom(TABLE_BANK, at)?, memory.read_rom(TABLE_BANK, at + 1)?]); + if !(0x4000..0x8000).contains(&list) { + return None; + } + let mut out = Vec::new(); + for entry in 0..MAX_ENTRIES { + let base = list.checked_add(entry * ENTRY_BYTES)?; + let y = memory.read_rom(TABLE_BANK, base)?; + if y == 0xff { + return Some(out); + } + let x = memory.read_rom(TABLE_BANK, base + 1)?; + let argument = memory.read_rom(TABLE_BANK, base + 2)?; + let routine = + u16::from_le_bytes([memory.read_rom(TABLE_BANK, base + 4)?, memory.read_rom(TABLE_BANK, base + 5)?]); + if x >= size.width || y >= size.height || routine >= 0x8000 { + return None; + } + let facing = FACINGS.contains(&argument).then(|| facing_from(argument)); + out.push(HiddenEvent { x, y, index: entry as u8, facing }); + } + None +} + /// Which of the current map's edges lead to another map, from `wCurMapConnections`. pub fn connections(memory: &mut dyn MemoryReader) -> Connections { let bits = read(memory, ram::wCurMapConnections); @@ -2245,6 +2323,10 @@ impl GameState for PokeState<'_> { signs(self.memory) } + fn hidden_events(&mut self) -> Vec { + hidden_events(self.memory) + } + fn walkable(&mut self, x: u8, y: u8) -> Walkable { walkable(self.memory, x, y) } diff --git a/services/flysim/crates/flybrain-gb/src/pokemon_red/tests.rs b/services/flysim/crates/flybrain-gb/src/pokemon_red/tests.rs index 8f4e17b..c6087ec 100644 --- a/services/flysim/crates/flybrain-gb/src/pokemon_red/tests.rs +++ b/services/flysim/crates/flybrain-gb/src/pokemon_red/tests.rs @@ -1273,6 +1273,8 @@ fn the_objective_is_the_next_unreached_rungs_place_where_the_catalog_knows_one() assert_eq!(RUNG_PLACES[11].map(|place| place.map), Some(maps::PEWTER_GYM), "BOULDER BADGE"); assert_eq!(RUNG_PLACES[14].map(|place| place.map), Some(maps::CERULEAN_GYM), "CASCADE BADGE"); assert_eq!(RUNG_PLACES[19], None, "THUNDER BADGE: Vermilion Gym's id is not derived"); + // Row 73: the ticket is an errand inside Bill's house, not the route the house is on. + assert_eq!(RUNG_PLACES[16], Some(crate::adapter::MapPlace::errand(maps::BILLS_HOUSE)), "MET BILL"); // And past the top of the ladder there is no next rung at all. assert_eq!(RUNG_PLACES.len(), RANK_LADDER.len()); assert_eq!(rung_place(&f.reward.seen, RANK_LADDER.len()), None); diff --git a/services/flysim/crates/flysim/tests/rom_macros_mode.rs b/services/flysim/crates/flysim/tests/rom_macros_mode.rs index d253f03..23715ba 100644 --- a/services/flysim/crates/flysim/tests/rom_macros_mode.rs +++ b/services/flysim/crates/flysim/tests/rom_macros_mode.rs @@ -5132,3 +5132,274 @@ fn row70_the_list_after_a_faint_is_still_a_forced_switch_and_is_answered() { assert!(turn_after.is_some(), "the forced switch was never answered: {:?}", drive.starts); assert_eq!(out, 1, "the Pokémon still standing (the Zubat, slot 1) was sent out"); } + +/// Route 25, Bill's house on it, and the flag rung 16 is (`constants/map_constants.asm`, +/// `constants/event_constants.asm`; `docs/design/ladder.md` verified bit 1372). +const ROUTE_25: u32 = 0x24; +const BILLS_HOUSE: u32 = 0x58; +const EVENT_GOT_SS_TICKET: u16 = 1372; + +/// A row-73 checkpoint named by `var`, or `None` to skip. +/// +/// Scout B3's, from the v0.7.5 tree and the live row-71 checkpoint (rung 15), plus the live one +/// itself (`FLY_ROW71_CHECKPOINT`, rom-env's existing name): +/// +/// - `FLY_ROW73_DOOR_CHECKPOINT` (`scout-b3-bills-ring-door`): the same ring, just inside the door. +/// - `FLY_ROW73_PC_CHECKPOINT` (`scout-b3-bills-pc-step`): a carry-forward by scripted presses -- +/// Bill has asked for the cell separator and walked into the machine, and the next step is the +/// PC, a hidden event no sprite or sign stands for. +fn row73_checkpoint(var: &str) -> Option { + std::env::var_os(var).map(|path| { + flysim::store::load(std::path::Path::new(&path)) + .expect("the checkpoint should be a FLYSIM01 envelope") + }) +} + +/// Row 73: the hidden-event table the macros read is the cartridge's own, and Bill's PC is in it. +/// +/// The two addresses are pinned the way `ItemUsePtrTable`'s is: they are the operands of +/// `CheckForHiddenEvent`'s own `ld hl, HiddenEventMaps` (followed by its `ld a, [hli] / ld b, a / +/// cp $ff`) and `ld hl, HiddenEventPointers` (followed by `add hl, de`), found in the routine's +/// bank. Then, standing in Bill's house, the seam reads one hidden event, the PC at (1, 4), pressed +/// facing up -- the entry the scout's scripted presses found by hand. +#[test] +fn row73_the_hidden_event_table_is_the_cartridges_and_bills_pc_is_in_it() { + use flybrain_gb::pokemon_red::macros::state::{Facing, HiddenEvent}; + use flybrain_gb::pokemon_red::state::{self, poke::hidden}; + let rom = skip_without_rom!(); + let gb = emulator(&rom); + let bank: Vec = (0x4000u16..0x8000) + .map(|address| gb.read_rom_bank(hidden::TABLE_BANK, address).expect("bank $11 is in the image")) + .collect(); + let [maps_low, maps_high] = hidden::MAPS_ADDRESS.to_le_bytes(); + let [pointers_low, pointers_high] = hidden::POINTERS_ADDRESS.to_le_bytes(); + let maps_load = [0x21, maps_low, maps_high, 0x2a, 0x47, 0xfe, 0xff]; + let pointers_load = [0x21, pointers_low, pointers_high, 0x19]; + let at = |needle: &[u8]| bank.windows(needle.len()).position(|window| window == needle); + let maps_at = at(&maps_load).expect("CheckForHiddenEvent loads HiddenEventMaps from the pinned address"); + let pointers_at = + at(&pointers_load).expect("CheckForHiddenEvent loads HiddenEventPointers from the pinned address"); + assert!(pointers_at > maps_at && pointers_at - maps_at < 32, "one routine: {maps_at:#x} {pointers_at:#x}"); + + let Some(checkpoint) = row73_checkpoint("FLY_ROW73_DOOR_CHECKPOINT") else { + eprintln!("skipped: no FLY_ROW73_DOOR_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.map(), BILLS_HOUSE, "the checkpoint is inside Bill's house"); + assert_eq!( + state::hidden_events(&mut run.gb), + vec![HiddenEvent { x: 1, y: 4, index: 0, facing: Some(Facing::Up) }], + "Bill's house has one hidden event, the cell separator's PC" + ); +} + +/// Row 73, the trap: from inside the ring at Bill's door, macros mode earns rung 16 (the S.S. +/// Ticket). +/// +/// **Live on v0.7.5** (scout B3, six seeds, 2.8 brain hours): rung 16's place was `at(ROUTE_25)`, +/// so a fly on Route 25 was already "there". `GO ROUTE` walked it into Bill's house, and inside +/// `GO OBJECTIVE` -- an exit into the objective's own map is toward it -- and `GO OUT` walked it +/// straight back out, 30 to 60 times per ten brain minutes; `GO NPC` was chosen 0 times in about +/// 600 starts in the house. Behind that, the errand's middle step is the cell separator's PC, a +/// hidden event no macro could press, so even a fly that talked to Bill could not earn the rung. +/// +/// The claims, over the stub rotation (no brain, a readout that never names a macro): the fly +/// does not leave the house before the errand is done, and `EVENT_GOT_SS_TICKET` is set within the +/// budget. On main the flag is never set. +/// +/// ```sh +/// FLY_ROM=/path/to/pokemon-red.gb \ +/// FLY_ROW73_DOOR_CHECKPOINT=.local/checkpoints/scout-b3-bills-ring-door.checkpoint \ +/// cargo test --release -p flysim --test rom_macros_mode -- --nocapture row73 +/// ``` +#[test] +fn row73_the_fly_earns_the_ss_ticket_from_inside_the_ring_at_bills_door() { + let rom = skip_without_rom!(); + let Some(checkpoint) = row73_checkpoint("FLY_ROW73_DOOR_CHECKPOINT") else { + eprintln!("skipped: no FLY_ROW73_DOOR_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.map(), BILLS_HOUSE, "the checkpoint is inside Bill's house"); + assert!(!run.event(EVENT_GOT_SS_TICKET), "the checkpoint has no ticket"); + let (_, out) = row73_drive_to_the_ticket(&mut run, 36_000); + assert_eq!(out, 0, "the house was left before the errand was done"); +} + +/// Row 73, the whole road: from the live row-71 checkpoint (v0.7.3, rung 15, in a wild battle on +/// Route 25) macros mode finishes the battle, walks to Bill's house and earns the ticket. Route +/// 25's own warp table is what pins `maps::BILLS_HOUSE`. +#[test] +fn row73_the_fly_walks_from_the_live_route_25_checkpoint_to_the_ss_ticket() { + let rom = skip_without_rom!(); + let Some(checkpoint) = row73_checkpoint("FLY_ROW71_CHECKPOINT") else { + eprintln!("skipped: no FLY_ROW71_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.gb.read_wram(flybrain_gb::pokemon_red::symbols::ram::wCurMap), ROUTE_25 as u8); + assert!(!run.event(EVENT_GOT_SS_TICKET), "the checkpoint has no ticket"); + let warps = flybrain_gb::pokemon_red::state::warps(&mut run.gb); + assert!( + warps.iter().any(|warp| (warp.x, warp.y, u32::from(warp.destination_map)) == (45, 3, BILLS_HOUSE)), + "Route 25's door at (45, 3) leads to $58: {warps:?}" + ); + row73_drive_to_the_ticket(&mut run, 216_000); +} + +/// Row 73, the hidden event alone: Bill is in the machine, the next step is the PC, and macros mode +/// presses it and earns the ticket. On main no button on any pad presses a hidden event. +#[test] +fn row73_the_cell_separator_pc_is_pressed_and_bill_hands_over_the_ticket() { + let rom = skip_without_rom!(); + let Some(checkpoint) = row73_checkpoint("FLY_ROW73_PC_CHECKPOINT") else { + eprintln!("skipped: no FLY_ROW73_PC_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.map(), BILLS_HOUSE, "the checkpoint is inside Bill's house"); + assert!(!run.event(EVENT_GOT_SS_TICKET), "the checkpoint has no ticket"); + row73_drive_to_the_ticket(&mut run, 36_000); +} + +/// Drive the stub rotation until the ticket's flag is set, counting the house's doors on the way: +/// `(into, out)`. +fn row73_drive_to_the_ticket(run: &mut Run, budget: u32) -> (u32, u32) { + let mut previous = run.map(); + let (mut into, mut out) = (0u32, 0u32); + let mut got = None; + for frame in 0..budget { + run.frame(); + let map = run.map(); + if map != previous && map != u32::MAX { + into += u32::from(map == BILLS_HOUSE); + out += u32::from(previous == BILLS_HOUSE); + previous = map; + } + if run.event(EVENT_GOT_SS_TICKET) { + got = Some(frame); + break; + } + } + eprintln!( + "ticket at {got:?} ({:.1} brain minutes), into the house {into} times, out {out}, rank {}, \ + talk on pad by map {:?}, talk starts {:?}, macros {:?}", + run.ms / 60_000.0, + run.adapter.progress().rank, + run.talk_on_pad_by_map, + run.talk_starts_by_map, + run.started + ); + assert!(got.is_some(), "no S.S. Ticket in {budget} frames: route {:?}, macros {:?}", run.route, run.started); + (into, out) +} + +const ROUTE_5: u32 = 0x10; +const CERULEAN_TRASHED_HOUSE: u32 = 0x3e; + +/// Where `GO OBJECTIVE` aims from here, read through the seam the macros read: the tiles. +fn row73_objective_aims(run: &mut Run) -> Vec<(u8, u8)> { + let ledger = AdapterLedger(&run.adapter); + let mut state = flybrain_gb::pokemon_red::state::PokeState::with_ledger(&mut run.gb, &ledger); + flybrain_gb::pokemon_red::macros::palette::objective_goals(&mut state) + .iter() + .map(|aim| (aim.tile.x, aim.tile.y)) + .collect() +} + +/// Row 73's third trap, on the seam: after the ticket, `GO OBJECTIVE` in the town aims at the +/// trashed house's front door, and inside the house at the hole in its back wall. +/// +/// On main the house is off the graph: in the town the objective toward Vermilion aimed at ground +/// the town's piece cannot reach (scout B3: `blocked` at (17, 28)), and inside the house the only +/// way toward an outdoor objective was the front door it came in by. From +/// `FLY_ROW73_SOUTH_CHECKPOINT` (`scout-b3-cerulean-south-half`, seed 4, 40 brain minutes, standing +/// at (10, 26) in the town's south-west) and `FLY_ROW73_TRASHED_CHECKPOINT` (the same run's seed 6, +/// going through the house's front door). +#[test] +fn row73_the_objective_south_of_cerulean_is_the_trashed_houses_two_doors() { + let rom = skip_without_rom!(); + if let Some(checkpoint) = row73_checkpoint("FLY_ROW73_SOUTH_CHECKPOINT") { + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert_eq!(run.map(), CERULEAN_CITY, "the checkpoint is in Cerulean"); + assert!(run.event(EVENT_GOT_SS_TICKET), "the checkpoint has the ticket"); + assert_eq!(row73_objective_aims(&mut run), vec![(27, 11)], "the trashed house's front door"); + } else { + eprintln!("skipped: no FLY_ROW73_SOUTH_CHECKPOINT"); + } + let Some(checkpoint) = row73_checkpoint("FLY_ROW73_TRASHED_CHECKPOINT") else { + eprintln!("skipped: no FLY_ROW73_TRASHED_CHECKPOINT"); + return; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + // Through the door with no button down: the warp's tear settles inside the house. + for _ in 0..240 { + run.gb.set_buttons(0); + run.gb.run_frame().expect("a frame should complete"); + run.ms += MS_PER_FRAME; + run.adapter.sample(&mut run.gb, run.ms); + } + assert_eq!(run.map(), CERULEAN_TRASHED_HOUSE, "inside the trashed house"); + let warps = flybrain_gb::pokemon_red::state::warps(&mut run.gb); + assert!( + warps.iter().any(|warp| (warp.x, warp.y, warp.destination_warp) == (3, 0, 7)), + "the hole in the back wall is the house's warp to Cerulean's (27, 9): {warps:?}" + ); + assert_eq!(row73_objective_aims(&mut run), vec![(3, 0)], "the hole in the back wall"); +} + +/// Row 73's third trap, after the ticket: the road south out of Cerulean is through the trashed +/// house, and macros mode takes it to Route 5. +/// +/// **Scout B3** (six seeds, 43 brain minutes each, from the ticket's carry-forward): 0 of 6 past +/// row 28 of Cerulean. The town's ground ends there; Route 5 is on the ground behind the trashed +/// house, in by its front door and out by the hole in its back wall, and the house was off the map +/// graph -- so `GO OBJECTIVE` toward Vermilion ended `blocked` at (17, 28) and the fly rang between +/// the town and its houses, 60 to 100 map changes per ten brain minutes. +/// +/// `FLY_ROW73_TRASHED_CHECKPOINT` (`scout-b3-cerulean-trashed-house`): seed 6, 40 brain minutes +/// in, going through the house's front door. `FLY_ROW73_TICKET_CHECKPOINT` +/// (`scout-b3-post-bill-ticket`): the carry-forward the Cerulean runs started from, in Bill's +/// house with the ticket. The claim from each: the fly is on Route 5 within the budget, and from +/// Bill's house in under half of what main needs. +#[test] +fn row73_the_fly_takes_the_trashed_house_south_to_route_5() { + let rom = skip_without_rom!(); + // Deterministic under the stub: on main the two take 54,442 and 63,880 frames, on the branch + // 52,081 and 27,067. The rotation does stumble through the house on main -- `GO ROUTE` takes + // every door in turn -- so this is the regression guard, and the seam test above is the claim + // main fails. + for (var, budget) in [("FLY_ROW73_TRASHED_CHECKPOINT", 72_000u32), ("FLY_ROW73_TICKET_CHECKPOINT", 48_000)] { + let Some(checkpoint) = row73_checkpoint(var) else { + eprintln!("skipped: no {var}"); + continue; + }; + let mut run = Run::resume(&rom, MacroMode::Macros, &checkpoint); + assert!(run.event(EVENT_GOT_SS_TICKET), "{var}: the checkpoint has the ticket"); + let mut previous = run.map(); + let (mut changes, mut into_the_house) = (0u32, 0u32); + let mut south = None; + for frame in 0..budget { + run.frame(); + let map = run.map(); + if map != previous && map != u32::MAX { + changes += 1; + into_the_house += u32::from(map == CERULEAN_TRASHED_HOUSE); + previous = map; + } + if map == ROUTE_5 { + south = Some(frame); + break; + } + } + let tail: Vec = run.route.iter().rev().take(24).rev().copied().collect(); + eprintln!( + "{var}: Route 5 at {south:?}, {changes} map changes, into the trashed house \ + {into_the_house} times, rank {}, last maps {tail:?}, macros {:?}", + run.adapter.progress().rank, + run.started + ); + assert!(south.is_some(), "{var}: not on Route 5 in {budget} frames: last maps {tail:?}"); + } +}