diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index f4680f5248..29bf58b56f 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -33,9 +33,12 @@ #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" +#include "Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h" #include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h" +#include "Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h" #include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h" #include "Pokemon/Navigation/Pokemon_MapData_Tests.h" +#include "Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h" #include "Pokemon/Navigation/Pokemon_RouteLog_Tests.h" #include "Pokemon/Navigation/Pokemon_RouteScorer_Tests.h" #include "Pokemon/Navigation/Pokemon_RuntimeMap_Tests.h" @@ -79,9 +82,12 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ OCR::add_tests(ret); Kernels::add_tests(ret); Pokemon::add_tests_LegPlanner(ret); + Pokemon::add_tests_RobustLegPlanner(ret); Pokemon::add_tests_LegWalker(ret); Pokemon::add_tests_WallRecovery(ret); Pokemon::add_tests_MapData(ret); + Pokemon::add_tests_ConnectedMaps(ret); + Pokemon::add_tests_MoveMechanics(ret); Pokemon::add_tests_RuntimeMap(ret); Pokemon::add_tests_RouteLog(ret); Pokemon::add_tests_RouteScorer(ret); diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp new file mode 100644 index 0000000000..f962515c48 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp @@ -0,0 +1,86 @@ +/* Story Certainty + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon_BuiltinStoryActions.h" +#include "Pokemon_StoryStepExecutor.h" +#include "Pokemon_StoryCertainty.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +StoryCertainty kind_certainty(StoryStepKind kind){ + switch (kind){ + case StoryStepKind::ROUTE: + return {PoseCertainty::TILE, PoseEnd::WALKED}; + case StoryStepKind::LEGS: + return {PoseCertainty::SET, PoseEnd::KEEPS}; + case StoryStepKind::STEP: + case StoryStepKind::HEAL: + return {PoseCertainty::TILE, PoseEnd::DECLARED}; + case StoryStepKind::TALK: + return {PoseCertainty::TILE, PoseEnd::KEEPS}; + case StoryStepKind::NEW_GAME: + return {PoseCertainty::UNKNOWN, PoseEnd::DECLARED}; + default: + return {PoseCertainty::UNKNOWN, PoseEnd::KEEPS}; + } +} + +} // namespace + + +StoryCertainty story_step_certainty(const StoryStep& step, std::span specs){ + StoryCertainty out = kind_certainty(step.kind); + if (const StoryActionSpec* spec = find_story_action(specs, step.kind, step.action)){ + out.needs = spec->certainty.value_or(out).needs; + out.leaves = spec->certainty.value_or(out).leaves; + } + return out; +} + +PoseCertainty certainty_after(const StoryStep& step, PoseEnd leaves, PoseCertainty before){ + switch (leaves){ + case PoseEnd::WALKED: + return PoseCertainty::TILE; + case PoseEnd::DECLARED: + return step.pose_after ? pose_of(*step.pose_after).certainty : before; + case PoseEnd::GAME_SET: + return step.pose_after ? PoseCertainty::SET : before; + case PoseEnd::KEEPS: + // A declared end the step does not walk onto is where the game + // leaves us, unseen. + return step.pose_after ? PoseCertainty::SET : before; + } + return before; +} + +PoseCertainty start_certainty(const StoryCheckpoint& data){ + return data.start ? PoseCertainty::SET : PoseCertainty::UNKNOWN; +} + +std::vector certainty_gaps(const StoryCheckpoint& data, std::span specs){ + std::vector gaps; + PoseCertainty have = start_certainty(data); + for (size_t c = 0; c < data.steps.size(); c++){ + const StoryStep& step = data.steps[c]; + const StoryCertainty certainty = story_step_certainty(step, specs); + if (!certainty_covers(have, certainty.needs)){ + gaps.push_back(std::format("{} step {} {}: needs {}, has {}", + data.id, c + 1, step.name, certainty_name(certainty.needs), certainty_name(have))); + } + have = certainty_after(step, certainty.leaves, have); + } + return gaps; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h new file mode 100644 index 0000000000..e1941b3db6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h @@ -0,0 +1,46 @@ +/* Story Certainty + * + * From: https://github.com/PokemonAutomation/ + * + * How sure of the player's tile each step must be when it starts, and how + * sure it leaves the run. A step that needs more than the steps before it + * guarantee walks from a guess: 00.05's route planned open legs from its + * save's declared start, a tile the save was never seen on, and walked + * into a building (lab-B 2026-11-11 15:22). + * + */ + +#ifndef PokemonAutomation_Pokemon_StoryCertainty_H +#define PokemonAutomation_Pokemon_StoryCertainty_H + +#include +#include +#include +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// What a step needs at its start and leaves at its end: the action's spec +// where it says, else its kind's default (a route needs one tile and +// leaves one; a scene needs nothing and leaves its declared end unseen). +StoryCertainty story_step_certainty(const StoryStep& step, std::span specs); + +// How sure the run is after `step` succeeds from `before`. +PoseCertainty certainty_after(const StoryStep& step, PoseEnd leaves, PoseCertainty before); + +// How sure a checkpoint is at its start: SET from its save (its declared +// start was never seen on the screen), UNKNOWN without one. +PoseCertainty start_certainty(const StoryCheckpoint& data); + +// Each step of `data` that needs a surer pose than the steps before it +// leave, as "00.05 step 1 to_the_center: needs TILE, has SET". +std::vector certainty_gaps(const StoryCheckpoint& data, std::span specs); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h index f9deb09ebb..cef4e27ef5 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h @@ -15,6 +15,7 @@ #include #include "Pokemon_StoryActionArg.h" #include "Pokemon_StoryStepKind.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" namespace PokemonAutomation{ namespace Pokemon{ @@ -31,6 +32,21 @@ struct StoryArgSpec{ std::string why; }; +// What an action leaves the pose as. +enum class PoseEnd{ + KEEPS, // as sure as before (a talk; taps counted from where we were) + WALKED, // walked onto its target and checked there: one tile + DECLARED, // its declared end, reached on walls or through a door + GAME_SET, // where a scene or battle leaves us: declared, not seen +}; + +// How sure of the player's tile an action must be at its start, and what +// it leaves (Pokemon_StoryCertainty.h). +struct StoryCertainty{ + PoseCertainty needs = PoseCertainty::UNKNOWN; + PoseEnd leaves = PoseEnd::KEEPS; +}; + // An action: the kind of step it does, its name and the args it takes. struct StoryActionSpec{ StoryStepKind kind = StoryStepKind::GAME; @@ -40,6 +56,8 @@ struct StoryActionSpec{ // keyboard, a battle AI): the engine refuses it on any other backend // (StoryBackendKind) with the failure "console_only". bool console_only = false; + // None: its kind's default (story_step_certainty()). + std::optional certainty = std::nullopt; }; // Each way `args` don't fit `spec`: a key it doesn't name, a value of diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp new file mode 100644 index 0000000000..1bd697a03e --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp @@ -0,0 +1,153 @@ +/* Connected Maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Pokemon_ConnectedMaps.h" + +namespace PokemonAutomation{ +namespace Pokemon{ +namespace{ + +// The tile of `to` that `connection` on `side` leads onto from `here`: +// the edge row or column, shifted by the connection's offset. +TilePos edge_entry(const TilePos& here, Direction side, const MapConnection& connection, const Grid& to){ + TilePos point{here.x - connection.offset, here.y - connection.offset}; + switch (side){ + case Direction::NORTH: + point.y = to.height - 1; + break; + case Direction::SOUTH: + point.y = 0; + break; + case Direction::WEST: + point.x = to.width - 1; + break; + case Direction::EAST: + point.x = 0; + break; + } + return point; +} + +} // namespace + + +const MapData& ConnectedMaps::map(size_t index) const{ + if (index >= m_maps->size()){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, + std::format("Map index {} is past the {} connected maps.", index, m_maps->size())); + } + return (*m_maps)[index]; +} + +std::optional ConnectedMaps::find(std::string_view name) const{ + for (size_t index = 0; index < m_maps->size(); index++){ + if ((*m_maps)[index].name == name){ + return index; + } + } + return std::nullopt; +} + +std::optional ConnectedMaps::warp_arrival(const MapWarp& warp) const{ + if (!warp.to){ + return std::nullopt; + } + const std::optional destination = find(warp.to->map); + if (!destination){ + return std::nullopt; + } + const MapData& to = map(*destination); + const auto arrival = to.points.find(warp.to->point); + if (arrival == to.points.end()){ + return std::nullopt; + } + return MapPlace{*destination, arrival->second}; +} + +std::optional ConnectedMaps::across_edge(const MapPlace& from, Direction side) const{ + for (const MapConnection& connection : map(from.map).connections){ + if (connection.side != side){ + continue; + } + const std::optional destination = find(connection.to_map); + if (!destination){ + continue; + } + const Grid& to = map(*destination).tiles; + const TilePos point = edge_entry(from.tile, side, connection, to); + if (to.contains(point)){ + return MapPlace{*destination, point}; + } + } + return std::nullopt; +} + +std::optional ConnectedMaps::neighbour(const MapPlace& from, Direction direction) const{ + const TilePos ahead = from.tile.next(direction); + if (map(from.map).tiles.contains(ahead)){ + return MapPlace{from.map, ahead}; + } + return across_edge(from, direction); +} + + +namespace{ + +// The side of `a` that `b` touches, and the offset of `b`'s tiles along it, +// if their rectangles on the world grid meet along a side. +std::optional touching(const MapData& a, const MapData& b){ + const TilePos pa = a.world->offset; + const TilePos pb = b.world->offset; + const int aw = a.tiles.width; + const int ah = a.tiles.height; + const int bw = b.tiles.width; + const int bh = b.tiles.height; + const bool columns_overlap = pa.x < pb.x + bw && pb.x < pa.x + aw; + const bool rows_overlap = pa.y < pb.y + bh && pb.y < pa.y + ah; + if (columns_overlap && pb.y + bh == pa.y){ + return MapConnection{Direction::NORTH, b.name, pb.x - pa.x}; + } + if (columns_overlap && pb.y == pa.y + ah){ + return MapConnection{Direction::SOUTH, b.name, pb.x - pa.x}; + } + if (rows_overlap && pb.x + bw == pa.x){ + return MapConnection{Direction::WEST, b.name, pb.y - pa.y}; + } + if (rows_overlap && pb.x == pa.x + aw){ + return MapConnection{Direction::EAST, b.name, pb.y - pa.y}; + } + return std::nullopt; +} + +} // namespace + +void connect_by_world(std::vector& maps){ + for (MapData& a : maps){ + for (const MapData& b : maps){ + if (&a == &b || !a.world || !b.world || a.world->name != b.world->name){ + continue; + } + const std::optional connection = touching(a, b); + if (!connection){ + continue; + } + const bool joined = std::ranges::any_of(a.connections, [&](const MapConnection& existing){ + return existing.to_map == b.name; + }); + if (!joined){ + a.connections.push_back(*connection); + } + } + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h new file mode 100644 index 0000000000..5fef2d16a6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h @@ -0,0 +1,99 @@ +/* Connected Maps + * + * From: https://github.com/PokemonAutomation/ + * + * The one world the tile games (BDSP, FRLG) plan and walk on: maps joined by + * their warps and their edges (MapData::connections). The player's place in + * it is a map and a tile of that map, in the map's own coordinates. Where a + * warp or an edge leads is the same in both games; whether a step is + * allowed, and what the game does on arrival (FRLG walks the player out of + * a door), is each game's. + * + */ + +#ifndef PokemonAutomation_Pokemon_ConnectedMaps_H +#define PokemonAutomation_Pokemon_ConnectedMaps_H + +#include +#include +#include +#include +#include "Pokemon_Grid.h" +#include "Pokemon_MapData.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A tile of one of the connected maps: the map's index and the tile in that +// map's own coordinates. +struct MapPlace{ + size_t map = 0; + TilePos tile; + + bool operator==(const MapPlace& other) const = default; + // Map, then tile: an order for sets and maps of places. + auto operator<=>(const MapPlace& other) const = default; +}; + + +// A view of loaded maps as one connected world. It does not own the maps, +// which must outlive it and keep their order: MapPlace::map indexes them. +class ConnectedMaps{ +public: + explicit ConnectedMaps(const std::vector& maps) + : m_maps(&maps) + {} + // A temporary list would be gone by the first call. + explicit ConnectedMaps(std::vector&& maps) = delete; + + // How many maps are loaded: MapPlace::map runs from 0 to size() - 1. + size_t size() const{ + return m_maps->size(); + } + // The map at `index`; throws InternalProgramError past the last map, + // as from a MapPlace of another world. + const MapData& map(size_t index) const; + // The loaded map named `name`, or nothing. + std::optional find(std::string_view name) const; + + // Where taking `warp` puts the player: its destination point. Nothing + // if it leads to a map that isn't loaded or names a point that map + // doesn't have. + std::optional warp_arrival(const MapWarp& warp) const; + + // The tile past `side` of `from`'s map that carries on `from`'s row or + // column: on the first loaded map connected on that side that has it. + // Nothing if no loaded map there has it. + std::optional across_edge(const MapPlace& from, Direction side) const; + + // The tile next to `from` in `direction`: on the same map, or across + // its edge. Nothing past an edge that leads nowhere loaded. + std::optional neighbour(const MapPlace& from, Direction direction) const; + +private: + const std::vector* m_maps; +}; + + +// Joins the maps that lie on the same world grid (MapData::world) where +// they meet: each map gets a connection on each side to every map whose +// rectangle touches that side, unless it has one to that map already. +// Maps without a world are left alone. +void connect_by_world(std::vector& maps); + + + +} // namespace Pokemon +} // namespace PokemonAutomation + + +// A hash of MapPlace, for planners that keep places in unordered sets. +template <> +struct std::hash{ + size_t operator()(const PokemonAutomation::Pokemon::MapPlace& place) const{ + return std::hash()(place.tile) * 31 + place.map; + } +}; + +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp new file mode 100644 index 0000000000..ceafa9304d --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp @@ -0,0 +1,270 @@ +/* Connected Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A town with a route north of it and a lake east of it, joined by their + * places on one world grid (connect_by_world()), and a house the town's + * door warps into: + * + * world x: -1 0 1 2 3 4 5 + * y 0..2: [ Route (6 wide) ] + * y 3..5: [ Town (4) ][Lake] + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_ConnectedMaps.h" +#include "Pokemon_ConnectedMaps_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ +namespace{ + + +MapData open_map(std::string name, int width, int height){ + MapData map; + map.name = std::move(name); + map.tiles = Grid{width, height, std::vector((size_t)width * height, TileKind::OPEN)}; + return map; +} + +MapData on_world(MapData map, const TilePos& offset){ + map.world = MapWorld{"Test", offset}; + return map; +} + +const std::vector& test_maps(){ + static const std::vector maps = []{ + std::vector ret{ + on_world(open_map("Town", 4, 3), {0, 3}), + on_world(open_map("Route", 6, 3), {-1, 0}), + on_world(open_map("Lake", 2, 3), {4, 3}), + open_map("House", 2, 2), + }; + ret[3].points["door"] = {0, 1}; + connect_by_world(ret); + return ret; + }(); + return maps; +} + +// A tile named by its map. +struct NamedPlace{ + std::string_view map; + TilePos tile; +}; + +std::string describe(const ConnectedMaps& world, const std::optional& place){ + if (!place){ + return "nowhere"; + } + return std::format("{} {}", world.map(place->map).name, to_string(place->tile)); +} + +// Where a step or a warp should put the player, or nothing for nowhere. +struct PlaceExpectation{ + std::optional place; +}; + +// Why `actual` is not `expected`, if it is not. +std::optional mismatch(const ConnectedMaps& world, const std::optional& actual, const PlaceExpectation& expectation){ + const std::optional& expected = expectation.place; + std::optional wanted; + if (expected){ + wanted = MapPlace{*world.find(expected->map), expected->tile}; + } + if (actual == wanted){ + return std::nullopt; + } + return std::format("Got {}, expected {}.", describe(world, actual), describe(world, wanted)); +} + + +struct StepInput{ + std::string_view name; + NamedPlace from; + Direction direction; +}; +struct StepCase{ + StepInput input; + PlaceExpectation expectation; +}; + +class Test_ConnectedMaps_Step : public UnitTest{ +public: + explicit Test_ConnectedMaps_Step(StepCase scenario) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedMaps world(test_maps()); + const StepInput& input = m_scenario.input; + const MapPlace from{*world.find(input.from.map), input.from.tile}; + if (std::optional error = mismatch(world, world.neighbour(from, input.direction), m_scenario.expectation)){ + return *error; + } + return true; + } +private: + StepCase m_scenario; +}; + +const StepCase STEP_CASES[] = { + { + .input = {.name = "a step on the same map", .from = {"Town", {1, 1}}, .direction = Direction::EAST}, + .expectation = {.place = NamedPlace{"Town", {2, 1}}}, + }, + { + .input = {.name = "north onto the route, shifted by its offset", .from = {"Town", {0, 0}}, .direction = Direction::NORTH}, + .expectation = {.place = NamedPlace{"Route", {1, 2}}}, + }, + { + .input = {.name = "south off the route into the town", .from = {"Route", {1, 2}}, .direction = Direction::SOUTH}, + .expectation = {.place = NamedPlace{"Town", {0, 0}}}, + }, + { + .input = {.name = "east into the lake", .from = {"Town", {3, 2}}, .direction = Direction::EAST}, + .expectation = {.place = NamedPlace{"Lake", {0, 2}}}, + }, + { + .input = {.name = "west into the town", .from = {"Lake", {0, 1}}, .direction = Direction::WEST}, + .expectation = {.place = NamedPlace{"Town", {3, 1}}}, + }, + { + .input = {.name = "north out of the lake onto the route's last column", .from = {"Lake", {0, 0}}, .direction = Direction::NORTH}, + .expectation = {.place = NamedPlace{"Route", {5, 2}}}, + }, + { + .input = {.name = "north out of the lake past the route's span", .from = {"Lake", {1, 0}}, .direction = Direction::NORTH}, + .expectation = {.place = std::nullopt}, + }, + { + .input = {.name = "an edge no map joins", .from = {"Town", {0, 1}}, .direction = Direction::WEST}, + .expectation = {.place = std::nullopt}, + }, + { + .input = {.name = "past the joined map's span", .from = {"Route", {0, 2}}, .direction = Direction::SOUTH}, + .expectation = {.place = std::nullopt}, + }, + { + .input = {.name = "a map off the world grid joins nothing", .from = {"House", {1, 0}}, .direction = Direction::NORTH}, + .expectation = {.place = std::nullopt}, + }, +}; + + +struct WarpInput{ + std::string_view name; + MapWarp warp; +}; +struct WarpCase{ + WarpInput input; + PlaceExpectation expectation; +}; + +class Test_ConnectedMaps_Warp : public UnitTest{ +public: + explicit Test_ConnectedMaps_Warp(WarpCase scenario) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedMaps world(test_maps()); + if (std::optional error = mismatch(world, world.warp_arrival(m_scenario.input.warp), m_scenario.expectation)){ + return *error; + } + return true; + } +private: + WarpCase m_scenario; +}; + +const WarpCase WARP_CASES[] = { + { + .input = {.name = "a warp to a loaded map's point", .warp = {.to = WarpDestination{"House", "door"}}}, + .expectation = {.place = NamedPlace{"House", {0, 1}}}, + }, + { + .input = {.name = "a warp to a map that isn't loaded", .warp = {.to = WarpDestination{"Cave", "door"}}}, + .expectation = {.place = std::nullopt}, + }, + { + .input = {.name = "a warp to a point the map lacks", .warp = {.to = WarpDestination{"House", "stairs"}}}, + .expectation = {.place = std::nullopt}, + }, + { + .input = {.name = "a warp that leads nowhere", .warp = {}}, + .expectation = {.place = std::nullopt}, + }, +}; + + +struct StalePlaceInput{ + std::string_view name; + size_t map; +}; +struct StalePlaceExpectation{ + // Whether reading the place throws InternalProgramError. + bool rejected = false; +}; +struct StalePlaceCase{ + StalePlaceInput input; + StalePlaceExpectation expectation; +}; + +// A place whose map index is past the loaded maps (from another world, or +// one that has since shrunk) is an InternalProgramError, not a read past +// the end. +class Test_ConnectedMaps_StalePlace : public UnitTest{ +public: + explicit Test_ConnectedMaps_StalePlace(StalePlaceCase scenario) + : UnitTest(std::format("Pokemon::ConnectedMaps - {}", scenario.input.name)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedMaps world(test_maps()); + const MapPlace stale{m_scenario.input.map, {0, 0}}; + bool rejected = false; + try{ + world.neighbour(stale, Direction::NORTH); + }catch (const InternalProgramError&){ + rejected = true; + } + if (rejected != m_scenario.expectation.rejected){ + return std::format("Map {} of {} was {}, expected it {}.", stale.map, world.size(), + rejected ? "rejected" : "read", m_scenario.expectation.rejected ? "rejected" : "read"); + } + return true; + } +private: + StalePlaceCase m_scenario; +}; + +const StalePlaceCase STALE_PLACE_CASES[] = { + {.input = {.name = "the last map index is read", .map = 3}, .expectation = {.rejected = false}}, + {.input = {.name = "a map index one past the last is rejected", .map = 4}, .expectation = {.rejected = true}}, + {.input = {.name = "a map index far past the last is rejected", .map = 1000}, .expectation = {.rejected = true}}, +}; + + +} // namespace + +void add_tests_ConnectedMaps(UnitTestDatabase& database){ + for (const StepCase& scenario : STEP_CASES){ + database.add(scenario); + } + for (const WarpCase& scenario : WARP_CASES){ + database.add(scenario); + } + for (const StalePlaceCase& scenario : STALE_PLACE_CASES){ + database.add(scenario); + } +} + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h new file mode 100644 index 0000000000..a3d6a6c26b --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h @@ -0,0 +1,22 @@ +/* Connected Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_ConnectedMaps_Tests_H +#define PokemonAutomation_Pokemon_ConnectedMaps_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers the checks on stepping and warping between connected maps. +void add_tests_ConnectedMaps(UnitTestDatabase& database); + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h new file mode 100644 index 0000000000..2b7d734b88 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics.h @@ -0,0 +1,119 @@ +/* Move Mechanics + * + * From: https://github.com/PokemonAutomation/ + * + * How each game moves the player for a press, as measured on the console: + * one entry per game, read by that game's walker and by its sim. + * + */ + +#ifndef PokemonAutomation_Pokemon_MoveMechanics_H +#define PokemonAutomation_Pokemon_MoveMechanics_H + +#include +#include "Common/Cpp/Time.h" +#include "Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// How the walker presses an open leg, one that ends short of a wall. +enum class OpenLegPress{ + STEP_TAPS, // a step tap a tile: the count is exact + TIMED_HOLD, // one hold, timed by the tile time +}; + +// Time per tile along each axis of the screen. +struct TileTime{ + Milliseconds across{}; // east or west + Milliseconds up_down{}; // north or south + + constexpr Milliseconds along(Direction direction) const{ + return direction == Direction::EAST || direction == Direction::WEST ? across : up_down; + } +}; + +// A tap that takes one step: the press, and the release before the next +// press. Their sum is the time per tapped tile. +struct StepTap{ + Milliseconds hold{}; + Milliseconds release{}; +}; + +// One way of moving: walking, running or riding. +struct Gait{ + TileTime tile; + // The step tap in this gait; a game's taps differ by gait (FRLG's + // Bicycle taps far faster than its walk). + StepTap tap; + OpenLegPress open_legs = OpenLegPress::STEP_TAPS; +}; + +// How one game moves the player: its turn tap, and a tile time and step +// tap per gait. +struct MoveMechanics{ + // A tap that turns a player facing another way, without a step. + Milliseconds turn_tap{}; + // From pressing, standing still, to the first step under way. + Milliseconds start_delay{}; + Gait walk; + // B held, once the player has the Running Shoes. + Gait run; + // None where the walker does not ride yet. + std::optional bike; +}; + + +// Brilliant Diamond and Shining Pearl, measured on console B. The camera +// tilts, so a row takes longer than a column. D-pad taps move exactly a +// tile each, while a held run overshoots about 3 tiles in 10 (2026-11-09, +// Jubilife), so open legs are tapped. Taps: PokemonBDSP_AutoStory_RouteInput.h; +// tile times: PokemonBDSP_AutoStory_RouteTiming.h. +inline constexpr MoveMechanics BDSP_MOVE_MECHANICS{ + .turn_tap = Milliseconds(50), + .start_delay = Milliseconds(250), + .walk = { + .tile = {.across = Milliseconds(160), .up_down = Milliseconds(240)}, + .tap = {.hold = Milliseconds(160), .release = Milliseconds(640)}, + .open_legs = OpenLegPress::STEP_TAPS, + }, + .run = { + .tile = {.across = Milliseconds(100), .up_down = Milliseconds(150)}, + .tap = {.hold = Milliseconds(160), .release = Milliseconds(640)}, + .open_legs = OpenLegPress::STEP_TAPS, + }, + .bike = std::nullopt, +}; + +// FireRed and LeafGreen, measured on console B: a walking tile is 16 +// frames, running 8, and a held leg stops where its time says, so open +// legs on foot are timed holds; on the Bicycle they are counted in taps, +// 40 ms at one per 100 ms (BIKE_TAP_PERIOD_WORKED; at a 60 ms period one +// tap in 12 drops). The walker's holds count no start delay. +// Measurements: PokemonFRLG_MovementMechanics.h and +// PokemonFRLG_BikeSpinMechanics.h. +inline constexpr MoveMechanics FRLG_MOVE_MECHANICS{ + .turn_tap = Milliseconds(40), + .start_delay = Milliseconds(0), + .walk = { + .tile = {.across = Milliseconds(267), .up_down = Milliseconds(267)}, + .tap = {.hold = Milliseconds(66), .release = Milliseconds(700)}, + .open_legs = OpenLegPress::TIMED_HOLD, + }, + .run = { + .tile = {.across = Milliseconds(133), .up_down = Milliseconds(133)}, + .tap = {.hold = Milliseconds(66), .release = Milliseconds(700)}, + .open_legs = OpenLegPress::TIMED_HOLD, + }, + .bike = Gait{ + .tile = {.across = Milliseconds(100), .up_down = Milliseconds(100)}, + .tap = {.hold = Milliseconds(40), .release = Milliseconds(60)}, + .open_legs = OpenLegPress::STEP_TAPS, + }, +}; + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp new file mode 100644 index 0000000000..c0de39e0f5 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp @@ -0,0 +1,130 @@ +/* Move Mechanics Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_MoveMechanics.h" +#include "Pokemon_MoveMechanics_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ +namespace{ + + +struct MoveMechanicsInput{ + std::string_view game; + MoveMechanics mechanics; +}; +struct MoveMechanicsExpectation{ + // How the walker presses an open leg on foot (the user's pick, + // 2026-11-11: BDSP taps, FRLG timed holds). + OpenLegPress open_legs_on_foot; +}; +struct MoveMechanicsCase{ + MoveMechanicsInput input; + MoveMechanicsExpectation expectation; +}; + +// Why `faster` is not faster than `slower` on both axes, if it is not. +std::optional not_faster(std::string_view faster_name, const Gait& faster, std::string_view slower_name, const Gait& slower){ + if (faster.tile.across >= slower.tile.across || faster.tile.up_down >= slower.tile.up_down){ + return std::format("{} ({}/{} ms) is not faster than {} ({}/{} ms).", + faster_name, faster.tile.across.count(), faster.tile.up_down.count(), + slower_name, slower.tile.across.count(), slower.tile.up_down.count()); + } + return std::nullopt; +} + +// Why the turn tap would step on foot in `gait`, if it would: a turn tap +// must be shorter than the gait's step tap. +std::optional turn_steps(std::string_view gait_name, const Gait& gait, Milliseconds turn_tap){ + if (turn_tap >= gait.tap.hold){ + return std::format("The turn tap ({} ms) is not shorter than the {} step tap ({} ms).", + turn_tap.count(), gait_name, gait.tap.hold.count()); + } + return std::nullopt; +} + +// Why a gait's step tap is unusable, if it is: both its press and its +// release must take time. +std::optional empty_tap(std::string_view gait_name, const Gait& gait){ + if (gait.tap.hold <= Milliseconds(0) || gait.tap.release <= Milliseconds(0)){ + return std::format("The {} step tap is {} ms pressed, {} ms released; both must be over 0.", + gait_name, gait.tap.hold.count(), gait.tap.release.count()); + } + return std::nullopt; +} + +std::string_view open_leg_press_name(OpenLegPress press){ + return press == OpenLegPress::STEP_TAPS ? "step taps" : "a timed hold"; +} + +// Why `gait` presses its open legs other than `expected`, if it does. +std::optional wrong_open_legs(std::string_view gait_name, const Gait& gait, OpenLegPress expected){ + if (gait.open_legs != expected){ + return std::format("Open legs {} are pressed as {}, expected {}.", + gait_name, open_leg_press_name(gait.open_legs), open_leg_press_name(expected)); + } + return std::nullopt; +} + +class Test_MoveMechanics : public UnitTest{ +public: + explicit Test_MoveMechanics(MoveMechanicsCase scenario) + : UnitTest(std::format("Pokemon::MoveMechanics - {}", scenario.input.game)), m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const MoveMechanics& game = m_scenario.input.mechanics; + const OpenLegPress expected = m_scenario.expectation.open_legs_on_foot; + const std::optional failures[] = { + empty_tap("walking", game.walk), + empty_tap("running", game.run), + game.bike ? empty_tap("bike", *game.bike) : std::nullopt, + turn_steps("walking", game.walk, game.turn_tap), + turn_steps("running", game.run, game.turn_tap), + not_faster("running", game.run, "walking", game.walk), + game.bike ? not_faster("the bike", *game.bike, "running", game.run) : std::nullopt, + wrong_open_legs("walking", game.walk, expected), + wrong_open_legs("running", game.run, expected), + }; + for (const std::optional& failure : failures){ + if (failure){ + return *failure; + } + } + return true; + } +private: + MoveMechanicsCase m_scenario; +}; + +const MoveMechanicsCase MOVE_MECHANICS_CASES[] = { + { + .input = {.game = "BDSP", .mechanics = BDSP_MOVE_MECHANICS}, + .expectation = {.open_legs_on_foot = OpenLegPress::STEP_TAPS}, + }, + { + .input = {.game = "FRLG", .mechanics = FRLG_MOVE_MECHANICS}, + .expectation = {.open_legs_on_foot = OpenLegPress::TIMED_HOLD}, + }, +}; + + +} // namespace + +void add_tests_MoveMechanics(UnitTestDatabase& database){ + for (const MoveMechanicsCase& scenario : MOVE_MECHANICS_CASES){ + database.add(scenario); + } +} + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h new file mode 100644 index 0000000000..a545eae699 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h @@ -0,0 +1,22 @@ +/* Move Mechanics Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_MoveMechanics_Tests_H +#define PokemonAutomation_Pokemon_MoveMechanics_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers the checks on each game's movement table. +void add_tests_MoveMechanics(UnitTestDatabase& database); + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h new file mode 100644 index 0000000000..a6fb75f8d0 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h @@ -0,0 +1,550 @@ +/* Robust Leg Planner + * + * From: https://github.com/PokemonAutomation/ + * + * Plans walks whose open legs may go a tile short or long. A leg to a wall + * is walked until the player stops; an open leg is walked for its tiles' + * worth of time and may end a few tiles either way. The planner searches + * over the sets of places the player may stand on after each leg, and + * later walls bring them back together, so the plan reaches the goal from + * every place the player may be. + * + * A step model is a class with: + * + * using State = ...; // where the player is: comparable with == + * using StateLess = ...; // a strict order of State, for sets of them: + * // std::less for TilePos and MapPlace + * std::optional step(const State& state, Direction direction) const; + * size_t step_tiles(const State& from, const State& to) const; + * bool held_at(const State& state, Direction direction) const; + * bool wild(const State& state) const; + * bool wander(const State& state) const; + * + * step() is where one step `direction` lands, or nothing if the player is + * stopped. step_tiles() is how many tiles that step counts (a ledge hop + * counts 2). held_at() is whether the player, stopped, stays put however + * long the button is held (a wall); a stop that isn't held (a door, an exit + * off the maps) makes a leg the planner can't tell the end of, and it is + * not used. wild() is a place where a wild battle may stop the walk (tall + * grass); wander() one where someone wanders. + * + * Warps and game actions (doors, Surf, spin tiles) are not legs: a stop + * that isn't held is never used, so a plan never crosses a warp. Callers + * plan each stretch between warps on its own. The step model here and the + * one of Pokemon_LegPlanner.h (press(), Step) describe the same + * world rules for two planners; a game writes one adapter for each. + * + */ + +#ifndef PokemonAutomation_Pokemon_RobustLegPlanner_H +#define PokemonAutomation_Pokemon_RobustLegPlanner_H + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// A leg of a robust plan: walk `direction` for `tiles` tiles, or until +// stopped if `to_wall`. `after` lists every place the player may stand on +// once the leg is done. +template +struct RobustLeg{ + Direction direction = Direction::NORTH; + size_t tiles = 0; // tiles travelled; a ledge hop counts 2 + bool to_wall = false; + std::vector after; + // An open leg held for its tiles' time instead of tapped a tile at a + // time (RobustLegCosts::hold_open_legs). A held leg is never joined + // with the next one the same way: each is its own hold. + bool held = false; +}; + + +// The weights of a robust plan and the limits of its search. +struct RobustLegCosts{ + int per_tile = 1; + int per_wild_tile = 4; // extra for each wild tile entered + int per_wander_tile = 3; // extra for each tile entered where someone wanders + int per_leg = 8; + int leg_not_at_wall = 50; // extra for a leg that stops in the open + // An open leg of n tiles may end open_error + n / open_error_per tiles + // short or long. open_error_per 0 adds no growth: every open leg is + // off by open_error at most, and by nothing if open_error is 0 too. + int open_error = 1; + int open_error_per = 5; + // Open legs this many tiles or shorter land exactly. 0 keeps every + // open leg uncertain. + int exact_open_tiles = 0; + // Extra per tile of an open leg: its timing error grows with its length. + int per_open_tile = 0; + // Open legs that may end off (longer than exact_open_tiles) are held + // for their time (RobustLeg::held), not tapped, and pay no + // per_open_tile: no such leg is planned whose possible ends past its + // shortest enter a wild or wander place or hop a ledge, so a long or + // short hold meets nothing a tap would not have. + bool hold_open_legs = false; + // Extra per wild place an open leg enters, on top of per_wild_tile: a + // wild battle loses an open leg's count, while a leg to a wall just + // walks to the wall again. + int per_open_wild_tile = 0; + int max_open_tiles = 12; // longest open leg to consider + size_t max_spread = 5; // most places the player may be on after a leg + // Most sets of places to search before giving up. The search is over + // sets, not places, so it grows far faster than the map. + size_t max_searched = 20000; +}; + + +// The cheapest legs that take the player from any of `from` to places that +// all satisfy `goal`, even if every open leg ends up to its error off. +// Legs that run along where someone wanders (two such places in a row, the +// leg's start among them) are not used. Nothing if no such plan exists, or +// none is found within `costs.max_searched` sets. +template +std::optional>> plan_robust_legs( + const Model& model, + std::vector from, + const std::function& goal, + const RobustLegCosts& costs +); + +// What plan_robust_legs() charges for walking `legs` from any of `from`, +// each leg from the places the one before may end on. A leg it would not +// plan costs its tiles and legs without wild or wander tiles. +template +long long robust_legs_cost( + const Model& model, + std::vector from, + const std::vector>& legs, + const RobustLegCosts& costs +); + + + +namespace RobustLegPlannerInternal{ + +// Most steps a leg to a wall may take. No map is this long; a model whose +// steps loop (edge connections that come back round, or a model bug) +// would otherwise slide forever. +inline constexpr size_t MAX_STEPS_TO_WALL = 1024; + +// Where the player stops walking `direction` until stopped. +template +struct WallHit{ + State stop; + size_t tiles = 0; + bool held = false; +}; +// Walks `direction` from `from` until the player is stopped. A walk that +// is not stopped within MAX_STEPS_TO_WALL steps is not held. +template +WallHit slide_to_wall(const Model& model, const typename Model::State& from, Direction direction){ + WallHit hit{from}; + for (size_t steps = 0; steps < MAX_STEPS_TO_WALL; steps++){ + const auto next = model.step(hit.stop, direction); + if (!next){ + hit.held = model.held_at(hit.stop, direction); + return hit; + } + hit.tiles += model.step_tiles(hit.stop, *next); + hit.stop = *next; + } + return hit; +} + +// How many tiles an open leg of `tiles` tiles may end short or long. +inline int open_leg_error(int tiles, const RobustLegCosts& costs){ + if (tiles <= costs.exact_open_tiles){ + return 0; + } + if (costs.open_error_per <= 0){ + return costs.open_error; + } + return costs.open_error + tiles / costs.open_error_per; +} + +// Where `from` ends up after `tiles` tiles `direction`, stopping early +// where it is held, and the wild and wander tiles it enters. Nothing if a +// step is stopped where the player is not held. +template +struct Stepped{ + State end; + int wild = 0; + int wander = 0; + bool along_wander = false; +}; +// Steps `from` up to `tiles` tiles `direction` (see Stepped). +template +std::optional> step_tiles(const Model& model, typename Model::State from, Direction direction, int tiles){ + Stepped stepped{from}; + int travelled = 0; + bool in_wander = model.wander(from); + while (travelled < tiles){ + const auto next = model.step(from, direction); + if (!next){ + if (!model.held_at(from, direction)){ + return std::nullopt; + } + break; + } + travelled += (int)model.step_tiles(from, *next); + stepped.wild += model.wild(*next) ? 1 : 0; + const bool next_wander = model.wander(*next); + if (next_wander){ + stepped.wander++; + stepped.along_wander |= in_wander; + } + in_wander = next_wander; + from = *next; + } + stepped.end = from; + return stepped; +} + +// step_tiles() for each count from 1 to `most`, in one walk: [n - 1] is +// step_tiles(model, from, direction, n). +template +std::vector>> step_prefixes( + const Model& model, typename Model::State from, Direction direction, int most +){ + std::vector>> out; + Stepped stepped{from}; + int travelled = 0; + bool in_wander = model.wander(from); + while ((int)out.size() < most){ + const auto next = model.step(from, direction); + if (!next){ + stepped.end = from; + std::optional> last; + if (model.held_at(from, direction)){ + last = stepped; + } + out.resize((size_t)most, last); + break; + } + travelled += (int)model.step_tiles(from, *next); + stepped.wild += model.wild(*next) ? 1 : 0; + const bool next_wander = model.wander(*next); + if (next_wander){ + stepped.wander++; + stepped.along_wander |= in_wander; + } + in_wander = next_wander; + from = *next; + stepped.end = from; + while ((int)out.size() < std::min(travelled, most)){ + out.push_back(stepped); + } + } + return out; +} + +// Whether a held leg's possible ends, `ends` in order from the shortest, +// meet nothing past the shortest that a tap would not: no wild or wander +// place, no ledge hop. +template +bool held_ends_safe(const Model& model, const std::vector& ends){ + for (size_t i = 1; i < ends.size(); i++){ + if (model.step_tiles(ends[i - 1], ends[i]) > 1 || model.wild(ends[i]) || model.wander(ends[i])){ + return false; + } + } + return true; +} + +// Sorts a spread and drops repeated places, so equal sets compare equal. +template +void normalize(std::vector& spread){ + using State = typename Model::State; + std::sort(spread.begin(), spread.end(), typename Model::StateLess()); + spread.erase(std::unique(spread.begin(), spread.end(), [](const State& a, const State& b){ return a == b; }), spread.end()); +} +// Orders spreads, for keeping them in a map. +template +struct SpreadLess{ + bool operator()(const std::vector& a, const std::vector& b) const{ + return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), typename Model::StateLess()); + } +}; + +// A leg out of a spread: where every place of it ends, and its cost. +template +struct Expansion{ + long long cost = 0; + RobustLeg leg; + // A held leg that may end somewhere unsafe (held_ends_safe()): not to + // be used, though a longer one may be. + bool unsafe = false; +}; + +// To the wall: every place walks until stopped. Nothing unless each is +// held, and one moves. +template +std::optional> to_wall_leg( + const Model& model, const std::vector& spread, Direction direction, const RobustLegCosts& costs +){ + Expansion expansion; + size_t longest = 0; + int wild = 0; + int wander = 0; + for (const auto& place : spread){ + const auto hit = slide_to_wall(model, place, direction); + if (!hit.held){ + return std::nullopt; + } + if (const auto stepped = step_tiles(model, place, direction, (int)hit.tiles)){ + if (stepped->along_wander){ + return std::nullopt; + } + wild = std::max(wild, stepped->wild); + wander = std::max(wander, stepped->wander); + } + longest = std::max(longest, hit.tiles); + expansion.leg.after.push_back(hit.stop); + } + if (longest == 0){ + return std::nullopt; + } + expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest + + (long long)costs.per_wild_tile * wild + (long long)costs.per_wander_tile * wander; + expansion.leg.direction = direction; + expansion.leg.tiles = longest; + expansion.leg.to_wall = true; + return expansion; +} + +// Open: about `tiles` tiles, give or take the error. Nothing if any +// possible end is stopped where the player is not held. A held leg whose +// ends may be unsafe is marked so (Expansion::unsafe). +template +std::optional> open_leg( + const Model& model, const std::vector& spread, Direction direction, int tiles, const RobustLegCosts& costs +){ + using State = typename Model::State; + Expansion expansion; + int wild = 0; + int wander = 0; + const int error = open_leg_error(tiles, costs); + const bool held = costs.hold_open_legs && error > 0; + for (const auto& place : spread){ + std::vector ends; + const auto prefixes = step_prefixes(model, place, direction, tiles + error); + for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ + const auto& stepped = prefixes[(size_t)n - 1]; + if (!stepped || stepped->along_wander){ + return std::nullopt; + } + wild = std::max(wild, stepped->wild); + wander = std::max(wander, stepped->wander); + ends.push_back(stepped->end); + } + if (held && !held_ends_safe(model, ends)){ + expansion.unsafe = true; + } + expansion.leg.after.insert(expansion.leg.after.end(), ends.begin(), ends.end()); + } + const int per_open_tile = held ? 0 : costs.per_open_tile; + expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall + + (long long)(costs.per_tile + per_open_tile) * tiles + + (long long)(costs.per_wild_tile + costs.per_open_wild_tile) * wild + (long long)costs.per_wander_tile * wander; + expansion.leg.direction = direction; + expansion.leg.tiles = (size_t)tiles; + expansion.leg.held = held; + return expansion; +} + +// Whether `next` walks on as one hold with `prev`: both open and tapped, +// the same way. +template +bool joins(const RobustLeg& prev, const RobustLeg& next){ + return prev.direction == next.direction && !prev.to_wall && !prev.held && !next.held; +} + +// Joins an open leg with the next one the same way: they are one hold. +template +std::vector> consolidate(const std::vector>& legs){ + std::vector> consolidated; + for (const RobustLeg& leg : legs){ + if (!consolidated.empty() && joins(consolidated.back(), leg)){ + consolidated.back().tiles += leg.tiles; + consolidated.back().to_wall = leg.to_wall; + consolidated.back().after = leg.after; + }else{ + consolidated.push_back(leg); + } + } + return consolidated; +} + +// Dijkstra over sets of places the player may stand on. +template +class Search{ +public: + using State = typename Model::State; + using Spread = std::vector; + + Search(const Model& model, const RobustLegCosts& costs) + : m_model(model) + , m_costs(costs) + {} + + std::optional>> run(Spread start, const std::function& goal){ + normalize(start); + m_start = start; + m_nodes[start] = Node{}; + m_queue.emplace(0, start); + size_t searched = 0; + while (!m_queue.empty()){ + const auto [cost, spread] = m_queue.top(); + m_queue.pop(); + Node& node = m_nodes[spread]; + if (node.done || node.cost != cost){ + continue; + } + node.done = true; + if (++searched > m_costs.max_searched){ + return std::nullopt; + } + if (std::all_of(spread.begin(), spread.end(), goal)){ + return consolidate(legs_to(spread)); + } + expand(spread, cost); + } + return std::nullopt; + } + +private: + struct Node{ + long long cost = 0; + Spread parent; + RobustLeg leg; + bool done = false; + }; + using Entry = std::pair; + struct EntryGreater{ + bool operator()(const Entry& a, const Entry& b) const{ + return a.first > b.first; + } + }; + + void expand(const Spread& spread, long long cost){ + for (Direction direction : ALL_DIRECTIONS){ + if (auto wall = to_wall_leg(m_model, spread, direction, m_costs)){ + relax(spread, cost, std::move(*wall)); + } + // A held leg unsafe at one length may be safe at a longer one. + for (int tiles = 1; tiles <= m_costs.max_open_tiles; tiles++){ + auto open = open_leg(m_model, spread, direction, tiles, m_costs); + if (!open){ + break; + } + if (!open->unsafe){ + relax(spread, cost, std::move(*open)); + } + } + } + } + + // Only the start may be wider than costs.max_spread: every leg must + // bring the player within it. + void relax(const Spread& spread, long long cost, Expansion expansion){ + Spread& next = expansion.leg.after; + normalize(next); + if (next.size() > m_costs.max_spread || next == spread){ + return; + } + if (spread != m_start){ + const RobustLeg& prev = m_nodes.at(spread).leg; + if (joins(prev, expansion.leg)){ + expansion.cost -= m_costs.per_leg; + } + } + const long long total = cost + expansion.cost; + auto iter = m_nodes.find(next); + if (iter != m_nodes.end() && iter->second.cost <= total){ + return; + } + m_nodes[next] = Node{total, spread, expansion.leg}; + m_queue.emplace(total, std::move(next)); + } + + std::vector> legs_to(const Spread& end) const{ + std::vector> legs; + for (Spread at = end; at != m_start; ){ + const Node& step = m_nodes.at(at); + legs.push_back(step.leg); + at = step.parent; + } + std::reverse(legs.begin(), legs.end()); + return legs; + } + + const Model& m_model; + const RobustLegCosts& m_costs; + Spread m_start; + std::map> m_nodes; + std::priority_queue, EntryGreater> m_queue; +}; + +} // namespace RobustLegPlannerInternal + + + +template +std::optional>> plan_robust_legs( + const Model& model, + std::vector from, + const std::function& goal, + const RobustLegCosts& costs +){ + return RobustLegPlannerInternal::Search(model, costs).run(std::move(from), goal); +} + +template +long long robust_legs_cost( + const Model& model, + std::vector from, + const std::vector>& legs, + const RobustLegCosts& costs +){ + using State = typename Model::State; + long long total = 0; + std::vector spread = std::move(from); + RobustLegPlannerInternal::normalize(spread); + const RobustLeg* previous = nullptr; + for (const RobustLeg& leg : legs){ + const auto expansion = leg.to_wall + ? RobustLegPlannerInternal::to_wall_leg(model, spread, leg.direction, costs) + : RobustLegPlannerInternal::open_leg(model, spread, leg.direction, (int)leg.tiles, costs); + long long cost = (long long)costs.per_leg + (long long)costs.per_tile * (long long)leg.tiles; + if (!leg.to_wall){ + cost += costs.leg_not_at_wall + (long long)costs.per_open_tile * (long long)leg.tiles; + } + if (expansion){ + cost = expansion->cost; + } + if (previous != nullptr && RobustLegPlannerInternal::joins(*previous, leg)){ + cost -= costs.per_leg; + } + total += cost; + spread = leg.after; + RobustLegPlannerInternal::normalize(spread); + previous = ⋚ + } + return total; +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp new file mode 100644 index 0000000000..b9866592b5 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp @@ -0,0 +1,370 @@ +/* Robust Leg Planner Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The robust planner on a small made-up game: walls hold the player, a + * door stops them without holding them, a ledge hops them south, and open + * legs may end a tile off. + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_RobustLegPlanner.h" +#include "Pokemon_RobustLegPlanner_Tests.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +namespace{ + +// '#' wall (and everything outside the rows), '.' floor, '"' tall grass, +// 'w' where someone wanders, 'D' a door: the player is stopped there but +// not held, since walking on enters the building. 'v' a ledge: a step south +// onto it hops to the tile past it and counts 2; it holds the player any +// other way. Rows that wrap join their east end to their west end, so a +// walk along them is never stopped. +class ToyGame{ +public: + using State = TilePos; + using StateLess = std::less; + + ToyGame(const std::vector& rows, bool wraps) + : m_rows(rows.begin(), rows.end()) + , m_wraps(wraps) + {} + + std::optional step(const State& state, Direction direction) const{ + TilePos next = wrapped(state.next(direction)); + const char tile = at(next); + if (tile == 'v' && direction == Direction::SOUTH){ + next = next.next(Direction::SOUTH); + return at(next) == '#' ? std::nullopt : std::optional(next); + } + if (tile == '#' || tile == 'D' || tile == 'v'){ + return std::nullopt; + } + return next; + } + size_t step_tiles(const State& from, const State& to) const{ + return to.y - from.y == 2 ? 2 : 1; + } + bool held_at(const State& state, Direction direction) const{ + return at(wrapped(state.next(direction))) != 'D'; + } + bool wild(const State& state) const{ + return at(state) == '"'; + } + bool wander(const State& state) const{ + return at(state) == 'w'; + } + +private: + TilePos wrapped(TilePos pos) const{ + if (m_wraps && pos.y >= 0 && pos.y < (int)m_rows.size()){ + const int width = (int)m_rows[pos.y].size(); + pos.x = (pos.x % width + width) % width; + } + return pos; + } + char at(const TilePos& pos) const{ + if (pos.y < 0 || pos.y >= (int)m_rows.size() || pos.x < 0 || pos.x >= (int)m_rows[pos.y].size()){ + return '#'; + } + return m_rows[pos.y][pos.x]; + } + + std::vector m_rows; + bool m_wraps = false; +}; + +using Legs = std::vector>; + +// Legs as "east 2 to wall: (2, 0); south 1 open: (2, 1) (2, 2)", or "none". +std::string describe(const std::optional& legs){ + if (!legs){ + return "none"; + } + std::string text; + for (const RobustLeg& leg : *legs){ + text += std::format("{}{} {} {}:", text.empty() ? "" : "; ", direction_name(leg.direction), leg.tiles, + leg.to_wall ? "to wall" : leg.held ? "held" : "open"); + for (const TilePos& pos : leg.after){ + text += " " + to_string(pos); + } + } + return text; +} + +constexpr RobustLegCosts EXACT{.exact_open_tiles = 12}; +// Open legs held for their time, a tile short or long at any length. +constexpr RobustLegCosts HELD{.open_error = 1, .open_error_per = 0, .hold_open_legs = true}; + + +struct PlanInput{ + std::string_view name; + std::vector rows; + bool wraps = false; + std::vector from; + TilePos goal; + RobustLegCosts costs; +}; +struct PlanExpectation{ + std::string_view legs; // as describe() writes them +}; +struct PlanCase{ + PlanInput input; + PlanExpectation expectation; +}; + +class Test_RobustLegPlanner_Plan : public UnitTest{ +public: + explicit Test_RobustLegPlanner_Plan(PlanCase scenario) + : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.input.name)) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const PlanInput& input = m_scenario.input; + const ToyGame game(input.rows, input.wraps); + const TilePos goal = input.goal; + const std::optional legs = plan_robust_legs(game, input.from, + std::function([goal](const TilePos& pos){ return pos == goal; }), input.costs); + const std::string actual = describe(legs); + if (actual != m_scenario.expectation.legs){ + return std::format("Planned \"{}\", expected \"{}\".", actual, m_scenario.expectation.legs); + } + return true; + } +private: + PlanCase m_scenario; +}; + +// Open legs on default costs may end a tile either way (two up to 5 tiles). +const PlanCase PLAN_CASES[] = { + { + .input = {.name = "a wall gathers the possible tiles", .rows = {"...#"}, .from = {{0, 0}, {1, 0}}, .goal = {2, 0}}, + .expectation = {.legs = "east 2 to wall: (2, 0)"}, + }, + { + .input = {.name = "no plan ends in the open while open legs may be off", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "an exact open leg ends in the open", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, .costs = EXACT}, + .expectation = {.legs = "east 3 open: (3, 0)"}, + }, + { + .input = { + .name = "open_error_per 0 with no open_error is exact", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, + .costs = {.open_error = 0, .open_error_per = 0}, + }, + .expectation = {.legs = "east 3 open: (3, 0)"}, + }, + { + .input = { + .name = "open_error_per 0 keeps open_error", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, + .costs = {.open_error = 1, .open_error_per = 0}, + }, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "a door is not a wall", .rows = {"#..D"}, .from = {{1, 0}}, .goal = {2, 0}, .costs = EXACT}, + .expectation = {.legs = "east 1 open: (2, 0)"}, + }, + { + .input = {.name = "no leg along a wander zone", .rows = {".www.", "....."}, .from = {{1, 0}}, .goal = {4, 0}, .costs = EXACT}, + .expectation = {.legs = "south 1 to wall: (1, 1); east 3 to wall: (4, 1); north 1 to wall: (4, 0)"}, + }, + { + .input = {.name = "a ledge hop counts 2 tiles", .rows = {".", "v", "."}, .from = {{0, 0}}, .goal = {0, 2}}, + .expectation = {.legs = "south 2 to wall: (0, 2)"}, + }, + { + .input = {.name = "a ledge cannot be climbed", .rows = {".", "v", "."}, .from = {{0, 2}}, .goal = {0, 0}}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "tall grass costs less than a detour", .rows = {".\"\"..", "....."}, .from = {{0, 0}}, .goal = {4, 0}}, + .expectation = {.legs = "east 4 to wall: (4, 0)"}, + }, + { + .input = { + .name = "costly tall grass is walked round", .rows = {".\"\"..", "....."}, .from = {{0, 0}}, .goal = {4, 0}, + .costs = {.per_wild_tile = 20}, + }, + .expectation = {.legs = "south 1 to wall: (0, 1); east 4 to wall: (4, 1); north 1 to wall: (4, 0)"}, + }, + { + // Only an open leg reaches the second row; a wall then gathers. + .input = {.name = "an open leg spreads, a wall gathers", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}}, + .expectation = {.legs = "east 1 open: (1, 0) (2, 0); south 1 to wall: (1, 1) (2, 1); east 2 to wall: (3, 1)"}, + }, + { + .input = { + .name = "a spread wider than max_spread is not planned", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, + .costs = {.max_spread = 1}, + }, + .expectation = {.legs = "none"}, + }, + { + .input = { + .name = "the search gives up past max_searched", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, + .costs = {.max_searched = 1}, + }, + .expectation = {.legs = "none"}, + }, + { + .input = { + .name = "two open legs the same way are one", .rows = {"........"}, .from = {{0, 0}}, .goal = {3, 0}, + .costs = {.exact_open_tiles = 12, .max_open_tiles = 2}, + }, + .expectation = {.legs = "east 3 open: (3, 0)"}, + }, + { + .input = {.name = "a walk that is never stopped is not a wall", .rows = {"...."}, .wraps = true, .from = {{0, 0}}, .goal = {2, 0}, .costs = EXACT}, + .expectation = {.legs = "east 2 open: (2, 0)"}, + }, + { + .input = {.name = "an open leg that may end off is held", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, + .expectation = {.legs = "east 1 held: (1, 0) (2, 0); south 1 to wall: (1, 1) (2, 1); east 2 to wall: (3, 1)"}, + }, + { + .input = {.name = "a held leg is refused when its long end lands in tall grass", .rows = {"..\"..", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "a held leg is refused when its long end lands where someone wanders", .rows = {"..w..", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = HELD}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "a held leg south lines up a wall leg", .rows = {".##", "...", "...", ".##", ".##"}, .from = {{0, 0}}, .goal = {2, 2}, .costs = HELD}, + .expectation = {.legs = "south 1 held: (0, 1) (0, 2); east 2 to wall: (2, 1) (2, 2); south 1 to wall: (2, 2)"}, + }, + { + .input = {.name = "a held leg is refused when its long end hops a ledge", .rows = {".##", "...", "v..", ".##", ".##"}, .from = {{0, 0}}, .goal = {2, 2}, .costs = HELD}, + .expectation = {.legs = "none"}, + }, + { + .input = {.name = "open legs are tapped while hold_open_legs is off", .rows = {".....", "#...#"}, .from = {{0, 0}}, .goal = {3, 1}, .costs = {.open_error = 1, .open_error_per = 0}}, + .expectation = {.legs = "east 1 open: (1, 0) (2, 0); south 1 to wall: (1, 1) (2, 1); east 2 to wall: (3, 1)"}, + }, +}; + + +struct CostInput{ + std::string_view name; + std::vector rows; + TilePos from; + Legs legs; + RobustLegCosts costs; +}; +struct CostExpectation{ + long long cost = 0; +}; +struct CostCase{ + CostInput input; + CostExpectation expectation; +}; + +class Test_RobustLegPlanner_Cost : public UnitTest{ +public: + explicit Test_RobustLegPlanner_Cost(CostCase scenario) + : UnitTest(std::format("Pokemon::RobustLegPlanner - {}", scenario.input.name)) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const CostInput& input = m_scenario.input; + const ToyGame game(input.rows, false); + const long long actual = robust_legs_cost(game, {input.from}, input.legs, input.costs); + if (actual != m_scenario.expectation.cost){ + return std::format("Cost {} for \"{}\", expected {}.", actual, describe(input.legs), m_scenario.expectation.cost); + } + return true; + } +private: + CostCase m_scenario; +}; + +// Default costs: 8 a leg, 1 a tile, 4 more a grass tile, 50 more for a +// leg that stops in the open. +const CostCase COST_CASES[] = { + { + .input = {.name = "a wall leg costs a leg and its tiles", .rows = {"...#"}, .from = {0, 0}, .legs = {{Direction::EAST, 2, true, {{2, 0}}}}}, + .expectation = {.cost = 8 + 2}, + }, + { + .input = { + .name = "an open leg costs its stop and open tiles on top", .rows = {"...#"}, .from = {0, 0}, + .legs = {{Direction::EAST, 1, false, {{1, 0}}}}, .costs = {.exact_open_tiles = 12, .per_open_tile = 2}, + }, + .expectation = {.cost = 8 + 50 + 3}, + }, + { + .input = {.name = "each grass tile entered costs extra", .rows = {".\"\"#"}, .from = {0, 0}, .legs = {{Direction::EAST, 2, true, {{2, 0}}}}}, + .expectation = {.cost = 8 + 2 + 2 * 4}, + }, + { + .input = { + .name = "a cost with open_error_per 0", .rows = {"........"}, .from = {0, 0}, + .legs = {{Direction::EAST, 3, false, {{3, 0}}}}, .costs = {.open_error_per = 0}, + }, + .expectation = {.cost = 8 + 50 + 3}, + }, + { + .input = { + .name = "a held leg pays no per_open_tile", .rows = {"........"}, .from = {0, 0}, + .legs = {{Direction::EAST, 3, false, {{2, 0}, {3, 0}, {4, 0}}, true}}, + .costs = {.open_error = 1, .open_error_per = 0, .per_open_tile = 2, .hold_open_legs = true}, + }, + .expectation = {.cost = 8 + 50 + 3}, + }, + { + .input = { + .name = "held legs the same way are not joined", .rows = {"........"}, .from = {0, 0}, + .legs = { + {Direction::EAST, 2, false, {{1, 0}, {2, 0}, {3, 0}}, true}, + {Direction::EAST, 2, false, {{2, 0}, {3, 0}, {4, 0}, {5, 0}}, true}, + }, + .costs = HELD, + }, + .expectation = {.cost = 2 * (8 + 50 + 2)}, + }, + { + .input = { + .name = "each grass tile of an open leg costs per_open_wild_tile more", .rows = {".\"\"...."}, .from = {0, 0}, + .legs = {{Direction::EAST, 3, false, {{3, 0}}}}, .costs = {.exact_open_tiles = 12, .per_open_wild_tile = 10}, + }, + .expectation = {.cost = 8 + 50 + 3 + 2 * (4 + 10)}, + }, + { + .input = { + .name = "per_open_wild_tile leaves a wall leg's grass alone", .rows = {".\"\"#"}, .from = {0, 0}, + .legs = {{Direction::EAST, 2, true, {{2, 0}}}}, .costs = {.per_open_wild_tile = 10}, + }, + .expectation = {.cost = 8 + 2 + 2 * 4}, + }, +}; + +} // namespace + + +void add_tests_RobustLegPlanner(UnitTestDatabase& database){ + for (const PlanCase& scenario : PLAN_CASES){ + database.add(scenario); + } + for (const CostCase& scenario : COST_CASES){ + database.add(scenario); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h new file mode 100644 index 0000000000..fec9e8a2e0 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h @@ -0,0 +1,23 @@ +/* Robust Leg Planner Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_RobustLegPlanner_Tests_H +#define PokemonAutomation_Pokemon_RobustLegPlanner_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers robust leg planner unit tests. +void add_tests_RobustLegPlanner(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp index 446a771ed8..7efb46838c 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Actions_Tests.cpp @@ -10,6 +10,7 @@ */ #include +#include #include #include #include @@ -20,12 +21,14 @@ #include "CommonFramework/GlobalAutoPaths.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Logging/Logger.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_BattleMenuReader.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Location.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_StoryLanguage.h" #include "PokemonBDSP_AutoStory_BattleMoves.h" #include "PokemonBDSP_AutoStory_Center.h" +#include "PokemonBDSP_AutoStory_Events.h" #include "PokemonBDSP_AutoStory_IntroProbe.h" #include "PokemonBDSP_AutoStory_IntroSteps.h" #include "PokemonBDSP_AutoStory_LitDoorway.h" @@ -441,6 +444,54 @@ UnitTestResult test_school_lamp(Logger& logger){ // no name read, Piplup's Pound at 35 PP and Growl at 22 PP, and the old // "newest move that is not a status move" fallback used Growl until the // training gave up after 25 turns. +// A step along the row below the clown: a fade or a dialogue left the row +// and fails the talk (00.05c, 2026-11-11: the step's fade was ignored and +// the search went on in the Poketch Company's lobby); a step that moved +// nothing counts no tile. +UnitTestResult test_wander_row_step(Logger&){ + struct Case{ std::string_view name; WalkStop stop; size_t moved; int east; std::optional expected; }; + const Case cases[] = { + {"east step moved", WalkStop::LIMIT, 1, 1, 1}, + {"west step moved", WalkStop::LIMIT, 1, -1, -1}, + {"west step blocked by him", WalkStop::LIMIT, 0, -1, 0}, + {"east step into a wall", WalkStop::BLOCKED, 0, 1, 0}, + {"east step through a door", WalkStop::TRANSITION, 0, 1, std::nullopt}, + {"west step into a dialogue", WalkStop::DIALOG, 0, -1, std::nullopt}, + }; + for (const Case& c : cases){ + WalkResult result{}; + result.stop = c.stop; + result.moved_chunks = c.moved; + if (wander_row_step(result, c.east) != c.expected){ + return std::format("{}: wrong step.", c.name); + } + } + return true; +} + +// 00.05b's Poketch Company clown (home (15, 18)): the row below him asks +// north from (14..16, 19); from a row low, (13, 20) faces the Company's +// sign (13, 19), whose text came first on the console (lab-B 2026-11-11: +// "answered" in round 5, and the president gave no Poketch). Such a tile +// is skipped; his own home and open tiles are not. +UnitTestResult test_asks_someone_else(Logger&){ + const Pokemon::MapData& city = story_map("JubilifeCity"); + const Pokemon::TilePos home{15, 18}; + struct Case{ std::string_view name; Pokemon::TilePos stand; bool expected; }; + const Case cases[] = { + {"below his home", {15, 19}, false}, + {"a tile west, open north", {14, 19}, false}, + {"a tile east, open north", {16, 19}, false}, + {"a row low, facing the sign", {13, 20}, true}, + }; + for (const Case& c : cases){ + if (asks_someone_else(city, c.stand, home) != c.expected){ + return std::format("{}: wrong answer.", c.name); + } + } + return true; +} + UnitTestResult test_choose_move(Logger&){ struct Case{ std::string_view name; std::vector slots; size_t best; }; const Case cases[] = { @@ -590,6 +641,14 @@ const AutoStoryActionsCase AUTO_STORY_ACTIONS_CASES[] = { .input = {"battle moves: the pick from names and PP", test_choose_move}, .expectation = {}, }, + { + .input = {"wanderer talk: a step along the row leaves it only by a fade or a dialogue", test_wander_row_step}, + .expectation = {}, + }, + { + .input = {"wanderer talk: no ask from a tile that faces a sign (00.05b, the Poketch Company's sign first)", test_asks_someone_else}, + .expectation = {}, + }, { .input = {"battle moves: move menu screenshots in each language", test_move_menu_screenshots}, .expectation = {}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h index a39c9738d9..64d5acd2fa 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h @@ -9,7 +9,8 @@ * Dawn's catching tutorial and the catch); the rest do what the shared * steps cannot, as they ran on the console: the Poke Mart lady's Potions * and the stairs into Jubilife (00.04c, 00.04d), a clown who wanders - * (00.05b), the Gym's tries from the Pokemon Center (01.04) and Rock Smash + * (00.05b and 00.05c), the Poketch check (00.05c, 01.01), the Gym's + * tries from the Pokemon Center (01.04) and Rock Smash * (01.09). Each fails by throwing, with a screenshot; the executor turns * that into a failed step. * @@ -24,8 +25,12 @@ #include #include +#include #include +#include +#include "Pokemon/Navigation/Pokemon_MapData.h" #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryExecutor.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -57,6 +62,25 @@ void add_oreburgh_events(StoryEvents& events); // Populates Route 204-area story event handlers. void add_route204_events(StoryEvents& events); +// A one-tile step along the row below a wanderer (00.05b's clowns), `east` +// +1 or -1, from its walk: the tiles it moved east (0 when he or a wall +// blocked it), or none when it left the row: through a door, into a +// dialogue. 00.05c (2026-11-11): a step's fade went unread and the search +// went on indoors, so the next checkpoint saved in the Poketch Company. +std::optional wander_row_step(const WalkResult& result, int east); +// Whether asking north from `stand` on `map` would talk to a sign or to +// someone who stands still, not the wanderer whose home is +// `wanderer_home` (00.05b, lab-B 2026-11-11: the Poketch Company clown's +// talk was "answered" in round 5 by another line). +bool asks_someone_else(const Pokemon::MapData& map, Pokemon::TilePos stand, Pokemon::TilePos wanderer_home); +// The box the Mart clown wanders, round (55, 33): PokemonSimulation's +// data/games/bdsp/maps/jubilife_city.json (decomp range 1). The story map +// leaves him out of its wanderers (the decomp hides him behind a flag). +Pokemon::TileBox jubilife_mart_clown_box(); +// The tiles 00.05c may start on: against the Poketch Company's sign +// (00.05b's end), and on the street east (its own end, 01.01's start). +std::pair jubilife_start_tiles(); + } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp index 86413db20a..858b79e2ee 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events_Jubilife.cpp @@ -1,9 +1,9 @@ -/* BDSP AutoStory - Events: Jubilife City (00.05b) +/* BDSP AutoStory - Events: Jubilife City (00.05b, 00.05c, 01.01) * * From: https://github.com/PokemonAutomation/ * - * The Jubilife beat of 00.05b the story table cannot plan: the talk to a - * wandering clown. + * The Jubilife beats the story table cannot plan: the talk to a wandering + * clown, the check that the Poketch came, and where 00.05c starts. * */ @@ -12,8 +12,17 @@ #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_SelectionArrow.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/Detect/PokemonBDSP_AutoStory_OverworldDetector.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTalk.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Walk.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkDpad.h" @@ -21,6 +30,7 @@ #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Walks.h" #include "PokemonBDSP_AutoStory_WildBattle.h" #include "PokemonBDSP_AutoStory_Events.h" +#include "PokemonBDSP_AutoStory_WanderWait.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -28,6 +38,7 @@ namespace PokemonBDSP{ using namespace std::chrono_literals; using Pokemon::Direction; +using Pokemon::TilePos; namespace{ @@ -36,8 +47,7 @@ namespace{ // row (the clowns by the Mart and the Poketch Company, WANDER_AROUND with // x range 1). Waiting under home alone missed him for a minute (r66: he // stood a tile east), so walk the row below his range, a whole D-pad tile -// at a time, asking north from each tile. His question's answer is Yes, so -// A answers and takes the coupon; then back under his home tile. +// at a time, asking north from each tile. bool ask_north(VideoStream& stream, ProControllerContext& context){ route_turn(stream, context, Direction::NORTH); for (size_t ask = 0; ask < 2; ask++){ @@ -50,14 +60,72 @@ bool ask_north(VideoStream& stream, ProControllerContext& context){ } return false; } -// One tile along the row, east (+1) or west (-1). -void step_along(VideoStream& stream, ProControllerContext& context, int east, const std::string& label){ +// A clown's talk is his question, then its Yes/No box: any dialog is not +// (00.05b, lab-B 2026-11-11: the Poketch Company clown was "answered" in +// round 5 by another line, and the president gave no Poketch). Press A +// until the box's cursor shows, then A for Yes and through the coupon. +// False when the talk ends with no box: someone or something else, or a +// clown who has given his coupon already. +bool answer_coupon_question(VideoStream& stream, ProControllerContext& context, const std::string& label){ + static const ImageFloatBox YES_NO_ARROW_BOX{0.700, 0.620, 0.070, 0.120}; + SelectionArrowFinder yes_no(stream.overlay(), YES_NO_ARROW_BOX, COLOR_GREEN); + for (size_t press = 0; press < 6; press++){ + context.wait_for(1200ms); + context.wait_for_all_requests(); + const VideoSnapshot screen = stream.video().snapshot(); + if (screen && yes_no.detect(*screen.frame)){ + stream.log("[Talk] " + label + ": the coupon question; Yes."); + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + finish_dialogue(stream, context, BUTTON_A, label); + return true; + } + if (!dialogue_opens(stream, context, 500ms)){ + stream.log("[Talk] " + label + ": the talk ended with no Yes/No box.", COLOR_ORANGE); + return false; + } + pbf_press_button(context, BUTTON_A, 80ms, 0ms); + } + finish_dialogue(stream, context, BUTTON_B, label); + stream.log("[Talk] " + label + ": no Yes/No box in 6 presses.", COLOR_ORANGE); + return false; +} +// One tile along the row, east (+1) or west (-1). Returns the tiles moved +// east; fails the step when the walk left the row (wander_row_step()). +int step_along(VideoStream& stream, ProControllerContext& context, int east, const std::string& label){ route_turn(stream, context, east > 0 ? Direction::EAST : Direction::WEST); - walk_tiles_dpad(stream, context, run_from_wild_battle, {east > 0 ? 1.0 : -1.0, 0}, 1, label); + const WalkResult result = walk_tiles_dpad(stream, context, run_from_wild_battle, {east > 0 ? 1.0 : -1.0, 0}, 1, label); + const std::optional moved = wander_row_step(result, east); + if (!moved){ + fail_step(stream, std::format("{}: {} instead of a step along the row.", label, walk_stop_name(result.stop))); + } + return *moved; } +// Walks back below his home and faces north. +void back_below_home(VideoStream& stream, ProControllerContext& context, int at, const std::string& name){ + for (size_t tries = 0; at != 0 && tries < 4; tries++){ + at += step_along(stream, context, at > 0 ? -1 : 1, "Back below " + name + "'s home"); + } + if (at != 0){ + fail_step(stream, std::format("{}: still {} tiles east of his home after 4 steps back.", name, at)); + } + route_turn(stream, context, Direction::NORTH); +} +// The talk to a wanderer from the step's declared pose, below his home. +// With "again" (00.05c), a talk with no question counts too: he may have +// given his coupon before, and the Poketch check after the president +// catches a coupon that is still missing. Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep& step){ VideoStream& stream = executor.stream(); ProControllerContext& context = executor.context(); + const bool again = Pokemon::story_arg(step.args, "again"); + std::optional> home; + if (step.pose_after){ + const Pokemon::Pose below = Pokemon::pose_of(*step.pose_after); + const std::vector tiles = Pokemon::tiles_of(below); + if (!tiles.empty()){ + home.emplace(below.map, tiles[0]); + } + } const std::string label = "Along the row below " + step.name; // Home, east, west, west, east: each move one tile on the D-pad. const int moves[] = {0, 1, -1, -1, 1}; @@ -65,29 +133,179 @@ Pokemon::Outcome talk_to_wanderer(StoryExecutor& executor, Pokemon::RunState&, c for (size_t round = 0; round < 6; round++){ for (int move : moves){ if (move != 0){ - step_along(stream, context, move, label); - at += move; + at += step_along(stream, context, move, label); + } + if (home && asks_someone_else(story_map(home->first), {home->second.x + at, home->second.y}, home->second.next(Direction::NORTH))){ + stream.log(std::format("[Talk] {}: not asking from {} tiles east of home: a sign or someone else is north.", step.name, at)); + continue; } if (!ask_north(stream, context)){ continue; } - stream.log(std::format("[Talk] {}: answered in round {}, {} tiles east of home.", step.name, round + 1, at)); - finish_dialogue(stream, context, BUTTON_A, step.name); - for (; at != 0; at += at > 0 ? -1 : 1){ - step_along(stream, context, at > 0 ? -1 : 1, "Back below " + step.name + "'s home"); + const bool coupon = answer_coupon_question(stream, context, step.name); + if (!coupon && !again){ + continue; } - route_turn(stream, context, Direction::NORTH); + stream.log(std::format("[Talk] {}: {} in round {}, {} tiles east of home.", + step.name, coupon ? "the coupon" : "talked, no question (his coupon given before)", round + 1, at)); + back_below_home(stream, context, at, step.name); return Pokemon::outcome_ok(); } } - fail_step(stream, step.name + ": no answer from any tile below his range."); + fail_step(stream, step.name + ": no coupon question from any tile below his range."); +} + +// The console's side of a wait beside a wanderer: a D-pad tap a step, +// counted, and A; the talk counts when his Yes/No box opens (or, with +// "again", when any talk opens). +class ConsoleWanderWait : public WanderWaitBody{ +public: + ConsoleWanderWait(VideoStream& stream, ProControllerContext& context, std::string name, bool again) + : m_stream(stream) + , m_context(context) + , m_name(std::move(name)) + , m_again(again) + {} + virtual bool step(Direction direction) override{ + const std::string label = "Waiting for " + m_name; + route_turn(m_stream, m_context, direction); + const WalkResult result = walk_tiles_dpad(m_stream, m_context, run_from_wild_battle, route_stick(direction), 1, label); + const std::optional moved = wander_row_step(result, 1); + if (!moved){ + fail_step(m_stream, std::format("{}: {} instead of a step along the column.", label, walk_stop_name(result.stop))); + } + return *moved != 0; + } + virtual void face(Direction direction) override{ + route_turn(m_stream, m_context, direction); + } + virtual bool ask() override{ + pbf_press_button(m_context, BUTTON_A, 80ms, 0ms); + m_context.wait_for_all_requests(); + ShortDialogWatcher dialog(COLOR_YELLOW); + if (wait_until(m_stream, m_context, 1500ms, {{dialog}}) != 0){ + return false; + } + return answer_coupon_question(m_stream, m_context, m_name) || m_again; + } + virtual void wait(Milliseconds time) override{ + m_context.wait_for(time); + } + +private: + VideoStream& m_stream; + ProControllerContext& m_context; + std::string m_name; + bool m_again; +}; +// The talk to a wanderer by waiting for him on the step's "stand" tiles, +// from the tile the step before left us on (in their column). It ends on +// its declared tile, against a wall the declared way and one at the +// column's back (away from his box): both taps must not move. +Pokemon::Outcome wait_for_wanderer(StoryExecutor& executor, Pokemon::RunState& state, const Pokemon::StoryStep& step){ + VideoStream& stream = executor.stream(); + const Pokemon::GridPose& stand = Pokemon::story_arg(step.args, "stand"); + const std::vector start = Pokemon::tiles_of(state.pose); + if (!step.pose_after || start.size() != 1 || stand.tiles.empty() || !stand.facing){ + fail_step(stream, step.name + ": needs one start tile, stand tiles and their facing, and a declared end."); + } + const Pokemon::Pose exit = Pokemon::pose_of(*step.pose_after); + const std::vector exit_tiles = Pokemon::tiles_of(exit); + const std::optional exit_wall = Pokemon::facing_of(exit); + if (exit_tiles.size() != 1 || !exit_wall){ + fail_step(stream, step.name + ": its declared end needs one tile and a facing."); + } + // The column's back: the way away from his box. + const Direction back = Pokemon::ALL_DIRECTIONS[((size_t)*stand.facing + 2) % 4]; + const WanderWaitPlan plan{.stands = stand.tiles, .facing = *stand.facing, .exit = exit_tiles[0], .exit_walls = {*exit_wall, back}}; + ConsoleWanderWait body(stream, executor.context(), step.name, Pokemon::story_arg(step.args, "again")); + const WanderWaitResult result = wait_beside_wanderer(body, start[0], plan); + switch (result.end){ + case WanderWaitEnd::TALKED: + stream.log(std::format("[Talk] {}: talked from {}; now on {}.", step.name, Pokemon::to_string(result.talked), Pokemon::to_string(result.at))); + return Pokemon::outcome_ok(); + case WanderWaitEnd::NO_TALK: + fail_step(stream, std::format("{}: no talk from any stand tile; on {}.", step.name, Pokemon::to_string(result.at))); + case WanderWaitEnd::STUCK: + fail_step(stream, std::format("{}: a step along the column stayed blocked at {}.", step.name, Pokemon::to_string(result.at))); + case WanderWaitEnd::LOST: + fail_step(stream, std::format("{}: a step from {} moved to {}: not on the column.", step.name, Pokemon::to_string(exit_tiles[0]), Pokemon::to_string(result.at))); + } + fail_step(stream, step.name + ": unknown wait end."); +} + +// 00.05c's end and 01.01's start: the Poketch shows on the screen's right +// (R toggles it). Without it, Jubilife's east-exit guard (the coord event +// on (60, 21..24)) asks about the Poketch campaign and turns us back. +void check_poketch(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + if (!ensure_poketch_visible(stream, context)){ + fail_step(stream, "No Poketch: the president gave none (a clown's coupon is missing?). " + "Jubilife's east-exit guard stops anyone without one: rerun 00.05c."); + } + stream.log("[Talk] The Poketch is on the screen."); +} + +// 00.05c starts against the Poketch Company's sign (14, 19) facing west +// (00.05b's end) or on the street east, (58, 22) facing east (its own end +// and 01.01's start, when a run gave no Poketch). A step west tells them +// apart: the sign blocks it, the street does not. +Pokemon::Outcome jubilife_start_probe(StoryExecutor& executor, Pokemon::RunState&, const Pokemon::StoryStep&){ + VideoStream& stream = executor.stream(); + ProControllerContext& context = executor.context(); + route_turn(stream, context, Direction::WEST); + const WalkResult result = walk_tiles_dpad(stream, context, run_from_wild_battle, {-1.0, 0}, 1, "00.05c start probe"); + const std::optional moved = wander_row_step(result, -1); + if (!moved){ + fail_step(stream, std::format("00.05c start probe: {} instead of a step west.", walk_stop_name(result.stop))); + } + const TilePos at = *moved == 0 ? jubilife_start_tiles().first : jubilife_start_tiles().second.next(Direction::WEST); + stream.log(std::format("[Talk] 00.05c starts {}: on {}.", *moved == 0 ? "at the Poketch Company's sign" : "on the street east", Pokemon::to_string(at))); + return Pokemon::outcome_ok(Pokemon::tile_pose("JubilifeCity", {at}, Direction::WEST)); } } // namespace +std::optional wander_row_step(const WalkResult& result, int east){ + switch (result.stop){ + case WalkStop::TRANSITION: + case WalkStop::DIALOG: + return std::nullopt; + default: + return result.moved_chunks > 0 ? east : 0; + } +} + +bool asks_someone_else(const Pokemon::MapData& map, TilePos stand, TilePos wanderer_home){ + const TilePos north = stand.next(Direction::NORTH); + if (north == wanderer_home || !map.tiles.contains(north)){ + return false; + } + if (map.tiles.at(north) == Pokemon::TileKind::SIGN){ + return true; + } + for (const Pokemon::MapObject& object : map.objects){ + if (!object.wander && object.x == north.x && object.y == north.y){ + return true; + } + } + return false; +} + +Pokemon::TileBox jubilife_mart_clown_box(){ + return {.x0 = 54, .y0 = 32, .x1 = 56, .y1 = 34}; +} + +std::pair jubilife_start_tiles(){ + return {{14, 19}, {58, 22}}; +} + void add_jubilife_events(StoryEvents& events){ events.emplace("talk_to_wanderer", talk_to_wanderer); + events.emplace("wait_for_wanderer", wait_for_wanderer); + events.emplace("check_poketch", console_event(check_poketch)); + events.emplace("jubilife_start_probe", jubilife_start_probe); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp new file mode 100644 index 0000000000..bd05488eeb --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp @@ -0,0 +1,98 @@ +/* BDSP AutoStory - Wait beside a wanderer + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonBDSP_AutoStory_WanderWait.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::TilePos; + + +namespace{ + +// Walks the column from `at` to `to`, a tile a step. A blocked step asks +// that way while `talked` is false, and ends the walk if the talk counts. +// False if a step stayed blocked for the plan's asks, or `to` is off the +// column. +bool walk_column(WanderWaitBody& body, TilePos& at, TilePos to, const WanderWaitPlan& plan, bool* talked){ + if (at.x != to.x){ + return false; + } + while (at != to){ + const Direction direction = to.y < at.y ? Direction::NORTH : Direction::SOUTH; + size_t tries = 0; + while (!body.step(direction)){ + if (talked != nullptr && !*talked){ + body.face(direction); + if (body.ask()){ + *talked = true; + return true; + } + } + if (++tries >= plan.asks){ + return false; + } + body.wait(plan.blocked_wait); + } + at = at.next(direction); + } + return true; +} + +// Asks from where the player stands, facing the plan's way. +bool ask_from_stand(WanderWaitBody& body, const WanderWaitPlan& plan){ + body.face(plan.facing); + for (size_t ask = 0; ask < plan.asks; ask++){ + if (body.ask()){ + return true; + } + body.wait(plan.between_asks); + } + return false; +} + +} // namespace + + +WanderWaitResult wait_beside_wanderer(WanderWaitBody& body, TilePos at, const WanderWaitPlan& plan){ + bool talked = false; + TilePos talked_at = at; + for (size_t round = 0; round < plan.rounds && !talked; round++){ + for (const TilePos& stand : plan.stands){ + if (!walk_column(body, at, stand, plan, &talked)){ + return {.end = WanderWaitEnd::STUCK, .at = at, .talked = at}; + } + if (!talked){ + talked = ask_from_stand(body, plan); + } + if (talked){ + talked_at = at; + break; + } + } + } + if (!talked){ + return {.end = WanderWaitEnd::NO_TALK, .at = at, .talked = at}; + } + if (!walk_column(body, at, plan.exit, plan, nullptr)){ + return {.end = WanderWaitEnd::STUCK, .at = at, .talked = talked_at}; + } + for (Direction wall : plan.exit_walls){ + if (body.step(wall)){ + return {.end = WanderWaitEnd::LOST, .at = at.next(wall), .talked = talked_at}; + } + } + return {.end = WanderWaitEnd::TALKED, .at = at, .talked = talked_at}; +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h new file mode 100644 index 0000000000..5cd7813aa1 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h @@ -0,0 +1,82 @@ +/* BDSP AutoStory - Wait beside a wanderer + * + * From: https://github.com/PokemonAutomation/ + * + * A talk to someone who wanders, by waiting for him rather than chasing + * him: stand on a tile beside his box, face it, and ask each time he may + * have come level, then try the next tile. The Mart clown (00.05b, + * 00.05c) is waited for on column 56, east of his box. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_H +#define PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "Pokemon/Navigation/Pokemon_Grid.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Where and how long to wait. The stands and the exit are on one column. +struct WanderWaitPlan{ + // The tiles to wait on, in order; the list is walked `rounds` times. + std::vector stands; + // The way to face from a stand: toward his box. + Pokemon::Direction facing = Pokemon::Direction::WEST; + // Where the wait ends after the talk. A step from it toward each of + // `exit_walls` must not move: the walls there prove the tile. + Pokemon::TilePos exit; + std::vector exit_walls; + // Asks from each stand before the next one. + size_t asks = 12; + // The pause after an ask that found nobody. + Milliseconds between_asks = Milliseconds(500); + // The wait for someone in the column to step out of it: a wanderer + // tries a step every 2 s or so, and may stay. + Milliseconds blocked_wait = Milliseconds(2000); + size_t rounds = 2; +}; + +// What the wait does in the game: the console's D-pad and A, or the +// simulation's. +class WanderWaitBody{ +public: + virtual ~WanderWaitBody() = default; + // One whole tile toward `direction`. False if something stopped it. + virtual bool step(Pokemon::Direction direction) = 0; + virtual void face(Pokemon::Direction direction) = 0; + // A toward the faced tile. True if the talk counted: his question. + virtual bool ask() = 0; + virtual void wait(Milliseconds time) = 0; +}; + +// How a wait ended. +enum class WanderWaitEnd{ + TALKED, // the talk counted; the player is on the plan's exit + NO_TALK, // every ask of every round found nobody to talk to + STUCK, // a step along the column stayed blocked + LOST, // an exit wall was not there: off the column +}; +// How a wait ended, and where. +struct WanderWaitResult{ + WanderWaitEnd end; + Pokemon::TilePos at; // where the player is, as counted + Pokemon::TilePos talked; // where the talk counted, for TALKED +}; + +// Waits beside the wanderer from `at`, on the plan's column. A step along +// the column that something stops is someone in the column: the wait asks +// that way too, then waits and steps again. +WanderWaitResult wait_beside_wanderer(WanderWaitBody& body, Pokemon::TilePos at, const WanderWaitPlan& plan); + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp index fed0c55f4c..3c6e96be0e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.cpp @@ -38,6 +38,12 @@ RobustPlanCosts town_plan_costs(){ costs.exact_open_tiles = costs.max_open_tiles; costs.per_open_tile = 1; costs.leg_not_at_wall = 4; + // A detour of a few tiles round a zone where someone wanders beats + // crossing it: at 3, 00.05b's walk to the Mart clown ran east along + // row 34 through the column a boy wanders (51, 33..35), and he stopped + // it 3 tiles short of its wall (lab-B 2026-11-11 21:00); row 36, below + // his zone, is 9 dearer. + costs.per_wander_tile = 15; return costs; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp index 7ea8b80c71..7f3bc7ef41 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_RoutePlanner.cpp @@ -7,10 +7,9 @@ #include #include #include -#include -#include #include "Common/Cpp/Exceptions.h" #include "Pokemon/Navigation/Pokemon_LegPlanner.h" +#include "Pokemon/Navigation/Pokemon_RobustLegPlanner.h" #include "PokemonBDSP_AutoStory_RobustRoute.h" #include "PokemonBDSP_AutoStory_RoutePlanner.h" #include "PokemonBDSP_AutoStory_TrainerSight.h" @@ -218,296 +217,78 @@ std::string to_string(const PlannedLeg& leg){ namespace{ -// Where `from` ends up after `tiles` steps in `direction`, stopping early at -// anything that stops the player, and how many tall-grass tiles it enters. -// Nothing if a step would leave the maps or enter a door: the plan cannot -// tell what happens then. -struct Stepped{ - TilePos end; - int grass = 0; - int wander = 0; - // Two tiles in a row where someone wanders, the start among them: the - // walk runs along their zone, and plan_robust_route() does not use it. - bool along_wander = false; -}; -std::optional step_tiles(const StoryWorld& world, TilePos from, Direction direction, int tiles){ - Stepped stepped; - int travelled = 0; - bool in_wander = wandering_hazard(world, from); - while (travelled < tiles){ - const std::optional next = step(world, from, direction); - if (!next){ - if (!at_wall(world, from, direction)){ - return std::nullopt; - } - break; - } - travelled += (int)distance(*next, from); - if (tall_grass(world, *next)){ - stepped.grass++; - } - const bool next_wander = wandering_hazard(world, *next); - if (next_wander){ - stepped.wander++; - stepped.along_wander |= in_wander; - } - in_wander = next_wander; - from = *next; - } - stepped.end = from; - return stepped; -} - -// step_tiles() for each count from 1 to `most`, in one walk: [n - 1] is -// step_tiles(world, from, direction, n). -std::vector> step_prefixes(const StoryWorld& world, TilePos from, Direction direction, int most){ - std::vector> out; - Stepped stepped; - int travelled = 0; - bool in_wander = wandering_hazard(world, from); - while ((int)out.size() < most){ - const std::optional next = step(world, from, direction); - if (!next){ - stepped.end = from; - const std::optional last = at_wall(world, from, direction) ? std::optional(stepped) : std::nullopt; - out.resize((size_t)most, last); - break; - } - travelled += (int)distance(*next, from); - stepped.grass += tall_grass(world, *next) ? 1 : 0; - const bool next_wander = wandering_hazard(world, *next); - if (next_wander){ - stepped.wander++; - stepped.along_wander |= in_wander; - } - in_wander = next_wander; - from = *next; - stepped.end = from; - while ((int)out.size() < std::min(travelled, most)){ - out.push_back(stepped); - } - } - return out; -} - -using Spread = std::vector; - -bool spread_less(const TilePos& a, const TilePos& b){ - return a.y != b.y ? a.y < b.y : a.x < b.x; -} -void normalize(Spread& spread){ - std::sort(spread.begin(), spread.end(), spread_less); - spread.erase(std::unique(spread.begin(), spread.end()), spread.end()); -} -struct SpreadLess{ - bool operator()(const Spread& a, const Spread& b) const{ - return std::lexicographical_compare(a.begin(), a.end(), b.begin(), b.end(), spread_less); - } -}; - -// A leg out of a spread: where every tile of it ends, and its cost. -struct Expansion{ - long long cost = 0; - Spread next; - TileLeg leg; - // A held leg that may end somewhere unsafe: not to be used, though a - // longer one may be. - bool unsafe = false; -}; - -// To the wall: every position walks until stopped. Nothing unless each is -// held at a wall, and one moves. -std::optional to_wall_leg(const StoryWorld& world, const Spread& spread, Direction direction, const RobustPlanCosts& costs){ - Expansion expansion; - size_t longest = 0; - int grass = 0; - int wander = 0; - for (const TilePos& pos : spread){ - const WallHit hit = slide_to_wall(world, pos, direction); - if (!hit.anchored){ - return std::nullopt; - } - if (const std::optional stepped = step_tiles(world, pos, direction, (int)hit.tiles)){ - if (stepped->along_wander){ - return std::nullopt; - } - grass = std::max(grass, stepped->grass); - wander = std::max(wander, stepped->wander); - } - longest = std::max(longest, hit.tiles); - expansion.next.push_back(hit.stop); - } - if (longest == 0){ - return std::nullopt; - } - expansion.cost = (long long)costs.per_leg + (long long)costs.per_tile * longest - + (long long)costs.per_grass_tile * grass + (long long)costs.per_wander_tile * wander; - expansion.leg = TileLeg{direction, longest, true, false}; - return expansion; -} - -// Whether a held leg's possible ends, `ends` in order from the shortest, -// meet nothing past the shortest that a tap would not: no tall grass, no -// wanderer's zone, no ledge hop. -bool held_ends_safe(const StoryWorld& world, const std::vector& ends){ - for (size_t i = 1; i < ends.size(); i++){ - if (distance(ends[i - 1], ends[i]) > 1 || tall_grass(world, ends[i]) || wandering_hazard(world, ends[i])){ - return false; - } - } - return true; -} - -// Open: about `tiles` tiles, give or take the error. Nothing if any -// possible end leaves the maps or enters a door, or a held leg's may end -// somewhere unsafe (held_ends_safe()). -std::optional open_leg(const StoryWorld& world, const Spread& spread, Direction direction, int tiles, const RobustPlanCosts& costs){ - Expansion expansion; - int grass = 0; - int wander = 0; - const int error = tiles <= costs.exact_open_tiles ? 0 : (int)open_hold_error((size_t)tiles); - const bool held = costs.hold_open_legs && error > 0; - for (const TilePos& pos : spread){ - std::vector ends; - const std::vector> prefixes = step_prefixes(world, pos, direction, tiles + error); - for (int n = std::max(1, tiles - error); n <= tiles + error; n++){ - const std::optional& stepped = prefixes[(size_t)n - 1]; - if (!stepped || stepped->along_wander){ - return std::nullopt; - } - grass = std::max(grass, stepped->grass); - wander = std::max(wander, stepped->wander); - ends.push_back(stepped->end); - } - if (held && !held_ends_safe(world, ends)){ - expansion.unsafe = true; +// The world's step rules for the shared robust planner. A ledge hop is one +// step that counts two tiles. +class RobustWorldModel{ +public: + using State = TilePos; + struct StateLess{ + bool operator()(const TilePos& a, const TilePos& b) const{ + return a.y != b.y ? a.y < b.y : a.x < b.x; } - expansion.next.insert(expansion.next.end(), ends.begin(), ends.end()); - } - const int per_open_tile = held ? 0 : costs.per_open_tile; - expansion.cost = (long long)costs.per_leg + costs.leg_not_at_wall + - (long long)(costs.per_tile + per_open_tile) * tiles - + (long long)(costs.per_grass_tile + costs.per_open_grass_tile) * grass + (long long)costs.per_wander_tile * wander; - expansion.leg = TileLeg{.direction = direction, .tiles = (size_t)tiles, .ends_at_wall = false, .held = held}; - return expansion; -} + }; -// Dijkstra over sets of tiles the player may stand on. -class RobustSearch{ -public: - RobustSearch(const StoryWorld& world, const RobustPlanCosts& costs) + explicit RobustWorldModel(const StoryWorld& world) : m_world(world) - , m_costs(costs) {} - std::optional> run(Spread start, const std::function& goal){ - normalize(start); - m_start = start; - m_nodes[start] = Node{0, {}, {}}; - m_queue.emplace(0, start); - size_t searched = 0; - while (!m_queue.empty()){ - const auto [cost, spread] = m_queue.top(); - m_queue.pop(); - Node& node = m_nodes[spread]; - if (node.done || node.cost != cost){ - continue; - } - node.done = true; - if (++searched > m_costs.max_searched){ - return std::nullopt; - } - if (std::all_of(spread.begin(), spread.end(), goal)){ - return legs_to(spread); - } - expand(spread, cost); - } - return std::nullopt; + std::optional step(const State& pos, Direction direction) const{ + return PokemonBDSP::step(m_world, pos, direction); } - -private: - struct Node{ - long long cost = 0; - Spread parent; - PlannedLeg leg; - bool done = false; - }; - using Entry = std::pair; - struct EntryGreater{ - bool operator()(const Entry& a, const Entry& b) const{ return a.first > b.first; } - }; - - void expand(const Spread& spread, long long cost){ - for (Direction direction : Pokemon::ALL_DIRECTIONS){ - if (std::optional wall = to_wall_leg(m_world, spread, direction, m_costs)){ - relax(spread, cost, std::move(*wall)); - } - // 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++){ - std::optional open = open_leg(m_world, spread, direction, tiles, m_costs); - if (!open){ - break; - } - if (!open->unsafe){ - relax(spread, cost, std::move(*open)); - } - } - } + size_t step_tiles(const State& from, const State& to) const{ + return distance(from, to); } - - // Only the start may be wider than costs.max_spread: every leg must - // bring the player within it. - void relax(const Spread& spread, long long cost, Expansion expansion){ - normalize(expansion.next); - if (expansion.next.size() > m_costs.max_spread || expansion.next == spread){ - return; - } - if (spread != m_start){ - const TileLeg& prev = m_nodes.at(spread).leg.leg; - if (expansion.leg.direction == prev.direction && !prev.ends_at_wall && !prev.held && !expansion.leg.held){ - expansion.cost -= m_costs.per_leg; - } - } - const long long total = cost + expansion.cost; - auto iter = m_nodes.find(expansion.next); - if (iter != m_nodes.end() && iter->second.cost <= total){ - return; - } - m_nodes[expansion.next] = Node{total, spread, PlannedLeg{expansion.leg, expansion.next}}; - m_queue.emplace(total, std::move(expansion.next)); + bool held_at(const State& pos, Direction direction) const{ + return at_wall(m_world, pos, direction); } - - std::vector legs_to(const Spread& end) const{ - std::vector legs; - for (Spread at = end; at != m_start; ){ - const Node& step = m_nodes.at(at); - legs.push_back(step.leg); - at = step.parent; - } - std::reverse(legs.begin(), legs.end()); - std::vector consolidated; - for (const PlannedLeg& planned : legs){ - if (!consolidated.empty() && - consolidated.back().leg.direction == planned.leg.direction && - !consolidated.back().leg.ends_at_wall && !consolidated.back().leg.held && !planned.leg.held - ){ - consolidated.back().leg.tiles += planned.leg.tiles; - consolidated.back().leg.ends_at_wall = planned.leg.ends_at_wall; - consolidated.back().after = planned.after; - }else{ - consolidated.push_back(planned); - } - } - return consolidated; + bool wild(const State& pos) const{ + return tall_grass(m_world, pos); + } + bool wander(const State& pos) const{ + return wandering_hazard(m_world, pos); } +private: const StoryWorld& m_world; - const RobustPlanCosts& m_costs; - Spread m_start; - std::map m_nodes; - std::priority_queue, EntryGreater> m_queue; }; +// Names every field of Pokemon::RobustLegCosts, in order, so it stops +// compiling when the shared costs gain or lose one: add the new field to +// robust_leg_costs() below (and to RobustPlanCosts if BDSP sets it), so it +// can't silently keep the shared default. +constexpr bool robust_leg_costs_fields_copied(){ + [[maybe_unused]] const auto& [ + per_tile, per_wild_tile, per_wander_tile, per_leg, leg_not_at_wall, + open_error, open_error_per, exact_open_tiles, per_open_tile, + hold_open_legs, per_open_wild_tile, + max_open_tiles, max_spread, max_searched + ] = Pokemon::RobustLegCosts{}; + return true; +} +static_assert(robust_leg_costs_fields_copied()); + +// BDSP's costs as the shared planner's, field by field. per_wander_tile is +// BDSP's own (town_plan_costs() may raise it), never the shared default. +// An open leg's error is open_hold_error(), the same at every length. +Pokemon::RobustLegCosts robust_leg_costs(const RobustPlanCosts& costs){ + Pokemon::RobustLegCosts ret; + ret.per_tile = costs.per_tile; + ret.per_wild_tile = costs.per_grass_tile; + ret.per_wander_tile = costs.per_wander_tile; + ret.per_leg = costs.per_leg; + ret.leg_not_at_wall = costs.leg_not_at_wall; + ret.open_error = (int)open_hold_error((size_t)costs.max_open_tiles); + ret.open_error_per = 0; + ret.exact_open_tiles = costs.exact_open_tiles; + ret.per_open_tile = costs.per_open_tile; + ret.hold_open_legs = costs.hold_open_legs; + ret.per_open_wild_tile = costs.per_open_grass_tile; + ret.max_open_tiles = costs.max_open_tiles; + ret.max_spread = costs.max_spread; + ret.max_searched = costs.max_searched; + return ret; +} + } // namespace size_t open_hold_error(size_t){ @@ -533,7 +314,18 @@ std::optional> plan_robust_route( throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Route starts must be standable: " + Pokemon::to_string(pos) + "."); } } - return RobustSearch(world, costs).run(from, goal); + const auto legs = Pokemon::plan_robust_legs(RobustWorldModel(world), from, goal, robust_leg_costs(costs)); + if (!legs){ + return std::nullopt; + } + std::vector ret; + for (const Pokemon::RobustLeg& leg : *legs){ + ret.push_back(PlannedLeg{ + .leg = {.direction = leg.direction, .tiles = leg.tiles, .ends_at_wall = leg.to_wall, .held = leg.held}, + .after = leg.after, + }); + } + return ret; } long long robust_route_cost( @@ -541,31 +333,17 @@ long long robust_route_cost( const std::vector& from, const std::vector& legs, const RobustPlanCosts& costs ){ - long long total = 0; - Spread spread = from; - normalize(spread); - const TileLeg* previous = nullptr; + std::vector> robust; for (const PlannedLeg& planned : legs){ - const TileLeg& leg = planned.leg; - const std::optional expansion = leg.ends_at_wall - ? to_wall_leg(world, spread, leg.direction, costs) - : open_leg(world, spread, leg.direction, (int)leg.tiles, costs); - long long cost = (long long)costs.per_leg + (long long)costs.per_tile * (long long)leg.tiles; - if (!leg.ends_at_wall){ - cost += costs.leg_not_at_wall + (long long)costs.per_open_tile * (long long)leg.tiles; - } - if (expansion){ - cost = expansion->cost; - } - if (previous != nullptr && previous->direction == leg.direction && !previous->ends_at_wall && !previous->held && !leg.held){ - cost -= costs.per_leg; - } - total += cost; - spread = planned.after; - normalize(spread); - previous = ⋚ + robust.push_back(Pokemon::RobustLeg{ + .direction = planned.leg.direction, + .tiles = planned.leg.tiles, + .to_wall = planned.leg.ends_at_wall, + .after = planned.after, + .held = planned.leg.held, + }); } - return total; + return Pokemon::robust_legs_cost(RobustWorldModel(world), from, robust, robust_leg_costs(costs)); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp index d6f7a67b80..1a49f296c1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.cpp @@ -49,6 +49,12 @@ std::optional ledge_direction(TileKind tile){ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown TileKind."); } +// Still people the console showed talking when bumped. The map data has no +// marker for it; r29 ran east into Mom, who talked. +bool bump_talker(const std::string& map, const std::string& object){ + return map == "PlayerHouse1F" && object == "mom_0"; +} + } // namespace @@ -58,10 +64,13 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Map placed twice: " + name); } } - Placed placed{.name = std::move(name), .tiles = map.tiles, .occupied = {}, .wander = {}, .warps = {}, .offset = offset}; + Placed placed{.name = std::move(name), .tiles = map.tiles, .occupied = {}, .talkers = {}, .wander = {}, .warps = {}, .offset = offset}; for (const Pokemon::MapObject& object : map.objects){ if (!object.wander){ placed.occupied.push_back({object.x, object.y}); + if (bump_talker(map.name, object.name)){ + placed.talkers.push_back({object.x, object.y}); + } }else{ placed.wander.push_back(*object.wander); } @@ -70,6 +79,11 @@ void StoryWorld::add(std::string name, const Pokemon::MapData& map, const TilePo placed.warps.push_back({warp.x, warp.y}); } check_overlap(placed); + Pokemon::MapData connected = map; + connected.name = placed.name; + connected.world = Pokemon::MapWorld{"story", offset}; + m_connected.push_back(std::move(connected)); + Pokemon::connect_by_world(m_connected); m_maps.push_back(std::move(placed)); rebuild(); } @@ -145,6 +159,11 @@ void StoryWorld::paint(const Placed& placed, const TilePos& corner){ for (const TilePos& pos : placed.occupied){ Pokemon::cell_at({corner.x + pos.x, corner.y + pos.y}, m_cells).occupant = PERSON; } + for (const TilePos& pos : placed.talkers){ + Cell& c = Pokemon::cell_at({corner.x + pos.x, corner.y + pos.y}, m_cells); + c.recovery_hazard = true; + c.talks = true; + } for (const auto& box : placed.wander){ for (int y = std::max(0, box.y0); y <= std::min(placed.tiles.height - 1, box.y1); y++){ for (int x = std::max(0, box.x0); x <= std::min(placed.tiles.width - 1, box.x1); x++){ @@ -183,11 +202,8 @@ std::optional StoryWorld::tile(const TilePos& pos) const{ return found->tile; } -StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos, OccupancyUse use) const{ +StoryWorld::Occupant StoryWorld::occupied(const TilePos& pos) const{ const Cell* found = cell(pos); - if (found && use == OccupancyUse::WALL_RECOVERY && found->recovery_hazard){ - return PERSON; - } return found == nullptr ? NOBODY : found->occupant; } @@ -235,6 +251,11 @@ bool recovery_hazard(const StoryWorld& world, const TilePos& pos){ return found != nullptr && found->recovery_hazard; } +bool talks_when_bumped(const StoryWorld& world, const TilePos& pos){ + const StoryWorld::Cell* found = world.cell(pos); + return found != nullptr && found->talks; +} + void StoryWorld::block(const TilePos& pos){ if (Cell* found = cell(pos)){ found->occupant = BLOCKED; @@ -271,6 +292,10 @@ std::optional StoryWorld::to_local(const TilePos& world) const{ +Pokemon::ConnectedMaps connected_maps(const StoryWorld& world){ + return Pokemon::ConnectedMaps(world.m_connected); +} + bool covered(const StoryWorld& world, const TilePos& pos){ return world.tile(pos).has_value(); } @@ -327,11 +352,13 @@ bool warp_within(const StoryWorld& world, const std::vector& from, Dire return false; } -// Someone standing in the way stops us too, but is no wall to stop against: -// they may turn and talk, or walk off (r29 ran east into Mom, who talked). +// Someone who never moves (a person or item with no wander box) is a wall +// like any other (the user's rule, 2026-11-12), unless they talk when bumped. +// A wanderer is none: it is not in the cells' occupants, and the walker +// waits for it. bool at_wall(const StoryWorld& world, const TilePos& pos, Direction direction){ const std::optional next = world.tile(pos.next(direction)); - return next && *next != TileKind::DOOR && world.occupied(pos.next(direction)) != StoryWorld::PERSON && + return next && *next != TileKind::DOOR && !talks_when_bumped(world, pos.next(direction)) && !step(world, pos, direction).has_value(); } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h index cf46b6f0c5..bed4f15cb0 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h @@ -11,6 +11,10 @@ * plan may not end there, but walking into one is not a wall, since it may * be an exit. * + * The same maps are also kept as connected maps (Pokemon::ConnectedMaps), + * joined where they meet on the world grid, for planning on a map and a + * tile instead of the grid. + * */ #ifndef PokemonAutomation_PokemonBDSP_AutoStory_StoryWorld_H @@ -19,6 +23,7 @@ #include #include #include +#include "Pokemon/Navigation/Pokemon_ConnectedMaps.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "Pokemon/Navigation/Pokemon_MapData.h" @@ -55,9 +60,7 @@ class StoryWorld{ PERSON, BLOCKED, }; - // Recovery also excludes wandering areas and declared warps. - enum class OccupancyUse{ MOVEMENT, WALL_RECOVERY }; - Occupant occupied(const Pokemon::TilePos& pos, OccupancyUse use = OccupancyUse::MOVEMENT) const; + Occupant occupied(const Pokemon::TilePos& pos) const; // Blocks a tile found in the way on the console. Tiles off the maps // are left alone. @@ -71,15 +74,18 @@ class StoryWorld{ // The map that holds a world tile, or nothing between maps. std::optional to_local(const Pokemon::TilePos& world) const; + friend Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); friend std::vector wandering_hazards(const StoryWorld& world); friend bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); friend bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); + friend bool talks_when_bumped(const StoryWorld& world, const Pokemon::TilePos& pos); private: struct Placed{ std::string name; Pokemon::Grid tiles; std::vector occupied; // local tiles + std::vector talkers; // local tiles of occupied people who talk when bumped std::vector wander; // recovery hazards, not terrain std::vector warps; Pokemon::TilePos offset; @@ -89,6 +95,7 @@ class StoryWorld{ Pokemon::TileKind tile = Pokemon::TileKind::WALL; Occupant occupant = NOBODY; bool recovery_hazard = false; + bool talks = false; bool wander_hazard = false; }; @@ -102,6 +109,7 @@ class StoryWorld{ Cell* cell(const Pokemon::TilePos& pos); std::vector m_maps; + std::vector m_connected; Pokemon::TilePos m_origin; // offset of world tile (0,0) Pokemon::Grid m_cells; std::vector m_blocked; // world tiles, kept across add() @@ -109,6 +117,13 @@ class StoryWorld{ }; +// The world's maps as added, under their names in it, joined where they +// meet. Tiles blocked or taken off the maps are not in them. The view +// lasts until the world's next add(). +Pokemon::ConnectedMaps connected_maps(const StoryWorld& world); +// A temporary world would be gone before the view is used. +Pokemon::ConnectedMaps connected_maps(StoryWorld&& world) = delete; + // The rules of walking on a story world, from its tiles. // All tiles where someone wanders on the maps, in world coordinates. @@ -117,6 +132,9 @@ std::vector wandering_hazards(const StoryWorld& world); bool wandering_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); // Whether a world tile is a recovery hazard (wander box or warp). bool recovery_hazard(const StoryWorld& world, const Pokemon::TilePos& pos); +// Someone who never moves but starts a talk or scene when bumped (Mom in +// PlayerHouse1F, r29): no wall to stop against or anchor on. +bool talks_when_bumped(const StoryWorld& world, const Pokemon::TilePos& pos); // "Route 201 (45, 3)", or "world (x, y)" if no map holds it. std::string describe(const StoryWorld& world, const Pokemon::TilePos& pos); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp index f385dfcacc..c0d247096b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WallRecovery.cpp @@ -18,22 +18,22 @@ using Pokemon::TilePos; // A wall ray must stay on the same map and walk one tile per step. A // ledge may be legal travel but must not become a localization anchor. +// A wander box or a warp on the ray or its wall spoils it; a person who +// never moves is a wall to stop against. std::optional safe_wall(const StoryWorld& world, TilePos from, Direction direction){ const auto map = world.to_local(from); - if (!map || !standable(world, from) - || world.occupied(from, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + if (!map || !standable(world, from) || recovery_hazard(world, from)){ return std::nullopt; } const WallHit wall = slide_to_wall(world, from, direction); - if (!wall.anchored - || world.occupied(wall.wall, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + if (!wall.anchored || recovery_hazard(world, wall.wall)){ return std::nullopt; } while (from != wall.stop){ const auto next = step(world, from, direction); const auto local = next ? world.to_local(*next) : std::nullopt; if (!next || *next != from.next(direction) || !local || local->map != map->map - || world.occupied(*next, StoryWorld::OccupancyUse::WALL_RECOVERY) == StoryWorld::PERSON){ + || recovery_hazard(world, *next)){ return std::nullopt; } from = *next; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt index 8709980adc..f85a1def34 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_bench.golden.txt @@ -19,6 +19,7 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.01 above_the_door | 7230 | 7230 | 7230 | 1 | 0 | 0 | 4.66! | 1.00 | 1.00 | 1550 ms (stand-in) | PASS 00.01 short_of_barrys_door | 11950 | 11950 | 11950 | 1 | 0 | 0 | 4.35! | 1.00 | 1.00 | 2750 ms (stand-in) | PASS 00.01 above_barrys_door | 7230 | 7230 | 7230 | 1 | 0 | 0 | 4.66! | 1.00 | 1.00 | 1550 ms (stand-in) | PASS +00.02 to_the_lake_entrance | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS 00.03 into_rowans_scene | 3030 | 3030 | 3030 | 1 | 0 | 0 | 2.33! | 1.00 | 1.00 | 1300 ms (stand-in) | PASS 00.03 into_dawns_scene | 61510 | 46690 | 34340 | 4 | 22 | 0 | 5.37! | 1.15 | 56.00! | 11450 ms (stand-in) | PASS 00.04 onto_the_path | 4050 | 4050 | 4050 | 2 | 0 | 0 | 5.79! | 1.00 | 1.00 | 700 ms (stand-in) | PASS @@ -32,15 +33,19 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 00.04b to_catch_grass | 11689 | 38550 | 6300 | 2 | 34 | 1 | 17.98! | 17.50! | 2.00! | 650 ms (stand-in) | PASS 00.04b into_sandgem | 9520 | 19400 | 7050 | 3 | 12 | 0 | 2.93! | 4.33! | 1.00 | 3250 ms (stand-in) | PASS 00.04d north_to_jubilife | 73575 | 42700 | 30350 | 8 | 35 | 0 | 7.21! | 1.24 | 80.00! | 10200 ms (stand-in) | PASS -00.05 to_the_school | 9700 | 9700 | 9700 | 0 | 0 | 0 | 6.69! | 1.00 | 1.00 | 1450 ms (stand-in) | PASS 00.05b below_the_presidents_trigger | 4900 | 4900 | 4900 | 0 | 0 | 0 | 5.76! | 1.00 | 1.00 | 850 ms (stand-in) | PASS -00.05b below_the_tv_clown | 21463 | 23600 | 20750 | 1 | 1 | 0 | 4.57! | 2.00! | 5.00! | 4700 ms (stand-in) | PASS +00.05b past_the_president | 1700 | 1700 | 1700 | 0 | 0 | 0 | 3.78! | 1.00 | 1.00 | 450 ms (stand-in) | PASS +00.05b below_the_mart_clown | 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.05c to_main_boulevard | 2500 | 2500 | 2500 | 0 | 0 | 0 | 3.57! | 1.00 | 1.00 | 700 ms (stand-in) | PASS -00.05c along_main_boulevard | 24100 | 24100 | 24100 | 0 | 0 | 0 | 7.42! | 1.00 | 1.00 | 3250 ms (stand-in) | PASS -00.05c beside_the_president | 10500 | 10500 | 10500 | 0 | 0 | 0 | 4.77! | 1.00 | 1.00 | 2200 ms (stand-in) | PASS +00.05b beside_the_company_sign | 1450 | 1450 | 1450 | 1 | 0 | 0 | 4.14! | 1.00 | 1.00 | 350 ms (stand-in) | PASS +00.05c below_the_company_clown | 900 | 900 | 900 | 0 | 0 | 0 | 2.57! | 1.00 | 1.00 | 350 ms (stand-in) | PASS +00.05c below_the_tv_clown | 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 +01.02 south_to_the_cliff | 1800 | 1800 | 1800 | 1 | 0 | 0 | 2.57! | 1.00 | 1.00 | 700 ms (stand-in) | PASS 01.02 by_the_gate | 24815 | 26050 | 13700 | 2 | 9 | 0 | 3.60! | 1.00 | 1.00 | 6900 ms (stand-in) | PASS 01.02 west_of_the_hikers_trigger | 3950 | 3950 | 3950 | 2 | 0 | 0 | 8.78! | 1.00 | 2.00! | 450 ms (stand-in) | PASS 01.02 past_curtis | 10500 | 10500 | 10500 | 0 | 0 | 0 | 6.77! | 1.00 | 1.00 | 1550 ms (stand-in) | PASS @@ -48,11 +53,12 @@ walk run with no stops) | verdict (why). A ratio above 1.5 is flagged "!". 01.02 west_of_the_welcome | 8550 | 8550 | 8550 | 2 | 0 | 0 | 9.00! | 1.00 | 4.00! | 950 ms (stand-in) | PASS 01.02b below_the_centers_door | 6663 | 8800 | 5950 | 2 | 1 | 0 | 2.38! | 2.00! | 2.00! | 2800 ms (stand-in) | PASS 01.03 above_the_mine | 16350 | 16350 | 16350 | 3 | 0 | 0 | 2.75! | 1.00 | 5.00! | 5950 ms (stand-in) | PASS -01.05 east_of_barrys_trigger | 26050 | 26050 | 26050 | 3 | 0 | 0 | 7.44! | 1.00 | 14.00! | 3500 ms (stand-in) | PASS +01.05 east_of_barrys_trigger | 19550 | 19550 | 19550 | 2 | 0 | 0 | 5.59! | 1.00 | 13.00! | 3500 ms (stand-in) | PASS 01.05 through_the_gate | 12050 | 12050 | 12050 | 5 | 0 | 0 | 4.92! | 1.00 | 27.00! | 2450 ms (stand-in) | PASS -01.06 up_jubilifes_road | 87286 | 119950 | 58350 | 3 | 10 | 4 | 7.66! | 2.20! | 20.00! | 11400 ms (stand-in) | PASS +01.06 up_jubilifes_road | 82607 | 94600 | 58350 | 3 | 10 | 4 | 7.25! | 2.20! | 20.00! | 11400 ms (stand-in) | PASS 01.06 below_rowans_trigger | 1950 | 1950 | 1950 | 1 | 0 | 0 | 2.29! | 1.00 | 1.00 | 850 ms (stand-in) | PASS -01.08 below_the_ravaged_path | 27098 | 25150 | 12800 | 3 | 12 | 0 | 4.52! | 1.30 | 4.00! | 6000 ms (stand-in) | PASS +01.08 west_to_the_wall | 1650 | 1650 | 1650 | 1 | 0 | 0 | 3.00! | 1.00 | 1.00 | 550 ms (stand-in) | PASS +01.08 below_the_ravaged_path | 24815 | 26050 | 13700 | 2 | 9 | 0 | 4.24! | 1.00 | 6.00! | 5850 ms (stand-in) | PASS 01.09 west_of_the_rock | 7050 | 7050 | 7050 | 1 | 0 | 0 | 4.70! | 1.00 | 1.00 | 1500 ms (stand-in) | PASS 01.09 above_the_way_out | 4550 | 4550 | 4550 | 2 | 0 | 0 | 4.14! | 1.00 | 2.00! | 1100 ms (stand-in) | PASS 01.10 line_1 | 900 | 900 | 900 | 0 | 0 | 0 | 2.25! | 1.00 | 1.00 | 400 ms (stand-in) | PASS diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt index fbc8c921ee..6f060714f7 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Data/route_plans.golden.txt @@ -57,6 +57,13 @@ anchor); 0 from one start tile. target: VerityLakefront (17, 14) facing north (tile) not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) +== 00.02 to_the_lake_entrance (costs: route) + from: VerityLakefront (17, 14) facing north (tile) + target: VerityLakefront (17, 13) facing north (tile) + start candidates: Verity Lakefront (17, 14) + 1. north 1 (open) -> Verity Lakefront (17, 13) + totals: 1 legs, 0 turns, 1 open, 0 localization + == 00.03 into_rowans_scene (costs: into_scene) from: VerityLakefront (17, 14) (17, 15) (set) target: VerityLakefront (17, 21) (tile) @@ -189,17 +196,10 @@ anchor); 0 from one start tile. 12. north 1 (open) -> Route 202 (18, 3) totals: 12 legs, 11 turns, 4 open, 0 localization -== 00.05 to_the_center (costs: town) - from: unknown - target: JubilifeCity (52, 41) facing north (tile) - not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) - == 00.05 to_the_school (costs: town) - from: JubilifeCity (52, 41) facing north (tile) + from: unknown target: JubilifeCity (40, 41) facing north (tile) - start candidates: Jubilife City (52, 41) - 1. west 12 (open) -> Jubilife City (40, 41) - totals: 1 legs, 0 turns, 1 open, 0 localization + not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) == 00.05b below_the_presidents_trigger (costs: town) from: JubilifeCity (40, 41) facing south (tile) @@ -208,19 +208,29 @@ anchor); 0 from one start tile. 1. east 6 (open) -> Jubilife City (46, 41) totals: 1 legs, 0 turns, 1 open, 0 localization +== 00.05b past_the_president (costs: route) + from: JubilifeCity (46, 40) facing north (tile) + target: JubilifeCity (48, 40) facing east (tile) + start candidates: Jubilife City (46, 40) + 1. east 2 (open) -> Jubilife City (48, 40) + totals: 1 legs, 0 turns, 1 open, 0 localization + == 00.05b below_the_mart_clown (costs: town) - from: unknown - target: JubilifeCity (55, 34) facing north (tile) - not planned: the start is unknown (a LEGS or STEP step before it does not say where it ends) + from: JubilifeCity (48, 40) facing east (tile) + target: JubilifeCity (56, 36) facing north (tile) + start candidates: Jubilife City (48, 40) + 1. north 4 (open) -> Jubilife City (48, 36) + 2. east 8 (to wall) -> Jubilife City (56, 36) + totals: 2 legs, 1 turns, 1 open, 0 localization == 00.05b below_the_tv_clown (costs: town) - from: JubilifeCity (55, 34) facing north (tile) + from: JubilifeCity (56, 31) facing north (tile) target: JubilifeCity (36, 17) facing north (tile) - start candidates: Jubilife City (55, 34) - 1. west 23 (to wall) -> Jubilife City (32, 34) - 2. north 10 (open) -> Jubilife City (32, 24) - 3. east 4 (open) -> Jubilife City (36, 24) - 4. north 7 (open) -> Jubilife City (36, 17) + start candidates: Jubilife City (56, 31) + 1. west 8 (open) -> Jubilife City (48, 31) + 2. north 7 (open) -> Jubilife City (48, 24) + 3. west 12 (open) -> Jubilife City (36, 24) + 4. north 7 (to wall) -> Jubilife City (36, 17) totals: 4 legs, 3 turns, 3 open, 0 localization == 00.05b below_the_company_clown (costs: town) @@ -232,26 +242,46 @@ anchor); 0 from one start tile. 3. north 2 (open) -> Jubilife City (15, 19) totals: 3 legs, 2 turns, 3 open, 0 localization -== 00.05c to_main_boulevard (costs: line) +== 00.05b beside_the_company_sign (costs: line) from: JubilifeCity (15, 19) facing north (tile) - target: JubilifeCity (15, 22) facing south (tile) + target: JubilifeCity (14, 19) facing west (tile) start candidates: Jubilife City (15, 19) - 1. south 3 (open) -> Jubilife City (15, 22) - totals: 1 legs, 0 turns, 1 open, 0 localization + 1. west 1 (to wall) -> Jubilife City (14, 19) + totals: 1 legs, 0 turns, 0 open, 0 localization -== 00.05c along_main_boulevard (costs: line) - from: JubilifeCity (15, 22) facing south (tile) - target: JubilifeCity (45, 22) facing south (tile) - start candidates: Jubilife City (15, 22) - 1. east 30 (open) -> Jubilife City (45, 22) +== 00.05c below_the_company_clown (costs: town) + from: JubilifeCity (14, 19) facing west (tile) + target: JubilifeCity (15, 19) facing north (tile) + start candidates: Jubilife City (14, 19) + 1. east 1 (open) -> Jubilife City (15, 19) totals: 1 legs, 0 turns, 1 open, 0 localization -== 00.05c beside_the_president (costs: line) - from: JubilifeCity (45, 22) facing south (tile) +== 00.05c below_the_tv_clown (costs: town) + from: JubilifeCity (15, 19) facing north (tile) + target: JubilifeCity (36, 17) facing north (tile) + start candidates: Jubilife City (15, 19) + 1. south 2 (open) -> Jubilife City (15, 21) + 2. east 21 (open) -> Jubilife City (36, 21) + 3. north 4 (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 + +== 00.05c beside_the_president (costs: town) + from: JubilifeCity (56, 31) facing north (tile) target: JubilifeCity (45, 35) facing east (tile) - start candidates: Jubilife City (45, 22) - 1. south 13 (open) -> Jubilife City (45, 35) - totals: 1 legs, 0 turns, 1 open, 0 localization + start candidates: Jubilife City (56, 31) + 1. west 11 (open) -> Jubilife City (45, 31) + 2. south 4 (open) -> Jubilife City (45, 35) + totals: 2 legs, 1 turns, 2 open, 0 localization == 00.05c to_the_route_203_street (costs: line) from: JubilifeCity (45, 35) facing east (tile) @@ -268,6 +298,13 @@ anchor); 0 from one start tile. 1. east 9 (open) -> Route 203 (4, 18) totals: 1 legs, 0 turns, 1 open, 0 localization +== 01.02 south_to_the_cliff (costs: route) + from: Route203 (5, 17) (5, 18) (5, 19) (5, 20) facing east (set) + target: Route203 (5, 20) facing south (tile) + start candidates: Route 203 (5, 17), Route 203 (5, 18), Route 203 (5, 19), Route 203 (5, 20) + 1. south 3 (to wall) -> Route 203 (5, 20) + totals: 1 legs, 0 turns, 0 open, 1 localization + == 01.02 by_the_gate (costs: route) from: Route203 (5, 20) facing south (tile) target: Route203 (55, 9) facing east (tile) @@ -337,12 +374,11 @@ anchor); 0 from one start tile. target: OreburghCity (7, 13) facing west (tile) start candidates: Oreburgh City (26, 21), Oreburgh City (26, 22) 1. south 5 (to wall) -> Oreburgh City (26, 26) - 2. west 2 (to wall) -> Oreburgh City (24, 26) - 3. north 5 (to wall) -> Oreburgh City (24, 21) - 4. west 9 (open) -> Oreburgh City (15, 21) - 5. north 8 (open) -> Oreburgh City (15, 13) - 6. west 8 (open) -> Oreburgh City (7, 13) - totals: 6 legs, 5 turns, 3 open, 1 localization + 2. north 1 (open) -> Oreburgh City (26, 25) + 3. west 14 (to wall) -> Oreburgh City (12, 25) + 4. north 12 (open) -> Oreburgh City (12, 13) + 5. west 5 (open) -> Oreburgh City (7, 13) + totals: 5 legs, 4 turns, 3 open, 1 localization == 01.05 through_the_gate (costs: route) from: OreburghGate (27, 22) (26, 22) facing west (set) @@ -374,16 +410,23 @@ anchor); 0 from one start tile. 1. east 6 (to wall) -> Jubilife City (47, 8) totals: 1 legs, 0 turns, 0 open, 0 localization +== 01.08 west_to_the_wall (costs: route) + from: JubilifeCity (46, 5) (47, 5) (set) + target: JubilifeCity (44, 5) facing west (tile) + start candidates: Jubilife City (46, 5), Jubilife City (47, 5) + 1. west 3 (to wall) -> Jubilife City (44, 5) + totals: 1 legs, 0 turns, 0 open, 1 localization + == 01.08 below_the_ravaged_path (costs: town) from: JubilifeCity (44, 5) facing west (tile) - target: Route204South (11, 2) facing north (tile) + target: Route204South (11, 3) facing north (tile) start candidates: Jubilife City (44, 5) 1. east 2 (open) -> Jubilife City (46, 5) 2. north 19 (to wall) -> Route 204 (14, 18) - 3. west 2 (open) -> Route 204 (12, 18) - 4. north 16 (to wall) -> Route 204 (12, 2) - 5. west 1 (to wall) -> Route 204 (11, 2) - totals: 5 legs, 4 turns, 2 open, 0 localization + 3. west 4 (open) -> Route 204 (10, 18) + 4. north 15 (to wall) -> Route 204 (10, 3) + 5. east 1 (open) -> Route 204 (11, 3) + totals: 5 legs, 4 turns, 3 open, 0 localization == 01.09 west_of_the_rock (costs: route) from: RavagedPath (19, 50) facing north (tile) diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp index 01174e5b99..45831399cf 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_Maps_Tests.cpp @@ -44,6 +44,13 @@ const MapObject* standing_object(const MapData& map, const TilePos& pos){ return nullptr; } +// Whether someone starts on `pos` and wanders a box round it. +bool wanders_from(const MapData& map, const TilePos& pos){ + return std::ranges::any_of(map.objects, [&](const MapObject& object){ + return object.wander && object.x == pos.x && object.y == pos.y; + }); +} + // "rocks" for "rocks.3", the point's own name otherwise. std::string region_of(const std::string& point){ const size_t dot = point.rfind('.'); @@ -84,6 +91,7 @@ enum class PointOn{ DOOR, SIGN, PERSON, // someone stands still there + WANDERER, // someone starts there and wanders a box round it WALL, // a rock until smashed }; struct PointCase{ @@ -113,9 +121,9 @@ const std::vector& point_cases(){ {.map = "JubilifeCity", .point = "pokemon_center_door", .on = PointOn::DOOR}, {.map = "JubilifeCity", .point = "tv_station_door", .on = PointOn::DOOR}, {.map = "JubilifeCity", .point = "poketch_president", .on = PointOn::PERSON}, - {.map = "JubilifeCity", .point = "clown_mart", .on = PointOn::PERSON}, + {.map = "JubilifeCity", .point = "clown_mart", .on = PointOn::WANDERER}, {.map = "JubilifeCity", .point = "clown_tv_station", .on = PointOn::PERSON}, - {.map = "JubilifeCity", .point = "clown_poketch_company", .on = PointOn::PERSON}, + {.map = "JubilifeCity", .point = "clown_poketch_company", .on = PointOn::WANDERER}, {.map = "OreburghCity", .point = "pokemon_center_door", .on = PointOn::DOOR}, {.map = "OreburghCity", .point = "gym_door", .on = PointOn::DOOR}, {.map = "OreburghCity", .point = "gate_mouth", .on = PointOn::DOOR}, @@ -148,6 +156,8 @@ std::string check_point_on(const MapData& map, const TilePos& pos, PointOn on){ return tile == TileKind::SIGN ? "" : "not a sign"; case PointOn::PERSON: return is_ground(tile) && object != nullptr && object->kind == Pokemon::ObjectKind::NPC ? "" : "nobody stands still there"; + case PointOn::WANDERER: + return is_ground(tile) && wanders_from(map, pos) ? "" : "nobody wanders from there"; case PointOn::WALL: return tile == TileKind::WALL ? "" : "not a wall"; } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp index d5f507d724..5590f1f3f1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_PlannedRoute_Tests.cpp @@ -497,6 +497,78 @@ UnitTestResult test_never_moved_plans_from_the_start(Logger& logger){ return replan.empty() ? UnitTestResult(true) : UnitTestResult(replan); } +// lab-B 2026-11-12 01:22 (00.05c below_the_company_clown): an open leg +// west was blocked by someone the map lacks, and the taps after the wait +// opened their talk (the Global Wonder Station's woman). Taken for a +// trainer, the talk was "fought", no battle followed, and the replans +// walked into her again until the third talk failed the step. Whoever +// talks as we tap on after a block is the one in the way: their tile is +// marked, and the walk plans again from where it stopped. +UnitTestResult test_open_leg_blocker_talks(Logger& logger){ + Script script{.steps = { + press_step("D-pad west 50 ms x1"), + walk_step("6 taps: T: west 6 (open)", WalkStop::BLOCKED, 2000ms, 2), + press_step("wait 2500 ms x1"), + walk_step("4 taps: T: west 6 (open): the rest", WalkStop::DIALOG, 800ms, 0), + }}; + // West along Route 202's row 5, as test_open_leg_known_trainer() walks + // it, with no trainer: the one in the way stands on (27, 5). + ScriptedWalk walk; + try{ + walk = walk_script(route202_world(), {30, 5}, {24, 5}, {}, script); + }catch (const ScriptMismatch&){ + // The walk after the replan is not scripted. + } + for (const std::string& note : script.notes){ + logger.log(note); + } + if (!walk.failure.empty()){ + return "failed: " + walk.failure; + } + if (script.next != script.steps.size()){ + return script_left(script); + } + const auto marked = std::find_if(script.notes.begin(), script.notes.end(), [](const std::string& note){ + return note.find("marked it") != std::string::npos && note.find("(27, 5)") != std::string::npos; + }); + if (marked == script.notes.end()){ + return "the tile of whoever talked, (27, 5), was not marked."; + } + const std::string replan = check_replan_from(script, {"Route 202 (28, 5)"}); + return replan.empty() ? UnitTestResult(true) : UnitTestResult(replan); +} + +// lab-B 2026-11-12 01:55 (00.05c below_the_company_clown, again): with +// the woman who talked marked at (45, 24), the plan from (46, 24) and the +// tile behind it began "west 1 (to wall)" against her. Walking into her +// opened her talk again, which was fought as a trainer, and the walk on +// ran out of time short of the "wall". A person is no wall: the walk after +// the replan must not walk to a wall into the tile it marked. +UnitTestResult test_marked_talker_is_no_wall(Logger& logger){ + Script script{.steps = { + press_step("D-pad west 50 ms x1"), + walk_step("6 taps: T: west 6 (open)", WalkStop::BLOCKED, 2000ms, 2), + press_step("wait 2500 ms x1"), + walk_step("4 taps: T: west 6 (open): the rest", WalkStop::DIALOG, 800ms, 0), + }}; + std::string after_replan; + try{ + walk_script(route202_world(), {30, 5}, {24, 5}, {}, script); + }catch (const ScriptMismatch& mismatch){ + after_replan = mismatch.message; + } + for (const std::string& note : script.notes){ + logger.log(note); + } + if (script.next != script.steps.size()){ + return script_left(script); + } + if (after_replan.find("\"wall: ") != std::string::npos && after_replan.find("west") != std::string::npos){ + return "after the replan the walk went to a wall west, into the one who talked: " + after_replan; + } + return UnitTestResult(true); +} + // A leg to the wall two tiles away that runs out of time after one tile // (one chunk moved): someone stands in it, as Route 204's youngster did on // 01.08's "west 2 (to wall)" (lab-B 2026-11-08). The check at the wall @@ -531,6 +603,35 @@ UnitTestResult test_short_leg_a_tile_short_is_not_arrived(Logger&){ } +// A leg to a wall 8 tiles away that stops far later than 8 tiles take: the +// player pushed against someone on the way, and the time counts 18 tiles +// (lab-B 2026-11-11 21:00, 00.05b: "east 8 (to wall)" stopped after +// 2800 ms against the boy below the Mart, about 5 tiles in, and the route +// went on from the wall). Not the wall: plan again from every tile of the +// leg, and a second leg to the wall pins it. +UnitTestResult test_wall_leg_held_up_is_not_at_its_wall(Logger&){ + const StoryWorld corridor = make_world({"###########", "#.........#", "###########"}); + Script script{.steps = { + walk_step("wall: T: east 8 (to wall)", WalkStop::BLOCKED, 3930ms, 5), + walk_step("wall: T: east 7 (to wall)", WalkStop::BLOCKED, 1450ms, 1), + answer_step("dialog within 500 ms", false), + }}; + ScriptedWalk walk; + try{ + walk = walk_script(corridor, {1, 1}, {9, 1}, {}, script); + }catch (const ScriptMismatch& e){ + return e.message; + } + if (!walk.failure.empty()){ + return "failed: " + walk.failure; + } + if (walk.at != std::vector{{9, 1}}){ + return "did not arrive at (9, 1)."; + } + const std::string left = script_left(script); + return left.empty() ? UnitTestResult(true) : UnitTestResult(left); +} + struct PlannedRouteInput{ std::string name; std::function body; @@ -578,6 +679,14 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .input = {"a known trainer stops an open leg", test_open_leg_known_trainer}, .expectation = {}, }, + { + .input = {"someone in the way who talks is marked, not fought (lab-B 2026-11-12, 00.05c)", test_open_leg_blocker_talks}, + .expectation = {}, + }, + { + .input = {"a marked talker is no wall for the replan (lab-B 2026-11-12, 00.05c)", test_marked_talker_is_no_wall}, + .expectation = {}, + }, { .input = {"a person a tile ahead on a short leg is waited out", test_short_leg_waits_for_the_way}, .expectation = {}, @@ -590,6 +699,10 @@ const PlannedRouteCase PLANNED_ROUTE_CASES[] = { .input = {"a wall leg that never moved plans from its start", test_never_moved_plans_from_the_start}, .expectation = {}, }, + { + .input = {"a wall leg held up on the way is not at its wall (lab-B 2026-11-11 21:00)", test_wall_leg_held_up_is_not_at_its_wall}, + .expectation = {}, + }, }; 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 995f476ce9..0d6578cc60 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_RoutePlanner_Tests.cpp @@ -233,6 +233,7 @@ struct RecoveryGeometryInput{ std::vector from; std::optional wander = {}; std::vector warps = {}; + std::optional still = {}; // someone who never moves }; struct RecoveryGeometryExpectation{ std::optional anchor; @@ -261,6 +262,10 @@ Pokemon::MapData recovery_map(const RecoveryGeometryInput& input){ map.objects.push_back({.name = "wanderer", .x = 3, .y = 1, .facing = std::nullopt, .wander = input.wander, .trainer = std::nullopt, .hide_flag = std::nullopt}); } + if (input.still){ + map.objects.push_back({.name = "still", .x = input.still->x, .y = input.still->y, .facing = std::nullopt, + .wander = std::nullopt, .trainer = std::nullopt, .hide_flag = std::nullopt}); + } for (const auto& warp : input.warps){ map.warps.push_back({.x = warp.x, .y = warp.y, .to = std::nullopt}); } @@ -372,6 +377,9 @@ const RecoveryGeometryCase GEOMETRY_CASES[] = { .expectation = {.anchor = std::nullopt, .free_tile = TilePos{.x = 3, .y = 1}}}, {.input = {.name = "warp crossings are unsafe", .from = {{1, 1}, {5, 1}}, .warps = {{3, 1}}}, .expectation = {.anchor = std::nullopt}}, + {.input = {.name = "a still person is a wall to anchor on", .from = {{2, 1}, {3, 1}}, + .warps = {{5, 1}}, .still = TilePos{.x = 1, .y = 1}}, + .expectation = {.anchor = TilePos{.x = 2, .y = 1}, .direction = Direction::WEST}}, {.input = {.name = "warps on blocked glyphs are unsafe", .from = {{1, 1}, {5, 1}}, .warps = {{0, 1}, {6, 1}}}, .expectation = {.anchor = std::nullopt}}, }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp index e85849305c..123a171f38 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_SimulatedRoute_Tests.cpp @@ -60,7 +60,7 @@ struct RouteFailed{ // The console as a small simulator: the player stands on one tile of // `world`, walls and `obstacles` stop them, and every walk and tap moves // them. Fails the case after `max_calls` calls (a walker that loops). -// code-health: allow public_methods -- a RouteIO fake: the interface's seven overrides plus three test knobs +// code-health: allow public_methods -- a RouteIO fake: the interface's seven overrides plus four test knobs class SimulatedRouteIO : public RouteIO{ public: SimulatedRouteIO(const StoryWorld& world, TilePos at, std::vector obstacles, std::vector& notes) @@ -79,17 +79,10 @@ class SimulatedRouteIO : public RouteIO{ virtual WalkResult walk_to_wall(const RouteWallWalk& walk) override{ count_call(); - const MoveSpeed speed = walk.options.pace == DpadPace::RUN ? MoveSpeed::RUN : MoveSpeed::WALK; + const MoveSpeed speed = walk.options.pace == DpadPace::RUN && m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK; const Milliseconds per_tile = route_ms_per_tile(walk.direction, speed); - if (m_overshoot && walk.limit > ROUTE_START_DELAY){ - // A hold timed for n tiles (ROUTE_START_DELAY, then half a - // tile under n) goes on past them until a wall stops it. - const size_t tiles = (size_t)((walk.limit - ROUTE_START_DELAY + per_tile / 2) / per_tile); - const size_t want = tiles + (tiles * 35 + 99) / 100; - const size_t moved = move(walk.direction, want); - return {.stop = moved < want ? WalkStop::BLOCKED : WalkStop::LIMIT, .walked = walk.limit, - .wild_battles = 0, .moved_chunks = moved}; - } + // walk_route() walks only legs to a wall here, and a walk to a wall + // ends at the wall: no overshoot (overshoot_timed_holds()). const size_t moved = move(walk.direction, SIZE_MAX); return {.stop = WalkStop::BLOCKED, .walked = ROUTE_START_DELAY + 800ms + per_tile * moved + per_tile / 2, .wild_battles = 0, .moved_chunks = moved}; @@ -102,6 +95,11 @@ class SimulatedRouteIO : public RouteIO{ void overshoot_timed_holds(bool overshoot){ m_overshoot = overshoot; } + // Before the running shoes, a walk held with B is still a walk: its + // time counts walking tiles, as the walker's plan speed does. + void set_can_run(bool can_run){ + m_can_run = can_run; + } virtual WalkResult walk_taps(Direction direction, size_t tiles, const std::string&) override{ count_call(); const size_t moved = move(direction, tiles); @@ -172,6 +170,7 @@ class SimulatedRouteIO : public RouteIO{ size_t m_calls = 0; size_t m_walked = 0; bool m_overshoot = false; + bool m_can_run = true; }; StoryWorld jubilife_world(){ @@ -299,6 +298,7 @@ UnitTestResult test_jubilife_center_kids(Logger&){ // One ROUTE step of the story table, from where the steps before it end. struct StoryRoute{ std::string name; + MoveSpeed speed; Pose from; Pose goal; std::string costs; @@ -311,7 +311,8 @@ void add_story_route(const std::string& row, const StoryStep& step, std::optiona if (step.kind == StoryStepKind::ROUTE){ const Pose goal = Pokemon::pose_of(Pokemon::story_arg(step.args, "target")); if (at){ - routes.push_back({std::format("{} {}", row, step.name), *at, goal, step.action}); + const MoveSpeed speed = row > std::string(RUNNING_SHOES_ROW) ? MoveSpeed::RUN : MoveSpeed::WALK; + routes.push_back({std::format("{} {}", row, step.name), speed, *at, goal, step.action}); } at = goal; }else{ @@ -356,6 +357,7 @@ std::string sweep_story_route(const StoryRoute& route, bool overshoot, std::vect std::vector notes; SimulatedRouteIO io(*world, from, {}, notes); io.overshoot_timed_holds(overshoot); + io.set_can_run(route.speed == MoveSpeed::RUN); RouteTrainers trainers{.sights = story_trainers(*world), .fight = [](const std::string&){}}; try{ walk_route(io, *world, start, trainers, { @@ -363,7 +365,7 @@ std::string sweep_story_route(const StoryRoute& route, bool overshoot, std::vect .label = route.name, .avoid = {}, .costs = *costs, - .speed = MoveSpeed::WALK, + .speed = route.speed, }); }catch (const RouteFailed& e){ std::string last; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp index a6bea013c2..1c09aa7543 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.cpp @@ -31,8 +31,53 @@ Pokemon::StoryArgSpec optional(std::string key, Pokemon::StoryArgType type, Poke void add_event_actions(std::vector& actions){ for (const auto& [name, unused] : story_events()){ - actions.push_back({.kind = Pokemon::StoryStepKind::GAME, .name = name, .args = {}}); + Pokemon::StoryActionSpec spec{.kind = Pokemon::StoryStepKind::GAME, .name = name, .args = {}}; + // 00.05c's start probe steps west from either save it may start on: + // the Poketch Company's sign stops it, the street does not, so it + // ends on one tile it knows. + if (name == "jubilife_start_probe"){ + spec.certainty = Pokemon::StoryCertainty{.needs = Pokemon::PoseCertainty::SET, .leaves = Pokemon::PoseEnd::WALKED}; + } + actions.push_back(std::move(spec)); + } +} + +// A hold to a wall or onto a map ends on its declared end from any start +// on the map: it is how a step pins an unsure pose. +constexpr Pokemon::StoryCertainty PINS{.needs = Pokemon::PoseCertainty::UNKNOWN, .leaves = Pokemon::PoseEnd::DECLARED}; + +// The LEGS actions, each walking `legs`. +void add_legs_actions( + std::vector& actions, + const Pokemon::StoryArgSpec& legs_arg, const Pokemon::StoryArgSpec& fight_wild +){ + using Pokemon::PoseCertainty; + using Pokemon::PoseEnd; + for (std::string_view act : {"to_wall", "to_map"}){ + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}, .console_only = false, .certainty = PINS}); } + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "to_dialogue", .args = {legs_arg, fight_wild}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::UNKNOWN, .leaves = PoseEnd::GAME_SET}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "one_short_ok", .args = {legs_arg, fight_wild}}); + actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = "counted_wall", .args = {legs_arg, fight_wild}, + .console_only = false, .certainty = Pokemon::StoryCertainty{.needs = PoseCertainty::SET, .leaves = PoseEnd::DECLARED}}); +} + +// The talks to someone who wanders: each walks in D-pad taps, a whole tile +// it counts, and ends on its declared tile. +void add_wanderer_talks(std::vector& actions){ + const Pokemon::StoryArgSpec again = optional("again", Pokemon::StoryArgType::BOOLEAN, false, "a talk with no coupon question counts"); + const Pokemon::StoryCertainty certainty{.needs = Pokemon::PoseCertainty::TILE, .leaves = Pokemon::PoseEnd::DECLARED}; + // Walks the row below his home, asking north. + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {again}, + .console_only = false, .certainty = certainty}); + // Waits for him on a column beside his box (WanderWaitPlan); ends + // against a wall the declared way and one at the column's back. + const Pokemon::StoryArgSpec stand = required( + "stand", Pokemon::StoryArgType::GRID_POSE, "the tiles to wait on, in order, on the start's column; facing his box" + ); + actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "wait_for_wanderer", .args = {stand, again}, + .console_only = false, .certainty = certainty}); } std::vector make_bdsp_actions(){ @@ -66,16 +111,16 @@ std::vector make_bdsp_actions(){ action.args.push_back(opt_legs); } } + const Pokemon::StoryArgSpec opt_avoid{.key = "avoid", .type = Pokemon::StoryArgType::INTEGER_ROWS, .required = false, + .fallback = std::nullopt, .why = "ground on the target's map to keep off: [x, y] tiles, [x0, y0, x1, y1] boxes"}; for (std::string_view cost : {"town", "overworld", "indoors", "caves", "robust", "line", "trigger"}){ - actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs}}); + actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = std::string(cost), .args = {route_target, fight_wild, opt_legs, opt_avoid}}); } actions.push_back({.kind = Pokemon::StoryStepKind::ROUTE, .name = "into_scene", .args = {route_target, fight_wild, legs_arg}}); - for (std::string_view act : {"to_wall", "to_dialogue", "to_map", "one_short_ok", "counted_wall"}){ - actions.push_back({.kind = Pokemon::StoryStepKind::LEGS, .name = std::string(act), .args = {legs_arg, fight_wild}}); - } - actions.push_back({.kind = Pokemon::StoryStepKind::STEP, .name = "to_banner", .args = {direction_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}}); - actions.push_back({.kind = Pokemon::StoryStepKind::TALK, .name = "talk_to_wanderer", .args = {}}); + add_wanderer_talks(actions); actions.push_back({.kind = Pokemon::StoryStepKind::MASH, .name = "a", .args = {}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "starter", .args = {may_lose}}); actions.push_back({.kind = Pokemon::StoryStepKind::BATTLE, .name = "doubles", .args = {may_lose}}); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp index a48158f2ca..5eb4d9dd17 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable_Tests.cpp @@ -55,7 +55,7 @@ const std::map>& built_in_actions(){ {StoryStepKind::LEGS, {"", "legs", "one_short_ok", "to_wall", "to_dialogue", "to_map", "counted_wall", "measured"}}, {StoryStepKind::STEP, {"", "face", "to_banner", "tap", "or_legs"}}, {StoryStepKind::MASH, {"", "a"}}, {StoryStepKind::BATTLE, {"", "fight", "doubles", "starter"}}, - {StoryStepKind::TALK, {"", "talk_to_wanderer"}}, + {StoryStepKind::TALK, {"", "talk_to_wanderer", "wait_for_wanderer"}}, {StoryStepKind::SHOP, {"", "sandgem_potions"}}, }; return actions; @@ -407,6 +407,84 @@ UnitTestResult test_story_routes_keep_off_wander_zones(Logger& logger){ return out.empty() ? UnitTestResult(true) : UnitTestResult("ROUTE steps:" + out); } +// No leg of 00.05b's or 00.05c's routes enters a tile where someone +// wanders, from any tile the player may be on: on lab-B (2026-11-11 21:00) +// the boy below the Mart (51, 33..35) stopped 00.05b's "east 8 (to wall)" +// along row 34 three tiles short; row 36 below him is open. The Mart +// clown's box counts too: the routes reach column 56 and leave it at +// (56, 36) and (56, 31), outside it, and wait_for_wanderer walks the +// column between. +UnitTestResult test_jubilife_routes_cross_no_wander_zone(Logger& logger){ + std::string out; + size_t checked = 0; + for (const PlannedStoryRoute& route : plan_story_routes(logger)){ + if (!route.name.starts_with("00.05b ") && !route.name.starts_with("00.05c ")){ + continue; + } + if (!route.legs){ + out += "\n " + route.name + ": no plan."; + continue; + } + checked++; + const StoryWorld& world = *route.world; + const Pokemon::TileBox clown = jubilife_mart_clown_box(); + const auto [most, leg] = most_zone_tiles(world, route.from, *route.legs, [&](const TilePos& pos){ + const std::optional local = story_to_local(world, "JubilifeCity", pos); + const bool clowns = local && local->x >= clown.x0 && local->x <= clown.x1 && local->y >= clown.y0 && local->y <= clown.y1; + return clowns || wandering_hazard(world, pos); + }); + if (most > 0){ + out += std::format("\n {}: {} enters {} tile(s) where someone wanders.", route.name, leg, most); + } + } + logger.log(std::format("{} Jubilife routes checked.", checked)); + if (checked == 0){ + return "No 00.05b or 00.05c route planned from a known place."; + } + return out.empty() ? UnitTestResult(true) : UnitTestResult("ROUTE steps:" + out); +} + +// Where the walk from `x` on row 22 walks the plaza, or "". +std::string company_clown_plaza_tiles(Logger& logger, TableRoute route, int x){ + route.from = Pokemon::tile_pose("JubilifeCity", {{x, 22}}, Direction::WEST); + const RouteStepPlan plan = plan_table_route(route); + if (!plan.legs){ + return std::format("no plan from ({}, 22).", x); + } + const StoryWorld& world = *route.world; + for (const PlannedLeg& planned : *plan.legs){ + logger.log(std::format("00.05c below_the_company_clown from ({}, 22): {}", x, to_string(planned))); + } + const auto plaza = [&](const TilePos& pos){ + const std::optional local = story_to_local(world, "JubilifeCity", pos); + return local && local->x >= 44 && local->x <= 52 && local->y >= 20 && local->y <= 24; + }; + const auto [most, leg] = most_zone_tiles(world, plan.start, *plan.legs, plaza); + return most == 0 ? "" : std::format("the leg {} walks {} tile(s) of the plaza (44..52, 20..24).", leg, most); +} + +// 00.05c's walk to the Poketch Company's clown from the street +// (57..58, 22), where the checkpoint starts on a rerun from 01.01's start, +// keeps off the plaza (44..52, 20..24). BDSP put the Global Wonder Station +// there, a round wall with people round it that pret's Diamond map lacks: +// on lab-B (2026-11-12 01:22 and 01:55) the walk west from (57, 22) was +// stopped at (50, 22), (51, 21) and (49, 23), and talked to the woman at +// (45, 24) until the step failed. +UnitTestResult test_company_clown_from_the_street_keeps_off_the_plaza(Logger& logger){ + for (const TableRoute& route : table_routes()){ + if (route.row != "00.05c" || route.step->name != "below_the_company_clown" || route.world == nullptr){ + continue; + } + std::string out; + for (int x : {57, 58}){ + const std::string found = company_clown_plaza_tiles(logger, route, x); + out += found.empty() ? "" : "\n " + found; + } + return out.empty() ? UnitTestResult(true) : UnitTestResult("00.05c below_the_company_clown:" + out); + } + return "00.05c below_the_company_clown: not in the table, or from nowhere known."; +} + // 01.08's walk below the Ravaged Path keeps off the row Route 204 South's // youngster_3 wanders, (12, 2) to (14, 2): on lab-B (2026-11-08) the plan // "north 35 (to wall) to (13, 2), west 2 (to wall) to (11, 2)" walked along @@ -530,7 +608,6 @@ std::string route_plans_text(){ // The golden file, in the Data folder beside this file's. std::string route_plans_golden_path(){ - // code-health: allow char_pointer -- std::getenv returns a const char pointer const char* path = std::getenv("PA_ROUTE_PLANS_GOLDEN"); if (path != nullptr && path[0] != '\0'){ return path; @@ -583,7 +660,6 @@ std::string plan_differences(const std::string& golden, const std::string& plann UnitTestResult test_route_plans_golden(Logger& logger){ const std::string path = route_plans_golden_path(); const std::string planned = route_plans_text(); - // code-health: allow char_pointer -- std::getenv returns a const char pointer const char* update = std::getenv("PA_UPDATE_ROUTE_PLANS"); if (update != nullptr && update[0] != '\0' && update[0] != '0'){ std::string crlf; @@ -681,6 +757,14 @@ const AutoStoryStoryTableCase AUTO_STORY_STORY_TABLE_CASES[] = { .input = {"01.08: the walk below the Ravaged Path keeps off the youngster's row (lab-B, 2026-11-08)", test_ravaged_path_keeps_off_the_youngster}, .expectation = {}, }, + { + .input = {"00.05b, 00.05c: no leg enters a wander zone (lab-B, 2026-11-11)", test_jubilife_routes_cross_no_wander_zone}, + .expectation = {}, + }, + { + .input = {"00.05c: from the street (57..58, 22), the walk keeps off the Wonder Station's plaza (lab-B, 2026-11-12)", test_company_clown_from_the_street_keeps_off_the_plaza}, + .expectation = {}, + }, }; void add_tests_AutoStory_StoryTable(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp index cd37db912c..60f97497a9 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.cpp @@ -152,6 +152,26 @@ TappedEnd tapped_end(const StoryWorld& world, const std::string& map, const Tile return tapped; } +std::vector story_route_avoid(const StoryWorld& world, const StoryStep& step){ + if (!step.args.contains("avoid")){ + return {}; + } + const std::string& map = story_arg(step.args, "target").map; + std::vector tiles; + for (const std::vector& row : story_arg>>(step.args, "avoid")){ + if (row.size() != 2 && row.size() != 4){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("{}: an avoid row is [x, y] or [x0, y0, x1, y1].", step.name)); + } + const size_t last = row.size() - 2; + for (int64_t y = row[1]; y <= row[last + 1]; y++){ + for (int64_t x = row[0]; x <= row[last]; x++){ + tiles.push_back(story_to_world(world, map, {(int)x, (int)y})); + } + } + } + return tiles; +} + std::optional measured_ends(const Pose& from, const StoryStep& step){ const StoryWorld* world = story_plan_world(from.map, from.map); const auto& legs_list = story_arg>(step.args, "legs"); @@ -235,7 +255,7 @@ Pose StoryWalkSteps::walk_to(const Pose& from, const Pose& goal, const StoryStep }; const RouteWalkPlan plan{ [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); }, - label_of(step), {}, *costs, m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK, m_scene_next.contains(step.name), + label_of(step), story_route_avoid(*maps, step), *costs, m_can_run ? MoveSpeed::RUN : MoveSpeed::WALK, m_scene_next.contains(step.name), step.action == ROUTE_ONTO_TRIGGER, }; RouteEnd end = walk_route_to_warp(m_route, *maps, start, trainers, plan); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h index 344e2b80c1..844fc8908a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWalkSteps.h @@ -67,6 +67,12 @@ std::optional measured_ends(const Pokemon::Pose& from, const Poke // less those an earlier row fights, whom its save and every later one's // keep beaten. std::vector row_trainers(const StoryWorld& world, const std::string& row); +// The world tiles a ROUTE step's "avoid" rows name on its target's map, +// [x, y] a tile and [x0, y0, x1, y1] a box: ground the maps leave open that +// the walk keeps off (BDSP's Global Wonder Station in Jubilife's plaza, +// which pret's Diamond map lacks). None without the arg. Throws +// InternalProgramError for a row of another length. +std::vector story_route_avoid(const StoryWorld& world, const Pokemon::StoryStep& step); // Executes walking and movement-related story steps via StoryStepIO. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp index 99cb510515..51c5fb16cd 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryWorld_Tests.cpp @@ -3,18 +3,23 @@ * From: https://github.com/PokemonAutomation/ * * StoryWorld on small synthetic maps: what each tile does to a step, maps - * joined at offsets, and tiles blocked or taken off the maps. + * joined at offsets, and tiles blocked or taken off the maps. Also the + * story's own worlds: their connected maps step across every map edge + * where the world grid does. * */ #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Data/PokemonBDSP_AutoStory_StoryMaps.h" #include "Data/PokemonBDSP_AutoStory_StoryWorld.h" #include "Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP_AutoStory_StoryPlaces.h" #include "PokemonBDSP_AutoStory_StoryWorld_Tests.h" namespace PokemonAutomation{ @@ -94,7 +99,7 @@ UnitTestResult test_story_world_steps(Logger&){ {.name = "a west ledge hops west", .rows = {".<."}, .from = {2, 0}, .direction = Direction::WEST, .lands = TilePos{0, 0}}, {.name = "a west ledge stops east", .rows = {".<."}, .direction = Direction::EAST, .at_wall = true}, {.name = "a ledge onto a wall stops", .rows = {".", "v", "#"}, .direction = Direction::SOUTH, .at_wall = true}, - {.name = "a person standing still", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = false}, + {.name = "a person standing still is a wall", .rows = {".", "."}, .standing = {{0, 0}}, .from = {0, 1}, .at_wall = true}, {.name = "a wanderer does not block", .rows = {".", "."}, .wandering = {{0, 0}}, .from = {0, 1}, .lands = TilePos{0, 0}}, }; for (const StepCase& item : cases){ @@ -108,6 +113,16 @@ UnitTestResult test_story_world_steps(Logger&){ return std::format("{}: at_wall() is {}, expected {}.", item.name, !item.at_wall, item.at_wall); } } + { + // Mom talks when bumped (r29): she stops a walk, but is no wall. + MapData map = make_map({".", "."}, {{0, 0}}); + map.name = "PlayerHouse1F"; + map.objects[0].name = "mom_0"; + const StoryWorld world = make_world(map); + if (at_wall(world, {0, 1}, Direction::NORTH) || step(world, {0, 1}, Direction::NORTH).has_value()){ + return "Mom: no wall to stop against, and no step onto her."; + } + } return true; } @@ -219,10 +234,127 @@ const StoryWorldCase STORY_WORLD_CASES[] = { }, }; +namespace{ + +// Whether stepping `direction` from `from` lands on the same map and tile +// on the world grid as on the connected maps (or nowhere on both). +bool steps_agree(const StoryWorld& world, const Pokemon::MapPlace& from, Direction direction){ + const Pokemon::ConnectedMaps connected = connected_maps(world); + const std::string& name = connected.map(from.map).name; + const std::optional grid = world.to_local(world.to_world(name, from.tile).next(direction)); + const std::optional place = connected.neighbour(from, direction); + if (grid && place){ + return grid->map == connected.map(place->map).name && grid->pos == place->tile; + } + return !grid && !place; +} + +// The first step off a map's edge, from any of its tiles, that lands +// somewhere else on the connected maps than on the world grid, or nothing. +std::optional edge_mismatch(const StoryWorld& world){ + const Pokemon::ConnectedMaps connected = connected_maps(world); + for (size_t index = 0; index < connected.size(); index++){ + const Pokemon::Grid& tiles = connected.map(index).tiles; + for (int cell = 0; cell < tiles.width * tiles.height; cell++){ + const TilePos from{cell % tiles.width, cell / tiles.width}; + for (Direction direction : Pokemon::ALL_DIRECTIONS){ + if (tiles.contains(from.next(direction)) || steps_agree(world, {index, from}, direction)){ + continue; + } + return std::format("{} {} {}: the grid and the connected maps disagree.", + connected.map(index).name, Pokemon::to_string(from), Pokemon::direction_name(direction)); + } + } + } + return std::nullopt; +} + +struct ConnectedWorldInput{ + std::string_view name; + // The story's plan world between two places (story_plan_world()), or, + // if `world` is set, that world. + std::string_view plan_from = {}; + std::string_view plan_to = {}; + const StoryWorld& (*world)() = nullptr; +}; +struct ConnectedWorldExpectation{ + // Connections over all the maps: two for each pair that meets. + size_t connections = 0; +}; +struct ConnectedWorldCase{ + ConnectedWorldInput input; + ConnectedWorldExpectation expectation; +}; + +class Test_ConnectedStoryWorld : public UnitTest{ +public: + explicit Test_ConnectedStoryWorld(ConnectedWorldCase test_case) + : UnitTest(std::format("PokemonBDSP::AutoStory - Story world as connected maps: {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const ConnectedWorldInput& input = m_case.input; + const StoryWorld* found = input.world != nullptr + ? &input.world() + : story_plan_world(std::string(input.plan_from), std::string(input.plan_to)); + if (found == nullptr){ + return std::format("No story plan world from {} to {}.", input.plan_from, input.plan_to); + } + const StoryWorld& world = *found; + if (std::optional error = edge_mismatch(world)){ + return *error; + } + const Pokemon::ConnectedMaps connected = connected_maps(world); + size_t connections = 0; + for (size_t index = 0; index < connected.size(); index++){ + connections += connected.map(index).connections.size(); + } + if (connections != m_case.expectation.connections){ + return std::format("{} connections, expected {}.", connections, m_case.expectation.connections); + } + return true; + } + +private: + ConnectedWorldCase m_case; +}; + +const ConnectedWorldCase CONNECTED_WORLD_CASES[] = { + { + .input = {.name = "Route 201, Sandgem and Route 202", .world = story_maps}, + .expectation = {.connections = 4}, + }, + { + .input = {.name = "Twinleaf to Route 202", .plan_from = "TwinleafTown", .plan_to = "Route202"}, + .expectation = {.connections = 8}, + }, + { + .input = {.name = "Route 203 into Jubilife", .plan_from = "Route203", .plan_to = "JubilifeCity"}, + .expectation = {.connections = 2}, + }, + { + .input = {.name = "Jubilife up Route 204's south half", .plan_from = "JubilifeCity", .plan_to = "Route204South"}, + .expectation = {.connections = 2}, + }, + { + .input = {.name = "Route 204's north half into Floaroma", .plan_from = "Route204North", .plan_to = "FloaromaTown"}, + .expectation = {.connections = 2}, + }, + { + .input = {.name = "Jubilife alone", .world = jubilife_maps}, + .expectation = {.connections = 0}, + }, +}; + +} // namespace + void add_tests_AutoStory_StoryWorld(UnitTestDatabase& database){ for (const auto& item : STORY_WORLD_CASES){ database.add(item); } + for (const ConnectedWorldCase& item : CONNECTED_WORLD_CASES){ + database.add(item); + } } diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp index 9f55f5a6c2..7a64bb465e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_TableRoutes.cpp @@ -84,11 +84,19 @@ std::vector world_tiles(const StoryWorld& world, const Pokemon::Pose& p } RouteStepPlan plan_table_route(const TableRoute& route){ - const StoryWorld& world = *route.world; + // As walk_route() plans: the step's avoided tiles off the map, but + // where it starts. + StoryWorld world = *route.world; + const std::vector from = world_tiles(world, *route.from); + for (const TilePos& pos : story_route_avoid(world, *route.step)){ + if (std::find(from.begin(), from.end(), pos) == from.end()){ + world.uncover(pos); + } + } const Pokemon::Pose target = Pokemon::pose_of(story_arg(route.step->args, "target")); const std::vector targets = world_tiles(world, target); const auto goal = [&](const TilePos& pos){ return std::find(targets.begin(), targets.end(), pos) != targets.end(); }; - RouteStepPlan plan{.start = world_tiles(world, *route.from)}; + RouteStepPlan plan{.start = from}; const MoveSpeed speed = route.row > std::string(RUNNING_SHOES_ROW) ? MoveSpeed::RUN : MoveSpeed::WALK; plan.legs = plan_fastest_route({ .world = world, .from = plan.start, .goal = goal, .costs = *story_route_costs(route.step->action), .speed = speed, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp index 8375ffbecc..bf9bd564d3 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_FaultSweep_Tests.cpp @@ -27,6 +27,11 @@ * with no settle() between goes nowhere (lab-B 2026-11-10, 00.04b * heal_sandgem: a fixed 1500 ms wait, then the walk to the nurse * stopped on "transition"). SimWorldKnobs::slow_fade_in. + * - START_OFFSET: the row's save leaves the player 1 to 3 tiles off its + * declared start, each way the player can walk there (00.05, lab-B + * 2026-11-11 15:22: the route planned open legs from Jubilife's declared + * (48, 62), and its third leg walked into a building). + * SimWorldKnobs::start_at. * * Missed and short fades are swept by SimFailureCases_Tests (every single * missed fade, banner and fade hold). @@ -53,6 +58,8 @@ #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryCertainty.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryData.h" #include "Pokemon/Navigation/Pokemon_MapData.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" @@ -78,6 +85,7 @@ enum class FaultClass{ GRASS_BATTLES, SCENE_EARLY, SLOW_FADE_IN, + START_OFFSET, // Not swept yet: the measured movement table's lost taps (#293). LOST_TAP, }; @@ -93,6 +101,8 @@ std::string_view fault_class_name(FaultClass fault){ return "scene starts during the walk before it"; case FaultClass::SLOW_FADE_IN: return "slow fade-in after every warp"; + case FaultClass::START_OFFSET: + return "start off its declared tile"; case FaultClass::LOST_TAP: return "lost tap"; } @@ -105,6 +115,75 @@ constexpr std::string_view LAST_ROW = "01.11"; // Sweeps the program fails today, by test name, with the likely fix. const std::map KNOWN_FAILING{ + {"PokemonBDSP::AutoStory - Fault sweep: 00.01, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.02, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.03, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.04, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.04b, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.05, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.05b, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 00.05c, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.01, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.02, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.02b, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.03, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.05, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.06, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.07, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.08, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.09, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.10, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, + {"PokemonBDSP::AutoStory - Fault sweep: 01.11, start off its declared tile", "a first leg to a wall or funnel that pins the start (as 00.05's walk to the Center)"}, +}; + +// Steps that need a surer pose than the steps before them leave, from +// the table before certainty_gaps(): each is to start on a wall leg or +// a landmark, as 00.05's walk to the Center does. +const std::set KNOWN_CERTAINTY_GAPS{ + "00.01 step 1 below_the_flute: needs tile, has set", + "00.01 step 12 into_barrys_house: needs tile, has set", + "00.01 step 19 down_barrys_stairs: needs tile, has set", + "00.01 step 23 barrys_warning: needs tile, has set", + "00.01 step 26 below_the_lake_entrance: needs tile, has set", + "00.01 step 4 down_the_stairs: needs tile, has set", + "00.01 step 6 above_the_door: needs tile, has set", + "00.02 step 1 to_the_lake_entrance: needs tile, has set", + "00.03 step 1 into_rowans_scene: needs tile, has set", + "00.03 step 3 out_of_the_house_again: needs tile, has set", + "00.04 step 1 out_of_the_lab: needs tile, has set", + "00.04 step 18 short_of_the_catch_tutorial: needs tile, has set", + "00.04 step 2 onto_the_path: needs tile, has set", + "00.04 step 5 to_ledge_column: needs tile, has set", + "00.04 step 7 along_route_201_road: needs tile, has set", + "00.04b step 1 to_catch_grass: needs tile, has set", + "00.04b step 3 into_sandgem: needs tile, has set", + "00.04d step 1 north_to_jubilife: needs tile, has set", + "00.05 step 10 barry: needs tile, has unknown", + "00.05 step 12 out_of_the_school: needs tile, has set", + "00.05b step 1 below_the_presidents_trigger: needs tile, has set", + "00.05b step 10 below_the_company_clown: needs tile, has set", + "00.05b step 4 past_the_president: needs tile, has set", + "00.05c step 12 to_the_route_203_street: needs tile, has set", + "01.01 step 2 west_of_barrys_trigger: needs tile, has set", + "01.02 step 1 south_to_the_cliff: needs tile, has set", + "01.02 step 10 west_of_the_welcome: needs tile, has set", + "01.02 step 4 west_of_the_hikers_trigger: needs tile, has set", + "01.02 step 7 past_curtis: needs tile, has set", + "01.02b step 2 barry: needs tile, has set", + "01.02b step 4 below_the_centers_door: needs tile, has set", + "01.03 step 1 above_the_mine: needs tile, has set", + "01.03 step 11 up_to_the_hall: needs tile, has set", + "01.03 step 15 heal_oreburgh: needs tile, has set", + "01.03 step 8 roark: needs tile, has set", + "01.05 step 2 east_of_barrys_trigger: needs tile, has set", + "01.05 step 8 through_the_gate: needs tile, has set", + "01.06 step 1 up_jubilifes_road: needs tile, has set", + "01.07 step 1 rowans_trigger: needs tile, has set", + "01.08 step 1 west_to_the_wall: needs tile, has set", + "01.09 step 1 west_of_the_rock: needs tile, has set", + "01.09 step 3 above_the_way_out: needs tile, has set", + "01.10 step 1 line_1: needs tile, has set", + "01.11 step 7 old_man: needs tile, has set", }; // Scenes whose end the console has proven, by step name: the sweep leaves @@ -116,6 +195,11 @@ const std::map PROVEN_SCENE_ENDS{ {"rowan_and_dawn", "lab-B 2026-11-09, 7 of 7 runs on (6, 8)"}, }; +// A talk that walks to its end itself: wait_for_wanderer counts its taps +// along one column and ends with taps into two walls that must not move, +// so a tile beside its end fails the step on the console. +constexpr std::string_view WALKS_TO_ITS_END = "wait_for_wanderer"; + // Runs row `row` with `knobs`: "" if it passes, else where and why it stopped. std::string run_row(Logger& logger, const std::string& row, SimWorldKnobs knobs){ SimExecutor executor(logger, {.fade = {}, .banner = {}}, std::move(knobs)); @@ -183,6 +267,20 @@ bool wild_or_trainers(const StoryStep& step){ // reach from it in one or two steps, and not in `seen`: where a scene can // leave them instead. A tile behind a wall is not one, nor a door's: a // step onto it goes through (00.04's moms_hat by the house's door). +// The tile next to `tile` toward `direction`. +TilePos step_from(const TilePos& tile, Direction direction){ + switch (direction){ + case Direction::NORTH: + return TilePos{tile.x, tile.y - 1}; + case Direction::SOUTH: + return TilePos{tile.x, tile.y + 1}; + case Direction::WEST: + return TilePos{tile.x - 1, tile.y}; + default: + return TilePos{tile.x + 1, tile.y}; + } +} + void walkable_neighbors(const StoryWorld* world, const Pose& pose, const TilePos& center, std::set>& seen, std::vector& out){ const auto step = [](const TilePos& tile, Direction direction){ switch (direction){ @@ -270,7 +368,7 @@ UnitTestResult sweep_scene_end_pose(Logger& logger, const StoryCheckpoint& row){ size_t variants = 0; for (size_t c = 0; c < row.steps.size(); c++){ const StoryStep& step = row.steps[c]; - if (!game_sets_end(step.kind) || !step.pose_after || PROVEN_SCENE_ENDS.contains(step.name) || + if (!game_sets_end(step.kind) || step.action == WALKS_TO_ITS_END || !step.pose_after || PROVEN_SCENE_ENDS.contains(step.name) || already_there(logger, row, c, Pokemon::pose_of(*step.pose_after))){ continue; } @@ -336,6 +434,40 @@ UnitTestResult sweep_slow_fade_in(Logger& logger, const StoryCheckpoint& row){ return sweep_result(logger, FaultClass::SLOW_FADE_IN, row.id, 1, failures); } +// Row `row` from 1 to 3 tiles off its declared start, each way the +// player can walk from it, one at a time. +UnitTestResult sweep_start_offset(Logger& logger, const StoryCheckpoint& row){ + std::vector failures; + size_t variants = 0; + if (!row.start){ + return sweep_result(logger, FaultClass::START_OFFSET, row.id, variants, failures); + } + const Pose start = Pokemon::pose_of(*row.start); + const std::vector tiles = Pokemon::tiles_of(start); + const StoryWorld* world = start.map.empty() ? nullptr : story_plan_world(start.map, start.map); + if (world == nullptr || tiles.empty()){ + return sweep_result(logger, FaultClass::START_OFFSET, row.id, variants, failures); + } + for (Direction direction : {Direction::NORTH, Direction::SOUTH, Direction::WEST, Direction::EAST}){ + TilePos at = tiles.front(); + for (int off = 1; off <= 3; off++){ + GridSim sim(SimWorld{.world = world}, story_to_world(*world, start.map, at), direction, false); + if (!detail::sim_can_step(sim, direction)){ + break; + } + at = step_from(at, direction); + SimWorldKnobs knobs; + knobs.start_at = Pokemon::tile_pose(start.map, {at}, Pokemon::facing_of(start)); + variants++; + const std::string stopped = run_row(logger, row.id, std::move(knobs)); + if (!stopped.empty()){ + failures.push_back({"", std::format("starts on ({}, {})", at.x, at.y), stopped}); + } + } + } + return sweep_result(logger, FaultClass::START_OFFSET, row.id, variants, failures); +} + // The route before scene step `c` of `steps`, right before it or before // the plain step onto its trigger; none if there is none. std::optional route_before_scene(const std::vector& steps, size_t c){ @@ -452,6 +584,8 @@ class Test_AutoStoryFaultSweep : public UnitTest{ return sweep_scene_early(logger, m_row); case FaultClass::SLOW_FADE_IN: return sweep_slow_fade_in(logger, m_row); + case FaultClass::START_OFFSET: + return sweep_start_offset(logger, m_row); case FaultClass::LOST_TAP: break; } @@ -462,6 +596,33 @@ class Test_AutoStoryFaultSweep : public UnitTest{ const StoryCheckpoint& m_row; }; +// No step of the table needs a surer pose than the steps before it leave +// (Pokemon_StoryCertainty.h), but those on KNOWN_CERTAINTY_GAPS. +class Test_AutoStoryCertainty : public UnitTest{ +public: + Test_AutoStoryCertainty() + : UnitTest("PokemonBDSP::AutoStory - Certainty: no step walks from a pose surer than the steps before leave") + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + std::string out; + size_t known = 0; + for (const StoryCheckpoint& row : story_checkpoints()){ + for (const std::string& gap : Pokemon::certainty_gaps(row, bdsp_story_actions())){ + logger.log("Certainty gap: " + gap); + if (KNOWN_CERTAINTY_GAPS.contains(gap)){ + known++; + continue; + } + out += "\n " + gap; + } + } + if (known != KNOWN_CERTAINTY_GAPS.size()){ + out += std::format("\n {} of the {} known gaps are gone: take them off KNOWN_CERTAINTY_GAPS.", KNOWN_CERTAINTY_GAPS.size() - known, KNOWN_CERTAINTY_GAPS.size()); + } + return out.empty() ? UnitTestResult(true) : UnitTestResult("Certainty gaps:" + out); + } +}; + } // namespace const FaultSweepCase FAULT_SWEEP_CASES[] = { @@ -470,9 +631,11 @@ const FaultSweepCase FAULT_SWEEP_CASES[] = { {.input = {.fault = FaultClass::GRASS_BATTLES}, .expectation = {}}, {.input = {.fault = FaultClass::SCENE_EARLY}, .expectation = {}}, {.input = {.fault = FaultClass::SLOW_FADE_IN}, .expectation = {}}, + {.input = {.fault = FaultClass::START_OFFSET}, .expectation = {}}, }; void add_tests_AutoStory_FaultSweep(UnitTestDatabase& database){ + database.add(); for (const FaultSweepCase& item : FAULT_SWEEP_CASES){ for (const StoryCheckpoint& row : story_checkpoints()){ if (row.id < FIRST_ROW || row.id > LAST_ROW){ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp index 882756c124..e835a17caa 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp @@ -61,7 +61,6 @@ const std::map KNOWN_FAILING{ {"01.05 through_the_gate is one run west", "planner: goal kinds and ms costs (PLANNER_DESIGN.md)"}, {"any one missed fade or banner from 00.00 to 01.11: every row still passes", "a third signal where a warp gives one (ONE_SIGNAL_STEPS): position (PLANNER_DESIGN.md 2, 4)"}, - {"01.08 with Route 204's youngster wandering (12..14, 2)", "planner: one recovery rule, a sidestep round a wanderer (PLANNER_DESIGN.md 4, 7)"}, }; // Warps that give one signal only (#268 slice 1: door = fade or banner), so @@ -330,6 +329,18 @@ UnitTestResult nurse_in_one_run(Logger&){ return true; } +// 00.05b with the boy below the Mart (school_kid_m_5, who wanders x 51, +// y 33..35) standing on (51, `row`), and a push against him reading as +// stopped only 1600 ms late, as on lab-B 2026-11-11 21:00 ("east 8 (to +// wall)" along row 34 stopped after 2800 ms about 5 tiles in, and the +// route went on from the wall). +std::string boy_below_the_mart(Logger& logger, int row){ + SimWorldKnobs knobs; + knobs.standing = {{"school_kid_m_5", TilePos{51, row}}}; + knobs.pushing_someone = 1600ms; + return run_case(logger, "00.05b", "00.05b", {.fade = {}, .banner = {}}, std::move(knobs)); +} + // 01.07: after the tag battle the screen fades back from the battle and // the grunts run off before anyone speaks: a scene that opens with no box, // 6 s of people moving (Rowan's cutscene shape), then Rowan's and Dawn's @@ -415,6 +426,44 @@ UnitTestResult sandgem_entry_two_columns_west(Logger& logger){ return passes(run_case(logger, "00.04b", "00.04b", {.fade = {}, .banner = {}}, std::move(knobs))); } +// 00.05c on lab-B 2026-11-11: 00.05b's Poketch Company clown was +// "answered" by the sign's text, so the save held two coupons; the +// president gave no Poketch and 00.05c went on to the street as passed. +// `misread` re-runs that read in 00.05c's own talk too. "" when the run +// stopped at 00.05c's Poketch check, as it must when a coupon is still +// missing. +std::string poketch_run(Logger& logger, bool misread){ + SimWorldKnobs knobs; + knobs.coupons_at_start = {"mart_clown", "tv_clown"}; + knobs.poketch_at_start = false; + if (misread){ + knobs.talks_without_coupon = {"company_clown"}; + } + return run_case(logger, "00.05c", "00.05c", {.fade = {}, .banner = {}}, std::move(knobs)); +} +UnitTestResult no_poketch_fails_00_05c(Logger& logger){ + const std::string stopped = poketch_run(logger, true); + if (stopped.find("00.05c poketch") == std::string::npos){ + return UnitTestResult("expected a stop at 00.05c's Poketch check; got " + (stopped.empty() ? std::string("a pass") : stopped)); + } + return true; +} +UnitTestResult missing_coupon_collected_in_00_05c(Logger& logger){ + return passes(poketch_run(logger, false)); +} +// 01.01 from a save with no Poketch: Jubilife's east-exit guard would +// ask about the Poketch campaign and turn us back (lab-B 2026-11-11, the +// walk took him for a trainer); the row stops at its first step instead. +UnitTestResult gate_guard_stops_01_01(Logger& logger){ + SimWorldKnobs knobs; + knobs.poketch_at_start = false; + const std::string stopped = run_case(logger, "01.01", "01.01", {.fade = {}, .banner = {}}, std::move(knobs)); + if (stopped.find("01.01 poketch_before_the_gate") == std::string::npos){ + return UnitTestResult("expected a stop at 01.01's Poketch check; got " + (stopped.empty() ? std::string("a pass") : stopped)); + } + return true; +} + // 00.03: Rowan's scene ends at home on (6, 8) beside Mom (lab-B // 2026-11-09, 7 of 7 runs). The way out holds south onto the door's tile // (6, 10); from a column west, (5, 8), the hold stops on (5, 10) with no @@ -662,6 +711,12 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { {.input = {"01.08 with Route 204's youngster wandering (12..14, 2)", [](Logger& logger){ return wanderers_move(logger, "01.08"); }}, .expectation = {}}, + {.input = {"00.05b with Jubilife's people wandering (the clowns, the boy below the Mart on 51, 33..35)", [](Logger& logger){ + return wanderers_move(logger, "00.05b"); + }}, .expectation = {}}, + {.input = {"00.05c with Jubilife's people wandering (the clowns, the boy below the Mart on 51, 33..35)", [](Logger& logger){ + return wanderers_move(logger, "00.05c"); + }}, .expectation = {}}, {.input = {"01.04 Roark's badge speech: the fanfare's pause, then a scene", roark_badge_speech}, .expectation = {}}, {.input = {"inside a Pokemon Center, the door's settle ends within 3 s of the fade-up with visitors walking, never during the fade", center_inside_settles}, .expectation = {}}, {.input = {"inside a Pokemon Center, one held run north from the door mat reaches the nurse", nurse_in_one_run}, .expectation = {}}, @@ -675,6 +730,17 @@ const FailureCase AUTO_STORY_FAILURE_CASES[] = { {.input = {"00.04 Mom's call fires above the mat, on (6, 9): the walk ends in it, her hat scene plays it (lab-B 2026-11-09 17:29)", moms_call_above_the_mat}, .expectation = {}}, {.input = {"00.04 the old walk round Mom to (6, 9) runs into her call: it hands it to her hat scene, not fights it (lab-B 2026-11-09 17:29)", old_walk_hands_moms_call_over}, .expectation = {}}, {.input = {"00.04b the run into Sandgem stops two columns west: the walk still ends below the Center's door (lab-B 2026-11-09 20:09)", sandgem_entry_two_columns_west}, .expectation = {}}, + {.input = {"00.05b the boy below the Mart stands on row 34: the walk to the Mart clown goes round his zone (lab-B 2026-11-11 21:00)", [](Logger& logger){ + return passes(boy_below_the_mart(logger, 34)); + }}, .expectation = {}}, + {.input = {"00.05b someone stands in the walk's way on row 36: a wall leg held up is not at its wall (lab-B 2026-11-11 21:00)", [](Logger& logger){ + const std::string stopped = boy_below_the_mart(logger, 36); + return stopped.find("sim_mismatch") == std::string::npos ? UnitTestResult(true) + : UnitTestResult("the program went on from a tile the player is not on: " + stopped); + }}, .expectation = {}}, + {.input = {"00.05c a coupon missing (the sign read for the Poketch Company clown): no Poketch, 00.05c fails (lab-B 2026-11-11)", no_poketch_fails_00_05c}, .expectation = {}}, + {.input = {"00.05c a coupon missing from 00.05b: its clown talks collect it, the president gives the Poketch", missing_coupon_collected_in_00_05c}, .expectation = {}}, + {.input = {"01.01 with no Poketch: the east-exit guard's gate stops the row at its check, not a trainer fight (lab-B 2026-11-11)", gate_guard_stops_01_01}, .expectation = {}}, {.input = {"00.04 to the ledge column with a wild battle on each pass through Route 201's grass (lab-B 2026-11-09 16:14)", [](Logger& logger){ return passes(ledge_walk_in_grass(logger, {})); }}, .expectation = {}}, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp new file mode 100644 index 0000000000..45c0a6156c --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp @@ -0,0 +1,113 @@ +/* BDSP AutoStory - Wait beside a wanderer, on the simulation + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h" +#include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h" +#include "PokemonBDSP_AutoStory_SimWanderWait.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using Pokemon::Direction; +using Pokemon::TilePos; + + +SimWanderWait::SimWanderWait(GridSim& sim, std::vector still) + : m_sim(sim) + , m_still(std::move(still)) +{} +bool SimWanderWait::step(Direction direction){ + return m_sim.tap(direction, ROUTE_MS_PER_TILE_ACROSS, false).distance > 0; +} +void SimWanderWait::face(Direction direction){ + m_sim.tap(direction, 50ms, false); +} +bool SimWanderWait::ask(){ + const TilePos faced = nearest_tile(m_sim.player().pos).next(m_sim.player().facing); + bool someone = std::find(m_still.begin(), m_still.end(), faced) != m_still.end(); + for (const SimWanderer& wanderer : detail::sim_wanderers(m_sim)){ + someone |= wanderer.pos == faced; + } + // Whoever is faced answers: the world leaves a wanderer's box empty, + // so the press alone misses one standing on his spawn. + m_sim.press_a(); + m_sim.end_dialogue(); + detail::sim_advance_time(m_sim, 1500ms); + return someone; +} +void SimWanderWait::wait(Milliseconds time){ + detail::sim_advance_time(m_sim, time); +} + + +WanderWaitPlan wander_wait_plan(const Pokemon::StoryStep& step){ + const Pokemon::GridPose& stand = Pokemon::story_arg(step.args, "stand"); + const Pokemon::Pose exit = Pokemon::pose_of(*step.pose_after); + const Direction back = Pokemon::ALL_DIRECTIONS[((size_t)*stand.facing + 2) % 4]; + return WanderWaitPlan{.stands = stand.tiles, .facing = *stand.facing, + .exit = Pokemon::tiles_of(exit).at(0), .exit_walls = {*Pokemon::facing_of(exit), back}}; +} + + +namespace{ + +// The plan's tiles on `world`. +WanderWaitPlan on_world(WanderWaitPlan plan, const StoryWorld& world, const std::string& map){ + for (TilePos& stand : plan.stands){ + stand = story_to_world(world, map, stand); + } + plan.exit = story_to_world(world, map, plan.exit); + return plan; +} + +// Where the people of `map` the simulation does not walk stand: their +// spawns, on `world`. +std::vector still_people(const GridSim& sim, const StoryWorld& world, const std::string& map){ + std::vector out; + const std::vector& walking = detail::sim_wanderers(sim); + for (const Pokemon::MapObject& object : story_map(map).objects){ + const bool walks = std::ranges::any_of(walking, [&](const SimWanderer& wanderer){ return wanderer.name == object.name; }); + if (object.kind == Pokemon::ObjectKind::NPC && !walks){ + out.push_back(story_to_world(world, map, {object.x, object.y})); + } + } + return out; +} + +} // namespace + + +Pokemon::Outcome sim_wait_for_wanderer(GridSim& sim, const StoryWorld& world, const Pokemon::Pose& start, const Pokemon::StoryStep& step){ + const TilePos from = story_to_world(world, start.map, Pokemon::tiles_of(start).at(0)); + SimWanderWait body(sim, still_people(sim, world, start.map)); + const WanderWaitResult result = wait_beside_wanderer(body, from, on_world(wander_wait_plan(step), world, start.map)); + const std::string at = Pokemon::to_string(result.at); + switch (result.end){ + case WanderWaitEnd::TALKED: + return Pokemon::outcome_ok(); + case WanderWaitEnd::NO_TALK: + return Pokemon::outcome_failed("operation_failed", std::format("{}: no talk from any stand tile; on {}.", step.name, at)); + case WanderWaitEnd::STUCK: + return Pokemon::outcome_failed("operation_failed", std::format("{}: a step along the column stayed blocked at {}.", step.name, at)); + case WanderWaitEnd::LOST: + return Pokemon::outcome_failed("operation_failed", std::format("{}: a step from the exit moved to {}: not on the column.", step.name, at)); + } + return Pokemon::outcome_failed("operation_failed", step.name + ": unknown wait end."); +} + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h new file mode 100644 index 0000000000..6fc3498c4a --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h @@ -0,0 +1,56 @@ +/* BDSP AutoStory - Wait beside a wanderer, on the simulation + * + * From: https://github.com/PokemonAutomation/ + * + * wait_beside_wanderer() on the grid simulation: the wander wait tests' + * body, and the story simulation's wait_for_wanderer step. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_SimWanderWait_H +#define PokemonAutomation_PokemonBDSP_AutoStory_SimWanderWait_H + +#include +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_StoryWorld.h" +#include "PokemonBDSP_AutoStory_GridSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The wait on the simulation: a tap a tile, A at the faced tile, and the +// console's time per ask (the dialog watch). An ask talks to a wanderer +// on the faced tile, or to someone on one of `still` (world tiles): the +// people the simulation does not walk. +class SimWanderWait : public WanderWaitBody{ +public: + explicit SimWanderWait(GridSim& sim, std::vector still = {}); + virtual bool step(Pokemon::Direction direction) override; + virtual void face(Pokemon::Direction direction) override; + virtual bool ask() override; + virtual void wait(Milliseconds time) override; + +private: + GridSim& m_sim; + std::vector m_still; +}; + +// The wait plan of a wait_for_wanderer step, as the console reads it, in +// its map's tiles. +WanderWaitPlan wander_wait_plan(const Pokemon::StoryStep& step); + +// Plays wait_for_wanderer `step` on `sim`, on `world`, from the tile of +// `start` (its map's): the console's wait (wait_for_wanderer()), its +// failures named as there. Who on the map has no wanderer on `sim` +// stands on their spawn. +Pokemon::Outcome sim_wait_for_wanderer(GridSim& sim, const StoryWorld& world, const Pokemon::Pose& start, const Pokemon::StoryStep& step); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp index 7e63509263..8df64c2a21 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -18,6 +18,7 @@ #include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryPlaces.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkResult.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_WalkScreen.h" +#include "PokemonBDSP_AutoStory_SimWanderWait.h" #include "PokemonBDSP_AutoStory_StorySim.h" namespace PokemonAutomation{ @@ -281,7 +282,16 @@ void SimKnobRouteIO::check_fade_in(const std::string& label){ WalkResult SimKnobRouteIO::walk_to_wall(const RouteWallWalk& walk){ check_fade_in(walk.label); - return GridSimRouteIO::walk_to_wall(walk); + WalkResult result = GridSimRouteIO::walk_to_wall(walk); + const TilePos ahead = nearest_tile(m_grid.player().pos).next(walk.direction); + const std::vector& people = sim_wanderers(m_grid); + const bool pushing = std::any_of(people.begin(), people.end(), [&](const SimWanderer& person){ + return person.pos == ahead; + }); + if (result.stop == WalkStop::BLOCKED && pushing){ + result.walked += m_knobs.pushing_someone; + } + return result; } WalkResult SimKnobRouteIO::walk_taps(Direction direction, size_t tiles, const std::string& label){ @@ -436,7 +446,7 @@ bool on_world(const StoryWorld& world, const std::string& map){ // (SimWorldKnobs::wander_seed), each with their own seed and start time. std::vector SimExecutor::wanderers(const StoryWorld& world) const{ std::vector out; - if (!m_knobs.wander_seed){ + if (!m_knobs.wander_seed && m_knobs.standing.empty()){ return out; } for (const auto& [map, json] : bdsp_map_json()){ @@ -444,20 +454,22 @@ std::vector SimExecutor::wanderers(const StoryWorld& world) const{ continue; } for (const auto& object : story_map(map).objects){ - if (!object.wander){ + const auto stands = m_knobs.standing.find(object.name); + if (!object.wander || (!m_knobs.wander_seed && stands == m_knobs.standing.end())){ continue; } - const uint64_t seed = *m_knobs.wander_seed * 1000003 + out.size() * 7919 + (uint64_t)(object.x * 31 + object.y); + const uint64_t seed = m_knobs.wander_seed.value_or(0) * 1000003 + out.size() * 7919 + (uint64_t)(object.x * 31 + object.y); const TilePos low = story_to_world(world, map, {object.wander->x0, object.wander->y0}); const TilePos high = story_to_world(world, map, {object.wander->x1, object.wander->y1}); + const bool still = stands != m_knobs.standing.end(); out.push_back({ .name = object.name, .box = {.x0 = low.x, .y0 = low.y, .x1 = high.x, .y1 = high.y}, - .pos = story_to_world(world, map, {object.x, object.y}), + .pos = story_to_world(world, map, still ? stands->second : TilePos{object.x, object.y}), .seed = seed, - .step_interval = Milliseconds(2000), + .step_interval = still ? Milliseconds(0) : Milliseconds(2000), .elapsed = Milliseconds(0), - .time_offset = Milliseconds((int64_t)(seed % 2000)), + .time_offset = still ? Milliseconds(0) : Milliseconds((int64_t)(seed % 2000)), }); } } @@ -507,6 +519,14 @@ bool SimExecutor::sync(const Pose& pose, const StoryWorld* on){ if (local && on_grid(player.pos) && std::find(tiles.begin(), tiles.end(), *local) != tiles.end()){ return true; } + const std::optional& start_at = m_knobs.start_at; + if (!m_placed && start_at && start_at->map == pose.map && !Pokemon::tiles_of(*start_at).empty()){ + m_sim.place(setup(world), story_to_world(*world, pose.map, Pokemon::tiles_of(*start_at).front()), Pokemon::facing_of(pose)); + m_placed = true; + m_misplaced = true; + m_logger.log(std::format("[{}] the save leaves the player on {}, off the declared {}.", m_row, to_string(*start_at), to_string(pose))); + return true; + } m_sim.place(setup(world), story_to_world(*world, pose.map, tiles.front()), Pokemon::facing_of(pose)); m_placed = true; return true; @@ -545,6 +565,7 @@ void SimExecutor::start_scene_at_end(const StoryStep& step){ } void SimExecutor::land(const std::string& step){ + count_coupons(step); const auto lands = m_knobs.lands.find(step); if (lands == m_knobs.lands.end()){ return; @@ -657,12 +678,30 @@ Outcome SimExecutor::stub(){ return Pokemon::outcome_ok(); } +void SimExecutor::count_coupons(const std::string& step){ + static const std::set CLOWNS{"mart_clown", "tv_clown", "company_clown"}; + if (CLOWNS.contains(step) && !m_knobs.talks_without_coupon.contains(step)){ + m_coupons.insert(step); + } + if (step == "president"){ + m_poketch = m_coupons.size() == CLOWNS.size(); + m_logger.log(std::format("[{}] president: {} coupons, {}.", m_row, m_coupons.size(), m_poketch ? "the Poketch" : "no Poketch")); + } +} + // The steps that need the console: stubbed, but for the Center's door and // the speeches after a battle. StoryBoundActions SimExecutor::sim_actions(){ const auto stubbed = [this](const StoryStep&, RunState&){ return stub(); }; + // Played from where the step before left us, on its map. + const auto wait_for_wanderer = [this, stubbed](const StoryStep& step, RunState& state){ + if (!sync(state.pose)){ + return stubbed(step, state); + } + return sim_wait_for_wanderer(m_sim, m_sim.world(), state.pose, step); + }; return StoryBoundActions{ .new_game = stubbed, .options = stubbed, @@ -675,7 +714,15 @@ StoryBoundActions SimExecutor::sim_actions(){ return heal(state, step); }, .save = stubbed, - .event = [stubbed](const std::string&) -> Pokemon::StoryActionFunction{ + .event = [this, stubbed, wait_for_wanderer](const std::string& name) -> Pokemon::StoryActionFunction{ + if (name == "check_poketch"){ + return [this](const StoryStep& step, RunState&){ + return m_poketch ? Pokemon::outcome_ok() : Pokemon::outcome_failed("no_poketch", step.name + ": no Poketch on the screen."); + }; + } + if (name == "wait_for_wanderer"){ + return wait_for_wanderer; + } return stubbed; }, }; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h index d467e53da6..b73e7a9884 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.h @@ -155,6 +155,16 @@ struct SimWorldKnobs{ std::map fade_into = {}; // People with a wander box on their map walk it, a step tried every 2 s. std::optional wander_seed = std::nullopt; + // People with a wander box who stand still on a tile of their map + // instead, by name, with or without wander_seed: 00.05b's boy below + // the Mart (school_kid_m_5, x 51, y 33..35) on row 34. + std::map standing = {}; + // How much longer a hold into someone standing still takes to read as + // stopped: the screen moves on while we push against them. On lab-B + // (2026-11-11 21:00, 00.05b) "east 8 (to wall)" stopped against the boy + // below the Mart after 2800 ms, about 5 tiles in, where a free run + // stops at its wall after about 2000. + Milliseconds pushing_someone = Milliseconds(0); // How long after the A press a talk's first line shows, by step name. std::map first_line = {}; // The scene a step's talk-over plays, by step name: a scene's or a @@ -188,6 +198,18 @@ struct SimWorldKnobs{ // goes nowhere (lab-B 2026-11-10, 00.04b heal_sandgem walked to the // nurse 1500 ms after the Center's fade and stopped on "transition"). bool slow_fade_in = false; + // Where the first row's save really leaves the player, when that is not + // its declared start: the program starts from the declared start, the + // player from here (00.05, lab-B 2026-11-11: two tiles off). + std::optional start_at = std::nullopt; + // Jubilife's coupons (00.05b, 00.05c): the clown talks, by step name, + // whose coupon the save holds at the run's start; the clown talks that + // read another line first and give none (lab-B 2026-11-11: the + // Poketch Company's sign); and whether the save has the Poketch. The + // president's talk gives it with all three coupons only. + std::set coupons_at_start = {"mart_clown", "tv_clown", "company_clown"}; + std::set talks_without_coupon = {}; + bool poketch_at_start = true; }; namespace detail{ @@ -434,6 +456,8 @@ class SimExecutor : public Pokemon::TableExecutor{ , m_walks(m_io) , m_table(story_action_table(m_walks, sim_actions())) , m_interrupts(story_interrupts([this](bool fresh){ return look(fresh); }, sim_interrupt_actions())) + , m_coupons(m_knobs.coupons_at_start) + , m_poketch(m_knobs.poketch_at_start) { if (m_knobs.clear_interrupts){ set_interrupts(&m_interrupts); @@ -492,6 +516,8 @@ class SimExecutor : public Pokemon::TableExecutor{ // A step the simulation does not play: its dialogue opened and closed. Pokemon::Outcome stub(); + // A clown's coupon or the president's Poketch, after step `step` passed. + void count_coupons(const std::string& step); StoryBoundActions sim_actions(); // The screen between steps: the dialog that popped up, if one did; a // battle's opening, its battle on the OPENING_LOOKS-th look. `fresh` @@ -507,7 +533,8 @@ class SimExecutor : public Pokemon::TableExecutor{ bool sync(const Pokemon::Pose& pose, const StoryWorld* on = nullptr); // Puts a trigger on walk `step`'s last tiles (SimWorldKnobs::scene_at_walk_end). void start_scene_at_end(const Pokemon::StoryStep& step); - // Puts the player where SimWorldKnobs::lands says `step` leaves them, if it says. + // Puts the player where SimWorldKnobs::lands says `step` leaves them, if + // it says, and counts its coupon or Poketch (count_coupons()). void land(const std::string& step); bool cross(); bool cross_to(const Pokemon::Pose& far); @@ -543,6 +570,9 @@ class SimExecutor : public Pokemon::TableExecutor{ mutable std::map, std::unique_ptr> m_peopled; // The steps of this row that have run. std::set m_ran; + // The clowns' coupons held and the Poketch (SimWorldKnobs::coupons_at_start). + std::set m_coupons; + bool m_poketch = true; std::string m_row; std::vector m_armed; // Where the step running now ends, if it says: a door's far side. diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp index 56af9971a4..ab45e4972d 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim_Tests.cpp @@ -43,6 +43,7 @@ #include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" #include "PokemonBDSP_AutoStory_GridSim.h" #include "PokemonBDSP_AutoStory_LegTrace_Tests.h" +#include "PokemonBDSP_AutoStory_WanderWait_Tests.h" #include "PokemonBDSP_AutoStory_OldStorySteps.h" #include "PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.h" #include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h" @@ -386,6 +387,7 @@ void add_tests_AutoStory_StorySim(UnitTestDatabase& database){ } add_tests_AutoStoryResources(database); add_tests_AutoStory_LegTrace(database); + add_tests_AutoStory_WanderWait(database); } } // namespace PokemonBDSP diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp index e2d0bdc8e9..6c917376ed 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.cpp @@ -543,6 +543,11 @@ UnitTestResult test_gives_up_after_attempts(Logger&){ return true; } +// Events that leave the player where they were: the look at the Poketch, +// and 00.05c's start probe, whose step west the Poketch Company's sign +// stops on 00.05b's end, (14, 19). +const std::set EVENTS_IN_PLACE{"check_poketch", "jubilife_start_probe"}; + // Each row that has a start pose starts where the row before it leaves // the player, by the same planning and walking the fake run does. UnitTestResult test_poses_chain(Logger&){ @@ -577,6 +582,8 @@ UnitTestResult test_poses_chain(Logger&){ } at = walked.at; measured = walked.measured; + }else if (step.kind == StoryStepKind::GAME && EVENTS_IN_PLACE.contains(step.action)){ + // Where it was. }else if (step.kind == StoryStepKind::GAME || step.kind == StoryStepKind::SHOP || step.kind == StoryStepKind::MASH){ // A scene or an event: where it ends is the table's to say. at.reset(); diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp new file mode 100644 index 0000000000..f22d1d1731 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp @@ -0,0 +1,212 @@ +/* BDSP AutoStory Wander Wait Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The Mart clown wanders (54..56, 32..34) round (55, 33). 00.05b and + * 00.05c wait for him on column 56 facing west (wait_for_wanderer): these + * run that wait on the simulation with him starting on each tile of his + * box, and pick the tile to wait on first. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Events.h" +#include "PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_Maps.h" +#include "PokemonBDSP/Programs/AutoStory/PokemonBDSP_AutoStory_StoryTable.h" +#include "PokemonBDSP_AutoStory_GridSim.h" +#include "PokemonBDSP_AutoStory_SimWanderWait.h" +#include "PokemonBDSP_AutoStory_WanderWait_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using Pokemon::Direction; +using Pokemon::TileBox; +using Pokemon::TilePos; + + +namespace{ + +// Jubilife alone, with the Mart clown wandering his box instead of +// standing on (55, 33). One map at (0, 0): world tiles are its own. +StoryWorld clown_world(){ + Pokemon::MapData map = story_map("JubilifeCity"); + for (Pokemon::MapObject& object : map.objects){ + if (object.name == "clown_mart"){ + object.wander = jubilife_mart_clown_box(); + } + } + StoryWorld world; + world.add("JubilifeCity", map, {0, 0}); + return world; +} + +// The step `name` of row `row`. +const Pokemon::StoryStep& story_step(const std::string& row, const std::string& name){ + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + if (checkpoint.id != row){ + continue; + } + for (const Pokemon::StoryStep& step : checkpoint.steps){ + if (step.name == name){ + return step; + } + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No step {} in row {}.", name, row)); +} + +// Where the clown may start: each tile of his box but `player`'s. +std::vector clown_starts(const TilePos& player){ + std::vector starts; + const TileBox box = jubilife_mart_clown_box(); + for (int y = box.y0; y <= box.y1; y++){ + for (int x = box.x0; x <= box.x1; x++){ + if (TilePos{x, y} != player){ + starts.push_back({x, y}); + } + } + } + return starts; +} + +// The wait from `start` with the clown starting on `clown`, his walk +// seeded by `seed`. +WanderWaitResult run_wait(const StoryWorld& world, const TilePos& start, const TilePos& clown, uint64_t seed, const WanderWaitPlan& plan){ + const SimWanderer wanderer{.name = "clown_mart", .box = jubilife_mart_clown_box(), .pos = clown, .seed = seed}; + GridSim sim({.world = &world, .wanderers = {wanderer}}, start, Direction::NORTH, false); + SimWanderWait body(sim); + const WanderWaitResult result = wait_beside_wanderer(body, start, plan); + if (nearest_tile(sim.player().pos) != result.at){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("the wait counted {}, the player is on {}.", + Pokemon::to_string(result.at), Pokemon::to_string(nearest_tile(sim.player().pos)))); + } + return result; +} + +constexpr uint64_t SEEDS = 8; + +// 00.05b comes up column 56 from the wall (56, 36), 00.05c down it from +// (56, 31): from each, the wait talks to the clown wherever in his box he +// starts, over seeds 1 to 8, and ends on (56, 31). +UnitTestResult test_mart_clown_reached_from_column_56(Logger& logger){ + const StoryWorld world = clown_world(); + std::string out; + size_t runs = 0; + for (const auto& [row, start] : {std::pair{"00.05b", {56, 36}}, {"00.05c", {56, 31}}}){ + const WanderWaitPlan plan = wander_wait_plan(story_step(row, "mart_clown")); + for (const TilePos& clown : clown_starts(start)){ + for (uint64_t seed = 1; seed <= SEEDS; seed++){ + runs++; + const WanderWaitResult result = run_wait(world, start, clown, seed, plan); + if (result.end != WanderWaitEnd::TALKED || result.at != plan.exit){ + out += std::format("\n {} with the clown on {}, seed {}: ended {} on {}.", row, + Pokemon::to_string(clown), seed, (int)result.end, Pokemon::to_string(result.at)); + } + } + } + } + logger.log(std::format("{} waits run.", runs)); + return out.empty() ? UnitTestResult(true) : UnitTestResult(std::format("The wait missed the clown:{}", out)); +} + +// How many of the clown's starts and seeds one stand tile alone talks +// to him from, facing west, within the plan's asks. +size_t talks_from(const StoryWorld& world, const TilePos& stand, const WanderWaitPlan& table_plan){ + WanderWaitPlan plan = table_plan; + plan.stands = {stand}; + plan.rounds = 1; + size_t talks = 0; + for (const TilePos& clown : clown_starts(stand)){ + for (uint64_t seed = 1; seed <= SEEDS; seed++){ + talks += run_wait(world, stand, clown, seed, plan).end == WanderWaitEnd::TALKED ? 1 : 0; + } + } + return talks; +} + +// The first stand tile is the one of (56, 32..34) the simulation finds +// the clown level with most often. +UnitTestResult test_mart_clown_first_stand(Logger& logger){ + const StoryWorld world = clown_world(); + const WanderWaitPlan plan = wander_wait_plan(story_step("00.05b", "mart_clown")); + size_t best = 0; + int best_y = 0; + for (int y = 32; y <= 34; y++){ + const size_t talks = talks_from(world, {56, y}, plan); + logger.log(std::format("From (56, {}): {} talks of {} starts and seeds.", y, talks, clown_starts({56, y}).size() * SEEDS)); + if (talks > best){ + best = talks; + best_y = y; + } + } + for (const std::string row : {"00.05b", "00.05c"}){ + const TilePos first = wander_wait_plan(story_step(row, "mart_clown")).stands.at(0); + if (first != TilePos{56, best_y}){ + return std::format("{} waits first on {}; the simulation talks most from (56, {}).", row, Pokemon::to_string(first), best_y); + } + } + return true; +} + +struct WanderWaitInput{ + std::string name; + std::function body; +}; +struct WanderWaitExpectation{}; +struct WanderWaitCase{ + WanderWaitInput input; + WanderWaitExpectation expectation; +}; + +class Test_AutoStoryWanderWait : public UnitTest{ +public: + explicit Test_AutoStoryWanderWait(WanderWaitCase test_case) + : UnitTest(std::format("PokemonBDSP::AutoStory - {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + WanderWaitCase m_case; +}; + +const WanderWaitCase WANDER_WAIT_CASES[] = { + {.input = {"Wander wait: the Mart clown is reached from column 56 wherever he starts (00.05b, 00.05c)", + test_mart_clown_reached_from_column_56}, .expectation = {}}, + {.input = {"Wander wait: the Mart clown's first stand tile is where the simulation meets him most", + test_mart_clown_first_stand}, .expectation = {}}, +}; + +} // namespace + + +void add_tests_AutoStory_WanderWait(UnitTestDatabase& database){ + for (const auto& item : WANDER_WAIT_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h new file mode 100644 index 0000000000..71f8d051f2 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h @@ -0,0 +1,25 @@ +/* BDSP AutoStory Wander Wait Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_Tests_H +#define PokemonAutomation_PokemonBDSP_AutoStory_WanderWait_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// The wait for the Mart clown on column 56 (00.05b, 00.05c), on the +// simulation with him wandering his box. +void add_tests_AutoStory_WanderWait(UnitTestDatabase& database); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json index 666569b83e..51020597df 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.04d.plan.json @@ -148,8 +148,8 @@ "map": "JubilifeCity", "tiles": [ [ - 48, - 62 + 46, + 58 ] ] }, @@ -162,8 +162,8 @@ "map": "JubilifeCity", "tiles": [ [ - 48, - 62 + 46, + 58 ] ] }, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json index fe94d37361..0753479fbd 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05.plan.json @@ -2,23 +2,314 @@ "checkpoint": { "events": [ { - "action": "town", "args": { "fight_wild": false, - "target": { - "facing": "north", - "map": "JubilifeCity", - "tiles": [ - [ - 52, - 41 - ] + "legs": [ + { + "direction": "north", + "tiles": 4 + } + ] + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 43, + 51 + ], + [ + 44, + 51 + ], + [ + 45, + 51 + ], + [ + 46, + 51 + ], + [ + 47, + 51 + ], + [ + 48, + 51 + ], + [ + 49, + 51 + ], + [ + 43, + 52 + ], + [ + 44, + 52 + ], + [ + 45, + 52 + ], + [ + 46, + 52 + ], + [ + 47, + 52 + ], + [ + 48, + 52 + ], + [ + 49, + 52 + ], + [ + 44, + 53 + ], + [ + 45, + 53 + ], + [ + 46, + 53 + ], + [ + 47, + 53 + ], + [ + 48, + 53 + ], + [ + 43, + 54 + ], + [ + 44, + 54 + ], + [ + 45, + 54 + ], + [ + 46, + 54 + ], + [ + 47, + 54 + ], + [ + 48, + 54 + ], + [ + 49, + 54 + ], + [ + 43, + 55 + ], + [ + 44, + 55 + ], + [ + 45, + 55 + ], + [ + 46, + 55 + ], + [ + 47, + 55 + ], + [ + 48, + 55 + ], + [ + 49, + 55 + ], + [ + 43, + 56 + ], + [ + 44, + 56 + ], + [ + 45, + 56 + ], + [ + 46, + 56 + ], + [ + 47, + 56 + ], + [ + 48, + 56 + ], + [ + 49, + 56 + ], + [ + 43, + 57 + ], + [ + 44, + 57 + ], + [ + 45, + 57 + ], + [ + 46, + 57 + ], + [ + 47, + 57 + ], + [ + 48, + 57 + ], + [ + 49, + 57 ] - } + ] }, - "id": "to_the_center", - "kind": "route", - "why": "below the Center's door (52, 40)" + "id": "north_onto_the_plaza", + "kind": "legs", + "why": "4 taps up from (46, 58) onto row 54, just below the lamps on row 53 (console, lab-B 2026-11-11); from 3 tiles off any way the start may be, it ends on rows 51 to 57" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "east", + "tiles": 10 + } + ] + }, + "declared_after": { + "facing": "east", + "map": "JubilifeCity", + "tiles": [ + [ + 52, + 51 + ], + [ + 52, + 52 + ], + [ + 52, + 53 + ], + [ + 52, + 54 + ], + [ + 52, + 55 + ], + [ + 52, + 56 + ], + [ + 52, + 57 + ] + ] + }, + "id": "east_to_the_wall", + "kind": "legs", + "why": "the small brick building's west wall (x 53, rows 51 to 57; on console against it from row 54) pins the column" + }, + { + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "west", + "tiles": 1 + } + ] + }, + "id": "off_the_wall", + "kind": "legs", + "why": "a column west, out of the way of the child north of column 52" + }, + { + "action": "to_wall", + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "north", + "tiles": 20 + } + ] + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 51, + 41 + ] + ] + }, + "id": "north_to_the_center", + "kind": "legs", + "why": "up column 51 to the Center's front wall: a tile west of its door (52, 40)" + }, + { + "args": { + "fight_wild": false, + "legs": [ + { + "direction": "east", + "tiles": 1 + } + ] + }, + "id": "below_the_centers_door", + "kind": "legs", + "why": "east under the door (52, 40)" }, { "id": "heal_jubilife", @@ -115,8 +406,8 @@ "map": "JubilifeCity", "tiles": [ [ - 48, - 62 + 46, + 58 ] ] }, diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json index 8021fabee4..4daa0c242e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05b.plan.json @@ -70,31 +70,51 @@ "map": "JubilifeCity", "tiles": [ [ - 55, - 34 + 56, + 36 ] ] } }, "id": "below_the_mart_clown", "kind": "route", - "why": "up the road east of the Center" + "why": "along row 36, below the boy by the Mart, to the wall east of the Center" }, { - "action": "talk_to_wanderer", + "action": "wait_for_wanderer", + "args": { + "stand": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 56, + 33 + ], + [ + 56, + 34 + ], + [ + 56, + 32 + ] + ] + } + }, "declared_after": { "facing": "north", "map": "JubilifeCity", "tiles": [ [ - 55, - 34 + 56, + 31 ] ] }, "id": "mart_clown", "kind": "talk", - "why": "the clown by the Mart: 'Do Pokemon grow by defeating others?' Yes; Coupon 1" + "why": "the clown by the Mart (wanders 54..56, 32..34): wait on column 56 facing west until he comes level, A about every 2 s; 'Do Pokemon grow by defeating others?' Yes; Coupon 1. Ends north against the wall at (56, 30)" }, { "action": "town", @@ -113,7 +133,7 @@ }, "id": "below_the_tv_clown", "kind": "route", - "why": "west and north to the TV station" + "why": "west along row 31, above the boy below the Mart, and north to the TV station" }, { "id": "tv_clown", @@ -170,6 +190,35 @@ "id": "company_clown", "kind": "talk", "why": "the clown by the Poketch Company: 'Do moves have types?' Yes; Coupon 2" + }, + { + "action": "line", + "args": { + "fight_wild": false, + "target": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 14, + 19 + ] + ] + } + }, + "declared_after": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 14, + 19 + ] + ] + }, + "id": "beside_the_company_sign", + "kind": "route", + "why": "west 1 against the Poketch Company's signboard (13, 19): the bump pins the tile the save is made on (console 2026-11-11: a save believed at (15, 19) was in the Poketch lobby)" } ], "id": "00.05b", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json index cc4053cbae..5bf12d8a0b 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-00.05c.plan.json @@ -2,26 +2,97 @@ "checkpoint": { "events": [ { - "action": "line", + "action": "jubilife_start_probe", + "id": "where_we_start", + "kind": "game_action", + "why": "a step west: the Poketch Company's sign (14, 19) blocks it (00.05b's end); on the street (58, 22) it goes (a rerun from 01.01's start when no Poketch came)" + }, + { + "action": "town", "args": { + "avoid": [ + [ + 44, + 20, + 52, + 24 + ] + ], "fight_wild": false, "target": { - "facing": "south", + "facing": "north", "map": "JubilifeCity", "tiles": [ [ 15, - 22 + 19 ] ] } }, - "id": "to_main_boulevard", + "id": "below_the_company_clown", "kind": "route", - "why": "south to the main boulevard" + "why": "below the Poketch Company's clown" }, { - "action": "line", + "action": "talk_to_wanderer", + "args": { + "again": true + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 15, + 19 + ] + ] + }, + "id": "company_clown", + "kind": "talk", + "why": "his coupon again, or his talk if he gave it (00.05b's, lab-B 2026-11-11: a coupon went missing)" + }, + { + "action": "town", + "args": { + "fight_wild": false, + "target": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 36, + 17 + ] + ] + } + }, + "id": "below_the_tv_clown", + "kind": "route", + "why": "east to the TV station" + }, + { + "action": "talk_to_wanderer", + "args": { + "again": true + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 36, + 17 + ] + ] + }, + "id": "tv_clown", + "kind": "talk", + "why": "his coupon again, or his talk if he gave it" + }, + { + "action": "town", "args": { "fight_wild": false, "target": { @@ -29,18 +100,55 @@ "map": "JubilifeCity", "tiles": [ [ - 45, - 22 + 56, + 31 ] ] } }, - "id": "along_main_boulevard", + "id": "below_the_mart_clown", "kind": "route", - "why": "east along the main boulevard" + "why": "east along row 31, above the Mart clown's box, to the wall (57, 31)" }, { - "action": "line", + "action": "wait_for_wanderer", + "args": { + "again": true, + "stand": { + "facing": "west", + "map": "JubilifeCity", + "tiles": [ + [ + 56, + 33 + ], + [ + 56, + 34 + ], + [ + 56, + 32 + ] + ] + } + }, + "declared_after": { + "facing": "north", + "map": "JubilifeCity", + "tiles": [ + [ + 56, + 31 + ] + ] + }, + "id": "mart_clown", + "kind": "talk", + "why": "his coupon again, or his talk if he gave it: wait on column 56 facing west, as in 00.05b" + }, + { + "action": "town", "args": { "fight_wild": false, "target": { @@ -56,7 +164,7 @@ }, "id": "beside_the_president", "kind": "route", - "why": "south down column 45 to the Poketch president" + "why": "from the wall north of column 56 round the boy below the Mart to the Poketch president" }, { "id": "president", @@ -78,6 +186,12 @@ "kind": "scene", "why": "the coupons for the Poketch; he walks off north" }, + { + "action": "check_poketch", + "id": "poketch", + "kind": "game_action", + "why": "the Poketch on the screen (R): without it the president had too few coupons, and Jubilife's east-exit guard (60, 21..24) turns us back in 01.01" + }, { "action": "line", "args": { @@ -100,16 +214,16 @@ ], "id": "00.05c", "start": { - "facing": "north", + "facing": "west", "map": "JubilifeCity", "tiles": [ [ - 15, + 14, 19 ] ] }, - "title": "Jubilife: the Poketch, up to the street east to Route 203" + "title": "Jubilife: the clowns' coupons again, the Poketch, up to the street east to Route 203" }, "execution": { "on_failure": "reload_and_retry", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json index e44f7cbc0b..5eed96c24f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.01.plan.json @@ -1,6 +1,12 @@ { "checkpoint": { "events": [ + { + "action": "check_poketch", + "id": "poketch_before_the_gate", + "kind": "game_action", + "why": "Jubilife's east-exit guard (the coord event on (60, 21..24)) asks about the Poketch campaign and turns back anyone without one (lab-B 2026-11-11): fail here, not in a walk that takes him for a trainer" + }, { "action": "town", "args": { diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json index 387cad3518..49909bfaff 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/StoryData/bdsp-01.08.plan.json @@ -39,14 +39,14 @@ "tiles": [ [ 11, - 2 + 3 ] ] } }, "id": "below_the_ravaged_path", "kind": "route", - "why": "north out of Jubilife, up Route 204's street and grass to below the door (11, 1)" + "why": "north out of Jubilife, up Route 204's street and grass to (11, 3), two tiles below the door (11, 1), clear of the youngster on row 2" }, { "action": "to_banner", @@ -65,7 +65,7 @@ }, "id": "into_the_ravaged_path", "kind": "step", - "why": "the door (11, 1)" + "why": "north up column 11 through the door (11, 1): the walk's last leg goes into the door, not to a tile before it" } ], "id": "01.08", diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp index d54cb520d8..178553ff52 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp @@ -18,7 +18,7 @@ #include "PokemonBDSP_AutoStory_RouteChoice.h" #include "PokemonBDSP_AutoStory_CountedWallLeg.h" #include "PokemonBDSP_AutoStory_PlannedRoute.h" -#include "PokemonBDSP_AutoStory_PlannedTalk.h" +#include "PokemonBDSP_AutoStory_RouteSteps.h" #include "PokemonBDSP_AutoStory_WalkDpad.h" namespace PokemonAutomation{ @@ -88,6 +88,21 @@ std::string map_of(const StoryWorld& maps, const std::vector& tiles){ } // namespace +[[noreturn]] void fail(RouteIO& io, const std::string& message){ + io.note(message, RouteNote::FAILURE); + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "RouteIO::note() returned from a failure: " + message); +} + +void turn(RouteIO& io, Direction direction){ + io.note(std::string("[Route] Turning ") + direction_name(direction) + ".", RouteNote::LOG); + io.press(route_turn_tap(direction)); +} + +RouteInput press_a(RouteInputEnd end){ + return {.kind = RouteInputKind::BUTTON_A, .direction = Direction::NORTH, .hold = 80ms, .release = 200ms, + .count = 1, .end = end}; +} + namespace{ // Sorted by row, then column, without repeats. @@ -116,24 +131,6 @@ Milliseconds wall_limit(const TileLeg& leg){ return ROUTE_START_DELAY + per_tile * leg.tiles * 5 / 4 + 1000ms; } -// Fails the program with `message` (RouteNote::FAILURE). -[[noreturn]] void fail(RouteIO& io, const std::string& message){ - io.note(message, RouteNote::FAILURE); - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "RouteIO::note() returned from a failure: " + message); -} - -// route_turn() through `io`. -void turn(RouteIO& io, Direction direction){ - io.note(std::string("[Route] Turning ") + direction_name(direction) + ".", RouteNote::LOG); - io.press(route_turn_tap(direction)); -} - -// A press of A, to talk to someone in front of us. -RouteInput press_a(RouteInputEnd end){ - return {.kind = RouteInputKind::BUTTON_A, .direction = Direction::NORTH, .hold = 80ms, .release = 200ms, - .count = 1, .end = end}; -} - // A wait for someone walking about to get out of the way. constexpr RouteInput WAIT_FOR_THE_WAY{.kind = RouteInputKind::WAIT, .direction = Direction::NORTH, .hold = 2500ms, .release = 0ms, .count = 1, .end = RouteInputEnd::DONE}; @@ -164,6 +161,24 @@ bool never_moved(const WalkResult& walk, size_t walked_tiles){ return walk.stop == WalkStop::BLOCKED && walk.moved_chunks == 0 && walked_tiles == 0; } +// Whether a walk to the wall that stopped took far longer than the tiles +// to its nearest wall `nearest` allow, past the walker's slack: two of its +// 400 ms chunks, or 30% of the tiles' time on a long leg. Something held +// it up on the way, and its time no longer counts tiles. On lab-B +// (2026-11-11 21:00, 00.05b) "east 8 (to wall)" stopped after 2800 ms +// against a boy below the Mart, about 5 tiles in, with 5 moved chunks +// where an 8-tile run moves about 3; the time counted 17 tiles, and the +// route went on from (56, 34) as if at the wall. +bool held_up(const WalkResult& walk, size_t nearest, Milliseconds per_tile){ + if (walk.stop != WalkStop::BLOCKED || walk.wild_battles > 0){ + return false; + } + const Milliseconds tiles_time = per_tile * nearest; + const Milliseconds slack = std::max(800ms, tiles_time * 3 / 10); + // 800 ms: the two still chunks that read as stopped (tiles_moved()). + return walk.walked > ROUTE_START_DELAY + tiles_time + 800ms + slack; +} + // Legs to a wall this many tiles or shorter must walk every tile: a tile // short is someone in the way, not the time count's slack. On lab-B // (2026-11-08, 01.08) Route 204's youngster stopped "west 2 (to wall)" @@ -184,6 +199,8 @@ enum class LegNext{ ARRIVED_EARLY, // through a warp at the leg's end (walk_route_to_warp()) SCENE, // the next step's scene started (RouteWalkPlan::scene_next) }; +// What stopped a walk where the map has nothing (see mark_blocker()). +enum class Blocker{ THING, PERSON }; // How far past a leg's end a walk that ran on may have gone. constexpr size_t WARP_SLIDE_TILES = 2; @@ -248,6 +265,7 @@ class RouteWalker{ bool finish_interrupted_wall(LegWalk& walk, Milliseconds limit); size_t unstick_wall_leg(LegWalk& walk, size_t walked_tiles, size_t nearest); LegNext stopped_short_of_wall(LegWalk& walk, size_t walked_tiles); + LegNext held_up_on_the_way(const LegWalk& walk, size_t nearest); void check_at_wall(LegWalk& walk, size_t walked_tiles = SIZE_MAX, size_t expected_tiles = SIZE_MAX); void on_to_wall(LegWalk& walk); @@ -256,6 +274,8 @@ class RouteWalker{ LegNext interrupted_open_leg(LegWalk& walk); void turn_tap(LegWalk& walk); LegNext blocked_open_leg(LegWalk& walk, size_t moved); + LegNext talking_blocker(LegWalk& walk, size_t moved); + LegNext mark_and_replan(LegWalk& walk, size_t moved, Blocker blocker); // After each leg. void check_banners(LegWalk& walk); @@ -264,9 +284,9 @@ class RouteWalker{ LegNext unknown_trainer(LegWalk& walk, const std::vector>& paths); LegNext known_trainer(LegWalk& walk, const std::vector>& paths, const std::vector& watching); - void talk_to_blocker(const std::string& leg_label); + Blocker talk_to_blocker(const std::string& leg_label); LegNext replan_from(const LegWalk& walk, std::vector stopped, const std::string& why); - void mark_blocker(const LegWalk& walk, const std::vector& stopped); + void mark_blocker(const LegWalk& walk, const std::vector& stopped, Blocker blocker); void mark_tiles_past(const LegWalk& walk, const std::vector& stopped); RouteIO& m_io; @@ -416,6 +436,10 @@ LegNext RouteWalker::wall_leg(LegWalk& walk){ direction_name(leg.direction) + ": " + std::to_string(nearest) + " tiles in " + std::to_string(walk.result.walked.count()) + " ms to the wall.", RouteNote::LOG); } + // Checked on the first walk only: one after a wait starts part way. + if (nearest != SIZE_MAX && walked_tiles >= nearest && held_up(walk.result, nearest, route_ms_per_tile(leg.direction, m_plan.speed))){ + return held_up_on_the_way(walk, nearest); + } walked_tiles = unstick_wall_leg(walk, walked_tiles, nearest); // Any stop short of the wall's distance: someone who stays put is // talked to, and the leg is planned again from where we are. Within the @@ -500,7 +524,7 @@ size_t RouteWalker::unstick_wall_leg(LegWalk& walk, size_t walked_tiles, size_t LegNext RouteWalker::stopped_short_of_wall(LegWalk& walk, size_t walked_tiles){ // Someone who stays put: talk to them. A trainer we walked up to from // the side starts the battle this way. - talk_to_blocker(walk.label); + const Blocker blocker = talk_to_blocker(walk.label); // A walk that never moved is where it began (never_moved()); any other // stop may be a tile either side of the tiles its time counts. const size_t last = never_moved(walk.result, walked_tiles) ? 0 : walked_tiles + 1; @@ -515,7 +539,7 @@ LegNext RouteWalker::stopped_short_of_wall(LegWalk& walk, size_t walked_tiles){ if (stopped.empty()){ fail(m_io, walk.label + ": stopped early, and no tile fits."); } - mark_blocker(walk, stopped); + mark_blocker(walk, stopped, blocker); if (never_moved(walk.result, walked_tiles)){ mark_tiles_past(walk, stopped); } @@ -598,6 +622,9 @@ LegNext RouteWalker::open_leg(LegWalk& walk){ std::to_string(leg.tiles) + " tiles; waiting for the way to clear.", RouteNote::WARNING); m_io.press(WAIT_FOR_THE_WAY); const WalkResult rest = m_io.walk_taps(leg.direction, leg.tiles - moved, walk.label + ": the rest"); + if (rest.stop == WalkStop::DIALOG && rest.moved_chunks == 0 && rest.wild_battles == 0){ + return talking_blocker(walk, moved); + } moved = std::min(leg.tiles, moved + rest.moved_chunks); walk.result.stop = rest.stop; walk.result.walked += rest.walked; @@ -649,14 +676,27 @@ void RouteWalker::turn_tap(LegWalk& walk){ } LegNext RouteWalker::blocked_open_leg(LegWalk& walk, size_t moved){ - talk_to_blocker(walk.label); + return mark_and_replan(walk, moved, talk_to_blocker(walk.label)); +} + +// Someone in the way who talks as we tap on after the wait is the one who +// blocked us, not a trainer the map lacks (lab-B 2026-11-12, 00.05c). +LegNext RouteWalker::talking_blocker(LegWalk& walk, size_t moved){ + m_io.note(walk.label + ": someone in the way talked to us; going round them.", RouteNote::STATUS); + m_trainers.fight("someone in the way"); + return mark_and_replan(walk, moved, Blocker::PERSON); +} + +// The tiles a blocked open leg may have stopped on after `moved` tiles: +// what stopped it goes on the map, and the walk plans again from them. +LegNext RouteWalker::mark_and_replan(LegWalk& walk, size_t moved, Blocker blocker){ std::vector stopped; for (const TilePos& pos : m_from){ const std::vector path = leg_path(m_grid, pos, walk.planned.leg.direction, moved); stopped.push_back(moved == 0 || path.empty() ? pos : path[std::min(moved, path.size()) - 1]); } stopped = sorted_unique(std::move(stopped)); - mark_blocker(walk, stopped); + mark_blocker(walk, stopped, blocker); if (moved == 0){ mark_tiles_past(walk, stopped); } @@ -831,25 +871,27 @@ LegNext RouteWalker::known_trainer(LegWalk& walk, const std::vector& stopped){ +// What stopped us on one tile is on the next; a person's comes off our map: no wall (00.05c). +void RouteWalker::mark_blocker(const LegWalk& walk, const std::vector& stopped, Blocker blocker){ if (stopped.size() != 1){ return; } - const TilePos blocker = stopped[0].next(walk.planned.leg.direction); - m_grid.block(blocker); - m_io.note("[Route] " + walk.label + ": something the map lacks is at " + - describe(m_maps, blocker) + "; marked it.", RouteNote::WARNING); + const TilePos pos = stopped[0].next(walk.planned.leg.direction); + const bool person = blocker == Blocker::PERSON; + person ? m_grid.uncover(pos) : m_grid.block(pos); + m_io.note(std::format("[Route] {}: {} the map lacks is at {}; marked it{}", walk.label, person ? "someone" : "something", + describe(m_maps, pos), person ? " (no wall to stop against)." : "."), RouteNote::WARNING); } // A walk that never moved from several possible tiles: whatever stopped it @@ -877,6 +919,26 @@ void RouteWalker::mark_tiles_past(const LegWalk& walk, const std::vector stopped; + for (const TilePos& pos : m_from){ + if (walk.result.moved_chunks == 0){ + stopped.push_back(pos); + } + const std::vector path = leg_path(m_grid, pos, walk.planned.leg.direction, nearest); + stopped.insert(stopped.end(), path.begin(), path.end()); + } + stopped = sorted_unique(std::move(stopped)); + if (stopped.empty()){ + fail(m_io, walk.label + ": held up on the way, and no tile fits."); + } + return replan_from(walk, std::move(stopped), std::format("held up on the way ({} ms for {} tiles to the wall)", + walk.result.walked.count(), nearest)); +} + LegNext RouteWalker::replan_from(const LegWalk& walk, std::vector stopped, const std::string& why){ m_io.note(std::format("{}{}", ROUTE_LOG_TAG, route_replan_line(m_plan.label, route_log_leg(walk.planned.leg), why, route_tiles(m_maps, stopped))), RouteNote::WARNING); m_facing = walk.planned.leg.direction; @@ -915,45 +977,6 @@ RouteEnd walk_route_to_warp( } -void talk_to_npc( - VideoStream& stream, ProControllerContext& context, const WildBattleEscape& escape, - const StoryWorld& maps, std::vector& at, - RouteTrainers& trainers, const NpcTalk& talk -){ - ConsoleRouteIO io(stream, context, escape); - talk_to_npc(io, maps, at, trainers, talk); -} - -void talk_to_npc( - RouteIO& io, const StoryWorld& maps, std::vector& at, - RouteTrainers& trainers, const NpcTalk& talk -){ - for (Direction side : talk.sides){ - const TilePos stand = talk.npc.next(side); - if (!standable(maps, stand)){ - continue; - } - at = walk_route(io, maps, at, trainers, { - .goal = [stand](const TilePos& pos){ return pos == stand; }, - .label = talk.label, - .avoid = {}, - .costs = route_plan_costs(), - }); - // Face the NPC: the opposite of the side we stand on. - const Direction face = - side == Direction::NORTH ? Direction::SOUTH : - side == Direction::SOUTH ? Direction::NORTH : - side == Direction::EAST ? Direction::WEST : Direction::EAST; - turn(io, face); - io.press(press_a(RouteInputEnd::DONE)); - if (io.dialog_within(2000ms, COLOR_CYAN)){ - io.note(talk.label + ": talking from " + describe(maps, stand) + ".", RouteNote::STATUS); - return; - } - io.note(talk.label + ": nobody answered from " + describe(maps, stand) + "; trying another side.", RouteNote::STATUS); - } - fail(io, talk.label + ": no side of " + describe(maps, talk.npc) + " started a dialogue."); -} namespace{ diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp new file mode 100644 index 0000000000..3a3b1ee3a6 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp @@ -0,0 +1,65 @@ +/* BDSP AutoStory - Planned talk + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_PlanCosts.h" +#include "PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_WalkRules.h" +#include "PokemonBDSP_AutoStory_PlannedTalk.h" +#include "PokemonBDSP_AutoStory_RouteSteps.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + +using namespace std::chrono_literals; +using namespace Pokemon; + + +void talk_to_npc( + VideoStream& stream, ProControllerContext& context, const WildBattleEscape& escape, + const StoryWorld& maps, std::vector& at, + RouteTrainers& trainers, const NpcTalk& talk +){ + ConsoleRouteIO io(stream, context, escape); + talk_to_npc(io, maps, at, trainers, talk); +} + +void talk_to_npc( + RouteIO& io, const StoryWorld& maps, std::vector& at, + RouteTrainers& trainers, const NpcTalk& talk +){ + for (Direction side : talk.sides){ + const TilePos stand = talk.npc.next(side); + if (!standable(maps, stand)){ + continue; + } + at = walk_route(io, maps, at, trainers, { + .goal = [stand](const TilePos& pos){ return pos == stand; }, + .label = talk.label, + .avoid = {}, + .costs = route_plan_costs(), + }); + // Face the NPC: the opposite of the side we stand on. + const Direction face = + side == Direction::NORTH ? Direction::SOUTH : + side == Direction::SOUTH ? Direction::NORTH : + side == Direction::EAST ? Direction::WEST : Direction::EAST; + turn(io, face); + io.press(press_a(RouteInputEnd::DONE)); + if (io.dialog_within(2000ms, COLOR_CYAN)){ + io.note(talk.label + ": talking from " + describe(maps, stand) + ".", RouteNote::STATUS); + return; + } + io.note(talk.label + ": nobody answered from " + describe(maps, stand) + "; trying another side.", RouteNote::STATUS); + } + fail(io, talk.label + ": no side of " + describe(maps, talk.npc) + " started a dialogue."); +} + + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp index 58f9d9604e..b5f91a50d4 100644 --- a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp @@ -177,6 +177,30 @@ std::vector> run_variants(const ScoredRoute& route, cons return out; } +// The tiles where someone wanders that `legs` enter, from every tile of +// `from`: a run on to a wall or a trigger may enter a zone the route's own +// plan keeps off (RobustPlanCosts::per_wander_tile). +size_t wander_tiles_entered(const StoryWorld& world, std::vector from, const std::vector& legs){ + size_t out = 0; + for (const PlannedLeg& planned : legs){ + for (const TilePos& start : from){ + TilePos at = start; + size_t walked = 0; + while (planned.leg.ends_at_wall || walked < planned.leg.tiles){ + const std::optional next = step(world, at, planned.leg.direction); + if (!next){ + break; + } + walked += (size_t)(std::abs(next->x - at.x) + std::abs(next->y - at.y)); + at = *next; + out += wandering_hazard(world, at) ? 1 : 0; + } + } + from = planned.after; + } + return out; +} + bool same_legs(const std::vector& a, const std::vector& b){ return std::equal(a.begin(), a.end(), b.begin(), b.end(), [](const PlannedLeg& x, const PlannedLeg& y){ return x.leg.direction == y.leg.direction && x.leg.tiles == y.leg.tiles && @@ -364,7 +388,14 @@ std::optional> plan_fastest_route(const ScoredRoute& rou const bool own_passes = own.verdict == Pokemon::RouteVerdict::PASS; const size_t own_back = Pokemon::tiles_walked_back(route_scored_legs(*best, route.speed)); double best_ms = own_passes ? own.expected_ms : -1; + // With costs that keep out of wander zones (town_plan_costs()), a plan + // that enters none is not swapped for a faster one that does. + const bool own_clear = route.costs.per_wander_tile > TilePlanCosts().per_wander_tile && + wander_tiles_entered(route.world, route.from, *best) == 0; for (std::vector& legs : candidates){ + if (own_clear && wander_tiles_entered(route.world, route.from, legs) > 0){ + continue; + } const Pokemon::RouteScore score = score_with(route, legs, replan); if (score.verdict != Pokemon::RouteVerdict::PASS || (best_ms >= 0 && score.expected_ms >= best_ms)){ continue; diff --git a/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h new file mode 100644 index 0000000000..debc220639 --- /dev/null +++ b/SerialPrograms/Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h @@ -0,0 +1,34 @@ +/* BDSP AutoStory - Route steps + * + * From: https://github.com/PokemonAutomation/ + * + * What the planned route and the planned talk both do through a RouteIO. + * + */ + +#ifndef PokemonAutomation_PokemonBDSP_AutoStory_RouteSteps_H +#define PokemonAutomation_PokemonBDSP_AutoStory_RouteSteps_H + +#include +#include "PokemonBDSP_AutoStory_RouteInput.h" +#include "PokemonBDSP_AutoStory_RouteIO.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonBDSP{ + + +// Fails the program with `message` (RouteNote::FAILURE). +[[noreturn]] void fail(RouteIO& io, const std::string& message); + +// route_turn() through `io`. +void turn(RouteIO& io, Pokemon::Direction direction); + +// A press of A, to talk to someone in front of us. +RouteInput press_a(RouteInputEnd end); + + +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e23e5d23fc..fcbcfa94db 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1465,6 +1465,10 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Inference/Pokemon_TrainPokemonOCR.h Source/Pokemon/Inference/Pokemon_TypeReader.cpp Source/Pokemon/Inference/Pokemon_TypeReader.h + Source/Pokemon/Navigation/Pokemon_ConnectedMaps.cpp + Source/Pokemon/Navigation/Pokemon_ConnectedMaps.h + Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.cpp + Source/Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h Source/Pokemon/Navigation/Pokemon_Direction.cpp Source/Pokemon/Navigation/Pokemon_Direction.h Source/Pokemon/Navigation/Pokemon_Grid.cpp @@ -1484,6 +1488,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_LegTrace.h Source/Pokemon/Navigation/Pokemon_LegTrace_Tests.cpp Source/Pokemon/Navigation/Pokemon_LegTrace_Tests.h + Source/Pokemon/Navigation/Pokemon_RobustLegPlanner.h + Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp + Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.h Source/Pokemon/Navigation/Pokemon_LegWalker.cpp Source/Pokemon/Navigation/Pokemon_LegWalker.h Source/Pokemon/Navigation/Pokemon_LegWalker_Tests.cpp @@ -1492,6 +1499,9 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_MapData.h Source/Pokemon/Navigation/Pokemon_MapData_Tests.cpp Source/Pokemon/Navigation/Pokemon_MapData_Tests.h + Source/Pokemon/Navigation/Pokemon_MoveMechanics.h + Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.cpp + Source/Pokemon/Navigation/Pokemon_MoveMechanics_Tests.h Source/Pokemon/Navigation/Pokemon_RuntimeMap.cpp Source/Pokemon/Navigation/Pokemon_RuntimeMap.h Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp @@ -1600,6 +1610,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.cpp Source/Pokemon/AutoStory/Pokemon_StoryActions_Tests.h Source/Pokemon/AutoStory/Pokemon_StoryCheckpointTypes.h + Source/Pokemon/AutoStory/Pokemon_StoryCertainty.cpp + Source/Pokemon/AutoStory/Pokemon_StoryCertainty.h Source/Pokemon/AutoStory/Pokemon_StoryEvent.h Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp Source/Pokemon/AutoStory/Pokemon_StoryEvents.h @@ -1740,6 +1752,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_TalkOver.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_Talks.h + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.cpp + Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WanderWait.h Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.cpp Source/PokemonBDSP/Programs/AutoStory/Actions/PokemonBDSP_AutoStory_WildBattle.h Source/PokemonBDSP/Programs/AutoStory/Data/PokemonBDSP_AutoStory_CoordEvents.cpp @@ -1837,6 +1851,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimFailureCases_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimTriggers.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_SimWanderWait.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StoryActions_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySim.cpp @@ -1847,6 +1863,8 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_StorySimulation_Tests.h Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.cpp Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WallBattleSim_Tests.h + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.cpp + Source/PokemonBDSP/Programs/AutoStory/Simulation/PokemonBDSP_AutoStory_WanderWait_Tests.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_CountedWallLeg.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_Indoors.h @@ -1861,6 +1879,7 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_OverlayLog.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedRoute.h + Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_PlannedTalk.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteChoice.h @@ -1868,6 +1887,7 @@ file(GLOB LIBRARY_SOURCES Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteInput.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteIO.cpp Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteIO.h + Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteSteps.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTalk.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteTiming.h Source/PokemonBDSP/Programs/AutoStory/Utils/PokemonBDSP_AutoStory_RouteWalk.cpp diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 1efcb689ef..b052d6f8cb 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "bdsp": { - "revision": "72093886bc7bc80497aff770d803a753e7e4bca7", + "revision": "4b886bbead2e85c42f15bfb0b5ac735c159db039", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "0ce25ea46dc00d91d5d8587c6f00f322490ca35b8d0ad9778588133a9f55d00f" + "manifest_sha256": "eeca55d046c02d5866b54f48abe90dc5dc4c59d483cd0edd7a857d374d85dd2c" } } }