diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 358de17122..7732433142 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -84,8 +84,10 @@ jobs: - name: Checkout Packages uses: actions/checkout@v7 with: - repository: 'PokemonAutomation/Packages' - ref: 'master' + # Upstream master plus the BDSP AutoStory option-screen templates (22 PNGs the + # AutoStoryResources test requires); drop this once they are merged upstream. + repository: 'dayfine/Packages' + ref: '7d108a255bfbd4923af1fb0cf49245f2c2483594' path: 'Arduino-Source/Packages' - name: Prepare pinned BDSP map resources diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h index a6fb75f8d0..0f36ff63fe 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h @@ -385,6 +385,11 @@ std::vector> consolidate(const std::vector>& l return consolidated; } +// The way back: the direction opposite `direction`. +inline Direction opposite(Direction direction){ + return Direction(((int)direction + 2) % 4); +} + // Dijkstra over sets of places the player may stand on. template class Search{ @@ -438,8 +443,9 @@ class Search{ 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)); + const auto wall = to_wall_leg(m_model, spread, direction, m_costs); + if (wall){ + relax(spread, cost, Expansion(*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++){ @@ -447,6 +453,11 @@ class Search{ if (!open){ break; } + // An open leg that ends where the leg to the wall does is + // that leg: it is held until the wall stops the player. + if (wall && wall->leg.tiles == open->leg.tiles && wall->leg.after == open->leg.after){ + continue; + } if (!open->unsafe){ relax(spread, cost, std::move(*open)); } @@ -463,7 +474,17 @@ class Search{ return; } if (spread != m_start){ - const RobustLeg& prev = m_nodes.at(spread).leg; + const Node& arrived = m_nodes.at(spread); + const RobustLeg& prev = arrived.leg; + // A run to a wall and back after a tapped leg: the taps left the + // player on a known tile, so the run past it and back adds a + // turn for nothing. From the start or after a leg to a wall it + // is how a long leg is made fast and exact. + if (prev.to_wall && arrived.parent != m_start && expansion.leg.direction == opposite(prev.direction)){ + if (!m_nodes.at(arrived.parent).leg.to_wall){ + return; + } + } if (joins(prev, expansion.leg)){ expansion.cost -= m_costs.per_leg; } diff --git a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp index c51b846fd4..2b5857e0ed 100644 --- a/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/PokemonBDSP_Tests.cpp @@ -8,6 +8,7 @@ #include "Inference/PokemonBDSP_DialogDetector.h" #include "Inference/PokemonBDSP_MenuDetector.h" #include "Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.h" +#include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FrozenTrainer_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_GridSim_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.h" #include "Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.h" @@ -54,6 +55,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_PlannedRoute(database); add_tests_AutoStory_SimulatedRoute(database); add_tests_AutoStory_GridSim(database); + add_tests_AutoStory_FrozenTrainer(database); add_tests_AutoStory_WallBattleSim(database); add_tests_AutoStory_RecoveryWalk(database); add_tests_AutoStory_StorySim(database); 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 7efb46838c..b328d00fe2 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 @@ -26,6 +26,7 @@ #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" +#include "PokemonBDSP_AutoStory_BagScreen.h" #include "PokemonBDSP_AutoStory_BattleMoves.h" #include "PokemonBDSP_AutoStory_Center.h" #include "PokemonBDSP_AutoStory_Events.h" @@ -562,6 +563,27 @@ UnitTestResult test_move_menu_screenshots(Logger& logger){ } +// The Potion after a fight reads the lead's HP when the Bag opens and goes +// on to the pocket and the list only if a dose is needed (lab-B 2026-11-12: +// it found the Potion, opened the party, read 80% and "no Potion needed"). +UnitTestResult test_potion_need(Logger&){ + struct Case{ std::string_view name; double hp; size_t dose; PotionNeed need; }; + const Case cases[] = { + {"full HP", 1.0, 0, PotionNeed::FULL}, + {"80% on the first dose with the check at 80%", 0.80, 0, PotionNeed::ENOUGH}, + {"a bit over the check", 0.90, 0, PotionNeed::ENOUGH}, + {"under the check", 0.55, 0, PotionNeed::NEEDED}, + {"the second dose heals on until full", 0.85, 1, PotionNeed::NEEDED}, + {"fainted", 0.0, 0, PotionNeed::FAINTED}, + }; + for (const Case& c : cases){ + if (potion_need(c.hp, c.dose, 0.8) != c.need){ + return std::string(c.name) + ": wrong verdict."; + } + } + return true; +} + struct AutoStoryActionsInput{ std::string name; std::function body; @@ -597,6 +619,10 @@ class Test_AutoStoryActions : public UnitTest{ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { + { + .input = {"Potion after a fight: the lead's HP decides before the Bag is searched", test_potion_need}, + .expectation = {}, + }, { .input = {"new-game intro decisions", test_intro_decisions}, .expectation = {}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.cpp index 47a82d84be..5e76a53bb2 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.cpp @@ -201,30 +201,35 @@ enum class Dose{ HEALED, GIVEN, NONE_LEFT }; // One Potion on the lead, from the overworld, its HP read before and after // in the Bag. HEALED when no dose is needed (HP full, or above -// `heal_below` on the first look, or no Potion when only checking) or the +// `heal_below` on the first look) or the // dose filled it; GIVEN when HP rose but is not full yet. Dose potion_dose(VideoStream& stream, ProControllerContext& context, size_t dose, double heal_below){ - stream.log("[Potion] Finding Bag/Medicine/Potion; dose " + std::to_string(dose + 1) + "/3."); - if (!find_bag_item_by_name(stream, context, "potion", 1, 5)){ - // No Potion left is not a failure: the next Center heals. After Roark - // the one Potion went on the first dose and the second found the - // Medicine pocket empty (lab-B, 2026-11-08 15:26). - stream.log("[Potion] No Potion left in the Bag after " + std::to_string(dose) + " dose(s); going on.", COLOR_ORANGE); - return Dose::NONE_LEFT; - } + stream.log("[Potion] Opening the Bag; dose " + std::to_string(dose + 1) + "/3."); + // The lead's HP shows as soon as the Bag opens: read it before the + // pocket is walked and the list scanned for a Potion nobody needs. + open_menu(stream, context, MenuCursorPosition::BAG, 5); + pbf_wait(context, 1000ms); const double before = confirmed_potion_hp(stream, context); stream.log("[Potion] Slot 1 HP bar before use=" + std::to_string(before * 100) + "%."); - if (before >= 0.98){ + switch (potion_need(before, dose, heal_below)){ + case PotionNeed::FULL: return Dose::HEALED; - } - if (dose == 0 && before >= heal_below){ + case PotionNeed::ENOUGH: stream.log("[Potion] Slot 1 HP is at least " + std::to_string(heal_below * 100) + "%; no Potion needed."); return Dose::HEALED; - } - if (before <= 0.005){ + case PotionNeed::FAINTED: OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, "Potion: Slot 1 appears fainted; a Potion cannot revive it.", stream); + case PotionNeed::NEEDED: + break; + } + if (!find_bag_item_in_open_bag(stream, context, "potion", 1)){ + // No Potion left is not a failure: the next Center heals. After Roark + // the one Potion went on the first dose and the second found the + // Medicine pocket empty (lab-B, 2026-11-08 15:26). + stream.log("[Potion] No Potion left in the Bag after " + std::to_string(dose) + " dose(s); going on.", COLOR_ORANGE); + return Dose::NONE_LEFT; } pbf_press_button(context, BUTTON_A, 80ms, 500ms); pbf_press_button(context, BUTTON_A, 80ms, 500ms); @@ -326,6 +331,16 @@ bool bag_list_is_empty(const ImageViewRGB32& frame){ return stats.average.r > 220 && stats.average.g > 220 && stats.average.b > 220 && stats.stddev.sum() < 20; } +PotionNeed potion_need(double hp, size_t dose, double heal_below){ + if (hp >= 0.98){ + return PotionNeed::FULL; + } + if (dose == 0 && hp >= heal_below){ + return PotionNeed::ENOUGH; + } + return hp <= 0.005 ? PotionNeed::FAINTED : PotionNeed::NEEDED; +} + BagPocketMovePlan plan_bag_pocket_move(int current, int target){ if (current < 1 || current > 8 || target < 1 || target > 8){ return {}; @@ -381,6 +396,19 @@ bool bag_has_item(VideoStream& stream, ProControllerContext& context, const std: return found; } +std::vector bag_has_items( + VideoStream& stream, ProControllerContext& context, const std::vector& names, int target_pocket +){ + std::vector found; + open_menu(stream, context, MenuCursorPosition::BAG, 5); + pbf_wait(context, 1000ms); + for (const std::string& name : names){ + found.push_back(find_bag_item_in_open_bag(stream, context, name, target_pocket)); + } + bag_back_to_overworld(stream, context, "Bag: Did not return to the overworld after looking for the Key Items."); + return found; +} + void use_potion_first_pokemon(VideoStream& stream, ProControllerContext& context, double heal_below){ OverlayBoxScope hp_overlay(stream.overlay(), COLOR_GREEN, {0.137, 0.160, 0.202, 0.016}, ""); bool healed = false; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.h index 8d36bcb927..f38caf2785 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Bag.h @@ -13,6 +13,7 @@ #include #include +#include #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" @@ -52,6 +53,15 @@ bool bag_has_item( int target_pocket ); +// Open the Bag from the overworld once, look for each of `names` in the +// pocket, and close it again. Whether each is there, in `names`' order. +std::vector bag_has_items( + VideoStream& stream, + ProControllerContext& context, + const std::vector& names, + int target_pocket +); + // Read the lead's HP bar in the Bag and, if it is below `heal_below` (a // fraction of full), use Potions until it is full. heal_below = 1 always // heals; 0.5 only checks and heals when the lead is under half, and is diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.cpp index c2fbea43f9..11bc87234f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.cpp @@ -24,7 +24,8 @@ constexpr std::string_view STORY_ITEM_OCR = R"JSON({ "eng": { "potion": ["Potion"], "antidote": ["Antidote"], "paralyze-heal": ["Paralyze Heal"], "awakening": ["Awakening"], "poke-ball": ["Poké Ball", "Poke Ball"], "repel": ["Repel"], - "super-repel": ["Super Repel"], "max-repel": ["Max Repel"], "escape-rope": ["Escape Rope"] + "super-repel": ["Super Repel"], "max-repel": ["Max Repel"], "escape-rope": ["Escape Rope"], + "coupon-1": ["Coupon 1"], "coupon-2": ["Coupon 2"], "coupon-3": ["Coupon 3"] }, "fra": { "potion": ["Potion"], "antidote": ["Antidote"], "paralyze-heal": ["Anti-Para"], @@ -109,6 +110,12 @@ std::string read_bag_item_slug(Logger& logger, Language language, const ImageVie return StoryItemMatcher::instance().read(logger, language, image); } +bool bag_item_named(Language language, std::string_view slug){ + const JsonValue json = parse_json(std::string(STORY_ITEM_OCR)); + const JsonObject* names = json.to_object_throw().get_object(language_data(language).code); + return names != nullptr && names->get_value(std::string(slug)) != nullptr; +} + } // namespace PokemonBDSP } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.h index 5f378de015..f4e7779ffe 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagItemReader.h @@ -11,6 +11,7 @@ #define PokemonAutomation_PokemonBDSP_AutoStory_BagItemReader_H #include +#include #include "Common/Cpp/Logging/AbstractLogger.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" @@ -24,6 +25,10 @@ namespace PokemonBDSP{ // "" when it is none of them. std::string read_bag_item_slug(Logger& logger, Language language, const ImageViewRGB32& image); +// Whether the reader has a name for the item `slug` in `language` (the +// coupons have their English names only). +bool bag_item_named(Language language, std::string_view slug); + } // namespace PokemonBDSP } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagScreen.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagScreen.h index 10b3f3bacd..c402094232 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagScreen.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_BagScreen.h @@ -41,6 +41,19 @@ struct BagPocketMovePlan{ BagPocketMovePlan plan_bag_pocket_move(int current, int target); +// What a first look at the lead's HP says about a Potion. +enum class PotionNeed{ + FULL, // nothing to heal + ENOUGH, // on the first dose, at or above `heal_below`: no Potion needed + FAINTED, // a Potion cannot revive it + NEEDED, +}; +// Whether the lead at `hp` (a fraction of full) needs dose number `dose` +// (0 first) of a Potion. Read before the Bag's pocket is walked for the +// Potion: no search when none is needed. +PotionNeed potion_need(double hp, size_t dose, double heal_below); + + } // namespace PokemonBDSP } // namespace NintendoSwitch } // namespace PokemonAutomation 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 64d5acd2fa..5ed92a1f06 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h @@ -26,7 +26,9 @@ #include #include #include +#include #include +#include #include #include "Pokemon/Navigation/Pokemon_MapData.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h" @@ -77,8 +79,19 @@ bool asks_someone_else(const Pokemon::MapData& map, Pokemon::TilePos stand, Poke // 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(); +// A Jubilife clown's coupon (00.05b): his talk step and the Key Item's +// Bag slug. +struct ClownCoupon{ + std::string_view step; + std::string_view slug; +}; +// The three clowns' coupons: the Mart's 1, the company's 2, the TV's 3. +std::span jubilife_clown_coupons(); +// The row the Poketch Company's clown wanders, round (15, 18), as the +// Mart clown's box. +Pokemon::TileBox jubilife_company_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). +// (00.05b's end), and below the east-exit sign (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 858b79e2ee..68d15a9618 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 @@ -9,6 +9,9 @@ #include #include +#include +#include +#include #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" @@ -28,6 +31,9 @@ #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" #include "PokemonBDSP_AutoStory_Talks.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" +#include "PokemonBDSP_AutoStory_Bag.h" +#include "PokemonBDSP_AutoStory_BagItemReader.h" #include "PokemonBDSP_AutoStory_WildBattle.h" #include "PokemonBDSP_AutoStory_Events.h" #include "PokemonBDSP_AutoStory_WanderWait.h" @@ -172,7 +178,7 @@ class ConsoleWanderWait : public WanderWaitBody{ 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))); + fail_step(m_stream, std::format("{}: {} instead of a one-tile step.", label, walk_stop_name(result.stop))); } return *moved != 0; } @@ -199,16 +205,21 @@ class ConsoleWanderWait : public WanderWaitBody{ 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. +// then on its "far_stand" tiles (his box's other end), in turn, from the +// tile the step before left us on. It ends on its declared tile, against +// a wall the declared way and one at the stand 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 Pokemon::GridPose& far_stand = Pokemon::story_arg(step.args, "far_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."); } + if (!far_stand.tiles.empty() && !far_stand.facing){ + fail_step(stream, step.name + ": its far stand tiles need a facing."); + } 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); @@ -217,7 +228,10 @@ Pokemon::Outcome wait_for_wanderer(StoryExecutor& executor, Pokemon::RunState& s } // 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}}; + WanderWaitPlan plan{.sides = {{.stands = stand.tiles, .facing = *stand.facing}}, .exit = exit_tiles[0], .exit_walls = {*exit_wall, back}}; + if (!far_stand.tiles.empty()){ + plan.sides.push_back({.stands = far_stand.tiles, .facing = *far_stand.facing}); + } 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){ @@ -227,9 +241,9 @@ Pokemon::Outcome wait_for_wanderer(StoryExecutor& executor, Pokemon::RunState& s 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))); + fail_step(stream, std::format("{}: a step on the way 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, std::format("{}: a step from {} moved to {}: not on the exit.", step.name, Pokemon::to_string(exit_tiles[0]), Pokemon::to_string(result.at))); } fail_step(stream, step.name + ": unknown wait end."); } @@ -246,8 +260,42 @@ void check_poketch(VideoStream& stream, ProControllerContext& context){ stream.log("[Talk] The Poketch is on the screen."); } +// The Bag's Key Items pocket. +constexpr int KEY_ITEMS_POCKET = 8; + +// The coupons in the Key Items pocket, when the reader has their names in +// the game's language: whether each clown's is held, in +// jubilife_clown_coupons()' order. +std::optional> held_coupons(VideoStream& stream, ProControllerContext& context){ + std::vector slugs; + for (const ClownCoupon& coupon : jubilife_clown_coupons()){ + if (!bag_item_named(story_language(), coupon.slug)){ + stream.log(std::format("[Coupons] No name for {} in the game's language: not read.", coupon.slug), COLOR_ORANGE); + return std::nullopt; + } + slugs.emplace_back(coupon.slug); + } + return bag_has_items(stream, context, slugs, KEY_ITEMS_POCKET); +} + +// 00.05b's end: all three coupons in the Bag, or the row fails here +// rather than saving a run the president will give no Poketch. +void check_coupons(VideoStream& stream, ProControllerContext& context){ + const std::optional> held = held_coupons(stream, context); + if (!held){ + return; + } + const std::span coupons = jubilife_clown_coupons(); + for (size_t i = 0; i < coupons.size(); i++){ + if (!(*held)[i]){ + fail_step(stream, std::format("No {} in the Key Items: {} gave none.", coupons[i].slug, coupons[i].step)); + } + } + stream.log("[Coupons] All three coupons are in the Key Items."); +} + // 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 +// (00.05b's end) or below the east-exit sign, (59, 21) facing north (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&){ @@ -297,14 +345,28 @@ Pokemon::TileBox jubilife_mart_clown_box(){ return {.x0 = 54, .y0 = 32, .x1 = 56, .y1 = 34}; } +std::span jubilife_clown_coupons(){ + static constexpr ClownCoupon COUPONS[] = { + {.step = "mart_clown", .slug = "coupon-1"}, + {.step = "company_clown", .slug = "coupon-2"}, + {.step = "tv_clown", .slug = "coupon-3"}, + }; + return COUPONS; +} + +Pokemon::TileBox jubilife_company_clown_box(){ + return {.x0 = 14, .y0 = 18, .x1 = 16, .y1 = 18}; +} + std::pair jubilife_start_tiles(){ - return {{14, 19}, {58, 22}}; + return {{14, 19}, {59, 21}}; } 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("check_coupons", console_event(check_coupons)); 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 index bd05488eeb..d9f4f29c57 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp @@ -4,6 +4,9 @@ * */ +#include +#include +#include #include "PokemonBDSP_AutoStory_WanderWait.h" namespace PokemonAutomation{ @@ -16,17 +19,19 @@ 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){ +// Walks a straight line 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 `tries` steps, or `to` is +// not on a line from `at`. +bool walk_line(WanderWaitBody& body, TilePos& at, TilePos to, const WanderWaitPlan& plan, size_t tries, bool* talked){ + if (at.x != to.x && at.y != to.y){ return false; } while (at != to){ - const Direction direction = to.y < at.y ? Direction::NORTH : Direction::SOUTH; - size_t tries = 0; + const Direction direction = at.x != to.x + ? (to.x < at.x ? Direction::WEST : Direction::EAST) + : (to.y < at.y ? Direction::NORTH : Direction::SOUTH); + size_t blocked = 0; while (!body.step(direction)){ if (talked != nullptr && !*talked){ body.face(direction); @@ -35,7 +40,7 @@ bool walk_column(WanderWaitBody& body, TilePos& at, TilePos to, const WanderWait return true; } } - if (++tries >= plan.asks){ + if (++blocked >= tries){ return false; } body.wait(plan.blocked_wait); @@ -45,9 +50,45 @@ bool walk_column(WanderWaitBody& body, TilePos& at, TilePos to, const WanderWait 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); +// The row to cross between columns from `at` to `to`: the one above the +// stands or the one below, whichever walk is shorter. +int crossing_row(const WanderWaitPlan& plan, const TilePos& at, const TilePos& to){ + std::optional top; + std::optional bottom; + for (const WanderWaitSide& side : plan.sides){ + for (const TilePos& stand : side.stands){ + top = top ? std::min(*top, stand.y) : stand.y; + bottom = bottom ? std::max(*bottom, stand.y) : stand.y; + } + } + const int above = top.value_or(at.y) - 1; + const int below = bottom.value_or(at.y) + 1; + const int up = std::abs(at.y - above) + std::abs(to.y - above); + const int down = std::abs(at.y - below) + std::abs(to.y - below); + return up <= down ? above : below; +} + +// Walks from `at` to `to`: along the row or the column they share, or +// between columns along a crossing row. Asks a blocked step in the row or +// column as walk_line() does: in his zone, it is him. +bool walk_to(WanderWaitBody& body, TilePos& at, TilePos to, const WanderWaitPlan& plan, size_t tries, bool* talked){ + if (at.x == to.x || at.y == to.y){ + return walk_line(body, at, to, plan, tries, talked); + } + const int row = crossing_row(plan, at, to); + if (!walk_line(body, at, {at.x, row}, plan, tries, talked)){ + return false; + } + if (talked != nullptr && *talked){ + return true; + } + return walk_line(body, at, {to.x, row}, plan, tries, nullptr) + && walk_line(body, at, to, plan, tries, talked); +} + +// Asks from where the player stands, facing `facing`. +bool ask_from_stand(WanderWaitBody& body, const WanderWaitPlan& plan, Direction facing){ + body.face(facing); for (size_t ask = 0; ask < plan.asks; ask++){ if (body.ask()){ return true; @@ -57,6 +98,49 @@ bool ask_from_stand(WanderWaitBody& body, const WanderWaitPlan& plan){ return false; } +// The way into the box from the side whose column `at` is on. +std::optional inward_from(const WanderWaitPlan& plan, const TilePos& at){ + for (const WanderWaitSide& side : plan.sides){ + if (!side.stands.empty() && side.stands[0].x == at.x){ + return side.facing; + } + } + return std::nullopt; +} + +// Walks from where the talk counted to the exit. If he stays in the way +// on the column, steps into the box beside him and goes round. +bool walk_out(WanderWaitBody& body, TilePos& at, const WanderWaitPlan& plan){ + if (walk_to(body, at, plan.exit, plan, plan.exit_tries, nullptr)){ + return true; + } + const std::optional inward = inward_from(plan, at); + if (!inward || at.x != plan.exit.x || !body.step(*inward)){ + return walk_to(body, at, plan.exit, plan, plan.blocked_tries, nullptr); + } + at = at.next(*inward); + return walk_to(body, at, plan.exit, plan, plan.blocked_tries, nullptr); +} + +// Walks `side`'s stands the plan's passes, asking from each, until the +// talk counts (`talked`, on `at`). False if a step stayed blocked. +bool wait_at_side(WanderWaitBody& body, TilePos& at, const WanderWaitPlan& plan, const WanderWaitSide& side, bool& talked){ + for (size_t pass = 0; pass < plan.passes; pass++){ + for (const TilePos& stand : side.stands){ + if (!walk_to(body, at, stand, plan, plan.blocked_tries, &talked)){ + return false; + } + if (!talked){ + talked = ask_from_stand(body, plan, side.facing); + } + if (talked){ + return true; + } + } + } + return true; +} + } // namespace @@ -64,23 +148,17 @@ WanderWaitResult wait_beside_wanderer(WanderWaitBody& body, TilePos at, const Wa 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)){ + for (size_t s = 0; s < plan.sides.size() && !talked; s++){ + if (!wait_at_side(body, at, plan, plan.sides[s], talked)){ return {.end = WanderWaitEnd::STUCK, .at = at, .talked = at}; } - if (!talked){ - talked = ask_from_stand(body, plan); - } - if (talked){ - talked_at = at; - break; - } + talked_at = at; } } if (!talked){ return {.end = WanderWaitEnd::NO_TALK, .at = at, .talked = at}; } - if (!walk_column(body, at, plan.exit, plan, nullptr)){ + if (!walk_out(body, at, plan)){ return {.end = WanderWaitEnd::STUCK, .at = at, .talked = talked_at}; } for (Direction wall : plan.exit_walls){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h index 5cd7813aa1..437a9ab50d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h @@ -3,9 +3,15 @@ * 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. + * him: stand on an end column of his box, inside it, face in, and ask + * each time he may have come level, then try the next tile. Our tile is + * one he can no longer step on, so he comes level more often. A box wider + * than two columns has a far column he can stay on out of reach: the wait + * then takes turns between the two ends, and a side may hold tiles a step + * in from its end, toward him. The Mart clown (00.05b, 00.05c) wanders + * columns 54 to 56: he is waited for on 56 facing west, then on 54 facing + * east. The Poketch Company's clown wanders the row (14..16, 18): from + * 14 and 15 facing east, then 16 and 15 facing west. * */ @@ -22,23 +28,40 @@ 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. +// One end of his box to wait at: tiles on one column, in order, a tile +// apart (the list is walked again from its start: end it a tile from its +// first), and the way to face from them, into the box. +struct WanderWaitSide{ std::vector stands; - // The way to face from a stand: toward his box. Pokemon::Direction facing = Pokemon::Direction::WEST; +}; + +// Where and how long to wait. Between stands on one row or column the +// wait walks straight; between columns otherwise it walks round the +// stands' rows: along the row above them or the one below, whichever is +// shorter. Those rows must be open. +struct WanderWaitPlan{ + // The ends to wait at, in turn; the list is walked `rounds` times. + std::vector sides; // 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; + // Asks from each stand before the next one: few, so the wait steps on + // to his row instead of pressing A at nobody (lab-B 2026-11-12 11:03: + // twelve asks from (56, 32) while he stood on (55, 33)). + size_t asks = 2; + // Times a side's stands are walked before the next side. + size_t passes = 3; // 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); + // Blocked steps on the way before giving up, and on the way out + // before walking round him. + size_t blocked_tries = 12; + size_t exit_tries = 3; size_t rounds = 2; }; @@ -59,8 +82,8 @@ class WanderWaitBody{ 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 + STUCK, // a step on the way stayed blocked + LOST, // an exit wall was not there: not on the exit }; // How a wait ended, and where. struct WanderWaitResult{ @@ -69,8 +92,8 @@ struct WanderWaitResult{ 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 +// Waits for the wanderer from `at`, at the plan's sides in turn. A step +// in his box that something stops is him 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); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp index 5994605164..a779393868 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp @@ -20,6 +20,7 @@ #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" #include "CommonTools/Async/InferenceRoutines.h" #include "CommonTools/OCR/OCR_RawTesseractOCR.h" +#include "CommonTools/OCR/OCR_Routines.h" #include "CommonTools/VisualDetectors/BlackScreenDetector.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonBDSP/Inference/Battles/PokemonBDSP_BattleMenuDetector.h" @@ -32,7 +33,10 @@ #include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" #include "PokemonBDSP/Inference/PokemonBDSP_ReceivePokemonDetector.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" +#include "PokemonBDSP_AutoStory_Bag.h" #include "PokemonBDSP_AutoStory_Battle.h" +#include "PokemonBDSP_AutoStory_Talks.h" #include "PokemonBDSP_AutoStory_WildBattle.h" namespace PokemonAutomation{ @@ -223,6 +227,11 @@ class ConsoleWildBattleEscape : public WildBattleEscapeActions{ virtual void fight() override{ fight_wild_battle(m_stream, m_context, "Mine escape"); } + virtual void fight_trainer() override{ + PokemonBDSP::fight_trainer(m_stream, m_context, "Mine escape"); + m_context.wait_for_all_requests(); + use_potion_first_pokemon(m_stream, m_context, 0.8); + } virtual void note(const std::string& text) override{ m_stream.log("[Mine escape] " + text); } @@ -235,6 +244,9 @@ class ConsoleWildBattleEscape : public WildBattleEscapeActions{ private: // B, then the exit (0) or the battle menu (1) within three seconds; -1 for neither. int exit_or_menu(); + // After A on Run: whether the box under the battle says a Trainer + // battle cannot be run from. Read while its text is still up. + bool says_no_running(); VideoStream& m_stream; ProControllerContext& m_context; @@ -249,6 +261,20 @@ int ConsoleWildBattleEscape::exit_or_menu(){ return wait_until(m_stream, m_context, 3s, {{m_battle_end}, {menu_ready}}); } +bool ConsoleWildBattleEscape::says_no_running(){ + // The refusal's box: the bottom of the battle screen, as a dialogue's. + const ImageFloatBox text_box(0.19, 0.80, 0.64, 0.18); + pbf_press_button(m_context, BUTTON_A, 80ms, 600ms); + m_context.wait_for_all_requests(); + const VideoSnapshot frame = m_stream.video().snapshot(); + if (!frame){ + return false; + } + const std::string text = OCR::ocr_read(story_language(), extract_box_reference(frame, text_box), OCR::PageSegMode::SINGLE_BLOCK); + m_stream.log("[Mine escape] Text after Run: \"" + text + "\""); + return sign_text_matches(text, "trainer"); +} + WildRunOutcome ConsoleWildBattleEscape::run(){ const int ready = exit_or_menu(); if (ready == 0){ @@ -257,6 +283,9 @@ WildRunOutcome ConsoleWildBattleEscape::run(){ if (ready != 1 || !mine_select_run(m_stream, m_context, m_battle_type)){ return WildRunOutcome::UNCERTAIN; } + if (says_no_running()){ + return WildRunOutcome::NO_RUNNING; + } m_stream.log("[Mine escape] Run input sent; watching for black-screen exit."); const int result = run_until(m_stream, m_context, @@ -435,8 +464,8 @@ void escape_wild_battle(VideoStream& stream, const WildBattleEscapePolicy& policy){ ConsoleWildBattleEscape actions(stream, context, battle_type); WildEscapeResult result = escape_wild_battle(actions, policy); - if (result == WildEscapeResult::FOUGHT){ - // fight_wild_battle() ended on the overworld. + if (result == WildEscapeResult::FOUGHT || result == WildEscapeResult::TRAINER_FOUGHT){ + // fight_wild_battle() and fight_trainer() ended on the overworld. return; } if (result == WildEscapeResult::UNCONFIRMED && actions.exit_within(10s)){ 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 f85a1def34..9fe25f5a57 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt @@ -29,7 +29,7 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 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 short_of_the_catch_tutorial | 84001 | 81950 | 49900 | 6 | 19 | 7 | 4.73! | 1.00 | 57.00! | 17750 ms (stand-in) | PASS +00.04 short_of_the_catch_tutorial | 84406 | 81950 | 51250 | 7 | 19 | 7 | 4.76! | 1.00 | 62.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 00.04d north_to_jubilife | 73575 | 42700 | 30350 | 8 | 35 | 0 | 7.21! | 1.24 | 80.00! | 10200 ms (stand-in) | PASS @@ -38,13 +38,10 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 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 | 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 | 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 +00.05b beside_the_company_sign | 0 | 0 | 0 | 0 | 0 | 0 | 0.00 | 1.00 | 1.00 | 250 ms (stand-in) | PASS +00.05c beside_the_president | 30150 | 30150 | 30150 | 1 | 0 | 0 | 5.24! | 1.00 | 1.00 | 5750 ms (stand-in) | PASS +00.05c below_the_east_exit_sign | 12150 | 12150 | 12150 | 2 | 0 | 0 | 3.24! | 1.00 | 1.00 | 3750 ms (stand-in) | PASS +01.01 west_of_barrys_trigger | 7400 | 7400 | 7400 | 0 | 0 | 0 | 6.17! | 1.00 | 1.00 | 1200 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 @@ -61,8 +58,8 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 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 -01.10 line_2 | 3250 | 3250 | 3250 | 1 | 0 | 0 | 2.83! | 1.00 | 1.00 | 1150 ms (stand-in) | PASS +01.10 line_1 | 1950 | 1950 | 1950 | 1 | 0 | 0 | 2.29! | 1.00 | 1.00 | 850 ms (stand-in) | PASS +01.10 line_2 | 9800 | 9800 | 9800 | 0 | 0 | 0 | 6.12! | 1.00 | 1.00 | 1600 ms (stand-in) | PASS 01.10 line_3 | 4100 | 4100 | 4100 | 0 | 0 | 0 | 4.10! | 1.00 | 1.00 | 1000 ms (stand-in) | PASS 01.10 line_4 | 4050 | 4050 | 4050 | 1 | 0 | 0 | 3.86! | 1.00 | 1.00 | 1050 ms (stand-in) | PASS 01.10 line_5 | 15110 | 20050 | 7700 | 1 | 6 | 0 | 7.75! | 1.17 | 1.00 | 1950 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 6f060714f7..f967f06877 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt @@ -154,11 +154,12 @@ anchor); 0 from one start tile. 5. west 7 (open) -> Route 201 (50, 13) 6. north 7 (open) -> Route 201 (50, 6) 7. east 43 (to wall) -> Sandgem Town (29, 13) - 8. west 5 (open) -> Sandgem Town (24, 13) - 9. north 21 (to wall) -> Route 202 (25, 24) - 10. west 3 (to wall) -> Route 202 (22, 24) - 11. south 3 (open) -> Route 202 (22, 27) - totals: 11 legs, 10 turns, 5 open, 1 localization + 8. north 2 (to wall) -> Sandgem Town (29, 11) + 9. west 5 (open) -> Sandgem Town (24, 11) + 10. north 19 (to wall) -> Route 202 (25, 24) + 11. west 3 (to wall) -> Route 202 (22, 24) + 12. south 3 (open) -> Route 202 (22, 27) + totals: 12 legs, 11 turns, 5 open, 1 localization == 00.04b to_catch_grass (costs: route) from: Route202 (15, 25) (16, 25) (17, 25) (18, 25) (19, 25) (20, 25) (21, 25) (15, 26) (16, 26) (17, 26) (18, 26) (19, 26) (20, 26) (21, 26) (15, 27) (16, 27) (17, 27) (18, 27) (19, 27) (20, 27) (21, 27) (21, 28) (21, 29) (set) @@ -243,60 +244,37 @@ anchor); 0 from one start tile. totals: 3 legs, 2 turns, 3 open, 0 localization == 00.05b beside_the_company_sign (costs: line) - from: JubilifeCity (15, 19) facing north (tile) - target: JubilifeCity (14, 19) facing west (tile) - start candidates: Jubilife City (15, 19) - 1. west 1 (to wall) -> Jubilife City (14, 19) - totals: 1 legs, 0 turns, 0 open, 0 localization - -== 00.05c below_the_company_clown (costs: town) from: JubilifeCity (14, 19) facing west (tile) - target: JubilifeCity (15, 19) facing north (tile) + target: JubilifeCity (14, 19) facing west (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 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 (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. 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 + totals: 0 legs, 0 turns, 0 open, 0 localization == 00.05c beside_the_president (costs: town) - from: JubilifeCity (56, 31) facing north (tile) + from: JubilifeCity (14, 19) facing west (tile) target: JubilifeCity (45, 35) facing east (tile) - 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 + start candidates: Jubilife City (14, 19) + 1. south 4 (open) -> Jubilife City (14, 23) + 2. east 18 (open) -> Jubilife City (32, 23) + 3. south 12 (open) -> Jubilife City (32, 35) + 4. east 13 (to wall) -> Jubilife City (45, 35) + totals: 4 legs, 3 turns, 3 open, 0 localization -== 00.05c to_the_route_203_street (costs: line) +== 00.05c below_the_east_exit_sign (costs: line) from: JubilifeCity (45, 35) facing east (tile) - target: JubilifeCity (58, 22) facing east (tile) + target: JubilifeCity (59, 21) facing north (tile) start candidates: Jubilife City (45, 35) - 1. north 13 (open) -> Jubilife City (45, 22) - 2. east 13 (open) -> Jubilife City (58, 22) - totals: 2 legs, 1 turns, 2 open, 0 localization + 1. north 9 (open) -> Jubilife City (45, 26) + 2. east 14 (to wall) -> Jubilife City (59, 26) + 3. north 5 (to wall) -> Jubilife City (59, 21) + totals: 3 legs, 2 turns, 1 open, 0 localization == 01.01 west_of_barrys_trigger (costs: town) - from: JubilifeCity (58, 22) facing east (tile) + from: JubilifeCity (59, 21) facing north (tile) target: Route203 (4, 18) facing east (tile) - start candidates: Jubilife City (58, 22) - 1. east 9 (open) -> Route 203 (4, 18) - totals: 1 legs, 0 turns, 1 open, 0 localization + start candidates: Jubilife City (59, 21) + 1. south 1 (open) -> Jubilife City (59, 22) + 2. east 8 (open) -> Route 203 (4, 18) + totals: 2 legs, 1 turns, 2 open, 0 localization == 01.02 south_to_the_cliff (costs: route) from: Route203 (5, 17) (5, 18) (5, 19) (5, 20) facing east (set) @@ -315,38 +293,31 @@ anchor); 0 from one start tile. 4. south 3 (open) -> Route 203 (55, 9) totals: 4 legs, 3 turns, 2 open, 0 localization -== 01.02 west_of_the_hikers_trigger (costs: route) +== 01.02 into_the_hikers_scene (costs: into_scene) from: OreburghGate (4, 22) (5, 22) facing east (set) - target: OreburghGate (6, 22) facing east (tile) + target: OreburghGate (4, 22) (5, 22) facing east (set) start candidates: OreburghGate (4, 22), OreburghGate (5, 22) - 1. south 1 (to wall) -> OreburghGate (4, 23), OreburghGate (5, 23) - 2. east 2 (to wall) -> OreburghGate (6, 23) - 3. north 1 (open) -> OreburghGate (6, 22) - totals: 3 legs, 2 turns, 1 open, 2 localization + totals: 0 legs, 0 turns, 0 open, 0 localization -== 01.02 past_curtis (costs: route) +== 01.02 past_curtis (costs: exit) from: OreburghGate (7, 22) facing east (tile) target: OreburghGate (20, 22) facing east (tile) start candidates: OreburghGate (7, 22) 1. east 13 (open) -> OreburghGate (20, 22) totals: 1 legs, 0 turns, 1 open, 0 localization -== 01.02 by_the_east_mouth (costs: route) +== 01.02 by_the_east_mouth (costs: exit) from: OreburghGate (20, 22) facing east (tile) target: OreburghGate (26, 22) facing east (tile) start candidates: OreburghGate (20, 22) 1. east 6 (open) -> OreburghGate (26, 22) totals: 1 legs, 0 turns, 1 open, 0 localization -== 01.02 west_of_the_welcome (costs: route) +== 01.02 into_the_welcome_scene (costs: into_scene) from: OreburghCity (2, 13) (3, 13) facing east (set) - target: OreburghCity (9, 13) facing east (tile) + target: OreburghCity (2, 13) (3, 13) facing east (set) start candidates: Oreburgh City (2, 13), Oreburgh City (3, 13) - 1. north 3 (to wall) -> Oreburgh City (2, 10), Oreburgh City (3, 10) - 2. east 4 (to wall) -> Oreburgh City (6, 10) - 3. south 3 (open) -> Oreburgh City (6, 13) - 4. east 3 (open) -> Oreburgh City (9, 13) - totals: 4 legs, 3 turns, 2 open, 2 localization + totals: 0 legs, 0 turns, 0 open, 0 localization == 01.02b below_the_centers_door (costs: town) from: OreburghCity (26, 22) facing north (tile) @@ -447,19 +418,19 @@ anchor); 0 from one start tile. totals: 3 legs, 2 turns, 1 open, 0 localization == 01.10 line_1 (costs: line) - from: Route204North (20, 26) facing south (tile) - target: Route204North (20, 27) (tile) - start candidates: Route 204 (20, 26) - 1. south 1 (open) -> Route 204 (20, 27) - totals: 1 legs, 0 turns, 1 open, 0 localization + from: Route204North (20, 26) (20, 27) facing south (set) + target: Route204North (20, 30) (tile) + start candidates: Route 204 (20, 26), Route 204 (20, 27) + 1. south 4 (to wall) -> Route 204 (20, 30) + totals: 1 legs, 0 turns, 0 open, 1 localization == 01.10 line_2 (costs: line) - from: Route204North (20, 27) (tile) + from: Route204North (20, 30) (tile) target: Route204North (11, 27) (tile) - start candidates: Route 204 (20, 27) - 1. west 10 (to wall) -> Route 204 (10, 27) - 2. east 1 (open) -> Route 204 (11, 27) - totals: 2 legs, 1 turns, 1 open, 0 localization + start candidates: Route 204 (20, 30) + 1. north 3 (open) -> Route 204 (20, 27) + 2. west 9 (open) -> Route 204 (11, 27) + totals: 2 legs, 1 turns, 2 open, 0 localization == 01.10 line_3 (costs: line) from: Route204North (11, 27) (tile) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h index e63fe2d69b..47e3e41ac8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlanGolden.h @@ -25,9 +25,6 @@ inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { "00.01 below_the_flute costs=default from PlayerHouse2F (4, 6) to PlayerHouse2F (7, 5)", "00.01 north 1 (to wall) -> PlayerHouse2F (4, 5)", "00.01 east 3 (open) -> PlayerHouse2F (7, 5)", - "00.01 onto_the_flute_tile costs=default from PlayerHouse2F (7, 5) to PlayerHouse2F (8, 4)", - "00.01 north 1 (to wall) -> PlayerHouse2F (7, 4)", - "00.01 east 1 (to wall) -> PlayerHouse2F (8, 4)", "00.01 above_the_door costs=default from PlayerHouse1F (10, 3) (10, 4) to PlayerHouse1F (6, 9)", "00.01 south 7 (to wall) -> PlayerHouse1F (10, 10)", "00.01 north 1 (open) -> PlayerHouse1F (10, 9)", @@ -36,39 +33,21 @@ inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { "00.01 west 7 (open) -> Twinleaf Town (13, 22)", "00.01 north 10 (to wall) -> Twinleaf Town (13, 12)", "00.01 west 3 (open) -> Twinleaf Town (10, 12)", - "00.01 back_onto_barrys_doorstep costs=default from TwinleafTown (9, 13) to TwinleafTown (9, 12)", - "00.01 north 1 (open) -> Twinleaf Town (9, 12)", "00.01 below_barrys_stairs costs=default from RivalHouse1F (6, 9) to RivalHouse1F (2, 3)", "00.01 west 4 (to wall) -> RivalHouse1F (2, 9)", "00.01 north 6 (to wall) -> RivalHouse1F (2, 3)", - "00.01 above_barrys_stairs costs=default from RivalHouse2F (3, 5) to RivalHouse2F (3, 4)", - "00.01 north 1 (to wall) -> RivalHouse2F (3, 4)", "00.01 above_barrys_door costs=default from RivalHouse1F (2, 3) to RivalHouse1F (6, 9)", "00.01 south 6 (open) -> RivalHouse1F (2, 9)", "00.01 east 4 (open) -> RivalHouse1F (6, 9)", - "00.01 below_barrys_warning costs=default from TwinleafTown (9, 12) to Route201 (15, 19)", - "00.01 east 6 (open) -> Twinleaf Town (15, 12)", - "00.01 north 24 (to wall) -> Route 201 (15, 13)", - "00.01 south 6 (open) -> Route 201 (15, 19)", - "00.01 away_from_barry costs=default from Route201 (15, 18) to Route201 (12, 17)", - "00.01 north 1 (open) -> Route 201 (15, 17)", - "00.01 west 3 (open) -> Route 201 (12, 17)", - "00.01 below_the_lake_entrance costs=default from Route201 (12, 17) to VerityLakefront (17, 14)", - "00.01 north 1 (open) -> Route 201 (12, 16)", - "00.01 west 26 (to wall) -> Verity Lakefront (18, 23)", + "00.01 below_the_lake_entrance costs=default from Route201 (14, 16) to VerityLakefront (17, 14)", + "00.01 west 28 (to wall) -> Verity Lakefront (18, 23)", "00.01 north 9 (to wall) -> Verity Lakefront (18, 14)", "00.01 west 1 (open) -> Verity Lakefront (17, 14)", "00.02 to_the_lake_entrance costs=default from VerityLakefront (17, 14) to VerityLakefront (17, 13)", "00.02 north 1 (open) -> Verity Lakefront (17, 13)", - "00.03 short_of_rowan costs=default from VerityLakefront (17, 14) (17, 15) to Route201 (4, 14)", + "00.03 into_rowans_scene costs=into_scene from VerityLakefront (17, 14) (17, 15) to VerityLakefront (17, 21)", "00.03 south 7 (to wall) -> Verity Lakefront (17, 21)", - "00.03 east 19 (open) -> Route 201 (4, 14)", - "00.03 by_the_counter costs=default from PlayerHouse1F (5, 8) (6, 8) to PlayerHouse1F (4, 8)", - "00.03 west 2 (to wall) -> PlayerHouse1F (4, 8)", - "00.03 above_the_door_again costs=default from PlayerHouse1F (4, 8) to PlayerHouse1F (6, 9)", - "00.03 east 2 (open) -> PlayerHouse1F (6, 8)", - "00.03 south 1 (open) -> PlayerHouse1F (6, 9)", - "00.03 short_of_dawn costs=default from TwinleafTown (20, 22) to Route201 (63, 5)", + "00.03 into_dawns_scene costs=into_scene from TwinleafTown (20, 22) to Route201 (63, 5)", "00.03 west 3 (open) -> Twinleaf Town (17, 22)", "00.03 north 34 (to wall) -> Route 201 (17, 13)", "00.03 east 40 (to wall) -> Route 201 (57, 13)", @@ -80,42 +59,46 @@ inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { "00.04 east 3 (to wall) -> Sandgem Town (29, 11) Sandgem Town (29, 12)", "00.04 north 1 (to wall) -> Sandgem Town (29, 11)", "00.04 south 1 (open) -> Sandgem Town (29, 12)", - "00.04 home costs=default from Route201 (57, 5) (58, 5) (59, 5) (60, 5) (61, 5) (62, 5) (63, 5) to TwinleafTown (20, 22) (20, 23) (20, 24) (20, 25) (20, 26)", - "00.04 west 21 (to wall) -> Route 201 (42, 5)", - "00.04 south 4 (open) -> Route 201 (42, 9)", - "00.04 west 28 (to wall) -> Route 201 (14, 9)", - "00.04 south 42 (to wall) -> Twinleaf Town (14, 26)", - "00.04 east 6 (open) -> Twinleaf Town (20, 26)", - "00.04 beside_mom costs=default from PlayerHouse1F (6, 9) to PlayerHouse1F (6, 7)", - "00.04 north 2 (open) -> PlayerHouse1F (6, 7)", - "00.04 around_mom costs=default from PlayerHouse1F (6, 7) to PlayerHouse1F (5, 9)", - "00.04 south 2 (open) -> PlayerHouse1F (6, 9)", - "00.04 west 1 (to wall) -> PlayerHouse1F (5, 9)", - "00.04 short_of_the_catch_tutorial costs=default from TwinleafTown (19, 22) to Route202 (22, 27)", - "00.04 west 2 (open) -> Twinleaf Town (17, 22)", - "00.04 north 34 (to wall) -> Route 201 (17, 13)", - "00.04 east 40 (to wall) -> Route 201 (57, 13)", + "00.04 to_ledge_column costs=line from Route201 (57, 4) (58, 4) (59, 4) (60, 4) (61, 4) (62, 4) (63, 4) to Route201 (55, 5)", + "00.04 west 7 (to wall) -> Route 201 (56, 4)", + "00.04 south 1 (open) -> Route 201 (56, 5)", + "00.04 west 1 (open) -> Route 201 (55, 5)", + "00.04 along_route_201_road costs=line from Route201 (55, 14) to Route201 (15, 14)", + "00.04 west 16 (open) -> Route 201 (39, 14)", + "00.04 north 3 (open) -> Route 201 (39, 11)", + "00.04 west 24 (open) -> Route 201 (15, 11)", + "00.04 south 2 (open) -> Route 201 (15, 14)", + "00.04 into_twinleaf costs=line from Route201 (15, 14) to TwinleafTown (15, 22)", + "00.04 south 33 (open) -> Twinleaf Town (15, 22)", + "00.04 to_moms_doorstep costs=line from TwinleafTown (15, 22) to TwinleafTown (20, 22)", + "00.04 east 5 (open) -> Twinleaf Town (20, 22)", + "00.04 beside_mom costs=default from PlayerHouse1F (6, 9) to PlayerHouse1F (6, 8)", + "00.04 north 1 (open) -> PlayerHouse1F (6, 8)", + "00.04 into_moms_call costs=trigger from PlayerHouse1F (11, 8) to PlayerHouse1F (6, 9)", + "00.04 west 1 (open) -> PlayerHouse1F (10, 8)", + "00.04 south 1 (open) -> PlayerHouse1F (10, 9)", + "00.04 west 4 (open) -> PlayerHouse1F (6, 9)", + "00.04 short_of_the_catch_tutorial costs=default from TwinleafTown (6, 22) (6, 23) to Route202 (22, 27)", + "00.04 north 19 (to wall) -> Twinleaf Town (6, 4)", + "00.04 east 8 (open) -> Twinleaf Town (14, 4)", + "00.04 north 16 (to wall) -> Route 201 (14, 13)", + "00.04 east 43 (to wall) -> Route 201 (57, 13)", "00.04 west 7 (open) -> Route 201 (50, 13)", "00.04 north 7 (open) -> Route 201 (50, 6)", "00.04 east 43 (to wall) -> Sandgem Town (29, 13)", - "00.04 west 5 (open) -> Sandgem Town (24, 13)", - "00.04 north 21 (to wall) -> Route 202 (25, 24)", + "00.04 north 2 (to wall) -> Sandgem Town (29, 11)", + "00.04 west 5 (open) -> Sandgem Town (24, 11)", + "00.04 north 19 (to wall) -> Route 202 (25, 24)", "00.04 west 3 (to wall) -> Route 202 (22, 24)", "00.04 south 3 (open) -> Route 202 (22, 27)", "00.04b to_catch_grass costs=default from Route202 (15, 25) (16, 25) (17, 25) (18, 25) (19, 25) (20, 25) (21, 25) (15, 26) (16, 26) (17, 26) (18, 26) (19, 26) (20, 26) (21, 26) (15, 27) (16, 27) (17, 27) (18, 27) (19, 27) (20, 27) (21, 27) (21, 28) (21, 29) to Route202 (18, 25) (19, 25) (20, 25) (18, 26) (19, 26) (20, 26) (18, 27) (19, 27) (20, 27)", - "00.04b east 15 (to wall) -> Route 202 (23, 25) Route 202 (30, 26) Route 202 (30, 27) Route 202 (30, 28) Route 202 (30, 29)", - "00.04b north 5 (to wall) -> Route 202 (23, 24) Route 202 (30, 24)", - "00.04b west 8 (to wall) -> Route 202 (22, 24)", - "00.04b south 1 (open) -> Route 202 (22, 25)", - "00.04b west 2 (open) -> Route 202 (20, 25)", + "00.04b north 4 (to wall) -> Route 202 (15, 25) Route 202 (16, 25) Route 202 (17, 25) Route 202 (18, 25) Route 202 (19, 25) Route 202 (20, 25) Route 202 (21, 25)", + "00.04b east 8 (to wall) -> Route 202 (23, 25)", + "00.04b west 3 (open) -> Route 202 (20, 25)", "00.04b into_sandgem costs=robust from Route202 (18, 25) (19, 25) (20, 25) (18, 26) (19, 26) (20, 26) (18, 27) (19, 27) (20, 27) to SandgemTown (29, 5)", "00.04b south 2 (to wall) -> Route 202 (18, 27) Route 202 (19, 27) Route 202 (20, 27)", "00.04b east 12 (to wall) -> Route 202 (30, 27)", "00.04b south 10 (to wall) -> Sandgem Town (29, 5)", - "00.04b below_center_door costs=town from SandgemTown (29, 5) to SandgemTown (17, 11)", - "00.04b west 5 (open) -> Sandgem Town (24, 5)", - "00.04b south 6 (open) -> Sandgem Town (24, 11)", - "00.04b west 7 (open) -> Sandgem Town (17, 11)", "00.04d north_to_jubilife costs=default from Route202 (30, 24) to Route202 (11, 0) (12, 0) (13, 0) (14, 0) (15, 0) (16, 0) (17, 0) (18, 0) (11, 1) (12, 1) (13, 1) (14, 1) (15, 1) (16, 1) (17, 1) (18, 1) (11, 2) (12, 2) (13, 2) (14, 2) (15, 2) (16, 2) (17, 2) (18, 2) (11, 3) (12, 3) (13, 3) (14, 3) (15, 3) (16, 3) (17, 3) (18, 3)", "00.04d south 2 (open) -> Route 202 (30, 26)", "00.04d west 27 (to wall) -> Route 202 (3, 26)", @@ -127,125 +110,89 @@ inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { "00.04d south 1 (open) -> Route 202 (30, 5)", "00.04d west 12 (open) -> Route 202 (18, 5)", "00.04d north 2 (open) -> Route 202 (18, 3)", - "00.05 to_the_center costs=town from JubilifeCity (48, 62) to JubilifeCity (52, 41)", - "00.05 west 1 (open) -> Jubilife City (47, 62)", - "00.05 north 21 (open) -> Jubilife City (47, 41)", - "00.05 east 5 (open) -> Jubilife City (52, 41)", "00.05 to_the_school costs=town from JubilifeCity (52, 41) to JubilifeCity (40, 41)", "00.05 west 12 (open) -> Jubilife City (40, 41)", "00.05b below_the_presidents_trigger costs=town from JubilifeCity (40, 41) to JubilifeCity (46, 41)", "00.05b east 6 (open) -> Jubilife City (46, 41)", "00.05b past_the_president costs=default from JubilifeCity (46, 40) to JubilifeCity (48, 40)", "00.05b east 2 (open) -> Jubilife City (48, 40)", - "00.05b below_the_mart_clown costs=town from JubilifeCity (48, 40) to JubilifeCity (55, 34)", - "00.05b north 6 (open) -> Jubilife City (48, 34)", - "00.05b east 7 (open) -> Jubilife City (55, 34)", - "00.05b below_the_tv_clown costs=town from JubilifeCity (55, 34) to JubilifeCity (36, 17)", - "00.05b west 23 (to wall) -> Jubilife City (32, 34)", - "00.05b north 10 (open) -> Jubilife City (32, 24)", - "00.05b east 4 (open) -> Jubilife City (36, 24)", - "00.05b north 7 (open) -> Jubilife City (36, 17)", + "00.05b below_the_mart_clown costs=town from JubilifeCity (48, 40) to JubilifeCity (56, 36)", + "00.05b north 4 (open) -> Jubilife City (48, 36)", + "00.05b east 8 (to wall) -> Jubilife City (56, 36)", + "00.05b below_the_tv_clown costs=town from JubilifeCity (56, 31) to JubilifeCity (36, 17)", + "00.05b west 8 (open) -> Jubilife City (48, 31)", + "00.05b north 7 (open) -> Jubilife City (48, 24)", + "00.05b west 12 (open) -> Jubilife City (36, 24)", + "00.05b north 7 (to wall) -> Jubilife City (36, 17)", "00.05b below_the_company_clown costs=town from JubilifeCity (36, 17) to JubilifeCity (15, 19)", "00.05b south 4 (open) -> Jubilife City (36, 21)", "00.05b west 21 (open) -> Jubilife City (15, 21)", "00.05b north 2 (open) -> Jubilife City (15, 19)", - "00.05c below_the_president costs=town from JubilifeCity (15, 19) to JubilifeCity (46, 36)", - "00.05c south 5 (open) -> Jubilife City (15, 24)", - "00.05c east 29 (open) -> Jubilife City (44, 24)", - "00.05c south 12 (open) -> Jubilife City (44, 36)", - "00.05c east 2 (open) -> Jubilife City (46, 36)", - "00.05c to_the_route_203_street costs=town from JubilifeCity (46, 36) to JubilifeCity (58, 22)", - "00.05c east 1 (open) -> Jubilife City (47, 36)", - "00.05c north 14 (open) -> Jubilife City (47, 22)", - "00.05c east 11 (open) -> Jubilife City (58, 22)", - "01.01 west_of_barrys_trigger costs=town from JubilifeCity (58, 22) to Route203 (4, 18)", - "01.01 east 9 (open) -> Route 203 (4, 18)", + "00.05b beside_the_company_sign costs=line from JubilifeCity (14, 19) to JubilifeCity (14, 19)", + "00.05c beside_the_president costs=town from JubilifeCity (14, 19) to JubilifeCity (45, 35)", + "00.05c south 4 (open) -> Jubilife City (14, 23)", + "00.05c east 18 (open) -> Jubilife City (32, 23)", + "00.05c south 12 (open) -> Jubilife City (32, 35)", + "00.05c east 13 (to wall) -> Jubilife City (45, 35)", + "00.05c below_the_east_exit_sign costs=line from JubilifeCity (45, 35) to JubilifeCity (59, 21)", + "00.05c north 9 (open) -> Jubilife City (45, 26)", + "00.05c east 14 (to wall) -> Jubilife City (59, 26)", + "00.05c north 5 (to wall) -> Jubilife City (59, 21)", + "01.01 west_of_barrys_trigger costs=town from JubilifeCity (59, 21) to Route203 (4, 18)", + "01.01 south 1 (open) -> Jubilife City (59, 22)", + "01.01 east 8 (open) -> Route 203 (4, 18)", "01.02 south_to_the_cliff costs=default from Route203 (5, 17) (5, 18) (5, 19) (5, 20) to Route203 (5, 20)", "01.02 south 3 (to wall) -> Route 203 (5, 20)", "01.02 by_the_gate costs=default from Route203 (5, 20) to Route203 (55, 9)", "01.02 north 2 (open) -> Route 203 (5, 18)", "01.02 east 50 (to wall) -> Route 203 (55, 18)", "01.02 north 9 (open) -> Route 203 (55, 9)", - "01.02 west_of_the_hikers_trigger costs=default from OreburghGate (4, 22) (5, 22) to OreburghGate (6, 22)", - "01.02 south 1 (to wall) -> OreburghGate (4, 23) OreburghGate (5, 23)", - "01.02 east 2 (to wall) -> OreburghGate (6, 23)", - "01.02 north 1 (open) -> OreburghGate (6, 22)", - "01.02 past_curtis costs=default from OreburghGate (7, 22) to OreburghGate (20, 22)", + "01.02 into_the_hikers_scene costs=into_scene from OreburghGate (4, 22) (5, 22) to OreburghGate (4, 22) (5, 22)", + "01.02 past_curtis costs=exit from OreburghGate (7, 22) to OreburghGate (20, 22)", "01.02 east 13 (open) -> OreburghGate (20, 22)", - "01.02 by_the_east_mouth costs=default from OreburghGate (20, 22) to OreburghGate (27, 22)", - "01.02 east 7 (open) -> OreburghGate (27, 22)", - "01.02 west_of_the_welcome costs=default from OreburghCity (2, 13) (3, 13) to OreburghCity (9, 13)", - "01.02 north 3 (to wall) -> Oreburgh City (2, 10) Oreburgh City (3, 10)", - "01.02 east 4 (to wall) -> Oreburgh City (6, 10)", - "01.02 south 3 (open) -> Oreburgh City (6, 13)", - "01.02 east 3 (open) -> Oreburgh City (9, 13)", - "01.03 below_the_centers_door costs=town from OreburghCity (43, 21) (44, 21) (45, 21) (43, 22) (44, 22) (45, 22) to OreburghCity (47, 21)", - "01.03 east 5 (to wall) -> Oreburgh City (48, 21) Oreburgh City (48, 22)", - "01.03 north 1 (to wall) -> Oreburgh City (48, 21)", - "01.03 west 1 (open) -> Oreburgh City (47, 21)", - "01.03 above_the_mine costs=town from OreburghCity (47, 21) to OreburghCity (46, 58)", - "01.03 west 3 (open) -> Oreburgh City (44, 21)", + "01.02 by_the_east_mouth costs=exit from OreburghGate (20, 22) to OreburghGate (26, 22)", + "01.02 east 6 (open) -> OreburghGate (26, 22)", + "01.02 into_the_welcome_scene costs=into_scene from OreburghCity (2, 13) (3, 13) to OreburghCity (2, 13) (3, 13)", + "01.02b below_the_centers_door costs=town from OreburghCity (26, 22) to OreburghCity (47, 21)", + "01.02b east 22 (to wall) -> Oreburgh City (48, 22)", + "01.02b north 1 (to wall) -> Oreburgh City (48, 21)", + "01.02b west 1 (open) -> Oreburgh City (47, 21)", + "01.03 above_the_mine costs=town from OreburghCity (47, 21) (46, 21) to OreburghCity (46, 57)", + "01.03 east 2 (to wall) -> Oreburgh City (48, 21)", + "01.03 west 4 (open) -> Oreburgh City (44, 21)", "01.03 south 20 (to wall) -> Oreburgh City (44, 41)", - "01.03 east 2 (open) -> Oreburgh City (46, 41)", - "01.03 south 17 (open) -> Oreburgh City (46, 58)", - "01.03 below_roark costs=default from OreburghMine (15, 9) to OreburghMine (18, 29)", - "01.03 east 2 (to wall) -> OreburghMine (17, 9)", - "01.03 south 2 (to wall) -> OreburghMine (17, 11)", - "01.03 west 2 (to wall) -> OreburghMine (15, 11)", - "01.03 south 6 (to wall) -> OreburghMine (15, 17)", - "01.03 east 14 (to wall) -> OreburghMine (29, 17)", - "01.03 south 10 (to wall) -> OreburghMine (29, 27)", - "01.03 west 3 (to wall) -> OreburghMine (26, 27)", - "01.03 south 2 (to wall) -> OreburghMine (26, 29)", - "01.03 west 8 (open) -> OreburghMine (18, 29)", - "01.03 below_the_coal_rooms_warp costs=default from OreburghMine (18, 29) to OreburghMine (15, 2)", - "01.03 east 9 (to wall) -> OreburghMine (27, 29)", - "01.03 north 5 (to wall) -> OreburghMine (27, 24)", - "01.03 east 2 (to wall) -> OreburghMine (29, 24)", - "01.03 north 8 (to wall) -> OreburghMine (29, 16)", - "01.03 west 16 (to wall) -> OreburghMine (13, 16)", - "01.03 east 2 (open) -> OreburghMine (15, 16)", - "01.03 north 5 (to wall) -> OreburghMine (15, 11)", - "01.03 east 2 (to wall) -> OreburghMine (17, 11)", - "01.03 north 2 (to wall) -> OreburghMine (17, 9)", - "01.03 west 4 (to wall) -> OreburghMine (13, 9)", - "01.03 north 7 (to wall) -> OreburghMine (13, 2)", - "01.03 east 2 (open) -> OreburghMine (15, 2)", - "01.03 below_the_centers_door_again costs=town from OreburghCity (45, 57) to OreburghCity (47, 21)", - "01.03 west 2 (to wall) -> Oreburgh City (43, 57)", - "01.03 north 16 (to wall) -> Oreburgh City (43, 41)", - "01.03 east 1 (open) -> Oreburgh City (44, 41)", - "01.03 north 21 (to wall) -> Oreburgh City (44, 20)", - "01.03 south 1 (open) -> Oreburgh City (44, 21)", - "01.03 east 3 (open) -> Oreburgh City (47, 21)", + "01.03 west 1 (open) -> Oreburgh City (43, 41)", + "01.03 south 16 (to wall) -> Oreburgh City (43, 57)", + "01.03 east 3 (open) -> Oreburgh City (46, 57)", "01.05 east_of_barrys_trigger costs=town from OreburghCity (26, 21) (26, 22) to OreburghCity (7, 13)", - "01.05 west 17 (to wall) -> Oreburgh City (9, 21) Oreburgh City (9, 22)", - "01.05 north 5 (to wall) -> Oreburgh City (9, 17)", - "01.05 east 2 (open) -> Oreburgh City (11, 17)", - "01.05 north 4 (open) -> Oreburgh City (11, 13)", - "01.05 west 4 (open) -> Oreburgh City (7, 13)", - "01.05 by_the_gate costs=default from OreburghCity (5, 13) to OreburghCity (2, 13)", - "01.05 west 3 (open) -> Oreburgh City (2, 13)", - "01.05 through_the_gate costs=default from OreburghGate (27, 22) (26, 22) to OreburghGate (4, 22)", - "01.05 south 1 (open) -> OreburghGate (26, 23) OreburghGate (27, 23)", + "01.05 south 5 (to wall) -> Oreburgh City (26, 26)", + "01.05 north 1 (open) -> Oreburgh City (26, 25)", + "01.05 west 14 (to wall) -> Oreburgh City (12, 25)", + "01.05 north 12 (open) -> Oreburgh City (12, 13)", + "01.05 west 5 (open) -> Oreburgh City (7, 13)", + "01.05 through_the_gate costs=default from OreburghGate (27, 22) (26, 22) to OreburghGate (5, 22)", + "01.05 north 2 (to wall) -> OreburghGate (27, 20) OreburghGate (26, 21)", + "01.05 east 1 (to wall) -> OreburghGate (27, 20) OreburghGate (27, 21)", + "01.05 south 3 (to wall) -> OreburghGate (27, 23)", "01.05 west 19 (to wall) -> OreburghGate (8, 23)", "01.05 north 1 (to wall) -> OreburghGate (8, 22)", - "01.05 west 4 (open) -> OreburghGate (4, 22)", - "01.06 below_rowans_trigger costs=town from Route203 (55, 9) to JubilifeCity (47, 8)", + "01.05 west 3 (open) -> OreburghGate (5, 22)", + "01.06 up_jubilifes_road costs=town from Route203 (55, 9) to JubilifeCity (41, 8)", "01.06 south 10 (to wall) -> Route 203 (55, 19)", "01.06 west 17 (to wall) -> Route 203 (38, 19)", "01.06 north 1 (open) -> Route 203 (38, 18)", - "01.06 west 57 (open) -> Jubilife City (44, 22)", - "01.06 north 14 (to wall) -> Jubilife City (44, 8)", - "01.06 east 3 (to wall) -> Jubilife City (47, 8)", + "01.06 west 60 (open) -> Jubilife City (41, 22)", + "01.06 north 14 (to wall) -> Jubilife City (41, 8)", + "01.06 below_rowans_trigger costs=town from JubilifeCity (41, 8) to JubilifeCity (47, 8)", + "01.06 east 6 (to wall) -> Jubilife City (47, 8)", "01.08 west_to_the_wall costs=default from JubilifeCity (46, 5) (47, 5) to JubilifeCity (44, 5)", "01.08 west 3 (to wall) -> Jubilife City (44, 5)", - "01.08 below_the_ravaged_path costs=town from JubilifeCity (44, 5) to Route204South (11, 2)", + "01.08 below_the_ravaged_path costs=town from JubilifeCity (44, 5) to Route204South (11, 3)", "01.08 east 2 (open) -> Jubilife City (46, 5)", "01.08 north 19 (to wall) -> Route 204 (14, 18)", - "01.08 west 2 (open) -> Route 204 (12, 18)", - "01.08 north 16 (to wall) -> Route 204 (12, 2)", - "01.08 west 1 (to wall) -> Route 204 (11, 2)", + "01.08 west 4 (open) -> Route 204 (10, 18)", + "01.08 north 15 (to wall) -> Route 204 (10, 3)", + "01.08 east 1 (open) -> Route 204 (11, 3)", "01.09 west_of_the_rock costs=default from RavagedPath (19, 50) to RavagedPath (21, 43)", "01.09 north 7 (open) -> RavagedPath (19, 43)", "01.09 east 2 (open) -> RavagedPath (21, 43)", @@ -253,9 +200,10 @@ inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { "01.09 east 8 (to wall) -> RavagedPath (29, 43)", "01.09 south 1 (to wall) -> RavagedPath (29, 44)", "01.09 west 1 (open) -> RavagedPath (28, 44)", - "01.10 line_1 costs=line from Route204North (20, 26) to Route204North (20, 27)", - "01.10 south 1 (open) -> Route 204 (20, 27)", - "01.10 line_2 costs=line from Route204North (20, 27) to Route204North (11, 27)", + "01.10 line_1 costs=line from Route204North (20, 26) (20, 27) to Route204North (20, 30)", + "01.10 south 4 (to wall) -> Route 204 (20, 30)", + "01.10 line_2 costs=line from Route204North (20, 30) to Route204North (11, 27)", + "01.10 north 3 (open) -> Route 204 (20, 27)", "01.10 west 9 (open) -> Route 204 (11, 27)", "01.10 line_3 costs=line from Route204North (11, 27) to Route204North (11, 22)", "01.10 north 5 (open) -> Route 204 (11, 22)", @@ -265,14 +213,6 @@ inline constexpr std::string_view BDSP_PLAN_GOLDEN[] = { "01.10 north 10 (open) -> Route 204 (19, 12)", "01.10 line_6 costs=line from Route204North (19, 12) to Route204North (11, 12)", "01.10 west 8 (open) -> Route 204 (11, 12)", - "01.10 line_7 costs=line from Route204North (11, 12) to Route204North (11, 5)", - "01.10 north 7 (open) -> Route 204 (11, 5)", - "01.10 into_floaroma costs=line from Route204North (11, 5) to FloaromaTown (11, 29)", - "01.10 north 8 (open) -> Floaroma Town (11, 29)", - "01.11 west_along_the_field costs=default from FloaromaTown (11, 29) to FloaromaTown (3, 29)", - "01.11 west 8 (open) -> Floaroma Town (3, 29)", - "01.11 below_the_old_man costs=default from FloaromaTown (4, 26) to FloaromaTown (3, 26)", - "01.11 west 1 (open) -> Floaroma Town (3, 26)", }; } // namespace PokemonBDSP 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 256dabe73f..f559241a59 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp @@ -119,8 +119,11 @@ class ScriptedRouteIO : public RouteIO{ virtual void press(const RouteInput& input) override{ expect(describe(input)); } - virtual bool dialog_within(Milliseconds wait, Color) override{ - return expect(std::format("dialog within {} ms", wait.count())).answer; + virtual RouteSight sight_within(const RouteWatch& watch) override{ + if (!watch.dialog){ + return {}; + } + return {.dialog = expect(std::format("dialog within {} ms", watch.wait.count())).answer}; } virtual bool holding_against_wall(Direction direction, const std::string&) override{ return expect(std::string("holding ") + Pokemon::direction_name(direction)).answer; @@ -162,7 +165,7 @@ enum class AfterTalk{ NO_BATTLE, }; -ScriptedWalk walk_script(const StoryWorld& maps, const TilePos& from, const TilePos& goal, std::vector sights, Script& script, +ScriptedWalk walk_script_from(const StoryWorld& maps, std::vector from, const TilePos& goal, std::vector sights, Script& script, AfterTalk after_talk = AfterTalk::BATTLE ){ ScriptedWalk out; @@ -172,7 +175,7 @@ ScriptedWalk walk_script(const StoryWorld& maps, const TilePos& from, const Tile }; ScriptedRouteIO io(script); try{ - out.at = walk_route(io, maps, {from}, trainers, { + out.at = walk_route(io, maps, std::move(from), trainers, { .goal = [goal](const TilePos& pos){ return pos == goal; }, .label = "T", .avoid = {}, @@ -185,6 +188,20 @@ ScriptedWalk walk_script(const StoryWorld& maps, const TilePos& from, const Tile return out; } +ScriptedWalk walk_script(const StoryWorld& maps, const TilePos& from, const TilePos& goal, std::vector sights, Script& script, + AfterTalk after_talk = AfterTalk::BATTLE +){ + return walk_script_from(maps, {from}, goal, std::move(sights), script, after_talk); +} + +std::string joined_notes(const Script& script){ + std::string out; + for (const std::string& note : script.notes){ + out += "\n " + note; + } + return out; +} + // The script's calls all made, or which are left. std::string script_left(const Script& script){ if (script.next == script.steps.size()){ @@ -374,6 +391,7 @@ UnitTestResult test_open_leg_known_trainer(Logger&){ Script script{.steps = { press_step("D-pad west 50 ms x1"), walk_step("6 taps: T: west 6 (open)", WalkStop::DIALOG, 1500ms, 3), + press_step("D-pad east 50 ms x1"), walk_step("wall: T: east 4 (to wall)", WalkStop::BLOCKED, 2000ms, 0), answer_step("dialog within 500 ms", false), press_step("D-pad west 50 ms x1"), @@ -669,6 +687,195 @@ UnitTestResult test_wall_leg_held_up_is_not_at_its_wall(Logger&){ return left.empty() ? UnitTestResult(true) : UnitTestResult(left); } +// lab-B 2026-11-12 14:50, 01.02 "south 3 (to wall)" on Route 203, straight +// after a battle: the start is one of four tiles, the player already stands +// at the wall, and the walk's three moved chunks (a turn counted as one) +// and 2000 ms read as held up. No tile of the leg past the wall fits, but +// the tile at the wall does: the leg ends there, it must not fail. +UnitTestResult test_wall_leg_at_its_wall_among_the_start_tiles(Logger&){ + const StoryWorld corridor = make_world({"###", "#.#", "#.#", "#.#", "#.#", "###"}); + Script script{.steps = { + walk_step("wall: T: south 3 (to wall)", WalkStop::BLOCKED, 2000ms, 3), + }}; + ScriptedWalk walk; + try{ + walk = walk_script_from(corridor, {{1, 1}, {1, 2}, {1, 3}, {1, 4}}, {1, 4}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (!walk.failure.empty()){ + return "failed: " + walk.failure; + } + if (walk.at != std::vector{{1, 4}}){ + return "did not end at the wall (1, 4)."; + } + return true; +} + +// A leg to a wall in another direction than the player faces turns first, +// with a tap that only turns; the held walk then counts from its first +// step, not a turn (lab-B 2026-11-12 14:55, 01.02 south_to_the_cliff). +UnitTestResult test_wall_leg_turns_before_the_walk(Logger&){ + const StoryWorld bend = make_world({"#####", "#...#", "###.#", "###.#", "#####"}); + Script script{.steps = { + walk_step("wall: T: east 2 (to wall)", WalkStop::BLOCKED, 1900ms, 2), + answer_step("dialog within 500 ms", false), + press_step("D-pad south 50 ms x1"), + walk_step("wall: T: south 2 (to wall)", WalkStop::BLOCKED, 1900ms, 2), + answer_step("dialog within 500 ms", false), + }}; + ScriptedWalk walk; + try{ + walk = walk_script(bend, {1, 1}, {3, 3}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (!walk.failure.empty()){ + return "failed: " + walk.failure; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + +// Facing unknown (after a battle), the first walk's chunk that changed the +// screen may be the turn: a leg to a wall that stopped with that one chunk +// has not moved, and whoever stopped it stands on the next tile. +UnitTestResult test_wall_leg_one_chunk_is_a_turn_when_facing_is_unknown(Logger&){ + const StoryWorld corridor = make_world({"###########", "#.........#", "###########"}); + Script script{.steps = { + walk_step("wall: T: east 8 (to wall)", WalkStop::BLOCKED, 800ms, 1), + }}; + ScriptedWalk walk; + try{ + walk = walk_script(corridor, {1, 1}, {9, 1}, {}, script); + }catch (const ScriptMismatch& e){ + script.notes.push_back(e.message); + } + const bool never_moved = std::any_of(script.notes.begin(), script.notes.end(), [](const std::string& note){ + return note.find("the first moved chunk may be the turn") != std::string::npos; + }); + return never_moved ? UnitTestResult(true) : UnitTestResult(std::format("the turn counted as a moved chunk (step {}, {} notes): {}{}", script.next, script.notes.size(), walk.failure, joined_notes(script))); +} + +// lab-B 2026-11-12 20:22, 01.02 "east 4 (to wall)": the player had left the +// Gate unseen and ran on in Oreburgh City; the leg hit its time limit still +// moving (6 moved chunks), and the "at the wall?" probe walked on 4 chunks +// more. A leg that is still moving past the farthest wall the map has is +// not where the plan has us: the walk stops, and nothing walks further. +UnitTestResult test_wall_leg_still_moving_at_limit_is_unknown(Logger&){ + Script script{.steps = {walk_step("wall: T: east 4 (to wall)", WalkStop::LIMIT, 2050ms, 6)}}; + ScriptedWalk walk; + try{ + walk = walk_script(make_world({"#.....#"}), {1, 0}, {5, 0}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (walk.failure.find("position unknown") == std::string::npos){ + return "did not stop with the position unknown: \"" + walk.failure + "\""; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + +// The probe after a leg that ran out of time: one that is still moving +// (4 moved chunks in 2000 ms) is not at a wall, so nothing asks the +// holding check and nothing walks on. +UnitTestResult test_wall_check_still_moving_is_unknown(Logger&){ + Script script{.steps = { + walk_step("wall: T: east 4 (to wall)", WalkStop::LIMIT, 2050ms, 0), + walk_step("wall: T: east 4 (to wall): at the wall?", WalkStop::LIMIT, 2000ms, 4), + }}; + ScriptedWalk walk; + try{ + walk = walk_script(make_world({"#.....#"}), {1, 0}, {5, 0}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (walk.failure.find("position unknown") == std::string::npos){ + return "did not stop with the position unknown: \"" + walk.failure + "\""; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + +// A walk the banner of another map shows on, whatever its stop, went +// through a warp unseen. +ScriptStep through_a_warp_step(std::string call, WalkStop stop, Milliseconds walked, size_t moved){ + ScriptStep step = walk_step(std::move(call), stop, walked, moved); + step.walk.warp.banner = "Oreburgh City"; + return step; +} + +UnitTestResult test_wall_check_on_another_map_is_unknown(Logger&){ + Script script{.steps = { + walk_step("wall: T: east 4 (to wall)", WalkStop::LIMIT, 2050ms, 0), + through_a_warp_step("wall: T: east 4 (to wall): at the wall?", WalkStop::BLOCKED, 1200ms, 0), + }}; + ScriptedWalk walk; + try{ + walk = walk_script(make_world({"#.....#"}), {1, 0}, {5, 0}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (walk.failure.find("another map") == std::string::npos){ + return "did not stop on the other map's banner: \"" + walk.failure + "\""; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + +// lab-B 2026-11-12 20:20, 01.02 past_curtis: no plan from the tiles left +// after a battle, so the walk held east "to find us again", ran through the +// Gate's east door unseen (5 moved chunks, 1850 ms against a wall 2 tiles +// away) and took itself for found at the wall. It is not found. +UnitTestResult test_find_again_still_moving_is_unknown(Logger&){ + Script script{.steps = {walk_step("wall: T: east 2 (to wall) to find us again", WalkStop::LIMIT, 1850ms, 5)}}; + ScriptedWalk walk; + try{ + walk = walk_script(make_world({"#...#...#"}), {1, 0}, {7, 0}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (walk.failure.find("position unknown") == std::string::npos){ + return "did not stop with the position unknown: \"" + walk.failure + "\""; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + +UnitTestResult test_find_again_on_another_map_is_unknown(Logger&){ + Script script{.steps = {through_a_warp_step("wall: T: east 2 (to wall) to find us again", WalkStop::BLOCKED, 1200ms, 1)}}; + ScriptedWalk walk; + try{ + walk = walk_script(make_world({"#...#...#"}), {1, 0}, {7, 0}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (walk.failure.find("another map") == std::string::npos){ + return "did not stop on the other map's banner: \"" + walk.failure + "\""; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + +// The same hold when the walk does see the fade: a recovery hold toward a +// door ends in the next map, and the route does not go on as if it were +// still in the old one. +UnitTestResult test_find_again_through_a_door_is_unknown(Logger&){ + Script script{.steps = {walk_step("wall: T: east 2 (to wall) to find us again", WalkStop::TRANSITION, 1200ms, 3)}}; + ScriptedWalk walk; + try{ + walk = walk_script(make_world({"#...#...#"}), {1, 0}, {7, 0}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (walk.failure.find("transition") == std::string::npos){ + return "did not stop on the transition: \"" + walk.failure + "\""; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + struct PlannedRouteInput{ std::string name; std::function body; @@ -744,6 +951,42 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .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 = {"a leg to a wall turns first when its way differs from the facing (lab-B 2026-11-12 14:55)", test_wall_leg_turns_before_the_walk}, + .expectation = {}, + }, + { + .input = {"one chunk of a walk with unknown facing is a turn, not a move (lab-B 2026-11-12 14:55)", test_wall_leg_one_chunk_is_a_turn_when_facing_is_unknown}, + .expectation = {}, + }, + { + .input = {"a wall leg that stood at its wall among the start tiles does not fail (lab-B 2026-11-12 14:50)", test_wall_leg_at_its_wall_among_the_start_tiles}, + .expectation = {}, + }, + { + .input = {"a wall leg still moving at its time limit is not where the plan has us (lab-B 2026-11-12 20:22)", test_wall_leg_still_moving_at_limit_is_unknown}, + .expectation = {}, + }, + { + .input = {"the at-the-wall check still moving is not at a wall (lab-B 2026-11-12 20:22)", test_wall_check_still_moving_is_unknown}, + .expectation = {}, + }, + { + .input = {"the at-the-wall check on another map's banner went through a warp (lab-B 2026-11-12 20:22)", test_wall_check_on_another_map_is_unknown}, + .expectation = {}, + }, + { + .input = {"finding us again still moving is not found (lab-B 2026-11-12 20:20)", test_find_again_still_moving_is_unknown}, + .expectation = {}, + }, + { + .input = {"finding us again on another map's banner went through a warp (lab-B 2026-11-12 20:20)", test_find_again_on_another_map_is_unknown}, + .expectation = {}, + }, + { + .input = {"finding us again through a door ends in the next map (lab-B 2026-11-12 20:20)", test_find_again_through_a_door_is_unknown}, + .expectation = {}, + }, }; void add_tests_AutoStory_PlannedRoute(UnitTestDatabase& database){ 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 0d6578cc60..60ddb0ed43 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -145,6 +145,36 @@ UnitTestResult test_plan_robust_route(Logger&){ return true; } +// A held run on to a wall and tapped back is fine from the start, but not +// after a tapped leg: the player is exactly where the taps left them, and a +// run past that tile and back only adds a turn (lab-B 2026-11-12 14:24, 00.05c +// "south 15 (to wall), north 1" after "east 19 (open)"). +UnitTestResult test_robust_wall_and_back_not_after_taps(Logger&){ + // East along the top row, which goes on past column 5, then down column 5 + // to the goal a few tiles above the wall. + std::vector rows{"#########", "#.......#"}; + for (int y = 0; y < 40; y++){ + rows.push_back("#####.###"); + } + rows.push_back("#########"); + const StoryWorld world = make_world(rows); + RobustPlanCosts costs; + costs.exact_open_tiles = costs.max_open_tiles; + const auto legs = plan_robust_route(world, {{1, 1}}, [](const TilePos& pos){ return pos == TilePos{5, 38}; }, costs); + if (!legs){ + return std::string("no plan."); + } + for (size_t i = 1; i + 1 < legs->size(); i++){ + const TileLeg& before = (*legs)[i - 1].leg; + const TileLeg& wall = (*legs)[i].leg; + const TileLeg& back = (*legs)[i + 1].leg; + if (!before.ends_at_wall && wall.ends_at_wall && (int)back.direction == ((int)wall.direction + 2) % 4){ + return "a run to the wall and back after a tapped leg: " + describe(*legs); + } + } + return true; +} + // Someone wanders a row, (2..4, 2): a leg may cross the row through one of // their tiles, but not run along it through two, the leg's start among // them. On lab-B (2026-11-08, 01.08) Route 204's youngster stopped a leg @@ -400,6 +430,10 @@ const RoutePlannerCase ROUTE_PLANNER_CASES[] = { .input = {"robust plans", test_plan_robust_route}, .expectation = {}, }, + { + .input = {"a run to the wall and back is not planned after a tapped leg", test_robust_wall_and_back_not_after_taps}, + .expectation = {}, + }, { .input = {"robust plans cross a wander zone, never along it", test_plan_robust_route_wander_zone}, .expectation = {}, 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 e786c357c5..23e555d157 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp @@ -126,9 +126,9 @@ class SimulatedRouteIO : public RouteIO{ } } } - virtual bool dialog_within(Milliseconds, Color) override{ + virtual RouteSight sight_within(const RouteWatch&) override{ count_call(); - return false; + return {}; } virtual bool holding_against_wall(Direction, const std::string&) override{ count_call(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index cb22e7d4c3..184f8d8a02 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -61,6 +61,10 @@ void add_legs_actions( 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}}); + // Taps counted against the map from each tile we may be on: legs each + // ended by a wall take every one of them to the declared end. + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "measured", .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 @@ -71,15 +75,38 @@ void add_wanderer_talks(std::vector& actions){ // 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. + // Waits for him at an end column of his box, then at the other end + // (WanderWaitPlan); ends against a wall the declared way and one at + // the stand 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" + "stand", Pokemon::StoryArgType::GRID_POSE, "the tiles to wait on first, in order, on one column; facing into his box" + ); + const Pokemon::StoryArgSpec far_stand = optional( + "far_stand", Pokemon::StoryArgType::GRID_POSE, Pokemon::GridPose{}, + "the tiles to wait on next, on his box's other end column; facing into it" ); - actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "wait_for_wanderer", .args = {stand, again}, + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "wait_for_wanderer", .args = {stand, far_stand, again}, .console_only = false, .certainty = certainty}); } +// ROUTE "exit": the room's way on is a door this way; a fight or a lost +// count on the way ends in a hold to the door, not a replan. +Pokemon::StoryArgSpec leave_arg(){ + return {.key = "leave", .type = Pokemon::StoryArgType::DIRECTION, .required = false, .fallback = std::nullopt, + .why = "the room's way on is a door this way"}; +} + +// The steps that end on a door or a banner: to_banner and door (the way to +// step), or_legs (a step, or legs if it did not move). +void add_door_steps( + std::vector& actions, + const Pokemon::StoryArgSpec& direction_arg, const Pokemon::StoryArgSpec& legs_arg +){ + 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 = "door", .args = {direction_arg}}); + actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "or_legs", .args = {direction_arg, legs_arg}}); +} + std::vector make_bdsp_actions(){ std::vector actions( Pokemon::builtin_story_actions().begin(), Pokemon::builtin_story_actions().end() @@ -115,13 +142,12 @@ std::vector make_bdsp_actions(){ .fallback = std::nullopt, .why = "ground on the target's map to keep off: [x, y] tiles, [x0, y0, x1, y1] boxes"}; const Pokemon::StoryArgSpec opt_greeter{.key = "greeter", .type = Pokemon::StoryArgType::INTEGER_ROWS, .required = false, .fallback = std::nullopt, .why = "ground on the target's map where someone walks up and talks, then walks 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, opt_avoid, opt_greeter}}); + for (std::string_view cost : {"town", "overworld", "indoors", "caves", "robust", "line", "trigger", "exit"}){ + actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs, opt_avoid, opt_greeter, leave_arg()}}); } 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); - 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_door_steps(actions, direction_arg, legs_arg); 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}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp index 4bfb37b98b..b089e41a04 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Filesystem/Filesystem.h" @@ -66,7 +67,7 @@ using Pokemon::story_arg; std::optional story_route_costs(const std::string& action){ - if (action.empty() || action == ROUTE_ONTO_TRIGGER || action == ROUTE_INTO_SCENE || action == "route"){ + if (action.empty() || action == ROUTE_ONTO_TRIGGER || action == ROUTE_INTO_SCENE || action == "route" || action == "exit"){ return route_plan_costs(); } if (action == "town"){ @@ -91,23 +92,35 @@ std::string label_of(const StoryStep& step){ return label; } -// The screen at a failed step, kept: the retry resets the game. -void save_failure_screenshot(VideoStream& stream, size_t attempt){ +// The screen now, kept in AutoStory/`folder`/ as "