From ad9c1b63960655d2632f321ac08532466d6cb122 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 23:25:46 -0800 Subject: [PATCH 1/7] PokemonFRLG: 11.01, Fly to Celadon and run from Route 16's Snorlax From Mr. Fuji's house (10.06): out to Lavender, Fly to Celadon, bike to Route 16 and wake the Snorlax with the POKE FLUTE, then run from it as pokeguy does. A battle step's new "run" arg runs from a scripted wild battle. The save is on Route 16 (save card place added). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Menus/PokemonFRLG_SaveCardReader.cpp | 1 + .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 + .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 4 +- .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 2 + .../PokemonFRLG_AutoStoryPlanGolden11.h | 36 ++++ .../PokemonFRLG_AutoStoryRows_Tests.h | 2 + .../PokemonFRLG_AutoStoryRunPlan_Tests.cpp | 8 +- .../PokemonFRLG_AutoStorySnorlax_Tests.cpp | 171 ++++++++++++++++++ .../PokemonFRLG_AutoStoryStepTable.cpp | 4 + .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 12 +- .../AutoStory/StoryData/frlg-11.01.plan.json | 78 ++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 12 files changed, 311 insertions(+), 10 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-11.01.plan.json 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/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index d1fb785988..12467bccfa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -327,6 +327,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 53a1122453..293d82718d 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(); @@ -360,6 +361,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..8679778fb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -117,6 +117,8 @@ 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"}, }; // The land encounter rates of the maps the story walks (pokefirered 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..7ee811462e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h @@ -0,0 +1,36 @@ +/* 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 from CeladonCity (48, 12) facing south to Route16 (32, 13) 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 7 -> CeladonCity (4, 23)", + "11.01 walk west 20 -> Route16 (32, 13) [connection 5]", +}; + +} // 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..2e21bac425 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp @@ -0,0 +1,171 @@ +/* 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, saved beside its tile once it is gone. The flute's wild + * battle is the script's: the sim takes the table's word for where it ends. + * + */ + +#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_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), the +// Snorlax still on Route 16. +std::vector maps_before_flute(){ + 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"); + 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, standing beside its tile after the +// battle. +UnitTestResult test_snorlax(){ + const StoryCheckpoint& row = checkpoint("11.01"); + StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); + const std::vector maps = maps_before_flute(); + 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(maps, 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", {32, 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; +} + +const AutoStorySnorlaxCase AUTO_STORY_SNORLAX_CASES[] = { + {.input = {"11.01 Fly to Celadon and Route 16's Snorlax", test_snorlax}, .expectation = {}}, + {.input = {"11.01 runs from the Snorlax's battle", test_snorlax_battle_runs}, .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 1629bdc815..4a1cb3164c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryStepTable.cpp @@ -195,6 +195,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 eb41abb728..9a07073af1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -35,6 +35,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" @@ -281,8 +282,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++){ @@ -311,9 +312,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); @@ -322,6 +323,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..12805c5579 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-11.01.plan.json @@ -0,0 +1,78 @@ +{ + "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", + "slot": 3 + }, + "declared_after": {"map": "CeladonCity", "tiles": [[48, 12]], "facing": "south"}, + "why": "the Pidgey (Fly, 10.01) 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", + "kind": "route", + "action": "bike", + "args": { + "target": {"map": "Route16", "tiles": [[32, 13]], "facing": "west"} + }, + "why": "west across Celadon and out onto Route 16's east end (Celadon's row 23 is the route's row 13), along row 13 to face the Snorlax (31, 13), which with the walls at (29..31, 12) and (29..31, 14) 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" + } + ] + }, + "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 on the tile east of the Snorlax's, saved there: west of it the planner's maps still have the Snorlax (its hide flag is set by the flute's script, not by the story's map flags), and Cycling Road (Route 17) has no map in the runtime maps yet, and Route 16's west part has six Bikers (sight 1, LOOK_AROUND) on both sides of rows 12..14. 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 8be83aece5..8a3a77b156 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2098,6 +2098,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 @@ -2128,6 +2129,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 From 262499e0768d2d7f96b73c90f38cb35dfb153cb4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 23:38:41 -0800 Subject: [PATCH 2/7] PokemonFRLG: 11.01 flies with the Pidgey by species and walks over the Snorlax's tile The fly step can name the Fly user's species instead of a slot; it reads the party for it (find_party_species(), now shared with teach). The story's maps have Route 16's Snorlax gone (FLAG_HIDE_ROUTE_16_SNORLAX), so 11.01 goes on over its tile to the Cycling Road gate and saves there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 5 ++ .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 2 + .../PokemonFRLG_AutoStoryFieldMoves.cpp | 34 +++++++--- .../PokemonFRLG_AutoStoryFieldMoves.h | 12 +++- .../PokemonFRLG_AutoStoryHideout.cpp | 2 +- .../PokemonFRLG_AutoStoryPlanGolden11.h | 2 + .../PokemonFRLG_AutoStorySnorlax_Tests.cpp | 67 +++++++++++++++---- .../AutoStory/PokemonFRLG_AutoStoryTeach.cpp | 7 -- .../AutoStory/PokemonFRLG_AutoStoryTeach.h | 5 ++ .../AutoStory/StoryData/frlg-11.01.plan.json | 15 ++++- 10 files changed, 118 insertions(+), 33 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 293d82718d..c1e00a1d3a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -325,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; 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 8679778fb4..08b6eb0537 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -154,6 +154,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()); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp index f9ea5c4df6..894a93e3b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp @@ -20,6 +20,7 @@ #include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryQuietOverworld.h" #include "PokemonFRLG_AutoStoryStepInterrupts.h" +#include "PokemonFRLG_AutoStoryTeach.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -33,9 +34,8 @@ using Pokemon::StoryStep; namespace{ -// The party has six slots; a Pokemon's menu at most SUMMARY, four field -// moves, SWITCH, ITEM and CANCEL. -constexpr size_t PARTY_SLOTS = 6; +// A Pokemon's menu has at most SUMMARY, four field moves, SWITCH, ITEM +// and CANCEL (the party's six slots are PARTY_SLOTS). constexpr size_t MON_MENU_ROWS = 8; } // namespace @@ -46,14 +46,25 @@ std::optional parse_fly_step(const StoryStep& step){ } const std::string* town = game_arg(step.args, "town"); const std::optional index = town == nullptr ? std::nullopt : fly_town_index(*town); - const std::optional slot = counted_arg(step.args, "slot", PARTY_SLOTS); + const std::string* species = game_arg(step.args, "species"); + // A slot or a species, not both. + const std::optional slot = species != nullptr + ? (step.args.contains("slot") || species->empty() ? std::nullopt : std::optional(0)) + : counted_arg(step.args, "slot", PARTY_SLOTS); const std::optional menu_row = step.args.contains("menu_row") ? counted_arg(step.args, "menu_row", MON_MENU_ROWS) : std::optional(FlyPlan{}.menu_row); if (!index || !slot || !menu_row){ return std::nullopt; } - return FlyPlan{*slot, *menu_row, *index}; + return FlyPlan{.slot = *slot, .species = species == nullptr ? "" : *species, .menu_row = *menu_row, .town = *index}; +} + +std::optional fly_slot(const FlyPlan& plan, const MemberReader& reader){ + if (plan.species.empty()){ + return plan.slot; + } + return find_party_species(reader, plan.species); } std::optional parse_surf_step(const StoryStep& step){ @@ -74,7 +85,8 @@ std::vector field_move_specs(){ return { {.kind = StoryStepKind::GAME, .name = FLY_VARIANT, .args = { required_arg("town", StoryArgType::WORD, "the town's map, as kanto_fly_towns() names it (CeladonCity, Route4)"), - required_arg("slot", StoryArgType::INTEGER, "the Fly user's party slot, from 1"), + absent_arg("slot", StoryArgType::INTEGER, "the Fly user's party slot, from 1, when no species is named"), + absent_arg("species", StoryArgType::WORD, "the Fly user by its species, e.g. \"pidgey\": the first slot whose summary reads it"), optional_arg("menu_row", StoryArgType::INTEGER, int64_t(2), "FLY's row on its menu, from 1: SUMMARY, then field moves in move order"), }}, {.kind = StoryStepKind::GAME, .name = SURF_VARIANT, .args = { @@ -161,7 +173,7 @@ std::string fly_to_town(ConsoleHandle& console, ProControllerContext& context, c } // namespace std::optional run_field_move_step( - ConsoleHandle& console, ProControllerContext& context, const StoryStep& step + ConsoleHandle& console, ProControllerContext& context, Language language, const StoryStep& step ){ const auto done = [&step]{ return step.pose_after ? Pokemon::outcome_ok(Pokemon::pose_of(*step.pose_after)) : Pokemon::outcome_ok(); @@ -171,11 +183,17 @@ std::optional run_field_move_step( OverworldWalkSteps::start_surf(console, context, *water, false); return done(); } - const std::optional plan = parse_fly_step(step); + std::optional plan = parse_fly_step(step); if (!plan){ return std::nullopt; } const FlyTown& town = kanto_fly_towns()[plan->town]; + const std::optional slot = fly_slot(*plan, console_member_reader(console, context, language)); + if (!slot){ + console.log(std::format("Story: no {} read in the party to Fly with.", plan->species), COLOR_RED); + return Pokemon::outcome_failed("fly_no_member", plan->species); + } + plan->slot = *slot; console.log(std::format( "Story: Fly with slot {}, menu row {}, to {} (cell {}, {}).", plan->slot + 1, plan->menu_row + 1, town.name, town.cell.x, town.cell.y diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h index e04e257b1d..538bb42134 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h @@ -18,11 +18,13 @@ #include #include #include +#include "CommonFramework/Language.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StoryEvents.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" +#include "PokemonFRLG_AutoStoryMemberInfo.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -30,7 +32,7 @@ namespace PokemonFRLG{ // The GAME step that flies to a town, outdoors: START, POKEMON, the Fly -// user (`slot`, from 1), FLY on its menu (`menu_row`, from 1: SUMMARY, +// user (`slot`, from 1, or the first member read as `species`), FLY on its menu (`menu_row`, from 1: SUMMARY, // then its field moves in move order, so 2 when Fly is its only one; // pokefirered SetPartyMonFieldSelectionActions()), and `town` on the fly // map (kanto_fly_towns()). It ends on the town's landing tile. @@ -43,6 +45,9 @@ inline const std::string SURF_VARIANT = "surf"; // A fly step's choices, counted from 0. struct FlyPlan{ size_t slot = 0; + // The Fly user's species ("pidgey"), when the step names it instead + // of a slot: fly_slot() finds its slot in the party. + std::string species = {}; size_t menu_row = 1; // In kanto_fly_towns(). size_t town = 0; @@ -51,6 +56,9 @@ struct FlyPlan{ // The fly step's choices, or nothing if `step` isn't one or names no town // Fly goes to. std::optional parse_fly_step(const Pokemon::StoryStep& step); +// The party slot `plan` flies with: its slot, or the first member +// `reader` reads as its species; nothing if none does. +std::optional fly_slot(const FlyPlan& plan, const MemberReader& reader); // The way a surf step faces the water, or nothing if it isn't one. std::optional parse_surf_step(const Pokemon::StoryStep& step); // Whether `step` is one of this file's steps. @@ -61,7 +69,7 @@ std::vector field_move_specs(); // On the console, a step of this file's; nothing for another step. The // step ends on its pose_after, if it has one. std::optional run_field_move_step( - ConsoleHandle& console, ProControllerContext& context, const Pokemon::StoryStep& step + ConsoleHandle& console, ProControllerContext& context, Language language, const Pokemon::StoryStep& step ); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp index dd0725d65c..a3f829a80c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryHideout.cpp @@ -189,7 +189,7 @@ std::optional run_field_game_step( ride_lift(console, context, *ride); return done(); } - if (std::optional moved = run_field_move_step(console, context, step)){ + if (std::optional moved = run_field_move_step(console, context, language, step)){ return moved; } if (is_center_variant(step.action)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h index 7ee811462e..89f81fbbb8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h @@ -28,6 +28,8 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN_11[] = { "11.01 walk west 19 (to wall) -> CeladonCity (4, 16)", "11.01 walk south 7 -> CeladonCity (4, 23)", "11.01 walk west 20 -> Route16 (32, 13) [connection 5]", + "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 diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp index 2e21bac425..4cf22109e7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp @@ -4,8 +4,10 @@ * * 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, saved beside its tile once it is gone. The flute's wild - * battle is the script's: the sim takes the table's word for where it ends. + * 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). * */ @@ -13,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +27,7 @@ #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" @@ -75,14 +79,18 @@ const StoryCheckpoint& checkpoint(std::string_view id){ return *row; } -// The maps as the story leaves them by 11.01 (as the Tower's rows), the -// Snorlax still on Route 16. -std::vector maps_before_flute(){ +// 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"); - flags.erase("FLAG_HIDE_ROUTE_16_SNORLAX"); + if (snorlax_gone){ + flags.insert("FLAG_HIDE_ROUTE_16_SNORLAX"); + }else{ + flags.erase("FLAG_HIDE_ROUTE_16_SNORLAX"); + } return overworld_maps(flags); } @@ -93,12 +101,12 @@ bool scripted(const StoryStep& step){ } // 11.01: out of Mr. Fuji's house, Fly to Celadon, the Bicycle to the -// Snorlax with no trainer fought, standing beside its tile after the -// battle. +// 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 = maps_before_flute(); + 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; @@ -113,7 +121,7 @@ UnitTestResult test_snorlax(){ 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(maps, MapPosition{at.map, at.tile}, *at.facing); + 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()){ @@ -123,7 +131,7 @@ UnitTestResult test_snorlax(){ 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", {32, 13}}; + 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)); } @@ -150,9 +158,44 @@ UnitTestResult test_snorlax_battle_runs(){ 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 (fly_slot(plan, party({"blastoise", "oddish", "pidgey", "eevee"})) != size_t(2) + || fly_slot(plan, party({"blastoise", "pidgey"})) != size_t(1) + || fly_slot(plan, 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 and Route 16's Snorlax", test_snorlax}, .expectation = {}}, + {.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 diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp index 2b9474447d..f0e20855c6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.cpp @@ -255,11 +255,6 @@ class TeachRun{ } // namespace -namespace{ - -// The first party slot whose member `reader` reads as `species`; nothing -// if none does. Stops at the first slot not read (an empty slot ends the -// party). std::optional find_party_species(const MemberReader& reader, std::string_view species){ for (size_t slot = 0; slot < PARTY_SLOTS; slot++){ const std::optional member = reader(slot); @@ -273,8 +268,6 @@ std::optional find_party_species(const MemberReader& reader, std::string return std::nullopt; } -} // namespace - TeachResult run_teach(Logger& logger, TeachActions& actions, const MemberReader& reader, const TeachPlan& plan){ TeachPlan found = plan; if (!plan.species.empty()){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h index b89dbbdd8b..08d418d90e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTeach.h @@ -89,6 +89,11 @@ struct TeachResult{ std::string detail = {}; }; +// The first party slot whose member `reader` reads as `species`; nothing +// if none does. Stops at the first slot not read (an empty slot ends the +// party). +std::optional find_party_species(const MemberReader& reader, std::string_view species); + // From the overworld: reads the member, teaches as `plan` says, back to // the overworld, and reads the member again to confirm. TeachResult run_teach(Logger& logger, TeachActions& actions, const MemberReader& reader, const TeachPlan& plan); 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 index 12805c5579..775cb2d80b 100644 --- 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 @@ -21,10 +21,10 @@ "action": "fly", "args": { "town": "CeladonCity", - "slot": 3 + "species": "pidgey" }, "declared_after": {"map": "CeladonCity", "tiles": [[48, 12]], "facing": "south"}, - "why": "the Pidgey (Fly, 10.01) flies to Celadon City, landing below the Pokemon Center's door (48, 11); pokeguy flies there from Mr. Fuji's at 1:11:30" + "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", @@ -60,6 +60,15 @@ }, "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" } ] }, @@ -69,7 +78,7 @@ "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 on the tile east of the Snorlax's, saved there: west of it the planner's maps still have the Snorlax (its hide flag is set by the flute's script, not by the story's map flags), and Cycling Road (Route 17) has no map in the runtime maps yet, and Route 16's west part has six Bikers (sight 1, LOOK_AROUND) on both sides of rows 12..14. With the BICYCLE (FLAG_GOT_BICYCLE) the gate's no-pedestrians triggers are off (VAR_TEMP_1 1).", + "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." ] } From 343f575d1725ff97e4c36705bbc80c7d2be40210 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 23:42:05 -0800 Subject: [PATCH 3/7] PokemonFRLG: the Fly user's slot lookup is FlyPlan::party_slot(), segment 11 golden Keeps the field moves header within code health's symbol limit, and stores 11.01's route over the Snorlax's tile to the Cycling Road gate. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp | 10 +++++----- .../AutoStory/PokemonFRLG_AutoStoryFieldMoves.h | 9 +++++---- .../AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp | 6 +++--- 3 files changed, 13 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp index 894a93e3b3..e8e8272d84 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.cpp @@ -60,11 +60,11 @@ std::optional parse_fly_step(const StoryStep& step){ return FlyPlan{.slot = *slot, .species = species == nullptr ? "" : *species, .menu_row = *menu_row, .town = *index}; } -std::optional fly_slot(const FlyPlan& plan, const MemberReader& reader){ - if (plan.species.empty()){ - return plan.slot; +std::optional FlyPlan::party_slot(const MemberReader& reader) const{ + if (species.empty()){ + return slot; } - return find_party_species(reader, plan.species); + return find_party_species(reader, species); } std::optional parse_surf_step(const StoryStep& step){ @@ -188,7 +188,7 @@ std::optional run_field_move_step( return std::nullopt; } const FlyTown& town = kanto_fly_towns()[plan->town]; - const std::optional slot = fly_slot(*plan, console_member_reader(console, context, language)); + const std::optional slot = plan->party_slot(console_member_reader(console, context, language)); if (!slot){ console.log(std::format("Story: no {} read in the party to Fly with.", plan->species), COLOR_RED); return Pokemon::outcome_failed("fly_no_member", plan->species); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h index 538bb42134..3b61fa7ed5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFieldMoves.h @@ -46,19 +46,20 @@ inline const std::string SURF_VARIANT = "surf"; struct FlyPlan{ size_t slot = 0; // The Fly user's species ("pidgey"), when the step names it instead - // of a slot: fly_slot() finds its slot in the party. + // of a slot: party_slot() finds its slot in the party. std::string species = {}; size_t menu_row = 1; // In kanto_fly_towns(). size_t town = 0; + + // The party slot to fly with: `slot`, or the first member `reader` + // reads as `species`; nothing if none does. + std::optional party_slot(const MemberReader& reader) const; }; // The fly step's choices, or nothing if `step` isn't one or names no town // Fly goes to. std::optional parse_fly_step(const Pokemon::StoryStep& step); -// The party slot `plan` flies with: its slot, or the first member -// `reader` reads as its species; nothing if none does. -std::optional fly_slot(const FlyPlan& plan, const MemberReader& reader); // The way a surf step faces the water, or nothing if it isn't one. std::optional parse_surf_step(const Pokemon::StoryStep& step); // Whether `step` is one of this file's steps. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp index 4cf22109e7..87d34466a5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySnorlax_Tests.cpp @@ -178,9 +178,9 @@ UnitTestResult test_fly_finds_pidgey(){ return MemberInfo{.species = species[slot], .level = 30}; }); }; - if (fly_slot(plan, party({"blastoise", "oddish", "pidgey", "eevee"})) != size_t(2) - || fly_slot(plan, party({"blastoise", "pidgey"})) != size_t(1) - || fly_slot(plan, party({"blastoise", "oddish"})).has_value() + 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."; } From deda35b020ffed26526d5789b65c6ea0a0b2e8b2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 05:12:41 -0800 Subject: [PATCH 4/7] PokemonFRLG AutoStory: 11.01 reaches the Snorlax from a wall The approach check (the walk before an A press ends on its tile) found 11.01's bike route to the Snorlax ending on held open legs: "south 7" down Celadon's west side and "west 20" along Route 16's row 13 could end a row off, against the walls at (30..32, 12) or (30..32, 14), facing a wall. Now the bike route ends against the wall (32, 14), south and west both to walls, and a tile north and a tile west from there face the Snorlax (31, 13). Golden: 11.01 east_of_snorlax_wall (to (33, 14)) and east_of_snorlax (from it, north 1 and west 1). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h | 9 ++++++--- .../Programs/AutoStory/StoryData/frlg-11.01.plan.json | 11 ++++++++++- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h index 89f81fbbb8..589d16ce86 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden11.h @@ -22,12 +22,15 @@ 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 from CeladonCity (48, 12) facing south to Route16 (32, 13) facing west", + "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 7 -> CeladonCity (4, 23)", - "11.01 walk west 20 -> Route16 (32, 13) [connection 5]", + "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)", }; 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 index 775cb2d80b..c5d04be578 100644 --- 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 @@ -32,6 +32,15 @@ "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", @@ -39,7 +48,7 @@ "args": { "target": {"map": "Route16", "tiles": [[32, 13]], "facing": "west"} }, - "why": "west across Celadon and out onto Route 16's east end (Celadon's row 23 is the route's row 13), along row 13 to face the Snorlax (31, 13), which with the walls at (29..31, 12) and (29..31, 14) closes the way 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", From 3464b581f2be007c35a43453ad18bc9162804fad Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 06:09:31 -0800 Subject: [PATCH 5/7] PokemonFRLG AutoStory: read the Bicycle again before a second SELECT 11.01 on console B (2026-11-12 05:42): after Fly to Celadon, the first SELECT's read had the player on foot, a second SELECT got them off, and its read had them riding. Every bike tap after that only turned the player and was taken as blocked; the route replanned the same two legs until "stopped part-way 9 times", the player on foot at (25, 12). select_onto_bike() now reads once more, after a settle, before it presses SELECT again. Red first: OverworldBike "SELECT onto the Bicycle shown a read late" (one read late: riding read, off the Bicycle, two presses). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldBike.h | 7 ++++-- .../PokemonFRLG_OverworldBike_Tests.cpp | 23 +++++++++++++++++++ .../Overworld/PokemonFRLG_OverworldWalk.cpp | 9 ++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike.h index ca42c358a7..352bd30454 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_OverworldBike_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp index 701d7faf3a..e6a53564b3 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(){ @@ -261,6 +283,7 @@ const BikeCase OVERWORLD_BIKE_CASES[] = { {.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()"}}, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index 7629250c53..c46b2f9242 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){ 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( From f76051a3012d275677bb4a14bb8b6aa58f89ca97 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 06:13:49 -0800 Subject: [PATCH 6/7] PokemonFRLG AutoStory sim: legs on the Bicycle that start off it (red) A leg on the Bicycle counted out a tap at a time can start with the player on foot (SimScript::off_bike_at_legs). OverworldBike "a leg on the Bicycle that starts off it" is red: 11.01 on console B (2026-11-12 05:42) had every bike tap only turn the player. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldBike_Tests.cpp | 32 +++++++++++++++++++ .../Overworld/PokemonFRLG_OverworldSim.h | 5 +++ .../Overworld/PokemonFRLG_OverworldSimState.h | 9 ++++++ .../PokemonFRLG_OverworldSimTaps.cpp | 9 ++++++ 4 files changed, 55 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp index e6a53564b3..71c18e14cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp @@ -278,6 +278,37 @@ 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); + } + if (sim.state().bike_legs != 1){ + return std::format("{} legs counted in taps; expected the one, not replanned.", sim.state().bike_legs) + 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"}}, @@ -285,6 +316,7 @@ const BikeCase OVERWORLD_BIKE_CASES[] = { {.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_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 8ee01c4336..225cf04bf4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -112,6 +112,11 @@ class OverworldSim{ // Returns whether it was there. (PokemonFRLG_OverworldSimField.cpp) bool use_field(SimField field, size_t floor = 0); + // A leg on the Bicycle counted out a tap at a time starts: the player + // is off the Bicycle if SimScript::off_bike_at_legs names it. + // (PokemonFRLG_OverworldSimTaps.cpp) + void start_bike_leg(); + private: // A screen that shows at `at`; `unfreeze`: the player can move again. struct Pending{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h index 3bf141e029..c843b5057a 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 + // (OverworldSim::start_bike_leg()), 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,9 @@ 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 + // (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..1efeda249d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp @@ -53,6 +53,14 @@ bool OverworldSim::press_select(){ return true; } +void OverworldSim::start_bike_leg(){ + m_state.bike_legs++; + if (m_state.on_bike && 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)); + } +} + BikeTap OverworldSimWalker::bike_tap(const RouteStep& step){ const MapPosition before = m_sim.state().position; const std::vector& ints = interrupts(step); @@ -74,6 +82,7 @@ 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); }; + m_sim.start_bike_leg(); m_leg_start = m_sim.state().time; m_leg_dark = m_sim.state().dark; return count_bike_taps(step, calls); From a1af231570474808f22d13c9ce457b96ad3fd2df Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 06:21:12 -0800 Subject: [PATCH 7/7] PokemonFRLG AutoStory: get back on the Bicycle when a bike tap finds the player on foot 11.01 on console B (2026-11-12 05:42): the player was on foot while the walker tapped out legs at the Bicycle's taps; every tap only turned them, was taken as blocked after 0 tiles, and the route replanned until "stopped part-way 9 times". Bike legs are now counted by count_bike_taps_remounting(): after a tap that didn't move, once a leg, the walker checks for the player's standing sprite (read_facing()); if it reads, get_on_bike() and the tap is tapped again, logged. Green: OverworldBike "a leg on the Bicycle that starts off it". The sim counts bike legs itself (SimState::bike_legs, from its taps), so the walker no longer pokes it. New fault class MOUNT_LOST in the AutoStory fault sweep: rows that ride, with ride_bike played on the sim, each bike leg starting off the Bicycle in turn. 10.01 (6 legs) and 11.01 (4) pass; 08.03 is on KNOWN_FAILING, its riding run failing clean at the warp to the Underground Path. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldBikeTaps.cpp | 15 +++++ .../Overworld/PokemonFRLG_OverworldBikeTaps.h | 7 +++ .../PokemonFRLG_OverworldBike_Tests.cpp | 3 - .../PokemonFRLG_OverworldRecoveryWalk.cpp | 11 +++- .../Overworld/PokemonFRLG_OverworldSim.cpp | 13 +--- .../Overworld/PokemonFRLG_OverworldSim.h | 11 ++-- .../Overworld/PokemonFRLG_OverworldSimState.h | 5 +- .../PokemonFRLG_OverworldSimTaps.cpp | 52 ++++++++++++---- .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 61 ++++++++++++++++++- 9 files changed, 144 insertions(+), 34 deletions(-) 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 71c18e14cb..20dcfb5d1f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp @@ -303,9 +303,6 @@ UnitTestResult test_leg_starts_off_bike(){ 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); } - if (sim.state().bike_legs != 1){ - return std::format("{} legs counted in taps; expected the one, not replanned.", sim.state().bike_legs) + log_text(log); - } return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp index 104de4037a..b1c99ae5b5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -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)){ + return false; + } + console.log("Bike: a tap didn't move and the player is on foot.", COLOR_ORANGE); + get_on_bike(console, context); + return true; + }; + const StepOutcome outcome = count_bike_taps_remounting(step, calls, remount); out.stopped = outcome.walked; out.blocked = outcome.blocked; return out; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index a51e0b04ba..a89e0feee0 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 225cf04bf4..a4643322f8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -112,11 +112,6 @@ class OverworldSim{ // Returns whether it was there. (PokemonFRLG_OverworldSimField.cpp) bool use_field(SimField field, size_t floor = 0); - // A leg on the Bicycle counted out a tap at a time starts: the player - // is off the Bicycle if SimScript::off_bike_at_legs names it. - // (PokemonFRLG_OverworldSimTaps.cpp) - void start_bike_leg(); - private: // A screen that shows at `at`; `unfreeze`: the player can move again. struct Pending{ @@ -234,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 c843b5057a..e3b0caa11e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h @@ -81,7 +81,7 @@ struct SimScript{ // (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 - // (OverworldSim::start_bike_leg()), by number from 1, that start with + // (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). @@ -155,7 +155,8 @@ 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 + // 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; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimTaps.cpp index 1efeda249d..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,12 +65,27 @@ bool OverworldSim::press_select(){ return true; } -void OverworldSim::start_bike_leg(){ - m_state.bike_legs++; - if (m_state.on_bike && 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)); +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){ @@ -82,10 +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); }; - m_sim.start_bike_leg(); + 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){ @@ -121,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/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp index 08b6eb0537..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 "?"; } @@ -119,6 +128,8 @@ const std::map KNOWN_FAILING{ "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 @@ -208,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. @@ -276,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 @@ -298,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; } @@ -317,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()){ @@ -619,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{ @@ -692,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; } @@ -712,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){