From bc6a5586771d04131c5c8a8b4b14b1a3a11195d7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:03:27 -0800 Subject: [PATCH 01/20] FRLG gates: row sims, replay and gated plans honor gates StoryMapsSim, OverworldStepSim and the replay executor now plan and walk over the run's gates (a closed door blocks; OPEN_GATE/PRESS_SWITCH change them). The gated planner keeps the step model's open-stop risk costs. A skipped step applies its gates_after (Event::when_skipped). New tests: AutoStoryGates (Silph door, Mansion statue on both row sims), OverworldGates stop-risk, executor skipped-step gates. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/AutoStory/Pokemon_StoryEvent.h | 4 + .../Pokemon/AutoStory/Pokemon_StoryEvents.cpp | 3 + .../AutoStory/Pokemon_StoryStepExecutor.cpp | 5 + .../Pokemon_StoryStepExecutor_Tests.cpp | 31 +++ .../Pokemon/Navigation/Pokemon_GatedPlanner.h | 16 ++ .../PokemonFRLG_OverworldGates_Tests.cpp | 37 +++ .../Overworld/PokemonFRLG_OverworldRoute.cpp | 3 + .../Overworld/PokemonFRLG_OverworldSim.h | 13 ++ .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../PokemonFRLG_AutoStoryGates_Tests.cpp | 216 ++++++++++++++++++ .../PokemonFRLG_AutoStoryGates_Tests.h | 27 +++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 49 ++-- .../AutoStory/PokemonFRLG_AutoStoryRowSim.h | 16 +- .../PokemonFRLG_StoryReplay_Executor.cpp | 101 ++++++-- .../PokemonFRLG_StoryReplay_Executor.h | 21 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 16 files changed, 514 insertions(+), 32 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h index 48f20e317e..ffda3cee12 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvent.h @@ -10,6 +10,7 @@ #define PokemonAutomation_Pokemon_StoryEvent_H #include +#include #include #include #include @@ -66,6 +67,9 @@ struct Event{ std::string why; // Skipped when all of these hold (and there is at least one). std::vector skip_if; + // Run when the event is skipped: what the event leaves in the run + // state that is already so (a door it opens, a flag it sets). + std::function when_skipped; // Must hold before `act`; a failure is "require_failed". std::vector require; Act act; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp index 8afcdfe404..deb4003d8f 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryEvents.cpp @@ -412,6 +412,9 @@ CheckpointReport run_checkpoint(RunState& state, Checkpoint& checkpoint, EventLo EventRun run{checkpoint, c + 1, event, state, log, std::vector(event.recoveries.size(), 0), 0}; if (already_done(event, state)){ log_status("skipped", run); + if (event.when_skipped){ + event.when_skipped(state); + } report.events_skipped++; continue; } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.cpp index dcb18049cb..3c0c574010 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor.cpp @@ -62,6 +62,11 @@ Event story_event(const StoryStep& step, StoryStepExecutor& executor){ } return outcome; }; + if (step.gates_after){ + event.when_skipped = [&step](RunState& state){ + apply_gate_change(state.gates, *step.gates_after); + }; + } if (step.pose_after){ event.pose_learned = pose_of(*step.pose_after); } diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp index a14b5b766d..6002f95900 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Pokemon_StoryStepExecutor_Tests.cpp @@ -344,6 +344,33 @@ UnitTestResult test_gate_state_carried(){ return true; } +UnitTestResult test_skipped_step_gates_applied(){ + // A step that skip_if skips has its effect already: the door it opens + // is open for the steps after it, and a later step that needs it runs + // with it open. + StoryStep open_door = make(StoryStepKind::TALK, "open_door"); + open_door.skip_if = {"door_done"}; + open_door.gates_after = GateChange{.opened = {"SilphCo_5F/door_2"}}; + const StoryCheckpoint data{ + .id = "16.02", + .title = "Silph", + .steps = {open_door, make(StoryStepKind::TALK, "after")}, + }; + FakeExecutor executor; + executor.conditions = {"door_done"}; + const Run result = run(data, executor); + if (!result.report.completed || result.report.events_skipped != 1){ + return std::format("Expected the door step skipped:{}", joined(result.lines)); + } + if (executor.gates_seen.size() != 1 || !executor.gates_seen[0].second.opened.contains("SilphCo_5F/door_2")){ + return "Expected the step after a skipped door step to see the door open."; + } + if (!result.state.gates.opened.contains("SilphCo_5F/door_2")){ + return "Expected the door open at the end of the checkpoint."; + } + return true; +} + UnitTestResult test_failure_names_the_step(){ const StoryCheckpoint data = lab_checkpoint(); FakeExecutor executor; @@ -826,6 +853,10 @@ const StoryStepTestCase STORY_STEP_CASES[] = { .input = {.name = "gate state and run flags carried from the save through the steps", .test = test_gate_state_carried}, .expectation = {.description = "applies start_gates, start_flags, gates_after and flags_after in order"}, }, + { + .input = {.name = "a skipped step's gates_after is applied", .test = test_skipped_step_gates_applied}, + .expectation = {.description = "the gates a skipped step opened are open for the steps after it"}, + }, { .input = {.name = "unsupported kinds and lost battles", .test = test_unsupported_and_lost_battles}, .expectation = {.description = "flags unsupported step types and handles battle defeat"}, diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h index fde399180f..183e3f8716 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h @@ -23,6 +23,9 @@ * bool held_at(const State&, Direction, const GateState&) const; * MapPlace place_of(const State&) const; * + * and may have open_stop_risk(const State&, Direction, const GateState&) + * const, as plan_legs()'s model may have it without the gates. + * * press() reads each tile with resolved_tile(), which makes a closed gate a * wall. One-way warps (MapWarp::one_way) are the game's to take as any warp: * the model leads the player to the warp's arrival, and the maps give no way @@ -33,6 +36,7 @@ #ifndef PokemonAutomation_Pokemon_GatedPlanner_H #define PokemonAutomation_Pokemon_GatedPlanner_H +#include #include #include #include @@ -45,6 +49,12 @@ namespace PokemonAutomation{ namespace Pokemon{ +// A step model that weighs an open stop (see the top of this file). +template +concept HasOpenStopRisk = requires (const Inner& inner, const typename Inner::State& state, const GateState& gates){ + { inner.open_stop_risk(state, Direction::NORTH, gates) } -> std::convertible_to; +}; + // The game's step model, wrapped: see the top of this file. template class GatedModel{ @@ -86,6 +96,12 @@ class GatedModel{ return m_inner.held_at(state.inner, direction, state.gates); } + // The inner model's risk of an open stop (see Pokemon_LegPlanner.h), if + // it has one, read through the gates the stop is made in. + int open_stop_risk(const State& state, Direction direction) const requires HasOpenStopRisk{ + return m_inner.open_stop_risk(state.inner, direction, state.gates); + } + private: static Step carry(const Step& walked, const GateState& gates){ Step step; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp index 2d0770d661..0180b7b473 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp @@ -166,6 +166,42 @@ UnitTestResult test_route_presses_statue(){ } +// A room with a sign on its north wall, above the third column, and a +// card-key door, open, in a corner out of the way. +const std::vector& sign_maps(){ + static const std::vector MAPS{parse_map(R"({ + "format": "pokesim-runtime-map/2", "name": "GateSign", "points": {}, "warps": [], "connections": [], "source": {"decomp_file": "", "revision": "test", "date": "2026-11-12"}, + "tiles": ["##S####", "#.....#", "#.....#", "#...G.#", "#######"], + "gates": {"door_1": {"tiles": [[4, 3]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_TEST"}} + })", "GateSign")}; + return MAPS; +} + +// A route over gated maps weighs a stop under a sign as one over maps +// without gates does: with the sign's overshoot dear, the walk to the tile +// under it comes from the side, not north from below. +UnitTestResult test_gated_plan_keeps_stop_risk(){ + RouteCosts costs = default_route_costs(); + costs[RouteCost::SIGN_OVERSHOOT] = 1000; + GateState open; + open.opened.insert(Pokemon::gate_key("GateSign", "door_1")); + const MapPosition start{"GateSign", {2, 3}}; + const RouteGoal goal{{"GateSign", {2, 1}}, std::nullopt}; + + const auto plain = plan_overworld_route(resolve_maps(sign_maps(), open), start, goal, costs); + const auto gated = plan_overworld_route_gated(sign_maps(), start, goal, open, GateRules(), costs); + if (!plain || !gated){ + return "No route to the tile under the sign."; + } + if (plain->back().direction == Direction::NORTH){ + return "The plain plan ends going north under the sign, so the test shows nothing:" + describe(*plain); + } + if (describe(*gated) != describe(*plain)){ + return "The gated plan differs from the plain one, which weighs the stop under the sign:" + describe(*gated) + "\n against" + describe(*plain); + } + return true; +} + // Walks `route` in the sim from `start`, with the Card Key as `card_key`. struct SimRun{ std::string failure; @@ -250,6 +286,7 @@ const std::vector GATES_CASES{ {.input = {.name = "no route through a card-key gate without the Card Key", .body = test_route_needs_card_key}, .expectation = {}}, {.input = {.name = "an open gate is walked through", .body = test_route_through_open_gate}, .expectation = {}}, {.input = {.name = "the route presses a statue for a switch's barrier", .body = test_route_presses_statue}, .expectation = {}}, + {.input = {.name = "a gated plan keeps the stop-risk costs", .body = test_gated_plan_keeps_stop_risk}, .expectation = {}}, {.input = {.name = "sim: face the door, A, walk through", .body = test_sim_opens_gate}, .expectation = {}}, {.input = {.name = "sim: face the statue, A, YES, walk through", .body = test_sim_presses_statue}, .expectation = {}}, {.input = {.name = "sim: the door stays shut without the Card Key", .body = test_sim_door_stays_shut_without_card_key}, .expectation = {}}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp index 06e4227675..f53a33d5c5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.cpp @@ -396,6 +396,9 @@ class GatedStepModel{ bool held_at(const State& state, Direction direction, const Pokemon::GateState& gates) const{ return StepModel(m_maps.at(gates), m_costs).held_at(state, direction); } + int open_stop_risk(const State& state, Direction direction, const Pokemon::GateState& gates) const{ + return StepModel(m_maps.at(gates), m_costs).open_stop_risk(state, direction); + } Pokemon::MapPlace place_of(const State& state) const{ return Pokemon::MapPlace{(size_t)state.map, state.state.position}; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 5e419e1ed3..77ebc050b2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -108,6 +108,19 @@ class OverworldSim{ // battle follows it. bool close_message(); + // Whether the maps have gates (MapData::gates), and the maps as loaded + // for planning through them, with a gate closed or open as the map + // says; whether the player holds the Card Key (SimScript::card_key_held). + bool has_gates() const{ + return !m_source_maps.empty(); + } + const std::vector& source_maps() const{ + return m_source_maps; + } + bool card_key_held() const{ + return m_script.card_key_held; + } + // A on what the player faces, as `field` says (`floor`: the lift's). // Returns whether it was there. (PokemonFRLG_OverworldSimField.cpp) bool use_field(SimField field, size_t floor = 0); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 66947d9483..567f804003 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -57,6 +57,7 @@ #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows12_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows14_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows15_Tests.h" +#include "Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows13_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryTable.h" @@ -343,6 +344,7 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){ add_tests_AutoStoryCinnabarGym(database); add_tests_AutoStorySilph(database); add_tests_AutoStoryMansion(database); + add_tests_AutoStoryGates(database); } void add_tests(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp new file mode 100644 index 0000000000..00d32ee224 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp @@ -0,0 +1,216 @@ +/* AutoStory Gates Tests + * + * From: https://github.com/PokemonAutomation/ + * + * A ROUTE step on the row sims with gates: StoryMapsSim (the whole story + * on maps) and OverworldStepSim (a row's steps on the OverworldSim) stop at + * a closed Silph Co. card-key door, open it for a player with the Card Key + * and keep the gate state, and press a Pokemon Mansion statue for the + * barrier its switch opens. + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" +#include "PokemonFRLG_AutoStoryGates_Tests.h" +#include "PokemonFRLG_AutoStoryPoses.h" +#include "PokemonFRLG_AutoStoryRowSim.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +namespace{ + +struct GatesInput{ + std::string name; + std::function body; +}; +struct GatesExpectation{ +}; +struct GatesCase{ + GatesInput input; + GatesExpectation expectation; +}; + +class Test_AutoStoryGates : public UnitTest{ +public: + explicit Test_AutoStoryGates(GatesCase test_case) + : UnitTest("PokemonFRLG::AutoStoryGates - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + try{ + return m_case.input.body(); + }catch (Exception& e){ + return std::string(e.name()) + ": " + e.message(); + } + } + +private: + GatesCase m_case; +}; + +// Silph Co. 5F's corridor, shortened: a card-key door at (4, 1). +const std::vector& door_maps(){ + static const std::vector MAPS{parse_map(R"({ + "format": "pokesim-runtime-map/2", "name": "SilphHall", "points": {}, "warps": [], "connections": [], "source": {"decomp_file": "", "revision": "test", "date": "2026-11-12"}, + "tiles": ["#########", "#...G...#", "#########"], + "gates": {"door_1": {"tiles": [[4, 1]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_TEST"}} + })", "SilphHall")}; + return MAPS; +} + +// The Mansion's 1F, shortened: a statue at (1, 0) and a barrier at (4, 1) +// that its switch opens. +const std::vector& statue_maps(){ + static const std::vector MAPS{parse_map(R"({ + "format": "pokesim-runtime-map/2", "name": "MansionHall", "points": {}, "warps": [], "connections": [], "source": {"decomp_file": "", "revision": "test", "date": "2026-11-12"}, + "tiles": ["#########", "#...G...#", "#########"], + "gates": {"barrier_1": {"tiles": [[4, 1]], "open_glyph": ".", "new_game": "closed", "switch": "mansion", "open_when": "on"}}, + "switches": {"mansion": {"flag": "FLAG_TEST_SWITCH", "toggle": true, "floors": ["MansionHall"], + "statues": [{"coord": [1, 0], "face_from": [1, 1], "facing": "north"}]}} + })", "MansionHall")}; + return MAPS; +} + +StoryStep route_step(const std::string& map, TilePos goal){ + StoryStep step; + step.kind = StoryStepKind::ROUTE; + step.name = "cross"; + step.args["target"] = Pokemon::GridPose{map, {goal}, std::nullopt}; + return step; +} + +Pokemon::RunState run_state(const std::string& map, bool card_key){ + Pokemon::RunState state; + state.pose = to_pose(StoryPose{map, TilePos{1, 1}, Direction::EAST}); + if (card_key){ + state.flags.insert("card_key_held"); + } + return state; +} + +// The step on StoryMapsSim over `maps`, from the start of the corridor. +Pokemon::Outcome on_maps(const std::vector& maps, const std::string& map, bool card_key, Pokemon::RunState& state){ + StorySimKnobs knobs; + knobs.maps = &maps; + StoryMapsSim sim(knobs); + state = run_state(map, card_key); + return sim.run(route_step(map, TilePos{6, 1}), state); +} + + +// A closed door stops a player without the Card Key: the story's sim does +// not walk through gates the run has not opened. +UnitTestResult test_maps_sim_door_blocks(){ + Pokemon::RunState state; + const Pokemon::Outcome outcome = on_maps(door_maps(), "SilphHall", false, state); + if (outcome.succeeded()){ + return "The row sim walked through a closed card-key door without the Card Key."; + } + return true; +} + +UnitTestResult test_maps_sim_door_opens(){ + Pokemon::RunState state; + const Pokemon::Outcome outcome = on_maps(door_maps(), "SilphHall", true, state); + if (!outcome.succeeded()){ + return "The row sim did not open the door for a player with the Card Key: " + Pokemon::to_string(outcome); + } + if (!state.gates.opened.contains("SilphHall/door_1")){ + return "The run's gates do not have the door open after the step."; + } + return true; +} + +UnitTestResult test_maps_sim_statue_switch(){ + Pokemon::RunState state; + const Pokemon::Outcome outcome = on_maps(statue_maps(), "MansionHall", false, state); + if (!outcome.succeeded()){ + return "The row sim did not press the statue for the barrier: " + Pokemon::to_string(outcome); + } + if (!state.gates.switch_on("mansion")){ + return "The run's gates do not have the switch on after the step."; + } + return true; +} + +struct GateStateOut{ + Pokemon::GateState gates; + MapPosition position; +}; + +// The step on OverworldStepSim and its OverworldSim, with the Card Key as `card_key`. +std::string on_overworld_sim(const std::vector& maps, const std::string& map, bool card_key, GateStateOut& out){ + SimScript script; + script.card_key_held = card_key; + OverworldSim sim(maps, MapPosition{map, TilePos{1, 1}}, Direction::EAST, script); + StoryPose at{map, TilePos{1, 1}, Direction::EAST}; + const std::string failure = row_step_on_sim(sim, at, route_step(map, TilePos{6, 1}), "test"); + out.gates = sim.state().gates; + out.position = sim.state().position; + return failure; +} + +UnitTestResult test_step_sim_door_blocks(){ + GateStateOut out; + if (on_overworld_sim(door_maps(), "SilphHall", false, out).empty()){ + return "The step walked through a closed card-key door without the Card Key."; + } + return true; +} + +UnitTestResult test_step_sim_door_opens(){ + GateStateOut out; + const std::string failure = on_overworld_sim(door_maps(), "SilphHall", true, out); + if (!failure.empty()){ + return "The step did not open the door for a player with the Card Key: " + failure; + } + if (!out.gates.opened.contains("SilphHall/door_1") || !(out.position == MapPosition{"SilphHall", TilePos{6, 1}})){ + return "Expected the door open and the player at the goal, ended at " + to_string(out.position); + } + return true; +} + +UnitTestResult test_step_sim_statue_switch(){ + GateStateOut out; + const std::string failure = on_overworld_sim(statue_maps(), "MansionHall", false, out); + if (!failure.empty()){ + return "The step did not press the statue: " + failure; + } + if (!out.gates.switch_on("mansion") || !(out.position == MapPosition{"MansionHall", TilePos{6, 1}})){ + return "Expected the switch on and the player at the goal, ended at " + to_string(out.position); + } + return true; +} + +const std::vector GATES_CASES{ + {.input = {.name = "story maps: a closed door blocks without the Card Key", .body = test_maps_sim_door_blocks}, .expectation = {}}, + {.input = {.name = "story maps: the door opens with the Card Key and stays open", .body = test_maps_sim_door_opens}, .expectation = {}}, + {.input = {.name = "story maps: the statue's switch opens its barrier", .body = test_maps_sim_statue_switch}, .expectation = {}}, + {.input = {.name = "overworld sim: a closed door blocks without the Card Key", .body = test_step_sim_door_blocks}, .expectation = {}}, + {.input = {.name = "overworld sim: the door opens with the Card Key", .body = test_step_sim_door_opens}, .expectation = {}}, + {.input = {.name = "overworld sim: the statue's switch opens its barrier", .body = test_step_sim_statue_switch}, .expectation = {}}, +}; + +} // namespace + + +void add_tests_AutoStoryGates(UnitTestDatabase& database){ + for (const GatesCase& item : GATES_CASES){ + database.add(item); + } +} + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h new file mode 100644 index 0000000000..e329fe4ede --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h @@ -0,0 +1,27 @@ +/* AutoStory Gates Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Registration of the tests of the story's sims with gates: a Silph Co. + * card-key door and a Pokemon Mansion statue switch on the row sim. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryGates_Tests_H +#define PokemonAutomation_PokemonFRLG_AutoStoryGates_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// StoryMapsSim and OverworldStepSim honoring gates (PokemonFRLG_AutoStoryGates_Tests.cpp). +void add_tests_AutoStoryGates(UnitTestDatabase& database); + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 102739fb16..a15e94460a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -12,11 +12,13 @@ #include #include #include "Common/Cpp/Exceptions.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" #include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryPacedRoute.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldWalk.h" #include "PokemonFRLG_AutoStoryFieldMoves.h" @@ -209,7 +211,7 @@ StepInterruptActions StoryMapsSim::sim_interrupt_actions(){ Pokemon::StoryAction StoryMapsSim::action(StoryActionId id){ switch (id){ case StoryActionId::ROUTE: - return played([this](const StoryStep& step, RunState& state){ return walk_to(state.pose, step); }); + return played([this](const StoryStep& step, RunState& state){ return walk_to(state, step); }); case StoryActionId::LEGS: return played([this](const StoryStep& step, RunState& state){ return legs(state.pose, step); }); case StoryActionId::STEP: @@ -217,7 +219,9 @@ Pokemon::StoryAction StoryMapsSim::action(StoryActionId id){ // The nurse's way must plan too, but the run goes on from where it stands. case StoryActionId::READY: return played([this](const StoryStep& step, RunState& state){ - const Outcome to_nurse = walk_to(state.pose, step); + // The way to the nurse is walked in a copy: the run goes on from here. + RunState visit = state; + const Outcome to_nurse = walk_to(visit, step); return to_nurse.succeeded() ? Pokemon::outcome_ok() : to_nurse; }); case StoryActionId::SHOP: @@ -248,7 +252,7 @@ Outcome StoryMapsSim::legs(const Pokemon::Pose& pose, const StoryStep& step) con if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } - const std::optional> route = fixed_route(story_maps(), at.position, Pokemon::story_arg>(step.args, "legs")); + const std::optional> route = fixed_route(maps(), at.position, Pokemon::story_arg>(step.args, "legs")); if (!route || route->empty()){ return Pokemon::outcome_failed("bad_legs", to_string(at.position)); } @@ -309,16 +313,23 @@ Outcome StoryMapsSim::shop(const StoryStep& step){ return Pokemon::outcome_ok(); } -Outcome StoryMapsSim::walk_to(const Pokemon::Pose& pose, const StoryStep& step) const{ +const std::vector& StoryMapsSim::maps() const{ + return m_knobs.maps != nullptr ? *m_knobs.maps : story_maps(); +} + +Outcome StoryMapsSim::walk_to(Pokemon::RunState& state, const StoryStep& step) const{ + const Pokemon::Pose& pose = state.pose; + const Pokemon::GateRules rules = Pokemon::gate_rules_of(state); if (Pokemon::tiles_of(pose).size() > 1){ // From the tiles a pacing step leaves: the route must plan, and // test_routes_after_pacing() walks it on the sim from each. const std::optional target = story_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target"))); const RouteGoal goal{{target->map, target->tile}, target->facing}; - const std::optional> route = plan_story_route(story_maps(), pose, std::nullopt, goal); + const std::optional> route = plan_story_route(maps(), pose, std::nullopt, goal, state.gates, rules); if (!route || route->empty()){ return Pokemon::outcome_failed("no_route", Pokemon::to_string(pose) + " to " + to_string(goal.position)); } + state.gates = gates_after_route(state.gates, *route); return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, route->back().facing_after})); } const Standing at = standing(pose); @@ -327,19 +338,20 @@ Outcome StoryMapsSim::walk_to(const Pokemon::Pose& pose, const StoryStep& step) } const std::optional target = story_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target"))); const RouteGoal goal{{target->map, target->tile}, target->facing}; - const std::optional> route = plan_overworld_route( - story_maps(), at.position, goal, story_route_costs(), at.facing + const std::optional> route = plan_overworld_route_gated( + maps(), at.position, goal, state.gates, rules, story_route_costs(), at.facing ); if (!route){ return Pokemon::outcome_failed("no_route", to_string(at.position) + " to " + to_string(goal.position)); } - const MapPosition end = follow_overworld_route(story_maps(), at.position, *route); + const MapPosition end = follow_overworld_route(maps(), at.position, *route, state.gates); if (!(end == goal.position)){ return Pokemon::outcome_failed("wrong_end", to_string(end)); } if (const std::optional leg = overrun_wall_leg(*route)){ return Pokemon::outcome_failed("wall_overrun", *leg); } + state.gates = gates_after_route(state.gates, *route); const Direction facing = route->empty() ? at.facing : route->back().facing_after; return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, facing})); } @@ -347,14 +359,21 @@ Outcome StoryMapsSim::walk_to(const Pokemon::Pose& pose, const StoryStep& step) // The route the program walks for `step`, a ROUTE or LEGS, from `at`: // planned, or the legs laid out. -std::optional> walked_route(const StoryPose& at, const StoryStep& step){ +std::optional> walked_route( + const StoryPose& at, const StoryStep& step, + const std::vector& maps, const Pokemon::GateState& gates, const Pokemon::GateRules& rules +){ const MapPosition start{at.map, at.tile}; if (step.kind == StoryStepKind::LEGS){ - return fixed_route(story_maps(), start, Pokemon::story_arg>(step.args, "legs")); + return fixed_route(maps, start, Pokemon::story_arg>(step.args, "legs")); } const std::optional target = story_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target"))); const RouteGoal goal{{target->map, target->tile}, target->facing}; - return plan_overworld_route(story_maps(), start, goal, story_route_costs(), at.facing); + return plan_overworld_route_gated(maps, start, goal, gates, rules, story_route_costs(), at.facing); +} + +std::optional> walked_route(const StoryPose& at, const StoryStep& step){ + return walked_route(at, step, story_maps(), Pokemon::GateState(), Pokemon::GateRules()); } @@ -471,12 +490,16 @@ void sim_wait_out_battle_exit(OverworldSim& sim){ // A ROUTE or LEGS by the sim's walker, fighting a trainer who sees the // player on the way. std::string OverworldStepSim::walk(const StoryStep& step){ - const std::optional> route = walked_route(m_at, step); + // The sim's own maps and gates, if it has gates: the route opens the + // ones the Card Key opens, and the walker's steps open them in the sim. + const std::vector& maps = m_sim.has_gates() ? m_sim.source_maps() : story_maps(); + const Pokemon::GateState& gates = m_sim.state().gates; + const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.card_key_held()}); if (route && route->empty()){ // Already there. return ""; } - const RoutePlanning planning{.maps = &story_maps(), .costs = story_route_costs(), .start = MapPosition{m_at.map, m_at.tile}, .label = step.name}; + const RoutePlanning planning{.maps = &maps, .gates = gates, .costs = story_route_costs(), .start = MapPosition{m_at.map, m_at.tile}, .label = step.name}; SimWalkerRules rules; rules.trainer_battle_end = battle_end_on_sim; // A BIKE_VARIANT rides, as on the console, when the sim has the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h index b4f7327504..c1f55ca7c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h @@ -19,6 +19,7 @@ #include #include #include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -40,6 +41,9 @@ struct StorySimKnobs{ // Whether the executor clears what came up between steps // (step_interrupts()), as the console does; off, as before it did. bool clear_interrupts = true; + // The maps the story is planned and walked on, with the gates of the + // run state; the story's (story_maps()) if null. + const std::vector* maps = nullptr; }; // The whole story on the story maps, without a walker: each ROUTE planned @@ -84,7 +88,9 @@ class StoryMapsSim : public Pokemon::TableExecutor{ private: Pokemon::StoryAction action(StoryActionId id); - Pokemon::Outcome walk_to(const Pokemon::Pose& pose, const StoryStep& step) const; + const std::vector& maps() const; + // Plans the route and moves the run's pose and gates to its end. + Pokemon::Outcome walk_to(Pokemon::RunState& state, const StoryStep& step) const; Pokemon::Outcome legs(const Pokemon::Pose& pose, const StoryStep& step) const; Pokemon::Outcome step_ahead(const Pokemon::Pose& pose, const StoryStep& step) const; Pokemon::Outcome shop(const StoryStep& step); @@ -108,7 +114,13 @@ class StoryMapsSim : public Pokemon::TableExecutor{ // The route the program walks for `step`, a ROUTE or LEGS, from `at`: -// planned, or the legs laid out. +// planned, or the legs laid out. A route is planned over `maps` through +// `gates`, and may open a card-key gate if `rules` say the player holds +// the Card Key. +std::optional> walked_route( + const StoryPose& at, const StoryStep& step, + const std::vector& maps, const Pokemon::GateState& gates, const Pokemon::GateRules& rules +); std::optional> walked_route(const StoryPose& at, const StoryStep& step); // A row's steps on the OverworldSim as the program does them: routes and diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp index f46ebfbe11..80faff34b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp @@ -6,6 +6,8 @@ #include "Common/Cpp/Exceptions.h" #include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" #include "Pokemon/AutoStory/Data/Pokemon_StoryStepJson.h" +#include "Pokemon/Navigation/Pokemon_GateTiles.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_StoryReplay_Executor.h" namespace PokemonAutomation{ @@ -77,9 +79,9 @@ bool ReplayStepGuard::stops_on_failure(const StoryStep&) const{ Pokemon::StoryAction ReplayExecutor::replay_action(StoryActionId id){ switch (id){ case StoryActionId::ROUTE: - return {.act = [this](const StoryStep& step, Pokemon::RunState&){ return replay_route(step); }}; + return {.act = [this](const StoryStep& step, Pokemon::RunState& state){ return replay_route(step, state); }}; case StoryActionId::STEP: - return {.act = [this](const StoryStep& step, Pokemon::RunState&){ return replay_step(step); }}; + return {.act = [this](const StoryStep& step, Pokemon::RunState& state){ return replay_step(step, state); }}; case StoryActionId::MASH: return {.act = [this](const StoryStep& step, Pokemon::RunState&){ return replay_scene(step); }}; default: @@ -153,9 +155,62 @@ void ReplayExecutor::observe_interruption(const OverworldPose& predicted){ m_interrupted = true; lose_pose("unknown-after-interruption"); } -ReplayLeg ReplayExecutor::prepare_leg(const JsonValue& value, OverworldPose& current) const{ +const std::vector& ReplayExecutor::maps_through(const Pokemon::GateState& gates) const{ + if (!has_gates(m_data->maps)){ + return m_data->maps; + } + if (!m_resolved || !(m_resolved->first == gates)){ + m_resolved.emplace(gates, resolve_maps(m_data->maps, gates)); + } + return m_resolved->second; +} +// An open_gate or a press_switch: A at the gate or statue the player +// faces, which the model has to find there (and, for a gate, the player to +// hold the Card Key). +ReplayLeg ReplayExecutor::prepare_gate_leg(const JsonValue& value, const OverworldPose& current, Pokemon::GateState& gates) const{ + const JsonObject& command = value.to_object_throw(); + fields(value, {"event", "kind", "map", "direction"}); + const bool opens = command.get_string_throw("kind") == "open_gate"; + const Direction facing = direction(command.get_string_throw("direction")); + if (command.get_string_throw("event") != m_active || command.get_string_throw("map") != current.position.map){ + throw ParseException("story replay: supplied route has wrong event/map"); + } + if (current.facing != facing){ + throw ParseException("story replay: supplied gate command is not facing its gate"); + } + const MapData& map = map_named(m_data->maps, current.position.map); + Pokemon::GateState after = gates; + if (opens){ + const Pokemon::MapGate* gate = m_rules.card_key_held + ? Pokemon::closed_card_key_gate_faced(map, current.position.point, facing, gates) : nullptr; + if (gate == nullptr){ + throw ParseException("story replay: no card-key gate to open (or no Card Key)"); + } + after.opened.insert(Pokemon::gate_key(map.name, gate->id)); + }else{ + const Pokemon::MapSwitch* pressed = Pokemon::switch_pressed(map, current.position.point, facing); + if (pressed == nullptr){ + throw ParseException("story replay: no statue to press"); + } + if (pressed->toggle && gates.switch_on(pressed->id)){ + after.switches_on.erase(pressed->id); + }else{ + after.switches_on.insert(pressed->id); + } + } + RouteStep step{.action = opens ? RouteAction::OPEN_GATE : RouteAction::PRESS_SWITCH, .direction = facing, .tiles = 0}; + step.end = current.position; + step.facing_after = facing; + step.gate_change = Pokemon::gate_change_between(gates, after); + gates = std::move(after); + return ReplayLeg{.step = step, .action = value.clone()}; +} +ReplayLeg ReplayExecutor::prepare_leg(const JsonValue& value, OverworldPose& current, Pokemon::GateState& gates) const{ const JsonObject& command = value.to_object_throw(); const std::string kind = command.get_string_throw("kind"); + if (kind == "open_gate" || kind == "press_switch"){ + return prepare_gate_leg(value, current, gates); + } if (kind == "walk"){ fields(value, {"event", "kind", "map", "direction", "tiles"}); }else if (kind == "transition"){ @@ -175,7 +230,7 @@ ReplayLeg ReplayExecutor::prepare_leg(const JsonValue& value, OverworldPose& cur } RouteStep step{.action = kind == "turn" ? RouteAction::FACE : RouteAction::WALK, .direction = facing, .tiles = (int)tiles}; for (int64_t n = 0; n < tiles; n++){ - const auto next = predict_overworld_press(m_data->maps, current, facing); + const auto next = predict_overworld_press(maps_through(gates), current, facing); if (!next){ throw ParseException("story replay: native model rejects supplied route"); } @@ -201,10 +256,11 @@ std::vector ReplayExecutor::prepare_route(const StoryStep& step){ throw ParseException("story replay: supplied route exceeds action bound"); } OverworldPose current = m_pose; + Pokemon::GateState gates = m_gates; std::vector route; m_legs.clear(); for (const JsonValue& command : commands){ - m_legs.emplace_back(prepare_leg(command, current)); + m_legs.emplace_back(prepare_leg(command, current, gates)); route.push_back(m_legs.back().step); } const OverworldPose goal = authored_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target")), m_data->maps); @@ -215,13 +271,15 @@ std::vector ReplayExecutor::prepare_route(const StoryStep& step){ } void ReplayExecutor::default_plan(const StoryStep& step){ const OverworldPose goal = authored_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target")), m_data->maps); - const auto planned = plan_overworld_route(m_data->maps, m_pose.position, {goal.position, goal.facing}, story_route_costs(), m_pose.facing); + const auto planned = plan_overworld_route_gated( + m_data->maps, m_pose.position, {goal.position, goal.facing}, m_gates, m_rules, story_route_costs(), m_pose.facing + ); JsonObject plan; plan["policy"] = "native-story-route-costs"; plan["exact_python_leg_comparison"] = "not-comparable-different-planner-policies"; JsonArray legs; if (planned){ - const MapPosition actual = follow_overworld_route(m_data->maps, m_pose.position, *planned); + const MapPosition actual = follow_overworld_route(m_data->maps, m_pose.position, *planned, m_gates); if (!(actual == goal.position)){ throw ParseException("story replay: native default plan did not reach target"); } @@ -239,8 +297,11 @@ void ReplayExecutor::timed_plan(const StoryStep& step, const std::vectormaps, m_pose.position, m_pose.facing); - const RoutePlanning planning{.maps = &m_data->maps, .start = m_pose.position, + SimScript script; + script.gates = m_gates; + script.card_key_held = m_rules.card_key_held; + OverworldSim sim(m_data->maps, m_pose.position, m_pose.facing, script); + const RoutePlanning planning{.maps = &m_data->maps, .gates = m_gates, .start = m_pose.position, .label = step.name, .wall_check = WallCheck::SKIP}; const std::string failure = OverworldSimWalker(sim).run(route, planning); const auto goal = authored_pose(Pokemon::pose_of(Pokemon::story_arg(step.args, "target")), m_data->maps); @@ -259,11 +320,20 @@ void ReplayExecutor::timed_plan(const StoryStep& step, const std::vectormaps, m_pose, step.direction); + const auto next = predict_overworld_press(maps_through(m_gates), m_pose, step.direction); if (!next){ throw ParseException("story replay: supplied walk became blocked"); } @@ -277,14 +347,16 @@ StepOutcome ReplayExecutor::walk_leg(const RouteStep& step){ m_moves++; } m_pose.facing = step.facing_after; - const MapPosition followed = follow_overworld_route(m_data->maps, start.position, {step}); + const MapPosition followed = follow_overworld_route(m_data->maps, start.position, {step}, m_gates); if (!(followed == m_pose.position)){ throw ParseException("story replay: walker and independent native route replay disagree"); } m_basis = "model-prediction"; return StepOutcome{}; } -Pokemon::Outcome ReplayExecutor::replay_route(const StoryStep& step){ +Pokemon::Outcome ReplayExecutor::replay_route(const StoryStep& step, Pokemon::RunState& state){ + m_gates = state.gates; + m_rules = Pokemon::gate_rules_of(state); default_plan(step); const std::vector route = prepare_route(step); size_t moves = 0; @@ -309,10 +381,11 @@ Pokemon::Outcome ReplayExecutor::replay_route(const StoryStep& step){ if (signal() && !m_interrupted){ throw ParseException("story replay: physical encounter injection was not reached"); } + state.gates = m_gates; return Pokemon::outcome_ok(native_pose(m_pose)); } -Pokemon::Outcome ReplayExecutor::replay_step(const StoryStep& step){ - const auto next = predict_overworld_press(m_data->maps, m_pose, Pokemon::story_arg(step.args, "direction")); +Pokemon::Outcome ReplayExecutor::replay_step(const StoryStep& step, const Pokemon::RunState& state){ + const auto next = predict_overworld_press(maps_through(state.gates), m_pose, Pokemon::story_arg(step.args, "direction")); if (!next){ lose_pose("unknown-after-transition"); return Pokemon::outcome_failed("step_unresolved"); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.h index 0801680e0d..011fb4d9dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.h @@ -3,10 +3,13 @@ */ #ifndef PokemonAutomation_PokemonFRLG_StoryReplay_Executor_H #define PokemonAutomation_PokemonFRLG_StoryReplay_Executor_H +#include #include #include +#include #include "Common/Cpp/Json/JsonArray.h" #include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "PokemonFRLG_AutoStoryStepInterrupts.h" #include "PokemonFRLG_AutoStoryStepTable.h" @@ -46,14 +49,21 @@ class ReplayExecutor : public Pokemon::StoryStepExecutor{ // The replay's action for `id`: a ROUTE, STEP or MASH; every other // action is unsupported. Pokemon::StoryAction replay_action(StoryActionId id); - Pokemon::Outcome replay_route(const StoryStep& step); - Pokemon::Outcome replay_step(const StoryStep& step); + // A ROUTE or STEP reads the maps through the run's gates, and a + // route's open_gate and press_switch commands change them. + Pokemon::Outcome replay_route(const StoryStep& step, Pokemon::RunState& state); + Pokemon::Outcome replay_step(const StoryStep& step, const Pokemon::RunState& state); Pokemon::Outcome replay_scene(const StoryStep& step); const JsonObject* signal() const; const JsonObject& parameters(const StoryStep& step) const; - ReplayLeg prepare_leg(const JsonValue& command, OverworldPose& current) const; + // `gates`: the gates before the command, and after it. + ReplayLeg prepare_leg(const JsonValue& command, OverworldPose& current, Pokemon::GateState& gates) const; + ReplayLeg prepare_gate_leg(const JsonValue& command, const OverworldPose& current, Pokemon::GateState& gates) const; + // The maps as `gates` make them: a closed gate is a wall. + const std::vector& maps_through(const Pokemon::GateState& gates) const; std::vector prepare_route(const StoryStep& step); StepOutcome walk_leg(const RouteStep& step); + StepOutcome gate_leg(const RouteStep& step); void default_plan(const StoryStep& step); void timed_plan(const StoryStep& step, const std::vector& route); void lose_pose(std::string basis); @@ -66,6 +76,11 @@ class ReplayExecutor : public Pokemon::StoryStepExecutor{ const ReplayData* m_data; const JsonObject* m_scenario; OverworldPose m_pose; + // The gates open and switches on, and what the player may open, as + // the run state says at the start of each step. + Pokemon::GateState m_gates; + Pokemon::GateRules m_rules; + mutable std::optional>> m_resolved; bool m_known = true; std::string m_basis = "scripted-observation"; std::string m_active; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 3b38604e26..0dd3bcaaec 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2097,6 +2097,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryCinnabarGym_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStorySilph_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMansion_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows13_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h From 5178e3f785b4a971205e66acebe7e21d4e85c338 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:08:24 -0800 Subject: [PATCH 02/20] FRLG gates: row sim reads the sim's maps for wall checks; has_gates -> gated OverworldSim::has_gates() clashed with the free has_gates(maps); renamed gated(). StoryMapsSim's wall-overrun and facing checks look in the maps the step is walked on, not the story maps. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldSim.h | 2 +- .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 24 +++++++++---------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 77ebc050b2..d6ae67cce9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -111,7 +111,7 @@ class OverworldSim{ // Whether the maps have gates (MapData::gates), and the maps as loaded // for planning through them, with a gate closed or open as the map // says; whether the player holds the Card Key (SimScript::card_key_held). - bool has_gates() const{ + bool gated() const{ return !m_source_maps.empty(); } const std::vector& source_maps() const{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index a15e94460a..2d9635feb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -73,8 +73,8 @@ std::string stub_report(const std::vector& rows){ namespace{ -const MapData* map_named(const std::string& name){ - for (const MapData& map : story_maps()){ +const MapData* map_named(const std::string& name, const std::vector& maps = story_maps()){ + for (const MapData& map : maps){ if (map.name == name){ return ↦ } @@ -85,8 +85,8 @@ const MapData* map_named(const std::string& name){ // Whether the player, at the end of a WALK `step`, stops there holding on: // the map's edge, a wall, or water to Surf onto, but no warp of any kind, // even one to a map that isn't loaded. -bool stops_past_end(const RouteStep& step){ - const MapData& map = *map_named(step.end.map); +bool stops_past_end(const RouteStep& step, const std::vector& maps){ + const MapData& map = *map_named(step.end.map, maps); const TilePos here = step.end.point; const TilePos ahead = here.next(step.direction); if (!in_bounds(map, ahead)){ @@ -104,9 +104,9 @@ bool stops_past_end(const RouteStep& step){ // The first leg of `route` to a wall that holding on would carry past its // end, or nothing (console B, 2026-11-02: one rode Route 4's Pokemon // Center escalator). -std::optional overrun_wall_leg(const std::vector& route){ +std::optional overrun_wall_leg(const std::vector& route, const std::vector& maps){ for (const RouteStep& step : route){ - if (step.to_wall && !stops_past_end(step)){ + if (step.to_wall && !stops_past_end(step, maps)){ return to_string(step); } } @@ -119,14 +119,14 @@ struct Standing{ Direction facing = Direction::NORTH; std::string error; }; -Standing standing(const Pokemon::Pose& pose){ +Standing standing(const Pokemon::Pose& pose, const std::vector& maps){ const std::optional at = story_pose(pose); if (!at){ return {{}, Direction::NORTH, "no one-tile pose: " + Pokemon::to_string(pose)}; } std::optional facing = at->facing; if (!facing){ - const MapData* map = map_named(at->map); + const MapData* map = map_named(at->map, maps); facing = map ? wall_beside(*map, at->tile) : std::nullopt; } if (!facing){ @@ -248,7 +248,7 @@ Pokemon::StoryAction StoryMapsSim::action(StoryActionId id){ } Outcome StoryMapsSim::legs(const Pokemon::Pose& pose, const StoryStep& step) const{ - const Standing at = standing(pose); + const Standing at = standing(pose, maps()); if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } @@ -332,7 +332,7 @@ Outcome StoryMapsSim::walk_to(Pokemon::RunState& state, const StoryStep& step) c state.gates = gates_after_route(state.gates, *route); return Pokemon::outcome_ok(to_pose(StoryPose{target->map, target->tile, route->back().facing_after})); } - const Standing at = standing(pose); + const Standing at = standing(pose, maps()); if (!at.error.empty()){ return Pokemon::outcome_failed("no_pose", at.error); } @@ -348,7 +348,7 @@ Outcome StoryMapsSim::walk_to(Pokemon::RunState& state, const StoryStep& step) c if (!(end == goal.position)){ return Pokemon::outcome_failed("wrong_end", to_string(end)); } - if (const std::optional leg = overrun_wall_leg(*route)){ + if (const std::optional leg = overrun_wall_leg(*route, maps())){ return Pokemon::outcome_failed("wall_overrun", *leg); } state.gates = gates_after_route(state.gates, *route); @@ -492,7 +492,7 @@ void sim_wait_out_battle_exit(OverworldSim& sim){ std::string OverworldStepSim::walk(const StoryStep& step){ // The sim's own maps and gates, if it has gates: the route opens the // ones the Card Key opens, and the walker's steps open them in the sim. - const std::vector& maps = m_sim.has_gates() ? m_sim.source_maps() : story_maps(); + const std::vector& maps = m_sim.gated() ? m_sim.source_maps() : story_maps(); const Pokemon::GateState& gates = m_sim.state().gates; const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.card_key_held()}); if (route && route->empty()){ From b887582908584d715166c70705419b6082bea7e7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:09:26 -0800 Subject: [PATCH 03/20] FRLG gates: sim keeps gate maps and Card Key in SimState; one walked_route Code health: OverworldSim public_methods back to 8 (gate maps and the Card Key are SimState fields, not accessors); walked_route's maps, gates and rules are default arguments, not an overload. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldSim.cpp | 1 + .../Overworld/PokemonFRLG_OverworldSim.h | 15 --------------- .../PokemonFRLG_OverworldSimField.cpp | 18 +++++++++--------- .../Overworld/PokemonFRLG_OverworldSimState.h | 5 +++++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 8 ++------ .../AutoStory/PokemonFRLG_AutoStoryRowSim.h | 5 +++-- 6 files changed, 20 insertions(+), 32 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index 2881dff960..e9bada9229 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -148,6 +148,7 @@ OverworldSim::OverworldSim(std::vector maps, MapPosition start, Directi } add_coded_field(); m_state.gates = m_script.gates; + m_state.card_key_held = m_script.card_key_held; read_gates(); m_player = PlayerState{start.point, elevation_at(map(), start.point), false}; m_state.facing = facing; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index d6ae67cce9..20c3b3efd1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -108,19 +108,6 @@ class OverworldSim{ // battle follows it. bool close_message(); - // Whether the maps have gates (MapData::gates), and the maps as loaded - // for planning through them, with a gate closed or open as the map - // says; whether the player holds the Card Key (SimScript::card_key_held). - bool gated() const{ - return !m_source_maps.empty(); - } - const std::vector& source_maps() const{ - return m_source_maps; - } - bool card_key_held() const{ - return m_script.card_key_held; - } - // A on what the player faces, as `field` says (`floor`: the lift's). // Returns whether it was there. (PokemonFRLG_OverworldSimField.cpp) bool use_field(SimField field, size_t floor = 0); @@ -215,8 +202,6 @@ class OverworldSim{ const MapData& map() const{ return m_maps[m_map]; } std::vector m_maps; - // The maps as loaded, with the gates closed or open as the map says. - std::vector m_source_maps; SimScript m_script; int m_map = 0; PlayerState m_player; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp index afbe8ab05c..f368a4e3c1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp @@ -147,22 +147,22 @@ bool OverworldSim::start_surf(){ void OverworldSim::read_gates(){ // Only the tiles: the objects the sim has changed stay as they are. // Maps without a gate were not copied. - if (m_source_maps.empty() && has_gates(m_maps)){ - m_source_maps = m_maps; + if (m_state.gate_maps.empty() && has_gates(m_maps)){ + m_state.gate_maps = m_maps; } - for (size_t c = 0; c < m_source_maps.size(); c++){ - if (!m_source_maps[c].gates.empty()){ - m_maps[c].tiles = Pokemon::resolve_tiles(m_source_maps[c], m_state.gates); + for (size_t c = 0; c < m_state.gate_maps.size(); c++){ + if (!m_state.gate_maps[c].gates.empty()){ + m_maps[c].tiles = Pokemon::resolve_tiles(m_state.gate_maps[c], m_state.gates); } } } bool OverworldSim::open_gate(){ - if (m_source_maps.empty()){ + if (m_state.gate_maps.empty()){ violation("no gates on the maps."); return false; } - const MapData& source = m_source_maps[m_map]; + const MapData& source = m_state.gate_maps[m_map]; const Pokemon::MapGate* gate = Pokemon::closed_card_key_gate_faced(source, m_player.position, m_state.facing, m_state.gates); if (gate == nullptr || !m_script.card_key_held || m_state.screen != SimScreen::OVERWORLD || m_frozen){ violation(std::format( @@ -180,9 +180,9 @@ bool OverworldSim::open_gate(){ } bool OverworldSim::press_switch(){ - const Pokemon::MapSwitch* pressed = m_source_maps.empty() + const Pokemon::MapSwitch* pressed = m_state.gate_maps.empty() ? nullptr - : Pokemon::switch_pressed(m_source_maps[m_map], m_player.position, m_state.facing); + : Pokemon::switch_pressed(m_state.gate_maps[m_map], m_player.position, m_state.facing); if (pressed == nullptr || m_state.screen != SimScreen::OVERWORLD || m_frozen){ violation(std::format("no statue to press {} of {}.", direction_name(m_state.facing), to_string(m_state.position))); return false; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h index a848c4988e..7c1e063d98 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h @@ -139,6 +139,11 @@ struct SimState{ // The gates open and the switches on (SimScript::gates, then what the // player opened and pressed). Pokemon::GateState gates; + // The maps as loaded, with each gate closed or open as the map says, to + // plan through the gates (resolve_maps()); empty if no map has a gate. + std::vector gate_maps; + // Whether the player holds the Card Key (SimScript::card_key_held). + bool card_key_held = false; Direction facing = Direction::SOUTH; SimScreen screen = SimScreen::OVERWORLD; // Whether black shows below the map: the player stands near the bottom diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 2d9635feb4..4734133382 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -372,10 +372,6 @@ std::optional> walked_route( return plan_overworld_route_gated(maps, start, goal, gates, rules, story_route_costs(), at.facing); } -std::optional> walked_route(const StoryPose& at, const StoryStep& step){ - return walked_route(at, step, story_maps(), Pokemon::GateState(), Pokemon::GateRules()); -} - OverworldStepSim::OverworldStepSim(OverworldSim& sim, std::string row, StoryPose at) : Pokemon::TableExecutor(m_table, m_guard) @@ -492,9 +488,9 @@ void sim_wait_out_battle_exit(OverworldSim& sim){ std::string OverworldStepSim::walk(const StoryStep& step){ // The sim's own maps and gates, if it has gates: the route opens the // ones the Card Key opens, and the walker's steps open them in the sim. - const std::vector& maps = m_sim.gated() ? m_sim.source_maps() : story_maps(); + const std::vector& maps = !m_sim.state().gate_maps.empty() ? m_sim.state().gate_maps : story_maps(); const Pokemon::GateState& gates = m_sim.state().gates; - const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.card_key_held()}); + const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.state().card_key_held}); if (route && route->empty()){ // Already there. return ""; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h index c1f55ca7c8..593d763f06 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h @@ -20,6 +20,7 @@ #include #include "Pokemon/AutoStory/Pokemon_StoryActions.h" #include "Pokemon/Navigation/Pokemon_GatedTypes.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_AutoStoryEvents.h" @@ -119,9 +120,9 @@ class StoryMapsSim : public Pokemon::TableExecutor{ // the Card Key. std::optional> walked_route( const StoryPose& at, const StoryStep& step, - const std::vector& maps, const Pokemon::GateState& gates, const Pokemon::GateRules& rules + const std::vector& maps = story_maps(), + const Pokemon::GateState& gates = Pokemon::GateState(), const Pokemon::GateRules& rules = Pokemon::GateRules() ); -std::optional> walked_route(const StoryPose& at, const StoryStep& step); // A row's steps on the OverworldSim as the program does them: routes and // legs by the sim's walker from where the table says the player stands, From 85d2ec28d37dfae870610c70c14e2c3c4431cf7b Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:37:09 -0800 Subject: [PATCH 04/20] FRLG maps: pin PokemonSimulation 4b886bb (Silph card-key doors, Mansion statue switches) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- devtools/maps/map-resources.lock.json | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 24f10bf535..71d82cd296 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "frlg": { - "revision": "0c46df1e5e9abe79016f2c8610aeb784835768fe", + "revision": "4b886bbead2e85c42f15bfb0b5ac735c159db039", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "70f1947e4b2474319e87959480abad04f130834d235ef7b8a2f24a0256314c14" + "manifest_sha256": "eeca55d046c02d5866b54f48abe90dc5dc4c59d483cd0edd7a857d374d85dd2c" } } } From fb8795f31e567907a9031b4d684657ebbe903698 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:58:19 -0800 Subject: [PATCH 05/20] FRLG gates: real maps in the gate tests, Mansion 13.01-13.04 planned with PRESS_SWITCH The synthetic gate maps are gone; the gate tests read the real Silph and Mansion maps (pinned in the previous commit). 13.01-13.04 are planned routes: the statue presses and the holes come from the planner, and 13.02 is split so the walk crosses 1F's row 24 out of Ted's line. The row sim plans on the story's maps again (the sim's own maps lacked the Rocket Hideout stairs a switch opens, 09.01). Goldens regenerated. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- SerialPrograms/CMakeLists.txt | 2 - .../GateTestMaps/PokemonMansion_1F.json | 63 ---- .../GateTestMaps/PokemonMansion_3F.json | 59 ---- .../Navigation/GateTestMaps/SilphCo_5F.json | 45 --- .../Pokemon/Navigation/Pokemon_Gates_Tests.h | 24 -- .../Pokemon_NavigationGateTestMaps.h | 30 -- .../PokemonFRLG_OverworldGateMaps_Tests.cpp} | 45 ++- .../PokemonFRLG_OverworldGateMaps_Tests.h | 26 ++ .../PokemonFRLG_OverworldSim_Tests.cpp | 2 + .../PokemonFRLG_AutoStoryGates_Tests.cpp | 68 ++-- .../PokemonFRLG_AutoStoryMansion_Tests.cpp | 93 ++--- .../PokemonFRLG_AutoStoryPlanGolden13.h | 63 +++- .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 7 +- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 88 ++++- .../AutoStory/StoryData/frlg-13.01.plan.json | 75 +--- .../AutoStory/StoryData/frlg-13.02.plan.json | 200 +++-------- .../AutoStory/StoryData/frlg-13.03.plan.json | 327 +++--------------- .../AutoStory/StoryData/frlg-13.04.plan.json | 127 ++----- SerialPrograms/cmake/SourceFiles.cmake | 5 +- 19 files changed, 383 insertions(+), 966 deletions(-) delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h delete mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h rename SerialPrograms/Source/{Pokemon/Navigation/Pokemon_Gates_Tests.cpp => VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp} (92%) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.h diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index ce0ec36aed..b03c3bb1c5 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -240,8 +240,6 @@ pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/Aut VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.h PokemonAutomation::NintendoSwitch::PokemonFRLG autostory_checkpoint_json) pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonFRLG/Programs/AutoStory/ReplayData VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay.h PokemonAutomation::NintendoSwitch::PokemonFRLG story_replay_fixture_json) -pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/GateTestMaps - Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h PokemonAutomation::Pokemon navigation_gate_test_map_json) # Create binary target diff --git a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json deleted file mode 100644 index a7d5797eb4..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json +++ /dev/null @@ -1,63 +0,0 @@ -{ - "format": "pokesim-runtime-map/2", - "name": "PokemonMansion_1F", - "source": {"decomp_file": "data/maps/PokemonMansion_1F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-10-31"}, - "tiles": [ - "######################################", - "######################################", - "######################################", - "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#", - "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#", - "#~~#~#~###~~~#~~~~~#~#~#~#~~#####~~~~#", - "#~~#~~~###~~~#~~~~~#~#~#~#~~#####~~~##", - "#~~~~~~~~~~~~#~~~~~~~~~~~~~~#####~~~##", - "#~~~~~~~~~~~~#~~~~~~~~~~~~~~#~~~~~~~~#", - "#~~~~~~~~~~~~##~~~####~~~####~~~~~~~~#", - "################~~####GGG####~~~###~~#", - "################~~####GGG####~~~###~~#", - "##############~~~~#~~~~~~~####~~~~~~~#", - "#~~~~~~~~~.###~~~~#~~~~~~~~###~~~~~~~#", - "#~~~~~~~~~~###~~~~#~~~~~~~~~##~~~~~~~#", - "#~~~~~~~~~~~~~~~~~#~~~~~~~~~##~~~~~~~#", - "#~~~~~~~~~~~~~~~~~#~~~~~~~~~##~~~~~~~#", - "#~~~~~~~~~~~~~~~###############~~~####", - "#~~~~~~~~~~~~~~~###############GGG####", - "##~~~~~~~~~~~~~~###############GGG####", - "###~~#~~~~~#~~~##~~#####~~~~~~~~~~~~~#", - "###~~#~~~~~#~~~##~~~~~~#~~~~~~~~~~~~~#", - "###~~#~~~~~#~~~##~~~~~~#~~~~~~~~~~~~~#", - "###~~~~~~~~~~~~~#~~~~~~#~~~~~~~~~~~~~#", - "#~~~~~~~~~~~~~~~#~~~~~~####~~~##~~~###", - "#~~~~#~~~~~#~~~~#~~~~~~####GGG##GGG###", - "#~~~~#~~~~~#~~~~#~~########GGG##GGG###", - "#~~~~#~~~~~#~~~~#~~~~~~##.~~~~~#~~~~~#", - "#~~~~~~~~~~~~~~~#~~~~~~##~~~~~~#~~~~~#", - "#~~~~~~~~~~~~~~~#~~~~~~~~~~~~~~#~~~~~#", - "#~~~~#~~~~~#~~~~#~~~~~~~~~~~~~~#~~~~~#", - "#~~~~#~~~~~#~~~~#~~~~~~~~~~~~~~#~~~~~#", - "#~~~~#~~~~~#~~~~#~~######~~~~~~#~~~~~#", - "#~~~~~~~.~~~~~~~#~~~~~~~~~~~~~~#~~.~~#", - "######################################" - ], - "points": {"warp_1": [8, 33], "warp_3": [10, 13], "warp_4": [25, 27], "warp_7": [19, 22], "warp_8": [20, 22]}, - "warps": [ - {"enter": "walk_into", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [7, 33]}, - {"enter": "walk_south", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [8, 33]}, - {"enter": "walk_into", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [9, 33]}, - {"enter": "walk_east", "to_map": "PokemonMansion_2F", "to_point": "warp_2", "coord": [10, 13]}, - {"enter": "walk_west", "to_map": "PokemonMansion_B1F", "to_point": "warp_0", "coord": [25, 27]}, - {"enter": "walk_south", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [34, 33]}, - {"enter": "walk_into", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [35, 34]}, - {"enter": "walk_into", "to_map": "PokemonMansion_3F", "to_point": "warp_3", "coord": [19, 22]}, - {"enter": "walk_into", "to_map": "PokemonMansion_3F", "to_point": "warp_4", "coord": [20, 22]}, - {"enter": "walk_into", "to_map": "PokemonMansion_2F", "to_point": "warp_2", "coord": [11, 13]} - ], - "connections": [], - "gates": { - "barrier_1": {"tiles": [[22, 10], [22, 11], [23, 10], [23, 11], [24, 10], [24, 11]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"}, - "barrier_2": {"tiles": [[31, 18], [31, 19], [32, 18], [32, 19], [33, 18], [33, 19]], "open_glyph": "~", "new_game": "open", "switch": "mansion", "open_when": "off"}, - "barrier_3": {"tiles": [[27, 25], [27, 26], [28, 25], [28, 26], [29, 25], [29, 26]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"}, - "barrier_4": {"tiles": [[32, 25], [32, 26], [33, 25], [33, 26], [34, 25], [34, 26]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"} - }, - "switches": {"mansion": {"flag": "FLAG_POKEMON_MANSION_SWITCH_STATE", "toggle": true, "floors": ["PokemonMansion_1F", "PokemonMansion_2F", "PokemonMansion_3F", "PokemonMansion_B1F"], "statues": [{"coord": [5, 5], "face_from": [5, 6], "facing": "north"}]}} -} diff --git a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json deleted file mode 100644 index 8dc8b4874e..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json +++ /dev/null @@ -1,59 +0,0 @@ -{ - "format": "pokesim-runtime-map/2", - "name": "PokemonMansion_3F", - "source": {"decomp_file": "data/maps/PokemonMansion_3F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-10-31"}, - "tiles": [ - "######################################", - "######################################", - "######################################", - "#~~~~~##.~~~~~~~###~~#~~~~~~~#~~~#~~~#", - "#~~~~~##~~~~~~~~~##~~#~~~~~~~#~~~~#~~#", - "##~~~~~~~~~~#~~~~##~~#~~###~~#~~~~##~#", - "###~~~~~~~~~~~~~~~~~~G~~###~~~~~~~~###", - "###~~~~~~~~~~~~~~~~~~G~~~~~~~~~~~~~~~#", - "########~######~~~~~~G~~~~~~~~~~~~~~~#", - "###############~~~~~~#~~~~~~~~~~~~~~~#", - "########~########~~~######~###~#######", - "#~###~~~~##.~~###GGG##################", - "#~~##~~~~##~~~###GGG######~~~~~#######", - "#~~#~~~~~~~~~~##~~~~~~~~~~~~~~~~~~~~~#", - "#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~#", - "#~~~~~~~~~~~~~####~~~##~~##~~#########", - "#~~~~~###~~~~~####~~~##~~##~~#########", - "####~~###~~~~#####~~~##~~##~~#########", - "####~~~~~~~~######~~~##~~##~~~~~##.~~#", - "#~~~~~~~~~~################~~~~~##~~~#", - "#~~~~~~~~~~~~~#############~~~~~~~~~~#", - "#~~~~~~~~~~~~~#############~~~~~~~~~~#", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################", - "######################################" - ], - "points": {"warp_0": [8, 3], "warp_1": [34, 18], "warp_2": [11, 11], "warp_3": [18, 18], "warp_4": [19, 18], "warp_5": [23, 18]}, - "warps": [ - {"enter": "walk_west", "to_map": "PokemonMansion_2F", "to_point": "warp_0", "coord": [8, 3]}, - {"enter": "walk_west", "to_map": "PokemonMansion_2F", "to_point": "warp_1", "coord": [34, 18]}, - {"enter": "walk_west", "to_map": "PokemonMansion_2F", "to_point": "warp_3", "coord": [11, 11]}, - {"enter": "step_on", "to_map": "PokemonMansion_1F", "to_point": "warp_7", "one_way": true, "coord": [18, 18]}, - {"enter": "step_on", "to_map": "PokemonMansion_1F", "to_point": "warp_8", "one_way": true, "coord": [19, 18]}, - {"enter": "step_on", "to_map": "PokemonMansion_2F", "to_point": "warp_4", "one_way": true, "coord": [23, 18]}, - {"enter": "step_on", "to_map": "PokemonMansion_1F", "to_point": "warp_8", "one_way": true, "coord": [20, 18]}, - {"enter": "step_on", "to_map": "PokemonMansion_2F", "to_point": "warp_4", "one_way": true, "coord": [24, 18]} - ], - "connections": [], - "gates": { - "barrier_1": {"tiles": [[21, 6], [21, 7], [21, 8]], "open_glyph": "~", "new_game": "open", "switch": "mansion", "open_when": "off"}, - "barrier_2": {"tiles": [[17, 11], [17, 12], [18, 11], [18, 12], [19, 11], [19, 12]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"} - }, - "switches": {"mansion": {"flag": "FLAG_POKEMON_MANSION_SWITCH_STATE", "toggle": true, "floors": ["PokemonMansion_1F", "PokemonMansion_2F", "PokemonMansion_3F", "PokemonMansion_B1F"], "statues": [{"coord": [12, 5], "face_from": [12, 6], "facing": "north"}]}} -} diff --git a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json deleted file mode 100644 index 53ecd291ad..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json +++ /dev/null @@ -1,45 +0,0 @@ -{ - "format": "pokesim-runtime-map/2", - "name": "SilphCo_5F", - "source": {"decomp_file": "data/maps/SilphCo_5F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-10-31"}, - "tiles": [ - "####################################", - "####################################", - "############################...#####", - "######################D#####...#####", - ".......##........###................", - ".......##...........................", - ".#.#.#.##...........................", - ".......##.........##########..#####.", - ".......##.........##########..#####.", - ".......GG..#########............###.", - ".......GG..#########.............##.", - ".#.#.#.##..##.....##.....######..##.", - ".......##..##.....##........###..##.", - "#########..###....GG........###..##.", - "#########..##.....GG........###..##.", - ".......##..##.....##.....######..##.", - "...##..##..###....##.............##.", - ".#####.##..##.....##.............##.", - "..####.GG..########################.", - "...###.GG..########################.", - "...###.##....#..#..#..#..#..#..#....", - ".......##..........................." - ], - "points": {"warp_0": [28, 2], "warp_1": [15, 7], "warp_2": [30, 2], "warp_3": [10, 20], "warp_4": [2, 20], "warp_5": [33, 5]}, - "warps": [ - {"enter": "walk_west", "to_map": "SilphCo_4F", "to_point": "warp_0", "coord": [28, 2]}, - {"enter": "step_on", "to_map": "SilphCo_3F", "to_point": "warp_1", "coord": [15, 7]}, - {"enter": "walk_east", "to_map": "SilphCo_6F", "to_point": "warp_2", "coord": [30, 2]}, - {"enter": "step_on", "to_map": "SilphCo_9F", "to_point": "warp_1", "coord": [10, 20]}, - {"enter": "step_on", "to_map": "SilphCo_3F", "to_point": "warp_5", "coord": [2, 20]}, - {"enter": "step_on", "to_map": "SilphCo_7F", "to_point": "warp_2", "coord": [33, 5]}, - {"enter": "walk_into", "to_map": "SilphCo_Elevator", "to_point": "warp_0", "coord": [22, 3]} - ], - "connections": [], - "gates": { - "door_1": {"tiles": [[7, 9], [7, 10], [8, 9], [8, 10]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_SILPH_5F_DOOR_1"}, - "door_2": {"tiles": [[7, 18], [7, 19], [8, 18], [8, 19]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_SILPH_5F_DOOR_2"}, - "door_3": {"tiles": [[18, 13], [18, 14], [19, 13], [19, 14]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_SILPH_5F_DOOR_3"} - } -} diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h deleted file mode 100644 index e82848786c..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* Gates Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_Pokemon_Gates_Tests_H -#define PokemonAutomation_Pokemon_Gates_Tests_H - -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// Registers the gate tests: the map reader's gates, switches and one-way -// warps, the gate state, and the gated planner. -void add_tests_Gates(UnitTestDatabase& database); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h deleted file mode 100644 index 2b3503fee4..0000000000 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h +++ /dev/null @@ -1,30 +0,0 @@ -/* Navigation Gate Test Maps - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_Pokemon_NavigationGateTestMaps_H -#define PokemonAutomation_Pokemon_NavigationGateTestMaps_H - -#include -#include -#include - -namespace PokemonAutomation{ -namespace Pokemon{ - - -// (name, JSON text) of each map in Pokemon/Navigation/GateTestMaps/, built -// into the program by pa_embed_text_files() (cmake/EmbedTextFiles.cmake): -// SilphCo_5F (card-key doors), PokemonMansion_1F (statue-switch barriers) -// and PokemonMansion_3F (barriers, a statue, and holes: one-way warps), -// trimmed from PokemonSimulation's runtime maps. 3F's hole tiles are -// tall grass here, which the reader knows. -const std::vector>& navigation_gate_test_map_json(); - - - -} // namespace Pokemon -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp similarity index 92% rename from SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp rename to SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp index 46f062f7f6..0e659afb2d 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp @@ -1,10 +1,9 @@ -/* Gates Tests +/* Overworld Gate Maps Tests * * From: https://github.com/PokemonAutomation/ * - * Fixtures: GateTestMaps/, trimmed from PokemonSimulation's runtime maps - * (SilphCo_5F: card-key doors; PokemonMansion_1F and _3F: statue switch, - * barriers, holes). + * The real maps, pinned PokemonSimulation resources: SilphCo_5F (card-key + * doors) and PokemonMansion_1F and _3F (statue switch, barriers, holes). * */ @@ -16,30 +15,25 @@ #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/TestRunners/UnitTest.h" -#include "Pokemon_GatedPlanner.h" -#include "Pokemon_Gates_Tests.h" -#include "Pokemon_NavigationGateTestMaps.h" +#include "Pokemon/Navigation/Pokemon_GatedPlanner.h" +#include "PokemonFRLG_OverworldGateMaps_Tests.h" +#include "PokemonFRLG_OverworldMaps.h" namespace PokemonAutomation{ -namespace Pokemon{ -namespace{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ +using namespace Pokemon; + +namespace{ -MapData load(const std::string& name){ - for (const auto& [file, text] : navigation_gate_test_map_json()){ - if (file == name){ - return parse_map(parse_json(text), name + ".json"); - } - } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No gate test map " + name); -} // Silph 5F, Mansion 1F and 3F, in that order. const std::vector& maps(){ static const std::vector loaded{ - load("SilphCo_5F"), - load("PokemonMansion_1F"), - load("PokemonMansion_3F"), + load_map("SilphCo_5F"), + load_map("PokemonMansion_1F"), + load_map("PokemonMansion_3F"), }; return loaded; } @@ -94,7 +88,7 @@ class GateGame{ private: static bool walkable(TileKind tile){ - return tile == TileKind::OPEN || tile == TileKind::TALL_GRASS; + return tile == TileKind::OPEN || tile == TileKind::TALL_GRASS || tile == TileKind::FALL_HOLE; } }; @@ -194,7 +188,7 @@ std::string parse_error(const std::string& rows, const std::string& gates, const "gates": {}, "switches": {} }})", rows, gates, switches); try{ - parse_map(parse_json(text), "T.json"); + Pokemon::parse_map(parse_json(text), "T.json"); }catch (ParseException& e){ return e.message(); } @@ -417,7 +411,7 @@ struct GatesTestCase{ class Test_Gates : public UnitTest{ public: explicit Test_Gates(GatesTestCase scenario) - : UnitTest(std::format("Pokemon::Gates - {}", scenario.input.name)) + : UnitTest(std::format("PokemonFRLG::OverworldGateMaps - {}", scenario.input.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -482,7 +476,7 @@ const GatesTestCase GATES_CASES[] = { } // namespace -void add_tests_Gates(UnitTestDatabase& database){ +void add_tests_OverworldGateMaps(UnitTestDatabase& database){ for (const auto& scenario : GATES_CASES){ database.add(scenario); } @@ -490,5 +484,6 @@ void add_tests_Gates(UnitTestDatabase& database){ -} // namespace Pokemon +} // namespace PokemonFRLG +} // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.h new file mode 100644 index 0000000000..8d5d15317b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.h @@ -0,0 +1,26 @@ +/* Overworld Gate Maps Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_OverworldGateMaps_Tests_H +#define PokemonAutomation_PokemonFRLG_OverworldGateMaps_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Registers the gate tests on the real Silph Co. and Mansion maps: the map reader's gates, switches and one-way +// warps, the gate state, and the gated planner. +void add_tests_OverworldGateMaps(UnitTestDatabase& database); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp index 3dcbaaa052..8270061996 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp @@ -21,6 +21,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonFRLG_OverworldGateMaps_Tests.h" #include "PokemonFRLG_OverworldLateBattle.h" #include "PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_OverworldSim.h" @@ -1039,6 +1040,7 @@ void add_tests_OverworldSim(UnitTestDatabase& database){ add_tests_OverworldWarpFade(database); add_tests_OverworldStairs(database); add_tests_OverworldGates(database); + add_tests_OverworldGateMaps(database); add_tests_OverworldSpin(database); add_tests_OverworldBike(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp index 00d32ee224..84f80324a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp @@ -58,26 +58,18 @@ class Test_AutoStoryGates : public UnitTest{ GatesCase m_case; }; -// Silph Co. 5F's corridor, shortened: a card-key door at (4, 1). -const std::vector& door_maps(){ - static const std::vector MAPS{parse_map(R"({ - "format": "pokesim-runtime-map/2", "name": "SilphHall", "points": {}, "warps": [], "connections": [], "source": {"decomp_file": "", "revision": "test", "date": "2026-11-12"}, - "tiles": ["#########", "#...G...#", "#########"], - "gates": {"door_1": {"tiles": [[4, 1]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_TEST"}} - })", "SilphHall")}; - return MAPS; -} +// A walk across a gate on the real maps: Silph Co. 5F's card-key door, and +// the Pokemon Mansion 1F's barrier behind its statue's switch. +struct Scene{ + const char* map; + TilePos start; + TilePos goal; +}; +constexpr Scene DOOR{"SilphCo_5F", {10, 9}, {5, 9}}; +constexpr Scene STATUE{"PokemonMansion_1F", {5, 8}, {19, 13}}; -// The Mansion's 1F, shortened: a statue at (1, 0) and a barrier at (4, 1) -// that its switch opens. -const std::vector& statue_maps(){ - static const std::vector MAPS{parse_map(R"({ - "format": "pokesim-runtime-map/2", "name": "MansionHall", "points": {}, "warps": [], "connections": [], "source": {"decomp_file": "", "revision": "test", "date": "2026-11-12"}, - "tiles": ["#########", "#...G...#", "#########"], - "gates": {"barrier_1": {"tiles": [[4, 1]], "open_glyph": ".", "new_game": "closed", "switch": "mansion", "open_when": "on"}}, - "switches": {"mansion": {"flag": "FLAG_TEST_SWITCH", "toggle": true, "floors": ["MansionHall"], - "statues": [{"coord": [1, 0], "face_from": [1, 1], "facing": "north"}]}} - })", "MansionHall")}; +const std::vector& scene_maps(){ + static const std::vector MAPS = overworld_maps(); return MAPS; } @@ -89,9 +81,9 @@ StoryStep route_step(const std::string& map, TilePos goal){ return step; } -Pokemon::RunState run_state(const std::string& map, bool card_key){ +Pokemon::RunState run_state(const Scene& scene, bool card_key){ Pokemon::RunState state; - state.pose = to_pose(StoryPose{map, TilePos{1, 1}, Direction::EAST}); + state.pose = to_pose(StoryPose{scene.map, scene.start, Direction::EAST}); if (card_key){ state.flags.insert("card_key_held"); } @@ -99,12 +91,12 @@ Pokemon::RunState run_state(const std::string& map, bool card_key){ } // The step on StoryMapsSim over `maps`, from the start of the corridor. -Pokemon::Outcome on_maps(const std::vector& maps, const std::string& map, bool card_key, Pokemon::RunState& state){ +Pokemon::Outcome on_maps(const Scene& scene, bool card_key, Pokemon::RunState& state){ StorySimKnobs knobs; - knobs.maps = &maps; + knobs.maps = &scene_maps(); StoryMapsSim sim(knobs); - state = run_state(map, card_key); - return sim.run(route_step(map, TilePos{6, 1}), state); + state = run_state(scene, card_key); + return sim.run(route_step(scene.map, scene.goal), state); } @@ -112,7 +104,7 @@ Pokemon::Outcome on_maps(const std::vector& maps, const std::string& ma // not walk through gates the run has not opened. UnitTestResult test_maps_sim_door_blocks(){ Pokemon::RunState state; - const Pokemon::Outcome outcome = on_maps(door_maps(), "SilphHall", false, state); + const Pokemon::Outcome outcome = on_maps(DOOR, false, state); if (outcome.succeeded()){ return "The row sim walked through a closed card-key door without the Card Key."; } @@ -121,11 +113,11 @@ UnitTestResult test_maps_sim_door_blocks(){ UnitTestResult test_maps_sim_door_opens(){ Pokemon::RunState state; - const Pokemon::Outcome outcome = on_maps(door_maps(), "SilphHall", true, state); + const Pokemon::Outcome outcome = on_maps(DOOR, true, state); if (!outcome.succeeded()){ return "The row sim did not open the door for a player with the Card Key: " + Pokemon::to_string(outcome); } - if (!state.gates.opened.contains("SilphHall/door_1")){ + if (!state.gates.opened.contains("SilphCo_5F/door_1")){ return "The run's gates do not have the door open after the step."; } return true; @@ -133,7 +125,7 @@ UnitTestResult test_maps_sim_door_opens(){ UnitTestResult test_maps_sim_statue_switch(){ Pokemon::RunState state; - const Pokemon::Outcome outcome = on_maps(statue_maps(), "MansionHall", false, state); + const Pokemon::Outcome outcome = on_maps(STATUE, false, state); if (!outcome.succeeded()){ return "The row sim did not press the statue for the barrier: " + Pokemon::to_string(outcome); } @@ -149,12 +141,12 @@ struct GateStateOut{ }; // The step on OverworldStepSim and its OverworldSim, with the Card Key as `card_key`. -std::string on_overworld_sim(const std::vector& maps, const std::string& map, bool card_key, GateStateOut& out){ +std::string on_overworld_sim(const Scene& scene, bool card_key, GateStateOut& out){ SimScript script; script.card_key_held = card_key; - OverworldSim sim(maps, MapPosition{map, TilePos{1, 1}}, Direction::EAST, script); - StoryPose at{map, TilePos{1, 1}, Direction::EAST}; - const std::string failure = row_step_on_sim(sim, at, route_step(map, TilePos{6, 1}), "test"); + OverworldSim sim(scene_maps(), MapPosition{scene.map, scene.start}, Direction::EAST, script); + StoryPose at{scene.map, scene.start, Direction::EAST}; + const std::string failure = row_step_on_sim(sim, at, route_step(scene.map, scene.goal), "test"); out.gates = sim.state().gates; out.position = sim.state().position; return failure; @@ -162,7 +154,7 @@ std::string on_overworld_sim(const std::vector& maps, const std::string UnitTestResult test_step_sim_door_blocks(){ GateStateOut out; - if (on_overworld_sim(door_maps(), "SilphHall", false, out).empty()){ + if (on_overworld_sim(DOOR, false, out).empty()){ return "The step walked through a closed card-key door without the Card Key."; } return true; @@ -170,11 +162,11 @@ UnitTestResult test_step_sim_door_blocks(){ UnitTestResult test_step_sim_door_opens(){ GateStateOut out; - const std::string failure = on_overworld_sim(door_maps(), "SilphHall", true, out); + const std::string failure = on_overworld_sim(DOOR, true, out); if (!failure.empty()){ return "The step did not open the door for a player with the Card Key: " + failure; } - if (!out.gates.opened.contains("SilphHall/door_1") || !(out.position == MapPosition{"SilphHall", TilePos{6, 1}})){ + if (!out.gates.opened.contains("SilphCo_5F/door_1") || !(out.position == MapPosition{DOOR.map, DOOR.goal})){ return "Expected the door open and the player at the goal, ended at " + to_string(out.position); } return true; @@ -182,11 +174,11 @@ UnitTestResult test_step_sim_door_opens(){ UnitTestResult test_step_sim_statue_switch(){ GateStateOut out; - const std::string failure = on_overworld_sim(statue_maps(), "MansionHall", false, out); + const std::string failure = on_overworld_sim(STATUE, false, out); if (!failure.empty()){ return "The step did not press the statue: " + failure; } - if (!out.gates.switch_on("mansion") || !(out.position == MapPosition{"MansionHall", TilePos{6, 1}})){ + if (!out.gates.switch_on("mansion") || !(out.position == MapPosition{STATUE.map, STATUE.goal})){ return "Expected the switch on and the player at the goal, ended at " + to_string(out.position); } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMansion_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMansion_Tests.cpp index 01aeb65a89..8679139cba 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMansion_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMansion_Tests.cpp @@ -4,8 +4,9 @@ * * Rows 13.01 to 13.04 (StoryData/frlg-13.0N.plan.json) on the overworld * sim: Cinnabar's Center to the Pokemon Mansion's statue switches, the - * SECRET KEY and the Escape Rope out. The sim has the map's switch state - * (flag clear), so a step through a barrier the switches open is declared. + * SECRET KEY and the Escape Rope out. The sim reads the real maps through + * the switch's state, from the checkpoint's start_gates, and the routes + * press the statues themselves. * */ @@ -90,72 +91,27 @@ struct MansionRow{ std::vector floors; }; -// A step over a tile the switches open: the pack's maps are the clear -// state, where it is a wall, so the sim cannot walk it and the step's -// declared pose stands. `wall` is whether the tile it lands on is such a -// barrier on the map; the step after it, onto floor, is declared too. -struct SwitchStep{ - std::string_view row; - std::string_view step; - bool wall; -}; - -const SwitchStep SWITCH_STEPS[] = { - {"13.02", "into_opening_1", true}, - {"13.02", "into_opening_2", true}, - {"13.02", "through_opening", false}, - {"13.03", "into_room_2", true}, - {"13.03", "into_room_3", true}, - {"13.04", "into_opening", true}, - {"13.04", "through_opening", false}, -}; - -const SwitchStep* switch_step(std::string_view row, std::string_view step){ - for (const SwitchStep& item : SWITCH_STEPS){ - if (item.row == row && item.step == step){ - return &item; - } - } - return nullptr; -} - -bool map_wall(const MapPosition& at){ - for (const MapData& map : story_maps()){ - if (map.name == at.map){ - return map.tiles.at(at.point) == TileKind::WALL; - } - } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("No map {}.", at.map)); -} - -// A row on the sim from its start: every step lands (a switch step on its -// declared pose, on a barrier that is a wall on the map), the row ends on -// its postcondition's tile after the floors it should cross, and nobody but Lewis is met and no rule is broken on the way (checked -// after each step). +// A row on the sim from its start, through the gates it has on a save +// (start_gates): every step lands (a route presses the statues it needs), +// the row ends on its postcondition's tile after the floors it should +// cross, the switch is as its last step says, and nobody but Lewis is met +// and no rule is broken on the way (checked after each step). UnitTestResult test_row(const MansionRow& expected){ const StoryCheckpoint& row = checkpoint(expected.id); StoryPose at = *story_pose(Pokemon::pose_of(*row.start)); + SimScript script; + script.gates = row.start_gates.value_or(Pokemon::GateState()); std::optional sim; - sim.emplace(story_maps(), MapPosition{at.map, at.tile}, *at.facing); + sim.emplace(story_maps(), MapPosition{at.map, at.tile}, *at.facing, script); std::vector floors; for (const StoryStep& step : row.steps){ - if (const SwitchStep* barrier = switch_step(row.id, step.name)){ - at = *story_pose(Pokemon::pose_of(*step.pose_after)); - if (map_wall(MapPosition{at.map, at.tile}) != barrier->wall){ - return std::format("{}/{}: expected {} on {}.", row.id, step.name, barrier->wall ? "a barrier" : "floor", to_string(MapPosition{at.map, at.tile})); - } - sim.emplace(story_maps(), MapPosition{at.map, at.tile}, *at.facing); - }else if (step.name == "escape_rope"){ + if (step.name == "escape_rope"){ // The rope's script has no map: the player stands where it says. at = *story_pose(Pokemon::pose_of(*step.pose_after)); - sim.emplace(story_maps(), MapPosition{at.map, at.tile}, *at.facing); + sim.emplace(story_maps(), MapPosition{at.map, at.tile}, *at.facing, script); }else if (const std::string failure = row_step_on_sim(*sim, at, step, row.id); !failure.empty()){ return std::format("{}: ended on {}; {}", row.id, to_string(sim->state().position), failure); } - if (step.name == "down_the_hole"){ - // The hole's fade: a declared step does not wait it out, a walk does. - sim->watch({}, OverworldWalkSteps::AFTER_WARP); - } if (!sim->state().violations.empty()){ return std::format("{}/{}: broke a rule on the way, on {}: {}.", row.id, step.name, to_string(sim->state().position), sim->state().violations.front()); } @@ -167,6 +123,9 @@ UnitTestResult test_row(const MansionRow& expected){ if (floors.empty() || floors.back() != at.map){ floors.push_back(at.map); } + if (step.name != "escape_rope"){ + script.gates = sim->state().gates; + } } if (!(MapPosition{at.map, at.tile} == expected.end)){ return std::format("{}: ended on {}, not {}.", row.id, to_string(MapPosition{at.map, at.tile}), to_string(expected.end)); @@ -181,31 +140,31 @@ UnitTestResult test_row(const MansionRow& expected){ return true; } -const MansionRow ROW_13_01{"13.01", {"PokemonMansion_3F", {12, 6}}, +const MansionRow ROW_13_01{"13.01", {"PokemonMansion_3F", {19, 13}}, {"PokemonMansion_3F"}}; const MansionRow ROW_13_02{"13.02", {"PokemonMansion_B1F", {34, 29}}, - {"PokemonMansion_3F", "PokemonMansion_1F", "PokemonMansion_B1F"}}; -const MansionRow ROW_13_03{"13.03", {"PokemonMansion_B1F", {27, 6}}, + {"PokemonMansion_1F", "PokemonMansion_B1F"}}; +const MansionRow ROW_13_03{"13.03", {"PokemonMansion_B1F", {23, 5}}, {"PokemonMansion_B1F"}}; const MansionRow ROW_13_04{"13.04", {"CinnabarIsland", {8, 4}}, {"PokemonMansion_B1F", "CinnabarIsland"}}; const AutoStoryMansionCase AUTO_STORY_MANSION_CASES[] = { { - .input = {.name = "13.01 Cinnabar to the Mansion's 3F statue", .body = []{ return test_row(ROW_13_01); }}, - .expectation = {.description = "through 1F and 2F to 3F's (12, 6), nobody met"}, + .input = {.name = "13.01 Cinnabar to the Mansion's 3F room of holes", .body = []{ return test_row(ROW_13_01); }}, + .expectation = {.description = "through 1F and 2F to 3F's (19, 13) by a statue press, nobody met"}, }, { - .input = {.name = "13.02 3F's opening, the hole, 1F's stairs", .body = []{ return test_row(ROW_13_02); }}, - .expectation = {.description = "through the declared opening and the hole to B1F's (34, 29)"}, + .input = {.name = "13.02 3F's hole, 1F's stairs", .body = []{ return test_row(ROW_13_02); }}, + .expectation = {.description = "through the hole and the stairs to B1F's (34, 29)"}, }, { - .input = {.name = "13.03 B1F's two statues, the Elixir and TM14", .body = []{ return test_row(ROW_13_03); }}, - .expectation = {.description = "through the declared opening to (27, 6), nobody but Lewis met"}, + .input = {.name = "13.03 B1F's Elixir and TM14", .body = []{ return test_row(ROW_13_03); }}, + .expectation = {.description = "by a statue press to the Elixir and TM14, nobody but Lewis met"}, }, { .input = {.name = "13.04 the SECRET KEY and the Escape Rope", .body = []{ return test_row(ROW_13_04); }}, - .expectation = {.description = "through the declared opening to the key, out by the rope to (8, 4)"}, + .expectation = {.description = "by a statue press to the key, out by the rope to (8, 4)"}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden13.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden13.h index 8f249b0c04..57e3a4717b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden13.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden13.h @@ -18,7 +18,7 @@ namespace PokemonFRLG{ // The stored plan lines of segment 13, after FRLG_PLAN_GOLDEN_16's. inline constexpr std::string_view FRLG_PLAN_GOLDEN_13[] = { - "13.01 mansion_3f from CinnabarIsland_PokemonCenter_1F (7, 4) facing north to PokemonMansion_3F (8, 3) facing east", + "13.01 mansion_holes from CinnabarIsland_PokemonCenter_1F (7, 4) facing north to PokemonMansion_3F (19, 13) facing south", "13.01 walk south 5 (warp) -> CinnabarIsland (14, 12) [walk only]", "13.01 walk east 7 -> CinnabarIsland (21, 12)", "13.01 walk north 7 (to wall) -> CinnabarIsland (21, 5)", @@ -32,8 +32,65 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN_13[] = { "13.01 walk west 8 -> PokemonMansion_2F (9, 6) [wild]", "13.01 walk north 3 (to wall) -> PokemonMansion_2F (9, 3) [wild]", "13.01 walk east 1 (warp) -> PokemonMansion_3F (8, 3)", - "13.02 down_to_b1f from PokemonMansion_1F (26, 27) facing north to PokemonMansion_B1F (34, 29) facing west", - "13.02 walk west 2 (warp) -> PokemonMansion_B1F (34, 29)", + "13.01 walk south 3 -> PokemonMansion_3F (8, 6) [wild]", + "13.01 walk east 4 -> PokemonMansion_3F (12, 6) [wild]", + "13.01 press switch north -> PokemonMansion_3F (12, 6)", + "13.01 walk east 8 (to wall) -> PokemonMansion_3F (20, 6) [wild]", + "13.01 walk north 3 (to wall) -> PokemonMansion_3F (20, 3) [wild]", + "13.01 walk west 1 (to wall) -> PokemonMansion_3F (19, 3) [wild]", + "13.01 walk south 10 -> PokemonMansion_3F (19, 13) [wild]", + "13.02 to_ted_room from PokemonMansion_3F (19, 13) facing south to PokemonMansion_1F (17, 23) facing south", + "13.02 walk south 5 (warp) -> PokemonMansion_1F (20, 22) [wild]", + "13.02 walk west 3 (to wall) -> PokemonMansion_1F (17, 22) [wild]", + "13.02 walk south 1 -> PokemonMansion_1F (17, 23) [wild]", + "13.02 past_ted from PokemonMansion_1F (17, 23) facing south to PokemonMansion_1F (17, 25) facing south", + "13.02 walk south 2 -> PokemonMansion_1F (17, 25) [wild]", + "13.02 down_to_b1f from PokemonMansion_1F (17, 25) facing south to PokemonMansion_B1F (34, 29) facing west", + "13.02 walk south 8 (to wall) -> PokemonMansion_1F (17, 33) [wild]", + "13.02 walk east 13 (to wall) -> PokemonMansion_1F (30, 33) [wild]", + "13.02 walk north 6 (to wall) -> PokemonMansion_1F (30, 27) [wild]", + "13.02 walk west 6 (warp) -> PokemonMansion_B1F (34, 29) [wild]", + "13.03 to_elixir from PokemonMansion_B1F (34, 29) facing west to PokemonMansion_B1F (34, 5) facing east", + "13.03 walk west 7 (to wall) -> PokemonMansion_B1F (27, 29) [wild]", + "13.03 walk north 12 (to wall) -> PokemonMansion_B1F (27, 17) [wild]", + "13.03 walk west 5 -> PokemonMansion_B1F (22, 17) [wild]", + "13.03 walk south 9 (to wall) -> PokemonMansion_B1F (22, 26) [wild]", + "13.03 walk east 3 (to wall) -> PokemonMansion_B1F (25, 26) [wild]", + "13.03 walk south 5 (to wall) -> PokemonMansion_B1F (25, 31) [wild]", + "13.03 walk west 1 -> PokemonMansion_B1F (24, 31) [wild]", + "13.03 walk north 1 (to wall) -> PokemonMansion_B1F (24, 30) [wild]", + "13.03 press switch north -> PokemonMansion_B1F (24, 30)", + "13.03 walk west 9 -> PokemonMansion_B1F (15, 30) [wild]", + "13.03 walk north 13 (to wall) -> PokemonMansion_B1F (15, 17) [wild]", + "13.03 walk east 14 (to wall) -> PokemonMansion_B1F (29, 17) [wild]", + "13.03 walk south 5 -> PokemonMansion_B1F (29, 22) [wild]", + "13.03 walk east 4 -> PokemonMansion_B1F (33, 22) [wild]", + "13.03 walk north 17 -> PokemonMansion_B1F (33, 5) [wild]", + "13.03 walk east 1 -> PokemonMansion_B1F (34, 5) [wild]", + "13.03 to_tm14 from PokemonMansion_B1F (34, 5) facing east to PokemonMansion_B1F (23, 5) facing north", + "13.03 walk west 4 -> PokemonMansion_B1F (30, 5) [wild]", + "13.03 walk south 8 (to wall) -> PokemonMansion_B1F (30, 13) [wild]", + "13.03 walk west 11 -> PokemonMansion_B1F (19, 13) [wild]", + "13.03 walk north 10 (to wall) -> PokemonMansion_B1F (19, 3) [wild]", + "13.03 walk east 5 (to wall) -> PokemonMansion_B1F (24, 3) [wild]", + "13.03 walk south 2 (to wall) -> PokemonMansion_B1F (24, 5) [wild]", + "13.03 walk west 1 -> PokemonMansion_B1F (23, 5) [wild]", + "13.03 face north -> PokemonMansion_B1F (23, 5)", + "13.04 to_key from PokemonMansion_B1F (23, 5) facing north to PokemonMansion_B1F (5, 6) facing south", + "13.04 walk west 4 -> PokemonMansion_B1F (19, 5) [wild]", + "13.04 walk south 8 (to wall) -> PokemonMansion_B1F (19, 13) [wild]", + "13.04 walk east 11 -> PokemonMansion_B1F (30, 13) [wild]", + "13.04 walk north 10 (to wall) -> PokemonMansion_B1F (30, 3) [wild]", + "13.04 walk west 4 (to wall) -> PokemonMansion_B1F (26, 3) [wild]", + "13.04 walk south 3 (to wall) -> PokemonMansion_B1F (26, 6) [wild]", + "13.04 walk east 1 -> PokemonMansion_B1F (27, 6) [wild]", + "13.04 press switch north -> PokemonMansion_B1F (27, 6)", + "13.04 walk east 3 -> PokemonMansion_B1F (30, 6) [wild]", + "13.04 walk south 4 -> PokemonMansion_B1F (30, 10) [wild]", + "13.04 walk west 29 (to wall) -> PokemonMansion_B1F (1, 10) [wild]", + "13.04 walk north 4 -> PokemonMansion_B1F (1, 6) [wild]", + "13.04 walk east 4 -> PokemonMansion_B1F (5, 6) [wild]", + "13.04 face south -> PokemonMansion_B1F (5, 6)", }; } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 4734133382..f5a138d6a9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -486,9 +486,10 @@ void sim_wait_out_battle_exit(OverworldSim& sim){ // A ROUTE or LEGS by the sim's walker, fighting a trainer who sees the // player on the way. std::string OverworldStepSim::walk(const StoryStep& step){ - // The sim's own maps and gates, if it has gates: the route opens the - // ones the Card Key opens, and the walker's steps open them in the sim. - const std::vector& maps = !m_sim.state().gate_maps.empty() ? m_sim.state().gate_maps : story_maps(); + // The story's maps, as the planner and the program have them (the grunt the sim has + // hidden stands on them, and the stairs a switch opens are open); the gates are the sim's, + // which the walker's steps open. + const std::vector& maps = story_maps(); const Pokemon::GateState& gates = m_sim.state().gates; const std::optional> route = walked_route(m_at, step, maps, gates, Pokemon::GateRules{.card_key_held = m_sim.state().card_key_held}); if (route && route->empty()){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index ea8cc3304d..7837cedfd4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -22,6 +22,7 @@ #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_OptionMenuReader.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRoute.h" @@ -95,6 +96,58 @@ const MapData* find_map_named(const std::string& name){ return nullptr; } +// The gates the walk the test is following has opened and the switches it +// has pressed, and whether it holds the Card Key: what the story's steps +// carry through a checkpoint (start_gates, gates_after, flags_after). Each +// test runs on one thread, from begin_walk() on. +struct WalkGates{ + Pokemon::GateState gates; + bool card_key_held = false; +}; +thread_local WalkGates WALK; + +// Starts a walk at `checkpoint`'s start: its start_gates and start_flags. +void begin_walk(const StoryCheckpoint& checkpoint){ + WALK = WalkGates{}; + if (checkpoint.start_gates){ + WALK.gates = *checkpoint.start_gates; + } + WALK.card_key_held = std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end(); +} + +// A walk through the checkpoint that follows the one before: only what its +// start says replaces the gates carried. +void continue_walk(const StoryCheckpoint& checkpoint){ + if (checkpoint.start_gates){ + WALK.gates = *checkpoint.start_gates; + } + if (std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end()){ + WALK.card_key_held = true; + } +} + +// What `step` does to the walk's gates once done, besides a route's own. +void apply_step_effects(const StoryStep& step){ + if (step.gates_after){ + apply_gate_change(WALK.gates, *step.gates_after); + } + if (std::ranges::find(step.flags_after, "card_key_held") != step.flags_after.end()){ + WALK.card_key_held = true; + } +} + +// The story's maps as the walk's gates make them. +const std::vector& walk_maps(){ + thread_local std::optional>> resolved; + if (!has_gates(story_maps())){ + return story_maps(); + } + if (!resolved || !(resolved->first == WALK.gates)){ + resolved.emplace(WALK.gates, resolve_maps(story_maps(), WALK.gates)); + } + return resolved->second; +} + std::string describe(const std::vector& route){ std::string text; for (const RouteStep& step : route){ @@ -164,7 +217,7 @@ UnitTestResult check_held_legs(const std::string& name, const std::vector> route = fixed_route(story_maps(), MapPosition{pose.map, pose.tile}, Pokemon::story_arg>(step.args, "legs")); + const std::optional> route = fixed_route(walk_maps(), MapPosition{pose.map, pose.tile}, Pokemon::story_arg>(step.args, "legs")); if (!route || route->empty()){ return step.name + ": the legs can't be walked from " + describe(pose) + "."; } @@ -214,7 +267,8 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vector(step.args, "target")); const RouteGoal goal{{target.map, target.tile}, target.facing}; - const std::optional> route = plan_overworld_route(story_maps(), start, goal, default_route_costs(), facing); + const Pokemon::GateRules rules{.card_key_held = WALK.card_key_held}; + const std::optional> route = plan_overworld_route_gated(story_maps(), start, goal, WALK.gates, rules, default_route_costs(), facing); if (!route){ return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; } @@ -223,7 +277,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vectorempty() ? facing : route->back().facing_after}; return true; } @@ -271,6 +326,7 @@ UnitTestResult check_checkpoint_steps(const StoryCheckpoint& checkpoint, StoryPo if (step.pose_after){ pose = one_tile(Pokemon::grid_pose_of(*step.pose_after)); } + apply_step_effects(step); } return true; } @@ -295,8 +351,10 @@ UnitTestResult chain_story_routes(std::vector& golden){ return "Expected 63 checkpoints, the first from a new game."; } StoryPose pose; + WALK = WalkGates{}; for (size_t c = 0; c < checkpoints.size(); c++){ const StoryCheckpoint& checkpoint = checkpoints[c]; + continue_walk(checkpoint); if (c > 0 && starts_after_unauthored_rows(checkpoint.id)){ pose = one_tile(Pokemon::grid_pose_of(*checkpoint.start)); }else if (c > 0){ @@ -541,12 +599,12 @@ std::vector legs_walked(const StoryPose& pose, const StoryStep& step) const MapPosition start{pose.map, pose.tile}; std::optional> route; if (step.kind == StoryStepKind::LEGS){ - route = fixed_route(story_maps(), start, Pokemon::story_arg>(step.args, "legs")); + route = fixed_route(walk_maps(), start, Pokemon::story_arg>(step.args, "legs")); }else if (step.args.contains("target")){ const MapData* map = find_map_named(pose.map); const std::optional facing = pose.facing ? pose.facing : map ? wall_beside(*map, pose.tile) : std::nullopt; const StoryPose target = one_tile(Pokemon::story_arg(step.args, "target")); - route = plan_overworld_route(story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, story_route_costs(), facing); + route = plan_overworld_route_gated(story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, WALK.gates, Pokemon::GateRules{.card_key_held = WALK.card_key_held}, story_route_costs(), facing); } return route ? *route : std::vector{}; } @@ -575,7 +633,7 @@ std::vector> wanderer_stops(const StoryPose& pose, co std::vector> stops; MapPosition from{pose.map, pose.tile}; for (const RouteStep& leg : legs_walked(pose, step)){ - const std::optional c = trainer_crossing(story_maps(), from, leg); + const std::optional c = trainer_crossing(walk_maps(), from, leg); if (c && std::any_of(c->seen.begin(), c->seen.end(), wanderer_sees)){ stops.push_back(c->seen.size() == 1 && !leg.wild && !leg.warps ? std::optional(c->seen[0]) : std::nullopt); } @@ -595,7 +653,7 @@ std::string held_past_lookers(const StoryPose& pose, const StoryStep& step, cons for (const RouteStep& leg : legs_walked(pose, step)){ const MapData* map = find_map_named(from.map); bool crosses = false; - for (const MapPosition& tile : leg.action == RouteAction::WALK && map ? leg_tiles(story_maps(), from, leg) : std::vector{}){ + for (const MapPosition& tile : leg.action == RouteAction::WALK && map ? leg_tiles(walk_maps(), from, leg) : std::vector{}){ for (const MapObject& object : map->objects){ crosses |= looks_around(object) && !beaten.contains(&object) && trainer_may_see(*map, object, tile.point); } @@ -614,7 +672,7 @@ std::vector tiles_walked(const StoryPose& pose, const StoryStep& st MapPosition from{pose.map, pose.tile}; for (const RouteStep& leg : legs_walked(pose, step)){ if (leg.action == RouteAction::WALK){ - const std::vector passed = leg_tiles(story_maps(), from, leg); + const std::vector passed = leg_tiles(walk_maps(), from, leg); tiles.insert(tiles.end(), passed.begin() + 1, passed.end()); } from = leg.end; @@ -665,6 +723,7 @@ UnitTestResult advance(StoryPose& pose, const StoryStep& step){ if (step.pose_after){ pose = one_tile(Pokemon::grid_pose_of(*step.pose_after)); } + apply_step_effects(step); return true; } @@ -673,6 +732,7 @@ UnitTestResult advance(StoryPose& pose, const StoryStep& step){ // `repelled`: a Repel the table used is on (it lasts past the // checkpoint's save): grass is walked as any floor. UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set& beaten, bool& repelled){ + begin_walk(checkpoint); StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint.start)); for (size_t c = 0; c < checkpoint.steps.size(); c++){ const StoryStep& step = checkpoint.steps[c]; @@ -692,9 +752,9 @@ UnitTestResult check_lines(const StoryCheckpoint& checkpoint, std::set> stops = walks ? wanderer_stops(pose, step) : std::vector>{}; - // 13.03's walk into Lewis's room, B1F of the Pokemon Mansion: its one way in, + // 13.03's walk into (and, planned, past) Lewis's room, B1F of the Pokemon Mansion: its one way in, // (22, 24), is beside his wander range (19..21, 24..26), on a cave's wild floor. - const bool lewis = checkpoint.id == "13.03" && step.name == "to_statue"; + const bool lewis = checkpoint.id == "13.03" && (step.name == "to_statue" || step.name == "to_elixir"); if (!lewis && std::count(stops.begin(), stops.end(), std::nullopt) > 0){ return where + "crosses a wandering trainer's sight where the walk can't tell where they'd stop the player."; } @@ -764,6 +824,7 @@ UnitTestResult test_legs_onto_stairs_their_way(){ if (!walked){ continue; } + begin_walk(checkpoint); StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint.start)); for (const StoryStep& step : checkpoint.steps){ if (step.kind == StoryStepKind::ROUTE){ @@ -836,6 +897,9 @@ UnitTestResult test_approaches_end_on_their_tile(){ // open routes; tap them (follow-up) and drop these. "14.01/below_quiz_1", "14.01/below_quiz_2", "14.01/below_quiz_3", "14.01/below_quiz_4", "14.01/below_quiz_5", "14.01/below_quiz_6", + // Not run on a console: 13.03 and 13.04 plan their statue approaches (PRESS_SWITCH, #442); the + // held legs before the A press are for the first console run to tap. + "13.03/to_elixir", "13.04/to_key", }; std::string wrong; size_t count = 0; @@ -844,6 +908,7 @@ UnitTestResult test_approaches_end_on_their_tile(){ if (!start){ continue; } + begin_walk(checkpoint); StoryPose pose = *start; // The legs of the ROUTE and LEGS steps since the last other step. std::vector approach; @@ -890,6 +955,7 @@ UnitTestResult test_facing_after_trainer_battles(){ if (!start){ continue; } + begin_walk(checkpoint); StoryPose pose = *start; for (size_t c = 0; c < checkpoint.steps.size(); c++){ const StoryStep& step = checkpoint.steps[c]; @@ -982,6 +1048,7 @@ UnitTestResult check_trigger(const TriggerCase& c){ return "No checkpoint " + c.checkpoint + "."; } const MapPosition onto{c.map, {c.onto_x, c.y}}; + begin_walk(*checkpoint); StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint->start)); for (const StoryStep& step : checkpoint->steps){ const std::string where = c.checkpoint + "/" + step.name + ": "; @@ -1031,6 +1098,7 @@ UnitTestResult test_nugget_bridge_order(){ } const std::vector& steps = checkpoint->steps; std::string met; + begin_walk(*checkpoint); StoryPose pose = one_tile(Pokemon::grid_pose_of(*checkpoint->start)); for (size_t c = 0; c < steps.size(); c++){ const MapData* map = find_map_named(pose.map); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.01.plan.json index e9a3f21201..7d340194ce 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.01.plan.json @@ -3,7 +3,7 @@ "game": "frlg", "checkpoint": { "id": "13.01", - "title": "Cinnabar to the Pokemon Mansion: 1F and 2F up to 3F's statue, press it", + "title": "Cinnabar to the Pokemon Mansion: 1F and 2F up to 3F's room of holes, the statue switch pressed on the way", "start": { "map": "CinnabarIsland_PokemonCenter_1F", "tiles": [ @@ -16,7 +16,7 @@ }, "events": [ { - "id": "mansion_3f", + "id": "mansion_holes", "kind": "route", "action": "run", "args": { @@ -24,60 +24,19 @@ "map": "PokemonMansion_3F", "tiles": [ [ - 8, - 3 + 19, + 13 ] ], - "facing": "east" + "facing": "south" } }, - "why": "out of Cinnabar's Center, up to the Mansion door (8, 3), 1F (8, 33) up its stairs (10, 13) to 2F (6, 14), through 2F's rooms to the stairs (9, 3), onto 3F's (8, 3); all in the switch's clear state, which is the map's" - }, - { - "id": "to_statue", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "south", - "tiles": 3 - }, - { - "direction": "east", - "tiles": 4 - } - ] - }, - "why": "a tap a tile on 3F in the clear state: down to (8, 6) and east along row 6 to (12, 6), below the statue (12, 5)" - }, - { - "id": "face_statue", - "kind": "step", - "args": { - "direction": "north" - }, - "declared_after": { - "map": "PokemonMansion_3F", - "tiles": [ - [ - 12, - 6 - ] - ], - "facing": "north" - }, - "why": "turn north to the statue (12, 5)" - }, - { - "id": "press_3f_statue", - "kind": "talk", - "why": "face the statue (12, 5) and press A: \"Press the secret switch?\"" - }, - { - "id": "press_3f", - "kind": "answer", - "why": "YES: \"Who wouldn't?\"; the switch flag is set, 3F's (17-19,11-12) open, its (21,4-8) close" + "why": "out of Cinnabar's Center, up to the Mansion door (8, 3), 1F up its stairs, 2F's northern rooms to the stairs (9, 3), and on 3F through the barrier (17-19, 11-12) that a statue press opens: the route presses the statue the cheapest way and walks on to (19, 13), the room of holes", + "gates_after": { + "switches": { + "mansion": true + } + } } ] }, @@ -85,10 +44,8 @@ "menu": "full", "notes": { "checkpoint": [ - "Starts at Cinnabar's nurse, facing her, where no earlier row ends (on the unauthored-start list). Ends on 3F (12, 6) facing the statue it just pressed.", - "The Mansion's statue switches: one flag for all four floors. Switch model (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc; one global flag, set on a press and applied on each floor's load; the pack's maps are the flag-clear state only). Assumed per floor (read from pokefirered; the overlay data on PokemonSimulation's maps/frlg-mansion-switches branch, seen 2026-11-12, has the same tiles open or closed per state): 1F set: (22-24,10-11), (27-29,25-26), (32-34,25-26) open, (31-33,18-19) closed. 2F set: (24-26,14-15), (10,30-32) open, (12,4-8) closed, (10,28-29) wall. 3F set: (17-19,11-12) open, (21,4-8) closed. B1F set: (12,10-12), (20-22,22-23) open, (33-35,20-21) and (16,28-30) closed. Clear = the map as it is.", - "13.01 walks only in the clear state; the press at its end sets the flag, and every row after walks the set state until a statue is pressed again (13.03 presses B1F's two).", - "Mansion trainers met on this walk: 1F Johnson wanders row 8, 2F Arnie (5, 23) and 3F Simon (6-8, 12-14) are off the route (the route takes 2F's northern rooms and 3F's (8, 3) arrival)." + "Starts at Cinnabar's nurse, facing her, where no earlier row ends (on the unauthored-start list). Ends on 3F (19, 13) facing south, in the room of holes, with the switch on.", + "The Mansion's statue switches: one flag for all four floors (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc), a toggle each press flips and each floor applies on load. The pinned maps (PokemonSimulation 4b886bb) carry it as gates: barriers that open when the switch is on or off, and the statues that press it. A route plans the presses itself (PRESS_SWITCH: face the statue, A, Yes, B through the text) wherever a barrier is in the way, and the step's gates_after says the switch it leaves; a checkpoint that starts from a save says the switch in start_gates." ] } }, @@ -99,11 +56,11 @@ "map": "PokemonMansion_3F", "tiles": [ [ - 12, - 6 + 19, + 13 ] ], - "facing": "north" + "facing": "south" } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.02.plan.json index db95982209..4a211eb32f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.02.plan.json @@ -3,167 +3,53 @@ "game": "frlg", "checkpoint": { "id": "13.02", - "title": "Pokemon Mansion 3F through the switch's opening, the hole to 1F, 1F's stairs to B1F", + "title": "Pokemon Mansion 3F's hole to 1F, 1F's stairs to B1F", "start": { "map": "PokemonMansion_3F", "tiles": [ [ - 12, - 6 + 19, + 13 ] ], - "facing": "north" + "facing": "south" }, "events": [ { - "id": "to_barrier", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "east", - "tiles": 7 - }, - { - "direction": "south", - "tiles": 4 - } - ] - }, - "why": "a tap a tile: east along row 6 to (19, 6), south to (19, 10), above 3F's opening (17-19, 11-12), set open by the press (the map has it closed)" - }, - { - "id": "into_opening_1", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_3F", - "tiles": [ - [ - 19, - 11 - ] - ], - "facing": "south" - }, - "why": "a step onto (19, 11): the opening is open only in the set state, closed on the map" - }, - { - "id": "into_opening_2", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_3F", - "tiles": [ - [ - 19, - 12 - ] - ], - "facing": "south" - }, - "why": "a step onto (19, 12), the opening's second row" - }, - { - "id": "through_opening", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_3F", - "tiles": [ - [ - 19, - 13 - ] - ], - "facing": "south" - }, - "why": "a step through onto (19, 13), the room of holes" - }, - { - "id": "to_hole_edge", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "south", - "tiles": 4 - } - ] - }, - "why": "a tap a tile down column 19 to (19, 17), above the hole row (18..20, 18); Braydon (22, 13) looks south along column 22, so x 19 is clear" - }, - { - "id": "down_the_hole", - "kind": "step", + "id": "to_ted_room", + "kind": "route", + "action": "run", "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_1F", - "tiles": [ - [ - 20, - 22 - ] - ], - "facing": "south" + "target": { + "map": "PokemonMansion_1F", + "tiles": [ + [ + 17, + 23 + ] + ], + "facing": "south" + } }, - "why": "a step onto the hole (19, 18), which drops to 1F (20, 22) (3F map.json warp to 1F warp 8)" + "why": "south to the hole row (18..20, 18), which drops to 1F's room (19..20, 22), west along row 23 to the room's west wall, out of the sight line of Ted at (22, 24) facing west (4 tiles: 18..21 on row 24)" }, { - "id": "to_stairs", - "kind": "legs", - "action": "taps", + "id": "past_ted", + "kind": "route", + "action": "run", "args": { - "legs": [ - { - "direction": "south", - "tiles": 1 - }, - { - "direction": "west", - "tiles": 3 - }, - { - "direction": "south", - "tiles": 2 - }, - { - "direction": "east", - "tiles": 1 - }, - { - "direction": "south", - "tiles": 2 - }, - { - "direction": "east", - "tiles": 4 - }, - { - "direction": "south", - "tiles": 2 - }, - { - "direction": "east", - "tiles": 4 - }, - { - "direction": "north", - "tiles": 2 - } - ] + "target": { + "map": "PokemonMansion_1F", + "tiles": [ + [ + 17, + 25 + ] + ], + "facing": "south" + } }, - "why": "a tap a tile along 1F's southern rooms to (26, 27): west to column 17 (Ted (22, 24) looks west along row 24 and sees x 18-21 only), down to row 27, east on to (22, 27), (22, 29), (26, 29) and up to (26, 27), east of the stairs (25, 27), an arrow warp to B1F (34, 29)" + "why": "south down the west wall: (17, 24) is the one tile of row 24 past Ted's 4-tile line" }, { "id": "down_to_b1f", @@ -181,18 +67,26 @@ "facing": "west" } }, - "why": "west from (26, 27) onto the stairs (25, 27), an arrow warp, to B1F's (34, 29)" + "why": "south to the hole row (18..20, 18), which drops to 1F's east rooms (a one-way warp), through them to the stairs (25, 27), an arrow warp, to B1F's (34, 29); the switch stays on", + "gates_after": { + "switches": { + "mansion": true + } + } } - ] + ], + "start_gates": { + "switches": { + "mansion": true + } + } }, "execution": { "menu": "full", "notes": { "checkpoint": [ - "Starts where 13.01 ends, 3F (12, 6) facing the pressed statue. Ends on B1F (34, 29), the foot of 1F's stairs, in the set state.", - "Barriers: Switch model (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc; one global flag, set on a press and applied on each floor's load; the pack's maps are the flag-clear state only). Assumed per floor (read from pokefirered; the overlay data on PokemonSimulation's maps/frlg-mansion-switches branch, seen 2026-11-12, has the same tiles open or closed per state): 1F set: (22-24,10-11), (27-29,25-26), (32-34,25-26) open, (31-33,18-19) closed. 2F set: (24-26,14-15), (10,30-32) open, (12,4-8) closed, (10,28-29) wall. 3F set: (17-19,11-12) open, (21,4-8) closed. B1F set: (12,10-12), (20-22,22-23) open, (33-35,20-21) and (16,28-30) closed. Clear = the map as it is.", - "This row walks 3F and 1F in the set state: 3F (19, 11-12) are open, so the three single steps are declared (the map has the barrier there); the holes (18..20, 18) drop to 1F (19, 22) and (20, 22), and 1F's east rooms (x 17-37, y 20-33) are reachable only by them (a wall at x 16 splits them from the west).", - "The hole is the way pokeguy goes (floor drop, then the staircase to the basement, before 1:19:56)." + "Starts where 13.01 ends, 3F (19, 13) facing south, the switch on (start_gates). Ends on B1F (34, 29), the foot of 1F's stairs. The hole is the way pokeguy goes (floor drop, then the staircase to the basement, before 1:19:56).", + "The Mansion's statue switches: one flag for all four floors (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc), a toggle each press flips and each floor applies on load. The pinned maps (PokemonSimulation 4b886bb) carry it as gates: barriers that open when the switch is on or off, and the statues that press it. A route plans the presses itself (PRESS_SWITCH: face the statue, A, Yes, B through the text) wherever a barrier is in the way, and the step's gates_after says the switch it leaves; a checkpoint that starts from a save says the switch in start_gates." ] } }, @@ -211,4 +105,4 @@ } } } -} +} \ No newline at end of file diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.03.plan.json index 778a840cab..70a7cdb5f1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.03.plan.json @@ -3,7 +3,7 @@ "game": "frlg", "checkpoint": { "id": "13.03", - "title": "Pokemon Mansion B1F: the statue by Lewis's room, the Elixir, TM14, the statue by the Elixir room", + "title": "Pokemon Mansion B1F: the Elixir and TM14", "start": { "map": "PokemonMansion_B1F", "tiles": [ @@ -16,176 +16,27 @@ }, "events": [ { - "id": "to_lewis_room", - "kind": "legs", - "action": "taps", + "id": "to_elixir", + "kind": "route", + "action": "run", "args": { - "legs": [ - { - "direction": "west", - "tiles": 7 - }, - { - "direction": "north", - "tiles": 9 - }, - { - "direction": "west", - "tiles": 5 - } - ] - }, - "why": "B1F arrives in the set state (the flag is set), which closes its north: a tap a tile west to (27, 29), up column 27 to (27, 20) and west along row 20 to (22, 20), above the opening (20-22, 22-23), set open" - }, - { - "id": "into_room_1", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 22, - 21 - ] - ], - "facing": "south" - }, - "why": "a step to (22, 21)" - }, - { - "id": "into_room_2", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 22, - 22 - ] - ], - "facing": "south" - }, - "why": "a step onto (22, 22): the opening (20-22, 22-23) is open only in the set state, closed on the map" - }, - { - "id": "into_room_3", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 22, - 23 - ] - ], - "facing": "south" - }, - "why": "a step onto (22, 23), the opening's second row" - }, - { - "id": "to_statue", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "south", - "tiles": 1 - }, - { - "direction": "east", - "tiles": 1 - }, - { - "direction": "south", - "tiles": 6 - }, - { - "direction": "east", - "tiles": 1 - } - ] - }, - "why": "a tap a tile down to (22, 24), east to (23, 24) and down column 23 to (23, 30), then east to (24, 30), below the statue (24, 29); Burglar Lewis wanders (19-21, 24-26) with sight 1, and a battle is taken as it comes (pokeguy passed without one)" - }, - { - "id": "face_statue", - "kind": "step", - "args": { - "direction": "north" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 24, - 30 - ] - ], - "facing": "north" - }, - "why": "turn north to the statue (24, 29)" - }, - { - "id": "press_b1f_south", - "kind": "talk", - "why": "press A: \"Press the secret switch?\"" - }, - { - "id": "press_south", - "kind": "answer", - "why": "YES: the flag clears, B1F's north opens again ((12, 10-12) and (20-22, 22-23) close, (33-35, 20-21) and (16, 28-30) open: the map)" - }, - { - "id": "south_to_north", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "west", - "tiles": 9 - }, - { - "direction": "north", - "tiles": 10 - }, - { - "direction": "east", - "tiles": 14 - }, - { - "direction": "south", - "tiles": 2 - }, - { - "direction": "east", - "tiles": 4 - }, - { - "direction": "north", - "tiles": 16 - }, - { - "direction": "north", - "tiles": 1 - }, - { - "direction": "east", - "tiles": 1 - } - ] - }, - "why": "a tap a tile in the clear state, which is the map's: west to (15, 30), up column 15 to (15, 20), east along row 20 to (29, 20), down to (29, 22), east to (33, 22), up column 33 to (33, 5) (Ivan (34, 13) looks south along column 34 with sight 6, so not x 34), and east to (34, 5), facing (35, 5)" + "target": { + "map": "PokemonMansion_B1F", + "tiles": [ + [ + 34, + 5 + ] + ], + "facing": "east" + } + }, + "why": "B1F arrives with the switch on, which closes its north ((33-35, 20-21), (16, 28-30)): the route presses the statue it needs and walks up to (34, 5), beside the hidden ELIXIR on (35, 5)", + "gates_after": { + "switches": { + "mansion": false + } + } }, { "id": "hidden_elixir", @@ -194,130 +45,40 @@ }, { "id": "to_tm14", - "kind": "legs", - "action": "taps", + "kind": "route", + "action": "run", "args": { - "legs": [ - { - "direction": "south", - "tiles": 1 - }, - { - "direction": "west", - "tiles": 4 - }, - { - "direction": "south", - "tiles": 4 - }, - { - "direction": "west", - "tiles": 11 - }, - { - "direction": "north", - "tiles": 5 - }, - { - "direction": "east", - "tiles": 4 - } - ] + "target": { + "map": "PokemonMansion_B1F", + "tiles": [ + [ + 23, + 5 + ] + ], + "facing": "north" + } }, - "why": "a tap a tile back down: (34, 6), west to (30, 6), down to (30, 10), west along row 10 to (19, 10), up column 19 to (19, 5) and east to (23, 5), below TM14 (23, 4)" - }, - { - "id": "face_tm14", - "kind": "step", - "args": { - "direction": "north" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 23, - 5 - ] - ], - "facing": "north" - }, - "why": "turn north to the ball" + "why": "back along the north rooms to (23, 5), below the ball (23, 4)" }, { "id": "tm14", "kind": "talk", "why": "TM14 (pokeguy 1:20:15)" - }, - { - "id": "to_north_statue", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "west", - "tiles": 4 - }, - { - "direction": "south", - "tiles": 5 - }, - { - "direction": "east", - "tiles": 11 - }, - { - "direction": "north", - "tiles": 4 - }, - { - "direction": "west", - "tiles": 3 - } - ] - }, - "why": "a tap a tile back: west to (19, 5), down column 19 to (19, 10), east along row 10 to (30, 10), up to (30, 6) and west to (27, 6), below the statue (27, 5)" - }, - { - "id": "face_north_statue", - "kind": "step", - "args": { - "direction": "north" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 27, - 6 - ] - ], - "facing": "north" - }, - "why": "turn north to the statue (27, 5)" - }, - { - "id": "press_b1f_north", - "kind": "talk", - "why": "press A: \"Press the secret switch?\" (pokeguy 1:20:09 presses the statue before the TM, the Elixir between)" - }, - { - "id": "press_north", - "kind": "answer", - "why": "YES: the flag is set; (12, 10-12) open, (33-35, 20-21) and (16, 28-30) close" } - ] + ], + "start_gates": { + "switches": { + "mansion": true + } + } }, "execution": { "menu": "full", "notes": { "checkpoint": [ - "Starts on B1F (34, 29) where 13.02 ends. Ends below the second statue (27, 5), at (27, 6), with the flag set: (12, 10-12) is the opening the walk to the SECRET KEY takes.", - "Barriers: Switch model (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc; one global flag, set on a press and applied on each floor's load; the pack's maps are the flag-clear state only). Assumed per floor (read from pokefirered; the overlay data on PokemonSimulation's maps/frlg-mansion-switches branch, seen 2026-11-12, has the same tiles open or closed per state): 1F set: (22-24,10-11), (27-29,25-26), (32-34,25-26) open, (31-33,18-19) closed. 2F set: (24-26,14-15), (10,30-32) open, (12,4-8) closed, (10,28-29) wall. 3F set: (17-19,11-12) open, (21,4-8) closed. B1F set: (12,10-12), (20-22,22-23) open, (33-35,20-21) and (16,28-30) closed. Clear = the map as it is.", - "The two B1F statues are (24, 29) (press from (24, 30)) and (27, 5) (from (27, 6)). B1F is entered in the set state whichever way it was left, so the first press is a reset to clear: that opens the north, which the set state closes ((33-35, 20-21), (16, 28-30) are open in the clear state). The path to the Elixir and TM14 is the clear state, as the map is.", - "Open: Burglar Lewis (wandering (19-21, 24-26), sight 1: Growlithe, Ponyta Lv34) cannot be avoided in the room (its one way in, (22, 24), is beside his range; the sim meets him there and the AutoStory test lists to_statue as the one wanderer crossing it allows); the row relies on the normal battle code if he fights. Ivan (34, 13, looking south, sight 6) is passed on x 33. The Elixir is a hidden item: the walk faces it from (34, 5).", - "PokeGuy (1:19:56 to 1:20:21): basement statue, the Elixir 1:20:06, another statue 1:20:09, TM14 1:20:15." + "Starts on B1F (34, 29) where 13.02 ends, the switch on (start_gates). Ends below TM14's ball at (23, 5), with the switch as the route to the Elixir left it.", + "The Mansion's statue switches: one flag for all four floors (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc), a toggle each press flips and each floor applies on load. The pinned maps (PokemonSimulation 4b886bb) carry it as gates: barriers that open when the switch is on or off, and the statues that press it. A route plans the presses itself (PRESS_SWITCH: face the statue, A, Yes, B through the text) wherever a barrier is in the way, and the step's gates_after says the switch it leaves; a checkpoint that starts from a save says the switch in start_gates." ] } }, @@ -328,8 +89,8 @@ "map": "PokemonMansion_B1F", "tiles": [ [ - 27, - 6 + 23, + 5 ] ], "facing": "north" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.04.plan.json index b33ae0ce44..cada9585b4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-13.04.plan.json @@ -8,110 +8,35 @@ "map": "PokemonMansion_B1F", "tiles": [ [ - 27, - 6 + 23, + 5 ] ], "facing": "north" }, "events": [ - { - "id": "to_opening", - "kind": "legs", - "action": "taps", - "args": { - "legs": [ - { - "direction": "east", - "tiles": 3 - }, - { - "direction": "south", - "tiles": 4 - }, - { - "direction": "west", - "tiles": 17 - } - ] - }, - "why": "a tap a tile in the set state: east to (30, 6), down to (30, 10) and west along row 10 to (13, 10), east of the opening (12, 10-12), set open (closed on the map)" - }, - { - "id": "into_opening", - "kind": "step", - "args": { - "direction": "west" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 12, - 10 - ] - ], - "facing": "west" - }, - "why": "a step onto (12, 10): open only in the set state" - }, - { - "id": "through_opening", - "kind": "step", - "args": { - "direction": "west" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 11, - 10 - ] - ], - "facing": "west" - }, - "why": "a step through onto (11, 10)" - }, { "id": "to_key", - "kind": "legs", - "action": "taps", + "kind": "route", + "action": "run", "args": { - "legs": [ - { - "direction": "west", - "tiles": 3 - }, - { - "direction": "north", - "tiles": 4 - }, - { - "direction": "west", - "tiles": 3 - } - ] + "target": { + "map": "PokemonMansion_B1F", + "tiles": [ + [ + 5, + 6 + ] + ], + "facing": "south" + } }, - "why": "a tap a tile: west to (8, 10), up column 8 to (8, 6) and west to (5, 6), above the SECRET KEY (5, 7)" - }, - { - "id": "face_key", - "kind": "step", - "args": { - "direction": "south" - }, - "declared_after": { - "map": "PokemonMansion_B1F", - "tiles": [ - [ - 5, - 6 - ] - ], - "facing": "south" - }, - "why": "turn south to the ball" + "why": "to (5, 6), above the SECRET KEY (5, 7): the opening (12, 10-12) is open only with the switch on, so the route presses the statue it passes", + "gates_after": { + "switches": { + "mansion": true + } + } }, { "id": "secret_key", @@ -137,15 +62,19 @@ }, "why": "out to the Mansion's door (pokeguy 1:20:24-36, his ESCAPE ROPE count 3 to 2); the player stands on (8, 4), where 14.01 starts" } - ] + ], + "start_gates": { + "switches": { + "mansion": false + } + } }, "execution": { "menu": "full", "notes": { "checkpoint": [ - "Starts below B1F's second statue, at (27, 6), where 13.03 ends, the flag set. Ends outside the Mansion door on Cinnabar (8, 4) facing south, where 14.01 starts.", - "Barriers: Switch model (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc; one global flag, set on a press and applied on each floor's load; the pack's maps are the flag-clear state only). Assumed per floor (read from pokefirered; the overlay data on PokemonSimulation's maps/frlg-mansion-switches branch, seen 2026-11-12, has the same tiles open or closed per state): 1F set: (22-24,10-11), (27-29,25-26), (32-34,25-26) open, (31-33,18-19) closed. 2F set: (24-26,14-15), (10,30-32) open, (12,4-8) closed, (10,28-29) wall. 3F set: (17-19,11-12) open, (21,4-8) closed. B1F set: (12,10-12), (20-22,22-23) open, (33-35,20-21) and (16,28-30) closed. Clear = the map as it is.", - "The walk west along row 10 crosses (12, 10-12), which is closed on the pack's map and open in the set state: its two steps are declared because the pack's map has the barrier there.", + "Starts below TM14's ball, at (23, 5), where 13.03 ends. Ends outside the Mansion door on Cinnabar (8, 4) facing south, where 14.01 starts.", + "The Mansion's statue switches: one flag for all four floors (pokefirered data/scripts/pokemon_mansion.inc, PokemonMansion_*F scripts.inc), a toggle each press flips and each floor applies on load. The pinned maps (PokemonSimulation 4b886bb) carry it as gates: barriers that open when the switch is on or off, and the statues that press it. A route plans the presses itself (PRESS_SWITCH: face the statue, A, Yes, B through the text) wherever a barrier is in the way, and the step's gates_after says the switch it leaves; a checkpoint that starts from a save says the switch in start_gates.", "Not taken: the FULL RESTORE (2F (2, 29)) and TM22 (1F (6, 21)); pokeguy leaves by Escape Rope after the key (1:20:24-36)." ] } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 0dd3bcaaec..16f0d545b4 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1478,8 +1478,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_GateState.h Source/Pokemon/Navigation/Pokemon_GateTiles.cpp Source/Pokemon/Navigation/Pokemon_GateTiles.h - Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp - Source/Pokemon/Navigation/Pokemon_Gates_Tests.h Source/Pokemon/Navigation/Pokemon_Direction.cpp Source/Pokemon/Navigation/Pokemon_Direction.h Source/Pokemon/Navigation/Pokemon_Grid.cpp @@ -1512,7 +1510,6 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.h Source/Pokemon/Navigation/Pokemon_NavigationTestMaps.h - Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h Source/Pokemon/Navigation/Pokemon_RouteLog.cpp Source/Pokemon/Navigation/Pokemon_RouteLog.h Source/Pokemon/Navigation/Pokemon_RouteLog_Tests.cpp @@ -2004,6 +2001,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBikeTaps.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldBike_Tests.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp + Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.h Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldLateBattle.cpp Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldLateBattle.h From 13f7f7b42fd7d1b3522f9aa3de8fb6a69b10e300 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:59:15 -0800 Subject: [PATCH 06/20] FRLG gates: code-health fixes (walk state accessor, string_view scene, test registration) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../PokemonFRLG_AutoStoryGates_Tests.cpp | 17 ++++---- .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 43 ++++++++++--------- 3 files changed, 33 insertions(+), 29 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 567f804003..9516b4c908 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -57,6 +57,7 @@ #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows12_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows14_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows15_Tests.h" +#include "Overworld/PokemonFRLG_OverworldGateMaps_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows13_Tests.h" #include "Programs/AutoStory/PokemonFRLG_AutoStoryRows16_Tests.h" @@ -345,6 +346,7 @@ static void add_tests_AutoStoryRows(UnitTestDatabase& database){ add_tests_AutoStorySilph(database); add_tests_AutoStoryMansion(database); add_tests_AutoStoryGates(database); + add_tests_OverworldGateMaps(database); } void add_tests(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp index 84f80324a1..2d40939534 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp @@ -13,6 +13,7 @@ #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" @@ -61,7 +62,7 @@ class Test_AutoStoryGates : public UnitTest{ // A walk across a gate on the real maps: Silph Co. 5F's card-key door, and // the Pokemon Mansion 1F's barrier behind its statue's switch. struct Scene{ - const char* map; + std::string_view map; TilePos start; TilePos goal; }; @@ -83,7 +84,7 @@ StoryStep route_step(const std::string& map, TilePos goal){ Pokemon::RunState run_state(const Scene& scene, bool card_key){ Pokemon::RunState state; - state.pose = to_pose(StoryPose{scene.map, scene.start, Direction::EAST}); + state.pose = to_pose(StoryPose{std::string(scene.map), scene.start, Direction::EAST}); if (card_key){ state.flags.insert("card_key_held"); } @@ -96,7 +97,7 @@ Pokemon::Outcome on_maps(const Scene& scene, bool card_key, Pokemon::RunState& s knobs.maps = &scene_maps(); StoryMapsSim sim(knobs); state = run_state(scene, card_key); - return sim.run(route_step(scene.map, scene.goal), state); + return sim.run(route_step(std::string(scene.map), scene.goal), state); } @@ -144,9 +145,9 @@ struct GateStateOut{ std::string on_overworld_sim(const Scene& scene, bool card_key, GateStateOut& out){ SimScript script; script.card_key_held = card_key; - OverworldSim sim(scene_maps(), MapPosition{scene.map, scene.start}, Direction::EAST, script); - StoryPose at{scene.map, scene.start, Direction::EAST}; - const std::string failure = row_step_on_sim(sim, at, route_step(scene.map, scene.goal), "test"); + OverworldSim sim(scene_maps(), MapPosition{std::string(scene.map), scene.start}, Direction::EAST, script); + StoryPose at{std::string(scene.map), scene.start, Direction::EAST}; + const std::string failure = row_step_on_sim(sim, at, route_step(std::string(scene.map), scene.goal), "test"); out.gates = sim.state().gates; out.position = sim.state().position; return failure; @@ -166,7 +167,7 @@ UnitTestResult test_step_sim_door_opens(){ if (!failure.empty()){ return "The step did not open the door for a player with the Card Key: " + failure; } - if (!out.gates.opened.contains("SilphCo_5F/door_1") || !(out.position == MapPosition{DOOR.map, DOOR.goal})){ + if (!out.gates.opened.contains("SilphCo_5F/door_1") || !(out.position == MapPosition{std::string(DOOR.map), DOOR.goal})){ return "Expected the door open and the player at the goal, ended at " + to_string(out.position); } return true; @@ -178,7 +179,7 @@ UnitTestResult test_step_sim_statue_switch(){ if (!failure.empty()){ return "The step did not press the statue: " + failure; } - if (!out.gates.switch_on("mansion") || !(out.position == MapPosition{STATUE.map, STATUE.goal})){ + if (!out.gates.switch_on("mansion") || !(out.position == MapPosition{std::string(STATUE.map), STATUE.goal})){ return "Expected the switch on and the player at the goal, ended at " + to_string(out.position); } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 7837cedfd4..dca9b9caff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -104,35 +104,38 @@ struct WalkGates{ Pokemon::GateState gates; bool card_key_held = false; }; -thread_local WalkGates WALK; +WalkGates& walk_state(){ + thread_local WalkGates walk; + return walk; +} // Starts a walk at `checkpoint`'s start: its start_gates and start_flags. void begin_walk(const StoryCheckpoint& checkpoint){ - WALK = WalkGates{}; + walk_state() = WalkGates{}; if (checkpoint.start_gates){ - WALK.gates = *checkpoint.start_gates; + walk_state().gates = *checkpoint.start_gates; } - WALK.card_key_held = std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end(); + walk_state().card_key_held = std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end(); } // A walk through the checkpoint that follows the one before: only what its // start says replaces the gates carried. void continue_walk(const StoryCheckpoint& checkpoint){ if (checkpoint.start_gates){ - WALK.gates = *checkpoint.start_gates; + walk_state().gates = *checkpoint.start_gates; } if (std::ranges::find(checkpoint.start_flags, "card_key_held") != checkpoint.start_flags.end()){ - WALK.card_key_held = true; + walk_state().card_key_held = true; } } // What `step` does to the walk's gates once done, besides a route's own. void apply_step_effects(const StoryStep& step){ if (step.gates_after){ - apply_gate_change(WALK.gates, *step.gates_after); + apply_gate_change(walk_state().gates, *step.gates_after); } if (std::ranges::find(step.flags_after, "card_key_held") != step.flags_after.end()){ - WALK.card_key_held = true; + walk_state().card_key_held = true; } } @@ -142,8 +145,8 @@ const std::vector& walk_maps(){ if (!has_gates(story_maps())){ return story_maps(); } - if (!resolved || !(resolved->first == WALK.gates)){ - resolved.emplace(WALK.gates, resolve_maps(story_maps(), WALK.gates)); + if (!resolved || !(resolved->first == walk_state().gates)){ + resolved.emplace(walk_state().gates, resolve_maps(story_maps(), walk_state().gates)); } return resolved->second; } @@ -267,8 +270,8 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vector(step.args, "target")); const RouteGoal goal{{target.map, target.tile}, target.facing}; - const Pokemon::GateRules rules{.card_key_held = WALK.card_key_held}; - const std::optional> route = plan_overworld_route_gated(story_maps(), start, goal, WALK.gates, rules, default_route_costs(), facing); + const Pokemon::GateRules rules{.card_key_held = walk_state().card_key_held}; + const std::optional> route = plan_overworld_route_gated(story_maps(), start, goal, walk_state().gates, rules, default_route_costs(), facing); if (!route){ return step.name + ": no route from " + to_string(start) + " to " + to_string(goal.position) + "."; } @@ -277,7 +280,7 @@ UnitTestResult check_route(StoryPose& pose, const StoryStep& step, std::vectorempty() ? facing : route->back().facing_after}; return true; } @@ -351,7 +354,7 @@ UnitTestResult chain_story_routes(std::vector& golden){ return "Expected 63 checkpoints, the first from a new game."; } StoryPose pose; - WALK = WalkGates{}; + walk_state() = WalkGates{}; for (size_t c = 0; c < checkpoints.size(); c++){ const StoryCheckpoint& checkpoint = checkpoints[c]; continue_walk(checkpoint); @@ -604,7 +607,7 @@ std::vector legs_walked(const StoryPose& pose, const StoryStep& step) const MapData* map = find_map_named(pose.map); const std::optional facing = pose.facing ? pose.facing : map ? wall_beside(*map, pose.tile) : std::nullopt; const StoryPose target = one_tile(Pokemon::story_arg(step.args, "target")); - route = plan_overworld_route_gated(story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, WALK.gates, Pokemon::GateRules{.card_key_held = WALK.card_key_held}, story_route_costs(), facing); + route = plan_overworld_route_gated(story_maps(), start, RouteGoal{{target.map, target.tile}, target.facing}, walk_state().gates, Pokemon::GateRules{.card_key_held = walk_state().card_key_held}, story_route_costs(), facing); } return route ? *route : std::vector{}; } @@ -887,19 +890,17 @@ std::string approach_off_tile(const std::vector& legs){ // approach to the Rare Candy, "west 4" and "south 6" held open, ended a // tile west and met a gravestone (console B, 2026-11-12 04:39). // PASSED_ON_CONSOLE: approaches before 10.05 that passed their console -// runs as held legs (a follow-up to tap them). +// runs as held legs (a follow-up to tap them). 13.03 and 13.04 plan their statue +// approaches (PRESS_SWITCH) and have not run on a console. UnitTestResult test_approaches_end_on_their_tile(){ const std::set PASSED_ON_CONSOLE{ "02.02/below_oak", "03.02/before_brock", "05.07/below_bill_clefairy", "05.07/pc_front", "05.07/beside_bill", "06.01/behind_captain", "07.01/beside_chairman", "07.01/bike_clerk", - "09.01/below_poster_guard", "09.02/below_left_guard", "09.03/above_tea_woman", "10.01/below_fly_woman", + "09.01/below_poster_guard", "09.02/below_left_guard", "09.03/above_tea_woman", "10.01/below_fly_woman", "13.03/to_elixir", "13.04/to_key", // Not run on a console: 14.01 (#410) predates this rule. Its quiz machine approaches are held // open routes; tap them (follow-up) and drop these. "14.01/below_quiz_1", "14.01/below_quiz_2", "14.01/below_quiz_3", "14.01/below_quiz_4", "14.01/below_quiz_5", "14.01/below_quiz_6", - // Not run on a console: 13.03 and 13.04 plan their statue approaches (PRESS_SWITCH, #442); the - // held legs before the A press are for the first console run to tap. - "13.03/to_elixir", "13.04/to_key", }; std::string wrong; size_t count = 0; From e22c2fd8052798d0121169a2f05a758ca6d33b5a Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 19:59:32 -0800 Subject: [PATCH 07/20] FRLG gates: register the gate-map tests with the FRLG suites (file_lines) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp index 8270061996..3dcbaaa052 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim_Tests.cpp @@ -21,7 +21,6 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" -#include "PokemonFRLG_OverworldGateMaps_Tests.h" #include "PokemonFRLG_OverworldLateBattle.h" #include "PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_OverworldSim.h" @@ -1040,7 +1039,6 @@ void add_tests_OverworldSim(UnitTestDatabase& database){ add_tests_OverworldWarpFade(database); add_tests_OverworldStairs(database); add_tests_OverworldGates(database); - add_tests_OverworldGateMaps(database); add_tests_OverworldSpin(database); add_tests_OverworldBike(database); } From bdf5fed5cf3ff1d83cad2a6311f5310cc70ea7d7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 20:14:44 -0800 Subject: [PATCH 08/20] FRLG gates: replay a recorded route through a Silph card-key door and a Mansion statue on the real maps The replay scenario takes start_flags (the Card Key); the new tests record the native route across each gate and replay it on the pinned maps. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_AutoStoryGates_Tests.cpp | 223 ++++++++++++++++++ .../AutoStory/PokemonFRLG_StoryReplay.cpp | 6 + .../AutoStory/PokemonFRLG_StoryReplay_IO.cpp | 7 +- 3 files changed, 235 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp index 2d40939534..7f307b1490 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp @@ -12,17 +12,23 @@ #include #include +#include #include #include #include #include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Pokemon_StoryPose.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_AutoStoryGates_Tests.h" #include "PokemonFRLG_AutoStoryPoses.h" #include "PokemonFRLG_AutoStoryRowSim.h" +#include "PokemonFRLG_StoryReplay.h" +#include "PokemonFRLG_StoryReplay_IO.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -185,6 +191,220 @@ UnitTestResult test_step_sim_statue_switch(){ return true; } +// A recorded route replayed on the real maps: the native planner's route +// through the gate as the replay's supplied commands (what a recording of +// the walk holds), replayed by the story engine on the pinned maps with the +// run's flags (the Card Key) and the gates the route's commands change. +constexpr std::string_view REVISION = "0123456789abcdef0123456789abcdef01234567"; + +const MapData& scene_map(const Scene& scene){ + for (const MapData& map : scene_maps()){ + if (map.name == scene.map){ + return map; + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unknown scene map."); +} + +JsonObject tile_json(const Scene& scene, TilePos tile, std::string_view facing){ + JsonArray pair; + pair.push_back(tile.x); + pair.push_back(tile.y); + JsonArray tiles; + tiles.push_back(std::move(pair)); + JsonObject where; + where["kind"] = "tiles"; + where["tiles"] = std::move(tiles); + where["facing"] = std::string(facing); + JsonObject pose; + pose["certainty"] = "tile"; + pose["map"] = std::string(scene.map); + pose["where"] = std::move(where); + return pose; +} + +// The planned route as supplied commands: walks, turns, and the gate's A press. +JsonArray recorded_commands(const Scene& scene, const std::vector& route){ + JsonArray commands; + for (const RouteStep& step : route){ + JsonObject command; + command["event"] = "cross"; + command["map"] = std::string(scene.map); + command["direction"] = std::string(direction_name(step.direction)); + switch (step.action){ + case RouteAction::WALK: + command["kind"] = "walk"; + command["tiles"] = step.tiles; + break; + case RouteAction::FACE: + command["kind"] = "turn"; + break; + case RouteAction::OPEN_GATE: + command["kind"] = "open_gate"; + break; + case RouteAction::PRESS_SWITCH: + command["kind"] = "press_switch"; + break; + default: + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "The scene's route has a step the replay does not take."); + } + commands.push_back(std::move(command)); + } + return commands; +} + +// The replay of the scene's checkpoint with the recorded route. The scenario starts with +// the Card Key if `card_key`; the recording is made with it either way. +// Throws what the replay rejects. +JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key = true){ + const MapData& map = scene_map(scene); + const Pokemon::GateRules rules{.card_key_held = recorded_card_key}; + const std::optional> route = plan_overworld_route_gated( + scene_maps(), MapPosition{std::string(scene.map), scene.start}, RouteGoal{MapPosition{std::string(scene.map), scene.goal}, std::nullopt}, + Pokemon::GateState(), rules, default_route_costs(), Direction::EAST + ); + if (!route){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No route across the scene to record."); + } + const Direction facing_after = route->back().direction; + + JsonObject start_pose = tile_json(scene, scene.start, "east"); + JsonObject target = tile_json(scene, scene.goal, direction_name(facing_after)); + JsonObject event; + event["id"] = "cross"; + event["kind"] = "route"; + event["target"] = std::move(target); + event["why"] = "across the gate"; + JsonArray events; + events.push_back(std::move(event)); + JsonObject checkpoint; + checkpoint["id"] = "99.01"; + checkpoint["title"] = "Gate replay"; + checkpoint["start"] = std::move(start_pose); + checkpoint["events"] = std::move(events); + JsonObject capture; + capture["format"] = "pokesim-native-checkpoint-export/1"; + capture["game"] = "frlg"; + capture["checkpoint"] = std::move(checkpoint); + capture["source_revision"] = std::string(REVISION); + capture["unbound"] = JsonArray(); + const std::string capture_text = capture.dump(-1); + + std::string map_hash; + for (const auto& [name, text] : overworld_map_json()){ + if (name == scene.map){ + map_hash = StoryReplayInternal::digest(text); + } + } + JsonObject capture_pin; + capture_pin["file"] = "gate-replay.json"; + capture_pin["sha256"] = StoryReplayInternal::digest(capture_text); + capture_pin["source_revision"] = std::string(REVISION); + JsonObject maps; + maps[std::string(scene.map)] = map_hash; + JsonObject capability; + capability["capability"] = "frlg-runtime-route/1"; + capability["parameters"] = JsonObject(); + JsonObject capabilities; + capabilities["cross"] = std::move(capability); + JsonObject costs; + costs["tile"] = 1; + costs["turn"] = 2; + costs["grass"] = 5; + costs["warp"] = 1; + JsonObject policy; + policy["basis"] = "synthetic-offline-policy"; + policy["entry"] = "scripted-observation"; + policy["attempts"] = 1; + policy["failure"] = "stop"; + policy["save"] = "never"; + JsonObject binding; + binding["format"] = "pokesim-story-replay-binding/1"; + binding["capture"] = std::move(capture_pin); + binding["map_revision"] = std::string(REVISION); + binding["maps"] = std::move(maps); + binding["capabilities"] = std::move(capabilities); + binding["costs"] = std::move(costs); + binding["max_route_moves"] = 256; + binding["policy"] = std::move(policy); + const std::string binding_text = binding.dump(-1); + + JsonObject routes; + routes["cross"] = recorded_commands(scene, *route); + JsonObject candidate; + candidate["format"] = "pokesim-route-candidate/1"; + candidate["binding_sha256"] = StoryReplayInternal::digest(binding_text); + candidate["checkpoint"] = "99.01"; + candidate["routes"] = std::move(routes); + + JsonObject entry_pose; + entry_pose["map"] = std::string(scene.map); + JsonArray tile; + tile.push_back(scene.start.x); + tile.push_back(scene.start.y); + entry_pose["tile"] = std::move(tile); + entry_pose["facing"] = "east"; + entry_pose["elevation"] = elevation_at(map, scene.start); + JsonObject entry; + entry["basis"] = "scripted"; + entry["screen"] = "overworld"; + entry["pose"] = std::move(entry_pose); + JsonObject scenario; + scenario["entry"] = std::move(entry); + scenario["signals"] = JsonObject(); + JsonArray flags; + if (card_key){ + flags.push_back("card_key_held"); + } + scenario["start_flags"] = std::move(flags); + return replay_story_checkpoint(capture_text, binding_text, candidate.dump(-1), scenario); +} + +// The replay completed the checkpoint and its actions have `kind` (the gate's command). +std::string completed_with(const JsonValue& report, std::string_view kind){ + const JsonObject& root = report.to_object_throw(); + if (root.get_string_throw("status") != "model_complete"){ + return "The replay stopped: " + report.dump(-1); + } + for (const JsonValue& action : root.get_array_throw("actions")){ + if (action.to_object_throw().get_string_throw("kind") == kind){ + return ""; + } + } + return std::format("The replay's actions have no {}.", kind); +} + +UnitTestResult test_replay_door_with_card_key(){ + const std::string failure = completed_with(replay_scene(DOOR, true), "open_gate"); + if (!failure.empty()){ + return failure; + } + return true; +} + +// The recording was made with the Card Key; the run's scenario has none. +UnitTestResult test_replay_door_without_card_key(){ + try{ + const std::string failure = completed_with(replay_scene(DOOR, false), "open_gate"); + if (failure.empty()){ + return "The replay opened a card-key door for a run without the Card Key."; + } + }catch (const ParseException& e){ + if (e.message().find("card-key") == std::string::npos){ + return "Unexpected rejection: " + e.message(); + } + } + return true; +} + +UnitTestResult test_replay_statue_switch(){ + const std::string failure = completed_with(replay_scene(STATUE, false), "press_switch"); + if (!failure.empty()){ + return failure; + } + return true; +} + const std::vector GATES_CASES{ {.input = {.name = "story maps: a closed door blocks without the Card Key", .body = test_maps_sim_door_blocks}, .expectation = {}}, {.input = {.name = "story maps: the door opens with the Card Key and stays open", .body = test_maps_sim_door_opens}, .expectation = {}}, @@ -192,6 +412,9 @@ const std::vector GATES_CASES{ {.input = {.name = "overworld sim: a closed door blocks without the Card Key", .body = test_step_sim_door_blocks}, .expectation = {}}, {.input = {.name = "overworld sim: the door opens with the Card Key", .body = test_step_sim_door_opens}, .expectation = {}}, {.input = {.name = "overworld sim: the statue's switch opens its barrier", .body = test_step_sim_statue_switch}, .expectation = {}}, + {.input = {.name = "replay: a recorded route opens Silph Co.'s card-key door", .body = test_replay_door_with_card_key}, .expectation = {}}, + {.input = {.name = "replay: the recorded door stays shut without the Card Key", .body = test_replay_door_without_card_key}, .expectation = {}}, + {.input = {.name = "replay: a recorded route presses the Mansion's statue", .body = test_replay_statue_switch}, .expectation = {}}, }; } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay.cpp index 159a6c2488..c23b2eb102 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay.cpp @@ -26,6 +26,12 @@ JsonValue replay_story_checkpoint(std::string_view capture, std::string_view bin const auto entry = StoryReplayInternal::read_pose(scenario.to_object_throw().get_object_throw("entry").get_value_throw("pose"), data.maps); Pokemon::RunState state; state.pose = Pokemon::tile_pose(entry.position.map, {entry.position.point}, entry.facing); + // The run flags the checkpoint starts with (card_key_held opens card-key doors). + if (const JsonArray* flags = scenario.to_object_throw().get_array("start_flags")){ + for (const JsonValue& flag : *flags){ + state.flags.insert(flag.to_string_throw()); + } + } JsonArray logs; Pokemon::EventLogger logger = [&](const std::string& line){ logs.push_back(line); }; const Pokemon::CheckpointReport result = Pokemon::run_checkpoint(state, checkpoint, logger); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp index 9105490f3c..6857128425 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp @@ -353,12 +353,17 @@ ReplayScreen between_steps_screen(std::string_view kind){ void validate_scenario(const ReplayData& data, const JsonValue& scenario){ const JsonObject& root = scenario.to_object_throw(); for (const auto& [name, value] : root){ - if (name != "entry" && name != "signals" && name != "between_steps" && name != "check_actions"){ + if (name != "entry" && name != "signals" && name != "between_steps" && name != "check_actions" && name != "start_flags"){ throw ParseException("story replay: unknown scenario field"); } if (name == "check_actions"){ value.to_boolean_throw(); } + if (name == "start_flags"){ + for (const JsonValue& flag : value.to_array_throw()){ + flag.to_string_throw(); + } + } } const JsonObject& entry = fields(root.get_value_throw("entry"), {"basis", "screen", "pose"}); expect(entry, "basis", "scripted"); From 569471cad9b7cc57139f61fa29c6655163a56981 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 20:15:12 -0800 Subject: [PATCH 09/20] FRLG gates: wrap the replay scenario in a JsonValue --- .../Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp index 7f307b1490..5d9b76c9c0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp @@ -357,7 +357,7 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key flags.push_back("card_key_held"); } scenario["start_flags"] = std::move(flags); - return replay_story_checkpoint(capture_text, binding_text, candidate.dump(-1), scenario); + return replay_story_checkpoint(capture_text, binding_text, candidate.dump(-1), JsonValue(std::move(scenario))); } // The replay completed the checkpoint and its actions have `kind` (the gate's command). From 4d3c3ea896cbb12d88f5100505e98b8a62c2f623 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 20:16:07 -0800 Subject: [PATCH 10/20] FRLG gates: a route run without maps keeps none through its gates (the replay's run_route has no planning) --- .../PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp index bb0f438d3f..8b1ba24d7b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldRecovery.cpp @@ -295,7 +295,11 @@ class RouteRun{ return m_resolved ? &*m_resolved : m_planning->maps; } + // A route run without maps (a replay's) keeps none through its gates. void read_gates(){ + if (m_planning == nullptr || m_planning->maps == nullptr){ + return; + } m_resolved = has_gates(*m_planning->maps) ? std::optional(resolve_maps(*m_planning->maps, m_gates)) : std::nullopt; } From b4d6bff7553f2e87fb83f581b387761e484e5694 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 20:17:10 -0800 Subject: [PATCH 11/20] FRLG gates: split the replay test's fixture builders (code health) --- .../PokemonFRLG_AutoStoryGates_Tests.cpp | 73 ++++++++++--------- .../AutoStory/PokemonFRLG_StoryReplay_IO.cpp | 12 ++- 2 files changed, 49 insertions(+), 36 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp index 5d9b76c9c0..faf10ba2a6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.cpp @@ -196,6 +196,7 @@ UnitTestResult test_step_sim_statue_switch(){ // the walk holds), replayed by the story engine on the pinned maps with the // run's flags (the Card Key) and the gates the route's commands change. constexpr std::string_view REVISION = "0123456789abcdef0123456789abcdef01234567"; +constexpr std::string_view CHECKPOINT_ID = "99.01"; const MapData& scene_map(const Scene& scene){ for (const MapData& map : scene_maps()){ @@ -253,22 +254,8 @@ JsonArray recorded_commands(const Scene& scene, const std::vector& ro return commands; } -// The replay of the scene's checkpoint with the recorded route. The scenario starts with -// the Card Key if `card_key`; the recording is made with it either way. -// Throws what the replay rejects. -JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key = true){ - const MapData& map = scene_map(scene); - const Pokemon::GateRules rules{.card_key_held = recorded_card_key}; - const std::optional> route = plan_overworld_route_gated( - scene_maps(), MapPosition{std::string(scene.map), scene.start}, RouteGoal{MapPosition{std::string(scene.map), scene.goal}, std::nullopt}, - Pokemon::GateState(), rules, default_route_costs(), Direction::EAST - ); - if (!route){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No route across the scene to record."); - } - const Direction facing_after = route->back().direction; - - JsonObject start_pose = tile_json(scene, scene.start, "east"); +// The capture of the scene's checkpoint: one route across it, to `facing_after`. +std::string capture_text(const Scene& scene, Direction facing_after){ JsonObject target = tile_json(scene, scene.goal, direction_name(facing_after)); JsonObject event; event["id"] = "cross"; @@ -278,9 +265,9 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key JsonArray events; events.push_back(std::move(event)); JsonObject checkpoint; - checkpoint["id"] = "99.01"; + checkpoint["id"] = std::string(CHECKPOINT_ID); checkpoint["title"] = "Gate replay"; - checkpoint["start"] = std::move(start_pose); + checkpoint["start"] = tile_json(scene, scene.start, "east"); checkpoint["events"] = std::move(events); JsonObject capture; capture["format"] = "pokesim-native-checkpoint-export/1"; @@ -288,8 +275,11 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key capture["checkpoint"] = std::move(checkpoint); capture["source_revision"] = std::string(REVISION); capture["unbound"] = JsonArray(); - const std::string capture_text = capture.dump(-1); + return capture.dump(-1); +} +// The binding of that capture to the scene's map, as the replay pins it. +std::string binding_text(const Scene& scene, const std::string& capture){ std::string map_hash; for (const auto& [name, text] : overworld_map_json()){ if (name == scene.map){ @@ -298,7 +288,7 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key } JsonObject capture_pin; capture_pin["file"] = "gate-replay.json"; - capture_pin["sha256"] = StoryReplayInternal::digest(capture_text); + capture_pin["sha256"] = StoryReplayInternal::digest(capture); capture_pin["source_revision"] = std::string(REVISION); JsonObject maps; maps[std::string(scene.map)] = map_hash; @@ -327,16 +317,11 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key binding["costs"] = std::move(costs); binding["max_route_moves"] = 256; binding["policy"] = std::move(policy); - const std::string binding_text = binding.dump(-1); - - JsonObject routes; - routes["cross"] = recorded_commands(scene, *route); - JsonObject candidate; - candidate["format"] = "pokesim-route-candidate/1"; - candidate["binding_sha256"] = StoryReplayInternal::digest(binding_text); - candidate["checkpoint"] = "99.01"; - candidate["routes"] = std::move(routes); + return binding.dump(-1); +} +// The scenario: the player on the scene's start, with the Card Key if `card_key`. +JsonValue scenario_json(const Scene& scene, bool card_key){ JsonObject entry_pose; entry_pose["map"] = std::string(scene.map); JsonArray tile; @@ -344,7 +329,7 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key tile.push_back(scene.start.y); entry_pose["tile"] = std::move(tile); entry_pose["facing"] = "east"; - entry_pose["elevation"] = elevation_at(map, scene.start); + entry_pose["elevation"] = elevation_at(scene_map(scene), scene.start); JsonObject entry; entry["basis"] = "scripted"; entry["screen"] = "overworld"; @@ -357,14 +342,36 @@ JsonValue replay_scene(const Scene& scene, bool card_key, bool recorded_card_key flags.push_back("card_key_held"); } scenario["start_flags"] = std::move(flags); - return replay_story_checkpoint(capture_text, binding_text, candidate.dump(-1), JsonValue(std::move(scenario))); + return scenario; +} + +// The scene's checkpoint replayed with the route recorded for a player who has the +// Card Key, for a run that has it if `card_key`. Throws what the replay rejects. +JsonValue replay_scene(const Scene& scene, bool card_key){ + const std::optional> route = plan_overworld_route_gated( + scene_maps(), MapPosition{std::string(scene.map), scene.start}, RouteGoal{MapPosition{std::string(scene.map), scene.goal}, std::nullopt}, + Pokemon::GateState(), Pokemon::GateRules{.card_key_held = true}, default_route_costs(), Direction::EAST + ); + if (!route){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No route across the scene to record."); + } + const std::string capture = capture_text(scene, route->back().direction); + const std::string binding = binding_text(scene, capture); + JsonObject routes; + routes["cross"] = recorded_commands(scene, *route); + JsonObject candidate; + candidate["format"] = "pokesim-route-candidate/1"; + candidate["binding_sha256"] = StoryReplayInternal::digest(binding); + candidate["checkpoint"] = std::string(CHECKPOINT_ID); + candidate["routes"] = std::move(routes); + return replay_story_checkpoint(capture, binding, candidate.dump(-1), scenario_json(scene, card_key)); } // The replay completed the checkpoint and its actions have `kind` (the gate's command). std::string completed_with(const JsonValue& report, std::string_view kind){ const JsonObject& root = report.to_object_throw(); if (root.get_string_throw("status") != "model_complete"){ - return "The replay stopped: " + report.dump(-1); + return std::format("The replay stopped: {}", report.dump(-1)); } for (const JsonValue& action : root.get_array_throw("actions")){ if (action.to_object_throw().get_string_throw("kind") == kind){ @@ -391,7 +398,7 @@ UnitTestResult test_replay_door_without_card_key(){ } }catch (const ParseException& e){ if (e.message().find("card-key") == std::string::npos){ - return "Unexpected rejection: " + e.message(); + return std::format("Unexpected rejection: {}", e.message()); } } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp index 6857128425..e1c484e17d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_IO.cpp @@ -350,6 +350,14 @@ ReplayScreen between_steps_screen(std::string_view kind){ } return screen; } +namespace{ +// The run flags a scenario starts with: strings. +void check_start_flags(const JsonValue& flags){ + for (const JsonValue& flag : flags.to_array_throw()){ + flag.to_string_throw(); + } +} +} // namespace void validate_scenario(const ReplayData& data, const JsonValue& scenario){ const JsonObject& root = scenario.to_object_throw(); for (const auto& [name, value] : root){ @@ -360,9 +368,7 @@ void validate_scenario(const ReplayData& data, const JsonValue& scenario){ value.to_boolean_throw(); } if (name == "start_flags"){ - for (const JsonValue& flag : value.to_array_throw()){ - flag.to_string_throw(); - } + check_start_flags(value); } } const JsonObject& entry = fields(root.get_value_throw("entry"), {"basis", "screen", "pose"}); From 16667797abdd48bd08b9a85f68f9f1e4e8be963f Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 20:47:41 -0800 Subject: [PATCH 12/20] FRLG AutoStory: the chain test expects 66 checkpoints (the split's merge counted one twice) Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 94afd2501b..6077c77bcd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -350,8 +350,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po // start: starts_after_unauthored_rows()), and adds the plans to `golden`. UnitTestResult chain_story_routes(std::vector& golden){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 65 || checkpoints[0].start){ - return "Expected 65 checkpoints, the first from a new game."; + if (checkpoints.size() != 66 || checkpoints[0].start){ + return "Expected 66 checkpoints, the first from a new game."; } StoryPose pose; walk_state() = WalkGates{}; From 0ad0952328ca12a02134faa21fac8ca298457a42 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 00:27:58 -0800 Subject: [PATCH 13/20] FRLG maps: pin PokemonSimulation 1cacf81 (Silph card keys, Mansion switches, Victory Road gates); map-pack action at the same revision Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .github/workflows/cpp-ci-serial-programs-base.yml | 2 +- devtools/maps/map-resources.lock.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 8eefdf4f37..85f9fe8847 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -109,7 +109,7 @@ jobs: - name: Prepare approved FRLG map resources id: map-resources - uses: dayfine/PokemonSimulation/integrations/arduino-source/verify-map-packs@d3eea1b5c04180f8b60eb98b0d65f70aca6b1abb + uses: dayfine/PokemonSimulation/integrations/arduino-source/verify-map-packs@1cacf81b2377ec1413317d905ad5415f6fe8dad5 with: layout: resources operation: prepare diff --git a/devtools/maps/map-resources.lock.json b/devtools/maps/map-resources.lock.json index 71d82cd296..6f55191d46 100644 --- a/devtools/maps/map-resources.lock.json +++ b/devtools/maps/map-resources.lock.json @@ -3,9 +3,9 @@ "repository": "dayfine/PokemonSimulation", "games": { "frlg": { - "revision": "4b886bbead2e85c42f15bfb0b5ac735c159db039", + "revision": "1cacf81b2377ec1413317d905ad5415f6fe8dad5", "manifest_path": "data/maps/runtime-manifest.json", - "manifest_sha256": "eeca55d046c02d5866b54f48abe90dc5dc4c59d483cd0edd7a857d374d85dd2c" + "manifest_sha256": "0fbd71b8f985746c673ef530fa69fea17b7c6b808156fc7d7dbdadade7e7dd9a" } } } From 54d5210ef9b71630609d9294c8774aa5b4d144e9 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 00:40:01 -0800 Subject: [PATCH 14/20] FRLG gates: Victory Road floor-switch barriers on the real maps Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldGateMaps_Tests.cpp | 46 +++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp index 0e659afb2d..a9b2782cbc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp @@ -219,6 +219,48 @@ UnitTestResult test_gate_errors(){ } +// Victory Road: each floor's boulder-fed floor switch opens its barrier, a +// top and a bottom tile. The boulder is not modelled: the switch has no +// statue to press, only its flag, which the game sets for good. +UnitTestResult test_victory_road_barriers(){ + struct Floor{ + const char* name; + size_t gates; + size_t switches; + const char* switch_id; + const char* barrier; + const char* flag; + TilePos top; + }; + const Floor floors[] = { + {"VictoryRoad_1F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_1F", {12, 14}}, + {"VictoryRoad_2F", 4, 2, "floor_switch_2", "barrier_2_top", "VAR_MAP_SCENE_VICTORY_ROAD_2F_BOULDER2", {33, 16}}, + {"VictoryRoad_3F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_3F", {12, 12}}, + }; + for (const Floor& floor : floors){ + const MapData map = load_map(floor.name); + if (map.gates.size() != floor.gates || map.switches.size() != floor.switches){ + return std::format("{}: expected {} gates and {} switches, got {} and {}.", + floor.name, floor.gates, floor.switches, map.gates.size(), map.switches.size()); + } + const auto found = map.switches.find(floor.switch_id); + if (found == map.switches.end() || found->second.toggle || found->second.flag != floor.flag || !found->second.statues.empty()){ + return std::format("{}: {} should be a one-way flag switch with no statue.", floor.name, floor.switch_id); + } + const MapGate& top = map.gates.at(floor.barrier); + if (top.kind != GateKind::SWITCH || top.switch_id != floor.switch_id || !top.open_when_on || top.open_at_new_game){ + return std::format("{}: the barrier should be closed at new game and open with {}.", floor.name, floor.switch_id); + } + GateState off; + GateState on; + on.switches_on.insert(floor.switch_id); + if (resolved_tile(map, floor.top, off) != TileKind::WALL || resolved_tile(map, floor.top, on) == TileKind::WALL){ + return std::format("{}: the barrier at ({}, {}) should be a wall until {} is on.", floor.name, floor.top.x, floor.top.y, floor.switch_id); + } + } + return true; +} + // State and tiles UnitTestResult test_tiles_follow_state(){ @@ -471,6 +513,10 @@ const GatesTestCase GATES_CASES[] = { .input = {.name = "a hole is one-way", .test = test_hole_one_way}, .expectation = {.description = "down yes, back up no"}, }, + { + .input = {.name = "Victory Road barriers", .test = test_victory_road_barriers}, + .expectation = {.description = "floor switches open the barriers; boulders are not modelled"}, + }, }; } // namespace From 4de8e2e9eedef123040e6de56846493319410f57 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 00:40:51 -0800 Subject: [PATCH 15/20] FRLG gates: Victory Road test uses string_view Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldGateMaps_Tests.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp index a9b2782cbc..72bae96f3a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp @@ -224,12 +224,12 @@ UnitTestResult test_gate_errors(){ // statue to press, only its flag, which the game sets for good. UnitTestResult test_victory_road_barriers(){ struct Floor{ - const char* name; + std::string_view name; size_t gates; size_t switches; - const char* switch_id; - const char* barrier; - const char* flag; + std::string_view switch_id; + std::string_view barrier; + std::string_view flag; TilePos top; }; const Floor floors[] = { @@ -238,22 +238,22 @@ UnitTestResult test_victory_road_barriers(){ {"VictoryRoad_3F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_3F", {12, 12}}, }; for (const Floor& floor : floors){ - const MapData map = load_map(floor.name); + const MapData map = load_map(std::string(floor.name)); if (map.gates.size() != floor.gates || map.switches.size() != floor.switches){ return std::format("{}: expected {} gates and {} switches, got {} and {}.", floor.name, floor.gates, floor.switches, map.gates.size(), map.switches.size()); } - const auto found = map.switches.find(floor.switch_id); + const auto found = map.switches.find(std::string(floor.switch_id)); if (found == map.switches.end() || found->second.toggle || found->second.flag != floor.flag || !found->second.statues.empty()){ return std::format("{}: {} should be a one-way flag switch with no statue.", floor.name, floor.switch_id); } - const MapGate& top = map.gates.at(floor.barrier); + const MapGate& top = map.gates.at(std::string(floor.barrier)); if (top.kind != GateKind::SWITCH || top.switch_id != floor.switch_id || !top.open_when_on || top.open_at_new_game){ return std::format("{}: the barrier should be closed at new game and open with {}.", floor.name, floor.switch_id); } GateState off; GateState on; - on.switches_on.insert(floor.switch_id); + on.switches_on.insert(std::string(floor.switch_id)); if (resolved_tile(map, floor.top, off) != TileKind::WALL || resolved_tile(map, floor.top, on) == TileKind::WALL){ return std::format("{}: the barrier at ({}, {}) should be a wall until {} is on.", floor.name, floor.top.x, floor.top.y, floor.switch_id); } From 0e0dc5f2dec8d497bcc221b13a80541d2b4bc628 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 01:21:20 -0800 Subject: [PATCH 16/20] Unit test runner: drop the deleted Pokemon_Gates_Tests.h frlg/gates (fb8795f31) moved these tests to PokemonFRLG_OverworldGateMaps_Tests but left the include and the call, so the runner did not compile. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 9a5cf86d3d..e56c4a593b 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -36,7 +36,6 @@ #include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" #include "Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h" -#include "Pokemon/Navigation/Pokemon_Gates_Tests.h" #include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h" #include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h" #include "Pokemon/Navigation/Pokemon_MapData_Tests.h" @@ -89,7 +88,6 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ Pokemon::add_tests_WallRecovery(ret); Pokemon::add_tests_MapData(ret); Pokemon::add_tests_ConnectedMaps(ret); - Pokemon::add_tests_Gates(ret); Pokemon::add_tests_MoveMechanics(ret); Pokemon::add_tests_RuntimeMap(ret); Pokemon::add_tests_RouteLog(ret); From f1aad341e2015740ce7479fe2ad4cac042f90a67 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 01:34:23 -0800 Subject: [PATCH 17/20] FRLG gates: a boulder on a floor switch's button turns it on; one floor's switch is its own Victory Road's maps give each floor a floor_switch_1 with its own flag, so a switch with one floor is known in GateState as gate_key(map, id) (switch_key()); the Mansion's shared switch keeps its id. MapSwitch reads the boulder buttons; the sim's PUSH_BOULDER, the console's push_boulder step and the map-level row sim (boulder_pushed()) turn the switch on when the boulder ends on a button. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Pokemon/Navigation/Pokemon_GateTiles.cpp | 19 +++++++++++- .../Pokemon/Navigation/Pokemon_GateTiles.h | 10 +++++++ .../Pokemon/Navigation/Pokemon_GatedPlanner.h | 8 +++-- .../Pokemon/Navigation/Pokemon_MapData.cpp | 8 +++++ .../Pokemon/Navigation/Pokemon_MapGates.h | 5 +++- .../PokemonFRLG_OverworldGateMaps_Tests.cpp | 24 +++++++++++---- .../PokemonFRLG_OverworldGates_Tests.cpp | 4 +-- .../PokemonFRLG_OverworldSimField.cpp | 17 +++++++++-- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 29 +++++++++++++++++-- .../PokemonFRLG_AutoStoryPacedRoute.h | 7 +++++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 3 +- .../PokemonFRLG_StoryReplay_Executor.cpp | 7 +++-- 12 files changed, 118 insertions(+), 23 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.cpp index 2c3053b27d..bca7bbbdd8 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.cpp @@ -10,6 +10,21 @@ namespace PokemonAutomation{ namespace Pokemon{ +std::string switch_key(const MapSwitch& pressed){ + return pressed.floors.size() == 1 ? gate_key(pressed.floors.front(), pressed.id) : pressed.id; +} + +const MapSwitch* switch_with_button(const MapData& map, const TilePos& pos){ + for (const auto& [id, result] : map.switches){ + for (const TilePos& button : result.buttons){ + if (button == pos){ + return &result; + } + } + } + return nullptr; +} + const MapGate* gate_at(const MapData& map, const TilePos& pos){ for (const auto& [id, gate] : map.gates){ for (const TilePos& tile : gate.tiles){ @@ -23,7 +38,9 @@ const MapGate* gate_at(const MapData& map, const TilePos& pos){ bool gate_is_open(const MapData& map, const MapGate& gate, const GateState& state){ if (gate.kind == GateKind::SWITCH){ - return state.switch_on(gate.switch_id) == gate.open_when_on; + const auto found = map.switches.find(gate.switch_id); + const std::string key = found == map.switches.end() ? gate.switch_id : switch_key(found->second); + return state.switch_on(key) == gate.open_when_on; } return gate.open_at_new_game || state.opened.contains(gate_key(map.name, gate.id)); } diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.h index 89a0c4fcd7..6a413df2a3 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GateTiles.h @@ -10,6 +10,7 @@ #ifndef PokemonAutomation_Pokemon_GateTiles_H #define PokemonAutomation_Pokemon_GateTiles_H +#include #include "Pokemon_GateState.h" #include "Pokemon_Grid.h" #include "Pokemon_MapData.h" @@ -18,6 +19,15 @@ namespace PokemonAutomation{ namespace Pokemon{ +// The name GateState::switches_on knows `pressed` by: its id when several +// maps share it (Pokemon Mansion's floors), and gate_key(its map, its id) +// when it is one map's own (each Victory Road floor has a +// "floor_switch_1" of its own, with its own flag). +std::string switch_key(const MapSwitch& pressed); + +// The switch whose boulder button is `pos`, or nullptr if no switch's is. +const MapSwitch* switch_with_button(const MapData& map, const TilePos& pos); + // The gate that has `pos`, or nullptr if no gate does. const MapGate* gate_at(const MapData& map, const TilePos& pos); diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h index 183e3f8716..205cb7dfcb 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_GatedPlanner.h @@ -39,6 +39,7 @@ #include #include #include +#include #include #include "Pokemon_ConnectedMaps.h" #include "Pokemon_GateTiles.h" @@ -131,11 +132,12 @@ class GatedModel{ Step press_switch(const State& state, const MapSwitch& pressed, Direction direction) const{ Step step; step.next = state; - const bool now_on = pressed.toggle ? !state.gates.switch_on(pressed.id) : true; + const std::string key = switch_key(pressed); + const bool now_on = pressed.toggle ? !state.gates.switch_on(key) : true; if (now_on){ - step.next.gates.switches_on.insert(pressed.id); + step.next.gates.switches_on.insert(key); }else{ - step.next.gates.switches_on.erase(pressed.id); + step.next.gates.switches_on.erase(key); } step.action = ACTION_PRESS_SWITCH; step.ends_leg = true; diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData.cpp index 227ca7ffcd..59e052b9de 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData.cpp +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapData.cpp @@ -572,6 +572,10 @@ MapStatue read_statue(const JsonObject& object, const std::string& where){ return statue; } +TilePos read_button(const JsonObject& object, const std::string& where){ + return read_pair_field(object, "coord", where); +} + MapSwitch read_switch(const std::string& id, const JsonObject& object, const std::string& where){ MapSwitch result; result.id = id; @@ -593,6 +597,7 @@ MapSwitch read_switch(const std::string& id, const JsonObject& object, const std result.floors.push_back(*floor); } result.statues = read_list(object, "statues", where, read_statue); + result.buttons = read_list(object, "buttons", where, read_button); return result; } @@ -682,6 +687,9 @@ void check_gates(const MapData& map, const std::string& where){ check_inside(map.tiles, result.statues[c].tile, statue_where); check_inside(map.tiles, result.statues[c].face_from, statue_where); } + for (size_t c = 0; c < result.buttons.size(); c++){ + check_inside(map.tiles, result.buttons[c], std::format("{}switches.{}.buttons[{}]", where, id, c)); + } } } diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapGates.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapGates.h index 8c2ef63083..11f902b09f 100644 --- a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapGates.h +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_MapGates.h @@ -54,13 +54,16 @@ struct MapStatue{ // A switch the map's gates follow. One state is shared by every map in // `floors` (Pokemon Mansion's statue switch, an event flag): pressing a // statue flips it, and each floor redraws its gates when it loads. -// `statues` are the statues on this map only. +// `statues` are the statues on this map only. `buttons` are the tiles a +// Strength boulder turns it on from (Victory Road's floor switches, which +// stay on). struct MapSwitch{ std::string id; std::string flag; bool toggle = true; std::vector floors; std::vector statues; + std::vector buttons = {}; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp index 72bae96f3a..baf68ee50f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGateMaps_Tests.cpp @@ -220,8 +220,9 @@ UnitTestResult test_gate_errors(){ // Victory Road: each floor's boulder-fed floor switch opens its barrier, a -// top and a bottom tile. The boulder is not modelled: the switch has no -// statue to press, only its flag, which the game sets for good. +// top and a bottom tile. The switch has no statue to press, only its flag, +// which the game sets for good, and its button, the tile a boulder turns it +// on from. Each floor's switch is its own: on, it opens no other floor's. UnitTestResult test_victory_road_barriers(){ struct Floor{ std::string_view name; @@ -231,11 +232,12 @@ UnitTestResult test_victory_road_barriers(){ std::string_view barrier; std::string_view flag; TilePos top; + TilePos button; }; const Floor floors[] = { - {"VictoryRoad_1F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_1F", {12, 14}}, - {"VictoryRoad_2F", 4, 2, "floor_switch_2", "barrier_2_top", "VAR_MAP_SCENE_VICTORY_ROAD_2F_BOULDER2", {33, 16}}, - {"VictoryRoad_3F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_3F", {12, 12}}, + {"VictoryRoad_1F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_1F", {12, 14}, {20, 16}}, + {"VictoryRoad_2F", 4, 2, "floor_switch_2", "barrier_2_top", "VAR_MAP_SCENE_VICTORY_ROAD_2F_BOULDER2", {33, 16}, {14, 19}}, + {"VictoryRoad_3F", 2, 1, "floor_switch_1", "barrier_1_top", "VAR_MAP_SCENE_VICTORY_ROAD_3F", {12, 12}, {7, 7}}, }; for (const Floor& floor : floors){ const MapData map = load_map(std::string(floor.name)); @@ -251,9 +253,19 @@ UnitTestResult test_victory_road_barriers(){ if (top.kind != GateKind::SWITCH || top.switch_id != floor.switch_id || !top.open_when_on || top.open_at_new_game){ return std::format("{}: the barrier should be closed at new game and open with {}.", floor.name, floor.switch_id); } + const MapSwitch* pressed = switch_with_button(map, floor.button); + if (pressed == nullptr || pressed->id != floor.switch_id){ + return std::format("{}: no {} button at ({}, {}).", floor.name, floor.switch_id, floor.button.x, floor.button.y); + } GateState off; GateState on; - on.switches_on.insert(std::string(floor.switch_id)); + on.switches_on.insert(switch_key(*pressed)); + // Another floor's switch of the same id leaves this barrier shut. + GateState elsewhere; + elsewhere.switches_on.insert(std::format("VictoryRoad_XF/{}", floor.switch_id)); + if (resolved_tile(map, floor.top, elsewhere) != TileKind::WALL){ + return std::format("{}: another floor's {} opened the barrier.", floor.name, floor.switch_id); + } if (resolved_tile(map, floor.top, off) != TileKind::WALL || resolved_tile(map, floor.top, on) == TileKind::WALL){ return std::format("{}: the barrier at ({}, {}) should be a wall until {} is on.", floor.name, floor.top.x, floor.top.y, floor.switch_id); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp index 0180b7b473..21d8aec2df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGates_Tests.cpp @@ -159,7 +159,7 @@ UnitTestResult test_route_presses_statue(){ if (count_steps(*route, RouteAction::PRESS_SWITCH) != 1 || !(route->back().end == STATUE_GOAL)){ return "Expected one press-switch step and the goal reached:" + describe(*route); } - if (!gates_after_route(GateState(), *route).switch_on("mansion")){ + if (!gates_after_route(GateState(), *route).switch_on("GateStatue/mansion")){ return "gates_after_route() does not have the switch on."; } return true; @@ -257,7 +257,7 @@ UnitTestResult test_sim_presses_statue(){ return "No route."; } const SimRun run = walk_in_sim(statue_maps(), STATUE_START, *route, false); - if (!run.failure.empty() || !(run.position == STATUE_GOAL) || !run.gates.switch_on("mansion")){ + if (!run.failure.empty() || !(run.position == STATUE_GOAL) || !run.gates.switch_on("GateStatue/mansion")){ return std::format("Expected the switch on and the goal reached, ended at {}: \"{}\"", to_string(run.position), run.failure) + describe(*route) + joined(run.log); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp index 1b4bb823f9..3acd5341bc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp @@ -140,6 +140,16 @@ bool OverworldSim::push_boulder(){ boulder->y = beyond.y; advance_to(m_now + PUSH_TIME); note("pushed the boulder to " + to_string(MapPosition{map().name, beyond}) + "."); + // A boulder on a floor switch's button turns it on for good (Victory + // Road's floors: the switch's flag, then the barrier redrawn). + const Pokemon::MapSwitch* pressed = m_state.gate_maps.empty() + ? nullptr + : Pokemon::switch_with_button(m_state.gate_maps[m_map], beyond); + if (pressed != nullptr){ + m_state.gates.switches_on.insert(Pokemon::switch_key(*pressed)); + read_gates(); + note(std::format("switch {} is on.", Pokemon::switch_key(*pressed))); + } return true; } @@ -217,11 +227,12 @@ bool OverworldSim::press_switch(){ } // The prompt, YES, and the text after it. advance_to(m_now + m_script.timing.message); - const bool now_on = pressed->toggle ? !m_state.gates.switch_on(pressed->id) : true; + const std::string key = Pokemon::switch_key(*pressed); + const bool now_on = pressed->toggle ? !m_state.gates.switch_on(key) : true; if (now_on){ - m_state.gates.switches_on.insert(pressed->id); + m_state.gates.switches_on.insert(key); }else{ - m_state.gates.switches_on.erase(pressed->id); + m_state.gates.switches_on.erase(key); } read_gates(); note(std::format("switch {} is {}.", pressed->id, now_on ? "on" : "off")); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 0100ed32bf..1afb193b0b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -12,6 +13,7 @@ #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "Pokemon/Navigation/Pokemon_GateTiles.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" @@ -422,6 +424,29 @@ void add_start_pose_check( add_start_check(checkpoint, start, std::move(reader), std::move(log)); } +Outcome boulder_pushed(RunState& state, const StoryStep& step, const std::vector& maps){ + const std::optional here = story_pose(state.pose); + if (!here){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const Direction direction = arg(step, "direction"); + const int64_t tiles = arg(step, "tiles"); + StoryPose at{here->map, here->tile, direction}; + for (int64_t c = 0; c < tiles; c++){ + at.tile = at.tile.next(direction); + } + // The boulder stands a tile ahead; on a floor switch's button, the + // switch is on for good and its barrier open. + const auto map = std::find_if(maps.begin(), maps.end(), [&](const MapData& item){ + return item.name == at.map; + }); + const Pokemon::MapSwitch* pressed = map == maps.end() ? nullptr : Pokemon::switch_with_button(*map, at.tile.next(direction)); + if (pressed != nullptr){ + state.gates.switches_on.insert(Pokemon::switch_key(*pressed)); + } + return Pokemon::outcome_ok(to_pose(at)); +} + Pokemon::Pose paced_pose(const Pokemon::Pose& patch, const StoryStep& step){ std::optional pace; if (const std::optional grind = step.action == GRIND_ACTION ? grind_plan_of(step.args) : std::nullopt){ @@ -632,12 +657,10 @@ Outcome push_boulder(StoryEnv& env, RunState& state, const StoryStep& step){ answer_yes_no(env.console, env.context, true, BUTTON_B, YES_NO_TIMEOUT); mash_until_overworld(env.console, env.context, SCENE_TIMEOUT); } - StoryPose at = *here; for (int64_t c = 0; c < tiles; c++){ step_once(env.console, env.context, direction, direction, env.player_gender); - at = StoryPose{at.map, at.tile.next(direction), direction}; } - return Pokemon::outcome_ok(to_pose(at)); + return boulder_pushed(state, step, story_maps()); } // Vermilion Gym's trash cans on the console: a walk to each can's stand diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h index 6fac86baf3..81d4268e5f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h @@ -12,6 +12,8 @@ #include #include +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" #include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" @@ -29,6 +31,11 @@ namespace PokemonFRLG{ // other step, or a `patch` not on one tile. Pokemon::Pose paced_pose(const Pokemon::Pose& patch, const StoryStep& step); +// Where a PUSH_BOULDER_VARIANT step leaves the player: `tiles` tiles on in +// its direction, behind the boulder. A boulder that ends on a floor +// switch's button turns that switch on in `state.gates`. +Pokemon::Outcome boulder_pushed(Pokemon::RunState& state, const StoryStep& step, const std::vector& maps); + // The maps the story plans on: every map to Route 4's Pokemon Center, with // the objects the game hides after the Hall of Fame removed, as the lab's // frlg_route does, and those a new game hides until their scene (the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 0cc99c37ec..7c9d6cb4bb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -229,8 +229,9 @@ Pokemon::StoryAction StoryMapsSim::action(StoryActionId id){ // Pacing leaves the player on either of its tiles, as on the console. case StoryActionId::CLOSE_TRAINER_CARD: case StoryActionId::LEAVE_GIFT_SUMMARY: - case StoryActionId::CUT_TREE: case StoryActionId::PUSH_BOULDER: + return played([this](const StoryStep& step, RunState& state){ return boulder_pushed(state, step, maps()); }); + case StoryActionId::CUT_TREE: case StoryActionId::TRASH_CANS: case StoryActionId::GAME: return m_stubs.stub([](const StoryStep& step, RunState& state){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp index 80faff34b3..3125211e69 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_StoryReplay_Executor.cpp @@ -192,10 +192,11 @@ ReplayLeg ReplayExecutor::prepare_gate_leg(const JsonValue& value, const Overwor if (pressed == nullptr){ throw ParseException("story replay: no statue to press"); } - if (pressed->toggle && gates.switch_on(pressed->id)){ - after.switches_on.erase(pressed->id); + const std::string key = Pokemon::switch_key(*pressed); + if (pressed->toggle && gates.switch_on(key)){ + after.switches_on.erase(key); }else{ - after.switches_on.insert(pressed->id); + after.switches_on.insert(key); } } RouteStep step{.action = opens ? RouteAction::OPEN_GATE : RouteAction::PRESS_SWITCH, .direction = facing, .tiles = 0}; From d0cca8009009f8fc03cc72420885f23dfa42ee97 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 02:20:08 -0800 Subject: [PATCH 18/20] FRLG 19.04b to 19.04d: Victory Road's boulder switches, 1F to 3F and out to Route 23 19.04b pushes 1F's boulder onto its switch and climbs to 2F; 19.04c does 2F's west switch and 3F's (7, 7); 19.04d pushes 3F's boulder down the hole, follows it to 2F, pushes it onto 2F's second switch and leaves by the exit. Pushes are the boulder solver's; corner waypoints keep routes off pushed boulders (the maps still show them where they started) and out of trainers' lines. The sim drops a boulder through a hole and shows the one the game hid below; the fault sweep counts a push as a step the sim plays. 19.05 starts at Route 23 (18, 29): the exit walks the player a tile off the cave mouth in the sim. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldSim.h | 3 + .../PokemonFRLG_OverworldSimField.cpp | 46 ++++ .../PokemonFRLG_AutoStoryBoulders_Tests.cpp | 9 +- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 1 + .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 5 +- .../PokemonFRLG_AutoStoryPlanGolden19.h | 184 ++++++++++++++- .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 5 +- .../PokemonFRLG_AutoStoryRunPlan_Tests.cpp | 8 +- .../AutoStory/PokemonFRLG_AutoStoryTable.cpp | 2 +- ...emonFRLG_AutoStoryUnauthoredStarts_Tests.h | 5 +- ...PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp | 74 ++++++ .../AutoStory/PokemonFRLG_AutoStory_Tests.cpp | 4 +- .../AutoStory/StoryData/frlg-19.04.plan.json | 2 +- .../AutoStory/StoryData/frlg-19.04b.plan.json | 196 ++++++++++++++++ .../AutoStory/StoryData/frlg-19.04c.plan.json | 220 ++++++++++++++++++ .../AutoStory/StoryData/frlg-19.04d.plan.json | 157 +++++++++++++ .../AutoStory/StoryData/frlg-19.05.plan.json | 6 +- 17 files changed, 899 insertions(+), 28 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04b.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04c.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04d.plan.json diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h index 0841d880b4..4eb93a93a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h @@ -176,6 +176,9 @@ class OverworldSim{ bool push_poster_switch(); // SimField::PUSH_BOULDER. (PokemonFRLG_OverworldSimField.cpp) bool push_boulder(); + // A boulder fell through `hole`: the boulder the game hid on the floor + // below (a pushable_boulder with a hide_flag) is shown. + void land_fallen_boulder(const MapPosition& hole); bool start_surf(); // A on the gate or the statue the player faces; false, as a violation, // if there is none or the Card Key is missing. diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp index 3acd5341bc..24fc75b2c6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp @@ -14,6 +14,7 @@ #include "PokemonFRLG_CodedRooms.h" #include "PokemonFRLG_FlyMap.h" #include "PokemonFRLG_OverworldGatedRoute.h" +#include "PokemonFRLG_OverworldMaps.h" #include "PokemonFRLG_OverworldSim.h" #include "PokemonFRLG_OverworldSimField.h" #include "PokemonFRLG_OverworldWalk.h" @@ -119,6 +120,39 @@ bool OverworldSim::cut_tree(){ return false; } +void OverworldSim::land_fallen_boulder(const MapPosition& hole){ + const MapData* from = nullptr; + for (const MapData& item : m_maps){ + if (item.name == hole.map){ + from = &item; + } + } + const MapWarp* warp = from == nullptr ? nullptr : warp_at(*from, hole.point); + if (warp == nullptr || !warp->to){ + return; + } + static const std::vector ALL = overworld_maps(); + for (const MapData& below : ALL){ + if (below.name != warp->to->map){ + continue; + } + for (MapData& shown : m_maps){ + if (shown.name != below.name){ + continue; + } + for (const MapObject& object : below.objects){ + const bool hidden = object.name == "pushable_boulder" && object.hide_flag && std::none_of( + shown.objects.begin(), shown.objects.end(), [&](const MapObject& item){ return item.x == object.x && item.y == object.y; } + ); + if (hidden){ + shown.objects.push_back(object); + note("the boulder lands on " + to_string(MapPosition{shown.name, TilePos{object.x, object.y}}) + "."); + } + } + } + } +} + bool OverworldSim::push_boulder(){ std::vector& objects = m_maps[m_map].objects; const TilePos ahead = m_player.position.next(m_state.facing); @@ -129,6 +163,18 @@ bool OverworldSim::push_boulder(){ violation("no boulder " + std::string(direction_name(m_state.facing)) + " of " + to_string(m_state.position) + "."); return false; } + // A boulder pushed onto a hole falls through it to the floor below, + // where the game shows the boulder it hid until then (Victory Road + // 3F's (34, 18): 2F's (33, 19), FLAG_HIDE_VICTORY_ROAD_2F_BOULDER). + const TilePos into = ahead.next(m_state.facing); + if (map().tiles.contains(into) && map().tiles.at(into) == TileKind::FALL_HOLE){ + const MapPosition hole{map().name, into}; + objects.erase(boulder); + advance_to(m_now + PUSH_TIME); + note("pushed the boulder into the hole at " + to_string(hole) + "."); + land_fallen_boulder(hole); + return true; + } // The boulder moves where a player on its tile could step. const PlayerState on_boulder{ahead, elevation_at(map(), ahead), false}; if (classify_step(map(), on_boulder, m_state.facing) != StepKind::WALK){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders_Tests.cpp index f19ebd507f..f4145e34ee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders_Tests.cpp @@ -6,12 +6,9 @@ * (Pokemon_BoulderSolver below), and the sim's PUSH_BOULDER, which the * search's answer is replayed on. * - * TODO(map edit, needs the user's OK): the Victory Road maps have the - * boulders (objects named "pushable_boulder") but not the switches' - * barriers or which tiles the switches press, so the planner walks - * through the barriers. The data below is from the decompilation - * (pokefirered data/maps/VictoryRoad_*), kept here until the maps carry - * it as `gates` and `switches`; then this search reads them from the map. + * The maps carry each floor's barriers as `gates` and its switch's + * button (PokemonSimulation 1cacf81); the puzzle below repeats 1F's for + * the search. Rows 19.04b to 19.04d play the search's answers. * */ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 1afb193b0b..886f137ed3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -367,6 +367,7 @@ std::string save_card_place(const std::string& map){ {"Route25", "route-25"}, {"Route22", "route-22"}, {"Route23", "route-23"}, + {"VictoryRoad", "victory-road"}, {"VermilionCity", "vermilion-city"}, {"Route10", "route-10"}, {"LavenderTown", "lavender-town"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp index 91f276348a..54ab37176b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -199,8 +199,9 @@ bool sim_plays(const StoryStep& step){ case StoryStepKind::GAME: // A Fly lands on its town's landing tile, as the sim plays it; a // lift's warp lets out on its floor's tile (sweep_maps()' lift - // rooms, with_lifts()). - return step.action == CUT_TREE_VARIANT || is_field_move_step(step) || parse_lift_floor_step(step).has_value(); + // rooms, with_lifts()). A boulder's push leaves the player behind + // it, as the sim plays it. + return step.action == CUT_TREE_VARIANT || step.action == PUSH_BOULDER_VARIANT || is_field_move_step(step) || parse_lift_floor_step(step).has_value(); default: return false; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden19.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden19.h index 872c365fae..0dd3939443 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden19.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPlanGolden19.h @@ -97,10 +97,186 @@ inline constexpr std::string_view FRLG_PLAN_GOLDEN_19[] = { "19.03 walk north 6 -> Route23 (5, 36)", "19.03 victory_road_mouth from Route23 (5, 35) facing north to Route23 (5, 29) facing north", "19.03 walk north 6 -> Route23 (5, 29)", - "19.05 indigo_door from Route23 (18, 28) facing south to IndigoPlateau_Exterior (11, 7) facing north", - "19.05 walk south 4 (to wall) -> Route23 (18, 32)", - "19.05 walk east 3 (to wall) -> Route23 (21, 32)", - "19.05 walk north 14 -> Route23 (21, 18)", + "19.04b behind_boulder_1 from VictoryRoad_1F (11, 20) facing north to VictoryRoad_1F (7, 17)", + "19.04b walk west 3 (to wall) -> VictoryRoad_1F (8, 20) [wild]", + "19.04b walk north 1 (to wall) -> VictoryRoad_1F (8, 19) [wild]", + "19.04b walk west 2 -> VictoryRoad_1F (6, 19) [wild]", + "19.04b walk north 2 (to wall) -> VictoryRoad_1F (6, 17) [wild]", + "19.04b walk east 1 (to wall) -> VictoryRoad_1F (7, 17) [wild]", + "19.04b by_boulder_2_corner from VictoryRoad_1F (7, 18) facing south to VictoryRoad_1F (6, 18)", + "19.04b walk west 1 -> VictoryRoad_1F (6, 18) [wild]", + "19.04b behind_boulder_2 from VictoryRoad_1F (6, 18) facing west to VictoryRoad_1F (6, 19)", + "19.04b walk south 1 (to wall) -> VictoryRoad_1F (6, 19) [wild]", + "19.04b by_boulder_3_corner from VictoryRoad_1F (11, 19) facing east to VictoryRoad_1F (10, 20)", + "19.04b walk south 1 -> VictoryRoad_1F (11, 20)", + "19.04b walk west 1 -> VictoryRoad_1F (10, 20) [wild]", + "19.04b behind_boulder_3 from VictoryRoad_1F (10, 20) facing west to VictoryRoad_1F (12, 20)", + "19.04b walk east 2 (to wall) -> VictoryRoad_1F (12, 20) [wild]", + "19.04b by_boulder_4_corner from VictoryRoad_1F (12, 18) facing north to VictoryRoad_1F (11, 18)", + "19.04b walk west 1 -> VictoryRoad_1F (11, 18) [wild]", + "19.04b behind_boulder_4 from VictoryRoad_1F (11, 18) facing west to VictoryRoad_1F (11, 17)", + "19.04b walk north 1 (to wall) -> VictoryRoad_1F (11, 17) [wild]", + "19.04b by_boulder_5_corner from VictoryRoad_1F (18, 17) facing east to VictoryRoad_1F (18, 18)", + "19.04b walk south 1 (to wall) -> VictoryRoad_1F (18, 18) [wild]", + "19.04b behind_boulder_5 from VictoryRoad_1F (18, 18) facing south to VictoryRoad_1F (19, 18)", + "19.04b walk east 1 (to wall) -> VictoryRoad_1F (19, 18) [wild]", + "19.04b by_boulder_6_corner from VictoryRoad_1F (19, 16) facing north to VictoryRoad_1F (20, 14)", + "19.04b walk east 1 (to wall) -> VictoryRoad_1F (20, 16)", + "19.04b walk north 2 (to wall) -> VictoryRoad_1F (20, 14) [wild]", + "19.04b by_boulder_6_top from VictoryRoad_1F (20, 14) facing north to VictoryRoad_1F (18, 14)", + "19.04b walk west 2 (to wall) -> VictoryRoad_1F (18, 14) [wild]", + "19.04b behind_boulder_6 from VictoryRoad_1F (18, 14) facing west to VictoryRoad_1F (18, 15)", + "19.04b walk south 1 (to wall) -> VictoryRoad_1F (18, 15) [wild]", + "19.04b by_boulder_7_corner from VictoryRoad_1F (19, 15) facing east to VictoryRoad_1F (19, 14)", + "19.04b walk north 1 (to wall) -> VictoryRoad_1F (19, 14) [wild]", + "19.04b behind_boulder_7 from VictoryRoad_1F (19, 14) facing north to VictoryRoad_1F (20, 14)", + "19.04b walk east 1 (to wall) -> VictoryRoad_1F (20, 14) [wild]", + "19.04b below_ladder from VictoryRoad_1F (20, 15) facing south to VictoryRoad_1F (4, 7) facing north", + "19.04b walk south 1 (to wall) -> VictoryRoad_1F (20, 16)", + "19.04b walk west 1 (to wall) -> VictoryRoad_1F (19, 16) [wild]", + "19.04b walk south 2 (to wall) -> VictoryRoad_1F (19, 18) [wild]", + "19.04b walk west 4 (to wall) -> VictoryRoad_1F (15, 18) [wild]", + "19.04b walk north 1 (to wall) -> VictoryRoad_1F (15, 17) [wild]", + "19.04b walk west 4 (to wall) -> VictoryRoad_1F (11, 17) [wild]", + "19.04b walk south 4 (warp) -> Route23 (5, 29) [wild]", + "19.04b walk north 1 (warp) -> VictoryRoad_1F (11, 20)", + "19.04b walk west 3 (to wall) -> VictoryRoad_1F (8, 20) [wild]", + "19.04b walk north 1 (to wall) -> VictoryRoad_1F (8, 19) [wild]", + "19.04b walk west 2 -> VictoryRoad_1F (6, 19) [wild]", + "19.04b walk north 2 (to wall) -> VictoryRoad_1F (6, 17) [wild]", + "19.04b walk east 1 (to wall) -> VictoryRoad_1F (7, 17) [wild]", + "19.04b walk north 6 (to wall) -> VictoryRoad_1F (7, 11) [wild]", + "19.04b walk east 3 (to wall) -> VictoryRoad_1F (10, 11) [wild]", + "19.04b walk south 4 (to wall) -> VictoryRoad_1F (10, 15) [wild]", + "19.04b walk east 5 (to wall) -> VictoryRoad_1F (15, 15) [wild]", + "19.04b walk north 10 (to wall) -> VictoryRoad_1F (15, 5) [wild]", + "19.04b walk west 5 -> VictoryRoad_1F (10, 5) [wild]", + "19.04b walk south 5 (to wall) -> VictoryRoad_1F (10, 10) [wild]", + "19.04b walk west 5 (to wall) -> VictoryRoad_1F (5, 10) [wild]", + "19.04b walk north 3 -> VictoryRoad_1F (5, 7) [wild]", + "19.04b walk west 1 -> VictoryRoad_1F (4, 7) [wild]", + "19.04b face north -> VictoryRoad_1F (4, 7)", + "19.04b ladder_2f from VictoryRoad_1F (4, 7) facing north to VictoryRoad_2F (1, 9)", + "19.04b walk north 5 (to wall) -> VictoryRoad_1F (4, 2) [wild]", + "19.04b walk west 1 (warp) -> VictoryRoad_2F (1, 9)", + "19.04c behind_boulder_1 from VictoryRoad_2F (1, 9) facing west to VictoryRoad_2F (7, 17)", + "19.04c walk south 1 (to wall) -> VictoryRoad_2F (1, 10) [wild]", + "19.04c walk east 5 (to wall) -> VictoryRoad_2F (6, 10) [wild]", + "19.04c walk south 6 -> VictoryRoad_2F (6, 16) [wild]", + "19.04c walk east 6 (to wall) -> VictoryRoad_2F (12, 16) [wild]", + "19.04c walk south 1 (to wall) -> VictoryRoad_2F (12, 17) [wild]", + "19.04c walk west 5 -> VictoryRoad_2F (7, 17) [wild]", + "19.04c by_boulder_2_corner from VictoryRoad_2F (5, 17) facing west to VictoryRoad_2F (5, 16)", + "19.04c walk north 1 -> VictoryRoad_2F (5, 16) [wild]", + "19.04c behind_boulder_2 from VictoryRoad_2F (5, 16) facing north to VictoryRoad_2F (4, 16)", + "19.04c walk west 1 -> VictoryRoad_2F (4, 16) [wild]", + "19.04c by_boulder_3_corner from VictoryRoad_2F (4, 18) facing south to VictoryRoad_2F (5, 18)", + "19.04c walk east 1 -> VictoryRoad_2F (5, 18) [wild]", + "19.04c behind_boulder_3 from VictoryRoad_2F (5, 18) facing east to VictoryRoad_2F (5, 19)", + "19.04c walk south 1 (to wall) -> VictoryRoad_2F (5, 19) [wild]", + "19.04c ladder_3f from VictoryRoad_2F (3, 19) facing west to VictoryRoad_3F (5, 2)", + "19.04c walk east 2 (to wall) -> VictoryRoad_2F (5, 19) [wild]", + "19.04c walk north 6 -> VictoryRoad_2F (5, 13) [wild]", + "19.04c walk east 4 -> VictoryRoad_2F (9, 13) [wild]", + "19.04c walk north 3 (to wall) -> VictoryRoad_2F (9, 10) [wild]", + "19.04c walk east 13 (to wall) -> VictoryRoad_2F (22, 10) [wild]", + "19.04c walk south 7 (to wall) -> VictoryRoad_2F (22, 17) [wild]", + "19.04c walk east 9 -> VictoryRoad_2F (31, 17) [wild]", + "19.04c walk south 3 (to wall) -> VictoryRoad_2F (31, 20) [wild]", + "19.04c walk east 11 (to wall) -> VictoryRoad_2F (42, 20) [wild]", + "19.04c walk north 4 (to wall) -> VictoryRoad_2F (42, 16) [wild]", + "19.04c walk west 2 (to wall) -> VictoryRoad_2F (40, 16) [wild]", + "19.04c walk north 2 (to wall) -> VictoryRoad_2F (40, 14) [wild]", + "19.04c walk west 6 -> VictoryRoad_2F (34, 14) [wild]", + "19.04c walk north 5 (warp) -> VictoryRoad_3F (34, 9) [wild]", + "19.04c walk north 7 (to wall) -> VictoryRoad_3F (34, 2) [wild]", + "19.04c walk west 24 (to wall) -> VictoryRoad_3F (10, 2) [wild]", + "19.04c walk south 2 -> VictoryRoad_3F (10, 4) [wild]", + "19.04c walk west 5 (to wall) -> VictoryRoad_3F (5, 4) [wild]", + "19.04c walk north 2 (warp) -> VictoryRoad_2F (3, 3) [wild]", + "19.04c walk south 2 (to wall) -> VictoryRoad_2F (3, 5) [wild]", + "19.04c walk north 2 (warp) -> VictoryRoad_3F (5, 2) [wild]", + "19.04c behind_boulder_4 from VictoryRoad_3F (5, 2) facing north to VictoryRoad_3F (32, 6)", + "19.04c walk east 1 (to wall) -> VictoryRoad_3F (6, 2) [wild]", + "19.04c walk south 5 (to wall) -> VictoryRoad_3F (6, 7) [wild]", + "19.04c walk east 1 (to wall) -> VictoryRoad_3F (7, 7)", + "19.04c walk north 1 (to wall) -> VictoryRoad_3F (7, 6) [wild]", + "19.04c walk east 1 (to wall) -> VictoryRoad_3F (8, 6) [wild]", + "19.04c walk north 2 (to wall) -> VictoryRoad_3F (8, 4) [wild]", + "19.04c walk east 4 (to wall) -> VictoryRoad_3F (12, 4) [wild]", + "19.04c walk north 2 (to wall) -> VictoryRoad_3F (12, 2) [wild]", + "19.04c walk east 19 -> VictoryRoad_3F (31, 2) [wild]", + "19.04c walk south 4 -> VictoryRoad_3F (31, 6) [wild]", + "19.04c walk east 1 -> VictoryRoad_3F (32, 6) [wild]", + "19.04c by_boulder_5_corner from VictoryRoad_3F (32, 4) facing north to VictoryRoad_3F (33, 4)", + "19.04c walk east 1 -> VictoryRoad_3F (33, 4) [wild]", + "19.04c behind_boulder_5 from VictoryRoad_3F (33, 4) facing east to VictoryRoad_3F (33, 3)", + "19.04c walk north 1 -> VictoryRoad_3F (33, 3) [wild]", + "19.04c by_boulder_6_corner from VictoryRoad_3F (12, 3) facing west to VictoryRoad_3F (12, 2)", + "19.04c walk north 1 (to wall) -> VictoryRoad_3F (12, 2) [wild]", + "19.04c behind_boulder_6 from VictoryRoad_3F (12, 2) facing north to VictoryRoad_3F (11, 2)", + "19.04c walk west 1 -> VictoryRoad_3F (11, 2) [wild]", + "19.04c by_boulder_7_corner from VictoryRoad_3F (11, 3) facing south to VictoryRoad_3F (12, 3)", + "19.04c walk east 1 -> VictoryRoad_3F (12, 3) [wild]", + "19.04c behind_boulder_7 from VictoryRoad_3F (12, 3) facing east to VictoryRoad_3F (12, 4)", + "19.04c walk south 1 -> VictoryRoad_3F (12, 4) [wild]", + "19.04c by_boulder_8_corner from VictoryRoad_3F (7, 4) facing west to VictoryRoad_3F (7, 3)", + "19.04c walk north 1 (to wall) -> VictoryRoad_3F (7, 3) [wild]", + "19.04c behind_boulder_8 from VictoryRoad_3F (7, 3) facing north to VictoryRoad_3F (6, 3)", + "19.04c walk west 1 -> VictoryRoad_3F (6, 3) [wild]", + "19.04c by_boulder_9_corner from VictoryRoad_3F (6, 6) facing south to VictoryRoad_3F (5, 6)", + "19.04c walk west 1 -> VictoryRoad_3F (5, 6) [wild]", + "19.04c behind_boulder_9 from VictoryRoad_3F (5, 6) facing west to VictoryRoad_3F (5, 7)", + "19.04c walk south 1 -> VictoryRoad_3F (5, 7) [wild]", + "19.04d hole_way_1 from VictoryRoad_3F (6, 7) facing east to VictoryRoad_3F (6, 6)", + "19.04d walk north 1 -> VictoryRoad_3F (6, 6) [wild]", + "19.04d hole_way_2 from VictoryRoad_3F (6, 6) facing north to VictoryRoad_3F (25, 8)", + "19.04d walk east 2 (to wall) -> VictoryRoad_3F (8, 6) [wild]", + "19.04d walk north 2 (to wall) -> VictoryRoad_3F (8, 4) [wild]", + "19.04d walk east 4 (to wall) -> VictoryRoad_3F (12, 4) [wild]", + "19.04d walk north 2 (to wall) -> VictoryRoad_3F (12, 2) [wild]", + "19.04d walk east 17 -> VictoryRoad_3F (29, 2) [wild]", + "19.04d walk south 6 -> VictoryRoad_3F (29, 8) [wild]", + "19.04d walk west 4 -> VictoryRoad_3F (25, 8) [wild]", + "19.04d hole_way_3 from VictoryRoad_3F (25, 8) facing west to VictoryRoad_3F (25, 6)", + "19.04d walk north 2 -> VictoryRoad_3F (25, 6) [wild]", + "19.04d hole_way_4 from VictoryRoad_3F (25, 6) facing north to VictoryRoad_3F (16, 6)", + "19.04d walk west 9 -> VictoryRoad_3F (16, 6) [wild]", + "19.04d hole_way_5 from VictoryRoad_3F (16, 6) facing west to VictoryRoad_3F (16, 13)", + "19.04d walk south 7 (to wall) -> VictoryRoad_3F (16, 13) [wild]", + "19.04d hole_way_6 from VictoryRoad_3F (16, 13) facing south to VictoryRoad_3F (11, 13)", + "19.04d walk west 5 -> VictoryRoad_3F (11, 13) [wild]", + "19.04d hole_way_7 from VictoryRoad_3F (11, 13) facing west to VictoryRoad_3F (4, 14)", + "19.04d walk west 2 (to wall) -> VictoryRoad_3F (9, 13) [wild]", + "19.04d walk north 4 (to wall) -> VictoryRoad_3F (9, 9) [wild]", + "19.04d walk west 5 -> VictoryRoad_3F (4, 9) [wild]", + "19.04d walk south 5 -> VictoryRoad_3F (4, 14) [wild]", + "19.04d hole_way_8 from VictoryRoad_3F (4, 14) facing south to VictoryRoad_3F (17, 15)", + "19.04d walk south 1 -> VictoryRoad_3F (4, 15) [wild]", + "19.04d walk east 13 (to wall) -> VictoryRoad_3F (17, 15) [wild]", + "19.04d hole_way_9 from VictoryRoad_3F (17, 15) facing east to VictoryRoad_3F (17, 19)", + "19.04d walk south 4 (to wall) -> VictoryRoad_3F (17, 19) [wild]", + "19.04d behind_hole_boulder from VictoryRoad_3F (17, 19) facing south to VictoryRoad_3F (32, 18)", + "19.04d walk east 15 -> VictoryRoad_3F (32, 19) [wild]", + "19.04d walk north 1 -> VictoryRoad_3F (32, 18) [wild]", + "19.04d drop_to_2f from VictoryRoad_3F (33, 18) facing east to VictoryRoad_2F (34, 19)", + "19.04d walk east 1 (warp) -> VictoryRoad_2F (34, 19) [wild]", + "19.04d exit_way_1 from VictoryRoad_2F (15, 19) facing west to VictoryRoad_2F (31, 19)", + "19.04d walk east 16 -> VictoryRoad_2F (31, 19) [wild]", + "19.04d exit_way_2 from VictoryRoad_2F (31, 19) facing east to VictoryRoad_2F (35, 17)", + "19.04d walk north 2 -> VictoryRoad_2F (31, 17) [wild]", + "19.04d walk east 4 -> VictoryRoad_2F (35, 17) [wild]", + "19.04d above_exit from VictoryRoad_2F (35, 17) facing east to VictoryRoad_2F (48, 11) facing south", + "19.04d walk east 1 (warp) -> VictoryRoad_3F (39, 17)", + "19.04d walk east 1 (to wall) -> VictoryRoad_3F (40, 17) [wild]", + "19.04d walk north 7 -> VictoryRoad_3F (40, 10) [wild]", + "19.04d walk west 3 (warp) -> VictoryRoad_2F (38, 9) [wild]", + "19.04d walk south 2 -> VictoryRoad_2F (38, 11) [wild]", + "19.04d walk east 10 (to wall) -> VictoryRoad_2F (48, 11) [wild]", + "19.04d face south -> VictoryRoad_2F (48, 11)", + "19.05 indigo_door from Route23 (18, 29) facing south to IndigoPlateau_Exterior (11, 7) facing north", + "19.05 walk east 3 (to wall) -> Route23 (21, 29)", + "19.05 walk north 11 -> Route23 (21, 18)", "19.05 walk west 7 -> Route23 (14, 18)", "19.05 walk north 13 (to wall) -> Route23 (14, 5)", "19.05 walk east 1 (to wall) -> Route23 (15, 5)", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index 7c9d6cb4bb..e2bde33e90 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -226,11 +226,12 @@ Pokemon::StoryAction StoryMapsSim::action(StoryActionId id){ }); case StoryActionId::SHOP: return played([this](const StoryStep& step, RunState&){ return shop(step); }); + // A push leaves the player behind the boulder, a switch on if it lands on one. + case StoryActionId::PUSH_BOULDER: + return played([this](const StoryStep& step, RunState& state){ return boulder_pushed(state, step, maps()); }); // Pacing leaves the player on either of its tiles, as on the console. case StoryActionId::CLOSE_TRAINER_CARD: case StoryActionId::LEAVE_GIFT_SUMMARY: - case StoryActionId::PUSH_BOULDER: - return played([this](const StoryStep& step, RunState& state){ return boulder_pushed(state, step, maps()); }); case StoryActionId::CUT_TREE: case StoryActionId::TRASH_CANS: case StoryActionId::GAME: diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp index 1bdf311e59..69656167e6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRunPlan_Tests.cpp @@ -145,7 +145,7 @@ class Test_RunPlan : public UnitTest{ const RunPlanScenario m_scenario; }; -const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.05"; +const std::string TODAY = "01.01 01.03 01.04 01.05 02.01 02.02 02.03 03.01 03.02 03.03 04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.04b 19.04c 19.04d 19.05"; const RunPlanScenario RUN_PLAN_CASES[] = { { @@ -236,11 +236,11 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Gift RNG off: 04.03 is passed over", .first = "04.01"}, - .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.05"}, + .expectation = {.expected_ids = "04.01 04.02 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.04b 19.04c 19.04d 19.05"}, }, { .input = {.name = "Gift RNG off: 04.03 runs when started at", .first = "04.03"}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.05"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.04b 19.04c 19.04d 19.05"}, }, { .input = { .name = "Gift RNG: started at 04.03, from the save beside the salesman", @@ -279,7 +279,7 @@ const RunPlanScenario RUN_PLAN_CASES[] = { }, { .input = {.name = "Starter RNG alone: 04.03 runs when started at", .first = "04.03", .handoffs = {.starter_rng = true}}, - .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.05"}, + .expectation = {.expected_ids = "04.03 04.04 04.05 04.06 05.01 05.02 05.03 05.04 05.05 05.06 05.07 05.08 05.09 05.10 06.01 06.02 06.03 06.04 07.01 07.02 08.01 08.02 08.03 09.01 09.02 09.03 10.01 10.02 10.03 10.04 10.05 10.06 11.01 11.02 11.03 12.01 12.02 12.02b 12.03 13.01 13.02 13.03 13.04 14.01 14.02 14.02b 14.03 14.04 14.04b 15.01 16.01 17.02 17.03 17.04 17.04b 19.01a 19.01 19.02 19.03 19.04 19.04b 19.04c 19.04d 19.05"}, }, { .input = { .name = "Starter RNG first, with both on", diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp index 31559b05e1..ebf6f1e31d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryTable.cpp @@ -237,7 +237,7 @@ constexpr std::string_view STORY_ORDER[] = { "12.01", "12.02", "12.02b", "12.03", "13.01", "13.02", "13.03", "13.04", "14.01", "14.02", "14.02b", "14.03", "14.04", "14.04b", "15.01", "16.01", - "17.02", "17.03", "17.04", "17.04b", "19.01a", "19.01", "19.02", "19.03", "19.04", "19.05", + "17.02", "17.03", "17.04", "17.04b", "19.01a", "19.01", "19.02", "19.03", "19.04", "19.04b", "19.04c", "19.04d", "19.05", }; // `checkpoints` in STORY_ORDER's order. Throws ParseException for a diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h index 5e4f1ef1fa..3ba3dbe560 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryUnauthoredStarts_Tests.h @@ -21,12 +21,11 @@ namespace PokemonFRLG{ // the story's order (STORY_ORDER in PokemonFRLG_AutoStoryTable.cpp) ends. // 17.02 starts at Saffron's Center nurse, where no row before it in the // order ends (Silph Co.'s 16.01 ends on a pad on 5F; the rest of Silph Co. -// and Sabrina are not authored). 19.05 starts at Victory Road's second-floor exit, after the -// cave's floors, whose boulder puzzles are not authored (19.04). 14.01 starts outside the Pokemon Mansion, +// and Sabrina are not authored). 14.01 starts outside the Pokemon Mansion, // after its Escape Rope (13.04), which is not authored. An id leaves this // list once the rows before it are in. inline bool starts_after_unauthored_rows(std::string_view id){ - return id == "17.02" || id == "14.01" || id == "19.05"; + return id == "17.02" || id == "14.01"; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp index ac2fa55d56..78d1a96762 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp @@ -17,6 +17,7 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_StoryPostconditionCheck.h" #include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.h" @@ -270,6 +271,67 @@ UnitTestResult test_strength_teach_and_cave_mouth(){ return true; } +// A Victory Road floor's row on the sim from its start_gates, its boulder +// pushes included: it starts where `previous` ends, turns on the switch +// `switch_key`, meets no trainer, breaks no rule and ends on `end`. +UnitTestResult cave_floor(std::string_view previous, std::string_view id, std::string_view switch_key, const MapPosition& end){ + const StoryCheckpoint& before = checkpoint(previous); + const StoryCheckpoint& row = checkpoint(id); + const StoryPose at_start = *story_pose(Pokemon::pose_of(*row.start)); + const std::optional before_pose = Pokemon::checkpoint_end_pose(before); + const std::optional before_end = before_pose ? story_pose(Pokemon::pose_of(*before_pose)) : std::nullopt; + if (!before_end || before_end->map != at_start.map || !(before_end->tile == at_start.tile)){ + return std::format("{} doesn't start where {} ends.", id, previous); + } + StoryPose at = at_start; + SimScript script; + script.gates = row.start_gates.value_or(Pokemon::GateState()); + OverworldSim sim(story_maps(), MapPosition{at.map, at.tile}, at.facing.value_or(Direction::NORTH), script); + for (const StoryStep& step : row.steps){ + const bool push = step.kind == StoryStepKind::GAME && step.action == PUSH_BOULDER_VARIANT; + if (!push && step.kind != StoryStepKind::ROUTE && step.kind != StoryStepKind::LEGS && step.kind != StoryStepKind::STEP){ + continue; + } + if (const std::string failure = row_step_on_sim(sim, at, step, row.id); !failure.empty()){ + std::string log; for (size_t c = sim.state().log.size() > 25 ? sim.state().log.size() - 25 : 0; c < sim.state().log.size(); c++){ log += "\n " + sim.state().log[c]; } return std::format("{} {}: ended on {}; {}{}", id, step.name, to_string(sim.state().position), failure, log); + } + if (!sim.state().violations.empty()){ + return std::format("{} {}: broke a rule on {}: {}", id, step.name, to_string(sim.state().position), sim.state().violations.front()); + } + if (!sim.state().trainers_beaten.empty()){ + return std::format("{} {}: met a trainer: {}", id, step.name, sim.state().trainers_beaten.front()); + } + } + if (!sim.state().gates.switch_on(std::string(switch_key))){ + return std::format("{}: the switch {} is not on.", id, switch_key); + } + if (!(sim.state().position == end)){ + return std::format("{}: ended on {}, not {}.", id, to_string(sim.state().position), to_string(end)); + } + if (!sim.state().trainers_beaten.empty() || !sim.state().violations.empty()){ + return std::format("{}: met a trainer or broke a rule on the way.", id); + } + return true; +} + +// 19.04b: 1F's boulder from (7, 18) onto the switch (20, 16), the barrier +// open, up the ladder to 2F. +UnitTestResult test_victory_road_1f(){ + return cave_floor("19.04", "19.04b", "VictoryRoad_1F/floor_switch_1", MapPosition{"VictoryRoad_2F", {1, 9}}); +} + +// 19.04c: 2F's west boulder onto the switch (2, 19), then up to 3F and its +// north boulder onto the switch (7, 7). +UnitTestResult test_victory_road_2f_3f(){ + return cave_floor("19.04b", "19.04c", "VictoryRoad_3F/floor_switch_1", MapPosition{"VictoryRoad_3F", {6, 7}}); +} + +// 19.04d: 3F's boulder down the hole, after it to 2F, onto 2F's second +// switch (14, 19), then the exit to Route 23, a tile below its mouth (18, 29), where 19.05 starts. +UnitTestResult test_victory_road_hole_and_exit(){ + return cave_floor("19.04c", "19.04d", "VictoryRoad_2F/floor_switch_2", MapPosition{"Route23", {18, 29}}); +} + // 19.05: from Victory Road's exit on Route 23 to the nurse's counter. UnitTestResult test_indigo_center_walk(){ const StoryCheckpoint& row = checkpoint("19.05"); @@ -306,6 +368,18 @@ const AutoStoryVictoryRoadCase AUTO_STORY_VICTORY_ROAD_CASES[] = { .input = {.name = "19.04 Strength over Water Pulse, into the cave", .body = test_strength_teach_and_cave_mouth}, .expectation = {.description = "keep surf, bite, blizzard; Victory Road 1F (11, 20)"}, }, + { + .input = {.name = "19.04b Victory Road 1F's boulder switch, up to 2F", .body = test_victory_road_1f}, + .expectation = {.description = "1F's switch on, 2F (1, 9), no trainer met"}, + }, + { + .input = {.name = "19.04c Victory Road 2F's and 3F's boulder switches", .body = test_victory_road_2f_3f}, + .expectation = {.description = "3F's switch on, 3F (6, 7), no trainer met"}, + }, + { + .input = {.name = "19.04d Victory Road 3F's hole, 2F's second switch, out to Route 23", .body = test_victory_road_hole_and_exit}, + .expectation = {.description = "2F's east switch on, Route 23 (18, 29), no trainer met"}, + }, { .input = {.name = "19.05 Indigo Plateau's Center", .body = test_indigo_center_walk}, .expectation = {.description = "Indigo Plateau Center (13, 12)"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp index 9488755fec..0e6dd7dd70 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStory_Tests.cpp @@ -352,8 +352,8 @@ UnitTestResult check_checkpoint(const StoryCheckpoint& checkpoint, StoryPose& po // start: starts_after_unauthored_rows()), and adds the plans to `golden`. UnitTestResult chain_story_routes(std::vector& golden){ const std::vector& checkpoints = story_checkpoints(); - if (checkpoints.size() != 76 || checkpoints[0].start){ - return "Expected 76 checkpoints, the first from a new game."; + if (checkpoints.size() != 79 || checkpoints[0].start){ + return "Expected 79 checkpoints, the first from a new game."; } StoryPose pose; walk_state() = WalkGates{}; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04.plan.json index 330d22ae1d..6419b15000 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04.plan.json @@ -32,7 +32,7 @@ "notes": { "checkpoint": [ "Starts below Victory Road's mouth, where 19.03 ends. Strength is taught here, at the cave's start, because every floor's boulders need it (pokeguy teaches it over Water Pulse at Victory Road, 1:43:24 on his video: the 12.02 note that pointed at 19.02, D3 meant this row).", - "Ends on Victory Road 1F's south end (11, 20). The boulder puzzles of the three floors are not authored: the maps have the boulders as objects but not the switches' barriers (1F (12, 14) and (12, 15); 2F (13, 10) and (13, 11), (33, 16) and (33, 17); 3F (12, 12) and (12, 13)) nor which tiles the switches press (1F (20, 16); 2F (2, 19), (14, 19); 3F (7, 7)), so the planner would walk through them. Pokemon_BoulderSolver in PokemonFRLG_AutoStoryBoulders_Tests.cpp holds the data and the search; the barriers need the user's map edit (TODO)." + "Ends on Victory Road 1F's south end (11, 20), where 19.04b, the first of the cave's boulder rows, starts." ] } }, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04b.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04b.plan.json new file mode 100644 index 0000000000..2ab0158fbb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04b.plan.json @@ -0,0 +1,196 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "19.04b", + "title": "Victory Road 1F: the boulder onto the floor switch, up to 2F", + "start": {"map": "VictoryRoad_1F", "tiles": [[11, 20]], "facing": "north"}, + "events": [ + { + "id": "behind_boulder_1", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[7, 17]]}}, + "why": "north of the south boulder (7, 18), the one that reaches the switch" + }, + { + "id": "push_south", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "south", "tiles": 1, "activate": true}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[7, 18]], "facing": "south"}, + "why": "Strength on (A, YES), the boulder down to (7, 19), the row it runs east along" + }, + { + "id": "by_boulder_2_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[6, 18]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_2", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[6, 19]]}}, + "why": "round to its west side" + }, + { + "id": "push_east_row19", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "east", "tiles": 5}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[11, 19]], "facing": "east"}, + "why": "east along row 19 to (12, 19), below the gap north" + }, + { + "id": "by_boulder_3_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[10, 20]]}}, + "why": "round the pushed boulder to (10, 20), so the step onto the cave mouth (11, 20) is eastward: south onto it would take its warp out to Route 23" + }, + { + "id": "behind_boulder_3", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[12, 20]]}}, + "why": "below it, by the cave's mouth" + }, + { + "id": "push_north_col12", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "north", "tiles": 2}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[12, 18]], "facing": "north"}, + "why": "north to (12, 17), the corridor east to the switch" + }, + { + "id": "by_boulder_4_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[11, 18]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_4", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[11, 17]]}}, + "why": "west of it" + }, + { + "id": "push_east_row17", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "east", "tiles": 7}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[18, 17]], "facing": "east"}, + "why": "east along row 17 to (19, 17)" + }, + { + "id": "by_boulder_5_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[18, 18]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_5", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[19, 18]]}}, + "why": "below it" + }, + { + "id": "push_north_col19", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "north", "tiles": 2}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[19, 16]], "facing": "north"}, + "why": "north to (19, 15), level with the switch's column" + }, + { + "id": "by_boulder_6_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[20, 14]]}}, + "why": "round the pushed boulder, now on (19, 15), over the switch's column (20, 16) to (20, 14): the maps still show it where it started, and the planner would walk through its new tile" + }, + { + "id": "by_boulder_6_top", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[18, 14]]}}, + "why": "west along row 14, above the boulder, to above its west side" + }, + { + "id": "behind_boulder_6", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[18, 15]]}}, + "why": "west of it" + }, + { + "id": "push_east_col20", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "east", "tiles": 1}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[19, 15]], "facing": "east"}, + "why": "east to (20, 15), above the switch" + }, + { + "id": "by_boulder_7_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[19, 14]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_7", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[20, 14]]}}, + "why": "above it" + }, + { + "id": "push_onto_switch", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "south", "tiles": 1}, + "declared_after": {"map": "VictoryRoad_1F", "tiles": [[20, 15]], "facing": "south"}, + "why": "onto the switch (20, 16): VAR_MAP_SCENE_VICTORY_ROAD_1F is set and the barrier (12, 14), (12, 15) opens for good", + "gates_after": {"switches": {"VictoryRoad_1F/floor_switch_1": true}} + }, + { + "id": "below_ladder", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_1F", "tiles": [[4, 7]], "facing": "north"}}, + "why": "through the opened barrier, over the platform and round to column 4 below the ladder: column 5 is in Rolando's sight (the cooltrainer at (5, 2), facing south, sight 4)" + }, + { + "id": "ladder_2f", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[1, 9]]}}, + "why": "north up column 4, past Rolando's line, and west onto the ladder (3, 2), which leads to 2F's (1, 9)" + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "checkpoint": [ + "Starts on Victory Road 1F's south end (11, 20), where 19.04 ends; Strength is HM04 on the lead (19.04).", + "The pushes are the boulder solver's (PokemonFRLG_AutoStoryBoulders_Tests.cpp) for the switch (20, 16), from the map's boulders (pokefirered data/maps/VictoryRoad_1F/map.json) and PokemonSimulation's floor switch and barrier (VAR_MAP_SCENE_VICTORY_ROAD_1F, one-way). Strength stays on until the player leaves the map, so only the first push asks.", + "Ends on Victory Road 2F (1, 9), the foot of 1F's ladder." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": {"map": "VictoryRoad_2F", "tiles": [[1, 9]]} + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04c.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04c.plan.json new file mode 100644 index 0000000000..3cc87410b5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04c.plan.json @@ -0,0 +1,220 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "19.04c", + "title": "Victory Road 2F and 3F: the west boulder and the north boulder onto their switches", + "start": {"map": "VictoryRoad_2F", "tiles": [[1, 9]]}, + "events": [ + { + "id": "behind_boulder_1", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[7, 17]]}}, + "why": "east of the west boulder (6, 17)" + }, + { + "id": "push_west", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "west", "tiles": 2, "activate": true}, + "declared_after": {"map": "VictoryRoad_2F", "tiles": [[5, 17]], "facing": "west"}, + "why": "Strength on again (a new map), the boulder west to (4, 17)" + }, + { + "id": "by_boulder_2_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[5, 16]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_2", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[4, 16]]}}, + "why": "above it" + }, + { + "id": "push_south", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "south", "tiles": 2}, + "declared_after": {"map": "VictoryRoad_2F", "tiles": [[4, 18]], "facing": "south"}, + "why": "south to (4, 19), the switch's row" + }, + { + "id": "by_boulder_3_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[5, 18]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_3", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[5, 19]]}}, + "why": "east of it" + }, + { + "id": "push_onto_2f_switch", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "west", "tiles": 2}, + "declared_after": {"map": "VictoryRoad_2F", "tiles": [[3, 19]], "facing": "west"}, + "why": "onto the switch (2, 19): VAR_MAP_SCENE_VICTORY_ROAD_2F_BOULDER1 is set and the barrier (13, 10), (13, 11) opens for good", + "gates_after": {"switches": {"VictoryRoad_2F/floor_switch_1": true}} + }, + { + "id": "ladder_3f", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[5, 2]]}}, + "why": "to the ladder (3, 3), which leads to 3F's (5, 2)" + }, + { + "id": "behind_boulder_4", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[32, 6]]}}, + "why": "east along 3F's north side to below the north boulder (32, 5)" + }, + { + "id": "push_north", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "north", "tiles": 2, "activate": true}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[32, 4]], "facing": "north"}, + "why": "Strength on (3F is a new map), the boulder up to (32, 3), the row west" + }, + { + "id": "by_boulder_5_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[33, 4]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_5", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[33, 3]]}}, + "why": "east of it" + }, + { + "id": "push_west_row3", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "west", "tiles": 21}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[12, 3]], "facing": "west"}, + "why": "west along row 3 to (12, 3)" + }, + { + "id": "by_boulder_6_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[12, 2]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_6", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[11, 2]]}}, + "why": "above it, now on (11, 3)" + }, + { + "id": "push_south_col11", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "south", "tiles": 1}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[11, 3]], "facing": "south"}, + "why": "down to (11, 4), the row west to the switch" + }, + { + "id": "by_boulder_7_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[12, 3]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_7", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[12, 4]]}}, + "why": "east of it" + }, + { + "id": "push_west_row4", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "west", "tiles": 5}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[7, 4]], "facing": "west"}, + "why": "west along row 4 to (6, 4)" + }, + { + "id": "by_boulder_8_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[7, 3]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_8", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[6, 3]]}}, + "why": "above it" + }, + { + "id": "push_south_col6", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "south", "tiles": 3}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[6, 6]], "facing": "south"}, + "why": "down to (6, 7), beside the switch" + }, + { + "id": "by_boulder_9_corner", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[5, 6]]}}, + "why": "round the pushed boulder, which the maps still show where it started: the planner would walk through its new tile" + }, + { + "id": "behind_boulder_9", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[5, 7]]}}, + "why": "west of it" + }, + { + "id": "push_onto_3f_switch", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "east", "tiles": 1}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[6, 7]], "facing": "east"}, + "why": "onto the switch (7, 7): VAR_MAP_SCENE_VICTORY_ROAD_3F is set and the barrier (12, 12), (12, 13) opens for good", + "gates_after": {"switches": {"VictoryRoad_3F/floor_switch_1": true}} + } + ] + }, + "execution": { + "menu": "full", + "notes": { + "checkpoint": [ + "Starts on Victory Road 2F (1, 9), where 19.04b ends.", + "Two floor switches, each the boulder solver's pushes (PokemonFRLG_AutoStoryBoulders_Tests.cpp) on the decomp's maps: 2F's (2, 19) with the boulder at (6, 17), then, up the ladder (3, 3), 3F's (7, 7) with the boulder at (32, 5). Strength asks again on each new map.", + "Ends on 3F (6, 7), beside the pressed switch; 3F's barrier is open, the way to its hole (34, 18)." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": {"map": "VictoryRoad_3F", "tiles": [[6, 7]], "facing": "east"} + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04d.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04d.plan.json new file mode 100644 index 0000000000..40ad9b42bb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.04d.plan.json @@ -0,0 +1,157 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "frlg", + "checkpoint": { + "id": "19.04d", + "title": "Victory Road 3F's hole: a boulder down to 2F, onto its switch, out to Route 23", + "start": {"map": "VictoryRoad_3F", "tiles": [[6, 7]], "facing": "east"}, + "events": [ + { + "id": "hole_way_1", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[6, 6]]}}, + "why": "north off the pressed switch: the maps still show its button bare, and the planner would step onto the boulder at (7, 7)" + }, + { + "id": "hole_way_2", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[25, 8]]}}, + "why": "east along 3F's north side and down to (25, 8), below the gap (25, 7) onto the platform" + }, + { + "id": "hole_way_3", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[25, 6]]}}, + "why": "up through the gap onto the platform's second row: (25, 5) is in Alexa's line (the cooltrainer at (21, 5), facing east, sight 4)" + }, + { + "id": "hole_way_4", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[16, 6]]}}, + "why": "west along row 6, below Alexa, to the platform's west end" + }, + { + "id": "hole_way_5", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[16, 13]]}}, + "why": "down the column x 16 to the barrier's row" + }, + { + "id": "hole_way_6", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[11, 13]]}}, + "why": "west through the opened barrier (12, 13)" + }, + { + "id": "hole_way_7", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[4, 14]]}}, + "why": "round the west room to (4, 14), the way down to the south room" + }, + { + "id": "hole_way_8", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[17, 15]]}}, + "why": "east along row 15, north of Caroline's line (the cooltrainer at (11, 16), facing east, sight 5) and Colby's (the cooltrainer at (10, 17), facing west, sight 5)" + }, + { + "id": "hole_way_9", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[17, 19]]}}, + "why": "down x 17, east of Caroline's line, to the south room's bottom row" + }, + { + "id": "behind_hole_boulder", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_3F", "tiles": [[32, 18]]}}, + "why": "east along row 19 to below, then west of, the boulder (33, 18) beside the hole" + }, + { + "id": "push_into_hole", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "east", "tiles": 1, "activate": true}, + "declared_after": {"map": "VictoryRoad_3F", "tiles": [[33, 18]], "facing": "east"}, + "why": "Strength on (the map was left for the save), the boulder into the hole (34, 18); it falls to 2F (33, 19), where the game now shows it (FLAG_HIDE_VICTORY_ROAD_2F_BOULDER cleared)" + }, + { + "id": "drop_to_2f", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[34, 19]]}}, + "why": "east onto the hole (34, 18), down to 2F's (34, 19), east of the fallen boulder; a route, so the fade is waited out before the next press" + }, + { + "id": "push_west_row19", + "kind": "game_action", + "action": "push_boulder", + "args": {"direction": "west", "tiles": 19, "activate": true}, + "declared_after": {"map": "VictoryRoad_2F", "tiles": [[15, 19]], "facing": "west"}, + "why": "Strength on (a new map), the boulder west along row 19 to the switch (14, 19): VAR_MAP_SCENE_VICTORY_ROAD_2F_BOULDER2 is set and the barrier (33, 16), (33, 17) opens for good", + "gates_after": {"switches": {"VictoryRoad_2F/floor_switch_2": true}} + }, + { + "id": "exit_way_1", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[31, 19]]}}, + "why": "back east along row 19 to (31, 19), south of Daisuke's line (the black belt at (20, 11), looking south and west, sight 4)" + }, + { + "id": "exit_way_2", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[35, 17]]}}, + "why": "north by (31, 18) and east through the opened barrier (33, 17) to beside the ladder (36, 17), below Nelson (the rocker at (31, 16), facing west)" + }, + { + "id": "above_exit", + "kind": "route", + "action": "run", + "args": {"target": {"map": "VictoryRoad_2F", "tiles": [[48, 11]], "facing": "south"}}, + "why": "onto the ladder (36, 17), 3F's east corridor to its ladder (37, 10), down to 2F (38, 9) and east to above the exit (48, 12)" + }, + { + "id": "onto_exit", + "kind": "step", + "args": {"direction": "south"}, + "declared_after": {"map": "VictoryRoad_2F", "tiles": [[48, 12]], "facing": "south"}, + "why": "south onto the exit mat (48, 12), a warp taken by walking south on it" + }, + { + "id": "exit_route23", + "kind": "step", + "args": {"direction": "south"}, + "declared_after": {"map": "Route23", "tiles": [[18, 29]], "facing": "south"}, + "why": "south again on the mat: out of the cave mouth (18, 28), which the game walks the player off a tile, onto Route 23 (18, 29)" + } + ], + "start_gates": {"switches": {"VictoryRoad_3F/floor_switch_1": true}} + }, + "execution": { + "menu": "full", + "notes": { + "checkpoint": [ + "Starts on Victory Road 3F (6, 7), where 19.04c ends; 3F's switch is on (start_gates) and so its barrier is open.", + "3F's boulder (33, 18) pushed into the hole (34, 18) lands on 2F (33, 19); the player follows it down the hole and pushes it west onto 2F's second switch (14, 19), which opens the barrier (33, 16), (33, 17) before 2F's ladder (36, 17). The maps show 2F's boulder from the start; the game hides it until 3F's falls.", + "Ends on Route 23 (18, 29), facing south, a tile below the cave mouth, where 19.05 starts." + ] + } + }, + "metadata": { + "phase": "testing", + "postconditions": { + "position": {"map": "Route23", "tiles": [[18, 29]], "facing": "south"} + } + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.05.plan.json index 5e46ffceec..0c9ce04697 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/StoryData/frlg-19.05.plan.json @@ -4,7 +4,7 @@ "checkpoint": { "id": "19.05", "title": "Victory Road's exit to Indigo Plateau: heal at its Center", - "start": {"map": "Route23", "tiles": [[18, 28]], "facing": "south"}, + "start": {"map": "Route23", "tiles": [[18, 29]], "facing": "south"}, "events": [ { "id": "indigo_door", @@ -13,7 +13,7 @@ "args": { "target": {"map": "IndigoPlateau_Exterior", "tiles": [[11, 7]], "facing": "north"} }, - "why": "from Victory Road's second-floor exit (Route 23 (18, 28)) north along Route 23 to Indigo Plateau (its north connection) and up to below the Center's door (11, 6)" + "why": "from below Victory Road's second-floor exit (Route 23 (18, 29)) north along Route 23 to Indigo Plateau (its north connection) and up to below the Center's door (11, 6)" }, { "id": "indigo_nurse", @@ -35,7 +35,7 @@ "menu": "full", "notes": { "checkpoint": [ - "Starts on Route 23 (18, 28), where Victory Road 2F's exit (48, 12) leaves the player, facing south. Victory Road's floors are not authored (19.04's note), so this row's start is its own (starts_after_unauthored_rows()).", + "Starts on Route 23 (18, 29), facing south, where 19.04d ends: Victory Road 2F's exit (48, 12) lets out on the cave mouth (18, 28), and the game walks the player a tile off it.", "Ends at Indigo Plateau's nurse below the counter (13, 12): the save point of the League's door, where the first League row (Lorelei) starts." ] } From f50ce991078018ee32e3d775725b342da8760fd3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 02:26:42 -0800 Subject: [PATCH 19/20] FRLG boulders: boulder_pushed() in its own file, flatter land_fallen_boulder() Code health: PokemonFRLG_AutoStoryEvents.cpp back to its 1030 lines, and the sim's landing no longer nests six deep. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG_OverworldSimField.cpp | 47 ++++++++++--------- .../PokemonFRLG_AutoStoryBoulders.cpp | 45 ++++++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryBoulders.h | 34 ++++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 26 +--------- .../PokemonFRLG_AutoStoryPacedRoute.h | 7 --- .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 1 + ...PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 8 files changed, 108 insertions(+), 56 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.h diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp index 24fc75b2c6..5da96d0c67 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimField.cpp @@ -120,35 +120,36 @@ bool OverworldSim::cut_tree(){ return false; } +namespace{ + +// The map named `name` in `maps`, or nullptr. +template +auto* map_named_in(Maps& maps, const std::string& name){ + const auto found = std::find_if(maps.begin(), maps.end(), [&](const MapData& map){ return map.name == name; }); + return found == maps.end() ? nullptr : &*found; +} + +} // namespace + void OverworldSim::land_fallen_boulder(const MapPosition& hole){ - const MapData* from = nullptr; - for (const MapData& item : m_maps){ - if (item.name == hole.map){ - from = &item; - } - } + const MapData* from = map_named_in(m_maps, hole.map); const MapWarp* warp = from == nullptr ? nullptr : warp_at(*from, hole.point); if (warp == nullptr || !warp->to){ return; } static const std::vector ALL = overworld_maps(); - for (const MapData& below : ALL){ - if (below.name != warp->to->map){ - continue; - } - for (MapData& shown : m_maps){ - if (shown.name != below.name){ - continue; - } - for (const MapObject& object : below.objects){ - const bool hidden = object.name == "pushable_boulder" && object.hide_flag && std::none_of( - shown.objects.begin(), shown.objects.end(), [&](const MapObject& item){ return item.x == object.x && item.y == object.y; } - ); - if (hidden){ - shown.objects.push_back(object); - note("the boulder lands on " + to_string(MapPosition{shown.name, TilePos{object.x, object.y}}) + "."); - } - } + const MapData* below = map_named_in(ALL, warp->to->map); + MapData* shown = map_named_in(m_maps, warp->to->map); + if (below == nullptr || shown == nullptr){ + return; + } + for (const MapObject& object : below->objects){ + const bool hidden = object.name == "pushable_boulder" && object.hide_flag && std::none_of( + shown->objects.begin(), shown->objects.end(), [&](const MapObject& item){ return item.x == object.x && item.y == object.y; } + ); + if (hidden){ + shown->objects.push_back(object); + note("the boulder lands on " + to_string(MapPosition{shown->name, TilePos{object.x, object.y}}) + "."); } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.cpp new file mode 100644 index 0000000000..da8b987a4b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.cpp @@ -0,0 +1,45 @@ +/* AutoStory Boulders + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Pokemon/AutoStory/Pokemon_StoryActions.h" +#include "Pokemon/Navigation/Pokemon_GateTiles.h" +#include "PokemonFRLG_AutoStoryBoulders.h" +#include "PokemonFRLG_AutoStoryPoses.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +Pokemon::Outcome boulder_pushed(Pokemon::RunState& state, const StoryStep& step, const std::vector& maps){ + const std::optional here = story_pose(state.pose); + if (!here){ + return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); + } + const Direction direction = Pokemon::story_arg(step.args, "direction"); + const int64_t tiles = Pokemon::story_arg(step.args, "tiles"); + StoryPose at{here->map, here->tile, direction}; + for (int64_t c = 0; c < tiles; c++){ + at.tile = at.tile.next(direction); + } + // The boulder stands a tile ahead; on a floor switch's button, the + // switch is on for good and its barrier open. + const auto map = std::find_if(maps.begin(), maps.end(), [&](const MapData& item){ + return item.name == at.map; + }); + const Pokemon::MapSwitch* pressed = map == maps.end() ? nullptr : Pokemon::switch_with_button(*map, at.tile.next(direction)); + if (pressed != nullptr){ + state.gates.switches_on.insert(Pokemon::switch_key(*pressed)); + } + return Pokemon::outcome_ok(to_pose(at)); +} + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.h new file mode 100644 index 0000000000..b38ae15080 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.h @@ -0,0 +1,34 @@ +/* AutoStory Boulders + * + * From: https://github.com/PokemonAutomation/ + * + * What a Strength boulder push does to the story's state, for the + * console's push_boulder step and the map-level sim alike. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_AutoStoryBoulders_H +#define PokemonAutomation_PokemonFRLG_AutoStoryBoulders_H + +#include +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "Pokemon/AutoStory/Pokemon_StoryPose.h" +#include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" +#include "PokemonFRLG_AutoStoryCheckpoints.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// Where a PUSH_BOULDER_VARIANT step leaves the player: `tiles` tiles on in +// its direction, behind the boulder. A boulder that ends on a floor +// switch's button turns that switch on in `state.gates`. +Pokemon::Outcome boulder_pushed(Pokemon::RunState& state, const StoryStep& step, const std::vector& maps); + + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 886f137ed3..bbd3f63186 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -4,7 +4,6 @@ * */ -#include #include #include #include @@ -13,7 +12,6 @@ #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" -#include "Pokemon/Navigation/Pokemon_GateTiles.h" #include "Pokemon/Navigation/Pokemon_RouteLog.h" #include "VideoGames/PokemonFRLG/Inference/Dialogs/PokemonFRLG_DialogDetector.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldGatedRoute.h" @@ -29,6 +27,7 @@ #include "PokemonFRLG_AutoStoryEvents.h" #include "PokemonFRLG_AutoStoryGrind.h" #include "PokemonFRLG_AutoStoryBattlePolicy.h" +#include "PokemonFRLG_AutoStoryBoulders.h" #include "PokemonFRLG_AutoStoryGameArgs.h" #include "PokemonFRLG_AutoStoryHealingSteps.h" #include "PokemonFRLG_AutoStoryHideout.h" @@ -425,29 +424,6 @@ void add_start_pose_check( add_start_check(checkpoint, start, std::move(reader), std::move(log)); } -Outcome boulder_pushed(RunState& state, const StoryStep& step, const std::vector& maps){ - const std::optional here = story_pose(state.pose); - if (!here){ - return Pokemon::outcome_failed("no_pose", Pokemon::to_string(state.pose)); - } - const Direction direction = arg(step, "direction"); - const int64_t tiles = arg(step, "tiles"); - StoryPose at{here->map, here->tile, direction}; - for (int64_t c = 0; c < tiles; c++){ - at.tile = at.tile.next(direction); - } - // The boulder stands a tile ahead; on a floor switch's button, the - // switch is on for good and its barrier open. - const auto map = std::find_if(maps.begin(), maps.end(), [&](const MapData& item){ - return item.name == at.map; - }); - const Pokemon::MapSwitch* pressed = map == maps.end() ? nullptr : Pokemon::switch_with_button(*map, at.tile.next(direction)); - if (pressed != nullptr){ - state.gates.switches_on.insert(Pokemon::switch_key(*pressed)); - } - return Pokemon::outcome_ok(to_pose(at)); -} - Pokemon::Pose paced_pose(const Pokemon::Pose& patch, const StoryStep& step){ std::optional pace; if (const std::optional grind = step.action == GRIND_ACTION ? grind_plan_of(step.args) : std::nullopt){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h index 81d4268e5f..6fac86baf3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryPacedRoute.h @@ -12,8 +12,6 @@ #include #include -#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" -#include "Pokemon/AutoStory/Pokemon_StoryPose.h" #include "Pokemon/Navigation/Pokemon_GatedTypes.h" #include "Pokemon/Navigation/Pokemon_Grid.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" @@ -31,11 +29,6 @@ namespace PokemonFRLG{ // other step, or a `patch` not on one tile. Pokemon::Pose paced_pose(const Pokemon::Pose& patch, const StoryStep& step); -// Where a PUSH_BOULDER_VARIANT step leaves the player: `tiles` tiles on in -// its direction, behind the boulder. A boulder that ends on a floor -// switch's button turns that switch on in `state.gates`. -Pokemon::Outcome boulder_pushed(Pokemon::RunState& state, const StoryStep& step, const std::vector& maps); - // The maps the story plans on: every map to Route 4's Pokemon Center, with // the objects the game hides after the Hall of Fame removed, as the lab's // frlg_route does, and those a new game hides until their scene (the diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp index e2bde33e90..2d7b2c04a4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.cpp @@ -14,6 +14,7 @@ #include "Common/Cpp/Exceptions.h" #include "Pokemon/AutoStory/Pokemon_StoryPose.h" #include "Pokemon/AutoStory/Pokemon_TilePose.h" +#include "PokemonFRLG_AutoStoryBoulders.h" #include "PokemonFRLG_AutoStoryLegs.h" #include "PokemonFRLG_AutoStoryPacedRoute.h" #include "PokemonFRLG_AutoStoryActions.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp index 78d1a96762..df0be63067 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp @@ -293,7 +293,7 @@ UnitTestResult cave_floor(std::string_view previous, std::string_view id, std::s continue; } if (const std::string failure = row_step_on_sim(sim, at, step, row.id); !failure.empty()){ - std::string log; for (size_t c = sim.state().log.size() > 25 ? sim.state().log.size() - 25 : 0; c < sim.state().log.size(); c++){ log += "\n " + sim.state().log[c]; } return std::format("{} {}: ended on {}; {}{}", id, step.name, to_string(sim.state().position), failure, log); + return std::format("{} {}: ended on {}; {}", id, step.name, to_string(sim.state().position), failure); } if (!sim.state().violations.empty()){ return std::format("{} {}: broke a rule on {}: {}", id, step.name, to_string(sim.state().position), sim.state().violations.front()); diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 88fcda6438..9eab0a92a1 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2106,6 +2106,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryGates_Tests.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryMansion_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryViridian_Tests.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.cpp + Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders.h Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryBoulders_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryVictoryRoad_Tests.cpp Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRows13_Tests.h From 8be4c65d451f2bc16abb5c3f8d30b3f30adb1be0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 15:40:24 -0800 Subject: [PATCH 20/20] Navigation: restore the shared gate tests next to the FRLG ones fb8795f31 replaced the shared gate tests (Pokemon_Gates_Tests, the synthetic GateTestMaps and their embedded map list) with tests on FRLG's real maps. The shared ones come back exactly as they are on nav/gates; the FRLG-map tests stay as extra FRLG tests. Both suites register. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- SerialPrograms/CMakeLists.txt | 2 + .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../GateTestMaps/PokemonMansion_1F.json | 63 +++ .../GateTestMaps/PokemonMansion_3F.json | 59 +++ .../Navigation/GateTestMaps/SilphCo_5F.json | 45 ++ .../Navigation/Pokemon_Gates_Tests.cpp | 494 ++++++++++++++++++ .../Pokemon/Navigation/Pokemon_Gates_Tests.h | 24 + .../Pokemon_NavigationGateTestMaps.h | 30 ++ SerialPrograms/cmake/SourceFiles.cmake | 3 + 9 files changed, 722 insertions(+) create mode 100644 SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json create mode 100644 SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json create mode 100644 SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h create mode 100644 SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index b03c3bb1c5..ce339c0433 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -230,6 +230,8 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES}) include(cmake/EmbedTextFiles.cmake) pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_NavigationTestMaps.h PokemonAutomation::Pokemon navigation_test_map_json) +pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/GateTestMaps + Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h PokemonAutomation::Pokemon navigation_gate_test_map_json) include(cmake/PokesimMapResources.cmake) pa_frlg_map_resources(FRLG_MAP_RESOURCES) pa_embed_text_files(SerialProgramsLib "${FRLG_MAP_RESOURCES}" diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index e56c4a593b..9a5cf86d3d 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -36,6 +36,7 @@ #include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" #include "Pokemon/Navigation/Pokemon_ConnectedMaps_Tests.h" +#include "Pokemon/Navigation/Pokemon_Gates_Tests.h" #include "Pokemon/Navigation/Pokemon_LegPlanner_Tests.h" #include "Pokemon/Navigation/Pokemon_LegWalker_Tests.h" #include "Pokemon/Navigation/Pokemon_MapData_Tests.h" @@ -88,6 +89,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ Pokemon::add_tests_WallRecovery(ret); Pokemon::add_tests_MapData(ret); Pokemon::add_tests_ConnectedMaps(ret); + Pokemon::add_tests_Gates(ret); Pokemon::add_tests_MoveMechanics(ret); Pokemon::add_tests_RuntimeMap(ret); Pokemon::add_tests_RouteLog(ret); diff --git a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json new file mode 100644 index 0000000000..a7d5797eb4 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_1F.json @@ -0,0 +1,63 @@ +{ + "format": "pokesim-runtime-map/2", + "name": "PokemonMansion_1F", + "source": {"decomp_file": "data/maps/PokemonMansion_1F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-10-31"}, + "tiles": [ + "######################################", + "######################################", + "######################################", + "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#", + "#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#", + "#~~#~#~###~~~#~~~~~#~#~#~#~~#####~~~~#", + "#~~#~~~###~~~#~~~~~#~#~#~#~~#####~~~##", + "#~~~~~~~~~~~~#~~~~~~~~~~~~~~#####~~~##", + "#~~~~~~~~~~~~#~~~~~~~~~~~~~~#~~~~~~~~#", + "#~~~~~~~~~~~~##~~~####~~~####~~~~~~~~#", + "################~~####GGG####~~~###~~#", + "################~~####GGG####~~~###~~#", + "##############~~~~#~~~~~~~####~~~~~~~#", + "#~~~~~~~~~.###~~~~#~~~~~~~~###~~~~~~~#", + "#~~~~~~~~~~###~~~~#~~~~~~~~~##~~~~~~~#", + "#~~~~~~~~~~~~~~~~~#~~~~~~~~~##~~~~~~~#", + "#~~~~~~~~~~~~~~~~~#~~~~~~~~~##~~~~~~~#", + "#~~~~~~~~~~~~~~~###############~~~####", + "#~~~~~~~~~~~~~~~###############GGG####", + "##~~~~~~~~~~~~~~###############GGG####", + "###~~#~~~~~#~~~##~~#####~~~~~~~~~~~~~#", + "###~~#~~~~~#~~~##~~~~~~#~~~~~~~~~~~~~#", + "###~~#~~~~~#~~~##~~~~~~#~~~~~~~~~~~~~#", + "###~~~~~~~~~~~~~#~~~~~~#~~~~~~~~~~~~~#", + "#~~~~~~~~~~~~~~~#~~~~~~####~~~##~~~###", + "#~~~~#~~~~~#~~~~#~~~~~~####GGG##GGG###", + "#~~~~#~~~~~#~~~~#~~########GGG##GGG###", + "#~~~~#~~~~~#~~~~#~~~~~~##.~~~~~#~~~~~#", + "#~~~~~~~~~~~~~~~#~~~~~~##~~~~~~#~~~~~#", + "#~~~~~~~~~~~~~~~#~~~~~~~~~~~~~~#~~~~~#", + "#~~~~#~~~~~#~~~~#~~~~~~~~~~~~~~#~~~~~#", + "#~~~~#~~~~~#~~~~#~~~~~~~~~~~~~~#~~~~~#", + "#~~~~#~~~~~#~~~~#~~######~~~~~~#~~~~~#", + "#~~~~~~~.~~~~~~~#~~~~~~~~~~~~~~#~~.~~#", + "######################################" + ], + "points": {"warp_1": [8, 33], "warp_3": [10, 13], "warp_4": [25, 27], "warp_7": [19, 22], "warp_8": [20, 22]}, + "warps": [ + {"enter": "walk_into", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [7, 33]}, + {"enter": "walk_south", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [8, 33]}, + {"enter": "walk_into", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [9, 33]}, + {"enter": "walk_east", "to_map": "PokemonMansion_2F", "to_point": "warp_2", "coord": [10, 13]}, + {"enter": "walk_west", "to_map": "PokemonMansion_B1F", "to_point": "warp_0", "coord": [25, 27]}, + {"enter": "walk_south", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [34, 33]}, + {"enter": "walk_into", "to_map": "CinnabarIsland", "to_point": "warp_0", "coord": [35, 34]}, + {"enter": "walk_into", "to_map": "PokemonMansion_3F", "to_point": "warp_3", "coord": [19, 22]}, + {"enter": "walk_into", "to_map": "PokemonMansion_3F", "to_point": "warp_4", "coord": [20, 22]}, + {"enter": "walk_into", "to_map": "PokemonMansion_2F", "to_point": "warp_2", "coord": [11, 13]} + ], + "connections": [], + "gates": { + "barrier_1": {"tiles": [[22, 10], [22, 11], [23, 10], [23, 11], [24, 10], [24, 11]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"}, + "barrier_2": {"tiles": [[31, 18], [31, 19], [32, 18], [32, 19], [33, 18], [33, 19]], "open_glyph": "~", "new_game": "open", "switch": "mansion", "open_when": "off"}, + "barrier_3": {"tiles": [[27, 25], [27, 26], [28, 25], [28, 26], [29, 25], [29, 26]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"}, + "barrier_4": {"tiles": [[32, 25], [32, 26], [33, 25], [33, 26], [34, 25], [34, 26]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"} + }, + "switches": {"mansion": {"flag": "FLAG_POKEMON_MANSION_SWITCH_STATE", "toggle": true, "floors": ["PokemonMansion_1F", "PokemonMansion_2F", "PokemonMansion_3F", "PokemonMansion_B1F"], "statues": [{"coord": [5, 5], "face_from": [5, 6], "facing": "north"}]}} +} diff --git a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json new file mode 100644 index 0000000000..8dc8b4874e --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/PokemonMansion_3F.json @@ -0,0 +1,59 @@ +{ + "format": "pokesim-runtime-map/2", + "name": "PokemonMansion_3F", + "source": {"decomp_file": "data/maps/PokemonMansion_3F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-10-31"}, + "tiles": [ + "######################################", + "######################################", + "######################################", + "#~~~~~##.~~~~~~~###~~#~~~~~~~#~~~#~~~#", + "#~~~~~##~~~~~~~~~##~~#~~~~~~~#~~~~#~~#", + "##~~~~~~~~~~#~~~~##~~#~~###~~#~~~~##~#", + "###~~~~~~~~~~~~~~~~~~G~~###~~~~~~~~###", + "###~~~~~~~~~~~~~~~~~~G~~~~~~~~~~~~~~~#", + "########~######~~~~~~G~~~~~~~~~~~~~~~#", + "###############~~~~~~#~~~~~~~~~~~~~~~#", + "########~########~~~######~###~#######", + "#~###~~~~##.~~###GGG##################", + "#~~##~~~~##~~~###GGG######~~~~~#######", + "#~~#~~~~~~~~~~##~~~~~~~~~~~~~~~~~~~~~#", + "#~~~~~~~~~~~~~#~~~~~~~~~~~~~~~~~~~~~~#", + "#~~~~~~~~~~~~~####~~~##~~##~~#########", + "#~~~~~###~~~~~####~~~##~~##~~#########", + "####~~###~~~~#####~~~##~~##~~#########", + "####~~~~~~~~######~~~##~~##~~~~~##.~~#", + "#~~~~~~~~~~################~~~~~##~~~#", + "#~~~~~~~~~~~~~#############~~~~~~~~~~#", + "#~~~~~~~~~~~~~#############~~~~~~~~~~#", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################", + "######################################" + ], + "points": {"warp_0": [8, 3], "warp_1": [34, 18], "warp_2": [11, 11], "warp_3": [18, 18], "warp_4": [19, 18], "warp_5": [23, 18]}, + "warps": [ + {"enter": "walk_west", "to_map": "PokemonMansion_2F", "to_point": "warp_0", "coord": [8, 3]}, + {"enter": "walk_west", "to_map": "PokemonMansion_2F", "to_point": "warp_1", "coord": [34, 18]}, + {"enter": "walk_west", "to_map": "PokemonMansion_2F", "to_point": "warp_3", "coord": [11, 11]}, + {"enter": "step_on", "to_map": "PokemonMansion_1F", "to_point": "warp_7", "one_way": true, "coord": [18, 18]}, + {"enter": "step_on", "to_map": "PokemonMansion_1F", "to_point": "warp_8", "one_way": true, "coord": [19, 18]}, + {"enter": "step_on", "to_map": "PokemonMansion_2F", "to_point": "warp_4", "one_way": true, "coord": [23, 18]}, + {"enter": "step_on", "to_map": "PokemonMansion_1F", "to_point": "warp_8", "one_way": true, "coord": [20, 18]}, + {"enter": "step_on", "to_map": "PokemonMansion_2F", "to_point": "warp_4", "one_way": true, "coord": [24, 18]} + ], + "connections": [], + "gates": { + "barrier_1": {"tiles": [[21, 6], [21, 7], [21, 8]], "open_glyph": "~", "new_game": "open", "switch": "mansion", "open_when": "off"}, + "barrier_2": {"tiles": [[17, 11], [17, 12], [18, 11], [18, 12], [19, 11], [19, 12]], "open_glyph": "~", "new_game": "closed", "switch": "mansion", "open_when": "on"} + }, + "switches": {"mansion": {"flag": "FLAG_POKEMON_MANSION_SWITCH_STATE", "toggle": true, "floors": ["PokemonMansion_1F", "PokemonMansion_2F", "PokemonMansion_3F", "PokemonMansion_B1F"], "statues": [{"coord": [12, 5], "face_from": [12, 6], "facing": "north"}]}} +} diff --git a/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json new file mode 100644 index 0000000000..53ecd291ad --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/GateTestMaps/SilphCo_5F.json @@ -0,0 +1,45 @@ +{ + "format": "pokesim-runtime-map/2", + "name": "SilphCo_5F", + "source": {"decomp_file": "data/maps/SilphCo_5F/map.json", "revision": "ce6406d8c2eaf46d543c8a2606de0c3cb1951982", "date": "2026-10-31"}, + "tiles": [ + "####################################", + "####################################", + "############################...#####", + "######################D#####...#####", + ".......##........###................", + ".......##...........................", + ".#.#.#.##...........................", + ".......##.........##########..#####.", + ".......##.........##########..#####.", + ".......GG..#########............###.", + ".......GG..#########.............##.", + ".#.#.#.##..##.....##.....######..##.", + ".......##..##.....##........###..##.", + "#########..###....GG........###..##.", + "#########..##.....GG........###..##.", + ".......##..##.....##.....######..##.", + "...##..##..###....##.............##.", + ".#####.##..##.....##.............##.", + "..####.GG..########################.", + "...###.GG..########################.", + "...###.##....#..#..#..#..#..#..#....", + ".......##..........................." + ], + "points": {"warp_0": [28, 2], "warp_1": [15, 7], "warp_2": [30, 2], "warp_3": [10, 20], "warp_4": [2, 20], "warp_5": [33, 5]}, + "warps": [ + {"enter": "walk_west", "to_map": "SilphCo_4F", "to_point": "warp_0", "coord": [28, 2]}, + {"enter": "step_on", "to_map": "SilphCo_3F", "to_point": "warp_1", "coord": [15, 7]}, + {"enter": "walk_east", "to_map": "SilphCo_6F", "to_point": "warp_2", "coord": [30, 2]}, + {"enter": "step_on", "to_map": "SilphCo_9F", "to_point": "warp_1", "coord": [10, 20]}, + {"enter": "step_on", "to_map": "SilphCo_3F", "to_point": "warp_5", "coord": [2, 20]}, + {"enter": "step_on", "to_map": "SilphCo_7F", "to_point": "warp_2", "coord": [33, 5]}, + {"enter": "walk_into", "to_map": "SilphCo_Elevator", "to_point": "warp_0", "coord": [22, 3]} + ], + "connections": [], + "gates": { + "door_1": {"tiles": [[7, 9], [7, 10], [8, 9], [8, 10]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_SILPH_5F_DOOR_1"}, + "door_2": {"tiles": [[7, 18], [7, 19], [8, 18], [8, 19]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_SILPH_5F_DOOR_2"}, + "door_3": {"tiles": [[18, 13], [18, 14], [19, 13], [19, 14]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "FLAG_SILPH_5F_DOOR_3"} + } +} diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp new file mode 100644 index 0000000000..46f062f7f6 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp @@ -0,0 +1,494 @@ +/* Gates Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Fixtures: GateTestMaps/, trimmed from PokemonSimulation's runtime maps + * (SilphCo_5F: card-key doors; PokemonMansion_1F and _3F: statue switch, + * barriers, holes). + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon_GatedPlanner.h" +#include "Pokemon_Gates_Tests.h" +#include "Pokemon_NavigationGateTestMaps.h" + +namespace PokemonAutomation{ +namespace Pokemon{ +namespace{ + + +MapData load(const std::string& name){ + for (const auto& [file, text] : navigation_gate_test_map_json()){ + if (file == name){ + return parse_map(parse_json(text), name + ".json"); + } + } + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "No gate test map " + name); +} + +// Silph 5F, Mansion 1F and 3F, in that order. +const std::vector& maps(){ + static const std::vector loaded{ + load("SilphCo_5F"), + load("PokemonMansion_1F"), + load("PokemonMansion_3F"), + }; + return loaded; +} +constexpr size_t SILPH = 0; +constexpr size_t MANSION_1F = 1; +constexpr size_t MANSION_3F = 2; + +const ConnectedMaps& world(){ + static const ConnectedMaps connected(maps()); + return connected; +} + + +// Walks the maps with the gates as the state says; a step onto a step-on +// warp takes it. Walk-into warps are not modeled: they are not the topic. +class GateGame{ +public: + using State = MapPlace; + using StateHash = std::hash; + + std::optional> press(const State& state, Direction direction, const GateState& gates) const{ + const MapData& map = world().map(state.map); + const TilePos next = state.tile.next(direction); + if (!map.tiles.contains(next) || !walkable(resolved_tile(map, next, gates))){ + return std::nullopt; + } + Step step; + step.next = {state.map, next}; + step.facing = direction; + for (const MapWarp& warp : map.warps){ + if (warp.enter != WarpEntry::STEP_ON || warp.x != next.x || warp.y != next.y){ + continue; + } + const std::optional arrival = warp.to ? world().warp_arrival(warp) : std::nullopt; + if (!arrival){ + return std::nullopt; + } + step.next = *arrival; + step.warped = true; + step.ends_leg = true; + } + return step; + } + bool held_at(const State& state, Direction direction, const GateState& gates) const{ + const MapData& map = world().map(state.map); + const TilePos next = state.tile.next(direction); + return !map.tiles.contains(next) || !walkable(resolved_tile(map, next, gates)); + } + MapPlace place_of(const State& state) const{ + return state; + } + +private: + static bool walkable(TileKind tile){ + return tile == TileKind::OPEN || tile == TileKind::TALL_GRASS; + } +}; + +using GatedLegs = std::vector>>; + +std::optional plan( + const MapPlace& from, const MapPlace& to, const GateState& gates, bool card_key_held +){ + GateRules rules; + rules.card_key_held = card_key_held; + return plan_gated_legs( + GateGame(), world(), rules, GatedStart{from, gates}, + GatedGoal{std::function([to](const MapPlace& place){ return place == to; })} + ); +} + +int count_actions(const GatedLegs& legs, int action){ + int count = 0; + for (const auto& leg : legs){ + if (leg.kind == LegKind::ACTION && leg.action == action){ + count++; + } + } + return count; +} + + +// Reader + +UnitTestResult test_reads_card_key_doors(){ + const MapData& silph = maps()[SILPH]; + if (silph.gates.size() != 3 || !silph.switches.empty()){ + return std::format("Expected 3 gates and no switches, got {} and {}.", silph.gates.size(), silph.switches.size()); + } + const auto found = silph.gates.find("door_1"); + if (found == silph.gates.end()){ + return "No door_1."; + } + const MapGate& door = found->second; + if (door.kind != GateKind::CARD_KEY || door.flag != "FLAG_SILPH_5F_DOOR_1" || door.open_at_new_game || + door.open_tile != TileKind::OPEN || door.tiles.size() != 4 + ){ + return "door_1 is not a closed card-key door of 4 tiles opening to floor with its flag."; + } + if (silph.tiles.at(TilePos{7, 9}) != TileKind::GATE){ + return "Tile (7, 9) is not a gate."; + } + return true; +} + +UnitTestResult test_reads_switches(){ + const MapData& first = maps()[MANSION_1F]; + if (first.gates.size() != 4 || first.switches.size() != 1){ + return std::format("Expected 4 gates and 1 switch, got {} and {}.", first.gates.size(), first.switches.size()); + } + const MapGate& open_first = first.gates.at("barrier_2"); + if (open_first.kind != GateKind::SWITCH || open_first.switch_id != "mansion" || open_first.open_when_on || !open_first.open_at_new_game){ + return "1F barrier_2 should open when the switch is off."; + } + if (!first.gates.at("barrier_1").open_when_on){ + return "1F barrier_1 should open when the switch is on."; + } + const MapSwitch& pressing = first.switches.at("mansion"); + if (!pressing.toggle || pressing.floors.size() != 4 || pressing.flag != "FLAG_POKEMON_MANSION_SWITCH_STATE"){ + return "The switch is a toggle on 4 floors with its flag."; + } + if (pressing.statues.size() != 1 || pressing.statues[0].tile != TilePos{5, 5} || + pressing.statues[0].face_from != TilePos{5, 6} || pressing.statues[0].facing != Direction::NORTH + ){ + return "1F statue should be (5, 5), pressed from (5, 6) facing north."; + } + return true; +} + +UnitTestResult test_reads_one_way_warps(){ + int drops = 0; + for (const MapWarp& warp : maps()[MANSION_3F].warps){ + drops += warp.one_way ? 1 : 0; + } + if (drops != 5){ + return std::format("Expected 5 one-way warps on 3F, got {}.", drops); + } + for (const MapWarp& warp : maps()[MANSION_1F].warps){ + if (warp.one_way){ + return "A 1F warp is one-way."; + } + } + return true; +} + +// A 3x3 map with `gates` and `switches` (JSON object text) on tiles "G..". +std::string parse_error(const std::string& rows, const std::string& gates, const std::string& switches){ + const std::string text = std::format(R"({{ + "format": "pokesim-runtime-map/2", "name": "T", + "source": {{"decomp_file": "x", "revision": "y", "date": "z"}}, + "tiles": [{}], "points": {{}}, "warps": [], "connections": [], + "gates": {}, "switches": {} + }})", rows, gates, switches); + try{ + parse_map(parse_json(text), "T.json"); + }catch (ParseException& e){ + return e.message(); + } + return ""; +} + +UnitTestResult test_gate_errors(){ + const std::string rows = R"("G..", "...", "...")"; + const std::string door = R"({"d": {"tiles": [[0, 0]], "open_glyph": ".", "new_game": "closed", "opens_by": "card_key_face_a", "flag": "F"}})"; + if (!parse_error(rows, door, "{}").empty()){ + return "A valid gate failed to parse."; + } + if (parse_error(rows, "{}", "{}").empty()){ + return "A G tile in no gate was accepted."; + } + if (parse_error(R"("...", "...", "...")", door, "{}").empty()){ + return "A gate on a tile that is not G was accepted."; + } + const std::string unknown_switch = R"({"d": {"tiles": [[0, 0]], "open_glyph": ".", "new_game": "closed", "switch": "nope", "open_when": "on"}})"; + if (parse_error(rows, unknown_switch, "{}").empty()){ + return "A gate on an unlisted switch was accepted."; + } + const std::string far_statue = R"({"s": {"flag": "F", "toggle": true, "floors": ["T"], "statues": [{"coord": [9, 9], "face_from": [1, 1], "facing": "north"}]}})"; + if (parse_error(rows, door, far_statue).empty()){ + return "A statue outside the map was accepted."; + } + return true; +} + + +// State and tiles + +UnitTestResult test_tiles_follow_state(){ + const MapData& silph = maps()[SILPH]; + GateState state; + if (resolved_tile(silph, TilePos{7, 9}, state) != TileKind::WALL){ + return "A closed door is not a wall."; + } + state.opened.insert(gate_key("SilphCo_5F", "door_1")); + if (resolved_tile(silph, TilePos{7, 9}, state) != TileKind::OPEN || resolved_tile(silph, TilePos{7, 18}, state) != TileKind::WALL){ + return "Only door_1 should be open."; + } + if (resolve_tiles(silph, state).at(TilePos{8, 10}) != TileKind::OPEN){ + return "resolve_tiles disagrees."; + } + + // The Mansion's gates follow the one switch on every floor. + const MapData& first = maps()[MANSION_1F]; + const MapData& third = maps()[MANSION_3F]; + GateState off; + GateState on; + on.switches_on.insert("mansion"); + if (resolved_tile(first, TilePos{22, 10}, off) != TileKind::WALL || resolved_tile(first, TilePos{22, 10}, on) != TileKind::TALL_GRASS){ + return "1F barrier_1 should open with the switch on."; + } + if (resolved_tile(third, TilePos{21, 6}, off) != TileKind::TALL_GRASS || resolved_tile(third, TilePos{21, 6}, on) != TileKind::WALL){ + return "3F barrier_1 should close with the switch on."; + } + return true; +} + +UnitTestResult test_gate_change(){ + GateState state; + GateChange change; + change.opened.insert("SilphCo_5F/door_1"); + change.switches["mansion"] = true; + apply_gate_change(state, change); + if (!state.opened.contains("SilphCo_5F/door_1") || !state.switch_on("mansion")){ + return "The change was not applied."; + } + GateChange off; + off.switches["mansion"] = false; + GateState after = state; + apply_gate_change(after, off); + if (after.switch_on("mansion") || !after.opened.contains("SilphCo_5F/door_1")){ + return "Turning the switch off changed more, or nothing."; + } + GateState rebuilt; + apply_gate_change(rebuilt, gate_change_between(GateState(), state)); + if (!(rebuilt == state)){ + return "gate_change_between from nothing does not rebuild the state."; + } + apply_gate_change(rebuilt, gate_change_between(state, after)); + if (!(rebuilt == after)){ + return "gate_change_between does not carry state to state."; + } + const GateState copy = after; + if (std::hash()(copy) != std::hash()(rebuilt)){ + return "Equal states hash differently."; + } + return true; +} + + +// Planner + +UnitTestResult test_silph_door_needs_key(){ + const MapPlace from{SILPH, {10, 9}}; + const MapPlace to{SILPH, {5, 9}}; + if (plan(from, to, GateState(), false)){ + return "Planned into the room without the Card Key."; + } + const auto legs = plan(from, to, GateState(), true); + if (!legs){ + return "No route with the Card Key."; + } + if (count_actions(*legs, ACTION_OPEN_GATE) != 1){ + return std::format("Expected one open-gate leg, got {}.", count_actions(*legs, ACTION_OPEN_GATE)); + } + GateChange expected; + expected.opened.insert("SilphCo_5F/door_1"); + for (const auto& leg : *legs){ + if (leg.kind == LegKind::ACTION){ + if (!(gate_change_of(leg) == expected)){ + return "The open-gate leg did not open door_1 alone."; + } + if (leg.direction != Direction::WEST || !(leg.start.inner == MapPlace{SILPH, {9, 9}})){ + return "Expected to open it facing west from (9, 9)."; + } + } + } + if (!gates_after(GateState(), *legs).opened.contains("SilphCo_5F/door_1")){ + return "The state after the plan does not have door_1 open."; + } + return true; +} + +UnitTestResult test_silph_open_door_needs_no_key(){ + GateState opened; + opened.opened.insert(gate_key("SilphCo_5F", "door_1")); + const auto legs = plan({SILPH, {10, 9}}, {SILPH, {5, 9}}, opened, false); + if (!legs){ + return "No route through an open door."; + } + if (count_actions(*legs, ACTION_OPEN_GATE) != 0){ + return "Opened a door that was open."; + } + return true; +} + +UnitTestResult test_mansion_press_opens_barrier(){ + // (19, 13) lies behind barrier_1 and barrier_2 of 1F, which open with the switch on. + const MapPlace from{MANSION_1F, {5, 8}}; + const MapPlace to{MANSION_1F, {19, 13}}; + const auto legs = plan(from, to, GateState(), false); + if (!legs){ + return "No route."; + } + if (count_actions(*legs, ACTION_PRESS_SWITCH) != 1){ + return std::format("Expected one statue press, got {}.", count_actions(*legs, ACTION_PRESS_SWITCH)); + } + if (!gates_after(GateState(), *legs).switch_on("mansion")){ + return "The switch is not on after the plan."; + } + for (const auto& leg : *legs){ + if (leg.kind == LegKind::ACTION && (leg.direction != Direction::NORTH || !(leg.start.inner == MapPlace{MANSION_1F, {5, 6}}))){ + return "Expected to press the statue from (5, 6) facing north."; + } + } + return true; +} + +UnitTestResult test_mansion_press_again(){ + // Switch already on; (25, 21) is reachable only with it off. + GateState on; + on.switches_on.insert("mansion"); + const auto legs = plan({MANSION_1F, {5, 6}}, {MANSION_1F, {25, 21}}, on, false); + if (!legs){ + return "No route."; + } + if (count_actions(*legs, ACTION_PRESS_SWITCH) != 1 || gates_after(on, *legs).switch_on("mansion")){ + return "Expected one press, ending with the switch off."; + } + return true; +} + +UnitTestResult test_mansion_no_press_needed(){ + // Reachable with the switch as it is: no press. + const auto legs = plan({MANSION_1F, {5, 6}}, {MANSION_1F, {5, 8}}, GateState(), false); + if (!legs || count_actions(*legs, ACTION_PRESS_SWITCH) != 0){ + return "Pressed a statue that was not needed."; + } + return true; +} + +UnitTestResult test_hole_one_way(){ + // The 3F hole at (18, 18) drops to 1F's (19, 22); nothing leads back up. + const auto down = plan({MANSION_3F, {18, 17}}, {MANSION_1F, {19, 22}}, GateState(), false); + if (!down){ + return "No route down the hole."; + } + bool warped = false; + for (const auto& leg : *down){ + warped = warped || leg.warps; + } + if (!warped){ + return "The route does not take the warp."; + } + if (plan({MANSION_1F, {19, 22}}, {MANSION_3F, {18, 17}}, GateState(), false)){ + return "Planned back up a hole."; + } + return true; +} + + +struct GatesTestCase{ + struct Input{ + std::string name; + UnitTestResult (*test)(); + }; + + struct Expectation{ + std::string_view description; + }; + + Input input; + Expectation expectation; +}; + +class Test_Gates : public UnitTest{ +public: + explicit Test_Gates(GatesTestCase scenario) + : UnitTest(std::format("Pokemon::Gates - {}", scenario.input.name)) + , m_scenario(std::move(scenario)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return m_scenario.input.test(); + } + +private: + GatesTestCase m_scenario; +}; + +const GatesTestCase GATES_CASES[] = { + { + .input = {.name = "reads card-key doors", .test = test_reads_card_key_doors}, + .expectation = {.description = "Silph 5F doors parse with tiles, flag, open glyph"}, + }, + { + .input = {.name = "reads switches and statues", .test = test_reads_switches}, + .expectation = {.description = "Mansion gates follow the switch; statue tile and press spot"}, + }, + { + .input = {.name = "reads one-way warps", .test = test_reads_one_way_warps}, + .expectation = {.description = "3F holes are one-way"}, + }, + { + .input = {.name = "gate errors", .test = test_gate_errors}, + .expectation = {.description = "bad gates fail to parse"}, + }, + { + .input = {.name = "tiles follow the state", .test = test_tiles_follow_state}, + .expectation = {.description = "closed gate is a wall, open is its glyph, Mansion follows the switch"}, + }, + { + .input = {.name = "gate change", .test = test_gate_change}, + .expectation = {.description = "apply and between agree"}, + }, + { + .input = {.name = "a card-key door needs the key", .test = test_silph_door_needs_key}, + .expectation = {.description = "open-gate leg only with the Card Key held"}, + }, + { + .input = {.name = "an open door needs no key", .test = test_silph_open_door_needs_no_key}, + .expectation = {.description = "no open-gate leg when the state has it open"}, + }, + { + .input = {.name = "a statue press opens a barrier", .test = test_mansion_press_opens_barrier}, + .expectation = {.description = "one press-switch leg; switch on afterwards"}, + }, + { + .input = {.name = "a press again closes it", .test = test_mansion_press_again}, + .expectation = {.description = "switch is part of the search state"}, + }, + { + .input = {.name = "no press when not needed", .test = test_mansion_no_press_needed}, + .expectation = {.description = "does not toggle without reason"}, + }, + { + .input = {.name = "a hole is one-way", .test = test_hole_one_way}, + .expectation = {.description = "down yes, back up no"}, + }, +}; + +} // namespace + + +void add_tests_Gates(UnitTestDatabase& database){ + for (const auto& scenario : GATES_CASES){ + database.add(scenario); + } +} + + + +} // namespace Pokemon +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h new file mode 100644 index 0000000000..e82848786c --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_Gates_Tests.h @@ -0,0 +1,24 @@ +/* Gates Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_Gates_Tests_H +#define PokemonAutomation_Pokemon_Gates_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// Registers the gate tests: the map reader's gates, switches and one-way +// warps, the gate state, and the gated planner. +void add_tests_Gates(UnitTestDatabase& database); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h new file mode 100644 index 0000000000..2b3503fee4 --- /dev/null +++ b/SerialPrograms/Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h @@ -0,0 +1,30 @@ +/* Navigation Gate Test Maps + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_Pokemon_NavigationGateTestMaps_H +#define PokemonAutomation_Pokemon_NavigationGateTestMaps_H + +#include +#include +#include + +namespace PokemonAutomation{ +namespace Pokemon{ + + +// (name, JSON text) of each map in Pokemon/Navigation/GateTestMaps/, built +// into the program by pa_embed_text_files() (cmake/EmbedTextFiles.cmake): +// SilphCo_5F (card-key doors), PokemonMansion_1F (statue-switch barriers) +// and PokemonMansion_3F (barriers, a statue, and holes: one-way warps), +// trimmed from PokemonSimulation's runtime maps. 3F's hole tiles are +// tall grass here, which the reader knows. +const std::vector>& navigation_gate_test_map_json(); + + + +} // namespace Pokemon +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b402466582..97a4bfd889 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1478,6 +1478,8 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_GateState.h Source/Pokemon/Navigation/Pokemon_GateTiles.cpp Source/Pokemon/Navigation/Pokemon_GateTiles.h + Source/Pokemon/Navigation/Pokemon_Gates_Tests.cpp + Source/Pokemon/Navigation/Pokemon_Gates_Tests.h Source/Pokemon/Navigation/Pokemon_Direction.cpp Source/Pokemon/Navigation/Pokemon_Direction.h Source/Pokemon/Navigation/Pokemon_Grid.cpp @@ -1509,6 +1511,7 @@ file(GLOB LIBRARY_SOURCES Source/Pokemon/Navigation/Pokemon_RuntimeMap.h Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.cpp Source/Pokemon/Navigation/Pokemon_RuntimeMap_Tests.h + Source/Pokemon/Navigation/Pokemon_NavigationGateTestMaps.h Source/Pokemon/Navigation/Pokemon_NavigationTestMaps.h Source/Pokemon/Navigation/Pokemon_RouteLog.cpp Source/Pokemon/Navigation/Pokemon_RouteLog.h