From 95a273e1eac137b389ccb066a866f6441cd1028e Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 15:42:04 -0800 Subject: [PATCH 01/47] BDSP AutoStory: steps declare the pose certainty they need; 00.05 starts on walls Each action's spec says how sure of the tile it must be at its start and what it leaves (Pokemon_StoryCertainty.h, shared); certainty_gaps() lists steps that need more than the steps before guarantee, a save's declared start counting as unseen. 00.05 starts where the console shows the save (46, 60) and walks to the Center on the buildings' wall and the Center's front wall. New sweep: every row 1 to 3 tiles off its declared start. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/Pokemon_StoryCertainty.cpp | 86 +++++ .../AutoStory/Pokemon_StoryCertainty.h | 46 +++ .../AutoStory/Types/Pokemon_StoryActionSpec.h | 18 + .../PokemonBDSP_AutoStory_StoryData.cpp | 16 +- ...PokemonBDSP_AutoStory_FaultSweep_Tests.cpp | 160 +++++++++ .../PokemonBDSP_AutoStory_StorySim.cpp | 8 + .../PokemonBDSP_AutoStory_StorySim.h | 4 + .../AutoStory/StoryData/bdsp-00.04d.plan.json | 8 +- .../AutoStory/StoryData/bdsp-00.05.plan.json | 313 ++++++++++++++++-- SerialPrograms/cmake/SourceFiles.cmake | 2 + 10 files changed, 634 insertions(+), 27 deletions(-) create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp create mode 100644 SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp new file mode 100644 index 0000000000..f962515c48 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp @@ -0,0 +1,86 @@ +/* Story Certainty + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_BuiltinStoryActions.h" +#include "Pokemon_StoryStepExecutor.h" +#include "Pokemon_StoryCertainty.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +StoryCertainty kind_certainty(StoryStepKind kind){ + switch (kind){ + case StoryStepKind::ROUTE: + return {PoseCertainty::TILE, PoseEnd::WALKED}; + case StoryStepKind::LEGS: + return {PoseCertainty::SET, PoseEnd::KEEPS}; + case StoryStepKind::STEP: + case StoryStepKind::HEAL: + return {PoseCertainty::TILE, PoseEnd::DECLARED}; + case StoryStepKind::TALK: + return {PoseCertainty::TILE, PoseEnd::KEEPS}; + case StoryStepKind::NEW_GAME: + return {PoseCertainty::UNKNOWN, PoseEnd::DECLARED}; + default: + return {PoseCertainty::UNKNOWN, PoseEnd::KEEPS}; + } +} + +} // namespace + + +StoryCertainty story_step_certainty(const StoryStep& step, std::span specs){ + StoryCertainty out = kind_certainty(step.kind); + if (const StoryActionSpec* spec = find_story_action(specs, step.kind, step.action)){ + out.needs = spec->certainty.value_or(out).needs; + out.leaves = spec->certainty.value_or(out).leaves; + } + return out; +} + +PoseCertainty certainty_after(const StoryStep& step, PoseEnd leaves, PoseCertainty before){ + switch (leaves){ + case PoseEnd::WALKED: + return PoseCertainty::TILE; + case PoseEnd::DECLARED: + return step.pose_after ? pose_of(*step.pose_after).certainty : before; + case PoseEnd::GAME_SET: + return step.pose_after ? PoseCertainty::SET : before; + case PoseEnd::KEEPS: + // A declared end the step does not walk onto is where the game + // leaves us, unseen. + return step.pose_after ? PoseCertainty::SET : before; + } + return before; +} + +PoseCertainty start_certainty(const StoryCheckpoint& data){ + return data.start ? PoseCertainty::SET : PoseCertainty::UNKNOWN; +} + +std::vector certainty_gaps(const StoryCheckpoint& data, std::span specs){ + std::vector gaps; + PoseCertainty have = start_certainty(data); + for (size_t c = 0; c < data.steps.size(); c++){ + const StoryStep& step = data.steps[c]; + const StoryCertainty certainty = story_step_certainty(step, specs); + if (!certainty_covers(have, certainty.needs)){ + gaps.push_back(std::format("{} step {} {}: needs {}, has {}", + data.id, c + 1, step.name, certainty_name(certainty.needs), certainty_name(have))); + } + have = certainty_after(step, certainty.leaves, have); + } + return gaps; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h new file mode 100644 index 0000000000..e1941b3db6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h @@ -0,0 +1,46 @@ +/* Story Certainty + * + * From: https://github.com/PokemonAutomation/ + * + * How sure of the player's tile each step must be when it starts, and how + * sure it leaves the run. A step that needs more than the steps before it + * guarantee walks from a guess: 00.05's route planned open legs from its + * save's declared start, a tile the save was never seen on, and walked + * into a building (lab-B 2026-11-11 15:22). + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCertainty_H +#define PokemonAutomation_Pokemon_StoryCertainty_H + +#include +#include +#include +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// What a step needs at its start and leaves at its end: the action's spec +// where it says, else its kind's default (a route needs one tile and +// leaves one; a scene needs nothing and leaves its declared end unseen). +StoryCertainty story_step_certainty(const StoryStep& step, std::span specs); + +// How sure the run is after `step` succeeds from `before`. +PoseCertainty certainty_after(const StoryStep& step, PoseEnd leaves, PoseCertainty before); + +// How sure a checkpoint is at its start: SET from its save (its declared +// start was never seen on the screen), UNKNOWN without one. +PoseCertainty start_certainty(const StoryCheckpoint& data); + +// Each step of `data` that needs a surer pose than the steps before it +// leave, as "00.05 step 1 to_the_center: needs TILE, has SET". +std::vector certainty_gaps(const StoryCheckpoint& data, std::span specs); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h index f9deb09ebb..cef4e27ef5 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h @@ -15,6 +15,7 @@ #include #include "Pokemon_StoryActionArg.h" #include "Pokemon_StoryStepKind.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" namespace PokemonAutomation{ namespace Pokemon{ @@ -31,6 +32,21 @@ struct StoryArgSpec{ std::string why; }; +// What an action leaves the pose as. +enum class PoseEnd{ + KEEPS, // as sure as before (a talk; taps counted from where we were) + WALKED, // walked onto its target and checked there: one tile + DECLARED, // its declared end, reached on walls or through a door + GAME_SET, // where a scene or battle leaves us: declared, not seen +}; + +// How sure of the player's tile an action must be at its start, and what +// it leaves (Pokemon_StoryCertainty.h). +struct StoryCertainty{ + PoseCertainty needs = PoseCertainty::UNKNOWN; + PoseEnd leaves = PoseEnd::KEEPS; +}; + // An action: the kind of step it does, its name and the args it takes. struct StoryActionSpec{ StoryStepKind kind = StoryStepKind::GAME; @@ -40,6 +56,8 @@ struct StoryActionSpec{ // keyboard, a battle AI): the engine refuses it on any other backend // (StoryBackendKind) with the failure "console_only". bool console_only = false; + // None: its kind's default (story_step_certainty()). + std::optional certainty = std::nullopt; }; // Each way `args` don't fit `spec`: a key it doesn't name, a value of diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index a6bea013c2..567cc3508c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -70,10 +70,20 @@ std::vector make_bdsp_actions(){ actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs}}); } actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = "into_scene", .args = {route_target, fight_wild, legs_arg}}); - for (std::string_view act : {"to_wall", "to_dialogue", "to_map", "one_short_ok", "counted_wall"}){ - actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}}); + // A hold to a wall or onto a map ends on its declared end from any + // start on the map: it is how a step pins an unsure pose. + using Pokemon::PoseCertainty; + using Pokemon::PoseEnd; + const Pokemon::StoryCertainty pins{.needs = PoseCertainty::UNKNOWN, .leaves = PoseEnd::DECLARED}; + for (std::string_view act : {"to_wall", "to_map"}){ + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}, .console_only = false, .certainty = pins}); } - actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "to_dialogue", .args = {legs_arg, fight_wild}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::UNKNOWN, .leaves = PoseEnd::GAME_SET}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "one_short_ok", .args = {legs_arg, fight_wild}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "counted_wall", .args = {legs_arg, fight_wild}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); + actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = pins}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {}}); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp index 8375ffbecc..3c4b82d57f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp @@ -27,6 +27,11 @@ * with no settle() between goes nowhere (lab-B 2026-11-10, 00.04b * heal_sandgem: a fixed 1500 ms wait, then the walk to the nurse * stopped on "transition"). SimWorldKnobs::slow_fade_in. + * - START_OFFSET: the row's save leaves the player 1 to 3 tiles off its + * declared start, each way the player can walk there (00.05, lab-B + * 2026-11-11 15:22: the route planned open legs from Jubilife's declared + * (48, 62), and its third leg walked into a building). + * SimWorldKnobs::start_at. * * Missed and short fades are swept by SimFailureCases_Tests (every single * missed fade, banner and fade hold). @@ -53,6 +58,8 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryCertainty.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h" #include "Pokemon/Navigation/Pokemon_MapData.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" @@ -78,6 +85,7 @@ enum class FaultClass{ GRASS_BATTLES, SCENE_EARLY, SLOW_FADE_IN, + START_OFFSET, // Not swept yet: the measured movement table's lost taps (#293). LOST_TAP, }; @@ -93,6 +101,8 @@ std::string_view fault_class_name(FaultClass fault){ return "scene starts during the walk before it"; case FaultClass::SLOW_FADE_IN: return "slow fade-in after every warp"; + case FaultClass::START_OFFSET: + return "start off its declared tile"; case FaultClass::LOST_TAP: return "lost tap"; } @@ -105,6 +115,77 @@ constexpr std::string_view LAST_ROW = "01.11"; // Sweeps the program fails today, by test name, with the likely fix. const std::map KNOWN_FAILING{ + {"PokemonBDSP::AutoStory - Fault sweep: 00.01, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.02, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.03, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.04, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.04b, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.05, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.05b, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.05c, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.01, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.02, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.02b, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.03, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.05, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.06, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.07, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.08, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.09, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.10, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.11, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, +}; + +// Steps that need a surer pose than the steps before them leave, from +// the table before certainty_gaps(): each is to start on a wall leg or +// a landmark, as 00.05's walk to the Center does. +const std::set KNOWN_CERTAINTY_GAPS{ + "00.01 step 1 below_the_flute: needs tile, has set", + "00.01 step 12 into_barrys_house: needs tile, has set", + "00.01 step 19 down_barrys_stairs: needs tile, has set", + "00.01 step 23 barrys_warning: needs tile, has set", + "00.01 step 26 below_the_lake_entrance: needs tile, has set", + "00.01 step 4 down_the_stairs: needs tile, has set", + "00.01 step 6 above_the_door: needs tile, has set", + "00.02 step 1 to_the_lake_entrance: needs tile, has set", + "00.03 step 1 into_rowans_scene: needs tile, has set", + "00.03 step 3 out_of_the_house_again: needs tile, has set", + "00.04 step 1 out_of_the_lab: needs tile, has set", + "00.04 step 18 short_of_the_catch_tutorial: needs tile, has set", + "00.04 step 2 onto_the_path: needs tile, has set", + "00.04 step 5 to_ledge_column: needs tile, has set", + "00.04 step 7 along_route_201_road: needs tile, has set", + "00.04b step 1 to_catch_grass: needs tile, has set", + "00.04b step 3 into_sandgem: needs tile, has set", + "00.04d step 1 north_to_jubilife: needs tile, has set", + "00.05 step 10 barry: needs tile, has unknown", + "00.05 step 12 out_of_the_school: needs tile, has set", + "00.05b step 1 below_the_presidents_trigger: needs tile, has set", + "00.05b step 10 below_the_company_clown: needs tile, has set", + "00.05b step 4 past_the_president: needs tile, has set", + "00.05b step 7 below_the_tv_clown: needs tile, has set", + "00.05c step 1 to_main_boulevard: needs tile, has set", + "00.05c step 6 to_the_route_203_street: needs tile, has set", + "01.01 step 1 west_of_barrys_trigger: needs tile, has set", + "01.02 step 1 south_to_the_cliff: needs tile, has set", + "01.02 step 10 west_of_the_welcome: needs tile, has set", + "01.02 step 4 west_of_the_hikers_trigger: needs tile, has set", + "01.02 step 7 past_curtis: needs tile, has set", + "01.02b step 2 barry: needs tile, has set", + "01.02b step 4 below_the_centers_door: needs tile, has set", + "01.03 step 1 above_the_mine: needs tile, has set", + "01.03 step 11 up_to_the_hall: needs tile, has set", + "01.03 step 15 heal_oreburgh: needs tile, has set", + "01.03 step 8 roark: needs tile, has set", + "01.05 step 2 east_of_barrys_trigger: needs tile, has set", + "01.05 step 8 through_the_gate: needs tile, has set", + "01.06 step 1 up_jubilifes_road: needs tile, has set", + "01.07 step 1 rowans_trigger: needs tile, has set", + "01.08 step 1 west_to_the_wall: needs tile, has set", + "01.09 step 1 west_of_the_rock: needs tile, has set", + "01.09 step 3 above_the_way_out: needs tile, has set", + "01.10 step 1 line_1: needs tile, has set", + "01.11 step 7 old_man: needs tile, has set", }; // Scenes whose end the console has proven, by step name: the sweep leaves @@ -183,6 +264,20 @@ bool wild_or_trainers(const StoryStep& step){ // reach from it in one or two steps, and not in `seen`: where a scene can // leave them instead. A tile behind a wall is not one, nor a door's: a // step onto it goes through (00.04's moms_hat by the house's door). +// The tile next to `tile` toward `direction`. +TilePos step_from(const TilePos& tile, Direction direction){ + switch (direction){ + case Direction::NORTH: + return TilePos{tile.x, tile.y - 1}; + case Direction::SOUTH: + return TilePos{tile.x, tile.y + 1}; + case Direction::WEST: + return TilePos{tile.x - 1, tile.y}; + default: + return TilePos{tile.x + 1, tile.y}; + } +} + void walkable_neighbors(const StoryWorld* world, const Pose& pose, const TilePos& center, std::set>& seen, std::vector& out){ const auto step = [](const TilePos& tile, Direction direction){ switch (direction){ @@ -336,6 +431,40 @@ UnitTestResult sweep_slow_fade_in(Logger& logger, const StoryCheckpoint& row){ return sweep_result(logger, FaultClass::SLOW_FADE_IN, row.id, 1, failures); } +// Row `row` from 1 to 3 tiles off its declared start, each way the +// player can walk from it, one at a time. +UnitTestResult sweep_start_offset(Logger& logger, const StoryCheckpoint& row){ + std::vector failures; + size_t variants = 0; + if (!row.start){ + return sweep_result(logger, FaultClass::START_OFFSET, row.id, variants, failures); + } + const Pose start = Pokemon::pose_of(*row.start); + const std::vector tiles = Pokemon::tiles_of(start); + const StoryWorld* world = start.map.empty() ? nullptr : story_plan_world(start.map, start.map); + if (world == nullptr || tiles.empty()){ + return sweep_result(logger, FaultClass::START_OFFSET, row.id, variants, failures); + } + for (Direction direction : {Direction::NORTH, Direction::SOUTH, Direction::WEST, Direction::EAST}){ + TilePos at = tiles.front(); + for (int off = 1; off <= 3; off++){ + GridSim sim(SimWorld{.world = world}, story_to_world(*world, start.map, at), direction, false); + if (!detail::sim_can_step(sim, direction)){ + break; + } + at = step_from(at, direction); + SimWorldKnobs knobs; + knobs.start_at = Pokemon::tile_pose(start.map, {at}, Pokemon::facing_of(start)); + variants++; + const std::string stopped = run_row(logger, row.id, std::move(knobs)); + if (!stopped.empty()){ + failures.push_back({"", std::format("starts on ({}, {})", at.x, at.y), stopped}); + } + } + } + return sweep_result(logger, FaultClass::START_OFFSET, row.id, variants, failures); +} + // The route before scene step `c` of `steps`, right before it or before // the plain step onto its trigger; none if there is none. std::optional route_before_scene(const std::vector& steps, size_t c){ @@ -452,6 +581,8 @@ class Test_AutoStoryFaultSweep : public UnitTest{ return sweep_scene_early(logger, m_row); case FaultClass::SLOW_FADE_IN: return sweep_slow_fade_in(logger, m_row); + case FaultClass::START_OFFSET: + return sweep_start_offset(logger, m_row); case FaultClass::LOST_TAP: break; } @@ -462,6 +593,33 @@ class Test_AutoStoryFaultSweep : public UnitTest{ const StoryCheckpoint& m_row; }; +// No step of the table needs a surer pose than the steps before it leave +// (Pokemon_StoryCertainty.h), but those on KNOWN_CERTAINTY_GAPS. +class Test_AutoStoryCertainty : public UnitTest{ +public: + Test_AutoStoryCertainty() + : UnitTest("PokemonBDSP::AutoStory - Certainty: no step walks from a pose surer than the steps before leave") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + std::string out; + size_t known = 0; + for (const StoryCheckpoint& row : story_checkpoints()){ + for (const std::string& gap : Pokemon::certainty_gaps(row, bdsp_story_actions())){ + logger.log("Certainty gap: " + gap); + if (KNOWN_CERTAINTY_GAPS.contains(gap)){ + known++; + continue; + } + out += "\n " + gap; + } + } + if (known != KNOWN_CERTAINTY_GAPS.size()){ + out += std::format("\n {} of the {} known gaps are gone: take them off KNOWN_CERTAINTY_GAPS.", KNOWN_CERTAINTY_GAPS.size() - known, KNOWN_CERTAINTY_GAPS.size()); + } + return out.empty() ? UnitTestResult(true) : UnitTestResult("Certainty gaps:" + out); + } +}; + } // namespace const FaultSweepCase FAULT_SWEEP_CASES[] = { @@ -470,9 +628,11 @@ const FaultSweepCase FAULT_SWEEP_CASES[] = { {.input = {.fault = FaultClass::GRASS_BATTLES}, .expectation = {}}, {.input = {.fault = FaultClass::SCENE_EARLY}, .expectation = {}}, {.input = {.fault = FaultClass::SLOW_FADE_IN}, .expectation = {}}, + {.input = {.fault = FaultClass::START_OFFSET}, .expectation = {}}, }; void add_tests_AutoStory_FaultSweep(UnitTestDatabase& database){ + database.add(); for (const FaultSweepCase& item : FAULT_SWEEP_CASES){ for (const StoryCheckpoint& row : story_checkpoints()){ if (row.id < FIRST_ROW || row.id > LAST_ROW){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index d028950c20..eed9a5836c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -602,6 +602,14 @@ bool SimExecutor::sync(const Pose& pose, const StoryWorld* on){ if (local && on_grid(player.pos) && std::find(tiles.begin(), tiles.end(), *local) != tiles.end()){ return true; } + const std::optional& start_at = m_knobs.start_at; + if (!m_placed && start_at && start_at->map == pose.map && !Pokemon::tiles_of(*start_at).empty()){ + m_sim.place(setup(world), story_to_world(*world, pose.map, Pokemon::tiles_of(*start_at).front()), Pokemon::facing_of(pose)); + m_placed = true; + m_misplaced = true; + m_logger.log(std::format("[{}] the save leaves the player on {}, off the declared {}.", m_row, to_string(*start_at), to_string(pose))); + return true; + } m_sim.place(setup(world), story_to_world(*world, pose.map, tiles.front()), Pokemon::facing_of(pose)); m_placed = true; return true; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index d467e53da6..0a8e5ac8e5 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -188,6 +188,10 @@ struct SimWorldKnobs{ // goes nowhere (lab-B 2026-11-10, 00.04b heal_sandgem walked to the // nurse 1500 ms after the Center's fade and stopped on "transition"). bool slow_fade_in = false; + // Where the first row's save really leaves the player, when that is not + // its declared start: the program starts from the declared start, the + // player from here (00.05, lab-B 2026-11-11: two tiles off). + std::optional start_at = std::nullopt; }; namespace detail{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json index 666569b83e..a36fcab0ce 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json @@ -148,8 +148,8 @@ "map": "JubilifeCity", "tiles": [ [ - 48, - 62 + 46, + 60 ] ] }, @@ -162,8 +162,8 @@ "map": "JubilifeCity", "tiles": [ [ - 48, - 62 + 46, + 60 ] ] }, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json index 0e985d5acc..30701dc037 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json @@ -1,6 +1,263 @@ { "checkpoint": { "events": [ + { + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 6 + } + ] + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 43, + 51 + ], + [ + 44, + 51 + ], + [ + 45, + 51 + ], + [ + 46, + 51 + ], + [ + 47, + 51 + ], + [ + 48, + 51 + ], + [ + 49, + 51 + ], + [ + 43, + 52 + ], + [ + 44, + 52 + ], + [ + 45, + 52 + ], + [ + 46, + 52 + ], + [ + 47, + 52 + ], + [ + 48, + 52 + ], + [ + 49, + 52 + ], + [ + 44, + 53 + ], + [ + 45, + 53 + ], + [ + 46, + 53 + ], + [ + 47, + 53 + ], + [ + 48, + 53 + ], + [ + 43, + 54 + ], + [ + 44, + 54 + ], + [ + 45, + 54 + ], + [ + 46, + 54 + ], + [ + 47, + 54 + ], + [ + 48, + 54 + ], + [ + 49, + 54 + ], + [ + 43, + 55 + ], + [ + 44, + 55 + ], + [ + 45, + 55 + ], + [ + 46, + 55 + ], + [ + 47, + 55 + ], + [ + 48, + 55 + ], + [ + 49, + 55 + ], + [ + 43, + 56 + ], + [ + 44, + 56 + ], + [ + 45, + 56 + ], + [ + 46, + 56 + ], + [ + 47, + 56 + ], + [ + 48, + 56 + ], + [ + 49, + 56 + ], + [ + 43, + 57 + ], + [ + 44, + 57 + ], + [ + 45, + 57 + ], + [ + 46, + 57 + ], + [ + 47, + 57 + ], + [ + 48, + 57 + ], + [ + 49, + 57 + ] + ] + }, + "id": "north_onto_the_plaza", + "kind": "legs", + "why": "up the steps onto the plaza's row 54, below the lamps on row 53; from 3 tiles off any way the start may be, it ends on rows 51 to 57" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "east", + "tiles": 10 + } + ] + }, + "declared_after": { + "facing": "east", + "map": "JubilifeCity", + "tiles": [ + [ + 52, + 51 + ], + [ + 52, + 52 + ], + [ + 52, + 53 + ], + [ + 52, + 54 + ], + [ + 52, + 55 + ], + [ + 52, + 56 + ], + [ + 52, + 57 + ] + ] + }, + "id": "east_to_the_wall", + "kind": "legs", + "why": "the buildings' west wall (x 53) on rows 51 to 57 pins the column" + }, { "args": { "fight_wild": false, @@ -8,35 +265,51 @@ { "direction": "west", "tiles": 1 - }, + } + ] + }, + "id": "off_the_wall", + "kind": "legs", + "why": "a column west, out of the way of the child north of column 52" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ { "direction": "north", - "tiles": 2 + "tiles": 20 } ] }, - "id": "up_the_steps", + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 51, + 41 + ] + ] + }, + "id": "north_to_the_center", "kind": "legs", - "why": "a tile west of the save, then up the steps to (47, 60)" + "why": "up column 51 to the Center's front wall: a tile west of its door (52, 40)" }, { - "action": "town", "args": { "fight_wild": false, - "target": { - "facing": "north", - "map": "JubilifeCity", - "tiles": [ - [ - 52, - 41 - ] - ] - } + "legs": [ + { + "direction": "east", + "tiles": 1 + } + ] }, - "id": "to_the_center", - "kind": "route", - "why": "below the Center's door (52, 40)" + "id": "below_the_centers_door", + "kind": "legs", + "why": "east under the door (52, 40)" }, { "id": "heal_jubilife", @@ -133,8 +406,8 @@ "map": "JubilifeCity", "tiles": [ [ - 48, - 62 + 46, + 60 ] ] }, diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 7db6e4d185..e49ba1686a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1581,6 +1581,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h + Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp + Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h Source/Pokemon/AutoStory/Pokemon_StoryEvent.h Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp Source/Pokemon/AutoStory/Pokemon_StoryEvents.h From 16e3ed301c84e7508ceb75a45759a40588d54451 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 16:21:31 -0800 Subject: [PATCH 02/47] BDSP AutoStory: 00.05 starts on (46, 58) and taps 4 north onto the plaza On lab-B the 00.05 save's start is 4 taps below the row under the lamps (row 54), not 6: the planned 6 taps passed the small brick building and the walk north missed the Center. 00.04d now ends on the same tile. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/AutoStory/StoryData/bdsp-00.04d.plan.json | 4 ++-- .../Programs/AutoStory/StoryData/bdsp-00.05.plan.json | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json index a36fcab0ce..51020597df 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json @@ -149,7 +149,7 @@ "tiles": [ [ 46, - 60 + 58 ] ] }, @@ -163,7 +163,7 @@ "tiles": [ [ 46, - 60 + 58 ] ] }, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json index 30701dc037..0753479fbd 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json @@ -7,7 +7,7 @@ "legs": [ { "direction": "north", - "tiles": 6 + "tiles": 4 } ] }, @@ -207,7 +207,7 @@ }, "id": "north_onto_the_plaza", "kind": "legs", - "why": "up the steps onto the plaza's row 54, below the lamps on row 53; from 3 tiles off any way the start may be, it ends on rows 51 to 57" + "why": "4 taps up from (46, 58) onto row 54, just below the lamps on row 53 (console, lab-B 2026-11-11); from 3 tiles off any way the start may be, it ends on rows 51 to 57" }, { "action": "to_wall", @@ -256,7 +256,7 @@ }, "id": "east_to_the_wall", "kind": "legs", - "why": "the buildings' west wall (x 53) on rows 51 to 57 pins the column" + "why": "the small brick building's west wall (x 53, rows 51 to 57; on console against it from row 54) pins the column" }, { "args": { @@ -407,7 +407,7 @@ "tiles": [ [ 46, - 60 + 58 ] ] }, From 9ced829366320c61260a58a98c03535d2b6747b3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 16:44:53 -0800 Subject: [PATCH 03/47] BDSP AutoStory: stop the wanderer talk when a row step leaves the row 00.05c on console B (2026-11-11): during company_clown, a one-tile step along the row ended in a fade (walk "transition") that step_along() ignored; the search went on in the Poketch Company's lobby, 00.05c saved there, and along_main_boulevard replanned from boulevard tiles until "too many plans". Steps now count only tiles they moved, fail the step on a fade or dialogue, and the walk back must reach home. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_Actions_Tests.cpp | 30 +++++++++++++++++++ .../PokemonBDSP_AutoStory_Events_Jubilife.cpp | 22 +++++++++----- .../Actions/PokemonBDSP_AutoStory_Talks.cpp | 12 ++++++++ .../Actions/PokemonBDSP_AutoStory_Talks.h | 8 +++++ 4 files changed, 65 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp index 446a771ed8..362457655f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -30,6 +30,7 @@ #include "PokemonBDSP_AutoStory_IntroSteps.h" #include "PokemonBDSP_AutoStory_LitDoorway.h" #include "PokemonBDSP_AutoStory_NewGame.h" +#include "PokemonBDSP_AutoStory_Talks.h" #include "PokemonBDSP_AutoStory_Actions_Tests.h" namespace PokemonAutomation{ @@ -441,6 +442,31 @@ UnitTestResult test_school_lamp(Logger& logger){ // no name read, Piplup's Pound at 35 PP and Growl at 22 PP, and the old // "newest move that is not a status move" fallback used Growl until the // training gave up after 25 turns. +// A step along the row below the clown: a fade or a dialogue left the row +// and fails the talk (00.05c, 2026-11-11: the step's fade was ignored and +// the search went on in the Poketch Company's lobby); a step that moved +// nothing counts no tile. +UnitTestResult test_wander_row_step(Logger&){ + struct Case{ std::string_view name; WalkStop stop; size_t moved; int east; std::optional expected; }; + const Case cases[] = { + {"east step moved", WalkStop::LIMIT, 1, 1, 1}, + {"west step moved", WalkStop::LIMIT, 1, -1, -1}, + {"west step blocked by him", WalkStop::LIMIT, 0, -1, 0}, + {"east step into a wall", WalkStop::BLOCKED, 0, 1, 0}, + {"east step through a door", WalkStop::TRANSITION, 0, 1, std::nullopt}, + {"west step into a dialogue", WalkStop::DIALOG, 0, -1, std::nullopt}, + }; + for (const Case& c : cases){ + WalkResult result{}; + result.stop = c.stop; + result.moved_chunks = c.moved; + if (wander_row_step(result, c.east) != c.expected){ + return std::string(c.name) + ": wrong step."; + } + } + return true; +} + UnitTestResult test_choose_move(Logger&){ struct Case{ std::string_view name; std::vector slots; size_t best; }; const Case cases[] = { @@ -590,6 +616,10 @@ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { .input = {"battle moves: the pick from names and PP", test_choose_move}, .expectation = {}, }, + { + .input = {"wanderer talk: a step along the row leaves it only by a fade or a dialogue", test_wander_row_step}, + .expectation = {}, + }, { .input = {"battle moves: move menu screenshots in each language", test_move_menu_screenshots}, .expectation = {}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp index 86413db20a..df91ae175f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp @@ -50,10 +50,16 @@ bool ask_north(VideoStream& stream, ProControllerContext& context){ } return false; } -// One tile along the row, east (+1) or west (-1). -void step_along(VideoStream& stream, ProControllerContext& context, int east, const std::string& label){ +// One tile along the row, east (+1) or west (-1). Returns the tiles moved +// east; fails the step when the walk left the row (wander_row_step()). +int step_along(VideoStream& stream, ProControllerContext& context, int east, const std::string& label){ route_turn(stream, context, east > 0 ? Direction::EAST : Direction::WEST); - walk_tiles_dpad(stream, context, run_from_wild_battle, {east > 0 ? 1.0 : -1.0, 0}, 1, label); + const WalkResult result = walk_tiles_dpad(stream, context, run_from_wild_battle, {east > 0 ? 1.0 : -1.0, 0}, 1, label); + const std::optional moved = wander_row_step(result, east); + if (!moved){ + fail_step(stream, label + ": " + walk_stop_name(result.stop) + " instead of a step along the row."); + } + return *moved; } Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep& step){ VideoStream& stream = executor.stream(); @@ -65,16 +71,18 @@ Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, c for (size_t round = 0; round < 6; round++){ for (int move : moves){ if (move != 0){ - step_along(stream, context, move, label); - at += move; + at += step_along(stream, context, move, label); } if (!ask_north(stream, context)){ continue; } stream.log(std::format("[Talk] {}: answered in round {}, {} tiles east of home.", step.name, round + 1, at)); finish_dialogue(stream, context, BUTTON_A, step.name); - for (; at != 0; at += at > 0 ? -1 : 1){ - step_along(stream, context, at > 0 ? -1 : 1, "Back below " + step.name + "'s home"); + for (size_t tries = 0; at != 0 && tries < 4; tries++){ + at += step_along(stream, context, at > 0 ? -1 : 1, "Back below " + step.name + "'s home"); + } + if (at != 0){ + fail_step(stream, std::format("{}: still {} tiles east of his home after 4 steps back.", step.name, at)); } route_turn(stream, context, Direction::NORTH); return Pokemon::outcome_ok(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp index 84dda41bbf..86b313431a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp @@ -294,6 +294,18 @@ DialogueRead read_sign(VideoStream& stream, ProControllerContext& context, Direc +std::optional wander_row_step(const WalkResult& result, int east){ + switch (result.stop){ + case WalkStop::TRANSITION: + case WalkStop::DIALOG: + return std::nullopt; + default: + return result.moved_chunks > 0 ? east : 0; + } +} + + + } // namespace PokemonBDSP } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h index b8fae5f225..1c8830ea84 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h @@ -13,11 +13,13 @@ #define PokemonAutomation_PokemonBDSP_AutoStory_Talks_H #include +#include #include #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "Pokemon/Navigation/Pokemon_Grid.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" #include "PokemonBDSP_AutoStory_Battle.h" namespace PokemonAutomation{ @@ -96,6 +98,12 @@ DialogueRead talk_walking(VideoStream& stream, ProControllerContext& context, Po // the screen (a sign's may be green, not a dialogue's), what OCR reads // in it, and whether B closed it. DialogueRead read_sign(VideoStream& stream, ProControllerContext& context, Pokemon::Direction facing, const std::string& label); +// A one-tile step along the row below a wanderer, `east` +1 or -1, from +// its walk: the tiles it moved east (0 when he or a wall blocked it), or +// none when it left the row: through a door, into a dialogue. 00.05c +// (2026-11-11): a step's fade went unread and the search went on indoors, +// so the next checkpoint saved in the Poketch Company's lobby. +std::optional wander_row_step(const WalkResult& result, int east); From cf0df9617cce14ea1e028327dc56ddc960525d71 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 16:52:45 -0800 Subject: [PATCH 04/47] BDSP AutoStory: wander_row_step in Events.h, not Talks.h (header symbol limit) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp | 5 +++-- .../AutoStory/Actions/PokemonBDSP_AutoStory_Events.h | 9 +++++++++ .../PokemonBDSP_AutoStory_Events_Jubilife.cpp | 12 +++++++++++- .../Actions/PokemonBDSP_AutoStory_Talks.cpp | 12 ------------ .../AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h | 8 -------- 5 files changed, 23 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp index 362457655f..f3e36035c9 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -26,11 +27,11 @@ #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "PokemonBDSP_AutoStory_BattleMoves.h" #include "PokemonBDSP_AutoStory_Center.h" +#include "PokemonBDSP_AutoStory_Events.h" #include "PokemonBDSP_AutoStory_IntroProbe.h" #include "PokemonBDSP_AutoStory_IntroSteps.h" #include "PokemonBDSP_AutoStory_LitDoorway.h" #include "PokemonBDSP_AutoStory_NewGame.h" -#include "PokemonBDSP_AutoStory_Talks.h" #include "PokemonBDSP_AutoStory_Actions_Tests.h" namespace PokemonAutomation{ @@ -461,7 +462,7 @@ UnitTestResult test_wander_row_step(Logger&){ result.stop = c.stop; result.moved_chunks = c.moved; if (wander_row_step(result, c.east) != c.expected){ - return std::string(c.name) + ": wrong step."; + return std::format("{}: wrong step.", c.name); } } return true; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h index a39c9738d9..63be0a09a5 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h @@ -24,8 +24,10 @@ #include #include +#include #include #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -57,6 +59,13 @@ void add_oreburgh_events(StoryEvents& events); // Populates Route 204-area story event handlers. void add_route204_events(StoryEvents& events); +// A one-tile step along the row below a wanderer (00.05b's clowns), `east` +// +1 or -1, from its walk: the tiles it moved east (0 when he or a wall +// blocked it), or none when it left the row: through a door, into a +// dialogue. 00.05c (2026-11-11): a step's fade went unread and the search +// went on indoors, so the next checkpoint saved in the Poketch Company. +std::optional wander_row_step(const WalkResult& result, int east); + } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp index df91ae175f..14afaa17f0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp @@ -57,7 +57,7 @@ int step_along(VideoStream& stream, ProControllerContext& context, int east, con const WalkResult result = walk_tiles_dpad(stream, context, run_from_wild_battle, {east > 0 ? 1.0 : -1.0, 0}, 1, label); const std::optional moved = wander_row_step(result, east); if (!moved){ - fail_step(stream, label + ": " + walk_stop_name(result.stop) + " instead of a step along the row."); + fail_step(stream, std::format("{}: {} instead of a step along the row.", label, walk_stop_name(result.stop))); } return *moved; } @@ -94,6 +94,16 @@ Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, c } // namespace +std::optional wander_row_step(const WalkResult& result, int east){ + switch (result.stop){ + case WalkStop::TRANSITION: + case WalkStop::DIALOG: + return std::nullopt; + default: + return result.moved_chunks > 0 ? east : 0; + } +} + void add_jubilife_events(StoryEvents& events){ events.emplace("talk_to_wanderer", talk_to_wanderer); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp index 86b313431a..84dda41bbf 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp @@ -294,18 +294,6 @@ DialogueRead read_sign(VideoStream& stream, ProControllerContext& context, Direc -std::optional wander_row_step(const WalkResult& result, int east){ - switch (result.stop){ - case WalkStop::TRANSITION: - case WalkStop::DIALOG: - return std::nullopt; - default: - return result.moved_chunks > 0 ? east : 0; - } -} - - - } // namespace PokemonBDSP } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h index 1c8830ea84..b8fae5f225 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h @@ -13,13 +13,11 @@ #define PokemonAutomation_PokemonBDSP_AutoStory_Talks_H #include -#include #include #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "Pokemon/Navigation/Pokemon_Grid.h" -#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" #include "PokemonBDSP_AutoStory_Battle.h" namespace PokemonAutomation{ @@ -98,12 +96,6 @@ DialogueRead talk_walking(VideoStream& stream, ProControllerContext& context, Po // the screen (a sign's may be green, not a dialogue's), what OCR reads // in it, and whether B closed it. DialogueRead read_sign(VideoStream& stream, ProControllerContext& context, Pokemon::Direction facing, const std::string& label); -// A one-tile step along the row below a wanderer, `east` +1 or -1, from -// its walk: the tiles it moved east (0 when he or a wall blocked it), or -// none when it left the row: through a door, into a dialogue. 00.05c -// (2026-11-11): a step's fade went unread and the search went on indoors, -// so the next checkpoint saved in the Poketch Company's lobby. -std::optional wander_row_step(const WalkResult& result, int east); From 1345efc2512b11175c92625d386444023f1ddfec Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 19:37:42 -0800 Subject: [PATCH 05/47] Pokemon Navigation: one movement mechanics table per game Tap lengths, tile times per gait and axis, start delay and how open legs are pressed (BDSP taps, FRLG timed holds on foot), with an entry for BDSP and one for FRLG and a check of each. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../Navigation/Pokemon_MoveMechanics.h | 92 +++++++++++++++++++ .../Pokemon_MoveMechanics_Tests.cpp | 76 +++++++++++++++ .../Navigation/Pokemon_MoveMechanics_Tests.h | 22 +++++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 5 files changed, 195 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 5eec7c80d7..4920e76717 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -35,6 +35,7 @@ #include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h" #include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h" #include "Pokemon/Navigation/Pokemon_MapData_Tests.h" +#include "Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h" #include "Pokemon/Navigation/Pokemon_RouteLog_Tests.h" #include "Pokemon/Navigation/Pokemon_RuntimeMap_Tests.h" #include "Pokemon/Navigation/Pokemon_WallRecovery_Tests.h" @@ -78,6 +79,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ Pokemon::add_tests_LegWalker(ret); Pokemon::add_tests_WallRecovery(ret); Pokemon::add_tests_MapData(ret); + Pokemon::add_tests_MoveMechanics(ret); Pokemon::add_tests_RuntimeMap(ret); Pokemon::add_tests_RouteLog(ret); Pokemon::add_tests_AutoStory(ret); diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h new file mode 100644 index 0000000000..4aab5f79eb --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h @@ -0,0 +1,92 @@ +/* Move Mechanics + * + * From: https://github.com/PokemonAutomation/ + * + * How each game moves the player for a press, as measured on the console: + * one entry per game, read by that game's walker and by its sim. + * + */ + +#ifndef PokemonAutomation_Pokemon_MoveMechanics_H +#define PokemonAutomation_Pokemon_MoveMechanics_H + +#include +#include "Common/Cpp/Time.h" +#include "Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// How the walker presses an open leg, one that ends short of a wall. +enum class OpenLegPress{ + STEP_TAPS, // a step tap a tile: the count is exact + TIMED_HOLD, // one hold, timed by the tile time +}; + +// Time per tile along each axis of the screen. +struct TileTime{ + Milliseconds across; // east or west + Milliseconds up_down; // north or south + + constexpr Milliseconds along(Direction direction) const{ + return direction == Direction::EAST || direction == Direction::WEST ? across : up_down; + } +}; + +// One way of moving: walking, running or riding. +struct Gait{ + TileTime tile; + OpenLegPress open_legs; +}; + +struct MoveMechanics{ + // A tap that turns a player facing another way, without a step. + Milliseconds turn_tap; + // A tap that takes one step, and the release before the next press. + Milliseconds step_tap; + Milliseconds step_tap_release; + // From pressing, standing still, to the first step under way. + Milliseconds start_delay; + Gait walk; + // B held, once the player has the Running Shoes. + Gait run; + // None where the walker does not ride yet. + std::optional bike; +}; + + +// Brilliant Diamond and Shining Pearl, measured on console B. The camera +// tilts, so a row takes longer than a column. D-pad taps move exactly a +// tile each, while a held run overshoots about 3 tiles in 10 (2026-11-09, +// Jubilife), so open legs are tapped. Taps: PokemonBDSP_AutoStory_RouteInput.h; +// tile times: PokemonBDSP_AutoStory_RouteTiming.h. +inline constexpr MoveMechanics BDSP_MOVE_MECHANICS{ + .turn_tap = Milliseconds(50), + .step_tap = Milliseconds(160), + .step_tap_release = Milliseconds(640), + .start_delay = Milliseconds(250), + .walk = {.tile = {.across = Milliseconds(160), .up_down = Milliseconds(240)}, .open_legs = OpenLegPress::STEP_TAPS}, + .run = {.tile = {.across = Milliseconds(100), .up_down = Milliseconds(150)}, .open_legs = OpenLegPress::STEP_TAPS}, + .bike = std::nullopt, +}; + +// FireRed and LeafGreen, measured on console B: a walking tile is 16 +// frames, running 8, and a held leg stops where its time says, so open +// legs on foot are timed holds; on the Bicycle they are counted in taps. +// The walker's holds count no start delay. Measurements: +// PokemonFRLG_MovementMechanics.h and PokemonFRLG_BikeSpinMechanics.h. +inline constexpr MoveMechanics FRLG_MOVE_MECHANICS{ + .turn_tap = Milliseconds(40), + .step_tap = Milliseconds(66), + .step_tap_release = Milliseconds(700), + .start_delay = Milliseconds(0), + .walk = {.tile = {.across = Milliseconds(267), .up_down = Milliseconds(267)}, .open_legs = OpenLegPress::TIMED_HOLD}, + .run = {.tile = {.across = Milliseconds(133), .up_down = Milliseconds(133)}, .open_legs = OpenLegPress::TIMED_HOLD}, + .bike = Gait{.tile = {.across = Milliseconds(100), .up_down = Milliseconds(100)}, .open_legs = OpenLegPress::STEP_TAPS}, +}; + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp new file mode 100644 index 0000000000..d9ab5bcdb4 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp @@ -0,0 +1,76 @@ +/* Move Mechanics Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_MoveMechanics.h" +#include "Pokemon_MoveMechanics_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ +namespace{ + + +struct MoveMechanicsCase{ + std::string game; + MoveMechanics mechanics; + // How the walker presses an open leg on foot (the user's pick, + // 2026-11-11: BDSP taps, FRLG timed holds). + OpenLegPress open_legs_on_foot; +}; + +// Why `faster` is not faster than `slower` on both axes, if it is not. +std::optional not_faster(const char* faster_name, const Gait& faster, const char* slower_name, const Gait& slower){ + if (faster.tile.across >= slower.tile.across || faster.tile.up_down >= slower.tile.up_down){ + return std::format("{} ({}/{} ms) is not faster than {} ({}/{} ms).", + faster_name, faster.tile.across.count(), faster.tile.up_down.count(), + slower_name, slower.tile.across.count(), slower.tile.up_down.count()); + } + return std::nullopt; +} + +class Test_MoveMechanics : public UnitTest{ +public: + explicit Test_MoveMechanics(MoveMechanicsCase scenario) + : UnitTest("Pokemon::MoveMechanics - " + scenario.game), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const MoveMechanics& game = m_scenario.mechanics; + if (game.turn_tap >= game.step_tap){ + return std::format("The turn tap ({} ms) is not shorter than the step tap ({} ms).", + game.turn_tap.count(), game.step_tap.count()); + } + if (std::optional slower = not_faster("running", game.run, "walking", game.walk)){ + return *slower; + } + if (game.bike){ + if (std::optional slower = not_faster("the bike", *game.bike, "running", game.run)){ + return *slower; + } + } + if (game.walk.open_legs != m_scenario.open_legs_on_foot || game.run.open_legs != m_scenario.open_legs_on_foot){ + return "Open legs on foot are not pressed the way the game's walker presses them."; + } + return true; + } +private: + MoveMechanicsCase m_scenario; +}; + + +} // namespace + +void add_tests_MoveMechanics(UnitTestDatabase& database){ + database.add(MoveMechanicsCase{"BDSP", BDSP_MOVE_MECHANICS, OpenLegPress::STEP_TAPS}); + database.add(MoveMechanicsCase{"FRLG", FRLG_MOVE_MECHANICS, OpenLegPress::TIMED_HOLD}); +} + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h new file mode 100644 index 0000000000..a545eae699 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h @@ -0,0 +1,22 @@ +/* Move Mechanics Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_MoveMechanics_Tests_H +#define PokemonAutomation_Pokemon_MoveMechanics_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers the checks on each game's movement table. +void add_tests_MoveMechanics(UnitTestDatabase& database); + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index cd4fc4c225..bd96a5cd27 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1480,6 +1480,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_MapData.h Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp Source/Pokemon/Navigation/Pokemon_MapData_Tests.h + Source/Pokemon/Navigation/Pokemon_MoveMechanics.h + Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp + Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h Source/Pokemon/Navigation/Pokemon_RuntimeMap.cpp Source/Pokemon/Navigation/Pokemon_RuntimeMap.h Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp From d1359c743442a8aa8db9271dc3328f795c511533 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 19:40:38 -0800 Subject: [PATCH 06/47] Pokemon Navigation: MoveMechanics tests from a table of cases Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_MoveMechanics.h | 1 + .../Pokemon_MoveMechanics_Tests.cpp | 36 ++++++++++++++----- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h index 4aab5f79eb..c96e424cd1 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h @@ -40,6 +40,7 @@ struct Gait{ OpenLegPress open_legs; }; +// How one game moves the player: its taps, and a tile time per gait. struct MoveMechanics{ // A tap that turns a player facing another way, without a step. Milliseconds turn_tap; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp index d9ab5bcdb4..bdb39073ab 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon_MoveMechanics.h" @@ -17,16 +18,22 @@ namespace Pokemon{ namespace{ -struct MoveMechanicsCase{ - std::string game; +struct MoveMechanicsInput{ + std::string_view game; MoveMechanics mechanics; +}; +struct MoveMechanicsExpectation{ // How the walker presses an open leg on foot (the user's pick, // 2026-11-11: BDSP taps, FRLG timed holds). OpenLegPress open_legs_on_foot; }; +struct MoveMechanicsCase{ + MoveMechanicsInput input; + MoveMechanicsExpectation expectation; +}; // Why `faster` is not faster than `slower` on both axes, if it is not. -std::optional not_faster(const char* faster_name, const Gait& faster, const char* slower_name, const Gait& slower){ +std::optional not_faster(std::string_view faster_name, const Gait& faster, std::string_view slower_name, const Gait& slower){ if (faster.tile.across >= slower.tile.across || faster.tile.up_down >= slower.tile.up_down){ return std::format("{} ({}/{} ms) is not faster than {} ({}/{} ms).", faster_name, faster.tile.across.count(), faster.tile.up_down.count(), @@ -38,10 +45,10 @@ std::optional not_faster(const char* faster_name, const Gait& faste class Test_MoveMechanics : public UnitTest{ public: explicit Test_MoveMechanics(MoveMechanicsCase scenario) - : UnitTest("Pokemon::MoveMechanics - " + scenario.game), m_scenario(std::move(scenario)) + : UnitTest(std::format("Pokemon::MoveMechanics - {}", scenario.input.game)), m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const MoveMechanics& game = m_scenario.mechanics; + const MoveMechanics& game = m_scenario.input.mechanics; if (game.turn_tap >= game.step_tap){ return std::format("The turn tap ({} ms) is not shorter than the step tap ({} ms).", game.turn_tap.count(), game.step_tap.count()); @@ -54,7 +61,8 @@ class Test_MoveMechanics : public UnitTest{ return *slower; } } - if (game.walk.open_legs != m_scenario.open_legs_on_foot || game.run.open_legs != m_scenario.open_legs_on_foot){ + const OpenLegPress expected = m_scenario.expectation.open_legs_on_foot; + if (game.walk.open_legs != expected || game.run.open_legs != expected){ return "Open legs on foot are not pressed the way the game's walker presses them."; } return true; @@ -63,12 +71,24 @@ class Test_MoveMechanics : public UnitTest{ MoveMechanicsCase m_scenario; }; +const MoveMechanicsCase MOVE_MECHANICS_CASES[] = { + { + .input = {.game = "BDSP", .mechanics = BDSP_MOVE_MECHANICS}, + .expectation = {.open_legs_on_foot = OpenLegPress::STEP_TAPS}, + }, + { + .input = {.game = "FRLG", .mechanics = FRLG_MOVE_MECHANICS}, + .expectation = {.open_legs_on_foot = OpenLegPress::TIMED_HOLD}, + }, +}; + } // namespace void add_tests_MoveMechanics(UnitTestDatabase& database){ - database.add(MoveMechanicsCase{"BDSP", BDSP_MOVE_MECHANICS, OpenLegPress::STEP_TAPS}); - database.add(MoveMechanicsCase{"FRLG", FRLG_MOVE_MECHANICS, OpenLegPress::TIMED_HOLD}); + for (const MoveMechanicsCase& scenario : MOVE_MECHANICS_CASES){ + database.add(scenario); + } } From fa4c284598109d759ca11e103241af20242124c7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:13:15 -0800 Subject: [PATCH 07/47] BDSP AutoStory: 00.05b ends against the Poketch Company sign, 00.05c starts there The console save believed at (15, 19) was in the Poketch lobby. 00.05b now ends with a step west into the signboard (13, 19), which pins (14, 19) facing west; 00.05c starts on that tile. Console B is saved there (2026-11-11). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/StoryData/bdsp-00.05b.plan.json | 29 +++++++++++++++++++ .../AutoStory/StoryData/bdsp-00.05c.plan.json | 4 +-- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json index c9d0ddeec7..56ef4d5f4f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json @@ -166,6 +166,35 @@ "id": "company_clown", "kind": "talk", "why": "the clown by the Poketch Company: 'Do moves have types?' Yes; Coupon 2" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 14, + 19 + ] + ] + } + }, + "declared_after": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 14, + 19 + ] + ] + }, + "id": "beside_the_company_sign", + "kind": "route", + "why": "west 1 against the Poketch Company's signboard (13, 19): the bump pins the tile the save is made on (console 2026-11-11: a save believed at (15, 19) was in the Poketch lobby)" } ], "id": "00.05b", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json index cc4053cbae..f05444f406 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json @@ -100,11 +100,11 @@ ], "id": "00.05c", "start": { - "facing": "north", + "facing": "west", "map": "JubilifeCity", "tiles": [ [ - 15, + 14, 19 ] ] From dbe09a798a95f87bed7eb89d6cd1bccc12341af2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:31:06 -0800 Subject: [PATCH 08/47] Pokemon Navigation: connected maps, one world type for BDSP and FRLG Maps joined by their warps and edges, with the player's place as a map and a tile of it. Where a warp or an edge leads is computed once here; whether a step is allowed stays per game. connect_by_world() joins maps placed on one world grid, for BDSP's maps, which have no connections. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../Navigation/Pokemon_ConnectedMaps.cpp | 134 ++++++++++++ .../Navigation/Pokemon_ConnectedMaps.h | 90 ++++++++ .../Pokemon_ConnectedMaps_Tests.cpp | 205 ++++++++++++++++++ .../Navigation/Pokemon_ConnectedMaps_Tests.h | 22 ++ SerialPrograms/cmake/SourceFiles.cmake | 4 + 6 files changed, 457 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 5eec7c80d7..8e3eb9c1ec 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -32,6 +32,7 @@ #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" +#include "Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h" #include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h" #include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h" #include "Pokemon/Navigation/Pokemon_MapData_Tests.h" @@ -78,6 +79,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ Pokemon::add_tests_LegWalker(ret); Pokemon::add_tests_WallRecovery(ret); Pokemon::add_tests_MapData(ret); + Pokemon::add_tests_ConnectedMaps(ret); Pokemon::add_tests_RuntimeMap(ret); Pokemon::add_tests_RouteLog(ret); Pokemon::add_tests_AutoStory(ret); diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp new file mode 100644 index 0000000000..7f802aac2d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp @@ -0,0 +1,134 @@ +/* Connected Maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_ConnectedMaps.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +std::optional ConnectedMaps::find(std::string_view name) const{ + for (size_t index = 0; index < m_maps->size(); index++){ + if ((*m_maps)[index].name == name){ + return index; + } + } + return std::nullopt; +} + +std::optional ConnectedMaps::warp_arrival(const MapWarp& warp) const{ + if (!warp.to){ + return std::nullopt; + } + const std::optional destination = find(warp.to->map); + if (!destination){ + return std::nullopt; + } + const MapData& to = map(*destination); + const auto arrival = to.points.find(warp.to->point); + if (arrival == to.points.end()){ + return std::nullopt; + } + return MapPlace{*destination, arrival->second}; +} + +std::optional ConnectedMaps::across_edge(const MapPlace& from, Direction side) const{ + const TilePos here = from.tile; + for (const MapConnection& connection : map(from.map).connections){ + if (connection.side != side){ + continue; + } + const std::optional destination = find(connection.to_map); + if (!destination){ + continue; + } + const Grid& to = map(*destination).tiles; + TilePos point{here.x - connection.offset, here.y - connection.offset}; + switch (side){ + case Direction::NORTH: + point.y = to.height - 1; + break; + case Direction::SOUTH: + point.y = 0; + break; + case Direction::WEST: + point.x = to.width - 1; + break; + case Direction::EAST: + point.x = 0; + break; + } + if (to.contains(point)){ + return MapPlace{*destination, point}; + } + } + return std::nullopt; +} + +std::optional ConnectedMaps::neighbour(const MapPlace& from, Direction direction) const{ + const TilePos ahead = from.tile.next(direction); + if (map(from.map).tiles.contains(ahead)){ + return MapPlace{from.map, ahead}; + } + return across_edge(from, direction); +} + + +namespace{ + +// The side of `a` that `b` touches, and the offset of `b`'s tiles along it, +// if their rectangles on the world grid meet along a side. +std::optional touching(const MapData& a, const MapData& b){ + const TilePos pa = a.world->offset; + const TilePos pb = b.world->offset; + const int aw = a.tiles.width; + const int ah = a.tiles.height; + const int bw = b.tiles.width; + const int bh = b.tiles.height; + const bool columns_overlap = pa.x < pb.x + bw && pb.x < pa.x + aw; + const bool rows_overlap = pa.y < pb.y + bh && pb.y < pa.y + ah; + if (columns_overlap && pb.y + bh == pa.y){ + return MapConnection{Direction::NORTH, b.name, pb.x - pa.x}; + } + if (columns_overlap && pb.y == pa.y + ah){ + return MapConnection{Direction::SOUTH, b.name, pb.x - pa.x}; + } + if (rows_overlap && pb.x + bw == pa.x){ + return MapConnection{Direction::WEST, b.name, pb.y - pa.y}; + } + if (rows_overlap && pb.x == pa.x + aw){ + return MapConnection{Direction::EAST, b.name, pb.y - pa.y}; + } + return std::nullopt; +} + +} // namespace + +void connect_by_world(std::vector& maps){ + for (MapData& a : maps){ + for (const MapData& b : maps){ + if (&a == &b || !a.world || !b.world || a.world->name != b.world->name){ + continue; + } + const std::optional connection = touching(a, b); + if (!connection){ + continue; + } + const bool joined = std::ranges::any_of(a.connections, [&](const MapConnection& existing){ + return existing.to_map == b.name; + }); + if (!joined){ + a.connections.push_back(*connection); + } + } + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h new file mode 100644 index 0000000000..f23e25d06a --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h @@ -0,0 +1,90 @@ +/* Connected Maps + * + * From: https://github.com/PokemonAutomation/ + * + * The one world the tile games (BDSP, FRLG) plan and walk on: maps joined by + * their warps and their edges (MapData::connections). The player's place in + * it is a map and a tile of that map, in the map's own coordinates. Where a + * warp or an edge leads is the same in both games; whether a step is + * allowed, and what the game does on arrival (FRLG walks the player out of + * a door), is each game's. + * + */ + +#ifndef PokemonAutomation_Pokemon_ConnectedMaps_H +#define PokemonAutomation_Pokemon_ConnectedMaps_H + +#include +#include +#include +#include +#include "Pokemon_Grid.h" +#include "Pokemon_MapData.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A tile of one of the connected maps: the map's index and the tile in that +// map's own coordinates. +struct MapPlace{ + size_t map = 0; + TilePos tile; + + bool operator==(const MapPlace& other) const = default; +}; + + +// A view of loaded maps as one connected world. It does not own the maps, +// which must outlive it and keep their order: MapPlace::map indexes them. +class ConnectedMaps{ +public: + explicit ConnectedMaps(const std::vector& maps) + : m_maps(&maps) + {} + + const MapData& map(size_t index) const{ + return (*m_maps)[index]; + } + // The loaded map named `name`, or nothing. + std::optional find(std::string_view name) const; + + // Where taking `warp` puts the player: its destination point. Nothing + // if it leads to a map that isn't loaded or names a point that map + // doesn't have. + std::optional warp_arrival(const MapWarp& warp) const; + + // The tile past `side` of `from`'s map that carries on `from`'s row or + // column: on the first loaded map connected on that side that has it. + // Nothing if no loaded map there has it. + std::optional across_edge(const MapPlace& from, Direction side) const; + + // The tile next to `from` in `direction`: on the same map, or across + // its edge. Nothing past an edge that leads nowhere loaded. + std::optional neighbour(const MapPlace& from, Direction direction) const; + +private: + const std::vector* m_maps; +}; + + +// Joins the maps that lie on the same world grid (MapData::world) where +// they meet: each map gets a connection on each side to every map whose +// rectangle touches that side, unless it has one to that map already. +// Maps without a world are left alone. +void connect_by_world(std::vector& maps); + + + +} // namespace Pokemon +} // namespace PokemonAutomation + + +template <> +struct std::hash{ + size_t operator()(const PokemonAutomation::Pokemon::MapPlace& place) const{ + return std::hash()(place.tile) * 31 + place.map; + } +}; + +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp new file mode 100644 index 0000000000..69ad4cbf65 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp @@ -0,0 +1,205 @@ +/* Connected Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A town with a route north of it and a lake east of it, joined by their + * places on one world grid (connect_by_world()), and a house the town's + * door warps into: + * + * world x: -1 0 1 2 3 4 5 + * y 0..2: [ Route (6 wide) ] + * y 3..5: [ Town (4) ][Lake] + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_ConnectedMaps.h" +#include "Pokemon_ConnectedMaps_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ +namespace{ + + +MapData open_map(std::string name, int width, int height){ + MapData map; + map.name = std::move(name); + map.tiles = Grid{width, height, std::vector((size_t)width * height, TileKind::OPEN)}; + return map; +} + +MapData on_world(MapData map, const TilePos& offset){ + map.world = MapWorld{"Test", offset}; + return map; +} + +const std::vector& test_maps(){ + static const std::vector maps = []{ + std::vector ret{ + on_world(open_map("Town", 4, 3), {0, 3}), + on_world(open_map("Route", 6, 3), {-1, 0}), + on_world(open_map("Lake", 2, 3), {4, 3}), + open_map("House", 2, 2), + }; + ret[3].points["door"] = {0, 1}; + connect_by_world(ret); + return ret; + }(); + return maps; +} + +// A tile named by its map. +struct NamedPlace{ + std::string_view map; + TilePos tile; +}; + +std::string describe(const ConnectedMaps& world, const std::optional& place){ + if (!place){ + return "nowhere"; + } + return world.map(place->map).name + " " + to_string(place->tile); +} + +// Why `actual` is not `expected`, if it is not. +std::optional mismatch(const ConnectedMaps& world, const std::optional& actual, const std::optional& expected){ + std::optional wanted; + if (expected){ + wanted = MapPlace{*world.find(expected->map), expected->tile}; + } + if (actual == wanted){ + return std::nullopt; + } + return std::format("Got {}, expected {}.", describe(world, actual), describe(world, wanted)); +} + + +struct StepInput{ + std::string_view name; + NamedPlace from; + Direction direction; +}; +struct StepCase{ + StepInput input; + std::optional expectation; +}; + +class Test_ConnectedMaps_Step : public UnitTest{ +public: + explicit Test_ConnectedMaps_Step(StepCase scenario) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedMaps world(test_maps()); + const StepInput& input = m_scenario.input; + const MapPlace from{*world.find(input.from.map), input.from.tile}; + if (std::optional error = mismatch(world, world.neighbour(from, input.direction), m_scenario.expectation)){ + return *error; + } + return true; + } +private: + StepCase m_scenario; +}; + +const StepCase STEP_CASES[] = { + { + .input = {.name = "a step on the same map", .from = {"Town", {1, 1}}, .direction = Direction::EAST}, + .expectation = NamedPlace{"Town", {2, 1}}, + }, + { + .input = {.name = "north onto the route, shifted by its offset", .from = {"Town", {0, 0}}, .direction = Direction::NORTH}, + .expectation = NamedPlace{"Route", {1, 2}}, + }, + { + .input = {.name = "south off the route into the town", .from = {"Route", {1, 2}}, .direction = Direction::SOUTH}, + .expectation = NamedPlace{"Town", {0, 0}}, + }, + { + .input = {.name = "east into the lake", .from = {"Town", {3, 2}}, .direction = Direction::EAST}, + .expectation = NamedPlace{"Lake", {0, 2}}, + }, + { + .input = {.name = "west into the town", .from = {"Lake", {0, 1}}, .direction = Direction::WEST}, + .expectation = NamedPlace{"Town", {3, 1}}, + }, + { + .input = {.name = "an edge no map joins", .from = {"Town", {0, 1}}, .direction = Direction::WEST}, + .expectation = std::nullopt, + }, + { + .input = {.name = "past the joined map's span", .from = {"Route", {0, 2}}, .direction = Direction::SOUTH}, + .expectation = std::nullopt, + }, + { + .input = {.name = "a map off the world grid joins nothing", .from = {"House", {1, 0}}, .direction = Direction::NORTH}, + .expectation = std::nullopt, + }, +}; + + +struct WarpInput{ + std::string_view name; + MapWarp warp; +}; +struct WarpCase{ + WarpInput input; + std::optional expectation; +}; + +class Test_ConnectedMaps_Warp : public UnitTest{ +public: + explicit Test_ConnectedMaps_Warp(WarpCase scenario) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedMaps world(test_maps()); + if (std::optional error = mismatch(world, world.warp_arrival(m_scenario.input.warp), m_scenario.expectation)){ + return *error; + } + return true; + } +private: + WarpCase m_scenario; +}; + +const WarpCase WARP_CASES[] = { + { + .input = {.name = "a warp to a loaded map's point", .warp = {.to = WarpDestination{"House", "door"}}}, + .expectation = NamedPlace{"House", {0, 1}}, + }, + { + .input = {.name = "a warp to a map that isn't loaded", .warp = {.to = WarpDestination{"Cave", "door"}}}, + .expectation = std::nullopt, + }, + { + .input = {.name = "a warp to a point the map lacks", .warp = {.to = WarpDestination{"House", "stairs"}}}, + .expectation = std::nullopt, + }, + { + .input = {.name = "a warp that leads nowhere", .warp = {}}, + .expectation = std::nullopt, + }, +}; + + +} // namespace + +void add_tests_ConnectedMaps(UnitTestDatabase& database){ + for (const StepCase& scenario : STEP_CASES){ + database.add(scenario); + } + for (const WarpCase& scenario : WARP_CASES){ + database.add(scenario); + } +} + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h new file mode 100644 index 0000000000..a3d6a6c26b --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h @@ -0,0 +1,22 @@ +/* Connected Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_ConnectedMaps_Tests_H +#define PokemonAutomation_Pokemon_ConnectedMaps_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers the checks on stepping and warping between connected maps. +void add_tests_ConnectedMaps(UnitTestDatabase& database); + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index cd4fc4c225..a5f48d3bcb 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1459,6 +1459,10 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Inference/Pokemon_TrainPokemonOCR.h Source/Pokemon/Inference/Pokemon_TypeReader.cpp Source/Pokemon/Inference/Pokemon_TypeReader.h + Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp + Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h + Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp + Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h Source/Pokemon/Navigation/Pokemon_Grid.cpp Source/Pokemon/Navigation/Pokemon_Grid.h Source/Pokemon/Navigation/Pokemon_LegTypes.h From b64cd70dc406a9931b2afdeb2041db2746dd541e Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:33:17 -0800 Subject: [PATCH 09/47] Pokemon Navigation: connected maps tests take an expectation struct; edge entry split out Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_ConnectedMaps.cpp | 41 +++++++++++-------- .../Navigation/Pokemon_ConnectedMaps.h | 1 + .../Pokemon_ConnectedMaps_Tests.cpp | 38 +++++++++-------- 3 files changed, 48 insertions(+), 32 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp index 7f802aac2d..73b0495f30 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp @@ -9,6 +9,30 @@ namespace PokemonAutomation{ namespace Pokemon{ +namespace{ + +// The tile of `to` that `connection` on `side` leads onto from `here`: +// the edge row or column, shifted by the connection's offset. +TilePos edge_entry(const TilePos& here, Direction side, const MapConnection& connection, const Grid& to){ + TilePos point{here.x - connection.offset, here.y - connection.offset}; + switch (side){ + case Direction::NORTH: + point.y = to.height - 1; + break; + case Direction::SOUTH: + point.y = 0; + break; + case Direction::WEST: + point.x = to.width - 1; + break; + case Direction::EAST: + point.x = 0; + break; + } + return point; +} + +} // namespace std::optional ConnectedMaps::find(std::string_view name) const{ @@ -37,7 +61,6 @@ std::optional ConnectedMaps::warp_arrival(const MapWarp& warp) const{ } std::optional ConnectedMaps::across_edge(const MapPlace& from, Direction side) const{ - const TilePos here = from.tile; for (const MapConnection& connection : map(from.map).connections){ if (connection.side != side){ continue; @@ -47,21 +70,7 @@ std::optional ConnectedMaps::across_edge(const MapPlace& from, Directi continue; } const Grid& to = map(*destination).tiles; - TilePos point{here.x - connection.offset, here.y - connection.offset}; - switch (side){ - case Direction::NORTH: - point.y = to.height - 1; - break; - case Direction::SOUTH: - point.y = 0; - break; - case Direction::WEST: - point.x = to.width - 1; - break; - case Direction::EAST: - point.x = 0; - break; - } + const TilePos point = edge_entry(from.tile, side, connection, to); if (to.contains(point)){ return MapPlace{*destination, point}; } diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h index f23e25d06a..905685db72 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h @@ -80,6 +80,7 @@ void connect_by_world(std::vector& maps); } // namespace PokemonAutomation +// A hash of MapPlace, for planners that keep places in unordered sets. template <> struct std::hash{ size_t operator()(const PokemonAutomation::Pokemon::MapPlace& place) const{ diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp index 69ad4cbf65..d39c6d2a3e 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp @@ -64,11 +64,17 @@ std::string describe(const ConnectedMaps& world, const std::optional& if (!place){ return "nowhere"; } - return world.map(place->map).name + " " + to_string(place->tile); + return std::format("{} {}", world.map(place->map).name, to_string(place->tile)); } // Why `actual` is not `expected`, if it is not. -std::optional mismatch(const ConnectedMaps& world, const std::optional& actual, const std::optional& expected){ +// Where a step or a warp should put the player, or nothing for nowhere. +struct PlaceExpectation{ + std::optional place; +}; + +std::optional mismatch(const ConnectedMaps& world, const std::optional& actual, const PlaceExpectation& expectation){ + const std::optional& expected = expectation.place; std::optional wanted; if (expected){ wanted = MapPlace{*world.find(expected->map), expected->tile}; @@ -87,7 +93,7 @@ struct StepInput{ }; struct StepCase{ StepInput input; - std::optional expectation; + PlaceExpectation expectation; }; class Test_ConnectedMaps_Step : public UnitTest{ @@ -111,35 +117,35 @@ class Test_ConnectedMaps_Step : public UnitTest{ const StepCase STEP_CASES[] = { { .input = {.name = "a step on the same map", .from = {"Town", {1, 1}}, .direction = Direction::EAST}, - .expectation = NamedPlace{"Town", {2, 1}}, + .expectation = {.place = NamedPlace{"Town", {2, 1}}}, }, { .input = {.name = "north onto the route, shifted by its offset", .from = {"Town", {0, 0}}, .direction = Direction::NORTH}, - .expectation = NamedPlace{"Route", {1, 2}}, + .expectation = {.place = NamedPlace{"Route", {1, 2}}}, }, { .input = {.name = "south off the route into the town", .from = {"Route", {1, 2}}, .direction = Direction::SOUTH}, - .expectation = NamedPlace{"Town", {0, 0}}, + .expectation = {.place = NamedPlace{"Town", {0, 0}}}, }, { .input = {.name = "east into the lake", .from = {"Town", {3, 2}}, .direction = Direction::EAST}, - .expectation = NamedPlace{"Lake", {0, 2}}, + .expectation = {.place = NamedPlace{"Lake", {0, 2}}}, }, { .input = {.name = "west into the town", .from = {"Lake", {0, 1}}, .direction = Direction::WEST}, - .expectation = NamedPlace{"Town", {3, 1}}, + .expectation = {.place = NamedPlace{"Town", {3, 1}}}, }, { .input = {.name = "an edge no map joins", .from = {"Town", {0, 1}}, .direction = Direction::WEST}, - .expectation = std::nullopt, + .expectation = {.place = std::nullopt}, }, { .input = {.name = "past the joined map's span", .from = {"Route", {0, 2}}, .direction = Direction::SOUTH}, - .expectation = std::nullopt, + .expectation = {.place = std::nullopt}, }, { .input = {.name = "a map off the world grid joins nothing", .from = {"House", {1, 0}}, .direction = Direction::NORTH}, - .expectation = std::nullopt, + .expectation = {.place = std::nullopt}, }, }; @@ -150,7 +156,7 @@ struct WarpInput{ }; struct WarpCase{ WarpInput input; - std::optional expectation; + PlaceExpectation expectation; }; class Test_ConnectedMaps_Warp : public UnitTest{ @@ -172,19 +178,19 @@ class Test_ConnectedMaps_Warp : public UnitTest{ const WarpCase WARP_CASES[] = { { .input = {.name = "a warp to a loaded map's point", .warp = {.to = WarpDestination{"House", "door"}}}, - .expectation = NamedPlace{"House", {0, 1}}, + .expectation = {.place = NamedPlace{"House", {0, 1}}}, }, { .input = {.name = "a warp to a map that isn't loaded", .warp = {.to = WarpDestination{"Cave", "door"}}}, - .expectation = std::nullopt, + .expectation = {.place = std::nullopt}, }, { .input = {.name = "a warp to a point the map lacks", .warp = {.to = WarpDestination{"House", "stairs"}}}, - .expectation = std::nullopt, + .expectation = {.place = std::nullopt}, }, { .input = {.name = "a warp that leads nowhere", .warp = {}}, - .expectation = std::nullopt, + .expectation = {.place = std::nullopt}, }, }; From a0991bc871c9461542ebc1ef88163740b002f91b Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:36:15 -0800 Subject: [PATCH 10/47] Pokemon Navigation: ConnectedMaps::size() Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h index 905685db72..8b8c62948f 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h @@ -43,6 +43,10 @@ class ConnectedMaps{ : m_maps(&maps) {} + // How many maps are loaded: MapPlace::map runs from 0 to size() - 1. + size_t size() const{ + return m_maps->size(); + } const MapData& map(size_t index) const{ return (*m_maps)[index]; } From 780b97bb0e2a7926dd0253badcf144636d420c54 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:36:27 -0800 Subject: [PATCH 11/47] PokemonBDSP AutoStory: story worlds also as connected maps Each StoryWorld now keeps its maps as Pokemon::ConnectedMaps too, joined where they meet on its grid, so the planner can move to a map and a tile (seam 2's one world type). Nothing reads it yet; a test checks that on the story's worlds every step off a map's edge lands where the grid puts it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 5 + .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 13 ++ ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 121 +++++++++++++++++- 3 files changed, 138 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index d6f7a67b80..40afe689da 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -70,6 +70,11 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo placed.warps.push_back({warp.x, warp.y}); } check_overlap(placed); + Pokemon::MapData connected = map; + connected.name = placed.name; + connected.world = Pokemon::MapWorld{"story", offset}; + m_connected.push_back(std::move(connected)); + Pokemon::connect_by_world(m_connected); m_maps.push_back(std::move(placed)); rebuild(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index cf46b6f0c5..b48bafaf10 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -11,6 +11,10 @@ * plan may not end there, but walking into one is not a wall, since it may * be an exit. * + * The same maps are also kept as connected maps (Pokemon::ConnectedMaps), + * joined where they meet on the world grid, for planning on a map and a + * tile instead of the grid. + * */ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_H @@ -19,6 +23,7 @@ #include #include #include +#include "Pokemon/Navigation/Pokemon_ConnectedMaps.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "Pokemon/Navigation/Pokemon_MapData.h" @@ -71,6 +76,13 @@ class StoryWorld{ // The map that holds a world tile, or nothing between maps. std::optional to_local(const Pokemon::TilePos& world) const; + // The maps as added, under their names here, joined where they meet. + // Tiles blocked or taken off the maps here are not in them. The view + // lasts until the next add(). + Pokemon::ConnectedMaps connected() const{ + return Pokemon::ConnectedMaps(m_connected); + } + friend std::vector wandering_hazards(const StoryWorld& world); friend bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); friend bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); @@ -102,6 +114,7 @@ class StoryWorld{ Cell* cell(const Pokemon::TilePos& pos); std::vector m_maps; + std::vector m_connected; Pokemon::TilePos m_origin; // offset of world tile (0,0) Pokemon::Grid m_cells; std::vector m_blocked; // world tiles, kept across add() diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 99cb510515..0ae63109d2 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -3,7 +3,9 @@ * From: https://github.com/PokemonAutomation/ * * StoryWorld on small synthetic maps: what each tile does to a step, maps - * joined at offsets, and tiles blocked or taken off the maps. + * joined at offsets, and tiles blocked or taken off the maps. Also the + * story's own worlds: their connected maps step across every map edge + * where the world grid does. * */ @@ -13,8 +15,10 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "Data/PokemonBDSP_AutoStory_StoryWorld.h" #include "Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" #include "PokemonBDSP_AutoStory_StoryWorld_Tests.h" namespace PokemonAutomation{ @@ -219,10 +223,125 @@ const StoryWorldCase STORY_WORLD_CASES[] = { }, }; +namespace{ + +// The first step off a map's edge, from any of its edge tiles, that lands +// somewhere else on the connected maps than on the world grid, or nothing. +std::optional edge_mismatch(const StoryWorld& world){ + const Pokemon::ConnectedMaps connected = world.connected(); + for (size_t index = 0; index < connected.size(); index++){ + const MapData& map = connected.map(index); + for (int y = 0; y < map.tiles.height; y++){ + for (int x = 0; x < map.tiles.width; x++){ + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + const TilePos from{x, y}; + if (map.tiles.contains(from.next(direction))){ + continue; + } + const std::optional grid = world.to_local(world.to_world(map.name, from).next(direction)); + const std::optional place = connected.neighbour({index, from}, direction); + const bool same = grid && place + ? grid->map == connected.map(place->map).name && grid->pos == place->tile + : !grid && !place; + if (!same){ + return std::format("{} {} {}: the grid and the connected maps disagree.", + map.name, Pokemon::to_string(from), Pokemon::direction_name(direction)); + } + } + } + } + } + return std::nullopt; +} + +struct ConnectedWorldInput{ + std::string name; + const StoryWorld& (*world)(); +}; +struct ConnectedWorldExpectation{ + // Connections over all the maps: two for each pair that meets. + size_t connections; +}; +struct ConnectedWorldCase{ + ConnectedWorldInput input; + ConnectedWorldExpectation expectation; +}; + +class Test_ConnectedStoryWorld : public UnitTest{ +public: + explicit Test_ConnectedStoryWorld(ConnectedWorldCase test_case) + : UnitTest(std::format("PokemonBDSP::AutoStory - Story world as connected maps: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const StoryWorld& world = m_case.input.world(); + if (std::optional error = edge_mismatch(world)){ + return *error; + } + const Pokemon::ConnectedMaps connected = world.connected(); + size_t connections = 0; + for (size_t index = 0; index < connected.size(); index++){ + connections += connected.map(index).connections.size(); + } + if (connections != m_case.expectation.connections){ + return std::format("{} connections, expected {}.", connections, m_case.expectation.connections); + } + return true; + } + +private: + ConnectedWorldCase m_case; +}; + +const StoryWorld& south_plan_world(){ + return *story_plan_world("TwinleafTown", "Route202"); +} +const StoryWorld& route_203_plan_world(){ + return *story_plan_world("Route203", "JubilifeCity"); +} +const StoryWorld& route_204_south_plan_world(){ + return *story_plan_world("JubilifeCity", "Route204South"); +} +const StoryWorld& route_204_north_plan_world(){ + return *story_plan_world("Route204North", "FloaromaTown"); +} + +const ConnectedWorldCase CONNECTED_WORLD_CASES[] = { + { + .input = {"Route 201, Sandgem and Route 202", story_maps}, + .expectation = {.connections = 4}, + }, + { + .input = {"Twinleaf to Route 202", south_plan_world}, + .expectation = {.connections = 8}, + }, + { + .input = {"Route 203 into Jubilife", route_203_plan_world}, + .expectation = {.connections = 2}, + }, + { + .input = {"Jubilife up Route 204's south half", route_204_south_plan_world}, + .expectation = {.connections = 2}, + }, + { + .input = {"Route 204's north half into Floaroma", route_204_north_plan_world}, + .expectation = {.connections = 2}, + }, + { + .input = {"Jubilife alone", jubilife_maps}, + .expectation = {.connections = 0}, + }, +}; + +} // namespace + void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database){ for (const auto& item : STORY_WORLD_CASES){ database.add(item); } + for (const ConnectedWorldCase& item : CONNECTED_WORLD_CASES){ + database.add(item); + } } From 40f15473e3367852aa5e775a59a94e2309de5d6e Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:40:46 -0800 Subject: [PATCH 12/47] PokemonBDSP AutoStory: connected_maps() as a free function; flatter edge check Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 4 ++ .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 13 +++--- ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 44 ++++++++++--------- 3 files changed, 34 insertions(+), 27 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index 40afe689da..a3cb3e6495 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -276,6 +276,10 @@ std::optional StoryWorld::to_local(const TilePos& world) const{ +Pokemon::ConnectedMaps connected_maps(const StoryWorld& world){ + return Pokemon::ConnectedMaps(world.m_connected); +} + bool covered(const StoryWorld& world, const TilePos& pos){ return world.tile(pos).has_value(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index b48bafaf10..819915568b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -76,13 +76,7 @@ class StoryWorld{ // The map that holds a world tile, or nothing between maps. std::optional to_local(const Pokemon::TilePos& world) const; - // The maps as added, under their names here, joined where they meet. - // Tiles blocked or taken off the maps here are not in them. The view - // lasts until the next add(). - Pokemon::ConnectedMaps connected() const{ - return Pokemon::ConnectedMaps(m_connected); - } - + friend Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); friend std::vector wandering_hazards(const StoryWorld& world); friend bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); friend bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); @@ -122,6 +116,11 @@ class StoryWorld{ }; +// The world's maps as added, under their names in it, joined where they +// meet. Tiles blocked or taken off the maps are not in them. The view +// lasts until the world's next add(). +Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); + // The rules of walking on a story world, from its tiles. // All tiles where someone wanders on the maps, in world coordinates. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 0ae63109d2..647f2cbaa7 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -225,29 +225,33 @@ const StoryWorldCase STORY_WORLD_CASES[] = { namespace{ -// The first step off a map's edge, from any of its edge tiles, that lands +// Whether stepping `direction` from `from` lands on the same map and tile +// on the world grid as on the connected maps (or nowhere on both). +bool steps_agree(const StoryWorld& world, const Pokemon::MapPlace& from, Direction direction){ + const Pokemon::ConnectedMaps connected = connected_maps(world); + const std::string& name = connected.map(from.map).name; + const std::optional grid = world.to_local(world.to_world(name, from.tile).next(direction)); + const std::optional place = connected.neighbour(from, direction); + if (grid && place){ + return grid->map == connected.map(place->map).name && grid->pos == place->tile; + } + return !grid && !place; +} + +// The first step off a map's edge, from any of its tiles, that lands // somewhere else on the connected maps than on the world grid, or nothing. std::optional edge_mismatch(const StoryWorld& world){ - const Pokemon::ConnectedMaps connected = world.connected(); + const Pokemon::ConnectedMaps connected = connected_maps(world); for (size_t index = 0; index < connected.size(); index++){ - const MapData& map = connected.map(index); - for (int y = 0; y < map.tiles.height; y++){ - for (int x = 0; x < map.tiles.width; x++){ - for (Direction direction : Pokemon::ALL_DIRECTIONS){ - const TilePos from{x, y}; - if (map.tiles.contains(from.next(direction))){ - continue; - } - const std::optional grid = world.to_local(world.to_world(map.name, from).next(direction)); - const std::optional place = connected.neighbour({index, from}, direction); - const bool same = grid && place - ? grid->map == connected.map(place->map).name && grid->pos == place->tile - : !grid && !place; - if (!same){ - return std::format("{} {} {}: the grid and the connected maps disagree.", - map.name, Pokemon::to_string(from), Pokemon::direction_name(direction)); - } + const Pokemon::Grid& tiles = connected.map(index).tiles; + for (int cell = 0; cell < tiles.width * tiles.height; cell++){ + const TilePos from{cell % tiles.width, cell / tiles.width}; + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + if (tiles.contains(from.next(direction)) || steps_agree(world, {index, from}, direction)){ + continue; } + return std::format("{} {} {}: the grid and the connected maps disagree.", + connected.map(index).name, Pokemon::to_string(from), Pokemon::direction_name(direction)); } } } @@ -278,7 +282,7 @@ class Test_ConnectedStoryWorld : public UnitTest{ if (std::optional error = edge_mismatch(world)){ return *error; } - const Pokemon::ConnectedMaps connected = world.connected(); + const Pokemon::ConnectedMaps connected = connected_maps(world); size_t connections = 0; for (size_t index = 0; index < connected.size(); index++){ connections += connected.map(index).connections.size(); From a24eaee8eb68becabc0079f067732a12d43561d0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:48:34 -0800 Subject: [PATCH 13/47] Pokemon Navigation: robust leg planner, shared by the tile games BDSP's search over the sets of tiles a player may stand on after an uncertain open leg, lifted as a template over a step model so it can plan on any state (a world tile, or a map and a tile). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../Navigation/Pokemon_RobustLegPlanner.h | 431 ++++++++++++++++++ .../Pokemon_RobustLegPlanner_Tests.cpp | 220 +++++++++ .../Pokemon_RobustLegPlanner_Tests.h | 23 + SerialPrograms/cmake/SourceFiles.cmake | 3 + 5 files changed, 679 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 8e3eb9c1ec..7de3fca05e 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -34,6 +34,7 @@ #include "Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h" #include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h" +#include "Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h" #include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h" #include "Pokemon/Navigation/Pokemon_MapData_Tests.h" #include "Pokemon/Navigation/Pokemon_RouteLog_Tests.h" @@ -76,6 +77,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ OCR::add_tests(ret); Kernels::add_tests(ret); Pokemon::add_tests_LegPlanner(ret); + Pokemon::add_tests_RobustLegPlanner(ret); Pokemon::add_tests_LegWalker(ret); Pokemon::add_tests_WallRecovery(ret); Pokemon::add_tests_MapData(ret); diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h new file mode 100644 index 0000000000..c4bff5a757 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h @@ -0,0 +1,431 @@ +/* Robust Leg Planner + * + * From: https://github.com/PokemonAutomation/ + * + * Plans walks whose open legs may go a tile short or long. A leg to a wall + * is walked until the player stops; an open leg is walked for its tiles' + * worth of time and may end a few tiles either way. The planner searches + * over the sets of places the player may stand on after each leg, and + * later walls bring them back together, so the plan reaches the goal from + * every place the player may be. + * + * A step model is a class with: + * + * using State = ...; // where the player is: comparable with == + * using StateLess = ...; // a strict order of State, for sets of them + * std::optional step(const State& state, Direction direction) const; + * size_t step_tiles(const State& from, const State& to) const; + * bool held_at(const State& state, Direction direction) const; + * bool wild(const State& state) const; + * bool wander(const State& state) const; + * + * step() is where one step `direction` lands, or nothing if the player is + * stopped. step_tiles() is how many tiles that step counts (a ledge hop + * counts 2). held_at() is whether the player, stopped, stays put however + * long the button is held (a wall); a stop that isn't held (a door, an exit + * off the maps) makes a leg the planner can't tell the end of, and it is + * not used. wild() is a place where a wild battle may stop the walk (tall + * grass); wander() one where someone wanders. + * + */ + +#ifndef PokemonAutomation_Pokemon_RobustLegPlanner_H +#define PokemonAutomation_Pokemon_RobustLegPlanner_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A leg of a robust plan: walk `direction` for `tiles` tiles, or until +// stopped if `to_wall`. `after` lists every place the player may stand on +// once the leg is done. +template +struct RobustLeg{ + Direction direction = Direction::NORTH; + size_t tiles = 0; // tiles travelled; a ledge hop counts 2 + bool to_wall = false; + std::vector after; +}; + + +// The weights of a robust plan and the limits of its search. +struct RobustLegCosts{ + int per_tile = 1; + int per_wild_tile = 4; // extra for each wild tile entered + int per_wander_tile = 3; // extra for each tile entered where someone wanders + int per_leg = 8; + int leg_not_at_wall = 50; // extra for a leg that stops in the open + // An open leg of n tiles may end open_error + n / open_error_per tiles + // short or long. + int open_error = 1; + int open_error_per = 5; + // Open legs this many tiles or shorter land exactly. 0 keeps every + // open leg uncertain. + int exact_open_tiles = 0; + // Extra per tile of an open leg: its timing error grows with its length. + int per_open_tile = 0; + int max_open_tiles = 12; // longest open leg to consider + size_t max_spread = 5; // most places the player may be on after a leg + // Most sets of places to search before giving up. The search is over + // sets, not places, so it grows far faster than the map. + size_t max_searched = 20000; +}; + + +// The cheapest legs that take the player from any of `from` to places that +// all satisfy `goal`, even if every open leg ends up to its error off. +// Legs that run along where someone wanders (two such places in a row, the +// leg's start among them) are not used. Nothing if no such plan exists, or +// none is found within `costs.max_searched` sets. +template +std::optional>> plan_robust_legs( + const Model& model, + std::vector from, + const std::function& goal, + const RobustLegCosts& costs +); + +// What plan_robust_legs() charges for walking `legs` from any of `from`, +// each leg from the places the one before may end on. A leg it would not +// plan costs its tiles and legs without wild or wander tiles. +template +long long robust_legs_cost( + const Model& model, + std::vector from, + const std::vector>& legs, + const RobustLegCosts& costs +); + + + +namespace RobustLegPlannerInternal{ + +// Where the player stops walking `direction` until stopped. +template +struct WallHit{ + State stop; + size_t tiles = 0; + bool held = false; +}; +template +WallHit slide_to_wall(const Model& model, const typename Model::State& from, Direction direction){ + WallHit hit{from}; + while (true){ + const auto next = model.step(hit.stop, direction); + if (!next){ + hit.held = model.held_at(hit.stop, direction); + return hit; + } + hit.tiles += model.step_tiles(hit.stop, *next); + hit.stop = *next; + } +} + +// Where `from` ends up after `tiles` tiles `direction`, stopping early +// where it is held, and the wild and wander tiles it enters. Nothing if a +// step is stopped where the player is not held. +template +struct Stepped{ + State end; + int wild = 0; + int wander = 0; + bool along_wander = false; +}; +template +std::optional> step_tiles(const Model& model, typename Model::State from, Direction direction, int tiles){ + Stepped stepped{from}; + int travelled = 0; + bool in_wander = model.wander(from); + while (travelled < tiles){ + const auto next = model.step(from, direction); + if (!next){ + if (!model.held_at(from, direction)){ + return std::nullopt; + } + break; + } + travelled += (int)model.step_tiles(from, *next); + stepped.wild += model.wild(*next) ? 1 : 0; + const bool next_wander = model.wander(*next); + if (next_wander){ + stepped.wander++; + stepped.along_wander |= in_wander; + } + in_wander = next_wander; + from = *next; + } + stepped.end = from; + return stepped; +} + +template +void normalize(std::vector& spread){ + using State = typename Model::State; + std::sort(spread.begin(), spread.end(), typename Model::StateLess()); + spread.erase(std::unique(spread.begin(), spread.end(), [](const State& a, const State& b){ return a == b; }), spread.end()); +} +template +struct SpreadLess{ + bool operator()(const std::vector& a, const std::vector& b) const{ + return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), typename Model::StateLess()); + } +}; + +// A leg out of a spread: where every place of it ends, and its cost. +template +struct Expansion{ + long long cost = 0; + RobustLeg leg; +}; + +// To the wall: every place walks until stopped. Nothing unless each is +// held, and one moves. +template +std::optional> to_wall_leg( + const Model& model, const std::vector& spread, Direction direction, const RobustLegCosts& costs +){ + Expansion expansion; + size_t longest = 0; + int wild = 0; + int wander = 0; + for (const auto& place : spread){ + const auto hit = slide_to_wall(model, place, direction); + if (!hit.held){ + return std::nullopt; + } + if (const auto stepped = step_tiles(model, place, direction, (int)hit.tiles)){ + if (stepped->along_wander){ + return std::nullopt; + } + wild = std::max(wild, stepped->wild); + wander = std::max(wander, stepped->wander); + } + longest = std::max(longest, hit.tiles); + expansion.leg.after.push_back(hit.stop); + } + if (longest == 0){ + return std::nullopt; + } + expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest + + (long long)costs.per_wild_tile * wild + (long long)costs.per_wander_tile * wander; + expansion.leg.direction = direction; + expansion.leg.tiles = longest; + expansion.leg.to_wall = true; + return expansion; +} + +// Open: about `tiles` tiles, give or take the error. Nothing if any +// possible end is stopped where the player is not held. +template +std::optional> open_leg( + const Model& model, const std::vector& spread, Direction direction, int tiles, const RobustLegCosts& costs +){ + Expansion expansion; + int wild = 0; + int wander = 0; + const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; + for (const auto& place : spread){ + for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ + const auto stepped = step_tiles(model, place, direction, n); + if (!stepped || stepped->along_wander){ + return std::nullopt; + } + wild = std::max(wild, stepped->wild); + wander = std::max(wander, stepped->wander); + expansion.leg.after.push_back(stepped->end); + } + } + expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall + + (long long)(costs.per_tile + costs.per_open_tile) * tiles + + (long long)costs.per_wild_tile * wild + (long long)costs.per_wander_tile * wander; + expansion.leg.direction = direction; + expansion.leg.tiles = (size_t)tiles; + return expansion; +} + +// Joins an open leg with the next one the same way: they are one hold. +template +std::vector> consolidate(const std::vector>& legs){ + std::vector> consolidated; + for (const RobustLeg& leg : legs){ + if (!consolidated.empty() && consolidated.back().direction == leg.direction && !consolidated.back().to_wall){ + consolidated.back().tiles += leg.tiles; + consolidated.back().to_wall = leg.to_wall; + consolidated.back().after = leg.after; + }else{ + consolidated.push_back(leg); + } + } + return consolidated; +} + +// Dijkstra over sets of places the player may stand on. +template +class Search{ +public: + using State = typename Model::State; + using Spread = std::vector; + + Search(const Model& model, const RobustLegCosts& costs) + : m_model(model) + , m_costs(costs) + {} + + std::optional>> run(Spread start, const std::function& goal){ + normalize(start); + m_start = start; + m_nodes[start] = Node{}; + m_queue.emplace(0, start); + size_t searched = 0; + while (!m_queue.empty()){ + const auto [cost, spread] = m_queue.top(); + m_queue.pop(); + Node& node = m_nodes[spread]; + if (node.done || node.cost != cost){ + continue; + } + node.done = true; + if (++searched > m_costs.max_searched){ + return std::nullopt; + } + if (std::all_of(spread.begin(), spread.end(), goal)){ + return consolidate(legs_to(spread)); + } + expand(spread, cost); + } + return std::nullopt; + } + +private: + struct Node{ + long long cost = 0; + Spread parent; + RobustLeg leg; + bool done = false; + }; + using Entry = std::pair; + struct EntryGreater{ + bool operator()(const Entry& a, const Entry& b) const{ + return a.first > b.first; + } + }; + + void expand(const Spread& spread, long long cost){ + for (Direction direction : ALL_DIRECTIONS){ + if (auto wall = to_wall_leg(m_model, spread, direction, m_costs)){ + relax(spread, cost, std::move(*wall)); + } + for (int tiles = 1; tiles <= m_costs.max_open_tiles; tiles++){ + auto open = open_leg(m_model, spread, direction, tiles, m_costs); + if (!open){ + break; + } + relax(spread, cost, std::move(*open)); + } + } + } + + // Only the start may be wider than costs.max_spread: every leg must + // bring the player within it. + void relax(const Spread& spread, long long cost, Expansion expansion){ + Spread& next = expansion.leg.after; + normalize(next); + if (next.size() > m_costs.max_spread || next == spread){ + return; + } + if (spread != m_start){ + const RobustLeg& prev = m_nodes.at(spread).leg; + if (expansion.leg.direction == prev.direction && !prev.to_wall){ + expansion.cost -= m_costs.per_leg; + } + } + const long long total = cost + expansion.cost; + auto iter = m_nodes.find(next); + if (iter != m_nodes.end() && iter->second.cost <= total){ + return; + } + m_nodes[next] = Node{total, spread, expansion.leg}; + m_queue.emplace(total, std::move(next)); + } + + std::vector> legs_to(const Spread& end) const{ + std::vector> legs; + for (Spread at = end; at != m_start; ){ + const Node& step = m_nodes.at(at); + legs.push_back(step.leg); + at = step.parent; + } + std::reverse(legs.begin(), legs.end()); + return legs; + } + + const Model& m_model; + const RobustLegCosts& m_costs; + Spread m_start; + std::map> m_nodes; + std::priority_queue, EntryGreater> m_queue; +}; + +} // namespace RobustLegPlannerInternal + + + +template +std::optional>> plan_robust_legs( + const Model& model, + std::vector from, + const std::function& goal, + const RobustLegCosts& costs +){ + return RobustLegPlannerInternal::Search(model, costs).run(std::move(from), goal); +} + +template +long long robust_legs_cost( + const Model& model, + std::vector from, + const std::vector>& legs, + const RobustLegCosts& costs +){ + using State = typename Model::State; + long long total = 0; + std::vector spread = std::move(from); + RobustLegPlannerInternal::normalize(spread); + const RobustLeg* previous = nullptr; + for (const RobustLeg& leg : legs){ + const auto expansion = leg.to_wall + ? RobustLegPlannerInternal::to_wall_leg(model, spread, leg.direction, costs) + : RobustLegPlannerInternal::open_leg(model, spread, leg.direction, (int)leg.tiles, costs); + long long cost = (long long)costs.per_leg + (long long)costs.per_tile * (long long)leg.tiles; + if (!leg.to_wall){ + cost += costs.leg_not_at_wall + (long long)costs.per_open_tile * (long long)leg.tiles; + } + if (expansion){ + cost = expansion->cost; + } + if (previous != nullptr && previous->direction == leg.direction && !previous->to_wall){ + cost -= costs.per_leg; + } + total += cost; + spread = leg.after; + RobustLegPlannerInternal::normalize(spread); + previous = ⋚ + } + return total; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp new file mode 100644 index 0000000000..7b5ab5dff6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp @@ -0,0 +1,220 @@ +/* Robust Leg Planner Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The robust planner on a small made-up game: walls hold the player, a + * door stops them without holding them, and open legs may end a tile off. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_RobustLegPlanner.h" +#include "Pokemon_RobustLegPlanner_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +// '#' wall (and everything outside the rows), '.' floor, '"' tall grass, +// 'w' where someone wanders, 'D' a door: the player is stopped there but +// not held, since walking on enters the building. +class ToyGame{ +public: + using State = TilePos; + struct StateLess{ + bool operator()(const TilePos& a, const TilePos& b) const{ + return a.y != b.y ? a.y < b.y : a.x < b.x; + } + }; + + explicit ToyGame(std::vector rows) + : m_rows(std::move(rows)) + {} + + std::optional step(const State& state, Direction direction) const{ + const TilePos next = state.next(direction); + const char tile = at(next); + if (tile == '#' || tile == 'D'){ + return std::nullopt; + } + return next; + } + size_t step_tiles(const State&, const State&) const{ + return 1; + } + bool held_at(const State& state, Direction direction) const{ + return at(state.next(direction)) == '#'; + } + bool wild(const State& state) const{ + return at(state) == '"'; + } + bool wander(const State& state) const{ + return at(state) == 'w'; + } + +private: + char at(const TilePos& pos) const{ + if (pos.y < 0 || pos.y >= (int)m_rows.size() || pos.x < 0 || pos.x >= (int)m_rows[pos.y].size()){ + return '#'; + } + return m_rows[pos.y][pos.x]; + } + + std::vector m_rows; +}; + +using Legs = std::vector>; + +std::string describe(const std::optional& legs){ + if (!legs){ + return " none"; + } + std::string text; + for (const RobustLeg& leg : *legs){ + text += std::format("\n {} {}{} to", direction_name(leg.direction), leg.tiles, leg.to_wall ? " (to wall)" : " (open)"); + for (const TilePos& pos : leg.after){ + text += " " + to_string(pos); + } + } + return text; +} + +std::optional plan(const ToyGame& game, std::vector from, TilePos to, const RobustLegCosts& costs){ + return plan_robust_legs(game, std::move(from), std::function([to](const TilePos& pos){ return pos == to; }), costs); +} + +RobustLegCosts exact_costs(){ + RobustLegCosts costs; + costs.exact_open_tiles = costs.max_open_tiles; + return costs; +} + + +UnitTestResult test_wall_gathers_spread(){ + // The player is on one of two tiles; walking east to the wall puts them + // on the goal either way. + const ToyGame game({ + "...#", + }); + const auto legs = plan(game, {{0, 0}, {1, 0}}, {2, 0}, RobustLegCosts()); + if (!legs || legs->size() != 1 || !(*legs)[0].to_wall || (*legs)[0].tiles != 2 || (*legs)[0].after != std::vector{{2, 0}}){ + return "Expected one leg east 2 to the wall:" + describe(legs); + } + return true; +} + +UnitTestResult test_open_leg_spreads(){ + // The goal is in the middle of a row with no wall near it: an open leg + // may end a tile either side, so there is no robust plan. With exact + // open legs, one open leg reaches it. + const ToyGame game({ + "........", + }); + const auto uncertain = plan(game, {{0, 0}}, {3, 0}, RobustLegCosts()); + if (uncertain){ + return "Expected no plan with uncertain open legs:" + describe(uncertain); + } + const auto exact = plan(game, {{0, 0}}, {3, 0}, exact_costs()); + if (!exact || exact->size() != 1 || (*exact)[0].to_wall || (*exact)[0].tiles != 3){ + return "Expected one open leg east 3:" + describe(exact); + } + return true; +} + +UnitTestResult test_door_is_not_a_wall(){ + // Walking east would stop at the door, but holding on enters it: the + // leg to the goal next to it must be an open one. + const ToyGame game({ + "#..D", + }); + const auto legs = plan(game, {{1, 0}}, {2, 0}, exact_costs()); + if (!legs || legs->size() != 1 || (*legs)[0].to_wall || (*legs)[0].tiles != 1){ + return "Expected one open leg east 1:" + describe(legs); + } + return true; +} + +UnitTestResult test_avoids_wander_run(){ + // The top row runs along where someone wanders; the bottom row is one + // longer but clear. + const ToyGame game({ + ".www.", + ".....", + }); + const auto legs = plan(game, {{1, 0}}, {4, 0}, exact_costs()); + if (!legs){ + return "No plan."; + } + for (const RobustLeg& leg : *legs){ + if (leg.direction == Direction::EAST && leg.after[0].y == 0){ + return "Walked east along the wander zone:" + describe(legs); + } + } + return true; +} + +UnitTestResult test_cost_of_plan(){ + // A wall leg costs a leg and its tiles; an open one its stop and open + // tiles on top. + const ToyGame game({ + "...#", + }); + RobustLegCosts costs = exact_costs(); + costs.per_open_tile = 2; + const Legs wall{{Direction::EAST, 2, true, {{2, 0}}}}; + const Legs open{{Direction::EAST, 1, false, {{1, 0}}}}; + const long long wall_cost = robust_legs_cost(game, {{0, 0}}, wall, costs); + const long long open_cost = robust_legs_cost(game, {{0, 0}}, open, costs); + if (wall_cost != 8 + 2 || open_cost != 8 + 50 + 3){ + return std::format("Expected costs 10 and 61, got {} and {}.", wall_cost, open_cost); + } + return true; +} + + +struct RobustLegPlannerTestCase{ + std::string name; + UnitTestResult (*test)(); +}; + +class Test_RobustLegPlanner : public UnitTest{ +public: + explicit Test_RobustLegPlanner(RobustLegPlannerTestCase scenario) + : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.name)) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return m_scenario.test(); + } + +private: + RobustLegPlannerTestCase m_scenario; +}; + +const RobustLegPlannerTestCase ROBUST_LEG_PLANNER_CASES[] = { + {.name = "a wall gathers the possible tiles", .test = test_wall_gathers_spread}, + {.name = "an open leg may end a tile off", .test = test_open_leg_spreads}, + {.name = "a door is not a wall", .test = test_door_is_not_a_wall}, + {.name = "no leg along a wander zone", .test = test_avoids_wander_run}, + {.name = "cost of given legs", .test = test_cost_of_plan}, +}; + +} // namespace + + +void add_tests_RobustLegPlanner(UnitTestDatabase& database){ + for (const auto& scenario : ROBUST_LEG_PLANNER_CASES){ + database.add(scenario); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h new file mode 100644 index 0000000000..fec9e8a2e0 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h @@ -0,0 +1,23 @@ +/* Robust Leg Planner Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_RobustLegPlanner_Tests_H +#define PokemonAutomation_Pokemon_RobustLegPlanner_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers robust leg planner unit tests. +void add_tests_RobustLegPlanner(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index a5f48d3bcb..5f6cd2bafb 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1476,6 +1476,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_LegPlanner.h Source/Pokemon/Navigation/Pokemon_LegPlanner_Tests.cpp Source/Pokemon/Navigation/Pokemon_LegPlanner_Tests.h + Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h + Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp + Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h Source/Pokemon/Navigation/Pokemon_LegWalker.cpp Source/Pokemon/Navigation/Pokemon_LegWalker.h Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp From 6d1adb06f44adbd78f8ce4c91244bcf07f0581ba Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:49:37 -0800 Subject: [PATCH 14/47] PokemonBDSP AutoStory: plan robust routes with the shared robust leg planner plan_robust_route() and robust_route_cost() keep their signatures and plans; the set search moves to Pokemon::plan_robust_legs(), with the story world's step rules as its model. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_RoutePlanner.cpp | 296 +++--------------- 1 file changed, 52 insertions(+), 244 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index a89679cf16..872e11d171 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -7,10 +7,9 @@ #include #include #include -#include -#include #include "Common/Cpp/Exceptions.h" #include "Pokemon/Navigation/Pokemon_LegPlanner.h" +#include "Pokemon/Navigation/Pokemon_RobustLegPlanner.h" #include "PokemonBDSP_AutoStory_RobustRoute.h" #include "PokemonBDSP_AutoStory_RoutePlanner.h" #include "PokemonBDSP_AutoStory_TrainerSight.h" @@ -217,237 +216,58 @@ std::string to_string(const PlannedLeg& leg){ namespace{ -// Where `from` ends up after `tiles` steps in `direction`, stopping early at -// anything that stops the player, and how many tall-grass tiles it enters. -// Nothing if a step would leave the maps or enter a door: the plan cannot -// tell what happens then. -struct Stepped{ - TilePos end; - int grass = 0; - int wander = 0; - // Two tiles in a row where someone wanders, the start among them: the - // walk runs along their zone, and plan_robust_route() does not use it. - bool along_wander = false; -}; -std::optional step_tiles(const StoryWorld& world, TilePos from, Direction direction, int tiles){ - Stepped stepped; - int travelled = 0; - bool in_wander = wandering_hazard(world, from); - while (travelled < tiles){ - const std::optional next = step(world, from, direction); - if (!next){ - if (!at_wall(world, from, direction)){ - return std::nullopt; - } - break; - } - travelled += (int)distance(*next, from); - if (tall_grass(world, *next)){ - stepped.grass++; - } - const bool next_wander = wandering_hazard(world, *next); - if (next_wander){ - stepped.wander++; - stepped.along_wander |= in_wander; - } - in_wander = next_wander; - from = *next; - } - stepped.end = from; - return stepped; -} - -using Spread = std::vector; - -bool spread_less(const TilePos& a, const TilePos& b){ - return a.y != b.y ? a.y < b.y : a.x < b.x; -} -void normalize(Spread& spread){ - std::sort(spread.begin(), spread.end(), spread_less); - spread.erase(std::unique(spread.begin(), spread.end()), spread.end()); -} -struct SpreadLess{ - bool operator()(const Spread& a, const Spread& b) const{ - return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), spread_less); - } -}; - -// A leg out of a spread: where every tile of it ends, and its cost. -struct Expansion{ - long long cost = 0; - Spread next; - TileLeg leg; -}; - -// To the wall: every position walks until stopped. Nothing unless each is -// held at a wall, and one moves. -std::optional to_wall_leg(const StoryWorld& world, const Spread& spread, Direction direction, const RobustPlanCosts& costs){ - Expansion expansion; - size_t longest = 0; - int grass = 0; - int wander = 0; - for (const TilePos& pos : spread){ - const WallHit hit = slide_to_wall(world, pos, direction); - if (!hit.anchored){ - return std::nullopt; - } - if (const std::optional stepped = step_tiles(world, pos, direction, (int)hit.tiles)){ - if (stepped->along_wander){ - return std::nullopt; - } - grass = std::max(grass, stepped->grass); - wander = std::max(wander, stepped->wander); - } - longest = std::max(longest, hit.tiles); - expansion.next.push_back(hit.stop); - } - if (longest == 0){ - return std::nullopt; - } - expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest - + (long long)costs.per_grass_tile * grass + (long long)costs.per_wander_tile * wander; - expansion.leg = TileLeg{direction, longest, true}; - return expansion; -} - -// Open: about `tiles` tiles, give or take the error. Nothing if any -// possible end leaves the maps or enters a door. -std::optional open_leg(const StoryWorld& world, const Spread& spread, Direction direction, int tiles, const RobustPlanCosts& costs){ - Expansion expansion; - int grass = 0; - int wander = 0; - const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; - for (const TilePos& pos : spread){ - for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ - const std::optional stepped = step_tiles(world, pos, direction, n); - if (!stepped || stepped->along_wander){ - return std::nullopt; - } - grass = std::max(grass, stepped->grass); - wander = std::max(wander, stepped->wander); - expansion.next.push_back(stepped->end); +// The world's step rules for the shared robust planner. A ledge hop is one +// step that counts two tiles. +class RobustWorldModel{ +public: + using State = TilePos; + struct StateLess{ + bool operator()(const TilePos& a, const TilePos& b) const{ + return a.y != b.y ? a.y < b.y : a.x < b.x; } - } - expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall + - (long long)(costs.per_tile + costs.per_open_tile) * tiles - + (long long)costs.per_grass_tile * grass + (long long)costs.per_wander_tile * wander; - expansion.leg = TileLeg{direction, (size_t)tiles, false}; - return expansion; -} + }; -// Dijkstra over sets of tiles the player may stand on. -class RobustSearch{ -public: - RobustSearch(const StoryWorld& world, const RobustPlanCosts& costs) + explicit RobustWorldModel(const StoryWorld& world) : m_world(world) - , m_costs(costs) {} - std::optional> run(Spread start, const std::function& goal){ - normalize(start); - m_start = start; - m_nodes[start] = Node{0, {}, {}}; - m_queue.emplace(0, start); - size_t searched = 0; - while (!m_queue.empty()){ - const auto [cost, spread] = m_queue.top(); - m_queue.pop(); - Node& node = m_nodes[spread]; - if (node.done || node.cost != cost){ - continue; - } - node.done = true; - if (++searched > m_costs.max_searched){ - return std::nullopt; - } - if (std::all_of(spread.begin(), spread.end(), goal)){ - return legs_to(spread); - } - expand(spread, cost); - } - return std::nullopt; + std::optional step(const State& pos, Direction direction) const{ + return PokemonBDSP::step(m_world, pos, direction); } - -private: - struct Node{ - long long cost = 0; - Spread parent; - PlannedLeg leg; - bool done = false; - }; - using Entry = std::pair; - struct EntryGreater{ - bool operator()(const Entry& a, const Entry& b) const{ return a.first > b.first; } - }; - - void expand(const Spread& spread, long long cost){ - for (Direction direction : Pokemon::ALL_DIRECTIONS){ - if (std::optional wall = to_wall_leg(m_world, spread, direction, m_costs)){ - relax(spread, cost, std::move(*wall)); - } - for (int tiles = 1; tiles <= m_costs.max_open_tiles; tiles++){ - std::optional open = open_leg(m_world, spread, direction, tiles, m_costs); - if (!open){ - break; - } - relax(spread, cost, std::move(*open)); - } - } + size_t step_tiles(const State& from, const State& to) const{ + return distance(from, to); } - - // Only the start may be wider than costs.max_spread: every leg must - // bring the player within it. - void relax(const Spread& spread, long long cost, Expansion expansion){ - normalize(expansion.next); - if (expansion.next.size() > m_costs.max_spread || expansion.next == spread){ - return; - } - if (spread != m_start){ - const TileLeg& prev = m_nodes.at(spread).leg.leg; - if (expansion.leg.direction == prev.direction && !prev.ends_at_wall){ - expansion.cost -= m_costs.per_leg; - } - } - const long long total = cost + expansion.cost; - auto iter = m_nodes.find(expansion.next); - if (iter != m_nodes.end() && iter->second.cost <= total){ - return; - } - m_nodes[expansion.next] = Node{total, spread, PlannedLeg{expansion.leg, expansion.next}}; - m_queue.emplace(total, std::move(expansion.next)); + bool held_at(const State& pos, Direction direction) const{ + return at_wall(m_world, pos, direction); } - - std::vector legs_to(const Spread& end) const{ - std::vector legs; - for (Spread at = end; at != m_start; ){ - const Node& step = m_nodes.at(at); - legs.push_back(step.leg); - at = step.parent; - } - std::reverse(legs.begin(), legs.end()); - std::vector consolidated; - for (const PlannedLeg& planned : legs){ - if (!consolidated.empty() && - consolidated.back().leg.direction == planned.leg.direction && - !consolidated.back().leg.ends_at_wall - ){ - consolidated.back().leg.tiles += planned.leg.tiles; - consolidated.back().leg.ends_at_wall = planned.leg.ends_at_wall; - consolidated.back().after = planned.after; - }else{ - consolidated.push_back(planned); - } - } - return consolidated; + bool wild(const State& pos) const{ + return tall_grass(m_world, pos); + } + bool wander(const State& pos) const{ + return wandering_hazard(m_world, pos); } +private: const StoryWorld& m_world; - const RobustPlanCosts& m_costs; - Spread m_start; - std::map m_nodes; - std::priority_queue, EntryGreater> m_queue; }; +Pokemon::RobustLegCosts robust_leg_costs(const RobustPlanCosts& costs){ + Pokemon::RobustLegCosts ret; + ret.per_tile = costs.per_tile; + ret.per_wild_tile = costs.per_grass_tile; + ret.per_wander_tile = costs.per_wander_tile; + ret.per_leg = costs.per_leg; + ret.leg_not_at_wall = costs.leg_not_at_wall; + ret.open_error = costs.open_error; + ret.open_error_per = costs.open_error_per; + ret.exact_open_tiles = costs.exact_open_tiles; + ret.per_open_tile = costs.per_open_tile; + ret.max_open_tiles = costs.max_open_tiles; + ret.max_spread = costs.max_spread; + ret.max_searched = costs.max_searched; + return ret; +} + } // namespace std::optional> plan_robust_route( @@ -469,7 +289,15 @@ std::optional> plan_robust_route( throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route starts must be standable: " + Pokemon::to_string(pos) + "."); } } - return RobustSearch(world, costs).run(from, goal); + const auto legs = Pokemon::plan_robust_legs(RobustWorldModel(world), from, goal, robust_leg_costs(costs)); + if (!legs){ + return std::nullopt; + } + std::vector ret; + for (const Pokemon::RobustLeg& leg : *legs){ + ret.push_back(PlannedLeg{TileLeg{leg.direction, leg.tiles, leg.to_wall}, leg.after}); + } + return ret; } long long robust_route_cost( @@ -477,31 +305,11 @@ long long robust_route_cost( const std::vector& from, const std::vector& legs, const RobustPlanCosts& costs ){ - long long total = 0; - Spread spread = from; - normalize(spread); - const TileLeg* previous = nullptr; + std::vector> robust; for (const PlannedLeg& planned : legs){ - const TileLeg& leg = planned.leg; - const std::optional expansion = leg.ends_at_wall - ? to_wall_leg(world, spread, leg.direction, costs) - : open_leg(world, spread, leg.direction, (int)leg.tiles, costs); - long long cost = (long long)costs.per_leg + (long long)costs.per_tile * (long long)leg.tiles; - if (!leg.ends_at_wall){ - cost += costs.leg_not_at_wall + (long long)costs.per_open_tile * (long long)leg.tiles; - } - if (expansion){ - cost = expansion->cost; - } - if (previous != nullptr && previous->direction == leg.direction && !previous->ends_at_wall){ - cost -= costs.per_leg; - } - total += cost; - spread = planned.after; - normalize(spread); - previous = ⋚ + robust.push_back(Pokemon::RobustLeg{planned.leg.direction, planned.leg.tiles, planned.leg.ends_at_wall, planned.after}); } - return total; + return Pokemon::robust_legs_cost(RobustWorldModel(world), from, robust, robust_leg_costs(costs)); } From 7c954ac2f969097ae4bacd9776020f1e75223015 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:50:22 -0800 Subject: [PATCH 15/47] Pokemon Navigation: robust leg planner: document helpers; tests as input and expectation cases Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_RobustLegPlanner.h | 4 ++ .../Pokemon_RobustLegPlanner_Tests.cpp | 53 ++++++++++++++----- 2 files changed, 43 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h index c4bff5a757..882e422c7f 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h @@ -117,6 +117,7 @@ struct WallHit{ size_t tiles = 0; bool held = false; }; +// Walks `direction` from `from` until the player is stopped. template WallHit slide_to_wall(const Model& model, const typename Model::State& from, Direction direction){ WallHit hit{from}; @@ -141,6 +142,7 @@ struct Stepped{ int wander = 0; bool along_wander = false; }; +// Steps `from` up to `tiles` tiles `direction` (see Stepped). template std::optional> step_tiles(const Model& model, typename Model::State from, Direction direction, int tiles){ Stepped stepped{from}; @@ -168,12 +170,14 @@ std::optional> step_tiles(const Model& model, typ return stepped; } +// Sorts a spread and drops repeated places, so equal sets compare equal. template void normalize(std::vector& spread){ using State = typename Model::State; std::sort(spread.begin(), spread.end(), typename Model::StateLess()); spread.erase(std::unique(spread.begin(), spread.end(), [](const State& a, const State& b){ return a == b; }), spread.end()); } +// Orders spreads, for keeping them in a map. template struct SpreadLess{ bool operator()(const std::vector& a, const std::vector& b) const{ diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp index 7b5ab5dff6..f7b73b7234 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon_RobustLegPlanner.h" @@ -79,7 +80,7 @@ std::string describe(const std::optional& legs){ for (const RobustLeg& leg : *legs){ text += std::format("\n {} {}{} to", direction_name(leg.direction), leg.tiles, leg.to_wall ? " (to wall)" : " (open)"); for (const TilePos& pos : leg.after){ - text += " " + to_string(pos); + text += std::format(" {}", to_string(pos)); } } return text; @@ -104,7 +105,7 @@ UnitTestResult test_wall_gathers_spread(){ }); const auto legs = plan(game, {{0, 0}, {1, 0}}, {2, 0}, RobustLegCosts()); if (!legs || legs->size() != 1 || !(*legs)[0].to_wall || (*legs)[0].tiles != 2 || (*legs)[0].after != std::vector{{2, 0}}){ - return "Expected one leg east 2 to the wall:" + describe(legs); + return std::format("Expected one leg east 2 to the wall:{}", describe(legs)); } return true; } @@ -118,11 +119,11 @@ UnitTestResult test_open_leg_spreads(){ }); const auto uncertain = plan(game, {{0, 0}}, {3, 0}, RobustLegCosts()); if (uncertain){ - return "Expected no plan with uncertain open legs:" + describe(uncertain); + return std::format("Expected no plan with uncertain open legs:{}", describe(uncertain)); } const auto exact = plan(game, {{0, 0}}, {3, 0}, exact_costs()); if (!exact || exact->size() != 1 || (*exact)[0].to_wall || (*exact)[0].tiles != 3){ - return "Expected one open leg east 3:" + describe(exact); + return std::format("Expected one open leg east 3:{}", describe(exact)); } return true; } @@ -135,7 +136,7 @@ UnitTestResult test_door_is_not_a_wall(){ }); const auto legs = plan(game, {{1, 0}}, {2, 0}, exact_costs()); if (!legs || legs->size() != 1 || (*legs)[0].to_wall || (*legs)[0].tiles != 1){ - return "Expected one open leg east 1:" + describe(legs); + return std::format("Expected one open leg east 1:{}", describe(legs)); } return true; } @@ -153,7 +154,7 @@ UnitTestResult test_avoids_wander_run(){ } for (const RobustLeg& leg : *legs){ if (leg.direction == Direction::EAST && leg.after[0].y == 0){ - return "Walked east along the wander zone:" + describe(legs); + return std::format("Walked east along the wander zone:{}", describe(legs)); } } return true; @@ -178,19 +179,28 @@ UnitTestResult test_cost_of_plan(){ } -struct RobustLegPlannerTestCase{ +struct RobustLegPlannerInput{ std::string name; UnitTestResult (*test)(); }; +struct RobustLegPlannerExpectation{ + std::string_view description; +}; + +struct RobustLegPlannerTestCase{ + RobustLegPlannerInput input; + RobustLegPlannerExpectation expectation; +}; + class Test_RobustLegPlanner : public UnitTest{ public: explicit Test_RobustLegPlanner(RobustLegPlannerTestCase scenario) - : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.name)) + : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.input.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - return m_scenario.test(); + return m_scenario.input.test(); } private: @@ -198,11 +208,26 @@ class Test_RobustLegPlanner : public UnitTest{ }; const RobustLegPlannerTestCase ROBUST_LEG_PLANNER_CASES[] = { - {.name = "a wall gathers the possible tiles", .test = test_wall_gathers_spread}, - {.name = "an open leg may end a tile off", .test = test_open_leg_spreads}, - {.name = "a door is not a wall", .test = test_door_is_not_a_wall}, - {.name = "no leg along a wander zone", .test = test_avoids_wander_run}, - {.name = "cost of given legs", .test = test_cost_of_plan}, + { + .input = {.name = "a wall gathers the possible tiles", .test = test_wall_gathers_spread}, + .expectation = {.description = "a leg to a wall ends every possible start on one tile"}, + }, + { + .input = {.name = "an open leg may end a tile off", .test = test_open_leg_spreads}, + .expectation = {.description = "no plan ends on an open tile unless open legs are exact"}, + }, + { + .input = {.name = "a door is not a wall", .test = test_door_is_not_a_wall}, + .expectation = {.description = "a stop that does not hold the player is not a wall leg"}, + }, + { + .input = {.name = "no leg along a wander zone", .test = test_avoids_wander_run}, + .expectation = {.description = "goes round a row where someone wanders"}, + }, + { + .input = {.name = "cost of given legs", .test = test_cost_of_plan}, + .expectation = {.description = "charges a wall leg its tiles and an open leg its stop on top"}, + }, }; } // namespace From f47162539895a0087acde3022f21db439eba2c4f Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 21:00:48 -0800 Subject: [PATCH 16/47] BDSP AutoStory: 00.05c collects missing coupons and checks the Poketch; 01.01 checks it before the gate The clown talk confirms the coupon by its Yes/No box and skips tiles that face a sign or someone standing still. 00.05c starts from the sign or the street east (a step west tells them apart), re-talks the three clowns, and fails when no Poketch shows after the president. 01.01 fails at its start without the Poketch instead of fighting the east-exit guard. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_Actions_Tests.cpp | 28 ++++ .../Actions/PokemonBDSP_AutoStory_Events.h | 13 +- .../PokemonBDSP_AutoStory_Events_Jubilife.cpp | 142 ++++++++++++++++-- .../PokemonBDSP_AutoStory_StoryData.cpp | 5 +- ...onBDSP_AutoStory_SimFailureCases_Tests.cpp | 41 +++++ .../PokemonBDSP_AutoStory_StorySim.cpp | 26 +++- .../PokemonBDSP_AutoStory_StorySim.h | 17 +++ .../AutoStory/StoryData/bdsp-00.05c.plan.json | 116 ++++++++++++-- .../AutoStory/StoryData/bdsp-01.01.plan.json | 6 + 9 files changed, 363 insertions(+), 31 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp index f3e36035c9..7efb46838c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -21,6 +21,7 @@ #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Logging/Logger.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" @@ -468,6 +469,29 @@ UnitTestResult test_wander_row_step(Logger&){ return true; } +// 00.05b's Poketch Company clown (home (15, 18)): the row below him asks +// north from (14..16, 19); from a row low, (13, 20) faces the Company's +// sign (13, 19), whose text came first on the console (lab-B 2026-11-11: +// "answered" in round 5, and the president gave no Poketch). Such a tile +// is skipped; his own home and open tiles are not. +UnitTestResult test_asks_someone_else(Logger&){ + const Pokemon::MapData& city = story_map("JubilifeCity"); + const Pokemon::TilePos home{15, 18}; + struct Case{ std::string_view name; Pokemon::TilePos stand; bool expected; }; + const Case cases[] = { + {"below his home", {15, 19}, false}, + {"a tile west, open north", {14, 19}, false}, + {"a tile east, open north", {16, 19}, false}, + {"a row low, facing the sign", {13, 20}, true}, + }; + for (const Case& c : cases){ + if (asks_someone_else(city, c.stand, home) != c.expected){ + return std::format("{}: wrong answer.", c.name); + } + } + return true; +} + UnitTestResult test_choose_move(Logger&){ struct Case{ std::string_view name; std::vector slots; size_t best; }; const Case cases[] = { @@ -621,6 +645,10 @@ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { .input = {"wanderer talk: a step along the row leaves it only by a fade or a dialogue", test_wander_row_step}, .expectation = {}, }, + { + .input = {"wanderer talk: no ask from a tile that faces a sign (00.05b, the Poketch Company's sign first)", test_asks_someone_else}, + .expectation = {}, + }, { .input = {"battle moves: move menu screenshots in each language", test_move_menu_screenshots}, .expectation = {}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h index 63be0a09a5..acdf13258c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h @@ -9,7 +9,8 @@ * Dawn's catching tutorial and the catch); the rest do what the shared * steps cannot, as they ran on the console: the Poke Mart lady's Potions * and the stairs into Jubilife (00.04c, 00.04d), a clown who wanders - * (00.05b), the Gym's tries from the Pokemon Center (01.04) and Rock Smash + * (00.05b and 00.05c), the Poketch check (00.05c, 01.01), the Gym's + * tries from the Pokemon Center (01.04) and Rock Smash * (01.09). Each fails by throwing, with a screenshot; the executor turns * that into a failed step. * @@ -26,6 +27,8 @@ #include #include #include +#include +#include "Pokemon/Navigation/Pokemon_MapData.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" @@ -65,6 +68,14 @@ void add_route204_events(StoryEvents& events); // dialogue. 00.05c (2026-11-11): a step's fade went unread and the search // went on indoors, so the next checkpoint saved in the Poketch Company. std::optional wander_row_step(const WalkResult& result, int east); +// Whether asking north from `stand` on `map` would talk to a sign or to +// someone who stands still, not the wanderer whose home is +// `wanderer_home` (00.05b, lab-B 2026-11-11: the Poketch Company clown's +// talk was "answered" in round 5 by another line). +bool asks_someone_else(const Pokemon::MapData& map, Pokemon::TilePos stand, Pokemon::TilePos wanderer_home); +// The tiles 00.05c may start on: against the Poketch Company's sign +// (00.05b's end), and on the street east (its own end, 01.01's start). +std::pair jubilife_start_tiles(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp index 14afaa17f0..1c2fddba5c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp @@ -1,9 +1,9 @@ -/* BDSP AutoStory - Events: Jubilife City (00.05b) +/* BDSP AutoStory - Events: Jubilife City (00.05b, 00.05c, 01.01) * * From: https://github.com/PokemonAutomation/ * - * The Jubilife beat of 00.05b the story table cannot plan: the talk to a - * wandering clown. + * The Jubilife beats the story table cannot plan: the talk to a wandering + * clown, the check that the Poketch came, and where 00.05c starts. * */ @@ -12,8 +12,16 @@ #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTalk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" @@ -28,6 +36,7 @@ namespace PokemonBDSP{ using namespace std::chrono_literals; using Pokemon::Direction; +using Pokemon::TilePos; namespace{ @@ -36,8 +45,7 @@ namespace{ // row (the clowns by the Mart and the Poketch Company, WANDER_AROUND with // x range 1). Waiting under home alone missed him for a minute (r66: he // stood a tile east), so walk the row below his range, a whole D-pad tile -// at a time, asking north from each tile. His question's answer is Yes, so -// A answers and takes the coupon; then back under his home tile. +// at a time, asking north from each tile. bool ask_north(VideoStream& stream, ProControllerContext& context){ route_turn(stream, context, Direction::NORTH); for (size_t ask = 0; ask < 2; ask++){ @@ -50,6 +58,35 @@ bool ask_north(VideoStream& stream, ProControllerContext& context){ } return false; } +// A clown's talk is his question, then its Yes/No box: any dialog is not +// (00.05b, lab-B 2026-11-11: the Poketch Company clown was "answered" in +// round 5 by another line, and the president gave no Poketch). Press A +// until the box's cursor shows, then A for Yes and through the coupon. +// False when the talk ends with no box: someone or something else, or a +// clown who has given his coupon already. +bool answer_coupon_question(VideoStream& stream, ProControllerContext& context, const std::string& label){ + static const ImageFloatBox YES_NO_ARROW_BOX{0.700, 0.620, 0.070, 0.120}; + SelectionArrowFinder yes_no(stream.overlay(), YES_NO_ARROW_BOX, COLOR_GREEN); + for (size_t press = 0; press < 6; press++){ + context.wait_for(1200ms); + context.wait_for_all_requests(); + const VideoSnapshot screen = stream.video().snapshot(); + if (screen && yes_no.detect(*screen.frame)){ + stream.log("[Talk] " + label + ": the coupon question; Yes."); + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + finish_dialogue(stream, context, BUTTON_A, label); + return true; + } + if (!dialogue_opens(stream, context, 500ms)){ + stream.log("[Talk] " + label + ": the talk ended with no Yes/No box.", COLOR_ORANGE); + return false; + } + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + } + finish_dialogue(stream, context, BUTTON_B, label); + stream.log("[Talk] " + label + ": no Yes/No box in 6 presses.", COLOR_ORANGE); + return false; +} // One tile along the row, east (+1) or west (-1). Returns the tiles moved // east; fails the step when the walk left the row (wander_row_step()). int step_along(VideoStream& stream, ProControllerContext& context, int east, const std::string& label){ @@ -61,9 +98,32 @@ int step_along(VideoStream& stream, ProControllerContext& context, int east, con } return *moved; } +// Walks back below his home and faces north. +void back_below_home(VideoStream& stream, ProControllerContext& context, int at, const std::string& name){ + for (size_t tries = 0; at != 0 && tries < 4; tries++){ + at += step_along(stream, context, at > 0 ? -1 : 1, "Back below " + name + "'s home"); + } + if (at != 0){ + fail_step(stream, std::format("{}: still {} tiles east of his home after 4 steps back.", name, at)); + } + route_turn(stream, context, Direction::NORTH); +} +// The talk to a wanderer from the step's declared pose, below his home. +// With "again" (00.05c), a talk with no question counts too: he may have +// given his coupon before, and the Poketch check after the president +// catches a coupon that is still missing. Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep& step){ VideoStream& stream = executor.stream(); ProControllerContext& context = executor.context(); + const bool again = Pokemon::story_arg(step.args, "again"); + std::optional> home; + if (step.pose_after){ + const Pokemon::Pose below = Pokemon::pose_of(*step.pose_after); + const std::vector tiles = Pokemon::tiles_of(below); + if (!tiles.empty()){ + home.emplace(below.map, tiles[0]); + } + } const std::string label = "Along the row below " + step.name; // Home, east, west, west, east: each move one tile on the D-pad. const int moves[] = {0, 1, -1, -1, 1}; @@ -73,22 +133,54 @@ Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, c if (move != 0){ at += step_along(stream, context, move, label); } - if (!ask_north(stream, context)){ + if (home && asks_someone_else(story_map(home->first), {home->second.x + at, home->second.y}, home->second.next(Direction::NORTH))){ + stream.log(std::format("[Talk] {}: not asking from {} tiles east of home: a sign or someone else is north.", step.name, at)); continue; } - stream.log(std::format("[Talk] {}: answered in round {}, {} tiles east of home.", step.name, round + 1, at)); - finish_dialogue(stream, context, BUTTON_A, step.name); - for (size_t tries = 0; at != 0 && tries < 4; tries++){ - at += step_along(stream, context, at > 0 ? -1 : 1, "Back below " + step.name + "'s home"); + if (!ask_north(stream, context)){ + continue; } - if (at != 0){ - fail_step(stream, std::format("{}: still {} tiles east of his home after 4 steps back.", step.name, at)); + const bool coupon = answer_coupon_question(stream, context, step.name); + if (!coupon && !again){ + continue; } - route_turn(stream, context, Direction::NORTH); + stream.log(std::format("[Talk] {}: {} in round {}, {} tiles east of home.", + step.name, coupon ? "the coupon" : "talked, no question (his coupon given before)", round + 1, at)); + back_below_home(stream, context, at, step.name); return Pokemon::outcome_ok(); } } - fail_step(stream, step.name + ": no answer from any tile below his range."); + fail_step(stream, step.name + ": no coupon question from any tile below his range."); +} + +// 00.05c's end and 01.01's start: the Poketch shows on the screen's right +// (R toggles it). Without it, Jubilife's east-exit guard (the coord event +// on (60, 21..24)) asks about the Poketch campaign and turns us back. +void check_poketch(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + if (!ensure_poketch_visible(stream, context)){ + fail_step(stream, "No Poketch: the president gave none (a clown's coupon is missing?). " + "Jubilife's east-exit guard stops anyone without one: rerun 00.05c."); + } + stream.log("[Talk] The Poketch is on the screen."); +} + +// 00.05c starts against the Poketch Company's sign (14, 19) facing west +// (00.05b's end) or on the street east, (58, 22) facing east (its own end +// and 01.01's start, when a run gave no Poketch). A step west tells them +// apart: the sign blocks it, the street does not. +Pokemon::Outcome jubilife_start_probe(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep&){ + VideoStream& stream = executor.stream(); + ProControllerContext& context = executor.context(); + route_turn(stream, context, Direction::WEST); + const WalkResult result = walk_tiles_dpad(stream, context, run_from_wild_battle, {-1.0, 0}, 1, "00.05c start probe"); + const std::optional moved = wander_row_step(result, -1); + if (!moved){ + fail_step(stream, std::format("00.05c start probe: {} instead of a step west.", walk_stop_name(result.stop))); + } + const TilePos at = *moved == 0 ? jubilife_start_tiles().first : jubilife_start_tiles().second.next(Direction::WEST); + stream.log(std::format("[Talk] 00.05c starts {}: on {}.", *moved == 0 ? "at the Poketch Company's sign" : "on the street east", Pokemon::to_string(at))); + return Pokemon::outcome_ok(Pokemon::tile_pose("JubilifeCity", {at}, Direction::WEST)); } } // namespace @@ -104,8 +196,30 @@ std::optional wander_row_step(const WalkResult& result, int east){ } } +bool asks_someone_else(const Pokemon::MapData& map, TilePos stand, TilePos wanderer_home){ + const TilePos north = stand.next(Direction::NORTH); + if (north == wanderer_home || !map.tiles.contains(north)){ + return false; + } + if (map.tiles.at(north) == Pokemon::TileKind::SIGN){ + return true; + } + for (const Pokemon::MapObject& object : map.objects){ + if (!object.wander && object.x == north.x && object.y == north.y){ + return true; + } + } + return false; +} + +std::pair jubilife_start_tiles(){ + return {{14, 19}, {58, 22}}; +} + void add_jubilife_events(StoryEvents& events){ events.emplace("talk_to_wanderer", talk_to_wanderer); + events.emplace("check_poketch", console_event(check_poketch)); + events.emplace("jubilife_start_probe", jubilife_start_probe); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index 567cc3508c..a2b7712fa0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -85,7 +85,10 @@ std::vector make_bdsp_actions(){ .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = pins}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); - actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {}}); + const Pokemon::StoryArgSpec again = optional( + "again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts: he may have given it before" + ); + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {again}}); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp index 882756c124..1bef8f0629 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp @@ -415,6 +415,44 @@ UnitTestResult sandgem_entry_two_columns_west(Logger& logger){ return passes(run_case(logger, "00.04b", "00.04b", {.fade = {}, .banner = {}}, std::move(knobs))); } +// 00.05c on lab-B 2026-11-11: 00.05b's Poketch Company clown was +// "answered" by the sign's text, so the save held two coupons; the +// president gave no Poketch and 00.05c went on to the street as passed. +// `misread` re-runs that read in 00.05c's own talk too. "" when the run +// stopped at 00.05c's Poketch check, as it must when a coupon is still +// missing. +std::string poketch_run(Logger& logger, bool misread){ + SimWorldKnobs knobs; + knobs.coupons_at_start = {"mart_clown", "tv_clown"}; + knobs.poketch_at_start = false; + if (misread){ + knobs.talks_without_coupon = {"company_clown"}; + } + return run_case(logger, "00.05c", "00.05c", {.fade = {}, .banner = {}}, std::move(knobs)); +} +UnitTestResult no_poketch_fails_00_05c(Logger& logger){ + const std::string stopped = poketch_run(logger, true); + if (stopped.find("00.05c poketch") == std::string::npos){ + return UnitTestResult("expected a stop at 00.05c's Poketch check; got " + (stopped.empty() ? std::string("a pass") : stopped)); + } + return true; +} +UnitTestResult missing_coupon_collected_in_00_05c(Logger& logger){ + return passes(poketch_run(logger, false)); +} +// 01.01 from a save with no Poketch: Jubilife's east-exit guard would +// ask about the Poketch campaign and turn us back (lab-B 2026-11-11, the +// walk took him for a trainer); the row stops at its first step instead. +UnitTestResult gate_guard_stops_01_01(Logger& logger){ + SimWorldKnobs knobs; + knobs.poketch_at_start = false; + const std::string stopped = run_case(logger, "01.01", "01.01", {.fade = {}, .banner = {}}, std::move(knobs)); + if (stopped.find("01.01 poketch_before_the_gate") == std::string::npos){ + return UnitTestResult("expected a stop at 01.01's Poketch check; got " + (stopped.empty() ? std::string("a pass") : stopped)); + } + return true; +} + // 00.03: Rowan's scene ends at home on (6, 8) beside Mom (lab-B // 2026-11-09, 7 of 7 runs). The way out holds south onto the door's tile // (6, 10); from a column west, (5, 8), the hold stops on (5, 10) with no @@ -675,6 +713,9 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { {.input = {"00.04 Mom's call fires above the mat, on (6, 9): the walk ends in it, her hat scene plays it (lab-B 2026-11-09 17:29)", moms_call_above_the_mat}, .expectation = {}}, {.input = {"00.04 the old walk round Mom to (6, 9) runs into her call: it hands it to her hat scene, not fights it (lab-B 2026-11-09 17:29)", old_walk_hands_moms_call_over}, .expectation = {}}, {.input = {"00.04b the run into Sandgem stops two columns west: the walk still ends below the Center's door (lab-B 2026-11-09 20:09)", sandgem_entry_two_columns_west}, .expectation = {}}, + {.input = {"00.05c a coupon missing (the sign read for the Poketch Company clown): no Poketch, 00.05c fails (lab-B 2026-11-11)", no_poketch_fails_00_05c}, .expectation = {}}, + {.input = {"00.05c a coupon missing from 00.05b: its clown talks collect it, the president gives the Poketch", missing_coupon_collected_in_00_05c}, .expectation = {}}, + {.input = {"01.01 with no Poketch: the east-exit guard's gate stops the row at its check, not a trainer fight (lab-B 2026-11-11)", gate_guard_stops_01_01}, .expectation = {}}, {.input = {"00.04 to the ledge column with a wild battle on each pass through Route 201's grass (lab-B 2026-11-09 16:14)", [](Logger& logger){ return passes(ledge_walk_in_grass(logger, {})); }}, .expectation = {}}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index eed9a5836c..a82b32538d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -760,6 +760,24 @@ Outcome SimExecutor::stub(){ return Pokemon::outcome_ok(); } +Outcome SimExecutor::check_poketch(){ + if (!m_poketch){ + return Pokemon::outcome_failed("no_poketch", m_step + ": no Poketch on the screen."); + } + return Pokemon::outcome_ok(); +} + +void SimExecutor::count_coupons(const std::string& step){ + static const std::set CLOWNS{"mart_clown", "tv_clown", "company_clown"}; + if (CLOWNS.contains(step) && !m_knobs.talks_without_coupon.contains(step)){ + m_coupons.insert(step); + } + if (step == "president"){ + m_poketch = m_coupons.size() == CLOWNS.size(); + m_logger.log(std::format("[{}] president: {} coupons, {}.", m_row, m_coupons.size(), m_poketch ? "the Poketch" : "no Poketch")); + } +} + // The steps that need the console: stubbed, but for the Center's door and // the speeches after a battle. StoryBoundActions SimExecutor::sim_actions(){ @@ -778,7 +796,12 @@ StoryBoundActions SimExecutor::sim_actions(){ return heal(state, step); }, .save = stubbed, - .event = [stubbed](const std::string&) -> Pokemon::StoryActionFunction{ + .event = [this, stubbed](const std::string& name) -> Pokemon::StoryActionFunction{ + if (name == "check_poketch"){ + return [this](const StoryStep&, RunState&){ + return check_poketch(); + }; + } return stubbed; }, }; @@ -910,6 +933,7 @@ Outcome SimExecutor::run(const StoryStep& step, RunState& state){ } if (outcome.succeeded()){ land(step.name); + count_coupons(step.name); } m_logger.log(std::format("[{}] {}: {}, the player at {}.", m_row, step.name, Pokemon::to_string(outcome), to_string(m_sim.player().pos))); if (std::exchange(m_misses.missed, false) && m_result.missed_step.empty()){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index 0a8e5ac8e5..c7917ac392 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -192,6 +192,14 @@ struct SimWorldKnobs{ // its declared start: the program starts from the declared start, the // player from here (00.05, lab-B 2026-11-11: two tiles off). std::optional start_at = std::nullopt; + // Jubilife's coupons (00.05b, 00.05c): the clown talks, by step name, + // whose coupon the save holds at the run's start; the clown talks that + // read another line first and give none (lab-B 2026-11-11: the + // Poketch Company's sign); and whether the save has the Poketch. The + // president's talk gives it with all three coupons only. + std::set coupons_at_start = {"mart_clown", "tv_clown", "company_clown"}; + std::set talks_without_coupon = {}; + bool poketch_at_start = true; }; namespace detail{ @@ -438,6 +446,8 @@ class SimExecutor : public Pokemon::TableExecutor{ , m_walks(m_io) , m_table(story_action_table(m_walks, sim_actions())) , m_interrupts(story_interrupts([this](bool fresh){ return look(fresh); }, sim_interrupt_actions())) + , m_coupons(m_knobs.coupons_at_start) + , m_poketch(m_knobs.poketch_at_start) { if (m_knobs.clear_interrupts){ set_interrupts(&m_interrupts); @@ -496,6 +506,10 @@ class SimExecutor : public Pokemon::TableExecutor{ // A step the simulation does not play: its dialogue opened and closed. Pokemon::Outcome stub(); + // The Poketch on the screen, or the check's failure. + Pokemon::Outcome check_poketch(); + // A clown's coupon or the president's Poketch, after step `step` passed. + void count_coupons(const std::string& step); StoryBoundActions sim_actions(); // The screen between steps: the dialog that popped up, if one did; a // battle's opening, its battle on the OPENING_LOOKS-th look. `fresh` @@ -547,6 +561,9 @@ class SimExecutor : public Pokemon::TableExecutor{ mutable std::map, std::unique_ptr> m_peopled; // The steps of this row that have run. std::set m_ran; + // The clowns' coupons held and the Poketch (SimWorldKnobs::coupons_at_start). + std::set m_coupons; + bool m_poketch = true; std::string m_row; std::vector m_armed; // Where the step running now ends, if it says: a door's far side. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json index f05444f406..079c5c0c2a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json @@ -2,45 +2,127 @@ "checkpoint": { "events": [ { - "action": "line", + "action": "jubilife_start_probe", + "id": "where_we_start", + "kind": "game_action", + "why": "a step west: the Poketch Company's sign (14, 19) blocks it (00.05b's end); on the street (58, 22) it goes (a rerun from 01.01's start when no Poketch came)" + }, + { + "action": "town", "args": { "fight_wild": false, "target": { - "facing": "south", + "facing": "north", "map": "JubilifeCity", "tiles": [ [ 15, - 22 + 19 ] ] } }, - "id": "to_main_boulevard", + "id": "below_the_company_clown", "kind": "route", - "why": "south to the main boulevard" + "why": "below the Poketch Company's clown" }, { - "action": "line", + "action": "talk_to_wanderer", + "args": { + "again": true + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 15, + 19 + ] + ] + }, + "id": "company_clown", + "kind": "talk", + "why": "his coupon again, or his talk if he gave it (00.05b's, lab-B 2026-11-11: a coupon went missing)" + }, + { + "action": "town", "args": { "fight_wild": false, "target": { - "facing": "south", + "facing": "north", "map": "JubilifeCity", "tiles": [ [ - 45, - 22 + 36, + 17 ] ] } }, - "id": "along_main_boulevard", + "id": "below_the_tv_clown", "kind": "route", - "why": "east along the main boulevard" + "why": "east to the TV station" }, { - "action": "line", + "action": "talk_to_wanderer", + "args": { + "again": true + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 36, + 17 + ] + ] + }, + "id": "tv_clown", + "kind": "talk", + "why": "his coupon again, or his talk if he gave it" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 55, + 34 + ] + ] + } + }, + "id": "below_the_mart_clown", + "kind": "route", + "why": "east and south to the Mart's clown" + }, + { + "action": "talk_to_wanderer", + "args": { + "again": true + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 55, + 34 + ] + ] + }, + "id": "mart_clown", + "kind": "talk", + "why": "his coupon again, or his talk if he gave it" + }, + { + "action": "town", "args": { "fight_wild": false, "target": { @@ -56,7 +138,7 @@ }, "id": "beside_the_president", "kind": "route", - "why": "south down column 45 to the Poketch president" + "why": "west along row 34 to the Poketch president" }, { "id": "president", @@ -78,6 +160,12 @@ "kind": "scene", "why": "the coupons for the Poketch; he walks off north" }, + { + "action": "check_poketch", + "id": "poketch", + "kind": "game_action", + "why": "the Poketch on the screen (R): without it the president had too few coupons, and Jubilife's east-exit guard (60, 21..24) turns us back in 01.01" + }, { "action": "line", "args": { @@ -109,7 +197,7 @@ ] ] }, - "title": "Jubilife: the Poketch, up to the street east to Route 203" + "title": "Jubilife: the clowns' coupons again, the Poketch, up to the street east to Route 203" }, "execution": { "on_failure": "reload_and_retry", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json index e44f7cbc0b..5eed96c24f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json @@ -1,6 +1,12 @@ { "checkpoint": { "events": [ + { + "action": "check_poketch", + "id": "poketch_before_the_gate", + "kind": "game_action", + "why": "Jubilife's east-exit guard (the coord event on (60, 21..24)) asks about the Poketch campaign and turns back anyone without one (lab-B 2026-11-11): fail here, not in a walk that takes him for a trainer" + }, { "action": "town", "args": { From 0cfc9c1e1430fc0d1bce63d6c88b1b225c6d7483 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 21:08:09 -0800 Subject: [PATCH 17/47] BDSP AutoStory: shorter make_bdsp_actions and SimExecutor::run (code health) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonBDSP_AutoStory_StoryData.cpp | 5 +---- .../Simulation/PokemonBDSP_AutoStory_StorySim.cpp | 13 +++---------- .../Simulation/PokemonBDSP_AutoStory_StorySim.h | 5 ++--- 3 files changed, 6 insertions(+), 17 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index a2b7712fa0..d2d648528f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -85,10 +85,7 @@ std::vector make_bdsp_actions(){ .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = pins}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); - const Pokemon::StoryArgSpec again = optional( - "again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts: he may have given it before" - ); - actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {again}}); + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {optional("again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts")}}); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index a82b32538d..8d54670fc1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -648,6 +648,7 @@ void SimExecutor::start_scene_at_end(const StoryStep& step){ } void SimExecutor::land(const std::string& step){ + count_coupons(step); const auto lands = m_knobs.lands.find(step); if (lands == m_knobs.lands.end()){ return; @@ -760,13 +761,6 @@ Outcome SimExecutor::stub(){ return Pokemon::outcome_ok(); } -Outcome SimExecutor::check_poketch(){ - if (!m_poketch){ - return Pokemon::outcome_failed("no_poketch", m_step + ": no Poketch on the screen."); - } - return Pokemon::outcome_ok(); -} - void SimExecutor::count_coupons(const std::string& step){ static const std::set CLOWNS{"mart_clown", "tv_clown", "company_clown"}; if (CLOWNS.contains(step) && !m_knobs.talks_without_coupon.contains(step)){ @@ -798,8 +792,8 @@ StoryBoundActions SimExecutor::sim_actions(){ .save = stubbed, .event = [this, stubbed](const std::string& name) -> Pokemon::StoryActionFunction{ if (name == "check_poketch"){ - return [this](const StoryStep&, RunState&){ - return check_poketch(); + return [this](const StoryStep& step, RunState&){ + return m_poketch ? Pokemon::outcome_ok() : Pokemon::outcome_failed("no_poketch", step.name + ": no Poketch on the screen."); }; } return stubbed; @@ -933,7 +927,6 @@ Outcome SimExecutor::run(const StoryStep& step, RunState& state){ } if (outcome.succeeded()){ land(step.name); - count_coupons(step.name); } m_logger.log(std::format("[{}] {}: {}, the player at {}.", m_row, step.name, Pokemon::to_string(outcome), to_string(m_sim.player().pos))); if (std::exchange(m_misses.missed, false) && m_result.missed_step.empty()){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index c7917ac392..0d1cb7e5ee 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -506,8 +506,6 @@ class SimExecutor : public Pokemon::TableExecutor{ // A step the simulation does not play: its dialogue opened and closed. Pokemon::Outcome stub(); - // The Poketch on the screen, or the check's failure. - Pokemon::Outcome check_poketch(); // A clown's coupon or the president's Poketch, after step `step` passed. void count_coupons(const std::string& step); StoryBoundActions sim_actions(); @@ -525,7 +523,8 @@ class SimExecutor : public Pokemon::TableExecutor{ bool sync(const Pokemon::Pose& pose, const StoryWorld* on = nullptr); // Puts a trigger on walk `step`'s last tiles (SimWorldKnobs::scene_at_walk_end). void start_scene_at_end(const Pokemon::StoryStep& step); - // Puts the player where SimWorldKnobs::lands says `step` leaves them, if it says. + // Puts the player where SimWorldKnobs::lands says `step` leaves them, if + // it says, and counts its coupon or Poketch (count_coupons()). void land(const std::string& step); bool cross(); bool cross_to(const Pokemon::Pose& far); From c567cbb3e31028cd1a270e5ad49914f23a00a6c4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 21:49:32 -0800 Subject: [PATCH 18/47] BDSP AutoStory: Jubilife routes keep out of wander zones; a held-up wall leg is not at its wall Console 2026-11-11 21:00, 00.05b below_the_mart_clown: "east 8 (to wall)" along row 34 crossed the column the boy below the Mart wanders (51, 33..35), stopped against him after 2800 ms about 5 tiles in, and the time count (17 tiles) passed it as the wall at (56, 34). - town_plan_costs() charges 15 a wander tile (was 3): the walk now goes north to row 36, east to the wall (56, 36) and up to (55, 34). plan_fastest_route() keeps a plan with those costs that enters no zone. - A wall leg whose first walk took far longer than its tiles is held up, not at its wall: it plans again from every tile of the leg. - Sim: SimWorldKnobs::standing and pushing_someone; tests for the boy on row 34 and someone on row 36 (red before the fix), a scripted held-up leg, and a story-table check that no 00.05b/00.05c leg enters a zone. - talk_to_wanderer leaves its declared tile (counted taps), the 00.05c start probe pins its tile; known certainty gaps updated (renumbered 00.05c step 12, 01.01 step 2). The chain test keeps the pose through check_poketch and the probe. 01.08's youngster case passes now. Goldens regenerated on lab/dev-bdsp. Route bench updated (PA_UPDATE_ROUTE_BENCH=1): 00.05b below_the_tv_clown 21463 -> 23700 ms and 01.08 below_the_ravaged_path worst 25150 -> 26950 ms, because both now go round a wander zone (the boy below the Mart; Route 204's youngster) instead of through it; 00.05c beside_the_president 10500 -> 6800 ms. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_PlanCosts.cpp | 6 + .../AutoStory/Data/route_bench.golden.txt | 18 ++- .../AutoStory/Data/route_plans.golden.txt | 122 +++++++++++++----- ...kemonBDSP_AutoStory_PlannedRoute_Tests.cpp | 33 +++++ .../PokemonBDSP_AutoStory_StoryData.cpp | 15 ++- ...PokemonBDSP_AutoStory_StoryTable_Tests.cpp | 35 +++++ ...PokemonBDSP_AutoStory_FaultSweep_Tests.cpp | 6 +- ...onBDSP_AutoStory_SimFailureCases_Tests.cpp | 21 ++- .../PokemonBDSP_AutoStory_StorySim.cpp | 25 +++- .../PokemonBDSP_AutoStory_StorySim.h | 10 ++ ...onBDSP_AutoStory_StorySimulation_Tests.cpp | 7 + .../PokemonBDSP_AutoStory_PlannedRoute.cpp | 43 ++++++ .../PokemonBDSP_AutoStory_RouteChoice.cpp | 31 +++++ 13 files changed, 318 insertions(+), 54 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp index fed0c55f4c..3c6e96be0e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -38,6 +38,12 @@ RobustPlanCosts town_plan_costs(){ costs.exact_open_tiles = costs.max_open_tiles; costs.per_open_tile = 1; costs.leg_not_at_wall = 4; + // A detour of a few tiles round a zone where someone wanders beats + // crossing it: at 3, 00.05b's walk to the Mart clown ran east along + // row 34 through the column a boy wanders (51, 33..35), and he stopped + // it 3 tiles short of its wall (lab-B 2026-11-11 21:00); row 36, below + // his zone, is 9 dearer. + costs.per_wander_tile = 15; return costs; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt index 8709980adc..c67197124c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt @@ -19,6 +19,7 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.01 above_the_door | 7230 | 7230 | 7230 | 1 | 0 | 0 | 4.66! | 1.00 | 1.00 | 1550 ms (stand-in) | PASS 00.01 short_of_barrys_door | 11950 | 11950 | 11950 | 1 | 0 | 0 | 4.35! | 1.00 | 1.00 | 2750 ms (stand-in) | PASS 00.01 above_barrys_door | 7230 | 7230 | 7230 | 1 | 0 | 0 | 4.66! | 1.00 | 1.00 | 1550 ms (stand-in) | PASS +00.02 to_the_lake_entrance | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS 00.03 into_rowans_scene | 3030 | 3030 | 3030 | 1 | 0 | 0 | 2.33! | 1.00 | 1.00 | 1300 ms (stand-in) | PASS 00.03 into_dawns_scene | 61510 | 46690 | 34340 | 4 | 22 | 0 | 5.37! | 1.15 | 56.00! | 11450 ms (stand-in) | PASS 00.04 onto_the_path | 4050 | 4050 | 4050 | 2 | 0 | 0 | 5.79! | 1.00 | 1.00 | 700 ms (stand-in) | PASS @@ -32,15 +33,19 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.04b to_catch_grass | 11689 | 38550 | 6300 | 2 | 34 | 1 | 17.98! | 17.50! | 2.00! | 650 ms (stand-in) | PASS 00.04b into_sandgem | 9520 | 19400 | 7050 | 3 | 12 | 0 | 2.93! | 4.33! | 1.00 | 3250 ms (stand-in) | PASS 00.04d north_to_jubilife | 73575 | 42700 | 30350 | 8 | 35 | 0 | 7.21! | 1.24 | 80.00! | 10200 ms (stand-in) | PASS -00.05 to_the_school | 9700 | 9700 | 9700 | 0 | 0 | 0 | 6.69! | 1.00 | 1.00 | 1450 ms (stand-in) | PASS 00.05b below_the_presidents_trigger | 4900 | 4900 | 4900 | 0 | 0 | 0 | 5.76! | 1.00 | 1.00 | 850 ms (stand-in) | PASS -00.05b below_the_tv_clown | 21463 | 23600 | 20750 | 1 | 1 | 0 | 4.57! | 2.00! | 5.00! | 4700 ms (stand-in) | PASS +00.05b past_the_president | 1700 | 1700 | 1700 | 0 | 0 | 0 | 3.78! | 1.00 | 1.00 | 450 ms (stand-in) | PASS +00.05b below_the_mart_clown | 8050 | 8050 | 8050 | 1 | 0 | 0 | 4.35! | 1.00 | 1.00 | 1850 ms (stand-in) | PASS +00.05b below_the_tv_clown | 23700 | 23700 | 23700 | 3 | 0 | 0 | 5.04! | 1.00 | 29.00! | 4700 ms (stand-in) | PASS 00.05b below_the_company_clown | 21900 | 21900 | 21900 | 0 | 0 | 0 | 6.74! | 1.00 | 3.00! | 3250 ms (stand-in) | PASS -00.05c to_main_boulevard | 2500 | 2500 | 2500 | 0 | 0 | 0 | 3.57! | 1.00 | 1.00 | 700 ms (stand-in) | PASS -00.05c along_main_boulevard | 24100 | 24100 | 24100 | 0 | 0 | 0 | 7.42! | 1.00 | 1.00 | 3250 ms (stand-in) | PASS -00.05c beside_the_president | 10500 | 10500 | 10500 | 0 | 0 | 0 | 4.77! | 1.00 | 1.00 | 2200 ms (stand-in) | PASS +00.05b beside_the_company_sign | 1450 | 1450 | 1450 | 1 | 0 | 0 | 4.14! | 1.00 | 1.00 | 350 ms (stand-in) | PASS +00.05c below_the_company_clown | 900 | 900 | 900 | 0 | 0 | 0 | 2.57! | 1.00 | 1.00 | 350 ms (stand-in) | PASS +00.05c below_the_tv_clown | 21900 | 21900 | 21900 | 0 | 0 | 0 | 6.74! | 1.00 | 5.00! | 3250 ms (stand-in) | PASS +00.05c below_the_mart_clown | 15250 | 15250 | 15250 | 3 | 0 | 0 | 3.24! | 1.00 | 23.00! | 4700 ms (stand-in) | PASS +00.05c beside_the_president | 6800 | 6800 | 6800 | 2 | 0 | 0 | 4.00! | 1.00 | 2.00! | 1700 ms (stand-in) | PASS 00.05c to_the_route_203_street | 21000 | 21000 | 21000 | 0 | 0 | 0 | 6.00! | 1.00 | 1.00 | 3500 ms (stand-in) | PASS 01.01 west_of_barrys_trigger | 7300 | 7300 | 7300 | 0 | 0 | 0 | 6.35! | 1.00 | 1.00 | 1150 ms (stand-in) | PASS +01.02 south_to_the_cliff | 1800 | 1800 | 1800 | 1 | 0 | 0 | 2.57! | 1.00 | 1.00 | 700 ms (stand-in) | PASS 01.02 by_the_gate | 24815 | 26050 | 13700 | 2 | 9 | 0 | 3.60! | 1.00 | 1.00 | 6900 ms (stand-in) | PASS 01.02 west_of_the_hikers_trigger | 3950 | 3950 | 3950 | 2 | 0 | 0 | 8.78! | 1.00 | 2.00! | 450 ms (stand-in) | PASS 01.02 past_curtis | 10500 | 10500 | 10500 | 0 | 0 | 0 | 6.77! | 1.00 | 1.00 | 1550 ms (stand-in) | PASS @@ -52,7 +57,8 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 01.05 through_the_gate | 12050 | 12050 | 12050 | 5 | 0 | 0 | 4.92! | 1.00 | 27.00! | 2450 ms (stand-in) | PASS 01.06 up_jubilifes_road | 87286 | 119950 | 58350 | 3 | 10 | 4 | 7.66! | 2.20! | 20.00! | 11400 ms (stand-in) | PASS 01.06 below_rowans_trigger | 1950 | 1950 | 1950 | 1 | 0 | 0 | 2.29! | 1.00 | 1.00 | 850 ms (stand-in) | PASS -01.08 below_the_ravaged_path | 27098 | 25150 | 12800 | 3 | 12 | 0 | 4.52! | 1.30 | 4.00! | 6000 ms (stand-in) | PASS +01.08 west_to_the_wall | 1650 | 1650 | 1650 | 1 | 0 | 0 | 3.00! | 1.00 | 1.00 | 550 ms (stand-in) | PASS +01.08 below_the_ravaged_path | 25715 | 26950 | 14600 | 2 | 9 | 0 | 4.29! | 1.00 | 6.00! | 6000 ms (stand-in) | PASS 01.09 west_of_the_rock | 7050 | 7050 | 7050 | 1 | 0 | 0 | 4.70! | 1.00 | 1.00 | 1500 ms (stand-in) | PASS 01.09 above_the_way_out | 4550 | 4550 | 4550 | 2 | 0 | 0 | 4.14! | 1.00 | 2.00! | 1100 ms (stand-in) | PASS 01.10 line_1 | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt index fbc8c921ee..63d3db3e93 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt @@ -57,6 +57,13 @@ anchor); 0 from one start tile. target: VerityLakefront (17, 14) facing north (tile) not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) +== 00.02 to_the_lake_entrance (costs: route) + from: VerityLakefront (17, 14) facing north (tile) + target: VerityLakefront (17, 13) facing north (tile) + start candidates: Verity Lakefront (17, 14) + 1. north 1 (open) -> Verity Lakefront (17, 13) + totals: 1 legs, 0 turns, 1 open, 0 localization + == 00.03 into_rowans_scene (costs: into_scene) from: VerityLakefront (17, 14) (17, 15) (set) target: VerityLakefront (17, 21) (tile) @@ -189,17 +196,10 @@ anchor); 0 from one start tile. 12. north 1 (open) -> Route 202 (18, 3) totals: 12 legs, 11 turns, 4 open, 0 localization -== 00.05 to_the_center (costs: town) - from: unknown - target: JubilifeCity (52, 41) facing north (tile) - not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) - == 00.05 to_the_school (costs: town) - from: JubilifeCity (52, 41) facing north (tile) + from: unknown target: JubilifeCity (40, 41) facing north (tile) - start candidates: Jubilife City (52, 41) - 1. west 12 (open) -> Jubilife City (40, 41) - totals: 1 legs, 0 turns, 1 open, 0 localization + not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) == 00.05b below_the_presidents_trigger (costs: town) from: JubilifeCity (40, 41) facing south (tile) @@ -208,20 +208,34 @@ anchor); 0 from one start tile. 1. east 6 (open) -> Jubilife City (46, 41) totals: 1 legs, 0 turns, 1 open, 0 localization +== 00.05b past_the_president (costs: route) + from: JubilifeCity (46, 40) facing north (tile) + target: JubilifeCity (48, 40) facing east (tile) + start candidates: Jubilife City (46, 40) + 1. east 2 (open) -> Jubilife City (48, 40) + totals: 1 legs, 0 turns, 1 open, 0 localization + == 00.05b below_the_mart_clown (costs: town) - from: unknown + from: JubilifeCity (48, 40) facing east (tile) target: JubilifeCity (55, 34) facing north (tile) - not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) + start candidates: Jubilife City (48, 40) + 1. north 4 (open) -> Jubilife City (48, 36) + 2. east 8 (to wall) -> Jubilife City (56, 36) + 3. west 1 (open) -> Jubilife City (55, 36) + 4. north 2 (open) -> Jubilife City (55, 34) + totals: 4 legs, 3 turns, 3 open, 0 localization == 00.05b below_the_tv_clown (costs: town) from: JubilifeCity (55, 34) facing north (tile) target: JubilifeCity (36, 17) facing north (tile) start candidates: Jubilife City (55, 34) - 1. west 23 (to wall) -> Jubilife City (32, 34) - 2. north 10 (open) -> Jubilife City (32, 24) - 3. east 4 (open) -> Jubilife City (36, 24) - 4. north 7 (open) -> Jubilife City (36, 17) - totals: 4 legs, 3 turns, 3 open, 0 localization + 1. south 2 (to wall) -> Jubilife City (55, 36) + 2. west 12 (to wall) -> Jubilife City (43, 36) + 3. north 7 (to wall) -> Jubilife City (43, 29) + 4. east 1 (open) -> Jubilife City (44, 29) + 5. north 12 (open) -> Jubilife City (44, 17) + 6. west 8 (open) -> Jubilife City (36, 17) + totals: 6 legs, 5 turns, 3 open, 0 localization == 00.05b below_the_company_clown (costs: town) from: JubilifeCity (36, 17) facing north (tile) @@ -232,26 +246,51 @@ anchor); 0 from one start tile. 3. north 2 (open) -> Jubilife City (15, 19) totals: 3 legs, 2 turns, 3 open, 0 localization -== 00.05c to_main_boulevard (costs: line) +== 00.05b beside_the_company_sign (costs: line) from: JubilifeCity (15, 19) facing north (tile) - target: JubilifeCity (15, 22) facing south (tile) + target: JubilifeCity (14, 19) facing west (tile) start candidates: Jubilife City (15, 19) - 1. south 3 (open) -> Jubilife City (15, 22) - totals: 1 legs, 0 turns, 1 open, 0 localization + 1. west 1 (to wall) -> Jubilife City (14, 19) + totals: 1 legs, 0 turns, 0 open, 0 localization -== 00.05c along_main_boulevard (costs: line) - from: JubilifeCity (15, 22) facing south (tile) - target: JubilifeCity (45, 22) facing south (tile) - start candidates: Jubilife City (15, 22) - 1. east 30 (open) -> Jubilife City (45, 22) +== 00.05c below_the_company_clown (costs: town) + from: JubilifeCity (14, 19) facing west (tile) + target: JubilifeCity (15, 19) facing north (tile) + start candidates: Jubilife City (14, 19) + 1. east 1 (open) -> Jubilife City (15, 19) totals: 1 legs, 0 turns, 1 open, 0 localization -== 00.05c beside_the_president (costs: line) - from: JubilifeCity (45, 22) facing south (tile) +== 00.05c below_the_tv_clown (costs: town) + from: JubilifeCity (15, 19) facing north (tile) + target: JubilifeCity (36, 17) facing north (tile) + start candidates: Jubilife City (15, 19) + 1. south 2 (open) -> Jubilife City (15, 21) + 2. east 21 (open) -> Jubilife City (36, 21) + 3. north 4 (open) -> Jubilife City (36, 17) + totals: 3 legs, 2 turns, 3 open, 0 localization + +== 00.05c below_the_mart_clown (costs: town) + from: JubilifeCity (36, 17) facing north (tile) + target: JubilifeCity (55, 34) facing north (tile) + start candidates: Jubilife City (36, 17) + 1. west 1 (open) -> Jubilife City (35, 17) + 2. south 10 (to wall) -> Jubilife City (35, 27) + 3. east 1 (to wall) -> Jubilife City (36, 27) + 4. south 5 (open) -> Jubilife City (36, 32) + 5. east 20 (to wall) -> Jubilife City (56, 32) + 6. south 2 (open) -> Jubilife City (56, 34) + 7. west 1 (open) -> Jubilife City (55, 34) + totals: 7 legs, 6 turns, 4 open, 0 localization + +== 00.05c beside_the_president (costs: town) + from: JubilifeCity (55, 34) facing north (tile) target: JubilifeCity (45, 35) facing east (tile) - start candidates: Jubilife City (45, 22) - 1. south 13 (open) -> Jubilife City (45, 35) - totals: 1 legs, 0 turns, 1 open, 0 localization + start candidates: Jubilife City (55, 34) + 1. south 2 (to wall) -> Jubilife City (55, 36) + 2. west 12 (to wall) -> Jubilife City (43, 36) + 3. east 2 (open) -> Jubilife City (45, 36) + 4. north 1 (open) -> Jubilife City (45, 35) + totals: 4 legs, 3 turns, 2 open, 0 localization == 00.05c to_the_route_203_street (costs: line) from: JubilifeCity (45, 35) facing east (tile) @@ -268,6 +307,13 @@ anchor); 0 from one start tile. 1. east 9 (open) -> Route 203 (4, 18) totals: 1 legs, 0 turns, 1 open, 0 localization +== 01.02 south_to_the_cliff (costs: route) + from: Route203 (5, 17) (5, 18) (5, 19) (5, 20) facing east (set) + target: Route203 (5, 20) facing south (tile) + start candidates: Route 203 (5, 17), Route 203 (5, 18), Route 203 (5, 19), Route 203 (5, 20) + 1. south 3 (to wall) -> Route 203 (5, 20) + totals: 1 legs, 0 turns, 0 open, 1 localization + == 01.02 by_the_gate (costs: route) from: Route203 (5, 20) facing south (tile) target: Route203 (55, 9) facing east (tile) @@ -374,16 +420,24 @@ anchor); 0 from one start tile. 1. east 6 (to wall) -> Jubilife City (47, 8) totals: 1 legs, 0 turns, 0 open, 0 localization +== 01.08 west_to_the_wall (costs: route) + from: JubilifeCity (46, 5) (47, 5) (set) + target: JubilifeCity (44, 5) facing west (tile) + start candidates: Jubilife City (46, 5), Jubilife City (47, 5) + 1. west 3 (to wall) -> Jubilife City (44, 5) + totals: 1 legs, 0 turns, 0 open, 1 localization + == 01.08 below_the_ravaged_path (costs: town) from: JubilifeCity (44, 5) facing west (tile) target: Route204South (11, 2) facing north (tile) start candidates: Jubilife City (44, 5) 1. east 2 (open) -> Jubilife City (46, 5) 2. north 19 (to wall) -> Route 204 (14, 18) - 3. west 2 (open) -> Route 204 (12, 18) - 4. north 16 (to wall) -> Route 204 (12, 2) - 5. west 1 (to wall) -> Route 204 (11, 2) - totals: 5 legs, 4 turns, 2 open, 0 localization + 3. west 4 (open) -> Route 204 (10, 18) + 4. north 15 (to wall) -> Route 204 (10, 3) + 5. east 1 (open) -> Route 204 (11, 3) + 6. north 1 (open) -> Route 204 (11, 2) + totals: 6 legs, 5 turns, 4 open, 0 localization == 01.09 west_of_the_rock (costs: route) from: RavagedPath (19, 50) facing north (tile) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp index 1808129ee5..869b9f26bf 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp @@ -519,6 +519,35 @@ UnitTestResult test_short_leg_a_tile_short_is_not_arrived(Logger&){ } +// A leg to a wall 8 tiles away that stops far later than 8 tiles take: the +// player pushed against someone on the way, and the time counts 18 tiles +// (lab-B 2026-11-11 21:00, 00.05b: "east 8 (to wall)" stopped after +// 2800 ms against the boy below the Mart, about 5 tiles in, and the route +// went on from the wall). Not the wall: plan again from every tile of the +// leg, and a second leg to the wall pins it. +UnitTestResult test_wall_leg_held_up_is_not_at_its_wall(Logger&){ + const StoryWorld corridor = make_world({"###########", "#.........#", "###########"}); + Script script{.steps = { + walk_step("wall: T: east 8 (to wall)", WalkStop::BLOCKED, 3930ms, 5), + walk_step("wall: T: east 7 (to wall)", WalkStop::BLOCKED, 1450ms, 1), + answer_step("dialog within 500 ms", false), + }}; + ScriptedWalk walk; + try{ + walk = walk_script(corridor, {1, 1}, {9, 1}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (!walk.failure.empty()){ + return "failed: " + walk.failure; + } + if (walk.at != std::vector{{9, 1}}){ + return "did not arrive at (9, 1)."; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + struct PlannedRouteInput{ std::string name; std::function body; @@ -703,6 +732,10 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .input = {"a wall leg that never moved plans from its start", test_never_moved_plans_from_the_start}, .expectation = {}, }, + { + .input = {"a wall leg held up on the way is not at its wall (lab-B 2026-11-11 21:00)", test_wall_leg_held_up_is_not_at_its_wall}, + .expectation = {}, + }, { .input = {"Jubilife Center with every timed hold overshooting", test_jubilife_center_held_overshoot}, .expectation = {}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index d2d648528f..7a58c59612 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -31,7 +31,14 @@ Pokemon::StoryArgSpec optional(std::string key, Pokemon::StoryArgType type, Poke void add_event_actions(std::vector& actions){ for (const auto& [name, unused] : story_events()){ - actions.push_back({.kind = Pokemon::StoryStepKind::GAME, .name = name, .args = {}}); + Pokemon::StoryActionSpec spec{.kind = Pokemon::StoryStepKind::GAME, .name = name, .args = {}}; + // 00.05c's start probe steps west from either save it may start on: + // the Poketch Company's sign stops it, the street does not, so it + // ends on one tile it knows. + if (name == "jubilife_start_probe"){ + spec.certainty = Pokemon::StoryCertainty{.needs = Pokemon::PoseCertainty::SET, .leaves = Pokemon::PoseEnd::WALKED}; + } + actions.push_back(std::move(spec)); } } @@ -85,7 +92,11 @@ std::vector make_bdsp_actions(){ .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = pins}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); - actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {optional("again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts")}}); + // The talk walks the row in D-pad taps, each a whole tile it counts, + // and back onto its declared tile. + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", + .args = {optional("again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts")}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::TILE, .leaves = PoseEnd::DECLARED}}); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp index a48158f2ca..c319a93dcc 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -407,6 +407,37 @@ UnitTestResult test_story_routes_keep_off_wander_zones(Logger& logger){ return out.empty() ? UnitTestResult(true) : UnitTestResult("ROUTE steps:" + out); } +// No leg of 00.05b's or 00.05c's routes enters a tile where someone +// wanders, from any tile the player may be on: on lab-B (2026-11-11 21:00) +// the boy below the Mart (51, 33..35) stopped 00.05b's "east 8 (to wall)" +// along row 34 three tiles short; row 36 below him is open. +UnitTestResult test_jubilife_routes_cross_no_wander_zone(Logger& logger){ + std::string out; + size_t checked = 0; + for (const PlannedStoryRoute& route : plan_story_routes(logger)){ + if (!route.name.starts_with("00.05b ") && !route.name.starts_with("00.05c ")){ + continue; + } + if (!route.legs){ + out += "\n " + route.name + ": no plan."; + continue; + } + checked++; + const StoryWorld& world = *route.world; + const auto [most, leg] = most_zone_tiles(world, route.from, *route.legs, [&](const TilePos& pos){ + return wandering_hazard(world, pos); + }); + if (most > 0){ + out += std::format("\n {}: {} enters {} tile(s) where someone wanders.", route.name, leg, most); + } + } + logger.log(std::format("{} Jubilife routes checked.", checked)); + if (checked == 0){ + return "No 00.05b or 00.05c route planned from a known place."; + } + return out.empty() ? UnitTestResult(true) : UnitTestResult("ROUTE steps:" + out); +} + // 01.08's walk below the Ravaged Path keeps off the row Route 204 South's // youngster_3 wanders, (12, 2) to (14, 2): on lab-B (2026-11-08) the plan // "north 35 (to wall) to (13, 2), west 2 (to wall) to (11, 2)" walked along @@ -681,6 +712,10 @@ const AutoStoryStoryTableCase AUTO_STORY_STORY_TABLE_CASES[] = { .input = {"01.08: the walk below the Ravaged Path keeps off the youngster's row (lab-B, 2026-11-08)", test_ravaged_path_keeps_off_the_youngster}, .expectation = {}, }, + { + .input = {"00.05b, 00.05c: no leg enters a wander zone (lab-B, 2026-11-11)", test_jubilife_routes_cross_no_wander_zone}, + .expectation = {}, + }, }; void add_tests_AutoStory_StoryTable(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp index 3c4b82d57f..810a6254b7 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp @@ -163,10 +163,8 @@ const std::set KNOWN_CERTAINTY_GAPS{ "00.05b step 1 below_the_presidents_trigger: needs tile, has set", "00.05b step 10 below_the_company_clown: needs tile, has set", "00.05b step 4 past_the_president: needs tile, has set", - "00.05b step 7 below_the_tv_clown: needs tile, has set", - "00.05c step 1 to_main_boulevard: needs tile, has set", - "00.05c step 6 to_the_route_203_street: needs tile, has set", - "01.01 step 1 west_of_barrys_trigger: needs tile, has set", + "00.05c step 12 to_the_route_203_street: needs tile, has set", + "01.01 step 2 west_of_barrys_trigger: needs tile, has set", "01.02 step 1 south_to_the_cliff: needs tile, has set", "01.02 step 10 west_of_the_welcome: needs tile, has set", "01.02 step 4 west_of_the_hikers_trigger: needs tile, has set", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp index 1bef8f0629..619aeeb74a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp @@ -61,7 +61,6 @@ const std::map KNOWN_FAILING{ {"01.05 through_the_gate is one run west", "planner: goal kinds and ms costs (PLANNER_DESIGN.md)"}, {"any one missed fade or banner from 00.00 to 01.11: every row still passes", "a third signal where a warp gives one (ONE_SIGNAL_STEPS): position (PLANNER_DESIGN.md 2, 4)"}, - {"01.08 with Route 204's youngster wandering (12..14, 2)", "planner: one recovery rule, a sidestep round a wanderer (PLANNER_DESIGN.md 4, 7)"}, }; // Warps that give one signal only (#268 slice 1: door = fade or banner), so @@ -330,6 +329,18 @@ UnitTestResult nurse_in_one_run(Logger&){ return true; } +// 00.05b with the boy below the Mart (school_kid_m_5, who wanders x 51, +// y 33..35) standing on (51, `row`), and a push against him reading as +// stopped only 1600 ms late, as on lab-B 2026-11-11 21:00 ("east 8 (to +// wall)" along row 34 stopped after 2800 ms about 5 tiles in, and the +// route went on from the wall). +std::string boy_below_the_mart(Logger& logger, int row){ + SimWorldKnobs knobs; + knobs.standing = {{"school_kid_m_5", TilePos{51, row}}}; + knobs.pushing_someone = 1600ms; + return run_case(logger, "00.05b", "00.05b", {.fade = {}, .banner = {}}, std::move(knobs)); +} + // 01.07: after the tag battle the screen fades back from the battle and // the grunts run off before anyone speaks: a scene that opens with no box, // 6 s of people moving (Rowan's cutscene shape), then Rowan's and Dawn's @@ -713,6 +724,14 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { {.input = {"00.04 Mom's call fires above the mat, on (6, 9): the walk ends in it, her hat scene plays it (lab-B 2026-11-09 17:29)", moms_call_above_the_mat}, .expectation = {}}, {.input = {"00.04 the old walk round Mom to (6, 9) runs into her call: it hands it to her hat scene, not fights it (lab-B 2026-11-09 17:29)", old_walk_hands_moms_call_over}, .expectation = {}}, {.input = {"00.04b the run into Sandgem stops two columns west: the walk still ends below the Center's door (lab-B 2026-11-09 20:09)", sandgem_entry_two_columns_west}, .expectation = {}}, + {.input = {"00.05b the boy below the Mart stands on row 34: the walk to the Mart clown goes round his zone (lab-B 2026-11-11 21:00)", [](Logger& logger){ + return passes(boy_below_the_mart(logger, 34)); + }}, .expectation = {}}, + {.input = {"00.05b someone stands in the walk's way on row 36: a wall leg held up is not at its wall (lab-B 2026-11-11 21:00)", [](Logger& logger){ + const std::string stopped = boy_below_the_mart(logger, 36); + return stopped.find("sim_mismatch") == std::string::npos ? UnitTestResult(true) + : UnitTestResult("the program went on from a tile the player is not on: " + stopped); + }}, .expectation = {}}, {.input = {"00.05c a coupon missing (the sign read for the Poketch Company clown): no Poketch, 00.05c fails (lab-B 2026-11-11)", no_poketch_fails_00_05c}, .expectation = {}}, {.input = {"00.05c a coupon missing from 00.05b: its clown talks collect it, the president gives the Poketch", missing_coupon_collected_in_00_05c}, .expectation = {}}, {.input = {"01.01 with no Poketch: the east-exit guard's gate stops the row at its check, not a trainer fight (lab-B 2026-11-11)", gate_guard_stops_01_01}, .expectation = {}}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index 8d54670fc1..ff9653043e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -282,7 +282,16 @@ void SimKnobRouteIO::check_fade_in(const std::string& label){ WalkResult SimKnobRouteIO::walk_to_wall(const RouteWallWalk& walk){ check_fade_in(walk.label); - return GridSimRouteIO::walk_to_wall(walk); + WalkResult result = GridSimRouteIO::walk_to_wall(walk); + const TilePos ahead = nearest_tile(m_grid.player().pos).next(walk.direction); + const std::vector& people = sim_wanderers(m_grid); + const bool pushing = std::any_of(people.begin(), people.end(), [&](const SimWanderer& person){ + return person.pos == ahead; + }); + if (result.stop == WalkStop::BLOCKED && pushing){ + result.walked += m_knobs.pushing_someone; + } + return result; } WalkResult SimKnobRouteIO::walk_taps(Direction direction, size_t tiles, const std::string& label){ @@ -531,7 +540,7 @@ bool on_world(const StoryWorld& world, const std::string& map){ // (SimWorldKnobs::wander_seed), each with their own seed and start time. std::vector SimExecutor::wanderers(const StoryWorld& world) const{ std::vector out; - if (!m_knobs.wander_seed){ + if (!m_knobs.wander_seed && m_knobs.standing.empty()){ return out; } for (const auto& [map, json] : bdsp_map_json()){ @@ -539,20 +548,22 @@ std::vector SimExecutor::wanderers(const StoryWorld& world) const{ continue; } for (const auto& object : story_map(map).objects){ - if (!object.wander){ + const auto stands = m_knobs.standing.find(object.name); + if (!object.wander || (!m_knobs.wander_seed && stands == m_knobs.standing.end())){ continue; } - const uint64_t seed = *m_knobs.wander_seed * 1000003 + out.size() * 7919 + (uint64_t)(object.x * 31 + object.y); + const uint64_t seed = m_knobs.wander_seed.value_or(0) * 1000003 + out.size() * 7919 + (uint64_t)(object.x * 31 + object.y); const TilePos low = story_to_world(world, map, {object.wander->x0, object.wander->y0}); const TilePos high = story_to_world(world, map, {object.wander->x1, object.wander->y1}); + const bool still = stands != m_knobs.standing.end(); out.push_back({ .name = object.name, .box = {.x0 = low.x, .y0 = low.y, .x1 = high.x, .y1 = high.y}, - .pos = story_to_world(world, map, {object.x, object.y}), + .pos = story_to_world(world, map, still ? stands->second : TilePos{object.x, object.y}), .seed = seed, - .step_interval = Milliseconds(2000), + .step_interval = still ? Milliseconds(0) : Milliseconds(2000), .elapsed = Milliseconds(0), - .time_offset = Milliseconds((int64_t)(seed % 2000)), + .time_offset = still ? Milliseconds(0) : Milliseconds((int64_t)(seed % 2000)), }); } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index 0d1cb7e5ee..b73e7a9884 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -155,6 +155,16 @@ struct SimWorldKnobs{ std::map fade_into = {}; // People with a wander box on their map walk it, a step tried every 2 s. std::optional wander_seed = std::nullopt; + // People with a wander box who stand still on a tile of their map + // instead, by name, with or without wander_seed: 00.05b's boy below + // the Mart (school_kid_m_5, x 51, y 33..35) on row 34. + std::map standing = {}; + // How much longer a hold into someone standing still takes to read as + // stopped: the screen moves on while we push against them. On lab-B + // (2026-11-11 21:00, 00.05b) "east 8 (to wall)" stopped against the boy + // below the Mart after 2800 ms, about 5 tiles in, where a free run + // stops at its wall after about 2000. + Milliseconds pushing_someone = Milliseconds(0); // How long after the A press a talk's first line shows, by step name. std::map first_line = {}; // The scene a step's talk-over plays, by step name: a scene's or a diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp index 7ab44ee342..52eabd9065 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp @@ -489,6 +489,11 @@ UnitTestResult test_gives_up_after_attempts(Logger&){ return true; } +// Events that leave the player where they were: the look at the Poketch, +// and 00.05c's start probe, whose step west the Poketch Company's sign +// stops on 00.05b's end, (14, 19). +const std::set EVENTS_IN_PLACE{"check_poketch", "jubilife_start_probe"}; + // Each row that has a start pose starts where the row before it leaves // the player, by the same planning and walking the fake run does. UnitTestResult test_poses_chain(Logger&){ @@ -523,6 +528,8 @@ UnitTestResult test_poses_chain(Logger&){ } at = walked.at; measured = walked.measured; + }else if (step.kind == StoryStepKind::GAME && EVENTS_IN_PLACE.contains(step.action)){ + // Where it was. }else if (step.kind == StoryStepKind::GAME || step.kind == StoryStepKind::SHOP || step.kind == StoryStepKind::MASH){ // A scene or an event: where it ends is the table's to say. at.reset(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index e7198e24a3..d68628e615 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -164,6 +164,24 @@ bool never_moved(const WalkResult& walk, size_t walked_tiles){ return walk.stop == WalkStop::BLOCKED && walk.moved_chunks == 0 && walked_tiles == 0; } +// Whether a walk to the wall that stopped took far longer than the tiles +// to its nearest wall `nearest` allow, past the walker's slack: two of its +// 400 ms chunks, or 30% of the tiles' time on a long leg. Something held +// it up on the way, and its time no longer counts tiles. On lab-B +// (2026-11-11 21:00, 00.05b) "east 8 (to wall)" stopped after 2800 ms +// against a boy below the Mart, about 5 tiles in, with 5 moved chunks +// where an 8-tile run moves about 3; the time counted 17 tiles, and the +// route went on from (56, 34) as if at the wall. +bool held_up(const WalkResult& walk, size_t nearest, Milliseconds per_tile){ + if (walk.stop != WalkStop::BLOCKED || walk.wild_battles > 0){ + return false; + } + const Milliseconds tiles_time = per_tile * nearest; + const Milliseconds slack = std::max(800ms, tiles_time * 3 / 10); + // 800 ms: the two still chunks that read as stopped (tiles_moved()). + return walk.walked > ROUTE_START_DELAY + tiles_time + 800ms + slack; +} + // Legs to a wall this many tiles or shorter must walk every tile: a tile // short is someone in the way, not the time count's slack. On lab-B // (2026-11-08, 01.08) Route 204's youngster stopped "west 2 (to wall)" @@ -248,6 +266,7 @@ class RouteWalker{ bool finish_interrupted_wall(LegWalk& walk, Milliseconds limit); size_t unstick_wall_leg(LegWalk& walk, size_t walked_tiles, size_t nearest); LegNext stopped_short_of_wall(LegWalk& walk, size_t walked_tiles); + LegNext held_up_on_the_way(const LegWalk& walk, size_t nearest); void check_at_wall(LegWalk& walk, size_t walked_tiles = SIZE_MAX, size_t expected_tiles = SIZE_MAX); void on_to_wall(LegWalk& walk); @@ -415,6 +434,10 @@ LegNext RouteWalker::wall_leg(LegWalk& walk){ direction_name(leg.direction) + ": " + std::to_string(nearest) + " tiles in " + std::to_string(walk.result.walked.count()) + " ms to the wall.", RouteNote::LOG); } + // Checked on the first walk only: one after a wait starts part way. + if (nearest != SIZE_MAX && walked_tiles >= nearest && held_up(walk.result, nearest, route_ms_per_tile(leg.direction, m_plan.speed))){ + return held_up_on_the_way(walk, nearest); + } walked_tiles = unstick_wall_leg(walk, walked_tiles, nearest); // Any stop short of the wall's distance: someone who stays put is // talked to, and the leg is planned again from where we are. Within the @@ -845,6 +868,26 @@ void RouteWalker::mark_blocker(const LegWalk& walk, const std::vector& describe(m_maps, blocker) + "; marked it.", RouteNote::WARNING); } +// A walk to the wall held up on the way (held_up()): it may have stopped on +// any tile of the leg, its first too if no chunk moved. Not the wall: plan +// again from all of them, which a leg to a wall brings back to one tile. +LegNext RouteWalker::held_up_on_the_way(const LegWalk& walk, size_t nearest){ + std::vector stopped; + for (const TilePos& pos : m_from){ + if (walk.result.moved_chunks == 0){ + stopped.push_back(pos); + } + const std::vector path = leg_path(m_grid, pos, walk.planned.leg.direction, nearest); + stopped.insert(stopped.end(), path.begin(), path.end()); + } + stopped = sorted_unique(std::move(stopped)); + if (stopped.empty()){ + fail(m_io, walk.label + ": held up on the way, and no tile fits."); + } + return replan_from(walk, std::move(stopped), std::format("held up on the way ({} ms for {} tiles to the wall)", + walk.result.walked.count(), nearest)); +} + LegNext RouteWalker::replan_from(const LegWalk& walk, std::vector stopped, const std::string& why){ m_io.note(std::format("{}{}", ROUTE_LOG_TAG, route_replan_line(m_plan.label, route_log_leg(walk.planned.leg), why, route_tiles(m_maps, stopped))), RouteNote::WARNING); m_facing = walk.planned.leg.direction; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp index 58f9d9604e..b5f91a50d4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp @@ -177,6 +177,30 @@ std::vector> run_variants(const ScoredRoute& route, cons return out; } +// The tiles where someone wanders that `legs` enter, from every tile of +// `from`: a run on to a wall or a trigger may enter a zone the route's own +// plan keeps off (RobustPlanCosts::per_wander_tile). +size_t wander_tiles_entered(const StoryWorld& world, std::vector from, const std::vector& legs){ + size_t out = 0; + for (const PlannedLeg& planned : legs){ + for (const TilePos& start : from){ + TilePos at = start; + size_t walked = 0; + while (planned.leg.ends_at_wall || walked < planned.leg.tiles){ + const std::optional next = step(world, at, planned.leg.direction); + if (!next){ + break; + } + walked += (size_t)(std::abs(next->x - at.x) + std::abs(next->y - at.y)); + at = *next; + out += wandering_hazard(world, at) ? 1 : 0; + } + } + from = planned.after; + } + return out; +} + bool same_legs(const std::vector& a, const std::vector& b){ return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](const PlannedLeg& x, const PlannedLeg& y){ return x.leg.direction == y.leg.direction && x.leg.tiles == y.leg.tiles && @@ -364,7 +388,14 @@ std::optional> plan_fastest_route(const ScoredRoute& rou const bool own_passes = own.verdict == Pokemon::RouteVerdict::PASS; const size_t own_back = Pokemon::tiles_walked_back(route_scored_legs(*best, route.speed)); double best_ms = own_passes ? own.expected_ms : -1; + // With costs that keep out of wander zones (town_plan_costs()), a plan + // that enters none is not swapped for a faster one that does. + const bool own_clear = route.costs.per_wander_tile > TilePlanCosts().per_wander_tile && + wander_tiles_entered(route.world, route.from, *best) == 0; for (std::vector& legs : candidates){ + if (own_clear && wander_tiles_entered(route.world, route.from, legs) > 0){ + continue; + } const Pokemon::RouteScore score = score_with(route, legs, replan); if (score.verdict != Pokemon::RouteVerdict::PASS || (best_ms >= 0 && score.expected_ms >= best_ms)){ continue; From 5975bb0eb9b38bc5299ff24bc301e8b7b26df309 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:13:32 -0800 Subject: [PATCH 19/47] BDSP AutoStory: wait for the Mart clown on column 56; 01.08's last leg before the door ends off it The Mart clown wanders (54..56, 32..34) round (55, 33) (PokemonSimulation's jubilife_city.json; the story map leaves him out). Instead of chasing him along the row below his home, 00.05b and 00.05c now wait for him: - New TALK action wait_for_wanderer (WanderWaitPlan, wait_beside_wanderer()): from the tile the route left us on, walk column 56 tile by tile on the D-pad to the step's "stand" tiles, face west and press A about every 2 s (12 asks), then try the next stand tile; the talk counts only when his Yes/No box opens ("again": any talk). A step along the column that something stops asks that way too. After the talk it walks to the declared end (56, 31) and taps north and east: both must not move. - The stand tiles and facing are in the plan step's "stand" arg: (56, 33), (56, 34), (56, 32), facing west. The sim talks to him most from (56, 33): 41 of 64 starts and seeds, against 37 from (56, 34) and 28 from (56, 32). - 00.05b comes along row 36 to the wall (56, 36); 00.05c along row 31 to the wall (57, 31). Both leave from (56, 31) west along row 31, above the boy below the Mart (51, 33..35). - 01.08 below_the_ravaged_path ends on (11, 3), two tiles below the door (11, 1): its last leg was "north 1 (open)" to (11, 2), the tile before the door, since the higher wander cost keeps it off the youngster's row 2. to_banner goes north through the door from there. Tests: Wander wait (the clown is reached from column 56 for each start tile and seeds 1..8, from both rows' starts; the first stand tile is the one the sim meets him most from). The Jubilife zone check also counts the clown's box. The scene-end-pose sweep skips wait_for_wanderer, which proves its end with the two wall taps. Goldens regenerated (PA_UPDATE_ROUTE_PLANS=1, PA_UPDATE_ROUTE_BENCH=1): 00.05b below_the_mart_clown 8050 -> 5450 ms and below_the_tv_clown 23700 -> 27350 ms (row 31 out of (56, 31) instead of row 36 out of (55, 34)); 00.05c below_the_mart_clown 15250 -> 20350 ms and beside_the_president 6800 -> 12200 ms (round the clown's box along row 31); 01.08 below_the_ravaged_path worst 26950 -> 26050 ms (one leg fewer). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonBDSP_AutoStory_Events.h | 4 + .../PokemonBDSP_AutoStory_Events_Jubilife.cpp | 86 ++++++ .../PokemonBDSP_AutoStory_WanderWait.cpp | 98 +++++++ .../PokemonBDSP_AutoStory_WanderWait.h | 82 ++++++ .../AutoStory/Data/route_bench.golden.txt | 10 +- .../AutoStory/Data/route_plans.golden.txt | 53 ++-- .../PokemonBDSP_AutoStory_StoryData.cpp | 23 +- ...PokemonBDSP_AutoStory_StoryTable_Tests.cpp | 12 +- ...PokemonBDSP_AutoStory_FaultSweep_Tests.cpp | 7 +- .../PokemonBDSP_AutoStory_StorySim_Tests.cpp | 2 + ...PokemonBDSP_AutoStory_WanderWait_Tests.cpp | 254 ++++++++++++++++++ .../PokemonBDSP_AutoStory_WanderWait_Tests.h | 25 ++ .../AutoStory/StoryData/bdsp-00.05b.plan.json | 36 ++- .../AutoStory/StoryData/bdsp-00.05c.plan.json | 38 ++- .../AutoStory/StoryData/bdsp-01.08.plan.json | 6 +- SerialPrograms/cmake/SourceFiles.cmake | 4 + 16 files changed, 673 insertions(+), 67 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h index acdf13258c..64d5acd2fa 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h @@ -73,6 +73,10 @@ std::optional wander_row_step(const WalkResult& result, int east); // `wanderer_home` (00.05b, lab-B 2026-11-11: the Poketch Company clown's // talk was "answered" in round 5 by another line). bool asks_someone_else(const Pokemon::MapData& map, Pokemon::TilePos stand, Pokemon::TilePos wanderer_home); +// The box the Mart clown wanders, round (55, 33): PokemonSimulation's +// data/games/bdsp/maps/jubilife_city.json (decomp range 1). The story map +// leaves him out of its wanderers (the decomp hides him behind a flag). +Pokemon::TileBox jubilife_mart_clown_box(); // The tiles 00.05c may start on: against the Poketch Company's sign // (00.05b's end), and on the street east (its own end, 01.01's start). std::pair jubilife_start_tiles(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp index 1c2fddba5c..858b79e2ee 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp @@ -22,6 +22,7 @@ #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" @@ -29,6 +30,7 @@ #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" #include "PokemonBDSP_AutoStory_WildBattle.h" #include "PokemonBDSP_AutoStory_Events.h" +#include "PokemonBDSP_AutoStory_WanderWait.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -153,6 +155,85 @@ Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, c fail_step(stream, step.name + ": no coupon question from any tile below his range."); } +// The console's side of a wait beside a wanderer: a D-pad tap a step, +// counted, and A; the talk counts when his Yes/No box opens (or, with +// "again", when any talk opens). +class ConsoleWanderWait : public WanderWaitBody{ +public: + ConsoleWanderWait(VideoStream& stream, ProControllerContext& context, std::string name, bool again) + : m_stream(stream) + , m_context(context) + , m_name(std::move(name)) + , m_again(again) + {} + virtual bool step(Direction direction) override{ + const std::string label = "Waiting for " + m_name; + route_turn(m_stream, m_context, direction); + const WalkResult result = walk_tiles_dpad(m_stream, m_context, run_from_wild_battle, route_stick(direction), 1, label); + const std::optional moved = wander_row_step(result, 1); + if (!moved){ + fail_step(m_stream, std::format("{}: {} instead of a step along the column.", label, walk_stop_name(result.stop))); + } + return *moved != 0; + } + virtual void face(Direction direction) override{ + route_turn(m_stream, m_context, direction); + } + virtual bool ask() override{ + pbf_press_button(m_context, BUTTON_A, 80ms, 0ms); + m_context.wait_for_all_requests(); + ShortDialogWatcher dialog(COLOR_YELLOW); + if (wait_until(m_stream, m_context, 1500ms, {{dialog}}) != 0){ + return false; + } + return answer_coupon_question(m_stream, m_context, m_name) || m_again; + } + virtual void wait(Milliseconds time) override{ + m_context.wait_for(time); + } + +private: + VideoStream& m_stream; + ProControllerContext& m_context; + std::string m_name; + bool m_again; +}; +// The talk to a wanderer by waiting for him on the step's "stand" tiles, +// from the tile the step before left us on (in their column). It ends on +// its declared tile, against a wall the declared way and one at the +// column's back (away from his box): both taps must not move. +Pokemon::Outcome wait_for_wanderer(StoryExecutor& executor, Pokemon::RunState& state, const Pokemon::StoryStep& step){ + VideoStream& stream = executor.stream(); + const Pokemon::GridPose& stand = Pokemon::story_arg(step.args, "stand"); + const std::vector start = Pokemon::tiles_of(state.pose); + if (!step.pose_after || start.size() != 1 || stand.tiles.empty() || !stand.facing){ + fail_step(stream, step.name + ": needs one start tile, stand tiles and their facing, and a declared end."); + } + const Pokemon::Pose exit = Pokemon::pose_of(*step.pose_after); + const std::vector exit_tiles = Pokemon::tiles_of(exit); + const std::optional exit_wall = Pokemon::facing_of(exit); + if (exit_tiles.size() != 1 || !exit_wall){ + fail_step(stream, step.name + ": its declared end needs one tile and a facing."); + } + // The column's back: the way away from his box. + const Direction back = Pokemon::ALL_DIRECTIONS[((size_t)*stand.facing + 2) % 4]; + const WanderWaitPlan plan{.stands = stand.tiles, .facing = *stand.facing, .exit = exit_tiles[0], .exit_walls = {*exit_wall, back}}; + ConsoleWanderWait body(stream, executor.context(), step.name, Pokemon::story_arg(step.args, "again")); + const WanderWaitResult result = wait_beside_wanderer(body, start[0], plan); + switch (result.end){ + case WanderWaitEnd::TALKED: + stream.log(std::format("[Talk] {}: talked from {}; now on {}.", step.name, Pokemon::to_string(result.talked), Pokemon::to_string(result.at))); + return Pokemon::outcome_ok(); + case WanderWaitEnd::NO_TALK: + fail_step(stream, std::format("{}: no talk from any stand tile; on {}.", step.name, Pokemon::to_string(result.at))); + case WanderWaitEnd::STUCK: + fail_step(stream, std::format("{}: a step along the column stayed blocked at {}.", step.name, Pokemon::to_string(result.at))); + case WanderWaitEnd::LOST: + fail_step(stream, std::format("{}: a step from {} moved to {}: not on the column.", step.name, Pokemon::to_string(exit_tiles[0]), Pokemon::to_string(result.at))); + } + fail_step(stream, step.name + ": unknown wait end."); +} + // 00.05c's end and 01.01's start: the Poketch shows on the screen's right // (R toggles it). Without it, Jubilife's east-exit guard (the coord event // on (60, 21..24)) asks about the Poketch campaign and turns us back. @@ -212,12 +293,17 @@ bool asks_someone_else(const Pokemon::MapData& map, TilePos stand, TilePos wande return false; } +Pokemon::TileBox jubilife_mart_clown_box(){ + return {.x0 = 54, .y0 = 32, .x1 = 56, .y1 = 34}; +} + std::pair jubilife_start_tiles(){ return {{14, 19}, {58, 22}}; } void add_jubilife_events(StoryEvents& events){ events.emplace("talk_to_wanderer", talk_to_wanderer); + events.emplace("wait_for_wanderer", wait_for_wanderer); events.emplace("check_poketch", console_event(check_poketch)); events.emplace("jubilife_start_probe", jubilife_start_probe); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp new file mode 100644 index 0000000000..bd05488eeb --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp @@ -0,0 +1,98 @@ +/* BDSP AutoStory - Wait beside a wanderer + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_WanderWait.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::TilePos; + + +namespace{ + +// Walks the column from `at` to `to`, a tile a step. A blocked step asks +// that way while `talked` is false, and ends the walk if the talk counts. +// False if a step stayed blocked for the plan's asks, or `to` is off the +// column. +bool walk_column(WanderWaitBody& body, TilePos& at, TilePos to, const WanderWaitPlan& plan, bool* talked){ + if (at.x != to.x){ + return false; + } + while (at != to){ + const Direction direction = to.y < at.y ? Direction::NORTH : Direction::SOUTH; + size_t tries = 0; + while (!body.step(direction)){ + if (talked != nullptr && !*talked){ + body.face(direction); + if (body.ask()){ + *talked = true; + return true; + } + } + if (++tries >= plan.asks){ + return false; + } + body.wait(plan.blocked_wait); + } + at = at.next(direction); + } + return true; +} + +// Asks from where the player stands, facing the plan's way. +bool ask_from_stand(WanderWaitBody& body, const WanderWaitPlan& plan){ + body.face(plan.facing); + for (size_t ask = 0; ask < plan.asks; ask++){ + if (body.ask()){ + return true; + } + body.wait(plan.between_asks); + } + return false; +} + +} // namespace + + +WanderWaitResult wait_beside_wanderer(WanderWaitBody& body, TilePos at, const WanderWaitPlan& plan){ + bool talked = false; + TilePos talked_at = at; + for (size_t round = 0; round < plan.rounds && !talked; round++){ + for (const TilePos& stand : plan.stands){ + if (!walk_column(body, at, stand, plan, &talked)){ + return {.end = WanderWaitEnd::STUCK, .at = at, .talked = at}; + } + if (!talked){ + talked = ask_from_stand(body, plan); + } + if (talked){ + talked_at = at; + break; + } + } + } + if (!talked){ + return {.end = WanderWaitEnd::NO_TALK, .at = at, .talked = at}; + } + if (!walk_column(body, at, plan.exit, plan, nullptr)){ + return {.end = WanderWaitEnd::STUCK, .at = at, .talked = talked_at}; + } + for (Direction wall : plan.exit_walls){ + if (body.step(wall)){ + return {.end = WanderWaitEnd::LOST, .at = at.next(wall), .talked = talked_at}; + } + } + return {.end = WanderWaitEnd::TALKED, .at = at, .talked = talked_at}; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h new file mode 100644 index 0000000000..5cd7813aa1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h @@ -0,0 +1,82 @@ +/* BDSP AutoStory - Wait beside a wanderer + * + * From: https://github.com/PokemonAutomation/ + * + * A talk to someone who wanders, by waiting for him rather than chasing + * him: stand on a tile beside his box, face it, and ask each time he may + * have come level, then try the next tile. The Mart clown (00.05b, + * 00.05c) is waited for on column 56, east of his box. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_H +#define PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Where and how long to wait. The stands and the exit are on one column. +struct WanderWaitPlan{ + // The tiles to wait on, in order; the list is walked `rounds` times. + std::vector stands; + // The way to face from a stand: toward his box. + Pokemon::Direction facing = Pokemon::Direction::WEST; + // Where the wait ends after the talk. A step from it toward each of + // `exit_walls` must not move: the walls there prove the tile. + Pokemon::TilePos exit; + std::vector exit_walls; + // Asks from each stand before the next one. + size_t asks = 12; + // The pause after an ask that found nobody. + Milliseconds between_asks = Milliseconds(500); + // The wait for someone in the column to step out of it: a wanderer + // tries a step every 2 s or so, and may stay. + Milliseconds blocked_wait = Milliseconds(2000); + size_t rounds = 2; +}; + +// What the wait does in the game: the console's D-pad and A, or the +// simulation's. +class WanderWaitBody{ +public: + virtual ~WanderWaitBody() = default; + // One whole tile toward `direction`. False if something stopped it. + virtual bool step(Pokemon::Direction direction) = 0; + virtual void face(Pokemon::Direction direction) = 0; + // A toward the faced tile. True if the talk counted: his question. + virtual bool ask() = 0; + virtual void wait(Milliseconds time) = 0; +}; + +// How a wait ended. +enum class WanderWaitEnd{ + TALKED, // the talk counted; the player is on the plan's exit + NO_TALK, // every ask of every round found nobody to talk to + STUCK, // a step along the column stayed blocked + LOST, // an exit wall was not there: off the column +}; +// How a wait ended, and where. +struct WanderWaitResult{ + WanderWaitEnd end; + Pokemon::TilePos at; // where the player is, as counted + Pokemon::TilePos talked; // where the talk counted, for TALKED +}; + +// Waits beside the wanderer from `at`, on the plan's column. A step along +// the column that something stops is someone in the column: the wait asks +// that way too, then waits and steps again. +WanderWaitResult wait_beside_wanderer(WanderWaitBody& body, Pokemon::TilePos at, const WanderWaitPlan& plan); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt index c67197124c..4f20ad59b1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt @@ -35,14 +35,14 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.04d north_to_jubilife | 73575 | 42700 | 30350 | 8 | 35 | 0 | 7.21! | 1.24 | 80.00! | 10200 ms (stand-in) | PASS 00.05b below_the_presidents_trigger | 4900 | 4900 | 4900 | 0 | 0 | 0 | 5.76! | 1.00 | 1.00 | 850 ms (stand-in) | PASS 00.05b past_the_president | 1700 | 1700 | 1700 | 0 | 0 | 0 | 3.78! | 1.00 | 1.00 | 450 ms (stand-in) | PASS -00.05b below_the_mart_clown | 8050 | 8050 | 8050 | 1 | 0 | 0 | 4.35! | 1.00 | 1.00 | 1850 ms (stand-in) | PASS -00.05b below_the_tv_clown | 23700 | 23700 | 23700 | 3 | 0 | 0 | 5.04! | 1.00 | 29.00! | 4700 ms (stand-in) | PASS +00.05b below_the_mart_clown | 5450 | 5450 | 5450 | 1 | 0 | 0 | 3.30! | 1.00 | 1.00 | 1650 ms (stand-in) | PASS +00.05b below_the_tv_clown | 27350 | 27350 | 27350 | 1 | 0 | 0 | 6.29! | 1.00 | 1.00 | 4350 ms (stand-in) | PASS 00.05b below_the_company_clown | 21900 | 21900 | 21900 | 0 | 0 | 0 | 6.74! | 1.00 | 3.00! | 3250 ms (stand-in) | PASS 00.05b beside_the_company_sign | 1450 | 1450 | 1450 | 1 | 0 | 0 | 4.14! | 1.00 | 1.00 | 350 ms (stand-in) | PASS 00.05c below_the_company_clown | 900 | 900 | 900 | 0 | 0 | 0 | 2.57! | 1.00 | 1.00 | 350 ms (stand-in) | PASS 00.05c below_the_tv_clown | 21900 | 21900 | 21900 | 0 | 0 | 0 | 6.74! | 1.00 | 5.00! | 3250 ms (stand-in) | PASS -00.05c below_the_mart_clown | 15250 | 15250 | 15250 | 3 | 0 | 0 | 3.24! | 1.00 | 23.00! | 4700 ms (stand-in) | PASS -00.05c beside_the_president | 6800 | 6800 | 6800 | 2 | 0 | 0 | 4.00! | 1.00 | 2.00! | 1700 ms (stand-in) | PASS +00.05c below_the_mart_clown | 20350 | 20350 | 20350 | 1 | 0 | 0 | 4.68! | 1.00 | 1.00 | 4350 ms (stand-in) | PASS +00.05c beside_the_president | 12200 | 12200 | 12200 | 0 | 0 | 0 | 6.26! | 1.00 | 1.00 | 1950 ms (stand-in) | PASS 00.05c to_the_route_203_street | 21000 | 21000 | 21000 | 0 | 0 | 0 | 6.00! | 1.00 | 1.00 | 3500 ms (stand-in) | PASS 01.01 west_of_barrys_trigger | 7300 | 7300 | 7300 | 0 | 0 | 0 | 6.35! | 1.00 | 1.00 | 1150 ms (stand-in) | PASS 01.02 south_to_the_cliff | 1800 | 1800 | 1800 | 1 | 0 | 0 | 2.57! | 1.00 | 1.00 | 700 ms (stand-in) | PASS @@ -58,7 +58,7 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 01.06 up_jubilifes_road | 87286 | 119950 | 58350 | 3 | 10 | 4 | 7.66! | 2.20! | 20.00! | 11400 ms (stand-in) | PASS 01.06 below_rowans_trigger | 1950 | 1950 | 1950 | 1 | 0 | 0 | 2.29! | 1.00 | 1.00 | 850 ms (stand-in) | PASS 01.08 west_to_the_wall | 1650 | 1650 | 1650 | 1 | 0 | 0 | 3.00! | 1.00 | 1.00 | 550 ms (stand-in) | PASS -01.08 below_the_ravaged_path | 25715 | 26950 | 14600 | 2 | 9 | 0 | 4.29! | 1.00 | 6.00! | 6000 ms (stand-in) | PASS +01.08 below_the_ravaged_path | 24815 | 26050 | 13700 | 2 | 9 | 0 | 4.24! | 1.00 | 6.00! | 5850 ms (stand-in) | PASS 01.09 west_of_the_rock | 7050 | 7050 | 7050 | 1 | 0 | 0 | 4.70! | 1.00 | 1.00 | 1500 ms (stand-in) | PASS 01.09 above_the_way_out | 4550 | 4550 | 4550 | 2 | 0 | 0 | 4.14! | 1.00 | 2.00! | 1100 ms (stand-in) | PASS 01.10 line_1 | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt index 63d3db3e93..5e5f4df555 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt @@ -217,25 +217,21 @@ anchor); 0 from one start tile. == 00.05b below_the_mart_clown (costs: town) from: JubilifeCity (48, 40) facing east (tile) - target: JubilifeCity (55, 34) facing north (tile) + target: JubilifeCity (56, 36) facing north (tile) start candidates: Jubilife City (48, 40) 1. north 4 (open) -> Jubilife City (48, 36) 2. east 8 (to wall) -> Jubilife City (56, 36) - 3. west 1 (open) -> Jubilife City (55, 36) - 4. north 2 (open) -> Jubilife City (55, 34) - totals: 4 legs, 3 turns, 3 open, 0 localization + totals: 2 legs, 1 turns, 1 open, 0 localization == 00.05b below_the_tv_clown (costs: town) - from: JubilifeCity (55, 34) facing north (tile) + from: JubilifeCity (56, 31) facing north (tile) target: JubilifeCity (36, 17) facing north (tile) - start candidates: Jubilife City (55, 34) - 1. south 2 (to wall) -> Jubilife City (55, 36) - 2. west 12 (to wall) -> Jubilife City (43, 36) - 3. north 7 (to wall) -> Jubilife City (43, 29) - 4. east 1 (open) -> Jubilife City (44, 29) - 5. north 12 (open) -> Jubilife City (44, 17) - 6. west 8 (open) -> Jubilife City (36, 17) - totals: 6 legs, 5 turns, 3 open, 0 localization + start candidates: Jubilife City (56, 31) + 1. west 8 (open) -> Jubilife City (48, 31) + 2. north 22 (to wall) -> Jubilife City (48, 9) + 3. south 8 (open) -> Jubilife City (48, 17) + 4. west 12 (open) -> Jubilife City (36, 17) + totals: 4 legs, 3 turns, 3 open, 0 localization == 00.05b below_the_company_clown (costs: town) from: JubilifeCity (36, 17) facing north (tile) @@ -271,26 +267,20 @@ anchor); 0 from one start tile. == 00.05c below_the_mart_clown (costs: town) from: JubilifeCity (36, 17) facing north (tile) - target: JubilifeCity (55, 34) facing north (tile) + target: JubilifeCity (56, 31) facing south (tile) start candidates: Jubilife City (36, 17) - 1. west 1 (open) -> Jubilife City (35, 17) - 2. south 10 (to wall) -> Jubilife City (35, 27) - 3. east 1 (to wall) -> Jubilife City (36, 27) - 4. south 5 (open) -> Jubilife City (36, 32) - 5. east 20 (to wall) -> Jubilife City (56, 32) - 6. south 2 (open) -> Jubilife City (56, 34) - 7. west 1 (open) -> Jubilife City (55, 34) - totals: 7 legs, 6 turns, 4 open, 0 localization + 1. east 8 (open) -> Jubilife City (44, 17) + 2. south 14 (open) -> Jubilife City (44, 31) + 3. east 12 (to wall) -> Jubilife City (56, 31) + totals: 3 legs, 2 turns, 2 open, 0 localization == 00.05c beside_the_president (costs: town) - from: JubilifeCity (55, 34) facing north (tile) + from: JubilifeCity (56, 31) facing north (tile) target: JubilifeCity (45, 35) facing east (tile) - start candidates: Jubilife City (55, 34) - 1. south 2 (to wall) -> Jubilife City (55, 36) - 2. west 12 (to wall) -> Jubilife City (43, 36) - 3. east 2 (open) -> Jubilife City (45, 36) - 4. north 1 (open) -> Jubilife City (45, 35) - totals: 4 legs, 3 turns, 2 open, 0 localization + start candidates: Jubilife City (56, 31) + 1. west 11 (open) -> Jubilife City (45, 31) + 2. south 4 (open) -> Jubilife City (45, 35) + totals: 2 legs, 1 turns, 2 open, 0 localization == 00.05c to_the_route_203_street (costs: line) from: JubilifeCity (45, 35) facing east (tile) @@ -429,15 +419,14 @@ anchor); 0 from one start tile. == 01.08 below_the_ravaged_path (costs: town) from: JubilifeCity (44, 5) facing west (tile) - target: Route204South (11, 2) facing north (tile) + target: Route204South (11, 3) facing north (tile) start candidates: Jubilife City (44, 5) 1. east 2 (open) -> Jubilife City (46, 5) 2. north 19 (to wall) -> Route 204 (14, 18) 3. west 4 (open) -> Route 204 (10, 18) 4. north 15 (to wall) -> Route 204 (10, 3) 5. east 1 (open) -> Route 204 (11, 3) - 6. north 1 (open) -> Route 204 (11, 2) - totals: 6 legs, 5 turns, 4 open, 0 localization + totals: 5 legs, 4 turns, 3 open, 0 localization == 01.09 west_of_the_rock (costs: route) from: RavagedPath (19, 50) facing north (tile) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index 7a58c59612..a90ceab66e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -42,6 +42,23 @@ void add_event_actions(std::vector& actions){ } } +// The talks to someone who wanders: each walks in D-pad taps, a whole tile +// it counts, and ends on its declared tile. +void add_wanderer_talks(std::vector& actions){ + const Pokemon::StoryArgSpec again = optional("again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts"); + const Pokemon::StoryCertainty certainty{.needs = Pokemon::PoseCertainty::TILE, .leaves = Pokemon::PoseEnd::DECLARED}; + // Walks the row below his home, asking north. + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {again}, + .console_only = false, .certainty = certainty}); + // Waits for him on a column beside his box (WanderWaitPlan); ends + // against a wall the declared way and one at the column's back. + const Pokemon::StoryArgSpec stand = required( + "stand", Pokemon::StoryArgType::GRID_POSE, "the tiles to wait on, in order, on the start's column; facing his box" + ); + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "wait_for_wanderer", .args = {stand, again}, + .console_only = false, .certainty = certainty}); +} + std::vector make_bdsp_actions(){ std::vector actions( Pokemon::builtin_story_actions().begin(), Pokemon::builtin_story_actions().end() @@ -92,11 +109,7 @@ std::vector make_bdsp_actions(){ .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = pins}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); - // The talk walks the row in D-pad taps, each a whole tile it counts, - // and back onto its declared tile. - actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", - .args = {optional("again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts")}, - .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::TILE, .leaves = PoseEnd::DECLARED}}); + add_wanderer_talks(actions); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp index c319a93dcc..ff42919a6a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -55,7 +55,7 @@ const std::map>& built_in_actions(){ {StoryStepKind::LEGS, {"", "legs", "one_short_ok", "to_wall", "to_dialogue", "to_map", "counted_wall", "measured"}}, {StoryStepKind::STEP, {"", "face", "to_banner", "tap", "or_legs"}}, {StoryStepKind::MASH, {"", "a"}}, {StoryStepKind::BATTLE, {"", "fight", "doubles", "starter"}}, - {StoryStepKind::TALK, {"", "talk_to_wanderer"}}, + {StoryStepKind::TALK, {"", "talk_to_wanderer", "wait_for_wanderer"}}, {StoryStepKind::SHOP, {"", "sandgem_potions"}}, }; return actions; @@ -410,7 +410,10 @@ UnitTestResult test_story_routes_keep_off_wander_zones(Logger& logger){ // No leg of 00.05b's or 00.05c's routes enters a tile where someone // wanders, from any tile the player may be on: on lab-B (2026-11-11 21:00) // the boy below the Mart (51, 33..35) stopped 00.05b's "east 8 (to wall)" -// along row 34 three tiles short; row 36 below him is open. +// along row 34 three tiles short; row 36 below him is open. The Mart +// clown's box counts too: the routes reach column 56 and leave it at +// (56, 36) and (56, 31), outside it, and wait_for_wanderer walks the +// column between. UnitTestResult test_jubilife_routes_cross_no_wander_zone(Logger& logger){ std::string out; size_t checked = 0; @@ -424,8 +427,11 @@ UnitTestResult test_jubilife_routes_cross_no_wander_zone(Logger& logger){ } checked++; const StoryWorld& world = *route.world; + const Pokemon::TileBox clown = jubilife_mart_clown_box(); const auto [most, leg] = most_zone_tiles(world, route.from, *route.legs, [&](const TilePos& pos){ - return wandering_hazard(world, pos); + const std::optional local = story_to_local(world, "JubilifeCity", pos); + const bool clowns = local && local->x >= clown.x0 && local->x <= clown.x1 && local->y >= clown.y0 && local->y <= clown.y1; + return clowns || wandering_hazard(world, pos); }); if (most > 0){ out += std::format("\n {}: {} enters {} tile(s) where someone wanders.", route.name, leg, most); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp index 810a6254b7..bf9bd564d3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp @@ -195,6 +195,11 @@ const std::map PROVEN_SCENE_ENDS{ {"rowan_and_dawn", "lab-B 2026-11-09, 7 of 7 runs on (6, 8)"}, }; +// A talk that walks to its end itself: wait_for_wanderer counts its taps +// along one column and ends with taps into two walls that must not move, +// so a tile beside its end fails the step on the console. +constexpr std::string_view WALKS_TO_ITS_END = "wait_for_wanderer"; + // Runs row `row` with `knobs`: "" if it passes, else where and why it stopped. std::string run_row(Logger& logger, const std::string& row, SimWorldKnobs knobs){ SimExecutor executor(logger, {.fade = {}, .banner = {}}, std::move(knobs)); @@ -363,7 +368,7 @@ UnitTestResult sweep_scene_end_pose(Logger& logger, const StoryCheckpoint& row){ size_t variants = 0; for (size_t c = 0; c < row.steps.size(); c++){ const StoryStep& step = row.steps[c]; - if (!game_sets_end(step.kind) || !step.pose_after || PROVEN_SCENE_ENDS.contains(step.name) || + if (!game_sets_end(step.kind) || step.action == WALKS_TO_ITS_END || !step.pose_after || PROVEN_SCENE_ENDS.contains(step.name) || already_there(logger, row, c, Pokemon::pose_of(*step.pose_after))){ continue; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp index 56af9971a4..ab45e4972d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp @@ -43,6 +43,7 @@ #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" #include "PokemonBDSP_AutoStory_GridSim.h" #include "PokemonBDSP_AutoStory_LegTrace_Tests.h" +#include "PokemonBDSP_AutoStory_WanderWait_Tests.h" #include "PokemonBDSP_AutoStory_OldStorySteps.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h" @@ -386,6 +387,7 @@ void add_tests_AutoStory_StorySim(UnitTestDatabase& database){ } add_tests_AutoStoryResources(database); add_tests_AutoStory_LegTrace(database); + add_tests_AutoStory_WanderWait(database); } } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp new file mode 100644 index 0000000000..0927df5baf --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp @@ -0,0 +1,254 @@ +/* BDSP AutoStory Wander Wait Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Mart clown wanders (54..56, 32..34) round (55, 33). 00.05b and + * 00.05c wait for him on column 56 facing west (wait_for_wanderer): these + * run that wait on the simulation with him starting on each tile of his + * box, and pick the tile to wait on first. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory_GridSim.h" +#include "PokemonBDSP_AutoStory_WanderWait_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::TileBox; +using Pokemon::TilePos; + + +namespace{ + +// Jubilife alone, with the Mart clown wandering his box instead of +// standing on (55, 33). One map at (0, 0): world tiles are its own. +StoryWorld clown_world(){ + Pokemon::MapData map = story_map("JubilifeCity"); + for (Pokemon::MapObject& object : map.objects){ + if (object.name == "clown_mart"){ + object.wander = jubilife_mart_clown_box(); + } + } + StoryWorld world; + world.add("JubilifeCity", map, {0, 0}); + return world; +} + +// The wait on the simulation: a tap a tile, A at the faced tile, and the +// console's time per ask (the dialog watch). +class SimWanderWait : public WanderWaitBody{ +public: + explicit SimWanderWait(GridSim& sim) + : m_sim(sim) + {} + virtual bool step(Direction direction) override{ + return m_sim.tap(direction, ROUTE_MS_PER_TILE_ACROSS, false).distance > 0; + } + virtual void face(Direction direction) override{ + m_sim.tap(direction, 50ms, false); + } + virtual bool ask() override{ + const TilePos faced = nearest_tile(m_sim.player().pos).next(m_sim.player().facing); + bool clown = false; + for (const SimWanderer& wanderer : detail::sim_wanderers(m_sim)){ + clown |= wanderer.pos == faced; + } + const bool talked = m_sim.press_a() && clown; + m_sim.end_dialogue(); + detail::sim_advance_time(m_sim, 1500ms); + return talked; + } + virtual void wait(Milliseconds time) override{ + detail::sim_advance_time(m_sim, time); + } + +private: + GridSim& m_sim; +}; + +// The step `name` of row `row`. +const Pokemon::StoryStep& story_step(const std::string& row, const std::string& name){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + if (checkpoint.id != row){ + continue; + } + for (const Pokemon::StoryStep& step : checkpoint.steps){ + if (step.name == name){ + return step; + } + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No step {} in row {}.", name, row)); +} + +// The wait plan of a wait_for_wanderer step, as the console reads it. +WanderWaitPlan plan_of(const Pokemon::StoryStep& step){ + const Pokemon::GridPose& stand = Pokemon::story_arg(step.args, "stand"); + const Pokemon::Pose exit = Pokemon::pose_of(*step.pose_after); + const Direction back = Pokemon::ALL_DIRECTIONS[((size_t)*stand.facing + 2) % 4]; + return WanderWaitPlan{.stands = stand.tiles, .facing = *stand.facing, + .exit = Pokemon::tiles_of(exit).at(0), .exit_walls = {*Pokemon::facing_of(exit), back}}; +} + +// Where the clown may start: each tile of his box but `player`'s. +std::vector clown_starts(const TilePos& player){ + std::vector starts; + const TileBox box = jubilife_mart_clown_box(); + for (int y = box.y0; y <= box.y1; y++){ + for (int x = box.x0; x <= box.x1; x++){ + if (TilePos{x, y} != player){ + starts.push_back({x, y}); + } + } + } + return starts; +} + +// The wait from `start` with the clown starting on `clown`, his walk +// seeded by `seed`. +WanderWaitResult run_wait(const StoryWorld& world, const TilePos& start, const TilePos& clown, uint64_t seed, const WanderWaitPlan& plan){ + const SimWanderer wanderer{.name = "clown_mart", .box = jubilife_mart_clown_box(), .pos = clown, .seed = seed}; + GridSim sim({.world = &world, .wanderers = {wanderer}}, start, Direction::NORTH, false); + SimWanderWait body(sim); + const WanderWaitResult result = wait_beside_wanderer(body, start, plan); + if (nearest_tile(sim.player().pos) != result.at){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("the wait counted {}, the player is on {}.", + Pokemon::to_string(result.at), Pokemon::to_string(nearest_tile(sim.player().pos)))); + } + return result; +} + +constexpr uint64_t SEEDS = 8; + +// 00.05b comes up column 56 from the wall (56, 36), 00.05c down it from +// (56, 31): from each, the wait talks to the clown wherever in his box he +// starts, over seeds 1 to 8, and ends on (56, 31). +UnitTestResult test_mart_clown_reached_from_column_56(Logger& logger){ + const StoryWorld world = clown_world(); + std::string out; + size_t runs = 0; + for (const auto& [row, start] : {std::pair{"00.05b", {56, 36}}, {"00.05c", {56, 31}}}){ + const WanderWaitPlan plan = plan_of(story_step(row, "mart_clown")); + for (const TilePos& clown : clown_starts(start)){ + for (uint64_t seed = 1; seed <= SEEDS; seed++){ + runs++; + const WanderWaitResult result = run_wait(world, start, clown, seed, plan); + if (result.end != WanderWaitEnd::TALKED || result.at != plan.exit){ + out += std::format("\n {} with the clown on {}, seed {}: ended {} on {}.", row, + Pokemon::to_string(clown), seed, (int)result.end, Pokemon::to_string(result.at)); + } + } + } + } + logger.log(std::format("{} waits run.", runs)); + return out.empty() ? UnitTestResult(true) : UnitTestResult(std::format("The wait missed the clown:{}", out)); +} + +// How many of the clown's starts and seeds one stand tile alone talks +// to him from, facing west, within the plan's asks. +size_t talks_from(const StoryWorld& world, const TilePos& stand, const WanderWaitPlan& table_plan){ + WanderWaitPlan plan = table_plan; + plan.stands = {stand}; + plan.rounds = 1; + size_t talks = 0; + for (const TilePos& clown : clown_starts(stand)){ + for (uint64_t seed = 1; seed <= SEEDS; seed++){ + talks += run_wait(world, stand, clown, seed, plan).end == WanderWaitEnd::TALKED ? 1 : 0; + } + } + return talks; +} + +// The first stand tile is the one of (56, 32..34) the simulation finds +// the clown level with most often. +UnitTestResult test_mart_clown_first_stand(Logger& logger){ + const StoryWorld world = clown_world(); + const WanderWaitPlan plan = plan_of(story_step("00.05b", "mart_clown")); + size_t best = 0; + int best_y = 0; + for (int y = 32; y <= 34; y++){ + const size_t talks = talks_from(world, {56, y}, plan); + logger.log(std::format("From (56, {}): {} talks of {} starts and seeds.", y, talks, clown_starts({56, y}).size() * SEEDS)); + if (talks > best){ + best = talks; + best_y = y; + } + } + for (const std::string row : {"00.05b", "00.05c"}){ + const TilePos first = plan_of(story_step(row, "mart_clown")).stands.at(0); + if (first != TilePos{56, best_y}){ + return std::format("{} waits first on {}; the simulation talks most from (56, {}).", row, Pokemon::to_string(first), best_y); + } + } + return true; +} + +struct WanderWaitInput{ + std::string name; + std::function body; +}; +struct WanderWaitExpectation{}; +struct WanderWaitCase{ + WanderWaitInput input; + WanderWaitExpectation expectation; +}; + +class Test_AutoStoryWanderWait : public UnitTest{ +public: + explicit Test_AutoStoryWanderWait(WanderWaitCase test_case) + : UnitTest(std::format("PokemonBDSP::AutoStory - {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + WanderWaitCase m_case; +}; + +const WanderWaitCase WANDER_WAIT_CASES[] = { + {.input = {"Wander wait: the Mart clown is reached from column 56 wherever he starts (00.05b, 00.05c)", + test_mart_clown_reached_from_column_56}, .expectation = {}}, + {.input = {"Wander wait: the Mart clown's first stand tile is where the simulation meets him most", + test_mart_clown_first_stand}, .expectation = {}}, +}; + +} // namespace + + +void add_tests_AutoStory_WanderWait(UnitTestDatabase& database){ + for (const auto& item : WANDER_WAIT_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h new file mode 100644 index 0000000000..71f8d051f2 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h @@ -0,0 +1,25 @@ +/* BDSP AutoStory Wander Wait Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The wait for the Mart clown on column 56 (00.05b, 00.05c), on the +// simulation with him wandering his box. +void add_tests_AutoStory_WanderWait(UnitTestDatabase& database); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json index 56ef4d5f4f..b8e41a61b1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json @@ -66,31 +66,51 @@ "map": "JubilifeCity", "tiles": [ [ - 55, - 34 + 56, + 36 ] ] } }, "id": "below_the_mart_clown", "kind": "route", - "why": "up the road east of the Center" + "why": "along row 36, below the boy by the Mart, to the wall east of the Center" }, { - "action": "talk_to_wanderer", + "action": "wait_for_wanderer", + "args": { + "stand": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 56, + 33 + ], + [ + 56, + 34 + ], + [ + 56, + 32 + ] + ] + } + }, "declared_after": { "facing": "north", "map": "JubilifeCity", "tiles": [ [ - 55, - 34 + 56, + 31 ] ] }, "id": "mart_clown", "kind": "talk", - "why": "the clown by the Mart: 'Do Pokemon grow by defeating others?' Yes; Coupon 1" + "why": "the clown by the Mart (wanders 54..56, 32..34): wait on column 56 facing west until he comes level, A about every 2 s; 'Do Pokemon grow by defeating others?' Yes; Coupon 1. Ends north against the wall at (56, 30)" }, { "action": "town", @@ -109,7 +129,7 @@ }, "id": "below_the_tv_clown", "kind": "route", - "why": "west and north to the TV station" + "why": "west along row 31, above the boy below the Mart, and north to the TV station" }, { "id": "tv_clown", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json index 079c5c0c2a..761a1c8397 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json @@ -88,38 +88,56 @@ "args": { "fight_wild": false, "target": { - "facing": "north", + "facing": "south", "map": "JubilifeCity", "tiles": [ [ - 55, - 34 + 56, + 31 ] ] } }, "id": "below_the_mart_clown", "kind": "route", - "why": "east and south to the Mart's clown" + "why": "east along row 31, above the Mart clown's box, to the wall (57, 31)" }, { - "action": "talk_to_wanderer", + "action": "wait_for_wanderer", "args": { - "again": true + "again": true, + "stand": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 56, + 33 + ], + [ + 56, + 34 + ], + [ + 56, + 32 + ] + ] + } }, "declared_after": { "facing": "north", "map": "JubilifeCity", "tiles": [ [ - 55, - 34 + 56, + 31 ] ] }, "id": "mart_clown", "kind": "talk", - "why": "his coupon again, or his talk if he gave it" + "why": "his coupon again, or his talk if he gave it: wait on column 56 facing west, as in 00.05b" }, { "action": "town", @@ -138,7 +156,7 @@ }, "id": "beside_the_president", "kind": "route", - "why": "west along row 34 to the Poketch president" + "why": "from the wall north of column 56 round the boy below the Mart to the Poketch president" }, { "id": "president", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json index db9402098c..3e907d14d6 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json @@ -36,14 +36,14 @@ "tiles": [ [ 11, - 2 + 3 ] ] } }, "id": "below_the_ravaged_path", "kind": "route", - "why": "north out of Jubilife, up Route 204's street and grass to below the door (11, 1)" + "why": "north out of Jubilife, up Route 204's street and grass to (11, 3), two tiles below the door (11, 1), clear of the youngster on row 2" }, { "action": "to_banner", @@ -62,7 +62,7 @@ }, "id": "into_the_ravaged_path", "kind": "step", - "why": "the door (11, 1)" + "why": "north up column 11 through the door (11, 1): the walk's last leg goes into the door, not to a tile before it" } ], "id": "01.08", diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e49ba1686a..d1619de031 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1720,6 +1720,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_CoordEvents.cpp @@ -1823,6 +1825,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.h + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_CountedWallLeg.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h From 4ad67e372e93d3688ab9df1486b88da5438c9345 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:13:48 -0800 Subject: [PATCH 20/47] BDSP AutoStory: talk_to_npc() moves to PlannedTalk.cpp (code health) PlannedRoute.cpp was over the 1000-line limit (1030). talk_to_npc() moves unchanged to PokemonBDSP_AutoStory_PlannedTalk.cpp beside the header that declares it; fail(), turn() and press_a(), which both files use, move out of the anonymous namespace unchanged and are declared in the new PokemonBDSP_AutoStory_RouteSteps.h. PlannedRoute.cpp is now 988 lines. Also: make_bdsp_actions() hands its LEGS actions to add_legs_actions() (it was 60 lines), and the two char_pointer tags in StoryTable_Tests.cpp that attached to nothing are gone. git diff --color-moved=dimmed-zebra --color-moved-ws=allow-indentation-change HEAD~1 HEAD Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_StoryData.cpp | 37 ++++++---- ...PokemonBDSP_AutoStory_StoryTable_Tests.cpp | 2 - .../PokemonBDSP_AutoStory_PlannedRoute.cpp | 74 ++++--------------- .../PokemonBDSP_AutoStory_PlannedTalk.cpp | 65 ++++++++++++++++ .../Utils/PokemonBDSP_AutoStory_RouteSteps.h | 34 +++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 6 files changed, 140 insertions(+), 74 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index a90ceab66e..414484cabe 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -42,6 +42,27 @@ void add_event_actions(std::vector& actions){ } } +// A hold to a wall or onto a map ends on its declared end from any start +// on the map: it is how a step pins an unsure pose. +constexpr Pokemon::StoryCertainty PINS{.needs = Pokemon::PoseCertainty::UNKNOWN, .leaves = Pokemon::PoseEnd::DECLARED}; + +// The LEGS actions, each walking `legs`. +void add_legs_actions( + std::vector& actions, + const Pokemon::StoryArgSpec& legs_arg, const Pokemon::StoryArgSpec& fight_wild +){ + using Pokemon::PoseCertainty; + using Pokemon::PoseEnd; + for (std::string_view act : {"to_wall", "to_map"}){ + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}, .console_only = false, .certainty = PINS}); + } + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "to_dialogue", .args = {legs_arg, fight_wild}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::UNKNOWN, .leaves = PoseEnd::GAME_SET}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "one_short_ok", .args = {legs_arg, fight_wild}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "counted_wall", .args = {legs_arg, fight_wild}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); +} + // The talks to someone who wanders: each walks in D-pad taps, a whole tile // it counts, and ends on its declared tile. void add_wanderer_talks(std::vector& actions){ @@ -94,20 +115,8 @@ std::vector make_bdsp_actions(){ actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs}}); } actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = "into_scene", .args = {route_target, fight_wild, legs_arg}}); - // A hold to a wall or onto a map ends on its declared end from any - // start on the map: it is how a step pins an unsure pose. - using Pokemon::PoseCertainty; - using Pokemon::PoseEnd; - const Pokemon::StoryCertainty pins{.needs = PoseCertainty::UNKNOWN, .leaves = PoseEnd::DECLARED}; - for (std::string_view act : {"to_wall", "to_map"}){ - actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}, .console_only = false, .certainty = pins}); - } - actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "to_dialogue", .args = {legs_arg, fight_wild}, - .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::UNKNOWN, .leaves = PoseEnd::GAME_SET}}); - actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "one_short_ok", .args = {legs_arg, fight_wild}}); - actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "counted_wall", .args = {legs_arg, fight_wild}, - .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); - actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = pins}); + add_legs_actions(actions, legs_arg, fight_wild); + actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_arg}, .console_only = false, .certainty = PINS}); actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); add_wanderer_talks(actions); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp index ff42919a6a..9e737a1493 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -567,7 +567,6 @@ std::string route_plans_text(){ // The golden file, in the Data folder beside this file's. std::string route_plans_golden_path(){ - // code-health: allow char_pointer -- std::getenv returns a const char pointer const char* path = std::getenv("PA_ROUTE_PLANS_GOLDEN"); if (path != nullptr && path[0] != '\0'){ return path; @@ -620,7 +619,6 @@ std::string plan_differences(const std::string& golden, const std::string& plann UnitTestResult test_route_plans_golden(Logger& logger){ const std::string path = route_plans_golden_path(); const std::string planned = route_plans_text(); - // code-health: allow char_pointer -- std::getenv returns a const char pointer const char* update = std::getenv("PA_UPDATE_ROUTE_PLANS"); if (update != nullptr && update[0] != '\0' && update[0] != '0'){ std::string crlf; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index d68628e615..fdd6966f6d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -18,7 +18,7 @@ #include "PokemonBDSP_AutoStory_RouteChoice.h" #include "PokemonBDSP_AutoStory_CountedWallLeg.h" #include "PokemonBDSP_AutoStory_PlannedRoute.h" -#include "PokemonBDSP_AutoStory_PlannedTalk.h" +#include "PokemonBDSP_AutoStory_RouteSteps.h" #include "PokemonBDSP_AutoStory_WalkDpad.h" namespace PokemonAutomation{ @@ -88,6 +88,21 @@ std::string map_of(const StoryWorld& maps, const std::vector& tiles){ } // namespace +[[noreturn]] void fail(RouteIO& io, const std::string& message){ + io.note(message, RouteNote::FAILURE); + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "RouteIO::note() returned from a failure: " + message); +} + +void turn(RouteIO& io, Direction direction){ + io.note(std::string("[Route] Turning ") + direction_name(direction) + ".", RouteNote::LOG); + io.press(route_turn_tap(direction)); +} + +RouteInput press_a(RouteInputEnd end){ + return {.kind = RouteInputKind::BUTTON_A, .direction = Direction::NORTH, .hold = 80ms, .release = 200ms, + .count = 1, .end = end}; +} + namespace{ // Sorted by row, then column, without repeats. @@ -116,24 +131,6 @@ Milliseconds wall_limit(const TileLeg& leg){ return ROUTE_START_DELAY + per_tile * leg.tiles * 5 / 4 + 1000ms; } -// Fails the program with `message` (RouteNote::FAILURE). -[[noreturn]] void fail(RouteIO& io, const std::string& message){ - io.note(message, RouteNote::FAILURE); - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "RouteIO::note() returned from a failure: " + message); -} - -// route_turn() through `io`. -void turn(RouteIO& io, Direction direction){ - io.note(std::string("[Route] Turning ") + direction_name(direction) + ".", RouteNote::LOG); - io.press(route_turn_tap(direction)); -} - -// A press of A, to talk to someone in front of us. -RouteInput press_a(RouteInputEnd end){ - return {.kind = RouteInputKind::BUTTON_A, .direction = Direction::NORTH, .hold = 80ms, .release = 200ms, - .count = 1, .end = end}; -} - // A wait for someone walking about to get out of the way. constexpr RouteInput WAIT_FOR_THE_WAY{.kind = RouteInputKind::WAIT, .direction = Direction::NORTH, .hold = 2500ms, .release = 0ms, .count = 1, .end = RouteInputEnd::DONE}; @@ -926,45 +923,6 @@ RouteEnd walk_route_to_warp( } -void talk_to_npc( - VideoStream& stream, ProControllerContext& context, const WildBattleEscape& escape, - const StoryWorld& maps, std::vector& at, - RouteTrainers& trainers, const NpcTalk& talk -){ - ConsoleRouteIO io(stream, context, escape); - talk_to_npc(io, maps, at, trainers, talk); -} - -void talk_to_npc( - RouteIO& io, const StoryWorld& maps, std::vector& at, - RouteTrainers& trainers, const NpcTalk& talk -){ - for (Direction side : talk.sides){ - const TilePos stand = talk.npc.next(side); - if (!standable(maps, stand)){ - continue; - } - at = walk_route(io, maps, at, trainers, { - .goal = [stand](const TilePos& pos){ return pos == stand; }, - .label = talk.label, - .avoid = {}, - .costs = route_plan_costs(), - }); - // Face the NPC: the opposite of the side we stand on. - const Direction face = - side == Direction::NORTH ? Direction::SOUTH : - side == Direction::SOUTH ? Direction::NORTH : - side == Direction::EAST ? Direction::WEST : Direction::EAST; - turn(io, face); - io.press(press_a(RouteInputEnd::DONE)); - if (io.dialog_within(2000ms, COLOR_CYAN)){ - io.note(talk.label + ": talking from " + describe(maps, stand) + ".", RouteNote::STATUS); - return; - } - io.note(talk.label + ": nobody answered from " + describe(maps, stand) + "; trying another side.", RouteNote::STATUS); - } - fail(io, talk.label + ": no side of " + describe(maps, talk.npc) + " started a dialogue."); -} namespace{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp new file mode 100644 index 0000000000..3a3b1ee3a6 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp @@ -0,0 +1,65 @@ +/* BDSP AutoStory - Planned talk + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP_AutoStory_PlannedTalk.h" +#include "PokemonBDSP_AutoStory_RouteSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using namespace Pokemon; + + +void talk_to_npc( + VideoStream& stream, ProControllerContext& context, const WildBattleEscape& escape, + const StoryWorld& maps, std::vector& at, + RouteTrainers& trainers, const NpcTalk& talk +){ + ConsoleRouteIO io(stream, context, escape); + talk_to_npc(io, maps, at, trainers, talk); +} + +void talk_to_npc( + RouteIO& io, const StoryWorld& maps, std::vector& at, + RouteTrainers& trainers, const NpcTalk& talk +){ + for (Direction side : talk.sides){ + const TilePos stand = talk.npc.next(side); + if (!standable(maps, stand)){ + continue; + } + at = walk_route(io, maps, at, trainers, { + .goal = [stand](const TilePos& pos){ return pos == stand; }, + .label = talk.label, + .avoid = {}, + .costs = route_plan_costs(), + }); + // Face the NPC: the opposite of the side we stand on. + const Direction face = + side == Direction::NORTH ? Direction::SOUTH : + side == Direction::SOUTH ? Direction::NORTH : + side == Direction::EAST ? Direction::WEST : Direction::EAST; + turn(io, face); + io.press(press_a(RouteInputEnd::DONE)); + if (io.dialog_within(2000ms, COLOR_CYAN)){ + io.note(talk.label + ": talking from " + describe(maps, stand) + ".", RouteNote::STATUS); + return; + } + io.note(talk.label + ": nobody answered from " + describe(maps, stand) + "; trying another side.", RouteNote::STATUS); + } + fail(io, talk.label + ": no side of " + describe(maps, talk.npc) + " started a dialogue."); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h new file mode 100644 index 0000000000..debc220639 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h @@ -0,0 +1,34 @@ +/* BDSP AutoStory - Route steps + * + * From: https://github.com/PokemonAutomation/ + * + * What the planned route and the planned talk both do through a RouteIO. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RouteSteps_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RouteSteps_H + +#include +#include "PokemonBDSP_AutoStory_RouteInput.h" +#include "PokemonBDSP_AutoStory_RouteIO.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Fails the program with `message` (RouteNote::FAILURE). +[[noreturn]] void fail(RouteIO& io, const std::string& message); + +// route_turn() through `io`. +void turn(RouteIO& io, Pokemon::Direction direction); + +// A press of A, to talk to someone in front of us. +RouteInput press_a(RouteInputEnd end); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index d1619de031..6f8a4e005f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1841,6 +1841,7 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_OverlayLog.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.h + Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.h @@ -1848,6 +1849,7 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteIO.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteIO.h + Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTalk.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.cpp From d2d34677701d0a29dc56036939be2aef122f096f Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:37:26 -0800 Subject: [PATCH 21/47] BDSP AutoStory: the story sim plays wait_for_wanderer; Jubilife's clowns wander The map pin moves to PokemonSimulation ed318db (#89): the Mart and Poketch Company clowns now have their wander boxes, with story flag 531. The story simulation played over the Mart clown's wait (00.05b, 00.05c mart_clown). It now runs the console's wait (wait_beside_wanderer()) on the grid simulation, through SimWanderWait, moved out of the wander wait tests into its own file. Someone the simulation does not walk stands on their spawn. 00.05b and 00.05c join the wander_seed runs: the clowns and the boy below the Mart (school_kid_m_5) walk their boxes, seeds 1 to 8. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...onBDSP_AutoStory_SimFailureCases_Tests.cpp | 6 + .../PokemonBDSP_AutoStory_SimWanderWait.cpp | 111 ++++++++++++++++++ .../PokemonBDSP_AutoStory_SimWanderWait.h | 56 +++++++++ .../PokemonBDSP_AutoStory_StorySim.cpp | 13 +- ...PokemonBDSP_AutoStory_WanderWait_Tests.cpp | 50 +------- SerialPrograms/cmake/SourceFiles.cmake | 2 + devtools/maps/map-resources.lock.json | 4 +- 7 files changed, 193 insertions(+), 49 deletions(-) create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp create mode 100644 SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp index 619aeeb74a..e835a17caa 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp @@ -711,6 +711,12 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { {.input = {"01.08 with Route 204's youngster wandering (12..14, 2)", [](Logger& logger){ return wanderers_move(logger, "01.08"); }}, .expectation = {}}, + {.input = {"00.05b with Jubilife's people wandering (the clowns, the boy below the Mart on 51, 33..35)", [](Logger& logger){ + return wanderers_move(logger, "00.05b"); + }}, .expectation = {}}, + {.input = {"00.05c with Jubilife's people wandering (the clowns, the boy below the Mart on 51, 33..35)", [](Logger& logger){ + return wanderers_move(logger, "00.05c"); + }}, .expectation = {}}, {.input = {"01.04 Roark's badge speech: the fanfare's pause, then a scene", roark_badge_speech}, .expectation = {}}, {.input = {"inside a Pokemon Center, the door's settle ends within 3 s of the fade-up with visitors walking, never during the fade", center_inside_settles}, .expectation = {}}, {.input = {"inside a Pokemon Center, one held run north from the door mat reaches the nurse", nurse_in_one_run}, .expectation = {}}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp new file mode 100644 index 0000000000..e1feb98b3e --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp @@ -0,0 +1,111 @@ +/* BDSP AutoStory - Wait beside a wanderer, on the simulation + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" +#include "PokemonBDSP_AutoStory_SimWanderWait.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::TilePos; + + +SimWanderWait::SimWanderWait(GridSim& sim, std::vector still) + : m_sim(sim) + , m_still(std::move(still)) +{} +bool SimWanderWait::step(Direction direction){ + return m_sim.tap(direction, ROUTE_MS_PER_TILE_ACROSS, false).distance > 0; +} +void SimWanderWait::face(Direction direction){ + m_sim.tap(direction, 50ms, false); +} +bool SimWanderWait::ask(){ + const TilePos faced = nearest_tile(m_sim.player().pos).next(m_sim.player().facing); + bool someone = std::find(m_still.begin(), m_still.end(), faced) != m_still.end(); + for (const SimWanderer& wanderer : detail::sim_wanderers(m_sim)){ + someone |= wanderer.pos == faced; + } + const bool talked = m_sim.press_a() && someone; + m_sim.end_dialogue(); + detail::sim_advance_time(m_sim, 1500ms); + return talked; +} +void SimWanderWait::wait(Milliseconds time){ + detail::sim_advance_time(m_sim, time); +} + + +WanderWaitPlan wander_wait_plan(const Pokemon::StoryStep& step){ + const Pokemon::GridPose& stand = Pokemon::story_arg(step.args, "stand"); + const Pokemon::Pose exit = Pokemon::pose_of(*step.pose_after); + const Direction back = Pokemon::ALL_DIRECTIONS[((size_t)*stand.facing + 2) % 4]; + return WanderWaitPlan{.stands = stand.tiles, .facing = *stand.facing, + .exit = Pokemon::tiles_of(exit).at(0), .exit_walls = {*Pokemon::facing_of(exit), back}}; +} + + +namespace{ + +// The plan's tiles on `world`. +WanderWaitPlan on_world(WanderWaitPlan plan, const StoryWorld& world, const std::string& map){ + for (TilePos& stand : plan.stands){ + stand = story_to_world(world, map, stand); + } + plan.exit = story_to_world(world, map, plan.exit); + return plan; +} + +// Where the people of `map` the simulation does not walk stand: their +// spawns, on `world`. +std::vector still_people(const GridSim& sim, const StoryWorld& world, const std::string& map){ + std::vector out; + const std::vector& walking = detail::sim_wanderers(sim); + for (const Pokemon::MapObject& object : story_map(map).objects){ + const bool walks = std::ranges::any_of(walking, [&](const SimWanderer& wanderer){ return wanderer.name == object.name; }); + if (object.kind == Pokemon::ObjectKind::NPC && !walks){ + out.push_back(story_to_world(world, map, {object.x, object.y})); + } + } + return out; +} + +} // namespace + + +Pokemon::Outcome sim_wait_for_wanderer(GridSim& sim, const StoryWorld& world, const Pokemon::Pose& start, const Pokemon::StoryStep& step){ + const TilePos from = story_to_world(world, start.map, Pokemon::tiles_of(start).at(0)); + SimWanderWait body(sim, still_people(sim, world, start.map)); + const WanderWaitResult result = wait_beside_wanderer(body, from, on_world(wander_wait_plan(step), world, start.map)); + const std::string at = Pokemon::to_string(result.at); + switch (result.end){ + case WanderWaitEnd::TALKED: + return Pokemon::outcome_ok(); + case WanderWaitEnd::NO_TALK: + return Pokemon::outcome_failed("operation_failed", std::format("{}: no talk from any stand tile; on {}.", step.name, at)); + case WanderWaitEnd::STUCK: + return Pokemon::outcome_failed("operation_failed", std::format("{}: a step along the column stayed blocked at {}.", step.name, at)); + case WanderWaitEnd::LOST: + return Pokemon::outcome_failed("operation_failed", std::format("{}: a step from the exit moved to {}: not on the column.", step.name, at)); + } + return Pokemon::outcome_failed("operation_failed", step.name + ": unknown wait end."); +} + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h new file mode 100644 index 0000000000..6fc3498c4a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h @@ -0,0 +1,56 @@ +/* BDSP AutoStory - Wait beside a wanderer, on the simulation + * + * From: https://github.com/PokemonAutomation/ + * + * wait_beside_wanderer() on the grid simulation: the wander wait tests' + * body, and the story simulation's wait_for_wanderer step. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_SimWanderWait_H +#define PokemonAutomation_PokemonBDSP_AutoStory_SimWanderWait_H + +#include +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h" +#include "PokemonBDSP_AutoStory_GridSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The wait on the simulation: a tap a tile, A at the faced tile, and the +// console's time per ask (the dialog watch). An ask talks to a wanderer +// on the faced tile, or to someone on one of `still` (world tiles): the +// people the simulation does not walk. +class SimWanderWait : public WanderWaitBody{ +public: + explicit SimWanderWait(GridSim& sim, std::vector still = {}); + virtual bool step(Pokemon::Direction direction) override; + virtual void face(Pokemon::Direction direction) override; + virtual bool ask() override; + virtual void wait(Milliseconds time) override; + +private: + GridSim& m_sim; + std::vector m_still; +}; + +// The wait plan of a wait_for_wanderer step, as the console reads it, in +// its map's tiles. +WanderWaitPlan wander_wait_plan(const Pokemon::StoryStep& step); + +// Plays wait_for_wanderer `step` on `sim`, on `world`, from the tile of +// `start` (its map's): the console's wait (wait_for_wanderer()), its +// failures named as there. Who on the map has no wanderer on `sim` +// stands on their spawn. +Pokemon::Outcome sim_wait_for_wanderer(GridSim& sim, const StoryWorld& world, const Pokemon::Pose& start, const Pokemon::StoryStep& step); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index 225870a361..8df64c2a21 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -18,6 +18,7 @@ #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h" +#include "PokemonBDSP_AutoStory_SimWanderWait.h" #include "PokemonBDSP_AutoStory_StorySim.h" namespace PokemonAutomation{ @@ -694,6 +695,13 @@ StoryBoundActions SimExecutor::sim_actions(){ const auto stubbed = [this](const StoryStep&, RunState&){ return stub(); }; + // Played from where the step before left us, on its map. + const auto wait_for_wanderer = [this, stubbed](const StoryStep& step, RunState& state){ + if (!sync(state.pose)){ + return stubbed(step, state); + } + return sim_wait_for_wanderer(m_sim, m_sim.world(), state.pose, step); + }; return StoryBoundActions{ .new_game = stubbed, .options = stubbed, @@ -706,12 +714,15 @@ StoryBoundActions SimExecutor::sim_actions(){ return heal(state, step); }, .save = stubbed, - .event = [this, stubbed](const std::string& name) -> Pokemon::StoryActionFunction{ + .event = [this, stubbed, wait_for_wanderer](const std::string& name) -> Pokemon::StoryActionFunction{ if (name == "check_poketch"){ return [this](const StoryStep& step, RunState&){ return m_poketch ? Pokemon::outcome_ok() : Pokemon::outcome_failed("no_poketch", step.name + ": no Poketch on the screen."); }; } + if (name == "wait_for_wanderer"){ + return wait_for_wanderer; + } return stubbed; }, }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp index 0927df5baf..f22d1d1731 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp @@ -23,16 +23,15 @@ #include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h" #include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" -#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h" #include "PokemonBDSP_AutoStory_GridSim.h" +#include "PokemonBDSP_AutoStory_SimWanderWait.h" #include "PokemonBDSP_AutoStory_WanderWait_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonBDSP{ -using namespace std::chrono_literals; using Pokemon::Direction; using Pokemon::TileBox; using Pokemon::TilePos; @@ -54,38 +53,6 @@ StoryWorld clown_world(){ return world; } -// The wait on the simulation: a tap a tile, A at the faced tile, and the -// console's time per ask (the dialog watch). -class SimWanderWait : public WanderWaitBody{ -public: - explicit SimWanderWait(GridSim& sim) - : m_sim(sim) - {} - virtual bool step(Direction direction) override{ - return m_sim.tap(direction, ROUTE_MS_PER_TILE_ACROSS, false).distance > 0; - } - virtual void face(Direction direction) override{ - m_sim.tap(direction, 50ms, false); - } - virtual bool ask() override{ - const TilePos faced = nearest_tile(m_sim.player().pos).next(m_sim.player().facing); - bool clown = false; - for (const SimWanderer& wanderer : detail::sim_wanderers(m_sim)){ - clown |= wanderer.pos == faced; - } - const bool talked = m_sim.press_a() && clown; - m_sim.end_dialogue(); - detail::sim_advance_time(m_sim, 1500ms); - return talked; - } - virtual void wait(Milliseconds time) override{ - detail::sim_advance_time(m_sim, time); - } - -private: - GridSim& m_sim; -}; - // The step `name` of row `row`. const Pokemon::StoryStep& story_step(const std::string& row, const std::string& name){ for (const StoryCheckpoint& checkpoint : story_checkpoints()){ @@ -101,15 +68,6 @@ const Pokemon::StoryStep& story_step(const std::string& row, const std::string& throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No step {} in row {}.", name, row)); } -// The wait plan of a wait_for_wanderer step, as the console reads it. -WanderWaitPlan plan_of(const Pokemon::StoryStep& step){ - const Pokemon::GridPose& stand = Pokemon::story_arg(step.args, "stand"); - const Pokemon::Pose exit = Pokemon::pose_of(*step.pose_after); - const Direction back = Pokemon::ALL_DIRECTIONS[((size_t)*stand.facing + 2) % 4]; - return WanderWaitPlan{.stands = stand.tiles, .facing = *stand.facing, - .exit = Pokemon::tiles_of(exit).at(0), .exit_walls = {*Pokemon::facing_of(exit), back}}; -} - // Where the clown may start: each tile of his box but `player`'s. std::vector clown_starts(const TilePos& player){ std::vector starts; @@ -148,7 +106,7 @@ UnitTestResult test_mart_clown_reached_from_column_56(Logger& logger){ std::string out; size_t runs = 0; for (const auto& [row, start] : {std::pair{"00.05b", {56, 36}}, {"00.05c", {56, 31}}}){ - const WanderWaitPlan plan = plan_of(story_step(row, "mart_clown")); + const WanderWaitPlan plan = wander_wait_plan(story_step(row, "mart_clown")); for (const TilePos& clown : clown_starts(start)){ for (uint64_t seed = 1; seed <= SEEDS; seed++){ runs++; @@ -183,7 +141,7 @@ size_t talks_from(const StoryWorld& world, const TilePos& stand, const WanderWai // the clown level with most often. UnitTestResult test_mart_clown_first_stand(Logger& logger){ const StoryWorld world = clown_world(); - const WanderWaitPlan plan = plan_of(story_step("00.05b", "mart_clown")); + const WanderWaitPlan plan = wander_wait_plan(story_step("00.05b", "mart_clown")); size_t best = 0; int best_y = 0; for (int y = 32; y <= 34; y++){ @@ -195,7 +153,7 @@ UnitTestResult test_mart_clown_first_stand(Logger& logger){ } } for (const std::string row : {"00.05b", "00.05c"}){ - const TilePos first = plan_of(story_step(row, "mart_clown")).stands.at(0); + const TilePos first = wander_wait_plan(story_step(row, "mart_clown")).stands.at(0); if (first != TilePos{56, best_y}){ return std::format("{} waits first on {}; the simulation talks most from (56, {}).", row, Pokemon::to_string(first), best_y); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index f351ea0252..bba43ab5a9 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1839,6 +1839,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimTriggers.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 1efcb689ef..6c923a3ddf 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "bdsp": { - "revision": "72093886bc7bc80497aff770d803a753e7e4bca7", + "revision": "ed318db8f7213cf297321d03b3e2463779339c0f", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "0ce25ea46dc00d91d5d8587c6f00f322490ca35b8d0ad9778588133a9f55d00f" + "manifest_sha256": "cbfbbf56b55f509773909217e201fc8e2a4b5f0ed688dbb6ec36c05f381d5dfb" } } } From e48e834b343871d14016125eed1d2123a031e486 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:45:43 -0800 Subject: [PATCH 22/47] BDSP AutoStory: the sim's wander wait talks to a clown on his spawn; clown points are wanderers' spawns With wander boxes, the world leaves the clowns' tiles empty, so the wait's A press alone found nobody there when the simulation does not walk them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp | 14 ++++++++++++-- .../PokemonBDSP_AutoStory_SimWanderWait.cpp | 6 ++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp index 01174e5b99..45831399cf 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp @@ -44,6 +44,13 @@ const MapObject* standing_object(const MapData& map, const TilePos& pos){ return nullptr; } +// Whether someone starts on `pos` and wanders a box round it. +bool wanders_from(const MapData& map, const TilePos& pos){ + return std::ranges::any_of(map.objects, [&](const MapObject& object){ + return object.wander && object.x == pos.x && object.y == pos.y; + }); +} + // "rocks" for "rocks.3", the point's own name otherwise. std::string region_of(const std::string& point){ const size_t dot = point.rfind('.'); @@ -84,6 +91,7 @@ enum class PointOn{ DOOR, SIGN, PERSON, // someone stands still there + WANDERER, // someone starts there and wanders a box round it WALL, // a rock until smashed }; struct PointCase{ @@ -113,9 +121,9 @@ const std::vector& point_cases(){ {.map = "JubilifeCity", .point = "pokemon_center_door", .on = PointOn::DOOR}, {.map = "JubilifeCity", .point = "tv_station_door", .on = PointOn::DOOR}, {.map = "JubilifeCity", .point = "poketch_president", .on = PointOn::PERSON}, - {.map = "JubilifeCity", .point = "clown_mart", .on = PointOn::PERSON}, + {.map = "JubilifeCity", .point = "clown_mart", .on = PointOn::WANDERER}, {.map = "JubilifeCity", .point = "clown_tv_station", .on = PointOn::PERSON}, - {.map = "JubilifeCity", .point = "clown_poketch_company", .on = PointOn::PERSON}, + {.map = "JubilifeCity", .point = "clown_poketch_company", .on = PointOn::WANDERER}, {.map = "OreburghCity", .point = "pokemon_center_door", .on = PointOn::DOOR}, {.map = "OreburghCity", .point = "gym_door", .on = PointOn::DOOR}, {.map = "OreburghCity", .point = "gate_mouth", .on = PointOn::DOOR}, @@ -148,6 +156,8 @@ std::string check_point_on(const MapData& map, const TilePos& pos, PointOn on){ return tile == TileKind::SIGN ? "" : "not a sign"; case PointOn::PERSON: return is_ground(tile) && object != nullptr && object->kind == Pokemon::ObjectKind::NPC ? "" : "nobody stands still there"; + case PointOn::WANDERER: + return is_ground(tile) && wanders_from(map, pos) ? "" : "nobody wanders from there"; case PointOn::WALL: return tile == TileKind::WALL ? "" : "not a wall"; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp index e1feb98b3e..45c0a6156c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp @@ -40,10 +40,12 @@ bool SimWanderWait::ask(){ for (const SimWanderer& wanderer : detail::sim_wanderers(m_sim)){ someone |= wanderer.pos == faced; } - const bool talked = m_sim.press_a() && someone; + // Whoever is faced answers: the world leaves a wanderer's box empty, + // so the press alone misses one standing on his spawn. + m_sim.press_a(); m_sim.end_dialogue(); detail::sim_advance_time(m_sim, 1500ms); - return talked; + return someone; } void SimWanderWait::wait(Milliseconds time){ detail::sim_advance_time(m_sim, time); From 78abee2da385d40de0af6aa1feda93dc95af7038 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:13:54 -0800 Subject: [PATCH 23/47] Pokemon Navigation: step taps per gait; default member values; failure messages name expected and actual (#402 review) FRLG's Bicycle taps 40 ms at one per 100 ms, its walk 66 ms with a 700 ms release, so the step tap moves from MoveMechanics onto Gait. Every scalar gets a default, and the test reports which gait and which value failed. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_MoveMechanics.h | 68 +++++++++++++------ .../Pokemon_MoveMechanics_Tests.cpp | 62 +++++++++++++---- 2 files changed, 95 insertions(+), 35 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h index c96e424cd1..2b7d734b88 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h @@ -26,29 +26,37 @@ enum class OpenLegPress{ // Time per tile along each axis of the screen. struct TileTime{ - Milliseconds across; // east or west - Milliseconds up_down; // north or south + Milliseconds across{}; // east or west + Milliseconds up_down{}; // north or south constexpr Milliseconds along(Direction direction) const{ return direction == Direction::EAST || direction == Direction::WEST ? across : up_down; } }; +// A tap that takes one step: the press, and the release before the next +// press. Their sum is the time per tapped tile. +struct StepTap{ + Milliseconds hold{}; + Milliseconds release{}; +}; + // One way of moving: walking, running or riding. struct Gait{ TileTime tile; - OpenLegPress open_legs; + // The step tap in this gait; a game's taps differ by gait (FRLG's + // Bicycle taps far faster than its walk). + StepTap tap; + OpenLegPress open_legs = OpenLegPress::STEP_TAPS; }; -// How one game moves the player: its taps, and a tile time per gait. +// How one game moves the player: its turn tap, and a tile time and step +// tap per gait. struct MoveMechanics{ // A tap that turns a player facing another way, without a step. - Milliseconds turn_tap; - // A tap that takes one step, and the release before the next press. - Milliseconds step_tap; - Milliseconds step_tap_release; + Milliseconds turn_tap{}; // From pressing, standing still, to the first step under way. - Milliseconds start_delay; + Milliseconds start_delay{}; Gait walk; // B held, once the player has the Running Shoes. Gait run; @@ -64,27 +72,45 @@ struct MoveMechanics{ // tile times: PokemonBDSP_AutoStory_RouteTiming.h. inline constexpr MoveMechanics BDSP_MOVE_MECHANICS{ .turn_tap = Milliseconds(50), - .step_tap = Milliseconds(160), - .step_tap_release = Milliseconds(640), .start_delay = Milliseconds(250), - .walk = {.tile = {.across = Milliseconds(160), .up_down = Milliseconds(240)}, .open_legs = OpenLegPress::STEP_TAPS}, - .run = {.tile = {.across = Milliseconds(100), .up_down = Milliseconds(150)}, .open_legs = OpenLegPress::STEP_TAPS}, + .walk = { + .tile = {.across = Milliseconds(160), .up_down = Milliseconds(240)}, + .tap = {.hold = Milliseconds(160), .release = Milliseconds(640)}, + .open_legs = OpenLegPress::STEP_TAPS, + }, + .run = { + .tile = {.across = Milliseconds(100), .up_down = Milliseconds(150)}, + .tap = {.hold = Milliseconds(160), .release = Milliseconds(640)}, + .open_legs = OpenLegPress::STEP_TAPS, + }, .bike = std::nullopt, }; // FireRed and LeafGreen, measured on console B: a walking tile is 16 // frames, running 8, and a held leg stops where its time says, so open -// legs on foot are timed holds; on the Bicycle they are counted in taps. -// The walker's holds count no start delay. Measurements: -// PokemonFRLG_MovementMechanics.h and PokemonFRLG_BikeSpinMechanics.h. +// legs on foot are timed holds; on the Bicycle they are counted in taps, +// 40 ms at one per 100 ms (BIKE_TAP_PERIOD_WORKED; at a 60 ms period one +// tap in 12 drops). The walker's holds count no start delay. +// Measurements: PokemonFRLG_MovementMechanics.h and +// PokemonFRLG_BikeSpinMechanics.h. inline constexpr MoveMechanics FRLG_MOVE_MECHANICS{ .turn_tap = Milliseconds(40), - .step_tap = Milliseconds(66), - .step_tap_release = Milliseconds(700), .start_delay = Milliseconds(0), - .walk = {.tile = {.across = Milliseconds(267), .up_down = Milliseconds(267)}, .open_legs = OpenLegPress::TIMED_HOLD}, - .run = {.tile = {.across = Milliseconds(133), .up_down = Milliseconds(133)}, .open_legs = OpenLegPress::TIMED_HOLD}, - .bike = Gait{.tile = {.across = Milliseconds(100), .up_down = Milliseconds(100)}, .open_legs = OpenLegPress::STEP_TAPS}, + .walk = { + .tile = {.across = Milliseconds(267), .up_down = Milliseconds(267)}, + .tap = {.hold = Milliseconds(66), .release = Milliseconds(700)}, + .open_legs = OpenLegPress::TIMED_HOLD, + }, + .run = { + .tile = {.across = Milliseconds(133), .up_down = Milliseconds(133)}, + .tap = {.hold = Milliseconds(66), .release = Milliseconds(700)}, + .open_legs = OpenLegPress::TIMED_HOLD, + }, + .bike = Gait{ + .tile = {.across = Milliseconds(100), .up_down = Milliseconds(100)}, + .tap = {.hold = Milliseconds(40), .release = Milliseconds(60)}, + .open_legs = OpenLegPress::STEP_TAPS, + }, }; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp index bdb39073ab..c0de39e0f5 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp @@ -42,6 +42,39 @@ std::optional not_faster(std::string_view faster_name, const Gait& return std::nullopt; } +// Why the turn tap would step on foot in `gait`, if it would: a turn tap +// must be shorter than the gait's step tap. +std::optional turn_steps(std::string_view gait_name, const Gait& gait, Milliseconds turn_tap){ + if (turn_tap >= gait.tap.hold){ + return std::format("The turn tap ({} ms) is not shorter than the {} step tap ({} ms).", + turn_tap.count(), gait_name, gait.tap.hold.count()); + } + return std::nullopt; +} + +// Why a gait's step tap is unusable, if it is: both its press and its +// release must take time. +std::optional empty_tap(std::string_view gait_name, const Gait& gait){ + if (gait.tap.hold <= Milliseconds(0) || gait.tap.release <= Milliseconds(0)){ + return std::format("The {} step tap is {} ms pressed, {} ms released; both must be over 0.", + gait_name, gait.tap.hold.count(), gait.tap.release.count()); + } + return std::nullopt; +} + +std::string_view open_leg_press_name(OpenLegPress press){ + return press == OpenLegPress::STEP_TAPS ? "step taps" : "a timed hold"; +} + +// Why `gait` presses its open legs other than `expected`, if it does. +std::optional wrong_open_legs(std::string_view gait_name, const Gait& gait, OpenLegPress expected){ + if (gait.open_legs != expected){ + return std::format("Open legs {} are pressed as {}, expected {}.", + gait_name, open_leg_press_name(gait.open_legs), open_leg_press_name(expected)); + } + return std::nullopt; +} + class Test_MoveMechanics : public UnitTest{ public: explicit Test_MoveMechanics(MoveMechanicsCase scenario) @@ -49,21 +82,22 @@ class Test_MoveMechanics : public UnitTest{ {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const MoveMechanics& game = m_scenario.input.mechanics; - if (game.turn_tap >= game.step_tap){ - return std::format("The turn tap ({} ms) is not shorter than the step tap ({} ms).", - game.turn_tap.count(), game.step_tap.count()); - } - if (std::optional slower = not_faster("running", game.run, "walking", game.walk)){ - return *slower; - } - if (game.bike){ - if (std::optional slower = not_faster("the bike", *game.bike, "running", game.run)){ - return *slower; - } - } const OpenLegPress expected = m_scenario.expectation.open_legs_on_foot; - if (game.walk.open_legs != expected || game.run.open_legs != expected){ - return "Open legs on foot are not pressed the way the game's walker presses them."; + const std::optional failures[] = { + empty_tap("walking", game.walk), + empty_tap("running", game.run), + game.bike ? empty_tap("bike", *game.bike) : std::nullopt, + turn_steps("walking", game.walk, game.turn_tap), + turn_steps("running", game.run, game.turn_tap), + not_faster("running", game.run, "walking", game.walk), + game.bike ? not_faster("the bike", *game.bike, "running", game.run) : std::nullopt, + wrong_open_legs("walking", game.walk, expected), + wrong_open_legs("running", game.run, expected), + }; + for (const std::optional& failure : failures){ + if (failure){ + return *failure; + } } return true; } From 371bd8d1d163f8e3b1298970f674310ed1bd7086 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:15:57 -0800 Subject: [PATCH 24/47] Pokemon Navigation: ConnectedMaps refuses temporaries, checks map indexes, orders MapPlace (#408 review) The rvalue constructor is deleted, map() throws InternalProgramError past the last map, and MapPlace gets a defaulted <=> over TilePos's. The test art matches the maps, the Lake to Route edge has two cases, and stale map indexes have their own. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_ConnectedMaps.cpp | 10 ++++ .../Navigation/Pokemon_ConnectedMaps.h | 10 +++- .../Pokemon_ConnectedMaps_Tests.cpp | 55 ++++++++++++++++++- 3 files changed, 69 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp index 73b0495f30..1bd697a03e 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp @@ -5,6 +5,8 @@ */ #include +#include +#include "Common/Cpp/Exceptions.h" #include "Pokemon_ConnectedMaps.h" namespace PokemonAutomation{ @@ -35,6 +37,14 @@ TilePos edge_entry(const TilePos& here, Direction side, const MapConnection& con } // namespace +const MapData& ConnectedMaps::map(size_t index) const{ + if (index >= m_maps->size()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, + std::format("Map index {} is past the {} connected maps.", index, m_maps->size())); + } + return (*m_maps)[index]; +} + std::optional ConnectedMaps::find(std::string_view name) const{ for (size_t index = 0; index < m_maps->size(); index++){ if ((*m_maps)[index].name == name){ diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h index 8b8c62948f..5fef2d16a6 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h @@ -32,6 +32,8 @@ struct MapPlace{ TilePos tile; bool operator==(const MapPlace& other) const = default; + // Map, then tile: an order for sets and maps of places. + auto operator<=>(const MapPlace& other) const = default; }; @@ -42,14 +44,16 @@ class ConnectedMaps{ explicit ConnectedMaps(const std::vector& maps) : m_maps(&maps) {} + // A temporary list would be gone by the first call. + explicit ConnectedMaps(std::vector&& maps) = delete; // How many maps are loaded: MapPlace::map runs from 0 to size() - 1. size_t size() const{ return m_maps->size(); } - const MapData& map(size_t index) const{ - return (*m_maps)[index]; - } + // The map at `index`; throws InternalProgramError past the last map, + // as from a MapPlace of another world. + const MapData& map(size_t index) const; // The loaded map named `name`, or nothing. std::optional find(std::string_view name) const; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp index d39c6d2a3e..abcc99f641 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp @@ -7,8 +7,8 @@ * door warps into: * * world x: -1 0 1 2 3 4 5 - * y 0..2: [ Route (6 wide) ] - * y 3..5: [ Town (4) ][Lake] + * y 0..2: [ Route (6 wide) ] + * y 3..5: [ Town (4) ][Lake] * */ @@ -18,6 +18,7 @@ #include #include #include +#include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon_ConnectedMaps.h" #include "Pokemon_ConnectedMaps_Tests.h" @@ -67,12 +68,12 @@ std::string describe(const ConnectedMaps& world, const std::optional& return std::format("{} {}", world.map(place->map).name, to_string(place->tile)); } -// Why `actual` is not `expected`, if it is not. // Where a step or a warp should put the player, or nothing for nowhere. struct PlaceExpectation{ std::optional place; }; +// Why `actual` is not `expected`, if it is not. std::optional mismatch(const ConnectedMaps& world, const std::optional& actual, const PlaceExpectation& expectation){ const std::optional& expected = expectation.place; std::optional wanted; @@ -135,6 +136,14 @@ const StepCase STEP_CASES[] = { .input = {.name = "west into the town", .from = {"Lake", {0, 1}}, .direction = Direction::WEST}, .expectation = {.place = NamedPlace{"Town", {3, 1}}}, }, + { + .input = {.name = "north out of the lake onto the route's last column", .from = {"Lake", {0, 0}}, .direction = Direction::NORTH}, + .expectation = {.place = NamedPlace{"Route", {5, 2}}}, + }, + { + .input = {.name = "north out of the lake past the route's span", .from = {"Lake", {1, 0}}, .direction = Direction::NORTH}, + .expectation = {.place = std::nullopt}, + }, { .input = {.name = "an edge no map joins", .from = {"Town", {0, 1}}, .direction = Direction::WEST}, .expectation = {.place = std::nullopt}, @@ -195,6 +204,43 @@ const WarpCase WARP_CASES[] = { }; +struct StalePlaceInput{ + std::string_view name; + size_t map; +}; +struct StalePlaceCase{ + StalePlaceInput input; +}; + +// A place whose map index is past the loaded maps (from another world, or +// one that has since shrunk) is an InternalProgramError, not a read past +// the end. +class Test_ConnectedMaps_StalePlace : public UnitTest{ +public: + explicit Test_ConnectedMaps_StalePlace(StalePlaceCase scenario) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedMaps world(test_maps()); + const MapPlace stale{m_scenario.input.map, {0, 0}}; + try{ + const std::optional place = world.neighbour(stale, Direction::NORTH); + return std::format("Map {} of {} was read: got {}, expected an InternalProgramError.", + stale.map, world.size(), place ? to_string(place->tile) : "nowhere"); + }catch (const InternalProgramError&){ + return true; + } + } +private: + StalePlaceCase m_scenario; +}; + +const StalePlaceCase STALE_PLACE_CASES[] = { + {.input = {.name = "a map index one past the last is rejected", .map = 4}}, + {.input = {.name = "a map index far past the last is rejected", .map = 1000}}, +}; + + } // namespace void add_tests_ConnectedMaps(UnitTestDatabase& database){ @@ -204,6 +250,9 @@ void add_tests_ConnectedMaps(UnitTestDatabase& database){ for (const WarpCase& scenario : WARP_CASES){ database.add(scenario); } + for (const StalePlaceCase& scenario : STALE_PLACE_CASES){ + database.add(scenario); + } } From 1ca9ec484722bf29b436f09c6f66be5649d388c0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:18:49 -0800 Subject: [PATCH 25/47] Pokemon Navigation: robust leg planner tests as data; open_error_per 0; capped slide (#412 review) Each row now holds the map, starts, goal and costs, and the expected plan as text; one runner compares describe() output. New rows cover a ledge hop, tall grass, max_spread, max_searched, joined open legs and a walk that never stops. open_error_per 0 adds no growth instead of dividing by zero, and slide_to_wall() gives up as not held after 1024 steps. The header says how this step model relates to LegPlanner's and that warps are the caller's job. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_RobustLegPlanner.h | 36 +- .../Pokemon_RobustLegPlanner_Tests.cpp | 329 +++++++++++------- 2 files changed, 228 insertions(+), 137 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h index 882e422c7f..6c527a19fb 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h @@ -12,7 +12,8 @@ * A step model is a class with: * * using State = ...; // where the player is: comparable with == - * using StateLess = ...; // a strict order of State, for sets of them + * using StateLess = ...; // a strict order of State, for sets of them: + * // std::less for TilePos and MapPlace * std::optional step(const State& state, Direction direction) const; * size_t step_tiles(const State& from, const State& to) const; * bool held_at(const State& state, Direction direction) const; @@ -27,6 +28,12 @@ * not used. wild() is a place where a wild battle may stop the walk (tall * grass); wander() one where someone wanders. * + * Warps and game actions (doors, Surf, spin tiles) are not legs: a stop + * that isn't held is never used, so a plan never crosses a warp. Callers + * plan each stretch between warps on its own. The step model here and the + * one of Pokemon_LegPlanner.h (press(), Step) describe the same + * world rules for two planners; a game writes one adapter for each. + * */ #ifndef PokemonAutomation_Pokemon_RobustLegPlanner_H @@ -66,7 +73,8 @@ struct RobustLegCosts{ int per_leg = 8; int leg_not_at_wall = 50; // extra for a leg that stops in the open // An open leg of n tiles may end open_error + n / open_error_per tiles - // short or long. + // short or long. open_error_per 0 adds no growth: every open leg is + // off by open_error at most, and by nothing if open_error is 0 too. int open_error = 1; int open_error_per = 5; // Open legs this many tiles or shorter land exactly. 0 keeps every @@ -110,6 +118,11 @@ long long robust_legs_cost( namespace RobustLegPlannerInternal{ +// Most steps a leg to a wall may take. No map is this long; a model whose +// steps loop (edge connections that come back round, or a model bug) +// would otherwise slide forever. +inline constexpr size_t MAX_STEPS_TO_WALL = 1024; + // Where the player stops walking `direction` until stopped. template struct WallHit{ @@ -117,11 +130,12 @@ struct WallHit{ size_t tiles = 0; bool held = false; }; -// Walks `direction` from `from` until the player is stopped. +// Walks `direction` from `from` until the player is stopped. A walk that +// is not stopped within MAX_STEPS_TO_WALL steps is not held. template WallHit slide_to_wall(const Model& model, const typename Model::State& from, Direction direction){ WallHit hit{from}; - while (true){ + for (size_t steps = 0; steps < MAX_STEPS_TO_WALL; steps++){ const auto next = model.step(hit.stop, direction); if (!next){ hit.held = model.held_at(hit.stop, direction); @@ -130,6 +144,18 @@ WallHit slide_to_wall(const Model& model, const typename hit.tiles += model.step_tiles(hit.stop, *next); hit.stop = *next; } + return hit; +} + +// How many tiles an open leg of `tiles` tiles may end short or long. +inline int open_leg_error(int tiles, const RobustLegCosts& costs){ + if (tiles <= costs.exact_open_tiles){ + return 0; + } + if (costs.open_error_per <= 0){ + return costs.open_error; + } + return costs.open_error + tiles / costs.open_error_per; } // Where `from` ends up after `tiles` tiles `direction`, stopping early @@ -237,7 +263,7 @@ std::optional> open_leg( Expansion expansion; int wild = 0; int wander = 0; - const int error = tiles <= costs.exact_open_tiles ? 0 : costs.open_error + tiles / costs.open_error_per; + const int error = open_leg_error(tiles, costs); for (const auto& place : spread){ for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ const auto stepped = step_tiles(model, place, direction, n); diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp index f7b73b7234..6333649e2c 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp @@ -3,14 +3,17 @@ * From: https://github.com/PokemonAutomation/ * * The robust planner on a small made-up game: walls hold the player, a - * door stops them without holding them, and open legs may end a tile off. + * door stops them without holding them, a ledge hops them south, and open + * legs may end a tile off. * */ #include #include +#include #include #include +#include #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon_RobustLegPlanner.h" @@ -24,33 +27,37 @@ namespace{ // '#' wall (and everything outside the rows), '.' floor, '"' tall grass, // 'w' where someone wanders, 'D' a door: the player is stopped there but -// not held, since walking on enters the building. +// not held, since walking on enters the building. 'v' a ledge: a step south +// onto it hops to the tile past it and counts 2; it holds the player any +// other way. Rows that wrap join their east end to their west end, so a +// walk along them is never stopped. class ToyGame{ public: using State = TilePos; - struct StateLess{ - bool operator()(const TilePos& a, const TilePos& b) const{ - return a.y != b.y ? a.y < b.y : a.x < b.x; - } - }; + using StateLess = std::less; - explicit ToyGame(std::vector rows) - : m_rows(std::move(rows)) + ToyGame(const std::vector& rows, bool wraps) + : m_rows(rows.begin(), rows.end()) + , m_wraps(wraps) {} std::optional step(const State& state, Direction direction) const{ - const TilePos next = state.next(direction); + TilePos next = wrapped(state.next(direction)); const char tile = at(next); - if (tile == '#' || tile == 'D'){ + if (tile == 'v' && direction == Direction::SOUTH){ + next = next.next(Direction::SOUTH); + return at(next) == '#' ? std::nullopt : std::optional(next); + } + if (tile == '#' || tile == 'D' || tile == 'v'){ return std::nullopt; } return next; } - size_t step_tiles(const State&, const State&) const{ - return 1; + size_t step_tiles(const State& from, const State& to) const{ + return to.y - from.y == 2 ? 2 : 1; } bool held_at(const State& state, Direction direction) const{ - return at(state.next(direction)) == '#'; + return at(wrapped(state.next(direction))) != 'D'; } bool wild(const State& state) const{ return at(state) == '"'; @@ -60,6 +67,13 @@ class ToyGame{ } private: + TilePos wrapped(TilePos pos) const{ + if (m_wraps && pos.y >= 0 && pos.y < (int)m_rows.size()){ + const int width = (int)m_rows[pos.y].size(); + pos.x = (pos.x % width + width) % width; + } + return pos; + } char at(const TilePos& pos) const{ if (pos.y < 0 || pos.y >= (int)m_rows.size() || pos.x < 0 || pos.x >= (int)m_rows[pos.y].size()){ return '#'; @@ -68,165 +82,213 @@ class ToyGame{ } std::vector m_rows; + bool m_wraps = false; }; using Legs = std::vector>; +// Legs as "east 2 to wall: (2, 0); south 1 open: (2, 1) (2, 2)", or "none". std::string describe(const std::optional& legs){ if (!legs){ - return " none"; + return "none"; } std::string text; for (const RobustLeg& leg : *legs){ - text += std::format("\n {} {}{} to", direction_name(leg.direction), leg.tiles, leg.to_wall ? " (to wall)" : " (open)"); + text += std::format("{}{} {} {}:", text.empty() ? "" : "; ", direction_name(leg.direction), leg.tiles, leg.to_wall ? "to wall" : "open"); for (const TilePos& pos : leg.after){ - text += std::format(" {}", to_string(pos)); + text += " " + to_string(pos); } } return text; } -std::optional plan(const ToyGame& game, std::vector from, TilePos to, const RobustLegCosts& costs){ - return plan_robust_legs(game, std::move(from), std::function([to](const TilePos& pos){ return pos == to; }), costs); -} - -RobustLegCosts exact_costs(){ - RobustLegCosts costs; - costs.exact_open_tiles = costs.max_open_tiles; - return costs; -} +constexpr RobustLegCosts EXACT{.exact_open_tiles = 12}; -UnitTestResult test_wall_gathers_spread(){ - // The player is on one of two tiles; walking east to the wall puts them - // on the goal either way. - const ToyGame game({ - "...#", - }); - const auto legs = plan(game, {{0, 0}, {1, 0}}, {2, 0}, RobustLegCosts()); - if (!legs || legs->size() != 1 || !(*legs)[0].to_wall || (*legs)[0].tiles != 2 || (*legs)[0].after != std::vector{{2, 0}}){ - return std::format("Expected one leg east 2 to the wall:{}", describe(legs)); - } - return true; -} - -UnitTestResult test_open_leg_spreads(){ - // The goal is in the middle of a row with no wall near it: an open leg - // may end a tile either side, so there is no robust plan. With exact - // open legs, one open leg reaches it. - const ToyGame game({ - "........", - }); - const auto uncertain = plan(game, {{0, 0}}, {3, 0}, RobustLegCosts()); - if (uncertain){ - return std::format("Expected no plan with uncertain open legs:{}", describe(uncertain)); - } - const auto exact = plan(game, {{0, 0}}, {3, 0}, exact_costs()); - if (!exact || exact->size() != 1 || (*exact)[0].to_wall || (*exact)[0].tiles != 3){ - return std::format("Expected one open leg east 3:{}", describe(exact)); - } - return true; -} - -UnitTestResult test_door_is_not_a_wall(){ - // Walking east would stop at the door, but holding on enters it: the - // leg to the goal next to it must be an open one. - const ToyGame game({ - "#..D", - }); - const auto legs = plan(game, {{1, 0}}, {2, 0}, exact_costs()); - if (!legs || legs->size() != 1 || (*legs)[0].to_wall || (*legs)[0].tiles != 1){ - return std::format("Expected one open leg east 1:{}", describe(legs)); - } - return true; -} +struct PlanInput{ + std::string_view name; + std::vector rows; + bool wraps = false; + std::vector from; + TilePos goal; + RobustLegCosts costs; +}; +struct PlanExpectation{ + std::string_view legs; // as describe() writes them +}; +struct PlanCase{ + PlanInput input; + PlanExpectation expectation; +}; -UnitTestResult test_avoids_wander_run(){ - // The top row runs along where someone wanders; the bottom row is one - // longer but clear. - const ToyGame game({ - ".www.", - ".....", - }); - const auto legs = plan(game, {{1, 0}}, {4, 0}, exact_costs()); - if (!legs){ - return "No plan."; - } - for (const RobustLeg& leg : *legs){ - if (leg.direction == Direction::EAST && leg.after[0].y == 0){ - return std::format("Walked east along the wander zone:{}", describe(legs)); +class Test_RobustLegPlanner_Plan : public UnitTest{ +public: + explicit Test_RobustLegPlanner_Plan(PlanCase scenario) + : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.input.name)) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const PlanInput& input = m_scenario.input; + const ToyGame game(input.rows, input.wraps); + const TilePos goal = input.goal; + const std::optional legs = plan_robust_legs(game, input.from, + std::function([goal](const TilePos& pos){ return pos == goal; }), input.costs); + const std::string actual = describe(legs); + if (actual != m_scenario.expectation.legs){ + return std::format("Planned \"{}\", expected \"{}\".", actual, m_scenario.expectation.legs); } + return true; } - return true; -} +private: + PlanCase m_scenario; +}; -UnitTestResult test_cost_of_plan(){ - // A wall leg costs a leg and its tiles; an open one its stop and open - // tiles on top. - const ToyGame game({ - "...#", - }); - RobustLegCosts costs = exact_costs(); - costs.per_open_tile = 2; - const Legs wall{{Direction::EAST, 2, true, {{2, 0}}}}; - const Legs open{{Direction::EAST, 1, false, {{1, 0}}}}; - const long long wall_cost = robust_legs_cost(game, {{0, 0}}, wall, costs); - const long long open_cost = robust_legs_cost(game, {{0, 0}}, open, costs); - if (wall_cost != 8 + 2 || open_cost != 8 + 50 + 3){ - return std::format("Expected costs 10 and 61, got {} and {}.", wall_cost, open_cost); - } - return true; -} +// Open legs on default costs may end a tile either way (two up to 5 tiles). +const PlanCase PLAN_CASES[] = { + { + .input = {.name = "a wall gathers the possible tiles", .rows = {"...#"}, .from = {{0, 0}, {1, 0}}, .goal = {2, 0}}, + .expectation = {.legs = "east 2 to wall: (2, 0)"}, + }, + { + .input = {.name = "no plan ends in the open while open legs may be off", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "an exact open leg ends in the open", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, .costs = EXACT}, + .expectation = {.legs = "east 3 open: (3, 0)"}, + }, + { + .input = { + .name = "open_error_per 0 with no open_error is exact", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, + .costs = {.open_error = 0, .open_error_per = 0}, + }, + .expectation = {.legs = "east 3 open: (3, 0)"}, + }, + { + .input = { + .name = "open_error_per 0 keeps open_error", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, + .costs = {.open_error = 1, .open_error_per = 0}, + }, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "a door is not a wall", .rows = {"#..D"}, .from = {{1, 0}}, .goal = {2, 0}, .costs = EXACT}, + .expectation = {.legs = "east 1 open: (2, 0)"}, + }, + { + .input = {.name = "no leg along a wander zone", .rows = {".www.", "....."}, .from = {{1, 0}}, .goal = {4, 0}, .costs = EXACT}, + .expectation = {.legs = "south 1 to wall: (1, 1); east 3 to wall: (4, 1); north 1 to wall: (4, 0)"}, + }, + { + .input = {.name = "a ledge hop counts 2 tiles", .rows = {".", "v", "."}, .from = {{0, 0}}, .goal = {0, 2}}, + .expectation = {.legs = "south 2 to wall: (0, 2)"}, + }, + { + .input = {.name = "a ledge cannot be climbed", .rows = {".", "v", "."}, .from = {{0, 2}}, .goal = {0, 0}}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "tall grass costs less than a detour", .rows = {".\"\"..", "....."}, .from = {{0, 0}}, .goal = {4, 0}}, + .expectation = {.legs = "east 4 to wall: (4, 0)"}, + }, + { + .input = { + .name = "costly tall grass is walked round", .rows = {".\"\"..", "....."}, .from = {{0, 0}}, .goal = {4, 0}, + .costs = {.per_wild_tile = 20}, + }, + .expectation = {.legs = "south 1 to wall: (0, 1); east 4 to wall: (4, 1); north 1 to wall: (4, 0)"}, + }, + { + // Only an open leg reaches the second row; a wall then gathers. + .input = {.name = "an open leg spreads, a wall gathers", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}}, + .expectation = {.legs = "east 1 open: (1, 0) (2, 0); south 1 to wall: (1, 1) (2, 1); east 2 to wall: (3, 1)"}, + }, + { + .input = { + .name = "a spread wider than max_spread is not planned", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, + .costs = {.max_spread = 1}, + }, + .expectation = {.legs = "none"}, + }, + { + .input = { + .name = "the search gives up past max_searched", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, + .costs = {.max_searched = 1}, + }, + .expectation = {.legs = "none"}, + }, + { + .input = { + .name = "two open legs the same way are one", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, + .costs = {.exact_open_tiles = 12, .max_open_tiles = 2}, + }, + .expectation = {.legs = "east 3 open: (3, 0)"}, + }, + { + .input = {.name = "a walk that is never stopped is not a wall", .rows = {"...."}, .wraps = true, .from = {{0, 0}}, .goal = {2, 0}, .costs = EXACT}, + .expectation = {.legs = "east 2 open: (2, 0)"}, + }, +}; -struct RobustLegPlannerInput{ - std::string name; - UnitTestResult (*test)(); +struct CostInput{ + std::string_view name; + std::vector rows; + TilePos from; + Legs legs; + RobustLegCosts costs; }; - -struct RobustLegPlannerExpectation{ - std::string_view description; +struct CostExpectation{ + long long cost = 0; }; - -struct RobustLegPlannerTestCase{ - RobustLegPlannerInput input; - RobustLegPlannerExpectation expectation; +struct CostCase{ + CostInput input; + CostExpectation expectation; }; -class Test_RobustLegPlanner : public UnitTest{ +class Test_RobustLegPlanner_Cost : public UnitTest{ public: - explicit Test_RobustLegPlanner(RobustLegPlannerTestCase scenario) + explicit Test_RobustLegPlanner_Cost(CostCase scenario) : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.input.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - return m_scenario.input.test(); + const CostInput& input = m_scenario.input; + const ToyGame game(input.rows, false); + const long long actual = robust_legs_cost(game, {input.from}, input.legs, input.costs); + if (actual != m_scenario.expectation.cost){ + return std::format("Cost {} for \"{}\", expected {}.", actual, describe(input.legs), m_scenario.expectation.cost); + } + return true; } - private: - RobustLegPlannerTestCase m_scenario; + CostCase m_scenario; }; -const RobustLegPlannerTestCase ROBUST_LEG_PLANNER_CASES[] = { - { - .input = {.name = "a wall gathers the possible tiles", .test = test_wall_gathers_spread}, - .expectation = {.description = "a leg to a wall ends every possible start on one tile"}, - }, +// Default costs: 8 a leg, 1 a tile, 4 more a grass tile, 50 more for a +// leg that stops in the open. +const CostCase COST_CASES[] = { { - .input = {.name = "an open leg may end a tile off", .test = test_open_leg_spreads}, - .expectation = {.description = "no plan ends on an open tile unless open legs are exact"}, + .input = {.name = "a wall leg costs a leg and its tiles", .rows = {"...#"}, .from = {0, 0}, .legs = {{Direction::EAST, 2, true, {{2, 0}}}}}, + .expectation = {.cost = 8 + 2}, }, { - .input = {.name = "a door is not a wall", .test = test_door_is_not_a_wall}, - .expectation = {.description = "a stop that does not hold the player is not a wall leg"}, + .input = { + .name = "an open leg costs its stop and open tiles on top", .rows = {"...#"}, .from = {0, 0}, + .legs = {{Direction::EAST, 1, false, {{1, 0}}}}, .costs = {.exact_open_tiles = 12, .per_open_tile = 2}, + }, + .expectation = {.cost = 8 + 50 + 3}, }, { - .input = {.name = "no leg along a wander zone", .test = test_avoids_wander_run}, - .expectation = {.description = "goes round a row where someone wanders"}, + .input = {.name = "each grass tile entered costs extra", .rows = {".\"\"#"}, .from = {0, 0}, .legs = {{Direction::EAST, 2, true, {{2, 0}}}}}, + .expectation = {.cost = 8 + 2 + 2 * 4}, }, { - .input = {.name = "cost of given legs", .test = test_cost_of_plan}, - .expectation = {.description = "charges a wall leg its tiles and an open leg its stop on top"}, + .input = { + .name = "a cost with open_error_per 0", .rows = {"........"}, .from = {0, 0}, + .legs = {{Direction::EAST, 3, false, {{3, 0}}}}, .costs = {.open_error_per = 0}, + }, + .expectation = {.cost = 8 + 50 + 3}, }, }; @@ -234,8 +296,11 @@ const RobustLegPlannerTestCase ROBUST_LEG_PLANNER_CASES[] = { void add_tests_RobustLegPlanner(UnitTestDatabase& database){ - for (const auto& scenario : ROBUST_LEG_PLANNER_CASES){ - database.add(scenario); + for (const PlanCase& scenario : PLAN_CASES){ + database.add(scenario); + } + for (const CostCase& scenario : COST_CASES){ + database.add(scenario); } } From d76aa604da3ffd33ffb43cfc29270e8c1ba80daa Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:20:48 -0800 Subject: [PATCH 26/47] BDSP AutoStory: connected-world test checks for a missing plan world; connected_maps() refuses temporaries (#411 review) Each row names its plan world's two places, and a pair that is renamed or dropped fails with their names instead of dereferencing null. Test fields get defaults and designated names. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 2 + ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 45 +++++++++---------- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index 819915568b..b7c57f01db 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -120,6 +120,8 @@ class StoryWorld{ // meet. Tiles blocked or taken off the maps are not in them. The view // lasts until the world's next add(). Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); +// A temporary world would be gone before the view is used. +Pokemon::ConnectedMaps connected_maps(StoryWorld&& world) = delete; // The rules of walking on a story world, from its tiles. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 647f2cbaa7..37e501f309 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -12,6 +12,7 @@ #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" @@ -259,12 +260,16 @@ std::optional edge_mismatch(const StoryWorld& world){ } struct ConnectedWorldInput{ - std::string name; - const StoryWorld& (*world)(); + std::string_view name; + // The story's plan world between two places (story_plan_world()), or, + // if `world` is set, that world. + std::string_view plan_from = {}; + std::string_view plan_to = {}; + const StoryWorld& (*world)() = nullptr; }; struct ConnectedWorldExpectation{ // Connections over all the maps: two for each pair that meets. - size_t connections; + size_t connections = 0; }; struct ConnectedWorldCase{ ConnectedWorldInput input; @@ -278,7 +283,14 @@ class Test_ConnectedStoryWorld : public UnitTest{ , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const StoryWorld& world = m_case.input.world(); + const ConnectedWorldInput& input = m_case.input; + const StoryWorld* found = input.world != nullptr + ? &input.world() + : story_plan_world(std::string(input.plan_from), std::string(input.plan_to)); + if (found == nullptr){ + return std::format("No story plan world from {} to {}.", input.plan_from, input.plan_to); + } + const StoryWorld& world = *found; if (std::optional error = edge_mismatch(world)){ return *error; } @@ -297,42 +309,29 @@ class Test_ConnectedStoryWorld : public UnitTest{ ConnectedWorldCase m_case; }; -const StoryWorld& south_plan_world(){ - return *story_plan_world("TwinleafTown", "Route202"); -} -const StoryWorld& route_203_plan_world(){ - return *story_plan_world("Route203", "JubilifeCity"); -} -const StoryWorld& route_204_south_plan_world(){ - return *story_plan_world("JubilifeCity", "Route204South"); -} -const StoryWorld& route_204_north_plan_world(){ - return *story_plan_world("Route204North", "FloaromaTown"); -} - const ConnectedWorldCase CONNECTED_WORLD_CASES[] = { { - .input = {"Route 201, Sandgem and Route 202", story_maps}, + .input = {.name = "Route 201, Sandgem and Route 202", .world = story_maps}, .expectation = {.connections = 4}, }, { - .input = {"Twinleaf to Route 202", south_plan_world}, + .input = {.name = "Twinleaf to Route 202", .plan_from = "TwinleafTown", .plan_to = "Route202"}, .expectation = {.connections = 8}, }, { - .input = {"Route 203 into Jubilife", route_203_plan_world}, + .input = {.name = "Route 203 into Jubilife", .plan_from = "Route203", .plan_to = "JubilifeCity"}, .expectation = {.connections = 2}, }, { - .input = {"Jubilife up Route 204's south half", route_204_south_plan_world}, + .input = {.name = "Jubilife up Route 204's south half", .plan_from = "JubilifeCity", .plan_to = "Route204South"}, .expectation = {.connections = 2}, }, { - .input = {"Route 204's north half into Floaroma", route_204_north_plan_world}, + .input = {.name = "Route 204's north half into Floaroma", .plan_from = "Route204North", .plan_to = "FloaromaTown"}, .expectation = {.connections = 2}, }, { - .input = {"Jubilife alone", jubilife_maps}, + .input = {.name = "Jubilife alone", .world = jubilife_maps}, .expectation = {.connections = 0}, }, }; From 96f8ad74ed09566f43610fff96534084b7df25bc Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:21:28 -0800 Subject: [PATCH 27/47] BDSP AutoStory: a field-count guard on the copy into the shared robust costs (#413 review) robust_leg_costs() copies BDSP's costs field by field; a static_assert that names every field of Pokemon::RobustLegCosts now stops the build when the shared struct grows, so a new field can't silently take the shared default. per_wander_tile stays BDSP's own, so the lab's town cost carries over. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_RoutePlanner.cpp | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index 872e11d171..e6ff4357e8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -251,6 +251,22 @@ class RobustWorldModel{ const StoryWorld& m_world; }; +// Names every field of Pokemon::RobustLegCosts, in order, so it stops +// compiling when the shared costs gain or lose one: add the new field to +// robust_leg_costs() below (and to RobustPlanCosts if BDSP sets it), so it +// can't silently keep the shared default. +constexpr bool robust_leg_costs_fields_copied(){ + [[maybe_unused]] const auto& [ + per_tile, per_wild_tile, per_wander_tile, per_leg, leg_not_at_wall, + open_error, open_error_per, exact_open_tiles, per_open_tile, + max_open_tiles, max_spread, max_searched + ] = Pokemon::RobustLegCosts{}; + return true; +} +static_assert(robust_leg_costs_fields_copied()); + +// BDSP's costs as the shared planner's, field by field. per_wander_tile is +// BDSP's own (town_plan_costs() may raise it), never the shared default. Pokemon::RobustLegCosts robust_leg_costs(const RobustPlanCosts& costs){ Pokemon::RobustLegCosts ret; ret.per_tile = costs.per_tile; From 213ceb78aaee19d59cbe9d8a0359047bb966a799 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:25:48 -0800 Subject: [PATCH 28/47] Pokemon Navigation: stale-place cases carry their expectation (code health) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon_ConnectedMaps_Tests.cpp | 22 ++++++++++++++----- 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp index abcc99f641..ceafa9304d 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp @@ -208,8 +208,13 @@ struct StalePlaceInput{ std::string_view name; size_t map; }; +struct StalePlaceExpectation{ + // Whether reading the place throws InternalProgramError. + bool rejected = false; +}; struct StalePlaceCase{ StalePlaceInput input; + StalePlaceExpectation expectation; }; // A place whose map index is past the loaded maps (from another world, or @@ -223,21 +228,26 @@ class Test_ConnectedMaps_StalePlace : public UnitTest{ virtual UnitTestResult run(Logger&, CancellableScope&) const override{ const ConnectedMaps world(test_maps()); const MapPlace stale{m_scenario.input.map, {0, 0}}; + bool rejected = false; try{ - const std::optional place = world.neighbour(stale, Direction::NORTH); - return std::format("Map {} of {} was read: got {}, expected an InternalProgramError.", - stale.map, world.size(), place ? to_string(place->tile) : "nowhere"); + world.neighbour(stale, Direction::NORTH); }catch (const InternalProgramError&){ - return true; + rejected = true; + } + if (rejected != m_scenario.expectation.rejected){ + return std::format("Map {} of {} was {}, expected it {}.", stale.map, world.size(), + rejected ? "rejected" : "read", m_scenario.expectation.rejected ? "rejected" : "read"); } + return true; } private: StalePlaceCase m_scenario; }; const StalePlaceCase STALE_PLACE_CASES[] = { - {.input = {.name = "a map index one past the last is rejected", .map = 4}}, - {.input = {.name = "a map index far past the last is rejected", .map = 1000}}, + {.input = {.name = "the last map index is read", .map = 3}, .expectation = {.rejected = false}}, + {.input = {.name = "a map index one past the last is rejected", .map = 4}, .expectation = {.rejected = true}}, + {.input = {.name = "a map index far past the last is rejected", .map = 1000}, .expectation = {.rejected = true}}, }; From 9f6cf8e57f546db69fd9efc7d9db937240fc4169 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:29:11 -0800 Subject: [PATCH 29/47] BDSP maps: pin PokemonSimulation 438b672; the Poketch Company clown wanders on row 18 only PokemonSimulation #90 keeps Diamond's range (1, 0) for the Poketch Company clown: x 14..16 on row 18, so 00.05b's company_clown talk from (15, 19) facing north finds him in the row above. #89's 3x3 box let the sim stand him on the talk tile. The Mart clown keeps (1, 1). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- devtools/maps/map-resources.lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 6c923a3ddf..7ce46c4b43 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "bdsp": { - "revision": "ed318db8f7213cf297321d03b3e2463779339c0f", + "revision": "438b67207a2d0e10419c31c1c541520aace7e86e", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "cbfbbf56b55f509773909217e201fc8e2a4b5f0ed688dbb6ec36c05f381d5dfb" + "manifest_sha256": "50c0ac960d5010db8ebf192960cdc556756696679867f2225fddbd8c868d4001" } } } From aad90b2cdee88110ad1a6b5f613ae106d8a0ca6f Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:50:03 -0800 Subject: [PATCH 30/47] BDSP AutoStory: the route sweep walks at the player's pace The timed-holds sweep planned every story route at a walk while its simulated console timed every wall walk at a run (the walker holds B on walls), so a long wall leg read as a few tiles short of the wall: 00.05b below_the_mart_clown ran 8 tiles to (56, 36), read about 5, tapped and waited at the wall, and re-planned into the Mart's wall. The sweep now plans and times at a run after the running shoes (RUNNING_SHOES_ROW), as the story's walk steps do, and at a walk before them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp index e85849305c..b3d956ffd4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp @@ -79,7 +79,7 @@ class SimulatedRouteIO : public RouteIO{ virtual WalkResult walk_to_wall(const RouteWallWalk& walk) override{ count_call(); - const MoveSpeed speed = walk.options.pace == DpadPace::RUN ? MoveSpeed::RUN : MoveSpeed::WALK; + const MoveSpeed speed = walk.options.pace == DpadPace::RUN && m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK; const Milliseconds per_tile = route_ms_per_tile(walk.direction, speed); if (m_overshoot && walk.limit > ROUTE_START_DELAY){ // A hold timed for n tiles (ROUTE_START_DELAY, then half a @@ -102,6 +102,11 @@ class SimulatedRouteIO : public RouteIO{ void overshoot_timed_holds(bool overshoot){ m_overshoot = overshoot; } + // Before the running shoes, a walk held with B is still a walk: its + // time counts walking tiles, as the walker's plan speed does. + void set_can_run(bool can_run){ + m_can_run = can_run; + } virtual WalkResult walk_taps(Direction direction, size_t tiles, const std::string&) override{ count_call(); const size_t moved = move(direction, tiles); @@ -172,6 +177,7 @@ class SimulatedRouteIO : public RouteIO{ size_t m_calls = 0; size_t m_walked = 0; bool m_overshoot = false; + bool m_can_run = true; }; StoryWorld jubilife_world(){ @@ -299,6 +305,7 @@ UnitTestResult test_jubilife_center_kids(Logger&){ // One ROUTE step of the story table, from where the steps before it end. struct StoryRoute{ std::string name; + MoveSpeed speed; Pose from; Pose goal; std::string costs; @@ -311,7 +318,8 @@ void add_story_route(const std::string& row, const StoryStep& step, std::optiona if (step.kind == StoryStepKind::ROUTE){ const Pose goal = Pokemon::pose_of(Pokemon::story_arg(step.args, "target")); if (at){ - routes.push_back({std::format("{} {}", row, step.name), *at, goal, step.action}); + const MoveSpeed speed = row > std::string(RUNNING_SHOES_ROW) ? MoveSpeed::RUN : MoveSpeed::WALK; + routes.push_back({std::format("{} {}", row, step.name), speed, *at, goal, step.action}); } at = goal; }else{ @@ -356,6 +364,7 @@ std::string sweep_story_route(const StoryRoute& route, bool overshoot, std::vect std::vector notes; SimulatedRouteIO io(*world, from, {}, notes); io.overshoot_timed_holds(overshoot); + io.set_can_run(route.speed == MoveSpeed::RUN); RouteTrainers trainers{.sights = story_trainers(*world), .fight = [](const std::string&){}}; try{ walk_route(io, *world, start, trainers, { @@ -363,7 +372,7 @@ std::string sweep_story_route(const StoryRoute& route, bool overshoot, std::vect .label = route.name, .avoid = {}, .costs = *costs, - .speed = MoveSpeed::WALK, + .speed = route.speed, }); }catch (const RouteFailed& e){ std::string last; From 90386653435aaab1cdc4a086681aec8b05e56be5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 00:53:46 -0800 Subject: [PATCH 31/47] BDSP AutoStory: in the route sweep a walk to a wall never overshoots The sweep's simulated console ran every walk to a wall with a limit past its limit's tiles when timed holds overshot, and reported the whole limit as walked: the walker read a leg that reached its wall as held up 0 tiles short (00.05b, 00.05c below_the_mart_clown). walk_route() walks only legs to a wall through walk_to_wall(), and a walk to a wall ends at the wall, as the overshoot fault's own comment says; the fault stays on stick holds. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp index b3d956ffd4..02fb9a10d3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp @@ -81,15 +81,8 @@ class SimulatedRouteIO : public RouteIO{ count_call(); const MoveSpeed speed = walk.options.pace == DpadPace::RUN && m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK; const Milliseconds per_tile = route_ms_per_tile(walk.direction, speed); - if (m_overshoot && walk.limit > ROUTE_START_DELAY){ - // A hold timed for n tiles (ROUTE_START_DELAY, then half a - // tile under n) goes on past them until a wall stops it. - const size_t tiles = (size_t)((walk.limit - ROUTE_START_DELAY + per_tile / 2) / per_tile); - const size_t want = tiles + (tiles * 35 + 99) / 100; - const size_t moved = move(walk.direction, want); - return {.stop = moved < want ? WalkStop::BLOCKED : WalkStop::LIMIT, .walked = walk.limit, - .wild_battles = 0, .moved_chunks = moved}; - } + // walk_route() walks only legs to a wall here, and a walk to a wall + // ends at the wall: no overshoot (overshoot_timed_holds()). const size_t moved = move(walk.direction, SIZE_MAX); return {.stop = WalkStop::BLOCKED, .walked = ROUTE_START_DELAY + 800ms + per_tile * moved + per_tile / 2, .wild_battles = 0, .moved_chunks = moved}; From 2df832f328dc69b13e24cc048680f8ca8ca6cda7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 01:01:00 -0800 Subject: [PATCH 32/47] BDSP AutoStory: the route sweep's console fake has four test knobs (code-health tag) Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp index 02fb9a10d3..123a171f38 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp @@ -60,7 +60,7 @@ struct RouteFailed{ // The console as a small simulator: the player stands on one tile of // `world`, walls and `obstacles` stop them, and every walk and tap moves // them. Fails the case after `max_calls` calls (a walker that loops). -// code-health: allow public_methods -- a RouteIO fake: the interface's seven overrides plus three test knobs +// code-health: allow public_methods -- a RouteIO fake: the interface's seven overrides plus four test knobs class SimulatedRouteIO : public RouteIO{ public: SimulatedRouteIO(const StoryWorld& world, TilePos at, std::vector obstacles, std::vector& notes) From 9b22df605f0f78b6c83700ebc24d22009bc6807e Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 01:36:41 -0800 Subject: [PATCH 33/47] BDSP AutoStory walk: someone in the way who talks is the blocker (red) lab-B 2026-11-12 01:22, 00.05c below_the_company_clown: an open leg west was blocked by someone the map lacks, and the taps after the wait opened their talk (the Global Wonder Station's woman, BDSP only). The walker took it for a trainer the map lacks, "fought" with no battle, replanned from the leg's end into her again, and failed on the third talk. This scripted walk wants her tile marked and the replan from where the leg stopped. It fails now: the talk is fought and nothing is marked. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...kemonBDSP_AutoStory_PlannedRoute_Tests.cpp | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp index 717eca1e09..a72e8ebfa2 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp @@ -497,6 +497,47 @@ UnitTestResult test_never_moved_plans_from_the_start(Logger& logger){ return replan.empty() ? UnitTestResult(true) : UnitTestResult(replan); } +// lab-B 2026-11-12 01:22 (00.05c below_the_company_clown): an open leg +// west was blocked by someone the map lacks, and the taps after the wait +// opened their talk (the Global Wonder Station's woman). Taken for a +// trainer, the talk was "fought", no battle followed, and the replans +// walked into her again until the third talk failed the step. Whoever +// talks as we tap on after a block is the one in the way: their tile is +// marked, and the walk plans again from where it stopped. +UnitTestResult test_open_leg_blocker_talks(Logger& logger){ + Script script{.steps = { + press_step("D-pad west 50 ms x1"), + walk_step("6 taps: T: west 6 (open)", WalkStop::BLOCKED, 2000ms, 2), + press_step("wait 2500 ms x1"), + walk_step("4 taps: T: west 6 (open): the rest", WalkStop::DIALOG, 800ms, 0), + }}; + // West along Route 202's row 5, as test_open_leg_known_trainer() walks + // it, with no trainer: the one in the way stands on (27, 5). + ScriptedWalk walk; + try{ + walk = walk_script(route202_world(), {30, 5}, {24, 5}, {}, script); + }catch (const ScriptMismatch&){ + // The walk after the replan is not scripted. + } + for (const std::string& note : script.notes){ + logger.log(note); + } + if (!walk.failure.empty()){ + return "failed: " + walk.failure; + } + if (script.next != script.steps.size()){ + return script_left(script); + } + const auto marked = std::find_if(script.notes.begin(), script.notes.end(), [](const std::string& note){ + return note.find("marked it") != std::string::npos && note.find("(27, 5)") != std::string::npos; + }); + if (marked == script.notes.end()){ + return "the tile of whoever talked, (27, 5), was not marked."; + } + const std::string replan = check_replan_from(script, {"Route 202 (28, 5)"}); + return replan.empty() ? UnitTestResult(true) : UnitTestResult(replan); +} + // A leg to the wall two tiles away that runs out of time after one tile // (one chunk moved): someone stands in it, as Route 204's youngster did on // 01.08's "west 2 (to wall)" (lab-B 2026-11-08). The check at the wall @@ -607,6 +648,10 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .input = {"a known trainer stops an open leg", test_open_leg_known_trainer}, .expectation = {}, }, + { + .input = {"someone in the way who talks is marked, not fought (lab-B 2026-11-12, 00.05c)", test_open_leg_blocker_talks}, + .expectation = {}, + }, { .input = {"a person a tile ahead on a short leg is waited out", test_short_leg_waits_for_the_way}, .expectation = {}, From a4daa26e3a58b97526cf8fee374faff9b33b41ad Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 01:36:42 -0800 Subject: [PATCH 34/47] BDSP AutoStory walk: mark someone in the way who talks, and go round An open leg blocked, waited out, whose remaining taps end in a talk without moving: whoever talked is the one in the way. Close the talk, mark their tile as blocked_open_leg() marks a blocker, and plan again from where the leg stopped, instead of fighting an unknown trainer and walking into them again (lab-B 2026-11-12, 00.05c). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_PlannedRoute.cpp | 22 +++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index 61ce5b2633..77df611e85 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -272,6 +272,8 @@ class RouteWalker{ LegNext interrupted_open_leg(LegWalk& walk); void turn_tap(LegWalk& walk); LegNext blocked_open_leg(LegWalk& walk, size_t moved); + LegNext talking_blocker(LegWalk& walk, size_t moved); + LegNext mark_and_replan(LegWalk& walk, size_t moved); // After each leg. void check_banners(LegWalk& walk); @@ -618,6 +620,9 @@ LegNext RouteWalker::open_leg(LegWalk& walk){ std::to_string(leg.tiles) + " tiles; waiting for the way to clear.", RouteNote::WARNING); m_io.press(WAIT_FOR_THE_WAY); const WalkResult rest = m_io.walk_taps(leg.direction, leg.tiles - moved, walk.label + ": the rest"); + if (rest.stop == WalkStop::DIALOG && rest.moved_chunks == 0 && rest.wild_battles == 0){ + return talking_blocker(walk, moved); + } moved = std::min(leg.tiles, moved + rest.moved_chunks); walk.result.stop = rest.stop; walk.result.walked += rest.walked; @@ -670,6 +675,23 @@ void RouteWalker::turn_tap(LegWalk& walk){ LegNext RouteWalker::blocked_open_leg(LegWalk& walk, size_t moved){ talk_to_blocker(walk.label); + return mark_and_replan(walk, moved); +} + +// Someone in the way who talks as we tap on after the wait: the one who +// blocked us, not a trainer the map lacks. Fought as a trainer, they were +// walked into again on every replan (lab-B 2026-11-12, 00.05c: the Global +// Wonder Station's woman, three talks, then the step failed). Close the +// talk, mark their tile and plan again from where we stopped. +LegNext RouteWalker::talking_blocker(LegWalk& walk, size_t moved){ + m_io.note(walk.label + ": someone in the way talked to us; going round them.", RouteNote::STATUS); + m_trainers.fight("someone in the way"); + return mark_and_replan(walk, moved); +} + +// The tiles a blocked open leg may have stopped on after `moved` tiles: +// what stopped it goes on the map, and the walk plans again from them. +LegNext RouteWalker::mark_and_replan(LegWalk& walk, size_t moved){ std::vector stopped; for (const TilePos& pos : m_from){ const std::vector path = leg_path(m_grid, pos, walk.planned.leg.direction, moved); From 8d9b47f9e4fbcf766f22e4dfc708f248cce5af84 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 02:04:02 -0800 Subject: [PATCH 35/47] BDSP AutoStory walk: a marked talker is no wall for the replan (red) lab-B 2026-11-12 01:55, 00.05c below_the_company_clown again: with the woman who talked marked, the replan from her tile's neighbour and the tile behind it began "west 1 (to wall)" against her. Walking into her opened her talk again, fought as a trainer, and the walk on ran out of time short of the "wall". This scripted walk fails now: the first call after the replan is a walk to a wall west, into her. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...kemonBDSP_AutoStory_PlannedRoute_Tests.cpp | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp index a72e8ebfa2..5590f1f3f1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp @@ -538,6 +538,37 @@ UnitTestResult test_open_leg_blocker_talks(Logger& logger){ return replan.empty() ? UnitTestResult(true) : UnitTestResult(replan); } +// lab-B 2026-11-12 01:55 (00.05c below_the_company_clown, again): with +// the woman who talked marked at (45, 24), the plan from (46, 24) and the +// tile behind it began "west 1 (to wall)" against her. Walking into her +// opened her talk again, which was fought as a trainer, and the walk on +// ran out of time short of the "wall". A person is no wall: the walk after +// the replan must not walk to a wall into the tile it marked. +UnitTestResult test_marked_talker_is_no_wall(Logger& logger){ + Script script{.steps = { + press_step("D-pad west 50 ms x1"), + walk_step("6 taps: T: west 6 (open)", WalkStop::BLOCKED, 2000ms, 2), + press_step("wait 2500 ms x1"), + walk_step("4 taps: T: west 6 (open): the rest", WalkStop::DIALOG, 800ms, 0), + }}; + std::string after_replan; + try{ + walk_script(route202_world(), {30, 5}, {24, 5}, {}, script); + }catch (const ScriptMismatch& mismatch){ + after_replan = mismatch.message; + } + for (const std::string& note : script.notes){ + logger.log(note); + } + if (script.next != script.steps.size()){ + return script_left(script); + } + if (after_replan.find("\"wall: ") != std::string::npos && after_replan.find("west") != std::string::npos){ + return "after the replan the walk went to a wall west, into the one who talked: " + after_replan; + } + return UnitTestResult(true); +} + // A leg to the wall two tiles away that runs out of time after one tile // (one chunk moved): someone stands in it, as Route 204's youngster did on // 01.08's "west 2 (to wall)" (lab-B 2026-11-08). The check at the wall @@ -652,6 +683,10 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .input = {"someone in the way who talks is marked, not fought (lab-B 2026-11-12, 00.05c)", test_open_leg_blocker_talks}, .expectation = {}, }, + { + .input = {"a marked talker is no wall for the replan (lab-B 2026-11-12, 00.05c)", test_marked_talker_is_no_wall}, + .expectation = {}, + }, { .input = {"a person a tile ahead on a short leg is waited out", test_short_leg_waits_for_the_way}, .expectation = {}, From 14b2b77dfdc5e159ddf9c4e596c5c57c55974c09 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 02:10:46 -0800 Subject: [PATCH 36/47] BDSP AutoStory walk: someone who talked is marked as no wall A tile marked for whoever talked was blocked like a wall, so the replan from the tiles beside her began "west 1 (to wall)" against her, walked into her and opened her talk again (lab-B 2026-11-12 01:55, 00.05c). A person may turn, talk or walk off: their tile now comes off our map (StoryWorld::uncover()), which no leg to a wall ends against, on every path that found them by a talk: the open leg's talk after the wait, and the A pressed at a blocker on open legs and legs to a wall. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_PlannedRoute.cpp | 56 ++++++++++++------- 1 file changed, 36 insertions(+), 20 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index 77df611e85..e65dbe2553 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -199,6 +199,15 @@ enum class LegNext{ ARRIVED_EARLY, // through a warp at the leg's end (walk_route_to_warp()) SCENE, // the next step's scene started (RouteWalkPlan::scene_next) }; +// What stopped a walk on a tile the map has free. A person (someone who +// talked) may turn, talk again or walk off: no wall to stop against, so +// their tile is taken off our map rather than blocked (StoryWorld::uncover()), +// and no leg to a wall ends against them (lab-B 2026-11-12, 00.05c). +enum class Blocker{ + THING, + PERSON, +}; + // How far past a leg's end a walk that ran on may have gone. constexpr size_t WARP_SLIDE_TILES = 2; @@ -273,7 +282,7 @@ class RouteWalker{ void turn_tap(LegWalk& walk); LegNext blocked_open_leg(LegWalk& walk, size_t moved); LegNext talking_blocker(LegWalk& walk, size_t moved); - LegNext mark_and_replan(LegWalk& walk, size_t moved); + LegNext mark_and_replan(LegWalk& walk, size_t moved, Blocker blocker); // After each leg. void check_banners(LegWalk& walk); @@ -282,9 +291,9 @@ class RouteWalker{ LegNext unknown_trainer(LegWalk& walk, const std::vector>& paths); LegNext known_trainer(LegWalk& walk, const std::vector>& paths, const std::vector& watching); - void talk_to_blocker(const std::string& leg_label); + Blocker talk_to_blocker(const std::string& leg_label); LegNext replan_from(const LegWalk& walk, std::vector stopped, const std::string& why); - void mark_blocker(const LegWalk& walk, const std::vector& stopped); + void mark_blocker(const LegWalk& walk, const std::vector& stopped, Blocker blocker); void mark_tiles_past(const LegWalk& walk, const std::vector& stopped); RouteIO& m_io; @@ -522,7 +531,7 @@ size_t RouteWalker::unstick_wall_leg(LegWalk& walk, size_t walked_tiles, size_t LegNext RouteWalker::stopped_short_of_wall(LegWalk& walk, size_t walked_tiles){ // Someone who stays put: talk to them. A trainer we walked up to from // the side starts the battle this way. - talk_to_blocker(walk.label); + const Blocker blocker = talk_to_blocker(walk.label); // A walk that never moved is where it began (never_moved()); any other // stop may be a tile either side of the tiles its time counts. const size_t last = never_moved(walk.result, walked_tiles) ? 0 : walked_tiles + 1; @@ -537,7 +546,7 @@ LegNext RouteWalker::stopped_short_of_wall(LegWalk& walk, size_t walked_tiles){ if (stopped.empty()){ fail(m_io, walk.label + ": stopped early, and no tile fits."); } - mark_blocker(walk, stopped); + mark_blocker(walk, stopped, blocker); if (never_moved(walk.result, walked_tiles)){ mark_tiles_past(walk, stopped); } @@ -674,8 +683,8 @@ void RouteWalker::turn_tap(LegWalk& walk){ } LegNext RouteWalker::blocked_open_leg(LegWalk& walk, size_t moved){ - talk_to_blocker(walk.label); - return mark_and_replan(walk, moved); + const Blocker blocker = talk_to_blocker(walk.label); + return mark_and_replan(walk, moved, blocker); } // Someone in the way who talks as we tap on after the wait: the one who @@ -686,19 +695,19 @@ LegNext RouteWalker::blocked_open_leg(LegWalk& walk, size_t moved){ LegNext RouteWalker::talking_blocker(LegWalk& walk, size_t moved){ m_io.note(walk.label + ": someone in the way talked to us; going round them.", RouteNote::STATUS); m_trainers.fight("someone in the way"); - return mark_and_replan(walk, moved); + return mark_and_replan(walk, moved, Blocker::PERSON); } // The tiles a blocked open leg may have stopped on after `moved` tiles: // what stopped it goes on the map, and the walk plans again from them. -LegNext RouteWalker::mark_and_replan(LegWalk& walk, size_t moved){ +LegNext RouteWalker::mark_and_replan(LegWalk& walk, size_t moved, Blocker blocker){ std::vector stopped; for (const TilePos& pos : m_from){ const std::vector path = leg_path(m_grid, pos, walk.planned.leg.direction, moved); stopped.push_back(moved == 0 || path.empty() ? pos : path[std::min(moved, path.size()) - 1]); } stopped = sorted_unique(std::move(stopped)); - mark_blocker(walk, stopped); + mark_blocker(walk, stopped, blocker); if (moved == 0){ mark_tiles_past(walk, stopped); } @@ -873,25 +882,32 @@ LegNext RouteWalker::known_trainer(LegWalk& walk, const std::vector& stopped){ +void RouteWalker::mark_blocker(const LegWalk& walk, const std::vector& stopped, Blocker blocker){ if (stopped.size() != 1){ return; } - const TilePos blocker = stopped[0].next(walk.planned.leg.direction); - m_grid.block(blocker); - m_io.note("[Route] " + walk.label + ": something the map lacks is at " + - describe(m_maps, blocker) + "; marked it.", RouteNote::WARNING); + const TilePos pos = stopped[0].next(walk.planned.leg.direction); + if (blocker == Blocker::PERSON){ + m_grid.uncover(pos); + }else{ + m_grid.block(pos); + } + m_io.note("[Route] " + walk.label + ": " + (blocker == Blocker::PERSON ? "someone" : "something") + + " the map lacks is at " + describe(m_maps, pos) + "; marked it" + + (blocker == Blocker::PERSON ? " (no wall to stop against)." : "."), RouteNote::WARNING); } // A walk that never moved from several possible tiles: whatever stopped it From 694414f737aef42a951f955ca41513db54b4cb23 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 02:14:25 -0800 Subject: [PATCH 37/47] BDSP AutoStory walk: the marked-talker fix within the file's line budget Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_PlannedRoute.cpp | 46 ++++++------------- 1 file changed, 15 insertions(+), 31 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index e65dbe2553..178553ff52 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -199,15 +199,8 @@ enum class LegNext{ ARRIVED_EARLY, // through a warp at the leg's end (walk_route_to_warp()) SCENE, // the next step's scene started (RouteWalkPlan::scene_next) }; -// What stopped a walk on a tile the map has free. A person (someone who -// talked) may turn, talk again or walk off: no wall to stop against, so -// their tile is taken off our map rather than blocked (StoryWorld::uncover()), -// and no leg to a wall ends against them (lab-B 2026-11-12, 00.05c). -enum class Blocker{ - THING, - PERSON, -}; - +// What stopped a walk where the map has nothing (see mark_blocker()). +enum class Blocker{ THING, PERSON }; // How far past a leg's end a walk that ran on may have gone. constexpr size_t WARP_SLIDE_TILES = 2; @@ -683,15 +676,11 @@ void RouteWalker::turn_tap(LegWalk& walk){ } LegNext RouteWalker::blocked_open_leg(LegWalk& walk, size_t moved){ - const Blocker blocker = talk_to_blocker(walk.label); - return mark_and_replan(walk, moved, blocker); + return mark_and_replan(walk, moved, talk_to_blocker(walk.label)); } -// Someone in the way who talks as we tap on after the wait: the one who -// blocked us, not a trainer the map lacks. Fought as a trainer, they were -// walked into again on every replan (lab-B 2026-11-12, 00.05c: the Global -// Wonder Station's woman, three talks, then the step failed). Close the -// talk, mark their tile and plan again from where we stopped. +// Someone in the way who talks as we tap on after the wait is the one who +// blocked us, not a trainer the map lacks (lab-B 2026-11-12, 00.05c). LegNext RouteWalker::talking_blocker(LegWalk& walk, size_t moved){ m_io.note(walk.label + ": someone in the way talked to us; going round them.", RouteNote::STATUS); m_trainers.fight("someone in the way"); @@ -885,29 +874,24 @@ LegNext RouteWalker::known_trainer(LegWalk& walk, const std::vector& stopped, Blocker blocker){ if (stopped.size() != 1){ return; } const TilePos pos = stopped[0].next(walk.planned.leg.direction); - if (blocker == Blocker::PERSON){ - m_grid.uncover(pos); - }else{ - m_grid.block(pos); - } - m_io.note("[Route] " + walk.label + ": " + (blocker == Blocker::PERSON ? "someone" : "something") + - " the map lacks is at " + describe(m_maps, pos) + "; marked it" + - (blocker == Blocker::PERSON ? " (no wall to stop against)." : "."), RouteNote::WARNING); + const bool person = blocker == Blocker::PERSON; + person ? m_grid.uncover(pos) : m_grid.block(pos); + m_io.note(std::format("[Route] {}: {} the map lacks is at {}; marked it{}", walk.label, person ? "someone" : "something", + describe(m_maps, pos), person ? " (no wall to stop against)." : "."), RouteNote::WARNING); } // A walk that never moved from several possible tiles: whatever stopped it From 7e9cd2ae0b5d016697ff91a96b9faebfcdcd3cbf Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 02:31:47 -0800 Subject: [PATCH 38/47] BDSP AutoStory 00.05c: the walk from the street keeps off the Wonder Station's plaza (red) From (58, 22) the walk to the Poketch Company's clown plans "west 43" along row 22, through the plaza where BDSP's Global Wonder Station stands (lab-B 2026-11-12: stopped at (50, 22), (51, 21), (49, 23), the woman at (45, 24)). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...PokemonBDSP_AutoStory_StoryTable_Tests.cpp | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp index 9e737a1493..b6b12a0555 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -444,6 +444,40 @@ UnitTestResult test_jubilife_routes_cross_no_wander_zone(Logger& logger){ return out.empty() ? UnitTestResult(true) : UnitTestResult("ROUTE steps:" + out); } +// 00.05c's walk to the Poketch Company's clown from the street (58, 22), +// where the checkpoint starts on a rerun from 01.01's start, keeps off the +// plaza (44..52, 20..24). BDSP put the Global Wonder Station there, a round +// wall with people round it that pret's Diamond map lacks: on lab-B +// (2026-11-12 01:22 and 01:55) the walk west was stopped at (50, 22), +// (51, 21) and (49, 23), and talked to the woman at (45, 24) until the +// step failed. +UnitTestResult test_company_clown_from_the_street_keeps_off_the_plaza(Logger& logger){ + for (TableRoute route : table_routes()){ + if (route.row != "00.05c" || route.step->name != "below_the_company_clown" || route.world == nullptr){ + continue; + } + route.from = Pokemon::tile_pose("JubilifeCity", {{58, 22}}, Direction::EAST); + const RouteStepPlan plan = plan_table_route(route); + if (!plan.legs){ + return "00.05c below_the_company_clown: no plan from (58, 22)."; + } + const StoryWorld& world = *route.world; + for (const PlannedLeg& planned : *plan.legs){ + logger.log("00.05c below_the_company_clown from (58, 22): " + to_string(planned)); + } + const auto plaza = [&](const TilePos& pos){ + const std::optional local = story_to_local(world, "JubilifeCity", pos); + return local && local->x >= 44 && local->x <= 52 && local->y >= 20 && local->y <= 24; + }; + const auto [most, leg] = most_zone_tiles(world, plan.start, *plan.legs, plaza); + if (most > 0){ + return std::format("the leg {} walks {} tile(s) of the plaza (44..52, 20..24).", leg, most); + } + return UnitTestResult(true); + } + return "00.05c below_the_company_clown: not in the table, or from nowhere known."; +} + // 01.08's walk below the Ravaged Path keeps off the row Route 204 South's // youngster_3 wanders, (12, 2) to (14, 2): on lab-B (2026-11-08) the plan // "north 35 (to wall) to (13, 2), west 2 (to wall) to (11, 2)" walked along @@ -720,6 +754,10 @@ const AutoStoryStoryTableCase AUTO_STORY_STORY_TABLE_CASES[] = { .input = {"00.05b, 00.05c: no leg enters a wander zone (lab-B, 2026-11-11)", test_jubilife_routes_cross_no_wander_zone}, .expectation = {}, }, + { + .input = {"00.05c: from the street (58, 22), the walk keeps off the Wonder Station's plaza (lab-B, 2026-11-12)", test_company_clown_from_the_street_keeps_off_the_plaza}, + .expectation = {}, + }, }; void add_tests_AutoStory_StoryTable(UnitTestDatabase& database){ From 6feb3d1bc6267e96e280919e538a8bc86436f3b2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 02:44:50 -0800 Subject: [PATCH 39/47] BDSP AutoStory: a route step's "avoid" keeps the walk off ground the map leaves open ROUTE steps take "avoid" rows on their target's map, [x, y] tiles or [x0, y0, x1, y1] boxes, planned as off the map by the walk (RouteWalkPlan's avoid) and by the table's route tests alike. 00.05c's walk to the Poketch Company's clown avoids Jubilife's plaza (44..52, 20..24), where BDSP's Global Wonder Station stands and pret's Diamond map has open ground: from the street (57..58, 22) it now goes south to row 26 and round. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonBDSP_AutoStory_StoryData.cpp | 4 +- ...PokemonBDSP_AutoStory_StoryTable_Tests.cpp | 59 +++++++++++-------- .../PokemonBDSP_AutoStory_StoryWalkSteps.cpp | 22 ++++++- .../PokemonBDSP_AutoStory_StoryWalkSteps.h | 6 ++ .../PokemonBDSP_AutoStory_TableRoutes.cpp | 12 +++- .../AutoStory/StoryData/bdsp-00.05c.plan.json | 8 +++ 6 files changed, 81 insertions(+), 30 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index 414484cabe..1c09aa7543 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -111,8 +111,10 @@ std::vector make_bdsp_actions(){ action.args.push_back(opt_legs); } } + const Pokemon::StoryArgSpec opt_avoid{.key = "avoid", .type = Pokemon::StoryArgType::INTEGER_ROWS, .required = false, + .fallback = std::nullopt, .why = "ground on the target's map to keep off: [x, y] tiles, [x0, y0, x1, y1] boxes"}; for (std::string_view cost : {"town", "overworld", "indoors", "caves", "robust", "line", "trigger"}){ - actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs}}); + actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs, opt_avoid}}); } actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = "into_scene", .args = {route_target, fight_wild, legs_arg}}); add_legs_actions(actions, legs_arg, fight_wild); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp index b6b12a0555..5eb4d9dd17 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -444,36 +444,43 @@ UnitTestResult test_jubilife_routes_cross_no_wander_zone(Logger& logger){ return out.empty() ? UnitTestResult(true) : UnitTestResult("ROUTE steps:" + out); } -// 00.05c's walk to the Poketch Company's clown from the street (58, 22), -// where the checkpoint starts on a rerun from 01.01's start, keeps off the -// plaza (44..52, 20..24). BDSP put the Global Wonder Station there, a round -// wall with people round it that pret's Diamond map lacks: on lab-B -// (2026-11-12 01:22 and 01:55) the walk west was stopped at (50, 22), -// (51, 21) and (49, 23), and talked to the woman at (45, 24) until the -// step failed. +// Where the walk from `x` on row 22 walks the plaza, or "". +std::string company_clown_plaza_tiles(Logger& logger, TableRoute route, int x){ + route.from = Pokemon::tile_pose("JubilifeCity", {{x, 22}}, Direction::WEST); + const RouteStepPlan plan = plan_table_route(route); + if (!plan.legs){ + return std::format("no plan from ({}, 22).", x); + } + const StoryWorld& world = *route.world; + for (const PlannedLeg& planned : *plan.legs){ + logger.log(std::format("00.05c below_the_company_clown from ({}, 22): {}", x, to_string(planned))); + } + const auto plaza = [&](const TilePos& pos){ + const std::optional local = story_to_local(world, "JubilifeCity", pos); + return local && local->x >= 44 && local->x <= 52 && local->y >= 20 && local->y <= 24; + }; + const auto [most, leg] = most_zone_tiles(world, plan.start, *plan.legs, plaza); + return most == 0 ? "" : std::format("the leg {} walks {} tile(s) of the plaza (44..52, 20..24).", leg, most); +} + +// 00.05c's walk to the Poketch Company's clown from the street +// (57..58, 22), where the checkpoint starts on a rerun from 01.01's start, +// keeps off the plaza (44..52, 20..24). BDSP put the Global Wonder Station +// there, a round wall with people round it that pret's Diamond map lacks: +// on lab-B (2026-11-12 01:22 and 01:55) the walk west from (57, 22) was +// stopped at (50, 22), (51, 21) and (49, 23), and talked to the woman at +// (45, 24) until the step failed. UnitTestResult test_company_clown_from_the_street_keeps_off_the_plaza(Logger& logger){ - for (TableRoute route : table_routes()){ + for (const TableRoute& route : table_routes()){ if (route.row != "00.05c" || route.step->name != "below_the_company_clown" || route.world == nullptr){ continue; } - route.from = Pokemon::tile_pose("JubilifeCity", {{58, 22}}, Direction::EAST); - const RouteStepPlan plan = plan_table_route(route); - if (!plan.legs){ - return "00.05c below_the_company_clown: no plan from (58, 22)."; - } - const StoryWorld& world = *route.world; - for (const PlannedLeg& planned : *plan.legs){ - logger.log("00.05c below_the_company_clown from (58, 22): " + to_string(planned)); - } - const auto plaza = [&](const TilePos& pos){ - const std::optional local = story_to_local(world, "JubilifeCity", pos); - return local && local->x >= 44 && local->x <= 52 && local->y >= 20 && local->y <= 24; - }; - const auto [most, leg] = most_zone_tiles(world, plan.start, *plan.legs, plaza); - if (most > 0){ - return std::format("the leg {} walks {} tile(s) of the plaza (44..52, 20..24).", leg, most); + std::string out; + for (int x : {57, 58}){ + const std::string found = company_clown_plaza_tiles(logger, route, x); + out += found.empty() ? "" : "\n " + found; } - return UnitTestResult(true); + return out.empty() ? UnitTestResult(true) : UnitTestResult("00.05c below_the_company_clown:" + out); } return "00.05c below_the_company_clown: not in the table, or from nowhere known."; } @@ -755,7 +762,7 @@ const AutoStoryStoryTableCase AUTO_STORY_STORY_TABLE_CASES[] = { .expectation = {}, }, { - .input = {"00.05c: from the street (58, 22), the walk keeps off the Wonder Station's plaza (lab-B, 2026-11-12)", test_company_clown_from_the_street_keeps_off_the_plaza}, + .input = {"00.05c: from the street (57..58, 22), the walk keeps off the Wonder Station's plaza (lab-B, 2026-11-12)", test_company_clown_from_the_street_keeps_off_the_plaza}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index cd37db912c..60f97497a9 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -152,6 +152,26 @@ TappedEnd tapped_end(const StoryWorld& world, const std::string& map, const Tile return tapped; } +std::vector story_route_avoid(const StoryWorld& world, const StoryStep& step){ + if (!step.args.contains("avoid")){ + return {}; + } + const std::string& map = story_arg(step.args, "target").map; + std::vector tiles; + for (const std::vector& row : story_arg>>(step.args, "avoid")){ + if (row.size() != 2 && row.size() != 4){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("{}: an avoid row is [x, y] or [x0, y0, x1, y1].", step.name)); + } + const size_t last = row.size() - 2; + for (int64_t y = row[1]; y <= row[last + 1]; y++){ + for (int64_t x = row[0]; x <= row[last]; x++){ + tiles.push_back(story_to_world(world, map, {(int)x, (int)y})); + } + } + } + return tiles; +} + std::optional measured_ends(const Pose& from, const StoryStep& step){ const StoryWorld* world = story_plan_world(from.map, from.map); const auto& legs_list = story_arg>(step.args, "legs"); @@ -235,7 +255,7 @@ Pose StoryWalkSteps::walk_to(const Pose& from, const Pose& goal, const StoryStep }; const RouteWalkPlan plan{ [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); }, - label_of(step), {}, *costs, m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK, m_scene_next.contains(step.name), + label_of(step), story_route_avoid(*maps, step), *costs, m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK, m_scene_next.contains(step.name), step.action == ROUTE_ONTO_TRIGGER, }; RouteEnd end = walk_route_to_warp(m_route, *maps, start, trainers, plan); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h index 344e2b80c1..844fc8908a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h @@ -67,6 +67,12 @@ std::optional measured_ends(const Pokemon::Pose& from, const Poke // less those an earlier row fights, whom its save and every later one's // keep beaten. std::vector row_trainers(const StoryWorld& world, const std::string& row); +// The world tiles a ROUTE step's "avoid" rows name on its target's map, +// [x, y] a tile and [x0, y0, x1, y1] a box: ground the maps leave open that +// the walk keeps off (BDSP's Global Wonder Station in Jubilife's plaza, +// which pret's Diamond map lacks). None without the arg. Throws +// InternalProgramError for a row of another length. +std::vector story_route_avoid(const StoryWorld& world, const Pokemon::StoryStep& step); // Executes walking and movement-related story steps via StoryStepIO. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp index 9f55f5a6c2..7a64bb465e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp @@ -84,11 +84,19 @@ std::vector world_tiles(const StoryWorld& world, const Pokemon::Pose& p } RouteStepPlan plan_table_route(const TableRoute& route){ - const StoryWorld& world = *route.world; + // As walk_route() plans: the step's avoided tiles off the map, but + // where it starts. + StoryWorld world = *route.world; + const std::vector from = world_tiles(world, *route.from); + for (const TilePos& pos : story_route_avoid(world, *route.step)){ + if (std::find(from.begin(), from.end(), pos) == from.end()){ + world.uncover(pos); + } + } const Pokemon::Pose target = Pokemon::pose_of(story_arg(route.step->args, "target")); const std::vector targets = world_tiles(world, target); const auto goal = [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); }; - RouteStepPlan plan{.start = world_tiles(world, *route.from)}; + RouteStepPlan plan{.start = from}; const MoveSpeed speed = route.row > std::string(RUNNING_SHOES_ROW) ? MoveSpeed::RUN : MoveSpeed::WALK; plan.legs = plan_fastest_route({ .world = world, .from = plan.start, .goal = goal, .costs = *story_route_costs(route.step->action), .speed = speed, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json index 761a1c8397..5bf12d8a0b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json @@ -10,6 +10,14 @@ { "action": "town", "args": { + "avoid": [ + [ + 44, + 20, + 52, + 24 + ] + ], "fight_wild": false, "target": { "facing": "north", From e2f4e3a35487fbad583f99a548f6b99b43ea0e37 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 03:54:15 -0800 Subject: [PATCH 40/47] Robust leg planner: held open legs and per_open_wild_tile (off by default) RobustLegCosts::hold_open_legs plans open legs that may end off as holds (RobustLeg::held) that pay no per_open_tile; a held leg whose possible ends past the shortest enter tall grass, a wander place or hop a ledge is not used, and held legs are never joined. per_open_wild_tile adds to each wild tile an open leg enters. open_leg() now steps each place once for all its lengths (step_prefixes). Same code as on bdsp/start-certainty. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_RobustLegPlanner.h | 109 ++++++++++++++++-- .../Pokemon_RobustLegPlanner_Tests.cpp | 58 +++++++++- 2 files changed, 156 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h index 6c527a19fb..a6fb75f8d0 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h @@ -62,6 +62,10 @@ struct RobustLeg{ size_t tiles = 0; // tiles travelled; a ledge hop counts 2 bool to_wall = false; std::vector after; + // An open leg held for its tiles' time instead of tapped a tile at a + // time (RobustLegCosts::hold_open_legs). A held leg is never joined + // with the next one the same way: each is its own hold. + bool held = false; }; @@ -82,6 +86,16 @@ struct RobustLegCosts{ int exact_open_tiles = 0; // Extra per tile of an open leg: its timing error grows with its length. int per_open_tile = 0; + // Open legs that may end off (longer than exact_open_tiles) are held + // for their time (RobustLeg::held), not tapped, and pay no + // per_open_tile: no such leg is planned whose possible ends past its + // shortest enter a wild or wander place or hop a ledge, so a long or + // short hold meets nothing a tap would not have. + bool hold_open_legs = false; + // Extra per wild place an open leg enters, on top of per_wild_tile: a + // wild battle loses an open leg's count, while a leg to a wall just + // walks to the wall again. + int per_open_wild_tile = 0; int max_open_tiles = 12; // longest open leg to consider size_t max_spread = 5; // most places the player may be on after a leg // Most sets of places to search before giving up. The search is over @@ -196,6 +210,57 @@ std::optional> step_tiles(const Model& model, typ return stepped; } +// step_tiles() for each count from 1 to `most`, in one walk: [n - 1] is +// step_tiles(model, from, direction, n). +template +std::vector>> step_prefixes( + const Model& model, typename Model::State from, Direction direction, int most +){ + std::vector>> out; + Stepped stepped{from}; + int travelled = 0; + bool in_wander = model.wander(from); + while ((int)out.size() < most){ + const auto next = model.step(from, direction); + if (!next){ + stepped.end = from; + std::optional> last; + if (model.held_at(from, direction)){ + last = stepped; + } + out.resize((size_t)most, last); + break; + } + travelled += (int)model.step_tiles(from, *next); + stepped.wild += model.wild(*next) ? 1 : 0; + const bool next_wander = model.wander(*next); + if (next_wander){ + stepped.wander++; + stepped.along_wander |= in_wander; + } + in_wander = next_wander; + from = *next; + stepped.end = from; + while ((int)out.size() < std::min(travelled, most)){ + out.push_back(stepped); + } + } + return out; +} + +// Whether a held leg's possible ends, `ends` in order from the shortest, +// meet nothing past the shortest that a tap would not: no wild or wander +// place, no ledge hop. +template +bool held_ends_safe(const Model& model, const std::vector& ends){ + for (size_t i = 1; i < ends.size(); i++){ + if (model.step_tiles(ends[i - 1], ends[i]) > 1 || model.wild(ends[i]) || model.wander(ends[i])){ + return false; + } + } + return true; +} + // Sorts a spread and drops repeated places, so equal sets compare equal. template void normalize(std::vector& spread){ @@ -216,6 +281,9 @@ template struct Expansion{ long long cost = 0; RobustLeg leg; + // A held leg that may end somewhere unsafe (held_ends_safe()): not to + // be used, though a longer one may be. + bool unsafe = false; }; // To the wall: every place walks until stopped. Nothing unless each is @@ -255,40 +323,58 @@ std::optional> to_wall_leg( } // Open: about `tiles` tiles, give or take the error. Nothing if any -// possible end is stopped where the player is not held. +// possible end is stopped where the player is not held. A held leg whose +// ends may be unsafe is marked so (Expansion::unsafe). template std::optional> open_leg( const Model& model, const std::vector& spread, Direction direction, int tiles, const RobustLegCosts& costs ){ - Expansion expansion; + using State = typename Model::State; + Expansion expansion; int wild = 0; int wander = 0; const int error = open_leg_error(tiles, costs); + const bool held = costs.hold_open_legs && error > 0; for (const auto& place : spread){ + std::vector ends; + const auto prefixes = step_prefixes(model, place, direction, tiles + error); for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ - const auto stepped = step_tiles(model, place, direction, n); + const auto& stepped = prefixes[(size_t)n - 1]; if (!stepped || stepped->along_wander){ return std::nullopt; } wild = std::max(wild, stepped->wild); wander = std::max(wander, stepped->wander); - expansion.leg.after.push_back(stepped->end); + ends.push_back(stepped->end); } + if (held && !held_ends_safe(model, ends)){ + expansion.unsafe = true; + } + expansion.leg.after.insert(expansion.leg.after.end(), ends.begin(), ends.end()); } + const int per_open_tile = held ? 0 : costs.per_open_tile; expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall - + (long long)(costs.per_tile + costs.per_open_tile) * tiles - + (long long)costs.per_wild_tile * wild + (long long)costs.per_wander_tile * wander; + + (long long)(costs.per_tile + per_open_tile) * tiles + + (long long)(costs.per_wild_tile + costs.per_open_wild_tile) * wild + (long long)costs.per_wander_tile * wander; expansion.leg.direction = direction; expansion.leg.tiles = (size_t)tiles; + expansion.leg.held = held; return expansion; } +// Whether `next` walks on as one hold with `prev`: both open and tapped, +// the same way. +template +bool joins(const RobustLeg& prev, const RobustLeg& next){ + return prev.direction == next.direction && !prev.to_wall && !prev.held && !next.held; +} + // Joins an open leg with the next one the same way: they are one hold. template std::vector> consolidate(const std::vector>& legs){ std::vector> consolidated; for (const RobustLeg& leg : legs){ - if (!consolidated.empty() && consolidated.back().direction == leg.direction && !consolidated.back().to_wall){ + if (!consolidated.empty() && joins(consolidated.back(), leg)){ consolidated.back().tiles += leg.tiles; consolidated.back().to_wall = leg.to_wall; consolidated.back().after = leg.after; @@ -355,12 +441,15 @@ class Search{ if (auto wall = to_wall_leg(m_model, spread, direction, m_costs)){ relax(spread, cost, std::move(*wall)); } + // A held leg unsafe at one length may be safe at a longer one. for (int tiles = 1; tiles <= m_costs.max_open_tiles; tiles++){ auto open = open_leg(m_model, spread, direction, tiles, m_costs); if (!open){ break; } - relax(spread, cost, std::move(*open)); + if (!open->unsafe){ + relax(spread, cost, std::move(*open)); + } } } } @@ -375,7 +464,7 @@ class Search{ } if (spread != m_start){ const RobustLeg& prev = m_nodes.at(spread).leg; - if (expansion.leg.direction == prev.direction && !prev.to_wall){ + if (joins(prev, expansion.leg)){ expansion.cost -= m_costs.per_leg; } } @@ -443,7 +532,7 @@ long long robust_legs_cost( if (expansion){ cost = expansion->cost; } - if (previous != nullptr && previous->direction == leg.direction && !previous->to_wall){ + if (previous != nullptr && RobustLegPlannerInternal::joins(*previous, leg)){ cost -= costs.per_leg; } total += cost; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp index 6333649e2c..65eca83138 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp @@ -94,7 +94,8 @@ std::string describe(const std::optional& legs){ } std::string text; for (const RobustLeg& leg : *legs){ - text += std::format("{}{} {} {}:", text.empty() ? "" : "; ", direction_name(leg.direction), leg.tiles, leg.to_wall ? "to wall" : "open"); + text += std::format("{}{} {} {}:", text.empty() ? "" : "; ", direction_name(leg.direction), leg.tiles, + leg.to_wall ? "to wall" : leg.held ? "held" : "open"); for (const TilePos& pos : leg.after){ text += " " + to_string(pos); } @@ -103,6 +104,8 @@ std::string describe(const std::optional& legs){ } constexpr RobustLegCosts EXACT{.exact_open_tiles = 12}; +// Open legs held for their time, a tile short or long at any length. +constexpr RobustLegCosts HELD{.open_error = 1, .open_error_per = 0, .hold_open_legs = true}; struct PlanInput{ @@ -228,6 +231,26 @@ const PlanCase PLAN_CASES[] = { .input = {.name = "a walk that is never stopped is not a wall", .rows = {"...."}, .wraps = true, .from = {{0, 0}}, .goal = {2, 0}, .costs = EXACT}, .expectation = {.legs = "east 2 open: (2, 0)"}, }, + { + .input = {.name = "an open leg that may end off is held", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, + .expectation = {.legs = "east 1 held: (1, 0) (2, 0); south 1 to wall: (1, 1) (2, 1); east 2 to wall: (3, 1)"}, + }, + { + .input = {.name = "a held leg is refused when its long end lands in tall grass", .rows = {"..\"..", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, + .expectation = {.legs = "TBD"}, + }, + { + .input = {.name = "a held leg is refused when its long end lands where someone wanders", .rows = {"..w..", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, + .expectation = {.legs = "TBD"}, + }, + { + .input = {.name = "a held leg is refused when its long end hops a ledge", .rows = {"..", "..", "v.", "..", "#."}, .from = {{0, 0}}, .goal = {0, 3}, .costs = HELD}, + .expectation = {.legs = "TBD"}, + }, + { + .input = {.name = "open legs are tapped while hold_open_legs is off", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = {.open_error = 1, .open_error_per = 0}}, + .expectation = {.legs = "TBD"}, + }, }; @@ -290,6 +313,39 @@ const CostCase COST_CASES[] = { }, .expectation = {.cost = 8 + 50 + 3}, }, + { + .input = { + .name = "a held leg pays no per_open_tile", .rows = {"........"}, .from = {0, 0}, + .legs = {{Direction::EAST, 3, false, {{2, 0}, {3, 0}, {4, 0}}, true}}, + .costs = {.open_error = 1, .open_error_per = 0, .per_open_tile = 2, .hold_open_legs = true}, + }, + .expectation = {.cost = 8 + 50 + 3}, + }, + { + .input = { + .name = "held legs the same way are not joined", .rows = {"........"}, .from = {0, 0}, + .legs = { + {Direction::EAST, 2, false, {{1, 0}, {2, 0}, {3, 0}}, true}, + {Direction::EAST, 2, false, {{2, 0}, {3, 0}, {4, 0}, {5, 0}}, true}, + }, + .costs = HELD, + }, + .expectation = {.cost = 2 * (8 + 50 + 2)}, + }, + { + .input = { + .name = "each grass tile of an open leg costs per_open_wild_tile more", .rows = {".\"\"...."}, .from = {0, 0}, + .legs = {{Direction::EAST, 3, false, {{3, 0}}}}, .costs = {.exact_open_tiles = 12, .per_open_wild_tile = 10}, + }, + .expectation = {.cost = 8 + 50 + 3 + 2 * (4 + 10)}, + }, + { + .input = { + .name = "per_open_wild_tile leaves a wall leg's grass alone", .rows = {".\"\"#"}, .from = {0, 0}, + .legs = {{Direction::EAST, 2, true, {{2, 0}}}}, .costs = {.per_open_wild_tile = 10}, + }, + .expectation = {.cost = 8 + 2 + 2 * 4}, + }, }; } // namespace From 6bf2fece9319f1fcaf3f5b7028810615ae48afde Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 03:55:57 -0800 Subject: [PATCH 41/47] Robust leg planner tests: held legs refused at grass, wander and ledge ends; held costs Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Navigation/Pokemon_RobustLegPlanner_Tests.cpp | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp index 65eca83138..b9866592b5 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp @@ -237,19 +237,23 @@ const PlanCase PLAN_CASES[] = { }, { .input = {.name = "a held leg is refused when its long end lands in tall grass", .rows = {"..\"..", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, - .expectation = {.legs = "TBD"}, + .expectation = {.legs = "none"}, }, { .input = {.name = "a held leg is refused when its long end lands where someone wanders", .rows = {"..w..", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, - .expectation = {.legs = "TBD"}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "a held leg south lines up a wall leg", .rows = {".##", "...", "...", ".##", ".##"}, .from = {{0, 0}}, .goal = {2, 2}, .costs = HELD}, + .expectation = {.legs = "south 1 held: (0, 1) (0, 2); east 2 to wall: (2, 1) (2, 2); south 1 to wall: (2, 2)"}, }, { - .input = {.name = "a held leg is refused when its long end hops a ledge", .rows = {"..", "..", "v.", "..", "#."}, .from = {{0, 0}}, .goal = {0, 3}, .costs = HELD}, - .expectation = {.legs = "TBD"}, + .input = {.name = "a held leg is refused when its long end hops a ledge", .rows = {".##", "...", "v..", ".##", ".##"}, .from = {{0, 0}}, .goal = {2, 2}, .costs = HELD}, + .expectation = {.legs = "none"}, }, { .input = {.name = "open legs are tapped while hold_open_legs is off", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = {.open_error = 1, .open_error_per = 0}}, - .expectation = {.legs = "TBD"}, + .expectation = {.legs = "east 1 open: (1, 0) (2, 0); south 1 to wall: (1, 1) (2, 1); east 2 to wall: (3, 1)"}, }, }; From 441b063911c8b66340f7db48366c2f0111482e45 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 18:51:31 -0800 Subject: [PATCH 42/47] BDSP maps: pin PokemonSimulation 4b886bb; Route 203's youngster stays at (54,16) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- devtools/maps/map-resources.lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 7ce46c4b43..b052d6f8cb 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "bdsp": { - "revision": "438b67207a2d0e10419c31c1c541520aace7e86e", + "revision": "4b886bbead2e85c42f15bfb0b5ac735c159db039", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "50c0ac960d5010db8ebf192960cdc556756696679867f2225fddbd8c868d4001" + "manifest_sha256": "eeca55d046c02d5866b54f48abe90dc5dc4c59d483cd0edd7a857d374d85dd2c" } } } From b32b47a463d9f50f4c0479d9f79af269b9256abd Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:04:57 -0800 Subject: [PATCH 43/47] BDSP maps: back to PokemonSimulation 438b672 for now; 4b886bb strands 01.06 up_jubilifes_road in the route bench Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- devtools/maps/map-resources.lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index b052d6f8cb..7ce46c4b43 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "bdsp": { - "revision": "4b886bbead2e85c42f15bfb0b5ac735c159db039", + "revision": "438b67207a2d0e10419c31c1c541520aace7e86e", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "eeca55d046c02d5866b54f48abe90dc5dc4c59d483cd0edd7a857d374d85dd2c" + "manifest_sha256": "50c0ac960d5010db8ebf192960cdc556756696679867f2225fddbd8c868d4001" } } } From 24b7d745dc3ed871cee31fec16fbe14b0421d7b4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:25:21 -0800 Subject: [PATCH 44/47] Revert "BDSP maps: back to PokemonSimulation 438b672 for now; 4b886bb strands 01.06 up_jubilifes_road in the route bench" This reverts commit b32b47a463d9f50f4c0479d9f79af269b9256abd. --- devtools/maps/map-resources.lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 7ce46c4b43..b052d6f8cb 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "bdsp": { - "revision": "438b67207a2d0e10419c31c1c541520aace7e86e", + "revision": "4b886bbead2e85c42f15bfb0b5ac735c159db039", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "50c0ac960d5010db8ebf192960cdc556756696679867f2225fddbd8c868d4001" + "manifest_sha256": "eeca55d046c02d5866b54f48abe90dc5dc4c59d483cd0edd7a857d374d85dd2c" } } } From c90722d6cb83c650deb7d573cc3d65f5ee0f4c2b Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:34:23 -0800 Subject: [PATCH 45/47] BDSP walk: someone who never moves is a wall anchor for holds and recovery A person or item with no wander box now counts as a wall in at_wall() and in safe_wall(); only wander boxes and warps still spoil a recovery ray. This lets 01.06 up_jubilifes_road recover at PokemonSimulation 4b886bb, where Route 203's youngster stays at (54,16). Plan, leg-trace and bench goldens follow; 00.04 into_moms_call now holds against Mom (3100 ms, was 2550). Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 13 +++---- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 4 +- .../PokemonBDSP_AutoStory_WallRecovery.cpp | 10 ++--- .../AutoStory/Data/route_bench.golden.txt | 12 +++--- .../AutoStory/Data/route_plans.golden.txt | 38 +++++++++---------- ...kemonBDSP_AutoStory_RoutePlanner_Tests.cpp | 8 ++++ ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 2 +- .../Simulation/leg_trace_00.04.golden.json | 6 +-- 8 files changed, 48 insertions(+), 45 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index a3cb3e6495..cb488fb453 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -188,11 +188,8 @@ std::optional StoryWorld::tile(const TilePos& pos) const{ return found->tile; } -StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos, OccupancyUse use) const{ +StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos) const{ const Cell* found = cell(pos); - if (found && use == OccupancyUse::WALL_RECOVERY && found->recovery_hazard){ - return PERSON; - } return found == nullptr ? NOBODY : found->occupant; } @@ -336,12 +333,12 @@ bool warp_within(const StoryWorld& world, const std::vector& from, Dire return false; } -// Someone standing in the way stops us too, but is no wall to stop against: -// they may turn and talk, or walk off (r29 ran east into Mom, who talked). +// Someone who never moves (a person or item with no wander box) is a wall +// like any other (the user's rule, 2026-11-12). A wanderer is none: it is +// not in the cells' occupants, and the walker waits for it. bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ const std::optional next = world.tile(pos.next(direction)); - return next && *next != TileKind::DOOR && world.occupied(pos.next(direction)) != StoryWorld::PERSON && - !step(world, pos, direction).has_value(); + return next && *next != TileKind::DOOR && !step(world, pos, direction).has_value(); } std::string describe(const StoryWorld& world, const TilePos& pos){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index b7c57f01db..f0ca17d1ca 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -60,9 +60,7 @@ class StoryWorld{ PERSON, BLOCKED, }; - // Recovery also excludes wandering areas and declared warps. - enum class OccupancyUse{ MOVEMENT, WALL_RECOVERY }; - Occupant occupied(const Pokemon::TilePos& pos, OccupancyUse use = OccupancyUse::MOVEMENT) const; + Occupant occupied(const Pokemon::TilePos& pos) const; // Blocks a tile found in the way on the console. Tiles off the maps // are left alone. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp index f385dfcacc..c0d247096b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp @@ -18,22 +18,22 @@ using Pokemon::TilePos; // A wall ray must stay on the same map and walk one tile per step. A // ledge may be legal travel but must not become a localization anchor. +// A wander box or a warp on the ray or its wall spoils it; a person who +// never moves is a wall to stop against. std::optional safe_wall(const StoryWorld& world, TilePos from, Direction direction){ const auto map = world.to_local(from); - if (!map || !standable(world, from) - || world.occupied(from, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + if (!map || !standable(world, from) || recovery_hazard(world, from)){ return std::nullopt; } const WallHit wall = slide_to_wall(world, from, direction); - if (!wall.anchored - || world.occupied(wall.wall, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + if (!wall.anchored || recovery_hazard(world, wall.wall)){ return std::nullopt; } while (from != wall.stop){ const auto next = step(world, from, direction); const auto local = next ? world.to_local(*next) : std::nullopt; if (!next || *next != from.next(direction) || !local || local->map != map->map - || world.occupied(*next, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + || recovery_hazard(world, *next)){ return std::nullopt; } from = *next; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt index 4f20ad59b1..76afdf193b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt @@ -28,7 +28,7 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.04 into_twinleaf | 10200 | 10200 | 10200 | 1 | 0 | 0 | 1.00 | 1.00 | 1.00 | 10200 ms (user's route) | PASS 00.04 to_moms_doorstep | 4100 | 4100 | 4100 | 0 | 0 | 0 | 5.47! | 1.00 | 1.00 | 750 ms (stand-in) | PASS 00.04 beside_mom | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS -00.04 into_moms_call | 2550 | 2550 | 2550 | 1 | 0 | 0 | 1.00 | 1.00 | 1.00 | 2550 ms (user's route) | PASS +00.04 into_moms_call | 3100 | 3100 | 3100 | 2 | 0 | 0 | 1.22 | 1.00 | 1.00 | 2550 ms (user's route) | PASS 00.04 short_of_the_catch_tutorial | 84001 | 81950 | 49900 | 6 | 19 | 7 | 4.73! | 1.00 | 57.00! | 17750 ms (stand-in) | PASS 00.04b to_catch_grass | 11689 | 38550 | 6300 | 2 | 34 | 1 | 17.98! | 17.50! | 2.00! | 650 ms (stand-in) | PASS 00.04b into_sandgem | 9520 | 19400 | 7050 | 3 | 12 | 0 | 2.93! | 4.33! | 1.00 | 3250 ms (stand-in) | PASS @@ -36,12 +36,12 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.05b below_the_presidents_trigger | 4900 | 4900 | 4900 | 0 | 0 | 0 | 5.76! | 1.00 | 1.00 | 850 ms (stand-in) | PASS 00.05b past_the_president | 1700 | 1700 | 1700 | 0 | 0 | 0 | 3.78! | 1.00 | 1.00 | 450 ms (stand-in) | PASS 00.05b below_the_mart_clown | 5450 | 5450 | 5450 | 1 | 0 | 0 | 3.30! | 1.00 | 1.00 | 1650 ms (stand-in) | PASS -00.05b below_the_tv_clown | 27350 | 27350 | 27350 | 1 | 0 | 0 | 6.29! | 1.00 | 1.00 | 4350 ms (stand-in) | PASS +00.05b below_the_tv_clown | 24300 | 24300 | 24300 | 1 | 0 | 0 | 5.59! | 1.00 | 1.00 | 4350 ms (stand-in) | PASS 00.05b below_the_company_clown | 21900 | 21900 | 21900 | 0 | 0 | 0 | 6.74! | 1.00 | 3.00! | 3250 ms (stand-in) | PASS 00.05b beside_the_company_sign | 1450 | 1450 | 1450 | 1 | 0 | 0 | 4.14! | 1.00 | 1.00 | 350 ms (stand-in) | PASS 00.05c below_the_company_clown | 900 | 900 | 900 | 0 | 0 | 0 | 2.57! | 1.00 | 1.00 | 350 ms (stand-in) | PASS -00.05c below_the_tv_clown | 21900 | 21900 | 21900 | 0 | 0 | 0 | 6.74! | 1.00 | 5.00! | 3250 ms (stand-in) | PASS -00.05c below_the_mart_clown | 20350 | 20350 | 20350 | 1 | 0 | 0 | 4.68! | 1.00 | 1.00 | 4350 ms (stand-in) | PASS +00.05c below_the_tv_clown | 20550 | 20550 | 20550 | 1 | 0 | 0 | 6.32! | 1.00 | 5.00! | 3250 ms (stand-in) | PASS +00.05c below_the_mart_clown | 17150 | 17150 | 17150 | 2 | 0 | 0 | 3.94! | 1.00 | 1.00 | 4350 ms (stand-in) | PASS 00.05c beside_the_president | 12200 | 12200 | 12200 | 0 | 0 | 0 | 6.26! | 1.00 | 1.00 | 1950 ms (stand-in) | PASS 00.05c to_the_route_203_street | 21000 | 21000 | 21000 | 0 | 0 | 0 | 6.00! | 1.00 | 1.00 | 3500 ms (stand-in) | PASS 01.01 west_of_barrys_trigger | 7300 | 7300 | 7300 | 0 | 0 | 0 | 6.35! | 1.00 | 1.00 | 1150 ms (stand-in) | PASS @@ -53,9 +53,9 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 01.02 west_of_the_welcome | 8550 | 8550 | 8550 | 2 | 0 | 0 | 9.00! | 1.00 | 4.00! | 950 ms (stand-in) | PASS 01.02b below_the_centers_door | 6663 | 8800 | 5950 | 2 | 1 | 0 | 2.38! | 2.00! | 2.00! | 2800 ms (stand-in) | PASS 01.03 above_the_mine | 16350 | 16350 | 16350 | 3 | 0 | 0 | 2.75! | 1.00 | 5.00! | 5950 ms (stand-in) | PASS -01.05 east_of_barrys_trigger | 26050 | 26050 | 26050 | 3 | 0 | 0 | 7.44! | 1.00 | 14.00! | 3500 ms (stand-in) | PASS +01.05 east_of_barrys_trigger | 19550 | 19550 | 19550 | 2 | 0 | 0 | 5.59! | 1.00 | 13.00! | 3500 ms (stand-in) | PASS 01.05 through_the_gate | 12050 | 12050 | 12050 | 5 | 0 | 0 | 4.92! | 1.00 | 27.00! | 2450 ms (stand-in) | PASS -01.06 up_jubilifes_road | 87286 | 119950 | 58350 | 3 | 10 | 4 | 7.66! | 2.20! | 20.00! | 11400 ms (stand-in) | PASS +01.06 up_jubilifes_road | 82607 | 94600 | 58350 | 3 | 10 | 4 | 7.25! | 2.20! | 20.00! | 11400 ms (stand-in) | PASS 01.06 below_rowans_trigger | 1950 | 1950 | 1950 | 1 | 0 | 0 | 2.29! | 1.00 | 1.00 | 850 ms (stand-in) | PASS 01.08 west_to_the_wall | 1650 | 1650 | 1650 | 1 | 0 | 0 | 3.00! | 1.00 | 1.00 | 550 ms (stand-in) | PASS 01.08 below_the_ravaged_path | 24815 | 26050 | 13700 | 2 | 9 | 0 | 4.24! | 1.00 | 6.00! | 5850 ms (stand-in) | PASS diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt index 5e5f4df555..12b68d81e9 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt @@ -138,10 +138,10 @@ anchor); 0 from one start tile. from: PlayerHouse1F (11, 8) facing south (tile) target: PlayerHouse1F (6, 9) facing west (tile) start candidates: PlayerHouse1F (11, 8) - 1. west 1 (open) -> PlayerHouse1F (10, 8) - 2. south 1 (open) -> PlayerHouse1F (10, 9) - 3. west 4 (to wall) -> PlayerHouse1F (6, 9) - totals: 3 legs, 2 turns, 2 open, 0 localization + 1. west 3 (to wall) -> PlayerHouse1F (8, 8) + 2. south 1 (open) -> PlayerHouse1F (8, 9) + 3. west 2 (to wall) -> PlayerHouse1F (6, 9) + totals: 3 legs, 2 turns, 1 open, 0 localization == 00.04 short_of_the_catch_tutorial (costs: route) from: TwinleafTown (6, 22) (6, 23) facing west (set) @@ -228,9 +228,9 @@ anchor); 0 from one start tile. target: JubilifeCity (36, 17) facing north (tile) start candidates: Jubilife City (56, 31) 1. west 8 (open) -> Jubilife City (48, 31) - 2. north 22 (to wall) -> Jubilife City (48, 9) - 3. south 8 (open) -> Jubilife City (48, 17) - 4. west 12 (open) -> Jubilife City (36, 17) + 2. north 7 (open) -> Jubilife City (48, 24) + 3. west 12 (open) -> Jubilife City (36, 24) + 4. north 7 (to wall) -> Jubilife City (36, 17) totals: 4 legs, 3 turns, 3 open, 0 localization == 00.05b below_the_company_clown (costs: town) @@ -262,17 +262,18 @@ anchor); 0 from one start tile. start candidates: Jubilife City (15, 19) 1. south 2 (open) -> Jubilife City (15, 21) 2. east 21 (open) -> Jubilife City (36, 21) - 3. north 4 (open) -> Jubilife City (36, 17) - totals: 3 legs, 2 turns, 3 open, 0 localization + 3. north 4 (to wall) -> Jubilife City (36, 17) + totals: 3 legs, 2 turns, 2 open, 0 localization == 00.05c below_the_mart_clown (costs: town) from: JubilifeCity (36, 17) facing north (tile) target: JubilifeCity (56, 31) facing south (tile) start candidates: Jubilife City (36, 17) - 1. east 8 (open) -> Jubilife City (44, 17) - 2. south 14 (open) -> Jubilife City (44, 31) - 3. east 12 (to wall) -> Jubilife City (56, 31) - totals: 3 legs, 2 turns, 2 open, 0 localization + 1. south 7 (to wall) -> Jubilife City (36, 24) + 2. east 8 (open) -> Jubilife City (44, 24) + 3. south 7 (open) -> Jubilife City (44, 31) + 4. east 12 (to wall) -> Jubilife City (56, 31) + totals: 4 legs, 3 turns, 2 open, 0 localization == 00.05c beside_the_president (costs: town) from: JubilifeCity (56, 31) facing north (tile) @@ -373,12 +374,11 @@ anchor); 0 from one start tile. target: OreburghCity (7, 13) facing west (tile) start candidates: Oreburgh City (26, 21), Oreburgh City (26, 22) 1. south 5 (to wall) -> Oreburgh City (26, 26) - 2. west 2 (to wall) -> Oreburgh City (24, 26) - 3. north 5 (to wall) -> Oreburgh City (24, 21) - 4. west 9 (open) -> Oreburgh City (15, 21) - 5. north 8 (open) -> Oreburgh City (15, 13) - 6. west 8 (open) -> Oreburgh City (7, 13) - totals: 6 legs, 5 turns, 3 open, 1 localization + 2. north 1 (open) -> Oreburgh City (26, 25) + 3. west 14 (to wall) -> Oreburgh City (12, 25) + 4. north 12 (open) -> Oreburgh City (12, 13) + 5. west 5 (open) -> Oreburgh City (7, 13) + totals: 5 legs, 4 turns, 3 open, 1 localization == 01.05 through_the_gate (costs: route) from: OreburghGate (27, 22) (26, 22) facing west (set) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp index 995f476ce9..0d6578cc60 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -233,6 +233,7 @@ struct RecoveryGeometryInput{ std::vector from; std::optional wander = {}; std::vector warps = {}; + std::optional still = {}; // someone who never moves }; struct RecoveryGeometryExpectation{ std::optional anchor; @@ -261,6 +262,10 @@ Pokemon::MapData recovery_map(const RecoveryGeometryInput& input){ map.objects.push_back({.name = "wanderer", .x = 3, .y = 1, .facing = std::nullopt, .wander = input.wander, .trainer = std::nullopt, .hide_flag = std::nullopt}); } + if (input.still){ + map.objects.push_back({.name = "still", .x = input.still->x, .y = input.still->y, .facing = std::nullopt, + .wander = std::nullopt, .trainer = std::nullopt, .hide_flag = std::nullopt}); + } for (const auto& warp : input.warps){ map.warps.push_back({.x = warp.x, .y = warp.y, .to = std::nullopt}); } @@ -372,6 +377,9 @@ const RecoveryGeometryCase GEOMETRY_CASES[] = { .expectation = {.anchor = std::nullopt, .free_tile = TilePos{.x = 3, .y = 1}}}, {.input = {.name = "warp crossings are unsafe", .from = {{1, 1}, {5, 1}}, .warps = {{3, 1}}}, .expectation = {.anchor = std::nullopt}}, + {.input = {.name = "a still person is a wall to anchor on", .from = {{2, 1}, {3, 1}}, + .warps = {{5, 1}}, .still = TilePos{.x = 1, .y = 1}}, + .expectation = {.anchor = TilePos{.x = 2, .y = 1}, .direction = Direction::WEST}}, {.input = {.name = "warps on blocked glyphs are unsafe", .from = {{1, 1}, {5, 1}}, .warps = {{0, 1}, {6, 1}}}, .expectation = {.anchor = std::nullopt}}, }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 37e501f309..f83a4d8c5f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -99,7 +99,7 @@ UnitTestResult test_story_world_steps(Logger&){ {.name = "a west ledge hops west", .rows = {".<."}, .from = {2, 0}, .direction = Direction::WEST, .lands = TilePos{0, 0}}, {.name = "a west ledge stops east", .rows = {".<."}, .direction = Direction::EAST, .at_wall = true}, {.name = "a ledge onto a wall stops", .rows = {".", "v", "#"}, .direction = Direction::SOUTH, .at_wall = true}, - {.name = "a person standing still", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = false}, + {.name = "a person standing still is a wall", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = true}, {.name = "a wanderer does not block", .rows = {".", "."}, .wandering = {{0, 0}}, .from = {0, 1}, .lands = TilePos{0, 0}}, }; for (const StepCase& item : cases){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json index 768074a022..3ff849677b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json @@ -20,9 +20,9 @@ {"checkpoint":"00.04","chunks":0,"dir":"north","end":[],"end_kind":"wall","event":"into_the_east_corner","interrupts":[],"known":"wall","leg":1,"ms":0,"planned_end":[],"tiles":4}, {"checkpoint":"00.04","chunks":0,"dir":"east","end":[],"end_kind":"wall","event":"into_the_east_corner","interrupts":[],"known":"wall","leg":2,"ms":0,"planned_end":[],"tiles":6}, {"checkpoint":"00.04","chunks":0,"dir":"south","end":[],"end_kind":"wall","event":"into_the_east_corner","interrupts":[],"known":"wall","leg":3,"ms":0,"planned_end":[],"tiles":4}, - {"checkpoint":"00.04","chunks":1,"dir":"west","end":[["PlayerHouse1F",10,8]],"end_kind":"open","event":"into_moms_call","interrupts":[],"known":"dead_reckoned","leg":1,"moved":1,"ms":800,"planned_end":[["PlayerHouse1F",10,8]],"tiles":1}, - {"checkpoint":"00.04","chunks":1,"dir":"south","end":[["PlayerHouse1F",10,9]],"end_kind":"open","event":"into_moms_call","interrupts":[],"known":"dead_reckoned","leg":2,"moved":1,"ms":800,"planned_end":[["PlayerHouse1F",10,9]],"tiles":1}, - {"checkpoint":"00.04","chunks":4,"dir":"west","end":[],"end_kind":"wall","event":"into_moms_call","interrupts":["scene"],"known":"dialogue","leg":3,"ms":650,"note":"scene","planned_end":[["PlayerHouse1F",6,9]],"tiles":4}, + {"checkpoint":"00.04","chunks":3,"dir":"west","end":[["PlayerHouse1F",8,8]],"end_kind":"wall","event":"into_moms_call","interrupts":[],"known":"wall","leg":1,"ms":1350,"planned_end":[["PlayerHouse1F",8,8]],"tiles":3}, + {"checkpoint":"00.04","chunks":1,"dir":"south","end":[["PlayerHouse1F",8,9]],"end_kind":"open","event":"into_moms_call","interrupts":[],"known":"dead_reckoned","leg":2,"moved":1,"ms":800,"planned_end":[["PlayerHouse1F",8,9]],"tiles":1}, + {"checkpoint":"00.04","chunks":2,"dir":"west","end":[],"end_kind":"wall","event":"into_moms_call","interrupts":["scene"],"known":"dialogue","leg":3,"ms":450,"note":"scene","planned_end":[["PlayerHouse1F",6,9]],"tiles":2}, {"checkpoint":"00.04","chunks":0,"dir":"west","end":[],"end_kind":"wall","event":"to_twinleafs_west_wall","interrupts":[],"known":"wall","leg":1,"ms":0,"planned_end":[],"tiles":16}, {"checkpoint":"00.04","chunks":18,"dir":"north","end":[["Twinleaf Town",6,4]],"end_kind":"wall","event":"short_of_the_catch_tutorial","interrupts":[],"known":"wall","leg":1,"ms":3750,"planned_end":[["Twinleaf Town",6,4]],"tiles":19}, {"checkpoint":"00.04","chunks":8,"dir":"east","end":[["Twinleaf Town",14,4]],"end_kind":"open","event":"short_of_the_catch_tutorial","interrupts":[],"known":"dead_reckoned","leg":2,"moved":8,"ms":6400,"planned_end":[["Twinleaf Town",14,4]],"tiles":8}, From 09040f5c486e1e8aed58c00bc592c2723e278889 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:54:00 -0800 Subject: [PATCH 46/47] BDSP walk: a still person who talks when bumped (Mom) is no wall anchor Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Data/PokemonBDSP_AutoStory_StoryWorld.cpp | 29 ++++++++++++++++--- .../Data/PokemonBDSP_AutoStory_StoryWorld.h | 6 ++++ ...PokemonBDSP_AutoStory_StoryWorld_Tests.cpp | 10 +++++++ 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index cb488fb453..1a49f296c1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -49,6 +49,12 @@ std::optional ledge_direction(TileKind tile){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown TileKind."); } +// Still people the console showed talking when bumped. The map data has no +// marker for it; r29 ran east into Mom, who talked. +bool bump_talker(const std::string& map, const std::string& object){ + return map == "PlayerHouse1F" && object == "mom_0"; +} + } // namespace @@ -58,10 +64,13 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Map placed twice: " + name); } } - Placed placed{.name = std::move(name), .tiles = map.tiles, .occupied = {}, .wander = {}, .warps = {}, .offset = offset}; + Placed placed{.name = std::move(name), .tiles = map.tiles, .occupied = {}, .talkers = {}, .wander = {}, .warps = {}, .offset = offset}; for (const Pokemon::MapObject& object : map.objects){ if (!object.wander){ placed.occupied.push_back({object.x, object.y}); + if (bump_talker(map.name, object.name)){ + placed.talkers.push_back({object.x, object.y}); + } }else{ placed.wander.push_back(*object.wander); } @@ -150,6 +159,11 @@ void StoryWorld::paint(const Placed& placed, const TilePos& corner){ for (const TilePos& pos : placed.occupied){ Pokemon::cell_at({corner.x + pos.x, corner.y + pos.y}, m_cells).occupant = PERSON; } + for (const TilePos& pos : placed.talkers){ + Cell& c = Pokemon::cell_at({corner.x + pos.x, corner.y + pos.y}, m_cells); + c.recovery_hazard = true; + c.talks = true; + } for (const auto& box : placed.wander){ for (int y = std::max(0, box.y0); y <= std::min(placed.tiles.height - 1, box.y1); y++){ for (int x = std::max(0, box.x0); x <= std::min(placed.tiles.width - 1, box.x1); x++){ @@ -237,6 +251,11 @@ bool recovery_hazard(const StoryWorld& world, const TilePos& pos){ return found != nullptr && found->recovery_hazard; } +bool talks_when_bumped(const StoryWorld& world, const TilePos& pos){ + const StoryWorld::Cell* found = world.cell(pos); + return found != nullptr && found->talks; +} + void StoryWorld::block(const TilePos& pos){ if (Cell* found = cell(pos)){ found->occupant = BLOCKED; @@ -334,11 +353,13 @@ bool warp_within(const StoryWorld& world, const std::vector& from, Dire } // Someone who never moves (a person or item with no wander box) is a wall -// like any other (the user's rule, 2026-11-12). A wanderer is none: it is -// not in the cells' occupants, and the walker waits for it. +// like any other (the user's rule, 2026-11-12), unless they talk when bumped. +// A wanderer is none: it is not in the cells' occupants, and the walker +// waits for it. bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ const std::optional next = world.tile(pos.next(direction)); - return next && *next != TileKind::DOOR && !step(world, pos, direction).has_value(); + return next && *next != TileKind::DOOR && !talks_when_bumped(world, pos.next(direction)) && + !step(world, pos, direction).has_value(); } std::string describe(const StoryWorld& world, const TilePos& pos){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index f0ca17d1ca..bed4f15cb0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -78,12 +78,14 @@ class StoryWorld{ friend std::vector wandering_hazards(const StoryWorld& world); friend bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); friend bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); + friend bool talks_when_bumped(const StoryWorld& world, const Pokemon::TilePos& pos); private: struct Placed{ std::string name; Pokemon::Grid tiles; std::vector occupied; // local tiles + std::vector talkers; // local tiles of occupied people who talk when bumped std::vector wander; // recovery hazards, not terrain std::vector warps; Pokemon::TilePos offset; @@ -93,6 +95,7 @@ class StoryWorld{ Pokemon::TileKind tile = Pokemon::TileKind::WALL; Occupant occupant = NOBODY; bool recovery_hazard = false; + bool talks = false; bool wander_hazard = false; }; @@ -129,6 +132,9 @@ std::vector wandering_hazards(const StoryWorld& world); bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); // Whether a world tile is a recovery hazard (wander box or warp). bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); +// Someone who never moves but starts a talk or scene when bumped (Mom in +// PlayerHouse1F, r29): no wall to stop against or anchor on. +bool talks_when_bumped(const StoryWorld& world, const Pokemon::TilePos& pos); // "Route 201 (45, 3)", or "world (x, y)" if no map holds it. std::string describe(const StoryWorld& world, const Pokemon::TilePos& pos); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index f83a4d8c5f..51c5fb16cd 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -113,6 +113,16 @@ UnitTestResult test_story_world_steps(Logger&){ return std::format("{}: at_wall() is {}, expected {}.", item.name, !item.at_wall, item.at_wall); } } + { + // Mom talks when bumped (r29): she stops a walk, but is no wall. + MapData map = make_map({".", "."}, {{0, 0}}); + map.name = "PlayerHouse1F"; + map.objects[0].name = "mom_0"; + const StoryWorld world = make_world(map); + if (at_wall(world, {0, 1}, Direction::NORTH) || step(world, {0, 1}, Direction::NORTH).has_value()){ + return "Mom: no wall to stop against, and no step onto her."; + } + } return true; } From 9c92982db1a968d36511ddddde00fe05520cd622 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 20:04:50 -0800 Subject: [PATCH 47/47] BDSP AutoStory: 00.04 into_moms_call back to 2550 ms (Mom is no anchor); plan, leg-trace and bench goldens Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/AutoStory/Data/route_bench.golden.txt | 2 +- .../Programs/AutoStory/Data/route_plans.golden.txt | 8 ++++---- .../AutoStory/Simulation/leg_trace_00.04.golden.json | 6 +++--- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt index 76afdf193b..f85a1def34 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt @@ -28,7 +28,7 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.04 into_twinleaf | 10200 | 10200 | 10200 | 1 | 0 | 0 | 1.00 | 1.00 | 1.00 | 10200 ms (user's route) | PASS 00.04 to_moms_doorstep | 4100 | 4100 | 4100 | 0 | 0 | 0 | 5.47! | 1.00 | 1.00 | 750 ms (stand-in) | PASS 00.04 beside_mom | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS -00.04 into_moms_call | 3100 | 3100 | 3100 | 2 | 0 | 0 | 1.22 | 1.00 | 1.00 | 2550 ms (user's route) | PASS +00.04 into_moms_call | 2550 | 2550 | 2550 | 1 | 0 | 0 | 1.00 | 1.00 | 1.00 | 2550 ms (user's route) | PASS 00.04 short_of_the_catch_tutorial | 84001 | 81950 | 49900 | 6 | 19 | 7 | 4.73! | 1.00 | 57.00! | 17750 ms (stand-in) | PASS 00.04b to_catch_grass | 11689 | 38550 | 6300 | 2 | 34 | 1 | 17.98! | 17.50! | 2.00! | 650 ms (stand-in) | PASS 00.04b into_sandgem | 9520 | 19400 | 7050 | 3 | 12 | 0 | 2.93! | 4.33! | 1.00 | 3250 ms (stand-in) | PASS diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt index 12b68d81e9..6f060714f7 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt @@ -138,10 +138,10 @@ anchor); 0 from one start tile. from: PlayerHouse1F (11, 8) facing south (tile) target: PlayerHouse1F (6, 9) facing west (tile) start candidates: PlayerHouse1F (11, 8) - 1. west 3 (to wall) -> PlayerHouse1F (8, 8) - 2. south 1 (open) -> PlayerHouse1F (8, 9) - 3. west 2 (to wall) -> PlayerHouse1F (6, 9) - totals: 3 legs, 2 turns, 1 open, 0 localization + 1. west 1 (open) -> PlayerHouse1F (10, 8) + 2. south 1 (open) -> PlayerHouse1F (10, 9) + 3. west 4 (to wall) -> PlayerHouse1F (6, 9) + totals: 3 legs, 2 turns, 2 open, 0 localization == 00.04 short_of_the_catch_tutorial (costs: route) from: TwinleafTown (6, 22) (6, 23) facing west (set) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json index 3ff849677b..768074a022 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/leg_trace_00.04.golden.json @@ -20,9 +20,9 @@ {"checkpoint":"00.04","chunks":0,"dir":"north","end":[],"end_kind":"wall","event":"into_the_east_corner","interrupts":[],"known":"wall","leg":1,"ms":0,"planned_end":[],"tiles":4}, {"checkpoint":"00.04","chunks":0,"dir":"east","end":[],"end_kind":"wall","event":"into_the_east_corner","interrupts":[],"known":"wall","leg":2,"ms":0,"planned_end":[],"tiles":6}, {"checkpoint":"00.04","chunks":0,"dir":"south","end":[],"end_kind":"wall","event":"into_the_east_corner","interrupts":[],"known":"wall","leg":3,"ms":0,"planned_end":[],"tiles":4}, - {"checkpoint":"00.04","chunks":3,"dir":"west","end":[["PlayerHouse1F",8,8]],"end_kind":"wall","event":"into_moms_call","interrupts":[],"known":"wall","leg":1,"ms":1350,"planned_end":[["PlayerHouse1F",8,8]],"tiles":3}, - {"checkpoint":"00.04","chunks":1,"dir":"south","end":[["PlayerHouse1F",8,9]],"end_kind":"open","event":"into_moms_call","interrupts":[],"known":"dead_reckoned","leg":2,"moved":1,"ms":800,"planned_end":[["PlayerHouse1F",8,9]],"tiles":1}, - {"checkpoint":"00.04","chunks":2,"dir":"west","end":[],"end_kind":"wall","event":"into_moms_call","interrupts":["scene"],"known":"dialogue","leg":3,"ms":450,"note":"scene","planned_end":[["PlayerHouse1F",6,9]],"tiles":2}, + {"checkpoint":"00.04","chunks":1,"dir":"west","end":[["PlayerHouse1F",10,8]],"end_kind":"open","event":"into_moms_call","interrupts":[],"known":"dead_reckoned","leg":1,"moved":1,"ms":800,"planned_end":[["PlayerHouse1F",10,8]],"tiles":1}, + {"checkpoint":"00.04","chunks":1,"dir":"south","end":[["PlayerHouse1F",10,9]],"end_kind":"open","event":"into_moms_call","interrupts":[],"known":"dead_reckoned","leg":2,"moved":1,"ms":800,"planned_end":[["PlayerHouse1F",10,9]],"tiles":1}, + {"checkpoint":"00.04","chunks":4,"dir":"west","end":[],"end_kind":"wall","event":"into_moms_call","interrupts":["scene"],"known":"dialogue","leg":3,"ms":650,"note":"scene","planned_end":[["PlayerHouse1F",6,9]],"tiles":4}, {"checkpoint":"00.04","chunks":0,"dir":"west","end":[],"end_kind":"wall","event":"to_twinleafs_west_wall","interrupts":[],"known":"wall","leg":1,"ms":0,"planned_end":[],"tiles":16}, {"checkpoint":"00.04","chunks":18,"dir":"north","end":[["Twinleaf Town",6,4]],"end_kind":"wall","event":"short_of_the_catch_tutorial","interrupts":[],"known":"wall","leg":1,"ms":3750,"planned_end":[["Twinleaf Town",6,4]],"tiles":19}, {"checkpoint":"00.04","chunks":8,"dir":"east","end":[["Twinleaf Town",14,4]],"end_kind":"open","event":"short_of_the_catch_tutorial","interrupts":[],"known":"dead_reckoned","leg":2,"moved":8,"ms":6400,"planned_end":[["Twinleaf Town",14,4]],"tiles":8},