diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp index 455eb7e731..46420ba7a2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -81,6 +81,7 @@ class PlaceNameMatcher : public OCR::SmallDictionaryMatcher{ {"celadon-city", "Celadon City"}, {"rocket-hideout", "Rocket Hideout"}, {"pokemon-tower", "Pokemon Tower"}, + {"route-16", "Route 16"}, }){ JsonArray names; names.push_back(std::string(name)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h index a81cff6203..d1ab0be7fa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h @@ -47,14 +47,17 @@ bool counts_bike_taps(const RouteStep& step, MoveSpeed speed); bool gets_on_bike(const RouteStep& step, MoveSpeed speed, bool riding); // The console side of select_onto_bike(): presses SELECT and waits it -// out; reads whether the player rides. +// out; reads whether the player rides; waits before reading again. struct BikeSelectCalls{ std::function press_select; std::function riding; + std::function wait_to_read_again; }; // Gets on the registered Bicycle with SELECT, checks the player rides, -// and presses again once if not. Returns whether they ride. +// and presses again once if not. A read on foot is read again first: a +// SELECT can show late, and pressed again then it gets the player off +// (11.01, console B, 2026-11-12). Returns whether they ride. bool select_onto_bike(const BikeSelectCalls& calls); // Whether the player rides the Bicycle, from the screen: the overworld diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp index 583fe96027..840abf76a9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.cpp @@ -87,6 +87,21 @@ StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls){ return StepOutcome{}; } +StepOutcome count_bike_taps_remounting(const RouteStep& step, const BikeTapCalls& calls, const std::function& remount){ + BikeTapCalls remounting = calls; + bool remounted = false; + remounting.tap = [&](int tap){ + const BikeTap result = calls.tap(tap); + if (result.moved || result.interrupt || result.cleared_late || remounted || !remount()){ + return result; + } + remounted = true; + calls.log(std::format("Bike: tap {} of {} didn't move, the player on foot: back on with SELECT, tapping again.", tap, step.tiles)); + return calls.tap(tap); + }; + return count_bike_taps(step, remounting); +} + bool counts_step_taps(const RouteStep& step){ return step.tapped && step.action == RouteAction::WALK && step.tiles > 0 && !step.surfing && !step.warps && step.connection_steps.empty(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h index b58fbf2882..17948483e7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h @@ -68,6 +68,13 @@ constexpr int BLOCKED_TAP_SLACK = 3; // and one more, which may have moved before its battle showed. StepOutcome count_bike_taps(const RouteStep& step, const BikeTapCalls& calls); +// count_bike_taps() on the Bicycle, where a tap that doesn't move may +// find the player on foot: `remount` then says whether they were and got +// back on, and the tap is tapped again, once a leg. On foot a bike tap +// only turned the player, each taken as blocked, and the route replanned +// 9 times (11.01, console B, 2026-11-12 05:42). +StepOutcome count_bike_taps_remounting(const RouteStep& step, const BikeTapCalls& calls, const std::function& remount); + // Whether `step` is walked on foot a tap at a time (RouteStep::tapped), // each a tile, by count_bike_taps() with STEP_TAP_TRIES: an open leg or // one to a wall or onto a spinner, not onto a warp or over a connection. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp index 701d7faf3a..20dcfb5d1f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp @@ -196,6 +196,28 @@ UnitTestResult test_select_onto_bike(){ return true; } +// A SELECT that shows on the screen a read late: the read right after it +// still has the player on foot. Pressed again then, SELECT got them off +// (11.01 ride_bike, console B, 2026-11-12 05:42: "not riding after +// SELECT", then "riding" on foot, and every bike tap after only turned). +UnitTestResult test_select_onto_bike_shown_late(){ + bool on_bike = false; + bool shown = false; + int presses = 0; + BikeSelectCalls calls; + calls.press_select = [&]{ presses++; on_bike = !on_bike; }; + calls.riding = [&]{ + const bool read = shown; + shown = on_bike; + return read; + }; + const bool riding = OverworldWalkSteps::select_onto_bike(calls); + if (!riding || !on_bike || presses != 1){ + return std::format("Read riding {}, on the Bicycle {}, after {} press(es).", riding, on_bike, presses); + } + return true; +} + // A door takes the player off the Bicycle: legs after it go on foot, // until one where the Bicycle may be ridden gets on again. UnitTestResult test_speed_after_door(){ @@ -256,12 +278,42 @@ UnitTestResult test_scroll_over_periodic_floor(){ return true; } +// An open leg of 11 tiles west on the Bicycle from (20, 2), the player +// facing south, found off the Bicycle as it starts (11.01, console B, +// 2026-11-12 05:42: on foot, every bike tap only turned the player, +// "blocked after 0 tiles", and the route replanned 9 times). The tap +// that didn't move finds them on foot, SELECT gets them on, and the leg +// is tapped out from there. +UnitTestResult test_leg_starts_off_bike(){ + SimScript script; + script.on_bike = true; + script.bike_registered = true; + script.off_bike_at_legs = {1}; + OverworldSim sim(field(), at(20, 2), Direction::SOUTH, script); + SimWalkerRules rules; + rules.speed = MoveSpeed::BIKE; + OverworldSimWalker walker(sim, rules); + const RoutePlanning planning{.maps = &field(), .costs = default_route_costs(), .start = at(20, 2), .label = "Sim"}; + const std::string failure = walker.run({open_leg(Direction::WEST, 11, at(9, 2))}, planning); + std::vector log = walker.log(); + log.insert(log.end(), sim.state().log.begin(), sim.state().log.end()); + if (!failure.empty()){ + return failure + log_text(log); + } + if (!(sim.state().position == at(9, 2)) || !sim.state().on_bike){ + return std::format("Ended on {}, riding {}; expected {}, riding.", to_string(sim.state().position), sim.state().on_bike, to_string(at(9, 2))) + log_text(log); + } + return true; +} + const BikeCase OVERWORLD_BIKE_CASES[] = { {.input = {"a tap over a floor that repeats every tile", test_scroll_over_periodic_floor}, .expectation = {"scroll seen at the bottom edge; a turn is not"}}, {.input = {"taps a tile each, one in 12 dropped 60ms apart", test_tap_chains}, .expectation = {"23 of 25 tiles at 60ms; 25 at 100 and 120ms"}}, {.input = {"an open leg of 11 from a start 2 off, counted in taps", test_counted_leg_off_start}, .expectation = {"found against the rock and walked back"}}, {.input = {"SELECT onto the registered Bicycle", test_select_onto_bike}, .expectation = {"one press registered; two and off unregistered"}}, + {.input = {"SELECT onto the Bicycle shown a read late", test_select_onto_bike_shown_late}, .expectation = {"read again, not pressed off"}}, {.input = {"on foot after a door, on again outdoors", test_speed_after_door}, .expectation = {"gets_on_bike(), on_foot()"}}, + {.input = {"a leg on the Bicycle that starts off it", test_leg_starts_off_bike}, .expectation = {"SELECT on at the tap that didn't move, the leg walked"}}, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp index b66999a143..736be580db 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -133,7 +133,7 @@ BikeTap console_bike_tap( // An open leg on the Bicycle, a tap at a time (count_bike_taps()). StepWalk walk_bike_taps( ConsoleHandle& console, ProControllerContext& context, - const RouteStep& step, const OverworldInterruptSet& interrupts + const RouteStep& step, const OverworldInterruptSet& interrupts, PlayerGender player ){ StepWalk out{std::nullopt, current_time(), false, false}; const OverworldInterrupts& watched = step.wild ? interrupts.wild : interrupts.other; @@ -141,7 +141,16 @@ StepWalk walk_bike_taps( calls.tap = [&](int){ return console_bike_tap(console, context, step, watched, BIKE_TAP_TIMING); }; calls.clear = [&](size_t index){ watched[index]->clear(console, context); }; calls.log = [&](const std::string& message){ console.log(message, COLOR_ORANGE); }; - const StepOutcome outcome = count_bike_taps(step, calls); + // On foot if the player's standing sprite reads. + const auto remount = [&]{ + if (!read_facing(console, context, player)){ + return false; + } + console.log("Bike: a tap didn't move and the player is on foot.", COLOR_ORANGE); + get_on_bike(console, context, player); + return true; + }; + const StepOutcome outcome = count_bike_taps_remounting(step, calls, remount); out.stopped = outcome.walked; out.blocked = outcome.blocked; return out; @@ -308,7 +317,7 @@ StepOutcome walk_and_watch( if (counts_step_taps(step)){ walked = walk_step_taps(console, context, step, interrupts, player); }else if (counts_bike_taps(step, speed)){ - walked = walk_bike_taps(console, context, step, interrupts); + walked = walk_bike_taps(console, context, step, interrupts, player); }else{ walked = walk_step(console, context, step, facing, interrupts, speed, player); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index 96e927ee10..dfb77a29e7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -541,6 +541,7 @@ std::optional OverworldSim::hold( const Milliseconds start = m_now; m_holds++; m_last_tap.reset(); + count_bike_leg(direction, duration); if (m_state.screen != SimScreen::OVERWORLD || m_frozen){ stuck_hold(direction); }else if (m_state.on_bike && duration <= MovementMechanics::LONGEST_TAP && drops_bike_tap(start)){ @@ -558,6 +559,7 @@ std::optional OverworldSim::hold( void OverworldSim::tap(Direction direction, Milliseconds duration, Milliseconds release){ const Milliseconds start = m_now; + m_bike_leg_direction.reset(); if (m_state.screen != SimScreen::OVERWORLD || m_frozen || start < m_battle_lockout_end){ stuck_hold(direction); m_last_tap.reset(); @@ -621,17 +623,6 @@ void OverworldSim::hold_on(Direction direction, Milliseconds end){ press.end = end; } -bool OverworldSim::reads_step_tap_as_step(const MapPosition& before, int turn_taps_before){ - const bool moved = !(m_state.position == before); - m_state.moved_step_taps += moved ? 1 : 0; - const bool misread = moved ? m_script.unseen_step_taps.contains(m_state.moved_step_taps) - : m_state.turn_taps > turn_taps_before && m_script.seen_turn_taps.contains(m_state.turn_taps); - if (misread){ - note(moved ? std::format("step tap {} moves the player, read as not moved.", m_state.moved_step_taps) : std::format("turn tap {} only turns the player, read as a step.", m_state.turn_taps)); - } - return moved != misread; -} - bool OverworldSim::drops_turn_tap(){ m_state.turn_taps++; return m_script.dropped_turn_taps.contains(m_state.turn_taps); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 69ca8c3884..2f06646560 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -229,6 +229,12 @@ class OverworldSim{ // When the last Bicycle tap started, and how many came too soon. std::optional m_last_bike_tap; int m_fast_bike_taps = 0; + // A hold of `direction` for `duration`: counts the leg a tap on the + // Bicycle starts (SimState::bike_legs), and takes the player off the + // Bicycle if SimScript::off_bike_at_legs names it. + void count_bike_leg(Direction direction, Milliseconds duration); + // The way of the last Bicycle tap, unless another press came since. + std::optional m_bike_leg_direction; // When the last tap that stepped started. std::optional m_last_step_tap; // The end of the lockout after the last battle. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h index 8222a0976a..d057ae3c4e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h @@ -80,6 +80,12 @@ struct SimScript{ // one leaves the player where they were, with no fade, as a wall would // (the warp no-op fault class, PokemonFRLG_AutoStoryFaultSweep_Tests.cpp). std::set dead_warp_maps; + // Fault injection: legs on the Bicycle counted out a tap at a time + // (SimState::bike_legs), by number from 1, that start with + // the player off the Bicycle: the mount state lost. On 11.01 a second + // SELECT took the player off, and every bike tap after only turned + // them (console B, 2026-11-12 05:42). + std::set off_bike_at_legs; // The player rides the Bicycle: a tap facing another way takes a step // too, a hold through a turn loses no tile // (MovementMechanics::BIKE_TAP_ONLY_TURNS), and no step tap is @@ -149,6 +155,10 @@ struct SimState{ int step_taps_ignored = 0; // Walker step taps that moved the player (SimScript::unseen_step_taps). int moved_step_taps = 0; + // Legs on the Bicycle counted out a tap at a time: taps on it, each + // a way other than the last's, or after another press + // (SimScript::off_bike_at_legs). + int bike_legs = 0; std::vector trainers_beaten; // Things the walker did that the game wouldn't let pass: D-pad holds // under a battle, a trainer's battle fled, a battle fought that wasn't diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp index 97f9fb3800..16ecfd42be 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp @@ -23,6 +23,18 @@ namespace PokemonFRLG{ using namespace MovementMechanics; using namespace OverworldWalkSteps; +namespace{ + +// select_onto_bike()'s side on `sim`. +BikeSelectCalls sim_select_calls(OverworldSim& sim){ + BikeSelectCalls calls; + calls.press_select = [&sim]{ sim.use_field(SimField::BIKE_SELECT); }; + calls.riding = [&sim]{ return sim.state().on_bike; }; + return calls; +} + +} // namespace + bool OverworldSim::drops_bike_tap(Milliseconds start){ const bool fast = m_last_bike_tap && start - *m_last_bike_tap < MovementMechanics::BIKE_TAP_DROP_PERIOD; @@ -53,6 +65,29 @@ bool OverworldSim::press_select(){ return true; } +bool OverworldSim::reads_step_tap_as_step(const MapPosition& before, int turn_taps_before){ + const bool moved = !(m_state.position == before); + m_state.moved_step_taps += moved ? 1 : 0; + const bool misread = moved ? m_script.unseen_step_taps.contains(m_state.moved_step_taps) + : m_state.turn_taps > turn_taps_before && m_script.seen_turn_taps.contains(m_state.turn_taps); + if (misread){ + note(moved ? std::format("step tap {} moves the player, read as not moved.", m_state.moved_step_taps) : std::format("turn tap {} only turns the player, read as a step.", m_state.turn_taps)); + } + return moved != misread; +} + +void OverworldSim::count_bike_leg(Direction direction, Milliseconds duration){ + const bool bike_tap = m_state.on_bike && duration <= MovementMechanics::LONGEST_TAP; + if (bike_tap && m_bike_leg_direction != direction){ + m_state.bike_legs++; + if (m_script.off_bike_at_legs.contains(m_state.bike_legs)){ + m_state.on_bike = false; + note(std::format("bike leg {} starts off the Bicycle.", m_state.bike_legs)); + } + } + m_bike_leg_direction = bike_tap ? std::optional(direction) : std::nullopt; +} + BikeTap OverworldSimWalker::bike_tap(const RouteStep& step){ const MapPosition before = m_sim.state().position; const std::vector& ints = interrupts(step); @@ -74,9 +109,16 @@ StepOutcome OverworldSimWalker::walk_bike_taps(const RouteStep& step){ calls.tap = [&](int){ return bike_tap(step); }; calls.clear = [&](size_t index){ clear(ints[index]); }; calls.log = [&](const std::string& message){ m_log.push_back(message); }; + const auto remount = [&]{ + if (m_sim.state().on_bike){ + return false; + } + m_log.push_back("Bike: a tap didn't move and the player is on foot: SELECT onto the Bicycle."); + return select_onto_bike(sim_select_calls(m_sim)); + }; m_leg_start = m_sim.state().time; m_leg_dark = m_sim.state().dark; - return count_bike_taps(step, calls); + return count_bike_taps_remounting(step, calls, remount); } BikeTap OverworldSimWalker::step_tap(const RouteStep& step, int tap){ @@ -112,10 +154,7 @@ StepOutcome OverworldSimWalker::walk_step_taps(const RouteStep& step){ // walk_overworld_route_with_recovery() does. StepOutcome OverworldSimWalker::walk(const RouteStep& step, std::optional facing){ if (m_rules.get_back_on_bike && gets_on_bike(step, m_rules.speed, m_riding)){ - BikeSelectCalls select; - select.press_select = [&]{ m_sim.use_field(SimField::BIKE_SELECT); }; - select.riding = [&]{ return m_sim.state().on_bike; }; - if (!select_onto_bike(select)){ + if (!select_onto_bike(sim_select_calls(m_sim))){ fail("get_on_bike(): not on the Bicycle after SELECT twice. Is it registered?"); } m_riding = true; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index b3f5bed738..1c37503a94 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -231,6 +231,12 @@ bool select_onto_bike(const BikeSelectCalls& calls){ if (calls.riding()){ return true; } + if (calls.wait_to_read_again){ + calls.wait_to_read_again(); + } + if (calls.riding()){ + return true; + } } return false; } @@ -256,6 +262,9 @@ void get_on_bike(ConsoleHandle& console, ProControllerContext& context, PlayerGe console.log(riding ? "Bike: riding." : "Bike: not riding after SELECT.", riding ? COLOR_BLACK : COLOR_ORANGE); return riding; }; + calls.wait_to_read_again = [&]{ + pbf_wait(context, BIKE_SELECT_SETTLE); + }; console.log("Bike: SELECT (MINUS) onto the Bicycle."); if (!select_onto_bike(calls)){ OperationFailedExceptionWithScreenshot::fire( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 38b6dd563a..cf577be935 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -102,6 +102,7 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){ add_tests_AutoStoryVermilion(database); add_tests_AutoStoryVermilionGym(database); add_tests_AutoStoryCeladon(database); + add_tests_AutoStorySnorlax(database); } void add_tests(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index ac6443b5eb..9a07917ee1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -260,7 +260,8 @@ Outcome battle(StoryEnv& env, const StoryStep& step){ step.name, env.supplies.trainer, battle_risk_name(env.supplies.risk) )); } - const BattleEnd end = fight_battle(env.console, env.context, env.supplies, BattleKind::TRAINER, env.checks, env.language); + const BattleKind kind = arg(step, "run") ? BattleKind::WILD_RUN : BattleKind::TRAINER; + const BattleEnd end = fight_battle(env.console, env.context, env.supplies, kind, env.checks, env.language); env.supplies.foes.clear(); env.supplies.trainer.clear(); env.supplies.foe_out.clear(); @@ -324,6 +325,11 @@ const std::vector& story_maps(){ // The one ball the story picks up in its way: B2F's MOON STONE // blocks column 2 of the arrow floor (09.02's moon_stone). flags.insert("FLAG_HIDE_ROCKET_HIDEOUT_B2F_MOON_STONE"); + // Route 16's Snorlax (31, 13), gone once 11.01 has played the POKE + // FLUTE and run: the routes after it go over its tile. None before + // it does (10.01 goes north by the Cut tree), and 11.01 walks up to + // it from the east. + flags.insert("FLAG_HIDE_ROUTE_16_SNORLAX"); return overworld_maps(flags); }(); return maps; @@ -360,6 +366,7 @@ std::string save_card_place(const std::string& map){ {"CeladonCity", "celadon-city"}, {"RocketHideout", "rocket-hideout"}, {"PokemonTower", "pokemon-tower"}, + {"Route16", "route-16"}, }; for (const auto& [prefix, place] : PLACES){ if (map == prefix || map.rfind(prefix + "_", 0) == 0){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp index 4a5095fd38..432b29894e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -32,6 +32,10 @@ * - UNSEEN_STEP: each step tap that moved the player, one at a time, read * by the walker as not moved: it must not tap again into a second * tile (09.02 Rocket Hideout B2F, console B, 2026-11-11 15:03 and 15:36). + * - MOUNT_LOST: rows that ride, with ride_bike played on the sim, each + * leg counted out on the Bicycle, one at a time, starting with the + * player off it: the walker must get back on, not replan its legs on + * foot at the Bicycle's taps (11.01, console B, 2026-11-12 05:42). * * Not swept here: a missed fade, which needs a knob in OverworldSim; a * battle's opening at a step's start, which needs one in OverworldStepSim; @@ -63,9 +67,11 @@ #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.h" #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryFieldMoves.h" #include "PokemonFRLG_AutoStoryHideoutLift.h" +#include "PokemonFRLG_AutoStoryItemUse.h" #include "PokemonFRLG_AutoStoryRowSim.h" #include "PokemonFRLG_AutoStoryTable.h" #include "PokemonFRLG_AutoStoryFaultSweep_Tests.h" @@ -88,6 +94,7 @@ enum class FaultClass{ LOST_TAP, WARP_NO_OP, UNSEEN_STEP, + MOUNT_LOST, }; std::string_view fault_class_name(FaultClass fault){ switch (fault){ @@ -107,6 +114,8 @@ std::string_view fault_class_name(FaultClass fault){ return "warp no-op"; case FaultClass::UNSEEN_STEP: return "step tap read as not moved"; + case FaultClass::MOUNT_LOST: + return "off the Bicycle at a bike leg"; } return "?"; } @@ -117,6 +126,10 @@ const std::map KNOWN_FAILING{ "below_oak on Route 1 gives up after 9 stops part-way (seeds 16, 30): count stops that make no progress, not every battle"}, {"PokemonFRLG::AutoStory - Fault sweep: 10.06, scene end pose", "below_fuji_house plans from (4, 7), where Mr. Fuji's script warps the player (warp 4, 7, exact); from a tile off, no wall in his house funnels the walk onto (3, 4): legs that re-anchor, if the console shows the warp can land elsewhere"}, + {"PokemonFRLG::AutoStory - Fault sweep: 11.01, warp no-op", + "fly_celadon: a Fly that doesn't leave Lavender Town goes unseen, and east_of_snorlax walks from Lavender to Route 16 by Routes 8 and 7 instead: check the fly lands on its town's tile (FlyTown::landing) before the step ends"}, + {"PokemonFRLG::AutoStory - Fault sweep: 08.03, off the Bicycle at a bike leg", + "riding with no fault, route7_underground_exit's warp to UndergroundPath_EastEntrance is not confirmed on the sim (the screen after the fade reads as before the hold): the sim's warp off the Bicycle, before this class can sweep 08.03"}, }; // The land encounter rates of the maps the story walks (pokefirered @@ -152,6 +165,8 @@ const std::vector& sweep_maps(){ const std::vector all = overworld_maps(); std::set flags = map_flag_set(all, "after_hall_of_fame"); flags.merge(map_flag_set(all, "new_game")); + // As story_maps(): Route 16's Snorlax gone (11.01's flute). + flags.insert("FLAG_HIDE_ROUTE_16_SNORLAX"); std::vector flagged = overworld_maps(flags); flagged.push_back(rocket_hideout_lift_room()); flagged.push_back(department_store_lift_room()); @@ -204,6 +219,7 @@ struct RowRun{ int wild_battles = 0; Milliseconds in_wild_battles{0}; int moved_step_taps = 0; + int bike_legs = 0; }; // Where a stubbed step leaves the player instead of its pose_after: by step index. @@ -272,6 +288,20 @@ bool run_row_step( return let_pass; } +// ride_bike, which the row's sim stubs, played on `sim` when `script` has +// the Bicycle registered (MOUNT_LOST). +void play_ride_bike(OverworldSim& sim, const SimScript& script, const StoryStep& step){ + if (script.bike_registered && step.kind == StoryStepKind::GAME && step.action == RIDE_BIKE_VARIANT){ + sim.use_field(SimField::BIKE_SELECT); + } +} + +// `script` for a new sim after `state`'s, riding if that one was. +SimScript still_riding(SimScript script, const SimState& state){ + script.on_bike = state.on_bike; + return script; +} + // Row `row` on the sim with `script`, from its start. After a step the sim // does not play, the player is put on its pose_after, or on `landings`' // tile for it, the program going on from the pose_after either way. A @@ -294,10 +324,12 @@ RowRun run_row( out.wild_battles += state.wild_battles; out.in_wild_battles += state.in_wild_battles; out.moved_step_taps += state.moved_step_taps; + out.bike_legs += state.bike_legs; }; for (size_t c = 0; c < row.steps.size() && out.failure.empty(); c++){ const StoryStep& step = row.steps[c]; const bool let_pass = run_row_step(out, *sim, at, row, c, scripted); + play_ride_bike(*sim, script, step); if (!out.failure.empty() || (sim_plays(step) && !let_pass) || !step.pose_after){ continue; } @@ -313,7 +345,7 @@ RowRun run_row( } if (!(sim->state().position == land) || hidden){ add(sim->state()); - sim = std::make_unique(maps, land, at.facing.value_or(sim->state().facing), script); + sim = std::make_unique(maps, land, at.facing.value_or(sim->state().facing), still_riding(script, sim->state())); } } if (out.failure.empty() && !sim->state().violations.empty()){ @@ -615,6 +647,34 @@ UnitTestResult sweep_unseen_step(Logger& logger, const StoryCheckpoint& row, con return sweep_result(logger, FaultClass::UNSEEN_STEP, row.id, (size_t)clean.moved_step_taps, failures); } +// Row `row` riding: the Bicycle registered and ride_bike played on the +// sim (run_row()). Each leg counted out on the Bicycle, one at a time, +// starts with the player off it, counted across the row's sims. A row +// that rides no such leg is not swept. +UnitTestResult sweep_mount_lost(Logger& logger, const StoryCheckpoint& row){ + SimScript riding; + riding.bike_registered = true; + const RowRun clean = run_row(row, riding); + if (clean.bike_legs == 0){ + logger.log(std::format("Fault sweep {}: not swept, the row rides no leg counted out on the Bicycle.", row.id)); + return true; + } + std::vector failures; + if (!clean.failure.empty()){ + failures.push_back({"", "riding, no fault", clean.failure}); + return sweep_result(logger, FaultClass::MOUNT_LOST, row.id, 0, failures); + } + for (int leg = 1; leg <= clean.bike_legs; leg++){ + SimScript script = riding; + script.off_bike_at_legs = {leg}; + const std::string stopped = differs(run_row(row, script, {}, clean.scripted), clean); + if (!stopped.empty()){ + failures.push_back({"", std::format("bike leg {} starts off the Bicycle", leg), stopped}); + } + } + return sweep_result(logger, FaultClass::MOUNT_LOST, row.id, (size_t)clean.bike_legs, failures); +} + // A fault class swept over row `row` (empty in FAULT_SWEEP_CASES: each // row with a start). struct FaultSweepInput{ @@ -688,6 +748,8 @@ class Test_AutoStoryFaultSweep : public UnitTest{ return sweep_warp_no_op(logger, m_row, clean); case FaultClass::UNSEEN_STEP: return sweep_unseen_step(logger, m_row, clean); + case FaultClass::MOUNT_LOST: + return sweep_mount_lost(logger, m_row); } return true; } @@ -708,6 +770,7 @@ const FaultSweepCase FAULT_SWEEP_CASES[] = { {.input = {.fault = FaultClass::LOST_TAP}, .expectation = {}}, {.input = {.fault = FaultClass::WARP_NO_OP}, .expectation = {}}, {.input = {.fault = FaultClass::UNSEEN_STEP}, .expectation = {}}, + {.input = {.fault = FaultClass::MOUNT_LOST}, .expectation = {}}, }; std::optional talk_battle_hide_flag(const StoryStep& step){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h new file mode 100644 index 0000000000..589d16ce86 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h @@ -0,0 +1,41 @@ +/* FRLG AutoStory Plan Golden, Segment 11 + * + * From: https://github.com/PokemonAutomation/ + * + * The golden's lines from segment 11 on, after + * PokemonFRLG_AutoStoryPlanGolden10.h's. The test reads FRLG_PLAN_GOLDEN, + * FRLG_PLAN_GOLDEN_10, then these. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryPlanGolden11_H +#define PokemonAutomation_PokemonFRLG_AutoStoryPlanGolden11_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +// The stored plan lines from segment 11 on, after FRLG_PLAN_GOLDEN_10's. +inline constexpr std::string_view FRLG_PLAN_GOLDEN_11[] = { + "11.01 out_of_fuji_house from LavenderTown_VolunteerPokemonHouse (3, 4) facing north to LavenderTown (10, 12) facing south", + "11.01 walk east 1 (to wall) -> LavenderTown_VolunteerPokemonHouse (4, 4) [walk only]", + "11.01 walk south 4 (warp) -> LavenderTown (10, 12) [walk only]", + "11.01 east_of_snorlax_wall from CeladonCity (48, 12) facing south to Route16 (33, 14) facing west", + "11.01 walk west 25 -> CeladonCity (23, 12)", + "11.01 walk south 4 (to wall) -> CeladonCity (23, 16)", + "11.01 walk west 19 (to wall) -> CeladonCity (4, 16)", + "11.01 walk south 8 (to wall) -> CeladonCity (4, 24)", + "11.01 walk west 19 (to wall) -> Route16 (33, 14) [connection 5]", + "11.01 east_of_snorlax from Route16 (33, 14) facing west to Route16 (32, 13) facing west", + "11.01 walk north 1 -> Route16 (33, 13)", + "11.01 walk west 1 -> Route16 (32, 13)", + "11.01 east_of_cycling_road_gate from Route16 (32, 13) facing west to Route16 (28, 13) facing west", + "11.01 walk west 4 -> Route16 (28, 13)", +}; + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h index dcf1f4092a..791b20785a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows_Tests.h @@ -28,6 +28,8 @@ void add_tests_AutoStoryCeladon(UnitTestDatabase& database); void add_tests_AutoStoryLavender(UnitTestDatabase& database); // Rows 10.01 to 10.06 on the overworld sim (PokemonFRLG_AutoStoryTower_Tests.cpp). void add_tests_AutoStoryTower(UnitTestDatabase& database); +// Row 11.01 on the overworld sim (PokemonFRLG_AutoStorySnorlax_Tests.cpp). +void add_tests_AutoStorySnorlax(UnitTestDatabase& database); } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp index 7ef168f77d..90444c3e15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -139,7 +139,7 @@ class Test_RunPlan : public UnitTest{ const RunPlanScenario m_scenario; }; -const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"; +const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -230,11 +230,11 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Gift RNG off: 04.03 is passed over", .first = "04.01"}, - .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"}, + .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"}, }, { .input = {.name = "Gift RNG off: 04.03 runs when started at", .first = "04.03"}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"}, }, { .input = { .name = "Gift RNG: started at 04.03, from the save beside the salesman", @@ -273,7 +273,7 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Starter RNG alone: 04.03 runs when started at", .first = "04.03", .handoffs = {.starter_rng = true}}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01"}, }, { .input = { .name = "Starter RNG first, with both on", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp new file mode 100644 index 0000000000..87d34466a5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp @@ -0,0 +1,214 @@ +/* AutoStory Snorlax Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Row 11.01 on the overworld sim: from Mr. Fuji's house (10.06) out to + * Lavender Town, a Fly to Celadon City, west on the Bicycle to Route 16's + * Snorlax, and over its tile once it is gone to the Cycling Road gate. + * The flute's wild battle is the script's: the sim goes on from where the + * table says it ends, with the Snorlax hidden (FLAG_HIDE_ROUTE_16_SNORLAX, + * as story_maps() has it). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_AutoStoryEvents.h" +#include "PokemonFRLG_AutoStoryFieldMoves.h" +#include "PokemonFRLG_AutoStoryRowSim.h" +#include "PokemonFRLG_AutoStoryRows_Tests.h" +#include "PokemonFRLG_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct AutoStorySnorlaxInput{ + std::string name; + std::function body; +}; + +struct AutoStorySnorlaxExpectation{ +}; + +struct AutoStorySnorlaxCase{ + AutoStorySnorlaxInput input; + AutoStorySnorlaxExpectation expectation; +}; + +class Test_AutoStorySnorlax : public UnitTest{ +public: + explicit Test_AutoStorySnorlax(AutoStorySnorlaxCase test_case) + : UnitTest(std::format("PokemonFRLG::AutoStory - Simulation: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_case.input.body(); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + AutoStorySnorlaxCase m_case; +}; + +const StoryCheckpoint& checkpoint(std::string_view id){ + const std::vector& rows = story_checkpoints(); + const auto row = std::find_if(rows.begin(), rows.end(), [&](const StoryCheckpoint& data){ return data.id == id; }); + if (row == rows.end()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No checkpoint {}.", id)); + } + return *row; +} + +// The maps as the story leaves them by 11.01 (as the Tower's rows), with +// the Snorlax on Route 16 unless `snorlax_gone`. +std::vector story_maps_by_11_01(bool snorlax_gone){ + const std::vector all = overworld_maps(); + std::set flags = map_flag_set(all, "after_hall_of_fame"); + flags.merge(map_flag_set(all, "new_game")); + flags.erase("FLAG_HIDE_VERMILION_CITY_OAKS_AIDE"); + if (snorlax_gone){ + flags.insert("FLAG_HIDE_ROUTE_16_SNORLAX"); + }else{ + flags.erase("FLAG_HIDE_ROUTE_16_SNORLAX"); + } + return overworld_maps(flags); +} + +// The Snorlax's battle: a BATTLE step with no trainer, which the sim +// can't play; the table says where it ends. +bool scripted(const StoryStep& step){ + return step.kind == StoryStepKind::BATTLE && Pokemon::story_arg(step.args, "trainer").empty(); +} + +// 11.01: out of Mr. Fuji's house, Fly to Celadon, the Bicycle to the +// Snorlax with no trainer fought, and, the Snorlax gone, on west over its +// tile to east of the Cycling Road gate's door. +UnitTestResult test_snorlax(){ + const StoryCheckpoint& row = checkpoint("11.01"); + StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); + const std::vector maps = story_maps_by_11_01(false); + if (std::none_of(maps.begin(), maps.end(), [](const MapData& map){ + return map.name == "Route16" && std::any_of(map.objects.begin(), map.objects.end(), [](const MapObject& object){ + return object.x == 31 && object.y == 13; + }); + })){ + return "11.01: the Snorlax isn't at (31, 13) on Route 16 before the flute."; + } + auto sim = std::make_unique(maps, MapPosition{at.map, at.tile}, *at.facing); + for (const StoryStep& step : row.steps){ + if (scripted(step)){ + if (!sim->state().trainers_beaten.empty() || !sim->state().violations.empty()){ + return std::format("11.01: a battle or a violation before {}.", step.name); + } + at = *story_pose(Pokemon::pose_of(*step.pose_after)); + sim = std::make_unique(story_maps_by_11_01(true), MapPosition{at.map, at.tile}, *at.facing); + continue; + } + if (const std::string failure = row_step_on_sim(*sim, at, step, row.id); !failure.empty()){ + return std::format("11.01: ended on {}; {}", to_string(sim->state().position), failure); + } + } + if (!sim->state().trainers_beaten.empty() || !sim->state().violations.empty()){ + return "11.01: a battle or a violation after the Snorlax."; + } + const MapPosition end{"Route16", {28, 13}}; + if (!(sim->state().position == end)){ + return std::format("11.01: ended on {}, not {}.", to_string(sim->state().position), to_string(end)); + } + return true; +} + +// 11.01's Snorlax battle runs (the "run" arg), and only that battle. +UnitTestResult test_snorlax_battle_runs(){ + for (const StoryStep& step : checkpoint("11.01").steps){ + if (step.kind != StoryStepKind::BATTLE){ + continue; + } + if (!Pokemon::story_arg(step.args, "run")){ + return std::format("11.01: {} fights; expected it to run.", step.name); + } + } + for (const StoryCheckpoint& row : story_checkpoints()){ + for (const StoryStep& step : row.steps){ + if (step.kind == StoryStepKind::BATTLE && row.id != "11.01" && Pokemon::story_arg(step.args, "run")){ + return std::format("{}: {} runs; only 11.01's Snorlax should.", row.id, step.name); + } + } + } + return true; +} + +// 11.01's Fly names the Pidgey, not a slot, and flies with the slot the +// party reads it in: the third here, the second with the Oddish gone, +// none without a Pidgey. +UnitTestResult test_fly_finds_pidgey(){ + const StoryCheckpoint& row = checkpoint("11.01"); + const auto fly = std::find_if(row.steps.begin(), row.steps.end(), [](const StoryStep& step){ + return parse_fly_step(step).has_value(); + }); + if (fly == row.steps.end() || parse_fly_step(*fly)->species != "pidgey" || fly->args.contains("slot")){ + return "11.01: expected a Fly by the Pidgey's species, with no slot."; + } + const FlyPlan plan = *parse_fly_step(*fly); + const auto party = [](std::vector species){ + return MemberReader([species](size_t slot) -> std::optional{ + if (slot >= species.size()){ + return std::nullopt; + } + return MemberInfo{.species = species[slot], .level = 30}; + }); + }; + if (plan.party_slot(party({"blastoise", "oddish", "pidgey", "eevee"})) != size_t(2) + || plan.party_slot(party({"blastoise", "pidgey"})) != size_t(1) + || plan.party_slot(party({"blastoise", "oddish"})).has_value() + ){ + return "11.01: the Fly doesn't find the Pidgey's slot as the party reads it."; + } + StoryStep both = *fly; + both.args["slot"] = int64_t(3); + if (parse_fly_step(both)){ + return "A Fly naming both a slot and a species should not parse."; + } + return true; +} + +const AutoStorySnorlaxCase AUTO_STORY_SNORLAX_CASES[] = { + {.input = {"11.01 Fly to Celadon, Route 16's Snorlax, and over its tile to the Cycling Road gate", test_snorlax}, .expectation = {}}, + {.input = {"11.01 runs from the Snorlax's battle", test_snorlax_battle_runs}, .expectation = {}}, + {.input = {"11.01 flies with the Pidgey found by species", test_fly_finds_pidgey}, .expectation = {}}, +}; + +} // namespace + + +void add_tests_AutoStorySnorlax(UnitTestDatabase& database){ + for (const auto& item : AUTO_STORY_SNORLAX_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp index 9836fdb983..092a229670 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -196,6 +196,10 @@ std::span story_action_specs(){ .key = "use_items", .type = Pokemon::StoryArgType::ITEMS, .required = false, .fallback = std::vector(), .why = "items used on the lead from the first turn, in order, before any attack (X Specials)", }); + spec.args.push_back(Pokemon::StoryArgSpec{ + .key = "run", .type = Pokemon::StoryArgType::BOOLEAN, .required = false, .fallback = false, + .why = "run from a scripted wild battle (Route 16's Snorlax) instead of fighting it", + }); } for (Pokemon::StoryActionSpec spec : movement_variant_specs(builtin)){ specs.push_back(std::move(spec)); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 2b85a7172e..4a47f846c4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -36,6 +36,7 @@ #include "PokemonFRLG_AutoStoryPcStorage.h" #include "PokemonFRLG_AutoStoryPlanGolden.h" #include "PokemonFRLG_AutoStoryPlanGolden10.h" +#include "PokemonFRLG_AutoStoryPlanGolden11.h" #include "PokemonFRLG_AutoStoryMoveData.h" #include "PokemonFRLG_AutoStoryStepTable.h" #include "PokemonFRLG_AutoStoryTable.h" @@ -282,8 +283,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po // before leaves the player, and adds the plans to `golden`. UnitTestResult chain_story_routes(std::vector& golden){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 47 || checkpoints[0].start){ - return "Expected 47 checkpoints, the first from a new game."; + if (checkpoints.size() != 48 || checkpoints[0].start){ + return "Expected 48 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -312,9 +313,9 @@ UnitTestResult test_routes_and_chain(){ // Every story route's plan against the stored copy in // PokemonFRLG_AutoStoryPlanGolden.h. A change that should not alter any // plan must leave this byte-identical. To regenerate after an intended plan -// change: run this suite, and replace the lines of FRLG_PLAN_GOLDEN and -// FRLG_PLAN_GOLDEN_10 (segment 10 on) with the lines the failure lists -// after "GOLDEN|". +// change: run this suite, and replace the lines of FRLG_PLAN_GOLDEN, +// FRLG_PLAN_GOLDEN_10 (segment 10) and FRLG_PLAN_GOLDEN_11 (segment 11 on) +// with the lines the failure lists after "GOLDEN|". UnitTestResult test_golden_plans(){ std::vector actual; UnitTestResult result = chain_story_routes(actual); @@ -323,6 +324,7 @@ UnitTestResult test_golden_plans(){ } std::vector golden(std::begin(FRLG_PLAN_GOLDEN), std::end(FRLG_PLAN_GOLDEN)); golden.insert(golden.end(), std::begin(FRLG_PLAN_GOLDEN_10), std::end(FRLG_PLAN_GOLDEN_10)); + golden.insert(golden.end(), std::begin(FRLG_PLAN_GOLDEN_11), std::end(FRLG_PLAN_GOLDEN_11)); const size_t stored = golden.size(); size_t first_diff = 0; while (first_diff < actual.size() && first_diff < stored && actual[first_diff] == golden[first_diff]){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-11.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-11.01.plan.json new file mode 100644 index 0000000000..c5d04be578 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-11.01.plan.json @@ -0,0 +1,96 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "11.01", + "title": "Fly to Celadon City, wake Route 16's Snorlax with the POKE FLUTE and run from it", + "start": {"map": "LavenderTown_VolunteerPokemonHouse", "tiles": [[3, 4]], "facing": "north"}, + "events": [ + { + "id": "out_of_fuji_house", + "kind": "route", + "action": "run", + "args": { + "target": {"map": "LavenderTown", "tiles": [[10, 12]], "facing": "south"} + }, + "why": "from below Mr. Fuji (10.06) down and out of his house's door (4, 7) onto Lavender Town below its door (10, 11), where Fly works" + }, + { + "id": "fly_celadon", + "kind": "game_action", + "action": "fly", + "args": { + "town": "CeladonCity", + "species": "pidgey" + }, + "declared_after": {"map": "CeladonCity", "tiles": [[48, 12]], "facing": "south"}, + "why": "the Pidgey (Fly, 10.01), found in the party by its summary's species, flies to Celadon City, landing below the Pokemon Center's door (48, 11); pokeguy flies there from Mr. Fuji's at 1:11:30" + }, + { + "id": "ride_bike", + "kind": "game_action", + "action": "ride_bike", + "why": "on the BICYCLE with SELECT (registered in 08.03)" + }, + { + "id": "east_of_snorlax_wall", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16", "tiles": [[33, 14]], "facing": "west"} + }, + "why": "west across Celadon and out onto Route 16's east end (Celadon's row 24 is the route's row 14), to the wall (32, 14) below the Snorlax's row: an approach to an A press ends on its tile, and held along row 13 the bike can end a row off, against the walls at (30..32, 12) or (30..32, 14)" + }, + { + "id": "east_of_snorlax", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16", "tiles": [[32, 13]], "facing": "west"} + }, + "why": "a tile north and a tile west from the wall, to face the Snorlax (31, 13), which with those walls closes the way west" + }, + { + "id": "wake_snorlax", + "kind": "talk", + "why": "Route16_EventScript_Snorlax: with FLAG_GOT_POKE_FLUTE, \"Want to use the POKE FLUTE?\"" + }, + { + "id": "use_poke_flute", + "kind": "answer", + "why": "YES: the flute plays, the Snorlax wakes and attacks (setwildbattle SPECIES_SNORLAX, 30; dowildbattle)" + }, + { + "id": "run_from_snorlax", + "kind": "battle", + "args": { + "foes": ["snorlax"], + "run": true + }, + "declared_after": {"map": "Route16", "tiles": [[32, 13]], "facing": "west"}, + "why": "Snorlax Lv30, a wild battle; RUN as pokeguy does (1:11:57; user's call: no RNG, no catch). B_OUTCOME_RAN goes on to \"SNORLAX calmed down... returned to the mountains\" (Route16_EventScript_FoughtSnorlax), and FLAG_HIDE_ROUTE_16_SNORLAX keeps it away" + }, + { + "id": "east_of_cycling_road_gate", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16", "tiles": [[28, 13]], "facing": "west"} + }, + "why": "west along row 13 over the Snorlax's tile (story_maps() has it gone) to a tile east of the Cycling Road gate's door (27, 13); pokeguy leaves the LEFTOVERS hidden there" + } + ] + }, + "execution": { + "menu": "full", + "lead": "after_brock", + "notes": { + "checkpoint": [ + "From Mr. Fuji's house (10.06), PokeGuy's way (1:11:24 to 1:12:00): Fly to Celadon, bike out onto Route 16 and wake the Snorlax (31, 13) with the POKE FLUTE (Route16 map.json, scripts.inc). He runs from it (Lv30, base Speed 30: the lead outspeeds it, so RUN gets away on the first try). The Snorlax stands on a hidden LEFTOVERS (FLAG_HIDDEN_ITEM_ROUTE16_LEFTOVERS), which pokeguy leaves.", + "The checkpoint stops east of the Cycling Road gate (Route16_NorthEntrance_1F), saved there: Route 16's west part has six Bikers (sight 1, LOOK_AROUND) on both sides of rows 11..15 with no way past out of every one's sight, and Cycling Road (Route 17) has no map yet. With the BICYCLE (FLAG_GOT_BICYCLE) the gate's no-pedestrians triggers are off (VAR_TEMP_1 1).", + "The save is on Route 16, ROUTE 16 on the save card." + ] + } + }, + "metadata": {"phase": "testing"} +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 690f3f754a..4680d1b630 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2144,6 +2144,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTower_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMart.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMartBuys.h @@ -2174,6 +2175,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPcStorage_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden10.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryResources.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryResources.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryResources_Tests.cpp