From 71bfb90f5e0cdd755e627d1e1f46aeaa0ea1aae3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:12:09 -0800 Subject: [PATCH 001/168] FRLG AutoStory 00.28-00.29: through Rock Tunnel to Lavender Town's Center 00.28 goes from Route 10's Pokemon Center through the tree (10, 20) into Rock Tunnel, fights the nine trainers the way can't go round (Cooper by the walker on a leg to a wall), and leaves by the south mouth onto Route 10, where it saves. 00.29 goes down Route 10's east side, hops the ledge (11, 74) and walks into Lavender Town to its nurse. Tunnel legs end on walls, ladders or people; open legs are followed only by legs a tile of error can't send astray. Maps: the FRLG map resource lock moves to PokemonSimulation 6c2f5c8 (dayfine/PokemonSimulation#80), which adds RockTunnel_1F/B1F, LavenderTown and its Center, decomp only. Lavender Town is a save card place. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Menus/PokemonFRLG_SaveCardReader.cpp | 1 + .../Menus/PokemonFRLG_SaveCardReader.h | 3 +- .../Overworld/PokemonFRLG_OverworldMaps.cpp | 5 + .../PokemonFRLG/PokemonFRLG_Tests.cpp | 1 + .../PokemonFRLG_AutoStoryBattleData.cpp | 11 + .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 1 + .../PokemonFRLG_AutoStoryLavender_Tests.cpp | 240 ++++++++++++++++++ .../PokemonFRLG_AutoStoryRunPlan_Tests.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 2 +- .../AutoStory/PokemonFRLG_AutoStoryTable.h | 2 + .../PokemonFRLG_AutoStoryTableLavender.cpp | 131 ++++++++++ .../PokemonFRLG_AutoStoryTableSteps.h | 12 + .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 11 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + devtools/maps/map-resources.lock.json | 4 +- 15 files changed, 421 insertions(+), 13 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableLavender.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp index af82fde0ea..995ae469e7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.cpp @@ -74,6 +74,7 @@ class PlaceNameMatcher : public OCR::SmallDictionaryMatcher{ {"route-24", "Route 24"}, {"route-25", "Route 25"}, {"route-10", "Route 10"}, + {"lavender-town", "Lavender Town"}, {"vermilion-city", "Vermilion City"}, }){ JsonArray names; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h index f693d02977..68e82bec51 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_SaveCardReader.h @@ -33,7 +33,8 @@ ImageFloatBox save_card_title_box(); // The place on the save card: "pallet-town", "viridian-city", // "viridian-forest", "pewter-city", "route-1" to "route-4", "cerulean-city", -// "route-10", "route-24", "route-25", "vermilion-city"; empty if it can't be read, as +// "route-10", "route-24", "route-25", "vermilion-city", +// "lavender-town"; empty if it can't be read, as // in a language the reader has no names for. std::string read_save_card_location(Logger& logger, Language language, const ImageViewRGB32& screen); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp index 2735ec7ae4..35934b78c3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.cpp @@ -78,6 +78,11 @@ const char* const MAP_NAMES[] = { "Route9", "Route10", "Route10_PokemonCenter_1F", + // Rock Tunnel to Lavender Town's Pokemon Center. + "RockTunnel_1F", + "RockTunnel_B1F", + "LavenderTown", + "LavenderTown_PokemonCenter_1F", "CeruleanCave_1F", "CeruleanCave_2F", "CeruleanCave_B1F", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 2bf7183092..27726c1b9d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -895,6 +895,7 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){ add_tests_AutoStoryVermilion(database); add_tests_AutoStoryVermilionGym(database); add_tests_AutoStoryCeladon(database); + add_tests_AutoStoryLavender(database); } void add_tests(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp index 5442216c83..0deab3ef7c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBattleData.cpp @@ -75,6 +75,17 @@ constexpr StoryTrainer STORY_TRAINERS[] = { {.map = "Route9", .battle = "picnicker_alicia", .trainer = "TRAINER_PICNICKER_ALICIA"}, {.map = "Route9", .battle = "hiker_jeremy", .trainer = "TRAINER_HIKER_JEREMY"}, {.map = "Route9", .battle = "bug_catcher_conner", .trainer = "TRAINER_BUG_CATCHER_CONNER"}, + // Rock Tunnel's nine the way can't walk around (RockTunnel_1F, + // RockTunnel_B1F scripts.inc). + {.map = "RockTunnel_1F", .battle = "pokemaniac_ashton", .trainer = "TRAINER_POKEMANIAC_ASHTON"}, + {.map = "RockTunnel_B1F", .battle = "pokemaniac_winston", .trainer = "TRAINER_POKEMANIAC_WINSTON"}, + {.map = "RockTunnel_B1F", .battle = "picnicker_martha", .trainer = "TRAINER_PICNICKER_MARTHA"}, + {.map = "RockTunnel_B1F", .battle = "hiker_allen", .trainer = "TRAINER_HIKER_ALLEN"}, + {.map = "RockTunnel_1F", .battle = "hiker_lenny", .trainer = "TRAINER_HIKER_LENNY"}, + {.map = "RockTunnel_B1F", .battle = "picnicker_sofia", .trainer = "TRAINER_PICNICKER_SOFIA"}, + {.map = "RockTunnel_B1F", .battle = "hiker_dudley", .trainer = "TRAINER_HIKER_DUDLEY"}, + {.map = "RockTunnel_B1F", .battle = "pokemaniac_cooper", .trainer = "TRAINER_POKEMANIAC_COOPER"}, + {.map = "RockTunnel_1F", .battle = "picnicker_dana", .trainer = "TRAINER_PICNICKER_DANA"}, }; using JsonTable = std::map>; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index d06a03851a..00fdd207dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -395,6 +395,7 @@ std::string save_card_place(const std::string& map){ {"Route25", "route-25"}, {"VermilionCity", "vermilion-city"}, {"Route10", "route-10"}, + {"LavenderTown", "lavender-town"}, }; for (const auto& [prefix, place] : PLACES){ if (map == prefix || map.rfind(prefix + "_", 0) == 0){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp new file mode 100644 index 0000000000..65ad046355 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp @@ -0,0 +1,240 @@ +/* AutoStory Lavender Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Rows from 00.28 on (PokemonFRLG_AutoStoryTableLavender.cpp) on the + * overworld sim: 00.28 from Route 10's Pokemon Center through Rock Tunnel + * to its south mouth, and 00.29 down Route 10 to Lavender Town's Center. + * Each row whole, each open leg a tile short or long, and a wild battle + * on every open leg in the tunnel. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.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_AutoStoryTable.h" +#include "PokemonFRLG_AutoStoryTableSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +struct AutoStoryLavenderInput{ + std::string name; + std::function body; +}; + +struct AutoStoryLavenderExpectation{ +}; + +struct AutoStoryLavenderCase{ + AutoStoryLavenderInput input; + AutoStoryLavenderExpectation expectation; +}; + +class Test_AutoStoryLavender : public UnitTest{ +public: + explicit Test_AutoStoryLavender(AutoStoryLavenderCase test_case) + : UnitTest("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::string(e.name()) + ": " + e.message(); + } + } + +private: + AutoStoryLavenderCase 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 00.27 leaves them: the story's flags, Rock Tunnel's and +// Route 10's trainers unfought. +std::vector maps_after_route10(){ + 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"); + return overworld_maps(flags); +} + +// Row `id`'s steps from `first` on, on `sim` from `at`: the failure, or +// empty once on the row's last route's target. +std::string row_rest(OverworldSim& sim, StoryPose at, const StoryCheckpoint& row, size_t first){ + std::string failure; + for (size_t c = first; c < row.steps.size() && failure.empty(); c++){ + failure = row_step_on_sim(sim, at, row.steps[c], row.id); + } + if (!failure.empty()){ + return std::format("ended on {}; {}", to_string(sim.state().position), failure); + } + return ""; +} + +UnitTestResult row_on_sim(std::string_view id, const SimScript& script, const std::vector& trainers, const MapPosition& end){ + const StoryCheckpoint& row = checkpoint(id); + const StoryPose at = *story_pose(*row.start); + OverworldSim sim(maps_after_route10(), MapPosition{at.map, at.tile}, *at.facing, script); + if (const std::string failure = row_rest(sim, at, row, 0); !failure.empty()){ + return std::string(id) + ": " + failure; + } + if (sim.state().trainers_beaten != trainers){ + std::string fought; + for (const std::string& name : sim.state().trainers_beaten){ + fought += " " + name; + } + return std::format("{}: fought{}.", id, fought); + } + if (!sim.state().violations.empty()){ + return std::string(id) + ": a violation on the way: " + sim.state().violations.back(); + } + if (!(sim.state().position == end)){ + return std::format("{}: ended on {}, not {}.", id, to_string(sim.state().position), to_string(end)); + } + return true; +} + +const std::vector ROCK_TUNNEL_TRAINERS{ + "poke_maniac", "poke_maniac", "picnicker", "hiker", "hiker", "picnicker", "hiker", "poke_maniac", "picnicker", +}; + +// 00.28 on the sim: the tree cut, the nine trainers fought where the +// table steps into their lines (Cooper by the walker, on the leg past +// him), no one else met, and the walk out of the south mouth. +UnitTestResult test_rock_tunnel_row(){ + return row_on_sim("00.28", SimScript{}, ROCK_TUNNEL_TRAINERS, MapPosition{StoryTable::ROUTE10, {8, 58}}); +} + +// 00.28 with a wild battle on the 3rd step on the tunnel's floor, mid-way +// down the leg to the wall (17, 8): the walker runs, holds the leg to its +// wall again, and nothing else changes. +UnitTestResult test_rock_tunnel_wild_battles(){ + SimScript script; + script.encounters.push_back(SimEncounter{.grass_step = 3}); + return row_on_sim("00.28", script, ROCK_TUNNEL_TRAINERS, MapPosition{StoryTable::ROUTE10, {8, 58}}); +} + +// 00.29 on the sim: no trainer met, the ledge hopped, Lavender's nurse. +UnitTestResult test_lavender_row(){ + return row_on_sim("00.29", SimScript{}, {}, MapPosition{StoryTable::LAVENDER_CENTER, {7, 4}}); +} + +// Where an open leg of two tiles or more ends a tile short or long, the +// next leg starts a tile off. From each such start (an open tile), the +// rest of the row still ends where the table says. A leg to a wall or +// onto a warp ends on its tile, and a one-tile leg is one step. +UnitTestResult tile_off_after_open_legs(std::string_view id){ + const StoryCheckpoint& row = checkpoint(id); + const std::vector& maps = story_maps(); + std::optional before; + StoryPose at = *story_pose(*row.start); + for (size_t s = 0; s < row.steps.size(); s++){ + const StoryStep& step = row.steps[s]; + const bool walks = step.kind == StoryStepKind::ROUTE || step.kind == StoryStepKind::LEGS; + if (!walks){ + // A step that isn't a walk starts where the table says. + before.reset(); + if (step.pose_after){ + at = *story_pose(*step.pose_after); + }else if (step.kind == StoryStepKind::STEP && step.variant == CUT_TREE_VARIANT){ + at = StoryPose{at.map, at.tile.next(step.direction), step.direction}; + } + continue; + } + const std::vector route = walked_route(at, step).value_or(std::vector{}); + MapPosition from{at.map, at.tile}; + for (size_t c = 0; c < route.size(); c++){ + const bool off = before && before->action == RouteAction::WALK && !before->to_wall && !before->warps && before->tiles > 1; + const TilePos on = from.point.next(before ? before->direction : Direction::NORTH); + const TilePos short_of{2 * from.point.x - on.x, 2 * from.point.y - on.y}; + const auto map = std::find_if(maps.begin(), maps.end(), [&](const MapData& data){ return data.name == from.map; }); + for (const TilePos& start : off ? std::vector{short_of, on} : std::vector{}){ + const bool open = map != maps.end() && in_bounds(*map, start) && object_at(*map, start) == nullptr + && (tile_at(*map, start) == TileKind::OPEN || tile_at(*map, start) == TileKind::TALL_GRASS); + if (!open){ + continue; + } + OverworldSim sim(maps_after_route10(), MapPosition{from.map, start}, before->direction); + const std::vector rest(route.begin() + c, route.end()); + const RoutePlanning planning{.maps = &maps, .costs = story_route_costs(), .start = from, .label = step.name}; + std::string failure = OverworldSimWalker(sim).run(rest, planning); + const StoryPose next{route.back().end.map, route.back().end.point, route.back().facing_after}; + failure = failure.empty() ? row_rest(sim, next, row, s + 1) : failure; + if (!failure.empty()){ + return std::format("{} {} leg {} ({}) from {}, not {}: {}", id, step.name, c + 1, to_string(route[c]), to_string(start), to_string(from.point), failure); + } + } + before = route[c]; + from = route[c].end; + } + at = route.empty() ? at : StoryPose{route.back().end.map, route.back().end.point, route.back().facing_after}; + } + return true; +} + +UnitTestResult test_rock_tunnel_tile_off(){ + return tile_off_after_open_legs("00.28"); +} + +UnitTestResult test_lavender_tile_off(){ + return tile_off_after_open_legs("00.29"); +} + +// 00.29 saves in Lavender Town's Pokemon Center, LAVENDER TOWN on the +// save card; 00.28 on Route 10. +UnitTestResult test_save_places(){ + if (save_card_place(StoryTable::LAVENDER_CENTER) != "lavender-town" || save_card_place(StoryTable::ROUTE10) != "route-10"){ + return "Wrong save card places for Lavender Town's Center or Route 10."; + } + return true; +} + +} // namespace + + +const AutoStoryLavenderCase AUTO_STORY_LAVENDER_CASES[] = { + {.input = {"00.28 the tree, Rock Tunnel's nine trainers, out of its south mouth", test_rock_tunnel_row}, .expectation = {}}, + {.input = {"00.28 a wild battle mid-leg in the tunnel", test_rock_tunnel_wild_battles}, .expectation = {}}, + {.input = {"00.28 a tile off after each open leg", test_rock_tunnel_tile_off}, .expectation = {}}, + {.input = {"00.29 Route 10 south, the ledge, Lavender Town's Pokemon Center", test_lavender_row}, .expectation = {}}, + {.input = {"00.29 a tile off after each open leg", test_lavender_tile_off}, .expectation = {}}, + {.input = {"00.28 and 00.29 save on Route 10 and in Lavender Town", test_save_places}, .expectation = {}}, +}; + +void add_tests_AutoStoryLavender(UnitTestDatabase& database){ + for (const auto& item : AUTO_STORY_LAVENDER_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation 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 39230fefbc..e595c875e0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -138,7 +138,7 @@ class Test_RunPlan : public UnitTest{ const RunPlanScenario m_scenario; }; -const std::string TODAY = "00.01 00.02 00.03 00.04 00.05 00.06 00.07 00.08 00.09 00.10 00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27"; +const std::string TODAY = "00.01 00.02 00.03 00.04 00.05 00.06 00.07 00.08 00.09 00.10 00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -229,11 +229,11 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Gift RNG off: 00.12b is passed over", .first = "00.11"}, - .expectation = {.expected_ids = "00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27"}, + .expectation = {.expected_ids = "00.11 00.12 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29"}, }, { .input = {.name = "Gift RNG off: 00.12b runs when started at", .first = "00.12b"}, - .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27"}, + .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29"}, }, { .input = { .name = "Gift RNG: started at 00.12b, from the save beside the salesman", @@ -258,7 +258,7 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Starter RNG alone: 00.12b runs when started at", .first = "00.12b", .handoffs = {.starter_rng = true}}, - .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27"}, + .expectation = {.expected_ids = "00.12b 00.12c 00.13 00.14 00.14b 00.14c 00.15 00.15b 00.16 00.17 00.18 00.19 00.20 00.21 00.22 00.23 00.24 00.25 00.26 00.27 00.28 00.29"}, }, { .input = { .name = "Starter RNG first, with both on", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 3f88fe03e1..94437d8c5c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -791,7 +791,7 @@ const std::vector& story_checkpoints(){ running_shoes(), route3(), magikarp_salesman(), after_gift_rng(), magikarp_to_box(), mt_moon(), route4_to_cerulean(), cerulean_gym(), misty(), cerulean_grind(), cerulean_rival(), nugget_bridge(), route25(), bill(), back_to_cerulean(), oddish(), to_vermilion(), ss_anne(), - vermilion_gym(), to_lt_surge(), lt_surge(), bike_voucher(), route10_center(), + vermilion_gym(), to_lt_surge(), lt_surge(), bike_voucher(), route10_center(), rock_tunnel(), lavender_center(), }; return checkpoints; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 2778f00eb5..5b964af410 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -46,6 +46,8 @@ void add_tests_AutoStoryVermilion(UnitTestDatabase& database); void add_tests_AutoStoryVermilionGym(UnitTestDatabase& database); // Rows from 00.26 on on the overworld sim (PokemonFRLG_AutoStoryCeladon_Tests.cpp). void add_tests_AutoStoryCeladon(UnitTestDatabase& database); +// Rows from 00.28 on on the overworld sim (PokemonFRLG_AutoStoryLavender_Tests.cpp). +void add_tests_AutoStoryLavender(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableLavender.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableLavender.cpp new file mode 100644 index 0000000000..73ae6ffbf4 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableLavender.cpp @@ -0,0 +1,131 @@ +/* AutoStory Table: to Lavender Town + * + * From: https://github.com/PokemonAutomation/ + * + * Rows from 00.28 on: through Rock Tunnel, without Flash, and down Route + * 10 to Lavender Town's Pokemon Center. + * + */ + +#include "PokemonFRLG_AutoStoryTableSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ +namespace StoryTable{ + + +// From Route 10's Pokemon Center through Rock Tunnel (pokefirered +// RockTunnel_1F, RockTunnel_B1F map.json and scripts.inc) to Route 10 +// south of it. The save is on Route 10 by the tunnel's south mouth: the +// save card's places don't include Rock Tunnel. +// - The tunnel's north mouth (8, 19) is reached from the Center through +// the tree (10, 20), cut from below; Heidi (9, 27) sees rows 28..29 +// below the trees and is left. Two single steps west then put the +// player below the mouth on (8, 20). +// - Every floor tile of the tunnel has wild encounters, which are run +// from (the table has no step that uses a Repel), so the legs end on +// walls, ladders or someone standing still, which the walker holds +// again after a battle. An open leg (two tiles or more, not to a wall) +// is followed only by legs a tile of error in it can't send astray. +// - Nine trainers stand where the way can't go round them. The others +// (1F Lucas, Oliver, Ariana, Leah; B1F Eric, Steve) are walked round. +// - 1F Ashton (27, 10) looks west over (24..26, 10), the only way south +// from the mouth's room: stepped into from (24, 9). +// - B1F Winston (29, 35) looks south over the south passage (29, +// 36..38): stepped into from (32, 37), after the leg down column 33 +// to the wall and a tile back. +// - B1F Martha (15, 33) looks east over (16..17, 33), the corridor +// north: stepped into from (17, 34), the wall east of row 34. +// - B1F Allen (36, 11) looks south over (36, 12..14), the way west to +// the ladder (33, 3): stepped into from (38, 12), below the wall. +// - 1F Lenny (7, 5) looks south over (7, 6..9), the way east from the +// ladder (4, 2): stepped into from (6, 9), the end of column 6. +// The way on to the ladder (20, 13) keeps west of Lucas's line (16..19, +// 17): down column 11, up column 14 to row 16. +// - B1F Sofia (11, 15) looks south over (11, 16..19), the way west: +// stepped into along row 16 from (12..14, 16). +// - B1F Dudley (5, 11) looks south over (5, 12..15): stepped into from +// (8, 15) along row 15. +// - B1F Cooper (2, 6) looks around (sight 2) by the ladder (2, 3): the +// leg up column 1 to the wall (1, 2) passes him on (1, 6); if he +// looks west, story_interrupts() fights him and the leg is held on +// to its wall, as Mt. Moon's Grunt in 00.13. +// - 1F Dana (26, 28) looks south over (26, 29..31), the only way west +// to the south mouth: stepped into along row 31 from (27..29, 31). +// - Unverified on the console: Rock Tunnel is dark without Flash, and +// the overworld, fade, dialog and battle detectors haven't been +// measured under its darkness (~/FRLGLab/notes/2026-11-09-0028-dark- +// measure.md). Every step from rock_tunnel_1f to route10_south depends +// on them. +StoryCheckpoint rock_tunnel(){ + return row("00.28", "Through Rock Tunnel: Ashton, Winston, Martha, Allen, Lenny, Sofia, Dudley, Cooper and Dana", at(ROUTE10_CENTER, 7, 4, NORTH), after_brock(), StartMenu::FULL, { + running(route("below_route10_tree", at(ROUTE10, 10, 21, NORTH), "out of the Center (13, 20), west along row 21 to the wall (9, 21), below the tree (10, 20)")), + cut_tree("cut_route10_tree", at(ROUTE10, 10, 20, NORTH), "the tree; a step onto its tile"), + step_onto("west_of_tree", WEST, at(ROUTE10, 9, 20, WEST), "a step west along row 20"), + step_onto("below_rock_tunnel", WEST, at(ROUTE10, 8, 20, WEST), "a step west, below the mouth (8, 19)"), + running(route("rock_tunnel_1f", at(ROCK_TUNNEL_1F, 17, 2, NORTH), "north into Rock Tunnel")), + running(legs("above_ashton_line", {{SOUTH, 6}, {EAST, 8}, {SOUTH, 1}, {WEST, 1}}, "down column 17 to the wall (17, 8), east along row 8 to (25, 8), onto row 9 and west to the wall (24, 9)")), + into_line("ashton_line", SOUTH, "onto (24, 10), in Ashton's line: he walks up to (25, 10)"), + battle("pokemaniac_ashton", at(ROCK_TUNNEL_1F, 24, 10, EAST), false, "Slowpoke, Slowpoke and Slowpoke"), + running(route("b1f_south_ladder", at(ROCK_TUNNEL_B1F, 38, 28, NORTH), "east along row 12 and up column 45 to the ladder (45, 2), down to B1F")), + running(legs("winston_line_end", {{WEST, 5}, {SOUTH, 10}, {NORTH, 1}, {WEST, 1}}, "west to the wall (33, 28), down column 33 to the wall (33, 38), up to (33, 37) and west to (32, 37)")), + into_line("winston_line", WEST, "along row 37 onto (29, 37), the end of Winston's line: he walks down to (29, 36)"), + battle("pokemaniac_winston", at(ROCK_TUNNEL_B1F, 29, 37, NORTH), false, "Slowpoke and Slowpoke"), + running(legs("below_martha_line", {{WEST, 16}, {NORTH, 2}, {EAST, 6}, {WEST, 3}, {NORTH, 1}, {EAST, 1}}, "west along row 37 to (13, 37), up to the wall (13, 35), east to the wall (19, 35), west to (16, 35), up to row 34 and east to the wall (17, 34)")), + into_line("martha_line", NORTH, "onto (17, 33), the end of Martha's line: she walks up to (16, 33)"), + battle("picnicker_martha", at(ROCK_TUNNEL_B1F, 17, 33, WEST), false, "Oddish and Bulbasaur"), + running(legs("below_allen_line", {{NORTH, 5}, {EAST, 12}, {NORTH, 9}, {EAST, 11}, {NORTH, 2}, {WEST, 2}, {NORTH, 5}}, "up column 17 to the wall (17, 28), east to the wall (29, 28), up column 29 past Steve's line to the wall (29, 19), east to (40, 19), up to row 17, west to the wall (38, 17) and up to the wall (38, 12)")), + into_line("allen_line", WEST, "along row 12 onto (36, 12), below Allen"), + battle("hiker_allen", at(ROCK_TUNNEL_B1F, 36, 12, NORTH), false, "Geodude, Geodude and Graveler"), + running(legs("west_of_b1f_ladder", {{WEST, 4}, {NORTH, 10}}, "west along row 12 to the wall (32, 12), up column 32 to the wall (32, 2)")), + running(route("1f_west_ladder", at(ROCK_TUNNEL_1F, 4, 2, NORTH), "onto the ladder (33, 3), up to 1F")), + running(legs("above_lenny_line", {{EAST, 2}, {SOUTH, 7}}, "east to the wall (6, 2), down column 6 to the wall (6, 9)")), + into_line("lenny_line", EAST, "onto (7, 9), the end of Lenny's line: he walks down to (7, 8)"), + battle("hiker_lenny", at(ROCK_TUNNEL_1F, 7, 9, NORTH), false, "Machop and Onix"), + running(legs("west_of_lucas_line", {{EAST, 4}, {SOUTH, 15}, {EAST, 7}, {WEST, 4}, {NORTH, 8}, {EAST, 6}}, "east to the wall (11, 9), down column 11 to the wall (11, 24), east to the wall (18, 24), west to (14, 24), up column 14 to the wall (14, 16), east to the wall (20, 16)")), + running(route("b1f_middle_ladder", at(ROCK_TUNNEL_B1F, 27, 12, NORTH), "up column 20 onto the ladder (20, 13), down to B1F")), + running(legs("east_of_sofia_line", {{SOUTH, 3}, {WEST, 12}, {SOUTH, 1}, {WEST, 2}}, "down to the wall (27, 15), west along row 15 to the wall (15, 15), down to row 16 and west to (13, 16)")), + into_line("sofia_line", WEST, "along row 16 onto (11, 16), below Sofia"), + battle("picnicker_sofia", at(ROCK_TUNNEL_B1F, 11, 16, NORTH), false, "Pidgey, Pidgey and Pidgeotto"), + running(legs("east_of_dudley_line", {{WEST, 3}, {NORTH, 1}}, "west to the wall (8, 16), up to (8, 15)")), + into_line("dudley_line", WEST, "along row 15 onto (5, 15), the end of Dudley's line: he walks down to (5, 14)"), + battle("hiker_dudley", at(ROCK_TUNNEL_B1F, 5, 15, NORTH), false, "Geodude, Geodude and Graveler"), + running(legs("past_cooper", {{WEST, 4}, {NORTH, 13}, {SOUTH, 1}}, "west to the wall (1, 15), up column 1 past Cooper (2, 6) to the wall (1, 2), back to (1, 3)")), + running(route("1f_east_ladder", at(ROCK_TUNNEL_1F, 45, 21, NORTH), "east onto the ladder (2, 3), up to 1F")), + running(legs("above_dana_line", { + {WEST, 6}, {SOUTH, 5}, {EAST, 6}, {WEST, 1}, {SOUTH, 4}, {WEST, 5}, {SOUTH, 5}, + {WEST, 2}, {NORTH, 3}, {WEST, 6}, {NORTH, 3}, {WEST, 3}, {SOUTH, 2}, + }, "west to the wall (39, 21), down column 39 to Ariana (39, 27), east to the wall (45, 26), down column 44 to the wall (44, 30), west to the wall (39, 30), down to the wall (39, 35), west to (37, 35), up to the wall (37, 32), west to the wall (31, 32), up to (31, 29), west to (28, 29) and down to the wall (28, 31)")), + into_line("dana_line", WEST, "along row 31 onto (26, 31), the end of Dana's line: she walks down to (26, 30)"), + battle("picnicker_dana", at(ROCK_TUNNEL_1F, 26, 31, NORTH), false, "Meowth, Oddish and Pidgey"), + running(legs("above_south_mouth", {{WEST, 6}, {SOUTH, 1}, {WEST, 8}, {SOUTH, 5}, {EAST, 2}, {NORTH, 1}, {EAST, 5}, {WEST, 1}}, "west along row 31 to (20, 31), onto row 32 and west to the wall (12, 32), down column 12 to the wall (12, 37), east to the wall (14, 37), up to (14, 36), east to the wall (19, 36), back to (18, 36)")), + running(route("route10_south", at(ROUTE10, 8, 58, SOUTH), "onto the mouth (18, 37), out onto Route 10")), + }); +} + +// Route 10 south of Rock Tunnel (Route10 map.json) to Lavender Town's +// Pokemon Center. It has no grass. Carol (7, 60) and Clark (4, 62) look +// around, Trent (4, 68) looks west and Herman wanders row 70 (13..17), +// looking west and east (sight 2, to x 19): the way keeps to the east +// side, columns 17..21, and crosses row 70 on column 21. The ledges of +// row 62 leave a gap at (18, 62); row 66's leaves (21, 66). Row 74's +// ledge (11, 74) is hopped, and the hold south goes on over the +// connection into Lavender Town to the wall (11, 9). West of the +// Center's building, the wall (8, 9) sets the door's column. +StoryCheckpoint lavender_center(){ + return row("00.29", "Route 10 south to Lavender Town's Pokemon Center", at(ROUTE10, 8, 58, SOUTH), after_brock(), StartMenu::FULL, { + running(legs("route10_east_side", {{EAST, 10}, {NORTH, 2}, {WEST, 1}, {EAST, 1}, {SOUTH, 8}, {EAST, 3}, {SOUTH, 9}, {WEST, 10}}, "east along row 58 to (18, 58), up to the wall (18, 56), west to the wall (17, 56), back to (18, 56), down through the ledges' gap to (18, 64), east to the wall (21, 64), down column 21 to the wall (21, 73), west along row 73 to the wall (11, 73)")), + hop("route10_ledge_hop", SOUTH, at(ROUTE10, 11, 75, SOUTH), "down the ledge (11, 74)"), + running(route("lavender_north_wall", at(LAVENDER, 11, 8, SOUTH), "down column 11 over the connection into Lavender Town, to the wall (11, 9)")), + running(legs("below_center_door", {{WEST, 6}, {SOUTH, 1}, {EAST, 2}, {WEST, 1}}, "west along row 8 to (5, 8), onto row 9, east to the wall (7, 9), west to (6, 9)")), + running(route("lavender_nurse", at(LAVENDER_CENTER, 7, 4, NORTH), "up column 6 onto the Center's door (6, 5), to the nurse")), + heal("heal_lavender"), + }); +} + + +} // namespace StoryTable +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableSteps.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableSteps.h index 8775379b84..d0a314a2ac 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableSteps.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTableSteps.h @@ -101,6 +101,14 @@ inline constexpr const char* ROUTE9 = "Route9"; inline constexpr const char* ROUTE10 = "Route10"; // Route 10 Pokemon Center map. inline constexpr const char* ROUTE10_CENTER = "Route10_PokemonCenter_1F"; +// Rock Tunnel 1F map. +inline constexpr const char* ROCK_TUNNEL_1F = "RockTunnel_1F"; +// Rock Tunnel B1F map. +inline constexpr const char* ROCK_TUNNEL_B1F = "RockTunnel_B1F"; +// Lavender Town overworld map. +inline constexpr const char* LAVENDER = "LavenderTown"; +// Lavender Town Pokemon Center map. +inline constexpr const char* LAVENDER_CENTER = "LavenderTown_PokemonCenter_1F"; // Constructs pose at map coordinates. Pokemon::Pose at(const char* map, int x, int y, std::optional facing = std::nullopt); @@ -187,6 +195,10 @@ StoryCheckpoint lt_surge(); StoryCheckpoint bike_voucher(); // Route 10 Pokemon Center navigation checkpoint. StoryCheckpoint route10_center(); +// Through Rock Tunnel to Route 10 south of it (PokemonFRLG_AutoStoryTableLavender.cpp). +StoryCheckpoint rock_tunnel(); +// Route 10 south to Lavender Town's Pokemon Center. +StoryCheckpoint lavender_center(); 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 4512a610ac..da54867cd9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -230,8 +230,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po UnitTestResult test_routes_and_chain(){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 34 || checkpoints[0].start){ - return "Expected 34 checkpoints, the first from a new game."; + if (checkpoints.size() != 36 || checkpoints[0].start){ + return "Expected 36 checkpoints, the first from a new game."; } StoryPose pose; for (size_t c = 0; c < checkpoints.size(); c++){ @@ -600,7 +600,7 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set Date: Mon, 9 Nov 2026 10:14:07 -0800 Subject: [PATCH 002/168] FRLG AutoStory: register the 00.28-00.29 sim tests from the Celadon ones PokemonFRLG_Tests.cpp is at the 1000-line limit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 1 - .../Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp | 1 + .../Programs/AutoStory/PokemonFRLG_AutoStoryTable.h | 3 ++- 3 files changed, 3 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 27726c1b9d..2bf7183092 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -895,7 +895,6 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){ add_tests_AutoStoryVermilion(database); add_tests_AutoStoryVermilionGym(database); add_tests_AutoStoryCeladon(database); - add_tests_AutoStoryLavender(database); } void add_tests(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp index 853b4e4af7..922b9c0e18 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCeladon_Tests.cpp @@ -434,6 +434,7 @@ void add_tests_AutoStoryCeladon(UnitTestDatabase& database){ for (const auto& item : AUTO_STORY_CELADON_CASES){ database.add(item); } + add_tests_AutoStoryLavender(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h index 5b964af410..0e97ce995e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h @@ -44,7 +44,8 @@ void add_tests_AutoStorySimulation(UnitTestDatabase& database); void add_tests_AutoStoryVermilion(UnitTestDatabase& database); // Rows 00.23 to 00.25 on the overworld sim (PokemonFRLG_AutoStoryVermilionGym_Tests.cpp). void add_tests_AutoStoryVermilionGym(UnitTestDatabase& database); -// Rows from 00.26 on on the overworld sim (PokemonFRLG_AutoStoryCeladon_Tests.cpp). +// Rows from 00.26 on on the overworld sim (PokemonFRLG_AutoStoryCeladon_Tests.cpp), +// with add_tests_AutoStoryLavender(). void add_tests_AutoStoryCeladon(UnitTestDatabase& database); // Rows from 00.28 on on the overworld sim (PokemonFRLG_AutoStoryLavender_Tests.cpp). void add_tests_AutoStoryLavender(UnitTestDatabase& database); From 8b656d1a218d9c759b81fe85fe3e4f7ed16112a4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:20:41 -0800 Subject: [PATCH 003/168] FRLG story drafts 00.29-00.31: Lavender to the Silph Scope Unverified authored-checkpoint drafts, outside the embedded StoryData set: the Lavender Mart, Route 8, the Underground Path, a Pidgey for Fly, and the Rocket Hideout to Giovanni. The README lists the whole 00.29-00.51 draft, its conventions, the user's open decisions and the leg check. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/StoryData/Draft/README.md | 135 ++++++++++++++++++ .../StoryData/Draft/frlg-00.29.plan.json | 91 ++++++++++++ .../StoryData/Draft/frlg-00.30.plan.json | 86 +++++++++++ .../StoryData/Draft/frlg-00.31.plan.json | 105 ++++++++++++++ 4 files changed, 417 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/README.md create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.29.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.30.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.31.plan.json diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/README.md b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/README.md new file mode 100644 index 0000000000..8046824952 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/README.md @@ -0,0 +1,135 @@ +# FRLG story drafts, 00.29 to the Hall of Fame + +**Every file here is an unverified draft.** None has run on a console, and the +story table doesn't load them: `pa_embed_text_files()` embeds only +`StoryData/*.json`, not this folder. The authored format has no status field, +so this README is where they are marked unverified. + +Each file is a `pokesim-authored-checkpoint/1` plan in the same format as +`../frlg-parcel-00.05.plan.json`. The order and the item stops follow PokeGuy's +LeafGreen run (PokemonSimulation `data/runs/pokeguy-leafgreen-15934/events.json` +and `external/pokeguy-notes.md`). They start where 00.28 (Rock Tunnel to +Lavender, on `frlg/stage8-rocktunnel`) is expected to end: at Lavender's nurse. + +| Id | Title | Events | +|---|---|---:| +| 00.29 | Lavender Mart, then west over Route 8: Gamer Rich, a Pidgey for Fly, the Underground Path to Celadon | 12 | +| 00.30 | Celadon Game Corner and the Rocket Hideout down to B4F: the poster guard, the Lift Key Grunt, the LIFT KEY and B3F's Rare Candy | 12 | +| 00.31 | Rocket Hideout: the lift to B4F, the two door guards, two Rare Candies, Blastoise, Giovanni and the SILPH SCOPE | 16 | +| 00.32 | Celadon: Department Store 5F battle items, HM02 Fly on Route 16 for the Pidgey, the Tea, then the Center | 20 | +| 00.32b | Celadon Mansion roof room: the Eevee (Gift RNG placeholder) | 4 | +| 00.33 | Fly to Lavender, the Center, Pokemon Tower 2F: the rival | 8 | +| 00.34 | Pokemon Tower 3F to 7F: Tammy, Jennifer, Emilia, the Marowak, three Grunts, Mr. Fuji | 21 | +| 00.35 | The POKE FLUTE, Fly to Celadon, Route 16's Snorlax, Cycling Road's Rare Candy and Max Elixir, Fuchsia | 16 | +| 00.36 | Safari Zone: a Full Restore, the GOLD TEETH, HM03 Surf from the Secret House | 12 | +| 00.37 | Fuchsia: Surf to the lead, Juggler Kirk, Koga, then HM04 Strength from the Warden | 14 | +| 00.38 | Fly to Pallet, Surf down Route 21 to Cinnabar, the Mansion: Elixir, TM14 Blizzard and the SECRET KEY | 15 | +| 00.38b | Cinnabar Lab: the Helix Fossil revived (Gift RNG placeholder) | 6 | +| 00.39 | Cinnabar Gym: the quiz doors, Blaine | 9 | +| 00.40 | Fly to Celadon: two Rare Candies, Blizzard, Celadon Gym: Tamia, Lori, Erika | 21 | +| 00.41 | East to Saffron: the TEA at the gate, the Fighting Dojo's Hitmonchan (Gift RNG placeholder), the Center | 13 | +| 00.42 | Silph Co.: the CARD KEY, the rival on 7F, the Lapras (Gift RNG placeholder) | 10 | +| 00.43 | Silph Co. 11F: the boardroom Grunt, Giovanni; then Sabrina | 13 | +| 00.44 | Fly to Viridian: Viridian Gym: Takashi, Warren, Giovanni | 14 | +| 00.45 | Route 22: the rival; Route 23's badge gates; Strength | 7 | +| 00.46 | Victory Road's boulders, Indigo Plateau: Full Restores, the nurse, the save | 8 | +| 00.47 | Lorelei | 4 | +| 00.48 | Bruno | 3 | +| 00.49 | Agatha | 3 | +| 00.50 | Lance | 3 | +| 00.51 | The Champion and the Hall of Fame | 4 | + +## Conventions + +- A `battle` event's `id` is the battle's id in PokemonSimulation + `docs/battles/pokeguy-trainers.json`, e.g. `route8-rich`, `koga`. Its strategy + belongs to the battle agent, not to these files. Two battles have no entry + there: `tower-marowak` (an `events.json` scripted fight) and + `dojo-karate-master` (not in PokeGuy's run). +- Shopping is a `mart ...` `game_action` with the quantities from + PokemonSimulation `docs/battles/pokeguy-conditions.md` bags and PokeGuy's + receipts: Lavender (4 Escape Ropes, 7 Super Repels), Celadon 5F (6 X Speed, + 21 X Special, 5 X Accuracy, 2 Guard Spec), Indigo Plateau (12 Full Restores). +- A pickup faces the ball and talks (A). Hidden items (Cycling Road's Rare Candy + and Max Elixir, the Mansion's Elixir) have no tile in the candidate maps. +- The story's shiny gifts are placeholders: a `party_room free=1` check, then a + `gift_rng ` handoff, for the Eevee (00.32b), the Omanyte from the Helix + Fossil (00.38b), the Hitmonchan (00.41) and the Lapras (00.42). The authored + format can't yet say `handoff`/`live_start` as 00.12/00.12b do in C++. +- New `game_action` variants that no executor has yet: `party_room`, + `gift_rng`, `use_item`, `fly`, `flee_wild`, `surf`, `strength_puzzle`, + `reenter_map`. The `mart` variants name Marts the Mart table doesn't list + yet (Lavender, Celadon 5F, Indigo Plateau). +- HMs and key items come in story order: LIFT KEY, SILPH SCOPE, HM02 Fly, TEA, + POKE FLUTE, HM03 Surf, GOLD TEETH, HM04 Strength, SECRET KEY, CARD KEY. + +## Decisions for the user + +- **A Pidgey for Fly.** PokeGuy flies everywhere from 1:03; the story party has + no flier. 00.29 catches a Pidgey in Route 7's grass (Route 8's grass is behind + two Cut trees). Without Fly, Cinnabar needs a long walk round to Pallet. +- **TM14 Blizzard over Mega Kick** (00.40) is a one-shot TM: it needs the team + plan first. +- **Strength over Water Pulse** (00.45) and **Surf over Water Gun** (00.37) + follow PokeGuy. +- **The Hitmonchan** needs the Dojo's Karate Master beaten, a fight PokeGuy + skipped. + +## Leg check + +Every `route` event was planned on PokemonSimulation `6c2f5c8` +(`data/games/frlg/maps/source-candidate`, plus `runtime` for the maps the +candidate set lacks) with `RuntimeWorld` and the shared `shortest_path()`, from +the previous event's pose. 74 legs plan; 36 are skipped, none fails. The +planner ignores trainer sight, Surf, Strength, spinner and quiz tiles, and holds +NPC wander boxes as walls. No map was edited. Where a leg crosses a map edge on +an open tile (Lavender to Route 8, Route 7 to Celadon), the executor should hold +it to a wall, because of the known off-by-one on unheld crossings. + +Two candidate maps look wrong; these are map questions for the user, not edits: +the Elite Four rooms' arrival points (e.g. Lorelei's `warp_0` (6, 12)) are +wall tiles, and Indigo Plateau's door glyph is at (11, 5) with its warp at +(11, 6). + +| Skipped leg | Why | +|---|---| +| 00.29/celadon_nurse | map not in source-candidate | +| 00.31/b2f_lift | B2F's lift corner is reached over arrow tiles the planner does not solve | +| 00.31/b4f_below_guards | RocketHideout_Elevator map not in source-candidate | +| 00.32/x_item_clerk | CeladonCity_DepartmentStore_Elevator map not in source-candidate | +| 00.32/route16_below_tree | CeladonCity_DepartmentStore_Elevator map not in source-candidate | +| 00.32/celadon_nurse | map not in source-candidate | +| 00.32b/eevee_ball | Condominiums 2F/3F/RoofRoom map not in source-candidate | +| 00.35/cycling_road_rare_candy | Route17 map not in source-candidate | +| 00.35/cycling_road_max_elixir | Route17 map not in source-candidate | +| 00.35/fuchsia_below_center | Route17 map not in source-candidate | +| 00.35/fuchsia_nurse | map not in source-candidate | +| 00.37/fuchsia_nurse | map not in source-candidate | +| 00.38/mansion_b1f | the statue-switch gates and the floor drop are not modeled | +| 00.38/hidden_elixir_spot | hidden item tiles are not in the candidate maps | +| 00.38/below_tm14 | the statue-switch gates are not modeled | +| 00.38/below_secret_key | the statue-switch gates are not modeled | +| 00.38/cinnabar_nurse | map not in source-candidate | +| 00.38b/fossil_scientist | CinnabarIsland_PokemonLab_* map not in source-candidate | +| 00.39/below_blaine | the quiz doors are not modeled | +| 00.40/celadon_nurse | map not in source-candidate | +| 00.41/karate_master | SaffronCity_Dojo map not in source-candidate | +| 00.41/hitmonchan_ball | SaffronCity_Dojo map not in source-candidate | +| 00.41/saffron_center_door | SaffronCity_Dojo map not in source-candidate | +| 00.41/saffron_nurse | map not in source-candidate | +| 00.43/below_sabrina | warp-tile room order not planned: check SaffronCity_Gym warps | +| 00.44/takashi_line | arrow tiles and trainer lines not planned | +| 00.44/warren_line | arrow tiles and trainer lines not planned | +| 00.44/below_gym_giovanni | start unknown | +| 00.45/victory_road_door | Surf legs between the gates are not planned | +| 00.46/indigo_door | Victory Road boulder states are not modeled | +| 00.46/indigo_clerk | the Plateau door (11, 6) does not lead in on the candidate maps (no door glyph under the credits NPCs) | +| 00.47/below_lorelei | E4 arrival: the room's arrival point is a wall tile in the candidate map (map question, not edited) | +| 00.48/below_bruno | E4 arrival: the room's arrival point is a wall tile in the candidate map (map question, not edited) | +| 00.49/below_agatha | E4 arrival: the room's arrival point is a wall tile in the candidate map (map question, not edited) | +| 00.50/below_lance | E4 arrival: the room's arrival point is a wall tile in the candidate map (map question, not edited) | +| 00.51/below_champion | E4 arrival: the room's arrival point is a wall tile in the candidate map (map question, not edited) | + +The native codec (`Pokemon::read_authored_checkpoint()`, built alone from the +story-data-tests sources) and PokemonSimulation's `read_authored_checkpoint()` +both read all 25 files. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.29.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.29.plan.json new file mode 100644 index 0000000000..135608d5d2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.29.plan.json @@ -0,0 +1,91 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.29", + "title": "Lavender Mart, then west over Route 8: Gamer Rich, a Pidgey for Fly, the Underground Path to Celadon", + "start": {"certainty": "tile", "map": "LavenderTown_PokemonCenter_1F", "where": {"facing": "north", "kind": "tiles", "tiles": [[7, 4]]}}, + "events": [ + { + "id": "lavender_mart_clerk", + "kind": "route", + "target": {"certainty": "tile", "map": "LavenderTown_Mart", "where": {"facing": "west", "kind": "tiles", "tiles": [[4, 3]]}}, + "variant": "run", + "why": "out of the Center, east along row 6 and down to the Mart (20, 15), to its clerk" + }, + { + "id": "buy_ropes_and_super_repels", + "kind": "game_action", + "variant": "mart LavenderTown_Mart budget=5700 floor=9000 escape-rope=4 super-repel=7", + "why": "pokeguy 54:18: 4 Escape Ropes and 7 Super Repels" + }, + { + "id": "east_of_rich_line", + "kind": "route", + "target": {"certainty": "tile", "map": "Route8", "where": {"facing": "west", "kind": "tiles", "tiles": [[56, 18]]}}, + "variant": "run", + "why": "west out of Lavender onto Route 8, down column 64 east of Julia (62, 14) and west along row 18" + }, + { + "id": "rich_line", + "kind": "step", + "direction": "west", + "variant": "trainer_line", + "why": "onto (55, 18), the end of Rich's line (55, 16..18): he walks down to (55, 17)" + }, + { + "id": "route8-rich", + "kind": "battle", + "declared_after": {"certainty": "tile", "map": "Route8", "where": {"facing": "north", "kind": "tiles", "tiles": [[55, 18]]}}, + "why": "Gamer Rich (TRAINER_GAMER_RICH): Growlithe, Vulpix Lv24" + }, + { + "id": "below_underground_door", + "kind": "route", + "target": {"certainty": "tile", "map": "Route8", "where": {"facing": "north", "kind": "tiles", "tiles": [[13, 5]]}}, + "variant": "run", + "why": "west along rows 14..18, up column 14 east of Aidan's line (10..13, 6), to below the Underground Path door (13, 4)" + }, + { + "id": "route7_underground_exit", + "kind": "route", + "target": {"certainty": "tile", "map": "Route7", "where": {"facing": "south", "kind": "tiles", "tiles": [[7, 15]]}}, + "variant": "run", + "why": "through the door, the east entrance, the east-west tunnel and the west entrance, out onto Route 7" + }, + { + "id": "pidgey_grass", + "kind": "route", + "target": {"certainty": "tile", "map": "Route7", "where": {"facing": "east", "kind": "tiles", "tiles": [[14, 5]]}}, + "variant": "run", + "why": "north round the ledges into Route 7's grass (11..16, 2..5), a grass tile east of it free; Route 8's grass is behind two Cut trees" + }, + { + "id": "catch_pidgey", + "kind": "game_action", + "variant": "capture pidgey catches=1 encounters=30 balls=5 pace=east", + "why": "a Pidgey to carry HM02 Fly (pokeguy flies with a Pidgey from 1:03 on); the party has no other flier" + }, + { + "id": "celadon_below_center", + "kind": "route", + "target": {"certainty": "tile", "map": "CeladonCity", "where": {"facing": "north", "kind": "tiles", "tiles": [[48, 12]]}}, + "variant": "run", + "why": "north round the grass, west onto Celadon (row 12..15) and along row 12 to below the Center door (48, 11)" + }, + { + "id": "celadon_nurse", + "kind": "route", + "target": {"certainty": "tile", "map": "CeladonCity_PokemonCenter_1F", "where": {"facing": "north", "kind": "tiles", "tiles": [[7, 4]]}}, + "variant": "run", + "why": "into the Center, to the nurse" + }, + { + "id": "heal_celadon", + "kind": "heal", + "why": "the nurse heals the party" + } + ] + }, + "execution": {"menu": "full"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.30.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.30.plan.json new file mode 100644 index 0000000000..0b256ee6be --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.30.plan.json @@ -0,0 +1,86 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.30", + "title": "Celadon Game Corner and the Rocket Hideout down to B4F: the poster guard, the Lift Key Grunt, the LIFT KEY and B3F's Rare Candy", + "start": {"certainty": "tile", "map": "CeladonCity_PokemonCenter_1F", "where": {"facing": "north", "kind": "tiles", "tiles": [[7, 4]]}}, + "events": [ + { + "id": "celadon_below_game_corner", + "kind": "route", + "target": {"certainty": "tile", "map": "CeladonCity", "where": {"facing": "north", "kind": "tiles", "tiles": [[34, 22]]}}, + "variant": "run", + "why": "out of the Center, west along row 12, down column 41..43 to row 22, west to below the Game Corner (34, 21)" + }, + { + "id": "below_poster_guard", + "kind": "route", + "target": {"certainty": "tile", "map": "CeladonCity_GameCorner", "where": {"facing": "north", "kind": "tiles", "tiles": [[11, 3]]}}, + "variant": "run", + "why": "into the Game Corner, up the slot rows to below the Grunt (11, 2) in front of the poster" + }, + { + "id": "talk_poster_guard", + "kind": "talk", + "why": "the Grunt guarding the poster" + }, + { + "id": "hideout-poster-guard", + "kind": "battle", + "declared_after": {"certainty": "tile", "map": "CeladonCity_GameCorner", "where": {"facing": "north", "kind": "tiles", "tiles": [[11, 3]]}}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_7): Raticate, Zubat Lv20; he runs off" + }, + { + "id": "poster_switch", + "kind": "talk", + "why": "the poster (11, 1): the switch opens the stairs (15, 2)" + }, + { + "id": "hideout_b4f_west", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "west", "kind": "tiles", "tiles": [[5, 3]]}}, + "variant": "run", + "why": "the stairs (15, 2) down to B1F, B1F to B2F (17, 2), B2F's arrow tiles to B3F (21, 2), B3F to B4F (15, 18), round to (5, 3), east of the tile below the Grunt (4, 2)" + }, + { + "id": "key_grunt_line", + "kind": "step", + "direction": "west", + "variant": "trainer_line", + "why": "onto (4, 3), in the Grunt's line (sight 1)" + }, + { + "id": "hideout-key-grunt", + "kind": "battle", + "declared_after": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "west", "kind": "tiles", "tiles": [[4, 3]]}}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_18): Koffing, Zubat Lv21; he drops the LIFT KEY" + }, + { + "id": "below_lift_key", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "north", "kind": "tiles", "tiles": [[3, 3]]}}, + "variant": "run", + "why": "a tile west, below the LIFT KEY (3, 2)" + }, + { + "id": "lift_key", + "kind": "talk", + "why": "pick up the LIFT KEY (pokeguy 57:33)" + }, + { + "id": "beside_b3f_rare_candy", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B3F", "where": {"facing": "north", "kind": "tiles", "tiles": [[12, 13]]}}, + "variant": "run", + "why": "back up the stairs to B3F, below the Rare Candy (12, 12) beside the arrow tiles" + }, + { + "id": "b3f_rare_candy", + "kind": "talk", + "why": "pick up the Rare Candy: two, with Route 9's" + } + ] + }, + "execution": {"menu": "full"} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.31.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.31.plan.json new file mode 100644 index 0000000000..e040f84d88 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/Draft/frlg-00.31.plan.json @@ -0,0 +1,105 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "00.31", + "title": "Rocket Hideout: the lift to B4F, the two door guards, two Rare Candies, Blastoise, Giovanni and the SILPH SCOPE", + "start": {"certainty": "tile", "map": "RocketHideout_B3F", "where": {"facing": "north", "kind": "tiles", "tiles": [[12, 13]]}}, + "events": [ + { + "id": "b2f_lift", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B2F", "where": {"facing": "north", "kind": "tiles", "tiles": [[28, 17]]}}, + "variant": "run", + "why": "up to B2F, along the arrow tiles to the lift (28..29, 16)" + }, + { + "id": "lift_to_b4f", + "kind": "scene", + "why": "the LIFT KEY works the lift: B4F" + }, + { + "id": "b4f_below_guards", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "north", "kind": "tiles", "tiles": [[17, 16]]}}, + "variant": "run", + "why": "out of the lift to below the two Grunts (16, 14) and (19, 14)" + }, + { + "id": "talk_left_guard", + "kind": "talk", + "why": "the left door guard" + }, + { + "id": "hideout-left-guard", + "kind": "battle", + "declared_after": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "north", "kind": "tiles", "tiles": [[17, 16]]}}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_16): Sandshrew, Sandslash, Ekans Lv23" + }, + { + "id": "talk_right_guard", + "kind": "talk", + "why": "the right door guard" + }, + { + "id": "hideout-right-guard", + "kind": "battle", + "declared_after": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "north", "kind": "tiles", "tiles": [[17, 16]]}}, + "why": "Rocket Grunt (TRAINER_TEAM_ROCKET_GRUNT_17): Ekans, Sandshrew, Arbok Lv23; the door opens" + }, + { + "id": "rare_candy_1", + "kind": "game_action", + "variant": "use_item rare-candy slot=1", + "why": "Rare Candy: Lv35 (pokeguy 1:00:25)" + }, + { + "id": "rare_candy_2", + "kind": "game_action", + "variant": "use_item rare-candy slot=1", + "why": "Rare Candy: Lv36, Wartortle evolves" + }, + { + "id": "evolve_blastoise", + "kind": "scene", + "why": "Wartortle evolves into Blastoise; do not press B" + }, + { + "id": "below_giovanni", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "north", "kind": "tiles", "tiles": [[19, 5]]}}, + "why": "through the door to below Giovanni (19, 4)" + }, + { + "id": "talk_giovanni", + "kind": "talk", + "why": "Giovanni" + }, + { + "id": "hideout-giovanni", + "kind": "battle", + "declared_after": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "north", "kind": "tiles", "tiles": [[19, 5]]}}, + "why": "Giovanni (TRAINER_BOSS_GIOVANNI): Onix, Rhyhorn, Kangaskhan" + }, + { + "id": "beside_silph_scope", + "kind": "route", + "target": {"certainty": "tile", "map": "RocketHideout_B4F", "where": {"facing": "west", "kind": "tiles", "tiles": [[21, 5]]}}, + "why": "round to east of the SILPH SCOPE (20, 5)" + }, + { + "id": "silph_scope", + "kind": "talk", + "why": "pick up the SILPH SCOPE" + }, + { + "id": "escape_rope_hideout", + "kind": "game_action", + "declared_after": {"certainty": "tile", "map": "CeladonCity", "where": {"facing": "south", "kind": "tiles", "tiles": [[34, 22]]}}, + "variant": "use_item escape-rope", + "why": "out to the Game Corner's door (pokeguy 1:02:10)" + } + ] + }, + "execution": {"menu": "full"} +} From ea47c4bcec3d4112238eb94148def1dee54b6e6b Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:40:16 -0800 Subject: [PATCH 004/168] AutoStory: replay recorded frames through the real watchers A frame source serves a recording's frames (".png") by virtual time, and replay_until / replay_events feed them to VisualInferenceCallbacks or a ScreenEventObserver at the inference period on one thread, so a console failure can become a deterministic test of the real detectors. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 1 + .../AutoStory/Pokemon_AutoStory_Tests.h | 2 + .../Pokemon/AutoStory/Pokemon_FrameReplay.cpp | 121 +++++++++++ .../Pokemon/AutoStory/Pokemon_FrameReplay.h | 115 +++++++++++ .../AutoStory/Pokemon_FrameReplay_Tests.cpp | 191 ++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 6 files changed, 433 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 2f878a6551..e75bd9d513 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -81,6 +81,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ Pokemon::add_tests_ScreenEvents(ret); Pokemon::add_tests_Interrupts(ret); Pokemon::add_tests_Transitions(ret); + Pokemon::add_tests_FrameReplay(ret); Pokemon::add_tests_StoryActions(ret); Pokemon::add_tests_StoryInterrupts(ret); Pokemon::add_tests_StoryEvents(ret); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h index 10c5ab8848..180f2ff64f 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h @@ -21,6 +21,8 @@ void add_tests_ScreenEvents(UnitTestDatabase& database); void add_tests_Interrupts(UnitTestDatabase& database); // The transition tracker and the games' fade profiles. void add_tests_Transitions(UnitTestDatabase& database); +// Recorded frames replayed through the detectors on a virtual clock. +void add_tests_FrameReplay(UnitTestDatabase& database); // Story action tables, the variant parser and the table executor. void add_tests_StoryActions(UnitTestDatabase& database); // The table executor's looks for interrupts between steps. diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.cpp new file mode 100644 index 0000000000..e1b9df7eac --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.cpp @@ -0,0 +1,121 @@ +/* Frame Replay + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Pokemon_FrameReplay.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +// The time a frame file's name gives ("1250.png" -> 1250), or -1 when the +// name is not all digits or the file not a .png. +long long frame_time_of(const Filesystem::Path& file){ + if (file.extension().string() != ".png"){ + return -1; + } + const std::string stem = file.stem().string(); + if (stem.empty() || stem.size() > 9){ + return -1; + } + for (char c : stem){ + if (!std::isdigit((unsigned char)c)){ + return -1; + } + } + return std::stoll(stem); +} + +} // namespace + + +ReplayFrameSource::ReplayFrameSource(std::vector frames) + : m_frames(std::move(frames)) +{ + std::stable_sort(m_frames.begin(), m_frames.end(), [](const ReplayFrame& a, const ReplayFrame& b){ + return a.at < b.at; + }); +} + +ReplayFrameSource ReplayFrameSource::from_folder(const std::string& folder){ + std::vector frames; + if (Filesystem::is_directory(folder)){ + for (const Filesystem::Path& file : Filesystem::list_directory(folder)){ + const long long ms = frame_time_of(file); + if (ms >= 0){ + frames.push_back(ReplayFrame{.at = Milliseconds(ms), .file = file.string()}); + } + } + } + if (frames.empty()){ + throw FileException(nullptr, PA_CURRENT_FUNCTION, "No .png frames to replay.", folder); + } + return ReplayFrameSource(std::move(frames)); +} + +Milliseconds ReplayFrameSource::last_frame() const{ + return m_frames.empty() ? Milliseconds(0) : m_frames.back().at; +} + +VideoSnapshot ReplayFrameSource::frame_at(Milliseconds at, WallClock origin) const{ + auto after = std::upper_bound(m_frames.begin(), m_frames.end(), at, [](Milliseconds time, const ReplayFrame& frame){ + return time < frame.at; + }); + if (after == m_frames.begin()){ + return VideoSnapshot(); + } + ReplayFrame& frame = *(after - 1); + if (!frame.image){ + frame.image = std::make_shared(frame.file); + } + VideoSnapshot out; + out.frame = frame.image; + out.timestamp = origin + at; + return out; +} + + +ReplayHit replay_until( + const ReplayFrameSource& source, ReplayWindow window, + const std::vector& callbacks, + WallClock origin, Milliseconds period +){ + for (Milliseconds now = window.start; now < window.end; now += period){ + const VideoSnapshot frame = source.frame_at(now, origin); + if (!frame){ + continue; + } + for (size_t c = 0; c < callbacks.size(); c++){ + if (callbacks[c]->process_frame(frame)){ + return ReplayHit{.index = (int)c, .at = now}; + } + } + } + return ReplayHit{}; +} + +ScreenEventLog replay_events( + const ReplayFrameSource& source, ReplayWindow window, + ScreenEventObserver& observer, + WallClock origin, Milliseconds period +){ + ScreenEventLog log; + for (Milliseconds now = window.start; now < window.end; now += period){ + const VideoSnapshot frame = source.frame_at(now, origin); + log.record(observer.observe(frame, origin + now), origin + now); + } + return log; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h new file mode 100644 index 0000000000..12214cb444 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h @@ -0,0 +1,115 @@ +/* Frame Replay + * + * From: https://github.com/PokemonAutomation/ + * + * Recorded console frames, replayed through the real detectors on a + * virtual clock, so a console failure becomes a deterministic test. The + * story sims script what a screen shows (a label per frame); a replay + * shows what the console showed and lets the game's own watchers and + * ScreenEventObserver judge it. + * + * A recording is a folder of frames named by their time in ms from its + * start ("0.png", "1250.png"), as the captured transitions + * (Pokemon_Transitions_Tests.cpp). A frame shows until the next one. + * Recordings are too big for this repo; tests read them from + * CommandLineTests//FrameReplay// and skip when it is missing. + * + * From the stream history (an error report's Video.mp4, kept when the + * "Stream History" setting is on), cut the seconds around the failure at + * 20 frames a second, then rename frame N to its time, (N - 1) * 50 ms: + * ffmpeg -ss -t -i Video.mp4 -vf fps=20 %d.png + * + * One thread, no real time: the caller says which window of the recording + * each action watched, and the replay feeds those frames at the inference + * period, as run_until / wait_until would. + * + */ + +#ifndef PokemonAutomation_Pokemon_FrameReplay_H +#define PokemonAutomation_Pokemon_FrameReplay_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h" +#include "Pokemon_ScreenEvents.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// One recorded frame: when it showed, from the recording's start, and the +// image, or the file it loads from on first use. +struct ReplayFrame{ + Milliseconds at = Milliseconds(0); + std::string file = {}; + std::shared_ptr image = {}; +}; + + +// Recorded frames, served by virtual time. Not thread-safe: images load +// on first use. +class ReplayFrameSource{ +public: + explicit ReplayFrameSource(std::vector frames); + + // Every ".png" in `folder`. Throws FileException if it has none. + static ReplayFrameSource from_folder(const std::string& folder); + + size_t size() const{ + return m_frames.size(); + } + // When the last frame showed. + Milliseconds last_frame() const; + + // The frame showing at `at`: the last one at or before it, stamped + // `origin + at`. None before the first frame. + VideoSnapshot frame_at(Milliseconds at, WallClock origin) const; + +private: + mutable std::vector m_frames; +}; + + +// How often a replay looks: the inference loop's default period. +constexpr Milliseconds REPLAY_PERIOD = Milliseconds(50); + +// Part of a recording an action watched, in ms from its start, end +// excluded: the hold of a leg run_until watched, or a wait_until after it. +struct ReplayWindow{ + Milliseconds start = Milliseconds(0); + Milliseconds end = Milliseconds(0); +}; + +// The first callback that stopped a replay, and when. +struct ReplayHit{ + // Its index in the callbacks; -1 if none did. + int index = -1; + Milliseconds at = Milliseconds(0); +}; + +// Feeds `callbacks` the frames of `window`, one look per `period`, each +// callback in order on each look, until one returns true: wait_until on a +// recording. Frames are stamped `origin + time`. +ReplayHit replay_until( + const ReplayFrameSource& source, ReplayWindow window, + const std::vector& callbacks, + WallClock origin, Milliseconds period = REPLAY_PERIOD +); + +// What `observer` sees over `window`, one look per `period`, as a +// ScreenEventWatcher's log; the judges (Pokemon_Interrupts.h) read it. +ScreenEventLog replay_events( + const ReplayFrameSource& source, ReplayWindow window, + ScreenEventObserver& observer, + WallClock origin, Milliseconds period = REPLAY_PERIOD +); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp new file mode 100644 index 0000000000..ea2bc0294d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp @@ -0,0 +1,191 @@ +/* Frame Replay Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The frame source and the replay loop, on synthetic frames: a door's + * black between two overworld frames, watched by the shared + * BlackScreenOverWatcher the walks use and by the shared fade test. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" +#include "Pokemon_AutoStory_Tests.h" +#include "Pokemon_FrameReplay.h" +#include "Pokemon_Interrupts.h" +#include "Pokemon_ScreenEvents.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + +namespace{ + +using namespace std::chrono_literals; + +const WallClock T0 = WallClock() + std::chrono::hours(1); + +// A textured frame: a fine checkerboard, never a fade. +std::shared_ptr overworld_frame(){ + auto image = std::make_shared(64, 36); + for (size_t y = 0; y < image->height(); y++){ + for (size_t x = 0; x < image->width(); x++){ + image->pixel(x, y) = (x + y) % 2 == 0 ? 0xff306030 : 0xffd0e0a0; + } + } + return image; +} + +std::shared_ptr black_frame(){ + auto image = std::make_shared(64, 36); + image->fill(0xff000000); + return image; +} + +// A door: the overworld, black from 1000 ms to 1500 ms, the overworld again. +ReplayFrameSource door_recording(){ + return ReplayFrameSource({ + {.at = 0ms, .image = overworld_frame()}, + {.at = 1000ms, .image = black_frame()}, + {.at = 1500ms, .image = overworld_frame()}, + }); +} + +// Only the shared fade test, as every game's observer reports it. +class FadeObserver : public ScreenEventObserver{ +public: + virtual ScreenEvents observe(const VideoSnapshot& frame, WallClock) override{ + if (!frame){ + return {}; + } + return fade_events(fade_of_screen(*frame.frame)); + } + virtual void make_overlays(VideoOverlaySet&) const override{} +}; + + +UnitTestResult test_frame_at(){ + const ReplayFrameSource source = door_recording(); + if (source.size() != 3 || source.last_frame() != 1500ms){ + return "the recording does not hold its three frames"; + } + const VideoSnapshot black = source.frame_at(1499ms, T0); + if (!black || fade_of_screen(*black.frame) != WarpFade::BLACK || black.timestamp != T0 + 1499ms){ + return "the frame at 1499 ms is not the black one, stamped 1499 ms"; + } + if (fade_of_screen(*source.frame_at(1500ms, T0).frame) != WarpFade::NONE){ + return "the frame at 1500 ms is not the overworld"; + } + const ReplayFrameSource late({{.at = 200ms, .image = black_frame()}}); + if (late.frame_at(100ms, T0)){ + return "a frame shows before the first one"; + } + return true; +} + +UnitTestResult test_missing_folder(){ + try{ + ReplayFrameSource::from_folder("FrameReplay/no such recording/"); + }catch (FileException&){ + return true; + } + return "a missing folder gave a recording"; +} + +// The walks' wait for a warp (BlackScreenOverWatcher after the hold) sees +// the door when it watches from before the black. +UnitTestResult test_watcher_sees_fade(){ + BlackScreenOverWatcher arrival; + const ReplayHit hit = replay_until(door_recording(), {0ms, 8000ms}, {&arrival}, T0); + if (hit.index != 0 || hit.at < 1500ms || hit.at > 1700ms){ + return std::format("expected the watcher to stop 1500 to 1700 ms in, got index {} at {} ms", hit.index, hit.at.count()); + } + return true; +} + +// A watcher started once the black is over never fires: a walk that holds +// onto a door and only then waits for the fade reports "no fade" though +// the warp happened. +UnitTestResult test_late_watcher_misses_fade(){ + BlackScreenOverWatcher arrival; + const ReplayHit hit = replay_until(door_recording(), {1600ms, 9600ms}, {&arrival}, T0); + if (hit.index != -1){ + return std::format("expected no stop, got index {} at {} ms", hit.index, hit.at.count()); + } + return true; +} + +UnitTestResult test_events_judged(){ + const ReplayFrameSource source = door_recording(); + FadeObserver observer; + const ScreenEventLog log = replay_events(source, {0ms, 3000ms}, observer, T0); + const InterruptWindow whole{T0, T0 + 3000ms}; + const WarpJudgement seen = judge_warp(log, whole, InterruptKnobs{}, SceneChange::DIFFERENT).judgement; + if (seen != WarpJudgement::WARPED){ + return std::format("from the start: expected warped, got {}", warp_judgement_name(seen)); + } + FadeObserver late_observer; + const ScreenEventLog late = replay_events(source, {1600ms, 3000ms}, late_observer, T0); + const WarpJudgement missed = judge_warp(late, whole, InterruptKnobs{}, SceneChange::DIFFERENT).judgement; + if (missed != WarpJudgement::NO_FADE){ + return std::format("after the black: expected no fade, got {}", warp_judgement_name(missed)); + } + return true; +} + + +struct FrameReplayInput{ + std::string name; + std::function body; +}; + +// The body checks its own expectations. +struct FrameReplayExpectation{ +}; + +struct FrameReplayCase{ + FrameReplayInput input; + FrameReplayExpectation expectation; +}; + +class Test_FrameReplay : public UnitTest{ +public: + explicit Test_FrameReplay(FrameReplayCase test_case) + : UnitTest("Pokemon::FrameReplay - " + test_case.input.name) + , m_input(std::move(test_case.input)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return m_input.body(); + } + +private: + FrameReplayInput m_input; +}; + +const FrameReplayCase FRAME_REPLAY_CASES[] = { + {.input = {"the frame showing at a time", test_frame_at}}, + {.input = {"a missing recording throws", test_missing_folder}}, + {.input = {"the warp watcher sees a door's black", test_watcher_sees_fade}}, + {.input = {"a warp watcher started after the black misses it", test_late_watcher_misses_fade}}, + {.input = {"the replayed events judged as a warp", test_events_judged}}, +}; + +} // namespace + + +void add_tests_FrameReplay(UnitTestDatabase& database){ + for (const auto& item : FRAME_REPLAY_CASES){ + database.add(item); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index fc888392dc..117c31badf 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1498,6 +1498,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_AutoStorySelect_Tests.h Source/Pokemon/AutoStory/Pokemon_AutoStoryStats.h Source/Pokemon/AutoStory/Pokemon_AutoStory_Tests.h + Source/Pokemon/AutoStory/Pokemon_FrameReplay.cpp + Source/Pokemon/AutoStory/Pokemon_FrameReplay.h + Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp Source/Pokemon/AutoStory/Pokemon_Interrupts.cpp Source/Pokemon/AutoStory/Pokemon_Interrupts.h Source/Pokemon/AutoStory/Pokemon_Interrupts_Tests.cpp From 1cfecb8c810885e7e425f22c088453a31947f6ed Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:41:28 -0800 Subject: [PATCH 005/168] FRLG AutoStory: replay the 00.27 Route 10 door failures from their frames The walk's warp watcher and FRLG's screen events, replayed over each run's end frame (CommandLineTests/PokemonFRLG/FrameReplay/), agree that no fade showed: the walk ended off the door, not past a missed fade. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + ...PokemonFRLG_AutoStoryFrameReplay_Tests.cpp | 145 ++++++++++++++++++ .../PokemonFRLG_AutoStoryFrameReplay_Tests.h | 26 ++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 4 files changed, 175 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 2bf7183092..6360a6e9f9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -9,6 +9,7 @@ #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/StaticGlobals.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h" #include "Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h" #include "Inference/Box/PokemonFRLG_BoxCellReader.h" @@ -880,6 +881,7 @@ static void add_tests_AutoStoryReaders(UnitTestDatabase& database){ add_tests_SummaryMovesReader(database); add_tests_TeachScreenReader(database); add_tests_AutoStoryScreenEvents(database); + add_tests_AutoStoryFrameReplay(database); } // The naming screen's cursor, plans, keys and text. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp new file mode 100644 index 0000000000..0da9021ce8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp @@ -0,0 +1,145 @@ +/* FRLG AutoStory - Frame Replay Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Console failures of the walk's warp check, replayed from their frames + * through the watcher the walk uses (BlackScreenOverWatcher, after the + * hold) and through FRLG's screen events, judged by the shared judges. + * Each case's frames are in CommandLineTests/PokemonFRLG/FrameReplay// + * (".png", Pokemon_FrameReplay.h); a case skips when they are missing. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonTools/VisualDetectors/BlackScreenDetector.h" +#include "Pokemon/AutoStory/Pokemon_FrameReplay.h" +#include "Pokemon/AutoStory/Pokemon_Interrupts.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" +#include "PokemonFRLG_AutoStoryFrameReplay_Tests.h" +#include "PokemonFRLG_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +namespace{ + +using namespace std::chrono_literals; + +const WallClock T0 = WallClock() + std::chrono::hours(1); + +// As the walk's WARP_TIMEOUT (PokemonFRLG_OverworldWalk.cpp). +constexpr Milliseconds WARP_WAIT = 8000ms; + +// A warp leg: the player holds onto the door for `hold`, the walk then +// waits for the fade (wait_out_warp()). +struct WarpReplayInput{ + // The case's folder under CommandLineTests/PokemonFRLG/FrameReplay/. + std::string recording; + Milliseconds hold; +}; + +struct WarpReplayExpectation{ + // "fade over at ms" or "no fade", from BlackScreenOverWatcher. + std::string watcher; + // judge_warp() and classify_interrupt() over FRLG's events. + std::string warp; + std::string interrupt; +}; + +struct WarpReplayCase{ + std::string name; + WarpReplayInput input; + WarpReplayExpectation expectation; +}; + +std::string replay_watcher(const Pokemon::ReplayFrameSource& source, const WarpReplayInput& input){ + BlackScreenOverWatcher arrival(COLOR_RED); + const Pokemon::ReplayWindow wait{input.hold, input.hold + WARP_WAIT}; + const Pokemon::ReplayHit hit = Pokemon::replay_until(source, wait, {&arrival}, T0); + return hit.index < 0 ? "no fade" : std::format("fade over at {} ms", hit.at.count()); +} + +class Test_WarpReplay : public UnitTest{ +public: + explicit Test_WarpReplay(WarpReplayCase test_case) + : UnitTest("PokemonFRLG::AutoStory - Frame replay: " + test_case.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string folder = UNIT_TEST_RESOURCE_PATH() + "PokemonFRLG/FrameReplay/" + m_case.input.recording + "/"; + std::optional source; + try{ + source.emplace(Pokemon::ReplayFrameSource::from_folder(folder)); + }catch (FileException& e){ + return UnitTestResult(UnitTestResult::SKIPPED, e.message()); + } + const std::string watcher = replay_watcher(*source, m_case.input); + + FrlgScreenObserver observer; + const Pokemon::ReplayWindow whole{0ms, m_case.input.hold + WARP_WAIT}; + const Pokemon::ScreenEventLog log = Pokemon::replay_events(*source, whole, observer, T0); + const Pokemon::InterruptWindow window{T0, T0 + whole.end}; + const std::string warp = Pokemon::warp_judgement_name( + Pokemon::judge_warp(log, window, Pokemon::InterruptKnobs{}, Pokemon::SceneChange::UNKNOWN).judgement + ); + const std::string interrupt = Pokemon::interrupt_kind_name( + Pokemon::classify_interrupt(log, window, Pokemon::InterruptKnobs{}).kind + ); + + const WarpReplayExpectation& expected = m_case.expectation; + if (watcher != expected.watcher || warp != expected.warp || interrupt != expected.interrupt){ + return std::format( + "expected watcher \"{}\", warp \"{}\", interrupt \"{}\"; got \"{}\", \"{}\", \"{}\"; events:\n{}", + expected.watcher, expected.warp, expected.interrupt, watcher, warp, interrupt, + Pokemon::describe(log, T0) + ); + } + return true; + } + +private: + WarpReplayCase m_case; +}; + +// 00.27 route10_nurse, console B 2026-11-09, runs 3 and 2: "no fade in +// and out after walking onto the warp to Route10_PokemonCenter_1F". The +// frames are the end screens of the runs (no stream history was kept): +// the player on Route10 (14, 10) in the grass and on (16, 19) beside the +// Center, not on its door (13, 20). The detectors agree there was no +// fade: the walk ended off the door (timed legs one tile off), not a +// missed fade (FRLGLab notes 2026-11-09-0027-route10-evidence). +const WarpReplayCase WARP_REPLAY_CASES[] = { + { + .name = "00.27 route10_nurse run 3: ended in the grass, no fade", + .input = {"0027-route10-run3", TILE_TIME + STEP_RELEASE}, + .expectation = {"no fade", "no fade", "none"}, + }, + { + .name = "00.27 route10_nurse run 2: ended beside the Center, no fade", + .input = {"0027-route10-run2", TILE_TIME + STEP_RELEASE}, + .expectation = {"no fade", "no fade", "none"}, + }, +}; + +} // namespace + + +void add_tests_AutoStoryFrameReplay(UnitTestDatabase& database){ + for (const auto& item : WARP_REPLAY_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h new file mode 100644 index 0000000000..c6da2374ee --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h @@ -0,0 +1,26 @@ +/* FRLG AutoStory - Frame Replay Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryFrameReplay_Tests_H +#define PokemonAutomation_PokemonFRLG_AutoStoryFrameReplay_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Console failures replayed from their recorded frames +// (CommandLineTests/PokemonFRLG/FrameReplay/) through FRLG's detectors. +void add_tests_AutoStoryFrameReplay(UnitTestDatabase& database); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 489ca0e64c..7f08470f1e 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1914,6 +1914,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFoeTracker.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGrind_Tests.cpp From ecc08f89704f4e3069cd5f1a2d23d60555c505dc Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:42:08 -0800 Subject: [PATCH 006/168] FRLG frame replay: name the one-tile hold from the walk's constants Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp index 0da9021ce8..5ad69c9f58 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp @@ -38,6 +38,9 @@ const WallClock T0 = WallClock() + std::chrono::hours(1); // As the walk's WARP_TIMEOUT (PokemonFRLG_OverworldWalk.cpp). constexpr Milliseconds WARP_WAIT = 8000ms; +// A one-tile walk onto a door: a tile's time, then the release. +constexpr Milliseconds ONE_TILE_HOLD = OverworldWalkSteps::TILE_TIME + OverworldWalkSteps::STEP_RELEASE; + // A warp leg: the player holds onto the door for `hold`, the walk then // waits for the fade (wait_out_warp()). struct WarpReplayInput{ @@ -119,12 +122,12 @@ class Test_WarpReplay : public UnitTest{ const WarpReplayCase WARP_REPLAY_CASES[] = { { .name = "00.27 route10_nurse run 3: ended in the grass, no fade", - .input = {"0027-route10-run3", TILE_TIME + STEP_RELEASE}, + .input = {"0027-route10-run3", ONE_TILE_HOLD}, .expectation = {"no fade", "no fade", "none"}, }, { .name = "00.27 route10_nurse run 2: ended beside the Center, no fade", - .input = {"0027-route10-run2", TILE_TIME + STEP_RELEASE}, + .input = {"0027-route10-run2", ONE_TILE_HOLD}, .expectation = {"no fade", "no fade", "none"}, }, }; From 1d0cef56f9cb14f2a394a8f45b88b4309e31832a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:43:55 -0800 Subject: [PATCH 007/168] AutoStory frame replay: designated test cases; keep the runner's registration function at 50 lines Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 1 - .../Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp | 10 +++++----- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index e75bd9d513..c40f6db961 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -55,7 +55,6 @@ namespace ComputerPrograms{ UnitTestDatabase make_UNIT_TESTS_ALL(){ UnitTestDatabase ret; - add_tests_QtEventThreadPool(ret, GlobalThreadPools::computation_normal()); add_tests_Sockets(ret, GlobalThreadPools::unlimited_normal()); add_tests_BlackBorderDetector(ret); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp index ea2bc0294d..c07748a3d0 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp @@ -169,11 +169,11 @@ class Test_FrameReplay : public UnitTest{ }; const FrameReplayCase FRAME_REPLAY_CASES[] = { - {.input = {"the frame showing at a time", test_frame_at}}, - {.input = {"a missing recording throws", test_missing_folder}}, - {.input = {"the warp watcher sees a door's black", test_watcher_sees_fade}}, - {.input = {"a warp watcher started after the black misses it", test_late_watcher_misses_fade}}, - {.input = {"the replayed events judged as a warp", test_events_judged}}, + {.input = {"the frame showing at a time", test_frame_at}, .expectation = {}}, + {.input = {"a missing recording throws", test_missing_folder}, .expectation = {}}, + {.input = {"the warp watcher sees a door's black", test_watcher_sees_fade}, .expectation = {}}, + {.input = {"a warp watcher started after the black misses it", test_late_watcher_misses_fade}, .expectation = {}}, + {.input = {"the replayed events judged as a warp", test_events_judged}, .expectation = {}}, }; } // namespace From 1af5d31c79f12ad3c24259b9a98a87b5c5147b01 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:44:02 -0800 Subject: [PATCH 008/168] FRLG frame replay: designated cases; register them with the screen events' tests PokemonFRLG_Tests.cpp is at its 1000-line limit. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 2 -- .../PokemonFRLG_AutoStoryFrameReplay_Tests.cpp | 10 ++++------ .../PokemonFRLG_AutoStoryScreenEvents_Tests.cpp | 3 +++ 3 files changed, 7 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 6360a6e9f9..2bf7183092 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -9,7 +9,6 @@ #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/StaticGlobals.h" -#include "Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents.h" #include "Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h" #include "Inference/Box/PokemonFRLG_BoxCellReader.h" @@ -881,7 +880,6 @@ static void add_tests_AutoStoryReaders(UnitTestDatabase& database){ add_tests_SummaryMovesReader(database); add_tests_TeachScreenReader(database); add_tests_AutoStoryScreenEvents(database); - add_tests_AutoStoryFrameReplay(database); } // The naming screen's cursor, plans, keys and text. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp index 5ad69c9f58..e6846b683d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp @@ -44,6 +44,7 @@ constexpr Milliseconds ONE_TILE_HOLD = OverworldWalkSteps::TILE_TIME + Overworld // A warp leg: the player holds onto the door for `hold`, the walk then // waits for the fade (wait_out_warp()). struct WarpReplayInput{ + std::string name; // The case's folder under CommandLineTests/PokemonFRLG/FrameReplay/. std::string recording; Milliseconds hold; @@ -58,7 +59,6 @@ struct WarpReplayExpectation{ }; struct WarpReplayCase{ - std::string name; WarpReplayInput input; WarpReplayExpectation expectation; }; @@ -73,7 +73,7 @@ std::string replay_watcher(const Pokemon::ReplayFrameSource& source, const WarpR class Test_WarpReplay : public UnitTest{ public: explicit Test_WarpReplay(WarpReplayCase test_case) - : UnitTest("PokemonFRLG::AutoStory - Frame replay: " + test_case.name) + : UnitTest("PokemonFRLG::AutoStory - Frame replay: " + test_case.input.name) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -121,13 +121,11 @@ class Test_WarpReplay : public UnitTest{ // missed fade (FRLGLab notes 2026-11-09-0027-route10-evidence). const WarpReplayCase WARP_REPLAY_CASES[] = { { - .name = "00.27 route10_nurse run 3: ended in the grass, no fade", - .input = {"0027-route10-run3", ONE_TILE_HOLD}, + .input = {"00.27 route10_nurse run 3: ended in the grass, no fade", "0027-route10-run3", ONE_TILE_HOLD}, .expectation = {"no fade", "no fade", "none"}, }, { - .name = "00.27 route10_nurse run 2: ended beside the Center, no fade", - .input = {"0027-route10-run2", ONE_TILE_HOLD}, + .input = {"00.27 route10_nurse run 2: ended beside the Center, no fade", "0027-route10-run2", ONE_TILE_HOLD}, .expectation = {"no fade", "no fade", "none"}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp index 7f8182bccc..8781ba736f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryScreenEvents_Tests.cpp @@ -14,6 +14,7 @@ #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "PokemonFRLG_AutoStoryFrameReplay_Tests.h" #include "PokemonFRLG_AutoStoryScreenEvents.h" namespace PokemonAutomation{ @@ -88,6 +89,8 @@ void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database){ for (const auto& item : SCREEN_EVENTS_CASES){ database.add(item); } + // The same events on recorded console frames. + add_tests_AutoStoryFrameReplay(database); } From 117649846eccd7712a4b7c8760d59561c958d0d5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 10:56:15 -0800 Subject: [PATCH 009/168] FRLG AutoStory 00.28: sim tests for wild battles every few steps in Rock Tunnel Console B, 2026-11-09: B1F row 37 met a wild battle 10 to 14 tiles into every try and the walker gave up after 9 stops. Red: both fail. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_AutoStoryLavender_Tests.cpp | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp index 65ad046355..4c96611513 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLavender_Tests.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -140,6 +141,67 @@ UnitTestResult test_rock_tunnel_wild_battles(){ return row_on_sim("00.28", script, ROCK_TUNNEL_TRAINERS, MapPosition{StoryTable::ROUTE10, {8, 58}}); } +// Wild battles on the tunnel's floor, `gaps` steps apart in turn, from the +// first step: as many as a row walks. +SimScript battles_every(const std::vector& gaps){ + SimScript script; + int step = 0; + for (size_t c = 0; step < 3000; c++){ + step += gaps[c % gaps.size()]; + script.encounters.push_back(SimEncounter{.grass_step = step}); + } + return script; +} + +// 00.28's step `name`: where it is in the row. +size_t step_index(const StoryCheckpoint& row, std::string_view name){ + for (size_t c = 0; c < row.steps.size(); c++){ + if (row.steps[c].name == name){ + return c; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No step {} in {}.", name, row.id)); +} + +// Console B, 2026-11-09: after Winston, the walk west along B1F row 37 to +// (13, 37) met a wild battle 10 to 14 tiles into every try. Each time the +// walker found the player again at the east wall (45, 37), behind where +// the leg started, and walked the whole 32 tiles again, until it gave up +// ("stopped part-way 9 times"). From Winston's tile, with a battle every +// 10 to 14 steps, the steps from below_martha_line on reach Martha's line. +UnitTestResult test_b1f_row37_battles_every_12(){ + const StoryCheckpoint& row = checkpoint("00.28"); + const size_t first = step_index(row, "below_martha_line"); + StoryPose at{StoryTable::ROCK_TUNNEL_B1F, {29, 37}, Direction::NORTH}; + OverworldSim sim(maps_after_route10(), MapPosition{at.map, at.tile}, *at.facing, battles_every({12, 10, 14, 11, 13})); + const std::string failure = row_step_on_sim(sim, at, row.steps[first], row.id); + if (!failure.empty()){ + return std::format("below_martha_line: ended on {}; {}", to_string(sim.state().position), failure); + } + if (!(sim.state().position == MapPosition{StoryTable::ROCK_TUNNEL_B1F, {17, 34}})){ + return std::format("below_martha_line: ended on {}, not (17, 34).", to_string(sim.state().position)); + } + return true; +} + +// 00.28 whole with a wild battle every 7 to 25 steps on the tunnel's floor, +// the gaps drawn from each of these seeds: the row ends where it should. +UnitTestResult test_rock_tunnel_frequent_battles(){ + for (unsigned seed = 1; seed <= 12; seed++){ + std::mt19937 random(seed); + std::uniform_int_distribution gap(7, 25); + std::vector gaps; + for (int c = 0; c < 400; c++){ + gaps.push_back(gap(random)); + } + const UnitTestResult result = row_on_sim("00.28", battles_every(gaps), ROCK_TUNNEL_TRAINERS, MapPosition{StoryTable::ROUTE10, {8, 58}}); + if (result.result != UnitTestResult::PASSED){ + return std::format("Seed {}: {}", seed, result.message); + } + } + return true; +} + // 00.29 on the sim: no trainer met, the ledge hopped, Lavender's nurse. UnitTestResult test_lavender_row(){ return row_on_sim("00.29", SimScript{}, {}, MapPosition{StoryTable::LAVENDER_CENTER, {7, 4}}); @@ -222,6 +284,8 @@ const AutoStoryLavenderCase AUTO_STORY_LAVENDER_CASES[] = { {.input = {"00.28 the tree, Rock Tunnel's nine trainers, out of its south mouth", test_rock_tunnel_row}, .expectation = {}}, {.input = {"00.28 a wild battle mid-leg in the tunnel", test_rock_tunnel_wild_battles}, .expectation = {}}, {.input = {"00.28 a tile off after each open leg", test_rock_tunnel_tile_off}, .expectation = {}}, + {.input = {"00.28 B1F row 37 with a wild battle every 10 to 14 steps", test_b1f_row37_battles_every_12}, .expectation = {}}, + {.input = {"00.28 a wild battle every 7 to 25 steps, 12 seeds", test_rock_tunnel_frequent_battles}, .expectation = {}}, {.input = {"00.29 Route 10 south, the ledge, Lavender Town's Pokemon Center", test_lavender_row}, .expectation = {}}, {.input = {"00.29 a tile off after each open leg", test_lavender_tile_off}, .expectation = {}}, {.input = {"00.28 and 00.29 save on Route 10 and in Lavender Town", test_save_places}, .expectation = {}}, From 4febace20fc474ae53ec0da33ff95c7474227450 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 11:01:45 -0800 Subject: [PATCH 010/168] FRLG walker: after a stop, find the player the way that walks the fewest tiles Rock Tunnel B1F row 37 (console B, 2026-11-09): a wild battle 10 to 14 tiles into every try of "west 16". The only single hold that found the player went east to the wall (45, 37), behind the leg's start, and the way back walked all 32 tiles again, until the route gave up. The reanchor search now also tries each first hold with the fewest holds after it, and plan_reanchor() takes the way whose holds and way back walk the fewest tiles together: there, south to row 38 and west to the wall (1, 38), then 13 tiles back. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldReanchor.cpp | 61 ++++++++++++++++--- .../Overworld/PokemonFRLG_OverworldReanchor.h | 9 ++- .../PokemonFRLG_OverworldRecovery.cpp | 14 +---- 3 files changed, 61 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp index 588b63c357..cdacd42e30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp @@ -236,14 +236,46 @@ bool walks_same_everywhere( return true; } -// The ways to find the player from all of `positions`: fewest holds first, -// then fewest tiles held. None needed if they are all on one tile. +int held_tiles(const std::vector& holds){ + int tiles = 0; + for (const RouteStep& hold : holds){ + tiles += hold.tiles; + } + return tiles; +} + +// The ways to find the player from all of `positions`, fewest holds first, +// then fewest tiles held. None needed if they are all on one tile. Not +// only the fewest holds: for each first hold, the fewest after it, so a +// caller can pick a way that keeps what a stopped leg walked. On Rock +// Tunnel B1F row 37 the one single hold went back east to the wall +// behind the leg's start, while a hold south and one west, ahead, were +// found too (console B, 2026-11-09). std::vector find_player( const std::vector>& worlds, const std::vector& positions, bool surfing ){ - return Pokemon::find_wall_anchors( - positions, ReanchorContext{.worlds = worlds, .surfing = surfing}, {.max_holds = MAX_HOLDS} - ); + const ReanchorContext context{.worlds = worlds, .surfing = surfing}; + std::vector found = Pokemon::find_wall_anchors(positions, context, {.max_holds = 0}); + if (!found.empty()){ + return found; + } + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + const auto first = ReanchorPolicy::hold(context, positions, direction); + if (!first || first->positions == positions || first->hold.tiles == 0){ + continue; + } + for (Found& rest : Pokemon::find_wall_anchors(first->positions, context, {.max_holds = MAX_HOLDS - 1})){ + rest.holds.insert(rest.holds.begin(), first->hold); + found.push_back(std::move(rest)); + } + } + std::stable_sort(found.begin(), found.end(), [](const Found& a, const Found& b){ + if (a.holds.size() != b.holds.size()){ + return a.holds.size() < b.holds.size(); + } + return held_tiles(a.holds) < held_tiles(b.holds); + }); + return found; } } // namespace @@ -326,6 +358,10 @@ std::vector stop_candidates( return candidates; } +int reanchor_tiles(const Reanchor& anchor){ + return held_tiles(anchor.holds) + held_tiles(anchor.back); +} + std::optional plan_reanchor( const std::vector& maps, const std::vector& candidates, @@ -351,7 +387,12 @@ std::optional plan_reanchor( add_unique(positions, Hypothesis{world, candidate.player}); } + // Of the ways found, the one that walks fewest tiles, holds and way back + // together: it keeps the most of what the leg walked. A wild battle + // every 10 to 14 tiles stopped every try of a leg whose way back + // started behind it (console B, 2026-11-09, Rock Tunnel B1F row 37). const std::vector clear_of_trainers = with_trainers(maps, trainers); + std::optional best; for (const Found& at : find_player(worlds, positions, step.surfing)){ const Direction facing = at.holds.empty() ? step.direction : at.holds.back().direction; // The way back keeps clear of every trainer who may stand in it if @@ -360,11 +401,15 @@ std::optional plan_reanchor( if (!back && !trainers.empty()){ back = plan_overworld_route(maps, at.at, RouteGoal{step.end, std::nullopt}, costs, facing); } - if (back && (trainers.empty() || walks_same_everywhere(worlds, positions, at.at, *back))){ - return Reanchor{.holds = at.holds, .found = at.at, .back = std::move(*back)}; + if (!back || (!trainers.empty() && !walks_same_everywhere(worlds, positions, at.at, *back))){ + continue; + } + Reanchor anchor{.holds = at.holds, .found = at.at, .back = std::move(*back)}; + if (!best || reanchor_tiles(anchor) < reanchor_tiles(*best)){ + best = std::move(anchor); } } - return std::nullopt; + return best; } std::optional> holds_to_one_tile( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h index 157917283e..1d1983c608 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -106,8 +106,13 @@ struct Reanchor{ std::vector back; }; -// After `step` stopped part-way, from `candidates`. Nothing if no holds -// bring them all to one tile, or no way back walks the same from there. +// How many tiles `anchor`'s holds and way back walk, as far as planned. +int reanchor_tiles(const Reanchor& anchor); + +// After `step` stopped part-way, from `candidates`: of the ways that find +// the player, the one that walks the fewest tiles, holds and way back +// together. Nothing if no holds bring them all to one tile, or no way +// back walks the same from there. std::optional plan_reanchor( const std::vector& maps, const std::vector& candidates, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 9053f963ea..b5b2c8d0f1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -86,18 +86,6 @@ bool hold_finds(const std::vector& maps, const std::vector anchor = plan_reanchor(*maps(), candidates, step, m_planning->costs); - if (!anchor || anchor->holds.empty() || anchor_tiles(*anchor) > 2 * step.tiles){ + if (!anchor || anchor->holds.empty() || reanchor_tiles(*anchor) > 2 * step.tiles){ m_calls.log("Route: no holds to walls within " + std::to_string(2 * step.tiles) + " tiles find the player if " + to_string(step) + " ended short; taken as walked."); return; } From 2a9ecac8ea54e5a75b833418dd38c004bd2aaadd Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 11:02:03 -0800 Subject: [PATCH 011/168] AutoStory frame replay: the warp watcher watches along the hold The late-watcher case showed a fade missed by a watch that starts after the hold; it now replays the walk's watch (WatchAlong over the hold, then the same watcher on) and checks it sees a door's black that is over before a 2000 ms hold ends, while a watcher started at the end of the hold still misses it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_FrameReplay_Tests.cpp | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp index c07748a3d0..841fa718eb 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay_Tests.cpp @@ -17,6 +17,7 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonTools/VisualDetectors/BlackScreenDetector.h" +#include "Pokemon/Navigation/Pokemon_LegWalker.h" #include "Pokemon_AutoStory_Tests.h" #include "Pokemon_FrameReplay.h" #include "Pokemon_Interrupts.h" @@ -109,14 +110,24 @@ UnitTestResult test_watcher_sees_fade(){ return true; } -// A watcher started once the black is over never fires: a walk that holds -// onto a door and only then waits for the fade reports "no fade" though -// the warp happened. -UnitTestResult test_late_watcher_misses_fade(){ +// A walk that holds onto a door for 2000 ms, past the black: its watcher +// sees the hold's frames (WatchAlong) and so the black, over before the +// hold ends. A watcher started once the black is over never fires: the +// walk then reported "no fade" though the warp happened (00.27, console +// B, 2026-11-09 01:41, the warp to CeruleanCity, watched from 1.3 s into +// the hold). +UnitTestResult test_watcher_along_hold_sees_fade(){ + const ReplayFrameSource source = door_recording(); BlackScreenOverWatcher arrival; - const ReplayHit hit = replay_until(door_recording(), {1600ms, 9600ms}, {&arrival}, T0); - if (hit.index != -1){ - return std::format("expected no stop, got index {} at {} ms", hit.index, hit.at.count()); + WatchAlong along(arrival); + const ReplayHit during = replay_until(source, {0ms, 2000ms}, {&along}, T0); + if (during.index != -1 || !along.fired()){ + return std::format("expected the hold not stopped and the fade seen, got index {}, seen {}", during.index, along.fired()); + } + BlackScreenOverWatcher late; + const ReplayHit missed = replay_until(source, {2000ms, 10000ms}, {&late}, T0); + if (missed.index != -1){ + return std::format("expected a watcher started after the black to miss it, got index {} at {} ms", missed.index, missed.at.count()); } return true; } @@ -172,7 +183,7 @@ const FrameReplayCase FRAME_REPLAY_CASES[] = { {.input = {"the frame showing at a time", test_frame_at}, .expectation = {}}, {.input = {"a missing recording throws", test_missing_folder}, .expectation = {}}, {.input = {"the warp watcher sees a door's black", test_watcher_sees_fade}, .expectation = {}}, - {.input = {"a warp watcher started after the black misses it", test_late_watcher_misses_fade}, .expectation = {}}, + {.input = {"a warp watcher along the hold sees a black over before it ends", test_watcher_along_hold_sees_fade}, .expectation = {}}, {.input = {"the replayed events judged as a warp", test_events_judged}, .expectation = {}}, }; From 1484c5e6fa286338c93dfed97a3a49a26f1e8c43 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 11:03:00 -0800 Subject: [PATCH 012/168] FRLG AutoStory: watch a warp's fade from the start of the hold onto it The walk waited for a warp's fade only once the hold onto the warp had ended, so a fade that was over by then went unseen and the walk stopped on "no fade in and out after walking onto the warp" though the player had warped (00.27, console B, 2026-11-09 01:41, the warp to CeruleanCity: the watch started about 1.3 s into the hold). The walk and the recovery walk now show the hold's frames to the same BlackScreenOverWatcher (Pokemon::WatchAlong) and wait on with it only if it has not fired. The watcher and its thresholds are unchanged, so a dim textured floor is still no fade. The overworld sim's walker watches for the fade from where the console does (SimWalkerRules::watch_fade_along_hold), and fails on a warp whose fade it missed, as the console does. OverworldWarpFade walks out of Viridian Mart with a 200 ms fade that is over before the hold ends: seen when watched from the start of the hold, missed from its end. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldRecoveryWalk.cpp | 7 +- .../Overworld/PokemonFRLG_OverworldSim.cpp | 26 +++- .../Overworld/PokemonFRLG_OverworldSim.h | 12 +- .../PokemonFRLG_OverworldSim_Tests.cpp | 1 + .../Overworld/PokemonFRLG_OverworldWalk.cpp | 54 ++++++-- .../Overworld/PokemonFRLG_OverworldWalk.h | 11 +- .../PokemonFRLG_OverworldWarpFade_Tests.cpp | 129 ++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 1 + 8 files changed, 222 insertions(+), 19 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp index 8aac65097e..e886503d5f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecoveryWalk.cpp @@ -16,6 +16,7 @@ #include "CommonTools/Async/InferenceSession.h" #include "CommonTools/VisualDetectors/BlackScreenDetector.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_OverworldLateBattle.h" #include "PokemonFRLG_OverworldRecoveryWalk.h" @@ -72,16 +73,18 @@ StepWalk walk_step( } context.wait_for_all_requests(); out.hold_start = current_time(); + BlackScreenOverWatcher arrival(COLOR_RED); + Pokemon::WatchAlong fade(arrival); const Pokemon::LegResult result = Pokemon::walk_leg( console, context, leg_mover(step, speed), step.wild ? interrupts.wild : interrupts.other, - leg_spec(step, speed), MAX_INTERRUPTIONS_PER_LEG + leg_spec(step, speed), MAX_INTERRUPTIONS_PER_LEG, warp_hold_watchers(step, fade) ); if (result.stopped){ out.stopped = walked_near(step, result.tiles, tile_time(step, speed)); return out; } if (step.warps){ - wait_out_warp(console, context, step); + wait_out_warp(console, context, step, fade); static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); if (run_from_battle_after_warp(console, context)){ console.log("Route: a wild battle, not the warp to " + step.end.map + "; the player is on " + to_string(step) + " before the warp.", COLOR_ORANGE); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index 3395eda537..b904273c14 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -650,17 +650,30 @@ std::optional OverworldSimWalker::hold_watching(const RouteStep& step, return m_sim.hold(step.direction, hold, STEP_RELEASE, hold + STEP_RELEASE + m_rules.watch_past_hold, watchers(interrupts)); } +// Whether a warp's fade showed and was over between `from` and now. +bool OverworldSimWalker::fade_over_since(Milliseconds from) const{ + const SimState& state = m_sim.state(); + if (state.screen == SimScreen::FADE){ + return false; + } + return std::any_of( + state.shown.begin(), state.shown.end(), + [&](const SimShown& shown){ return shown.screen == SimScreen::FADE && shown.at >= from; } + ); +} + // wait_out_warp(), then run_from_battle_after_warp(): false if the fade // was a wild battle's, run from. wait_out_warp()'s watcher takes a wild // battle's wipe for the fade (run 7; console B, 2026-11-03, Mt. Moon 1F): -// the battle screen stands in for the wipe. -bool OverworldSimWalker::after_warp(const RouteStep& step, int warps_before){ +// the battle screen stands in for the wipe. The fade is watched for from +// `watched_from`: a fade over by then is missed. +bool OverworldSimWalker::after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from){ if (m_sim.state().warps == warps_before){ if (!m_sim.watch({SimWatcher::BATTLE_SCREEN}, WARP_TIMEOUT)){ fail("walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + "."); } - }else{ - m_sim.watch({SimWatcher::FADE}, WARP_TIMEOUT); + }else if (!fade_over_since(watched_from) && !m_sim.watch({SimWatcher::FADE}, WARP_TIMEOUT)){ + fail("walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + "."); } m_sim.watch({}, AFTER_WARP); if (!m_sim.watch(watchers({m_wild[1]}), AFTER_WARP_BATTLE_WATCH - AFTER_WARP)){ @@ -712,7 +725,8 @@ std::optional OverworldSimWalker::walk_step(const RouteStep& step, if (result.stopped){ return walked_near(step, result.tiles, TILE_TIME); } - if (step.warps && !after_warp(step, warps_before)){ + const Milliseconds fade_watched_from = m_rules.watch_fade_along_hold ? m_leg_start : m_sim.state().time; + if (step.warps && !after_warp(step, warps_before, fade_watched_from)){ if (!m_rules.find_player_after_warp_battle){ fail_off_route(step); } @@ -795,7 +809,7 @@ void OverworldSimWalker::hold_to_warp(const RouteStep& step){ const Milliseconds hold = TILE_TIME * (step.tiles + 2); const std::optional seen = m_sim.hold(step.direction, hold, STEP_RELEASE, hold + STEP_RELEASE, fade_first); if (seen && seen->watcher == 0){ - if (!after_warp(step, warps_before)){ + if (!after_warp(step, warps_before, m_sim.state().time)){ fail_off_route(step); } return; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 9483c2e289..32751834dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -328,6 +328,13 @@ struct SimWalkerRules{ // player may be anywhere on the leg: on Route 10, "east 11" was found // again from all 12 of its tiles (console B, 2026-11-09, 00.27 run 2). bool place_late_battle = true; + // The watch for a warp's fade starts with the hold onto the warp + // (Pokemon::WatchAlong), not when it ends. Without it a fade over + // before the hold ended was missed, and the walk stopped on "no fade in + // and out after walking onto the warp" though it had warped (console B, + // 2026-11-09 01:41, 00.27, the warp to CeruleanCity: the watch started + // about 1.3 s into the hold). + bool watch_fade_along_hold = true; }; // The console side of run_route() on an OverworldSim, as @@ -367,7 +374,8 @@ class OverworldSimWalker{ StepOutcome walk(const RouteStep& step, std::optional facing); std::optional late_stop(const RouteStep& step); std::optional walk_step(const RouteStep& step, std::optional facing); - bool after_warp(const RouteStep& step, int warps_before); + bool after_warp(const RouteStep& step, int warps_before, Milliseconds watched_from); + bool fade_over_since(Milliseconds from) const; [[noreturn]] void fail_off_route(const RouteStep& step); std::optional hold_watching(const RouteStep& step, Milliseconds hold, const std::vector& interrupts); size_t clear_late(const std::vector& interrupts, Milliseconds watch, size_t max); @@ -394,6 +402,8 @@ class OverworldSimWalker{ // Register overworld simulation unit tests. void add_tests_OverworldSim(UnitTestDatabase& database); +// Register the tests of a warp's fade over before the hold onto it ends. +void add_tests_OverworldWarpFade(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp index f8a2c4ca80..3179e1829a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp @@ -983,6 +983,7 @@ void add_tests_OverworldSim(UnitTestDatabase& database){ database.add(item); } add_tests_OverworldLateBattle(database); + add_tests_OverworldWarpFade(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp index 8e57b1cc73..f6332251fb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp @@ -213,12 +213,22 @@ std::string speed_note(const RouteStep& step, MoveSpeed speed){ ); } +std::vector warp_hold_watchers(const RouteStep& step, Pokemon::WatchAlong& fade){ + if (!step.warps){ + return {}; + } + return {&fade}; +} + // One watcher for the whole fade: a ladder's black is short enough to be // over before a second watcher, started once the fade is seen, looks. -void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ - BlackScreenOverWatcher arrival(COLOR_RED); +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade){ + if (fade.fired()){ + console.log("Route: the fade to " + step.end.map + " was over before the hold ended."); + return; + } context.wait_for_all_requests(); - if (wait_until(console, context, WARP_TIMEOUT, {arrival}) < 0){ + if (wait_until(console, context, WARP_TIMEOUT, {fade.watcher()}) < 0){ OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, "walk_overworld_route(): no fade in and out after walking onto the warp to " + step.end.map + ".", @@ -227,6 +237,12 @@ void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const } } +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step){ + BlackScreenOverWatcher arrival(COLOR_RED); + Pokemon::WatchAlong fade(arrival); + wait_out_warp(console, context, step, fade); +} + // Fails unless the overworld is up. Under the START menu or a message the // D-pad only moves a cursor, and legs to a wall seem to go fine: three // "walked" that way in Viridian Forest without the player moving (console B, @@ -454,6 +470,31 @@ const OverworldInterruptSet& default_overworld_interrupts(){ } +namespace{ + +// A WALK step's leg, and the fade of the warp it walks onto, watched from +// the start of the hold. +void walk_step_leg( + ConsoleHandle& console, ProControllerContext& context, + const RouteStep& step, const OverworldInterruptSet& interrupts, MoveSpeed speed +){ + BlackScreenOverWatcher arrival(COLOR_RED); + Pokemon::WatchAlong fade(arrival); + Pokemon::walk_leg( + console, context, leg_mover(step, speed), step.wild ? interrupts.wild : interrupts.other, + leg_spec(step, speed), MAX_INTERRUPTIONS_PER_LEG, warp_hold_watchers(step, fade) + ); + if (!step.warps){ + return; + } + wait_out_warp(console, context, step, fade); + static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); + check_warp_was_no_battle(console, context, step); +} + +} // namespace + + void walk_overworld_route( ConsoleHandle& console, ProControllerContext& context, const std::vector& route, @@ -479,12 +520,7 @@ void walk_overworld_route( if (const std::string note = speed_note(step, speed); !note.empty()){ console.log(note); } - Pokemon::walk_leg(console, context, leg_mover(step, speed), step.wild ? interrupts.wild : interrupts.other, leg_spec(step, speed), MAX_INTERRUPTIONS_PER_LEG); - if (step.warps){ - wait_out_warp(console, context, step); - static_assert(AFTER_WARP_BATTLE_WATCH >= AFTER_WARP); - check_warp_was_no_battle(console, context, step); - } + walk_step_leg(console, context, step, interrupts, speed); break; case RouteAction::SURF: start_surf(console, context, step.direction, facing == step.direction); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h index e166617c2a..c74361044e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h @@ -176,7 +176,16 @@ Milliseconds leg_hold_time(const RouteStep& step, MoveSpeed speed); // the tiles at the assumed pace and the hold. Empty for other steps. std::string speed_note(const RouteStep& step, MoveSpeed speed); -// After a hold onto `step`'s warp: waits out its fade. +// The hold watchers (Pokemon::walk_leg()) of a leg onto `step`: `fade`, +// which watches for the warp's fade from the start of the hold, if the +// step warps. A fade can be over before the hold ends. +std::vector warp_hold_watchers(const RouteStep& step, Pokemon::WatchAlong& fade); + +// After a hold onto `step`'s warp: waits out its fade, unless `fade`, a +// BlackScreenOverWatcher watched along the hold, saw it over already; +// else waits on with that watcher, which may have seen the black. +void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step, Pokemon::WatchAlong& fade); +// The same, watching only from now: for a caller that saw the black itself. void wait_out_warp(ConsoleHandle& console, ProControllerContext& context, const RouteStep& step); // Before `step`: fails unless the overworld is up. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp new file mode 100644 index 0000000000..de344c2dc1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp @@ -0,0 +1,129 @@ +/* Overworld Warp Fade Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A warp whose fade is over before the hold onto it ends, on the sim: the + * walker must watch for the fade from the start of the hold. + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldMaps.h" +#include "PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_OverworldWalk.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +using namespace std::chrono_literals; + +struct WarpFadeInput{ + std::string name; + // How long the fade shows, from the end of the step onto the warp. + Milliseconds fade{0}; + // SimWalkerRules::watch_fade_along_hold. + bool watch_along_hold = true; +}; + +struct WarpFadeExpectation{ + // The failure the walk stops on; empty: the route is walked. + std::string failure; +}; + +struct WarpFadeCase{ + WarpFadeInput input; + WarpFadeExpectation expectation; +}; + +const std::vector& maps(){ + static const std::vector MAPS = overworld_maps(); + return MAPS; +} + +const MapPosition MART{"ViridianCity_Mart", {4, 3}}; +// Where the Mart's exit mat, (4, 7), puts the player. +const MapPosition OUTSIDE{"ViridianCity", {36, 20}}; + +// 00.27 (console B, 2026-11-09 01:41), the warp to CeruleanCity: "no fade +// in and out after walking onto the warp", the watch for the fade having +// started about 1.3 s into the hold, after the fade was over. Here the +// walk out of Viridian Mart, south 5 onto its mat, is held as to a wall, +// two tiles past the mat; a 200 ms fade is over before the hold ends. +class Test_OverworldWarpFade : public UnitTest{ +public: + explicit Test_OverworldWarpFade(WarpFadeCase test_case) + : UnitTest("PokemonFRLG::OverworldWarpFade - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + RouteStep out; + out.direction = Direction::SOUTH; + out.tiles = 5; + out.warps = true; + out.to_wall = true; + out.facing_after = Direction::SOUTH; + out.end = OUTSIDE; + SimScript script; + script.timing.fade = m_case.input.fade; + SimWalkerRules rules; + rules.watch_fade_along_hold = m_case.input.watch_along_hold; + OverworldSim sim(maps(), MART, Direction::SOUTH, script); + OverworldSimWalker walker(sim, rules); + const RoutePlanning planning{.maps = &maps(), .costs = default_route_costs(), .start = MART, .label = "Sim"}; + const std::string failure = walker.run({out}, planning); + const std::string& expected = m_case.expectation.failure; + const bool as_expected = expected.empty() ? failure.empty() : failure.find(expected) != std::string::npos; + if (as_expected && sim.state().warps == 1){ + return true; + } + std::string log; + for (const std::string& line : walker.log()){ + log += "\n " + line; + } + return std::format( + "Expected failure \"{}\" after 1 warp; got \"{}\" after {}:{}", + expected, failure, sim.state().warps, log + ); + } + +private: + WarpFadeCase m_case; +}; + +} // namespace + + +const WarpFadeCase WARP_FADE_CASES[] = { + { + .input = {.name = "a fade over before the hold ends, watched from its start", .fade = 200ms}, + .expectation = {.failure = ""}, + }, + { + .input = {.name = "a fade over before the hold ends, watched from its end", .fade = 200ms, .watch_along_hold = false}, + .expectation = {.failure = "no fade in and out after walking onto the warp to ViridianCity"}, + }, + { + .input = {.name = "a fade still on when the hold ends, watched from its end", .fade = 1000ms, .watch_along_hold = false}, + .expectation = {.failure = ""}, + }, +}; + +void add_tests_OverworldWarpFade(UnitTestDatabase& database){ + for (const WarpFadeCase& item : WARP_FADE_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index f3d79ac4b8..0b44daf242 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1871,6 +1871,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWarpFade_Tests.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_PlayerFacingReader.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp From 2a975569c6b6f672daed4f88c12ad9a2f43a3dc7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 11:05:33 -0800 Subject: [PATCH 013/168] FRLG frame replay: replay the warp watcher as the walk now runs it replay_watcher() shows the hold's frames to the walk's BlackScreenOverWatcher through a WatchAlong, then waits on with it, as walk_overworld_route() does since its fade watch covers the hold; a fade over before the hold ends reads "fade over during the hold". Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_AutoStoryFrameReplay_Tests.cpp | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp index e6846b683d..57c30047a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFrameReplay_Tests.cpp @@ -3,8 +3,9 @@ * From: https://github.com/PokemonAutomation/ * * Console failures of the walk's warp check, replayed from their frames - * through the watcher the walk uses (BlackScreenOverWatcher, after the - * hold) and through FRLG's screen events, judged by the shared judges. + * through the watcher the walk uses (BlackScreenOverWatcher, from the + * start of the hold) and through FRLG's screen events, judged by the + * shared judges. * Each case's frames are in CommandLineTests/PokemonFRLG/FrameReplay// * (".png", Pokemon_FrameReplay.h); a case skips when they are missing. * @@ -41,8 +42,9 @@ constexpr Milliseconds WARP_WAIT = 8000ms; // A one-tile walk onto a door: a tile's time, then the release. constexpr Milliseconds ONE_TILE_HOLD = OverworldWalkSteps::TILE_TIME + OverworldWalkSteps::STEP_RELEASE; -// A warp leg: the player holds onto the door for `hold`, the walk then -// waits for the fade (wait_out_warp()). +// A warp leg: the player holds onto the door for `hold`, watched for the +// fade (warp_hold_watchers()), and the walk then waits out the rest of it +// (wait_out_warp()). struct WarpReplayInput{ std::string name; // The case's folder under CommandLineTests/PokemonFRLG/FrameReplay/. @@ -51,7 +53,8 @@ struct WarpReplayInput{ }; struct WarpReplayExpectation{ - // "fade over at ms" or "no fade", from BlackScreenOverWatcher. + // "fade over during the hold", "fade over at ms" or "no fade", + // from BlackScreenOverWatcher. std::string watcher; // judge_warp() and classify_interrupt() over FRLG's events. std::string warp; @@ -65,6 +68,11 @@ struct WarpReplayCase{ std::string replay_watcher(const Pokemon::ReplayFrameSource& source, const WarpReplayInput& input){ BlackScreenOverWatcher arrival(COLOR_RED); + Pokemon::WatchAlong fade(arrival); + Pokemon::replay_until(source, {Milliseconds(0), input.hold}, {&fade}, T0); + if (fade.fired()){ + return "fade over during the hold"; + } const Pokemon::ReplayWindow wait{input.hold, input.hold + WARP_WAIT}; const Pokemon::ReplayHit hit = Pokemon::replay_until(source, wait, {&arrival}, T0); return hit.index < 0 ? "no fade" : std::format("fade over at {} ms", hit.at.count()); From ad654be579b81d15b454a06a6d563e95ba97f329 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 11:07:51 -0800 Subject: [PATCH 014/168] AutoStory frame replay: how to cut a failure capture's video into a case Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/Pokemon/AutoStory/Pokemon_FrameReplay.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h index 12214cb444..f3d56e386a 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_FrameReplay.h @@ -19,6 +19,16 @@ * 20 frames a second, then rename frame N to its time, (N - 1) * 50 ms: * ffmpeg -ss -t -i Video.mp4 -vf fps=20 %d.png * + * A failed AutoStory event saves its own (Pokemon_AutoStoryFailureCapture.h) + * in USER_FILE_PATH()//AutoStoryFailures/