From 1b1da4f024d399c5292a747c29c65658a14ec2f7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 00:35:12 -0800 Subject: [PATCH 1/3] FRLG AutoStory 16.03: sim test, the walk to the rival's trigger ends facing west after a re-anchor --- .../PokemonFRLG_AutoStorySilph_Tests.cpp | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp index 4ee0b188f1..b1ca61c882 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp @@ -295,6 +295,46 @@ UnitTestResult test_rival_row(){ return true; } +// 16.03 to_rival_trigger from 7F's pad (5, 4): "west 2 (open)" to (3, 4) +// ends where a hold can't tell a tile short from none, so the walker finds +// the player at walls and walks back, its last leg "north 1 (to wall)". The +// route must still end facing west, as planned: the rival_trigger step's +// tap west then only turned the player, who never stepped onto the +// trigger (2, 4) (pokefirered data/maps/SilphCo_7F/map.json, coord_events +// (2, 4) and (2, 5), SilphCo_7F_EventScript_RivalTriggerTop) and the +// rival's battle never came (console B, 2026-11-15 00:28, 16.03 run 5). +UnitTestResult test_rival_trigger_walk_ends_facing_west(){ + const std::vector maps = maps_after_16_02(); + const MapPosition pad{"SilphCo_7F", {5, 4}}; + const MapPosition beside_trigger{"SilphCo_7F", {3, 4}}; + const std::optional> route = plan_overworld_route( + maps, pad, RouteGoal{beside_trigger, Direction::WEST}, story_route_costs(), Direction::WEST + ); + if (!route || route->empty()){ + return "No route from 7F's pad to (3, 4)."; + } + OverworldSim sim(maps, pad, Direction::WEST); + OverworldSimWalker walker(sim); + const RoutePlanning planning{.maps = &maps, .costs = story_route_costs(), .start = pad, .label = "to_rival_trigger"}; + if (const std::string failure = walker.run(*route, planning); !failure.empty()){ + return "The walk failed: " + failure; + } + const std::vector& log = walker.log(); + const bool found_at_walls = std::any_of(log.begin(), log.end(), [](const std::string& line){ + return line.find("finding the player at walls") != std::string::npos; + }); + if (!found_at_walls){ + return "Expected the walker to find the player at walls after \"west 2 (open)\", as on the console."; + } + if (!(sim.state().position == beside_trigger) || sim.state().facing != Direction::WEST){ + return std::format( + "Expected {} facing west, got {} facing {}.", + to_string(beside_trigger), to_string(sim.state().position), direction_name(sim.state().facing) + ); + } + return true; +} + // 16.03b's checkpoint: Gift RNG's Lapras, on 7F beside the employee. UnitTestResult test_lapras_handoff(){ const StoryCheckpoint& gift = checkpoint("16.03b"); @@ -487,6 +527,10 @@ const AutoStorySilphCase AUTO_STORY_SILPH_CASES[] = { .input = {.name = "16.03 3F's Card Key door, the pad to 7F and the rival; 16.03b to the employee", .body = test_rival_row}, .expectation = {.description = "opens 3F's door_2, ends by the employee on 7F"}, }, + { + .input = {.name = "16.03 the walk to the rival's trigger, found again at walls", .body = test_rival_trigger_walk_ends_facing_west}, + .expectation = {.description = "after the holds and the way back, on (3, 4) facing west, the trigger (2, 4) a tap ahead"}, + }, { .input = {.name = "16.03b/16.04 the Lapras by Gift RNG", .body = test_lapras_handoff}, .expectation = {.description = "16.03b hands off to Gift RNG for a Lapras; 16.04 is the live save"}, From 9b8142fe6825b6b8fe1c378136b06ce71ca63841 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 00:36:33 -0800 Subject: [PATCH 2/3] FRLG overworld: a re-anchor of a route's last leg ends facing the way that leg did The way back after finding the player at walls was planned to the leg's end tile with no facing, so it ended with its own last leg's facing ("north 1 (to wall)") while the route still reported the planned one (west). 16.03's rival_trigger step then tapped west with no turn first, which only turned the player beside the trigger (2, 4). plan_reanchor() now takes the facing the way back must end with; the walker passes the leg's own when nothing follows it. --- .../Overworld/PokemonFRLG_OverworldReanchor.cpp | 7 ++++--- .../PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h | 8 ++++++-- .../Overworld/PokemonFRLG_OverworldRecovery.cpp | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp index 6a76bb6c76..9801e7a4d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.cpp @@ -456,7 +456,8 @@ std::optional plan_reanchor( const std::vector& maps, const std::vector& candidates, const RouteStep& step, - const RouteCosts& costs + const RouteCosts& costs, + std::optional end_facing ){ if (candidates.empty() || step.action != RouteAction::WALK){ return std::nullopt; @@ -478,9 +479,9 @@ std::optional plan_reanchor( 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 // it can, and must walk the same whether they do or not. - std::optional> back = plan_overworld_route(clear_of_trainers, at.at, RouteGoal{step.end, std::nullopt}, costs, facing); + std::optional> back = plan_overworld_route(clear_of_trainers, at.at, RouteGoal{step.end, end_facing}, costs, facing); if (!back && !trainers.empty()){ - back = plan_overworld_route(maps, at.at, RouteGoal{step.end, std::nullopt}, costs, facing); + back = plan_overworld_route(maps, at.at, RouteGoal{step.end, end_facing}, costs, facing); } if (!back || (!trainers.empty() && !walks_same_everywhere(worlds, positions, at.at, *back))){ continue; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h index bcc65bffb7..e32947523a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldReanchor.h @@ -92,12 +92,16 @@ struct Reanchor{ // the player, the one that walks the fewest tiles, holds and way back // together, with tiles of open legs weighted over held ones. Nothing if // no holds bring them all to one tile, or no way back walks the same from -// there. +// there. With `end_facing`, the way back ends facing that way: the route's +// last leg must leave the player facing as planned, or a step after it only +// turns them (16.03's rival_trigger, a tap west after a way back that ended +// "north 1 (to wall)" beside the trigger; console B, 2026-11-15 00:28). std::optional plan_reanchor( const std::vector& maps, const std::vector& candidates, const RouteStep& step, - const RouteCosts& costs = default_route_costs() + const RouteCosts& costs = default_route_costs(), + std::optional end_facing = std::nullopt ); // Holds to walls that bring the player to one tile from every one of diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index 72aef14d38..7de8a16c30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -777,7 +777,7 @@ class RouteRun{ if (candidates.size() < 2 || (!last && is_wall_hold(m_plan[m_next]) && hold_finds(*maps(), candidates, m_plan[m_next]))){ return; } - const std::optional anchor = plan_reanchor(*maps(), candidates, step, m_planning->costs); + const std::optional anchor = plan_reanchor(*maps(), candidates, step, m_planning->costs, last ? std::optional(step.facing_after) : std::nullopt); if (water_chain && (!anchor || anchor->holds.empty())){ m_calls.fail(std::format( "walk_overworld_route(): {} on the water may have ended short with nothing seen, and {} after it is open too; " @@ -871,7 +871,7 @@ class RouteRun{ } const std::optional anchor = candidates.empty() ? std::nullopt - : plan_reanchor(*maps(), candidates, step, m_planning->costs); + : plan_reanchor(*maps(), candidates, step, m_planning->costs, m_next + 1 == m_plan.size() ? std::optional(step.facing_after) : std::nullopt); if (!anchor){ m_calls.fail( "walk_overworld_route(): stopped part-way on " + to_string(step) From d067b94d29d14472349e6b3e8da1fa33a64b3d4b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 00:38:18 -0800 Subject: [PATCH 3/3] FRLG AutoStory 16.03 test: std::format for the failure message --- .../Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp index b1ca61c882..732ea35c9a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp @@ -317,7 +317,7 @@ UnitTestResult test_rival_trigger_walk_ends_facing_west(){ OverworldSimWalker walker(sim); const RoutePlanning planning{.maps = &maps, .costs = story_route_costs(), .start = pad, .label = "to_rival_trigger"}; if (const std::string failure = walker.run(*route, planning); !failure.empty()){ - return "The walk failed: " + failure; + return std::format("The walk failed: {}", failure); } const std::vector& log = walker.log(); const bool found_at_walls = std::any_of(log.begin(), log.end(), [](const std::string& line){