From 23b2d73ca3cb0837e005c9476f97cdcba32823a4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 13:33:44 -0800 Subject: [PATCH 1/2] FRLG AutoStory: sweep a warp that does nothing at every warp Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Overworld/PokemonFRLG_OverworldSim.cpp | 5 +- .../Overworld/PokemonFRLG_OverworldSimState.h | 6 ++ .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 64 +++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp index f4e8a243c3..02a46be46d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSim.cpp @@ -244,7 +244,7 @@ std::optional OverworldSim::watch_until(const std::vector& std::optional OverworldSim::take_warp(int map_index, const TilePos& tile) const{ const MapWarp* warp = warp_at(m_maps[map_index], tile); - if (warp == nullptr){ + if (warp == nullptr || m_script.dead_warp_maps.contains(m_maps[map_index].name)){ return std::nullopt; } if (m_lift_floor && m_script.lift_floors.contains(m_maps[map_index].name)){ @@ -360,6 +360,9 @@ bool OverworldSim::after_step(const Step& step, Milliseconds pressed){ if (step.warped && black_without_warp(pressed)){ return true; } + if (step.warped){ + m_state.warped_from.push_back(map().name); + } m_map = step.map; m_player = step.player; m_state.steps++; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h index 0d336a4d5c..fb0a38e779 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSimState.h @@ -59,6 +59,10 @@ struct SimScript{ // fade's black and clear with the player where they were, not warped // (console B, 2026-11-10 01:44, 09.01 run 4, "east 1 (warp)" on B4F). std::set black_without_warp; + // Fault injection: maps whose warps do nothing: a step or press onto + // one leaves the player where they were, with no fade, as a wall would + // (the warp no-op fault class, PokemonFRLG_AutoStoryFaultSweep_Tests.cpp). + std::set dead_warp_maps; // The player rides the Bicycle: a tap facing another way takes a step // too, a hold through a turn loses no tile // (MovementMechanics::BIKE_TAP_ONLY_TURNS), and no step tap is @@ -98,6 +102,8 @@ struct SimState{ bool dark = false; int steps = 0; int warps = 0; + // The map each warp was taken from, oldest first. + std::vector warped_from; int wild_battles = 0; // From each wild battle's step to the overworld after it, together. Milliseconds in_wild_battles{0}; 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 01fea4ccb5..c7d7a985d6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -25,6 +25,10 @@ * back, inside the lockout after a battle (08.01 winston_line, console * B, 2026-11-09 15:50). The step alone, from where the clean run took * it, on its map made a wild floor. + * - WARP_NO_OP: the warps of each map the row warps from do nothing, + * no fade and no move, so the step that walks onto the first of them + * must stop there, not go on as if warped (09.01's B4F stairs, console + * B, 2026-11-10, reported as walked to B3F). * * Not swept here: a missed fade, which needs a knob in OverworldSim; a * battle's opening at a step's start, which needs one in OverworldStepSim; @@ -76,6 +80,7 @@ enum class FaultClass{ SLOW_FADE_IN, DARK_CAVE, LOST_TAP, + WARP_NO_OP, }; std::string_view fault_class_name(FaultClass fault){ switch (fault){ @@ -91,6 +96,8 @@ std::string_view fault_class_name(FaultClass fault){ return "dark cave without Flash"; case FaultClass::LOST_TAP: return "lost tap after a battle in a trainer's line"; + case FaultClass::WARP_NO_OP: + return "warp no-op"; } return "?"; } @@ -162,6 +169,10 @@ struct RowRun{ // Where the player stood before each step, by index. std::map before; std::map facing_before; + // The maps each step warped from, by index. + std::map> warped_from; + // The step `failure` is from; none for a violation or a row's end. + std::optional failed_at; MapPosition end; Milliseconds time{0}; int steps = 0; @@ -237,12 +248,21 @@ RowRun run_row( const StoryStep& step = row.steps[c]; out.before.emplace(c, sim->state().position); out.facing_before.emplace(c, sim->state().facing); + const size_t warps_before = sim->state().warped_from.size(); out.failure = row_step_on_sim(*sim, at, step, row.id); + const std::vector& warped = sim->state().warped_from; + out.warped_from[c].assign(warped.begin() + warps_before, warped.end()); + if (!out.failure.empty()){ + out.failed_at = c; + } const bool let_pass = unscripted(out.failure) && (!scripted || scripted->contains(c)); if (let_pass){ out.failure.clear(); out.scripted.insert(c); } + if (let_pass){ + out.failed_at.reset(); + } if (!out.failure.empty() || (sim_plays(step) && !let_pass) || !step.pose_after){ continue; } @@ -504,6 +524,47 @@ UnitTestResult sweep_lost_tap(Logger& logger, const StoryCheckpoint& row, const return sweep_result(logger, FaultClass::LOST_TAP, row.id, variants, failures); } +// The steps of the clean run `clean` of `row` that warp, by index: the +// first from each map, with that map. +std::vector> first_warps_by_map(const StoryCheckpoint& row, const RowRun& clean){ + std::vector> out; + std::set maps; + for (size_t c = 0; c < row.steps.size(); c++){ + const auto warped = clean.warped_from.find(c); + if (warped == clean.warped_from.end()){ + continue; + } + for (const std::string& map : warped->second){ + if (maps.insert(map).second){ + out.emplace_back(c, map); + } + } + } + return out; +} + +// Row `row` with the warps of each map it warps from doing nothing, one +// map at a time: the step onto the first of them must stop the row. +UnitTestResult sweep_warp_no_op(Logger& logger, const StoryCheckpoint& row, const RowRun& clean){ + std::vector failures; + const std::vector> warps = first_warps_by_map(row, clean); + for (const auto& [c, map] : warps){ + SimScript script; + script.dead_warp_maps = {map}; + const RowRun run = run_row(row, script, {}, clean.scripted); + if (run.failed_at == c){ + continue; + } + const std::string variant = "every warp on " + map + " does nothing"; + if (run.failure.empty()){ + failures.push_back({row.steps[c].name, variant, std::format("not stopped: the row went on and ended on {}.", to_string(run.end))}); + }else{ + failures.push_back({row.steps[c].name, variant, std::format("stopped at {}, not here: {}", run.failed_at ? row.steps[*run.failed_at].name : "the row's end", run.failure)}); + } + } + return sweep_result(logger, FaultClass::WARP_NO_OP, row.id, warps.size(), failures); +} + // A fault class swept over row `row` (empty in FAULT_SWEEP_CASES: each // row with a start). struct FaultSweepInput{ @@ -573,6 +634,8 @@ class Test_AutoStoryFaultSweep : public UnitTest{ return sweep_dark_cave(logger, m_row, clean); case FaultClass::LOST_TAP: return sweep_lost_tap(logger, m_row, clean); + case FaultClass::WARP_NO_OP: + return sweep_warp_no_op(logger, m_row, clean); } return true; } @@ -591,6 +654,7 @@ const FaultSweepCase FAULT_SWEEP_CASES[] = { {.input = {.fault = FaultClass::SLOW_FADE_IN}, .expectation = {}}, {.input = {.fault = FaultClass::DARK_CAVE}, .expectation = {}}, {.input = {.fault = FaultClass::LOST_TAP}, .expectation = {}}, + {.input = {.fault = FaultClass::WARP_NO_OP}, .expectation = {}}, }; std::optional talk_battle_hide_flag(const StoryStep& step){ From 34f5c6b1c2f6faa44f572d39ba29828248b8fc1c Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 13:39:15 -0800 Subject: [PATCH 2/2] FRLG AutoStory: a step onto a warp is done only once the warp is confirmed A plain STEP onto a door, mat or stairs was taken as walked with no check that the game warped. It now waits out the fade and checks the screen left the scene (wait_out_warp()), and the row sim does the same. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonFRLG_AutoStoryEvents.cpp | 17 ++++++++ .../PokemonFRLG_AutoStoryFaultSweep_Tests.cpp | 41 +++++++++++-------- .../AutoStory/PokemonFRLG_AutoStoryLegs.cpp | 26 ++++++++++++ .../AutoStory/PokemonFRLG_AutoStoryLegs.h | 6 +++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.cpp | 21 ++++++++++ .../AutoStory/PokemonFRLG_AutoStoryRowSim.h | 1 + 6 files changed, 95 insertions(+), 17 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp index 997160b306..1457ccf5ef 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryEvents.cpp @@ -200,6 +200,18 @@ Outcome walk_legs(StoryEnv& env, RunState& state, const StoryStep& step){ return Pokemon::outcome_ok(to_pose(StoryPose{route->back().end.map, route->back().end.point, route->back().facing_after})); } +// A step onto a warp (a door, a mat, stairs): done only once its fade +// shows and the screen after it leaves the scene, else it fails +// (wait_out_warp()). The pose after it is the table's. +Outcome take_warp_step(StoryEnv& env, const RunState& state, const RouteStep& warp){ + env.context.wait_for_all_requests(); + const VideoSnapshot before = env.console.video().snapshot(); + step_once(env.console, env.context, warp.direction, facing_of(state.pose)); + OverworldWalkSteps::wait_out_warp(env.console, env.context, warp, before); + env.console.log(std::format("Story: the step took the warp to {}.", warp.end.map)); + return Pokemon::outcome_ok(); +} + Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ const Direction direction = arg(step, "direction"); int tiles_stepped = 1; @@ -214,6 +226,11 @@ Outcome take_step(StoryEnv& env, RunState& state, const StoryStep& step){ if (!step_into_line(env.console, env.context, direction, facing_of(state.pose), 1, TRAINER_WAIT_WATCH)){ return Pokemon::outcome_failed("no_trainer", std::format("{} s on the tile {}", TRAINER_WAIT_WATCH.count() / 1000, direction_name(direction))); } + }else if (const std::optional from = story_pose(state.pose)){ + if (const std::optional warp = warp_press(story_maps(), MapPosition{from->map, from->tile}, direction)){ + return take_warp_step(env, state, *warp); + } + step_once(env.console, env.context, direction, facing_of(state.pose)); }else{ step_once(env.console, env.context, direction, facing_of(state.pose)); } 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 c7d7a985d6..ab6be39a0f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryFaultSweep_Tests.cpp @@ -223,6 +223,29 @@ bool hide_talk_battle_trainer(std::vector& maps, const StoryStep& step) return true; } +// Row `row`'s step `c` on `sim` from `at`, recorded in `out`. Returns +// whether it failed as unscripted() and was let pass (run_row()). +bool run_row_step( + RowRun& out, OverworldSim& sim, StoryPose& at, const StoryCheckpoint& row, size_t c, + const std::optional>& scripted +){ + out.before.emplace(c, sim.state().position); + out.facing_before.emplace(c, sim.state().facing); + const size_t warps_before = sim.state().warped_from.size(); + out.failure = row_step_on_sim(sim, at, row.steps[c], row.id); + const std::vector& warped = sim.state().warped_from; + out.warped_from[c].assign(warped.begin() + warps_before, warped.end()); + const bool let_pass = unscripted(out.failure) && (!scripted || scripted->contains(c)); + if (let_pass){ + out.failure.clear(); + out.scripted.insert(c); + } + if (!out.failure.empty()){ + out.failed_at = c; + } + return let_pass; +} + // Row `row` on the sim with `script`, from its start. After a step the sim // does not play, the player is put on its pose_after, or on `landings`' // tile for it, the program going on from the pose_after either way. A @@ -246,23 +269,7 @@ RowRun run_row( }; for (size_t c = 0; c < row.steps.size() && out.failure.empty(); c++){ const StoryStep& step = row.steps[c]; - out.before.emplace(c, sim->state().position); - out.facing_before.emplace(c, sim->state().facing); - const size_t warps_before = sim->state().warped_from.size(); - out.failure = row_step_on_sim(*sim, at, step, row.id); - const std::vector& warped = sim->state().warped_from; - out.warped_from[c].assign(warped.begin() + warps_before, warped.end()); - if (!out.failure.empty()){ - out.failed_at = c; - } - const bool let_pass = unscripted(out.failure) && (!scripted || scripted->contains(c)); - if (let_pass){ - out.failure.clear(); - out.scripted.insert(c); - } - if (let_pass){ - out.failed_at.reset(); - } + const bool let_pass = run_row_step(out, *sim, at, row, c, scripted); if (!out.failure.empty() || (sim_plays(step) && !let_pass) || !step.pose_after){ continue; } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp index 420268e05a..ee0e282b4c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.cpp @@ -4,6 +4,7 @@ * */ +#include #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMap.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldSpin.h" #include "PokemonFRLG_AutoStoryLegs.h" @@ -71,6 +72,31 @@ std::optional> fixed_route( return route; } +std::optional warp_press(const std::vector& maps, const MapPosition& from, Direction direction){ + const auto map = std::find_if(maps.begin(), maps.end(), [&](const MapData& data){ return data.name == from.map; }); + if (map == maps.end() || !in_bounds(*map, from.point)){ + return std::nullopt; + } + const TilePos ahead = from.point.next(direction); + TilePos warp_tile = ahead; + if (exit_mat(*map, from.point) == direction){ + warp_tile = from.point; + }else if (!in_bounds(*map, ahead) || !((direction == Direction::NORTH && is_door(*map, ahead)) || warps_on_step(*map, ahead))){ + return std::nullopt; + } + const MapWarp* warp = warp_at(*map, warp_tile); + if (warp == nullptr){ + return std::nullopt; + } + RouteStep step; + step.direction = direction; + step.tiles = 1; + step.warps = true; + step.facing_after = direction; + step.end = MapPosition{warp->to ? warp->to->map : map->name, warp_tile}; + return step; +} + } // namespace PokemonFRLG } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h index d19c8fd42f..75f33bd28f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryLegs.h @@ -31,6 +31,12 @@ std::optional> fixed_route( const std::vector& maps, const MapPosition& start, const std::vector& legs ); +// The one-tile walk a press of `direction` from `from` makes, if it takes +// a warp: an exit mat stood on, a door ahead going north, or a warp tile +// stepped onto. Its fade and the scene after it must then be confirmed +// (OverworldWalkSteps::wait_out_warp()), not taken as walked. +std::optional warp_press(const std::vector& maps, const MapPosition& from, Direction direction); + } // 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 397b96750d..a5115687b5 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_TilePose.h" #include "PokemonFRLG_AutoStoryLegs.h" +#include "PokemonFRLG_AutoStoryPacedRoute.h" #include "PokemonFRLG_AutoStoryActions.h" #include "PokemonFRLG_AutoStoryBattleDecisions.h" #include "VideoGames/PokemonFRLG/Overworld/PokemonFRLG_OverworldMaps.h" @@ -489,6 +490,11 @@ std::string OverworldStepSim::step_ahead(const StoryStep& step){ return step_onto(step); } const Direction direction = Pokemon::story_arg(step.args, "direction"); + if (step.action.empty()){ + if (const std::optional warp = warp_press(story_maps(), MapPosition{m_at.map, m_at.tile}, direction)){ + return step_onto_warp(*warp); + } + } const auto tap = [this, direction]{ sim_step_once(m_sim, direction); }; @@ -509,6 +515,21 @@ std::string OverworldStepSim::step_ahead(const StoryStep& step){ return step_until_seen(tiles, tap, seen) ? "" : "no trainer saw the player."; } +// take_warp_step() on the sim: the step, then its fade, with a step more +// twice while none shows (wait_out_warp()). +std::string OverworldStepSim::step_onto_warp(const RouteStep& warp){ + const int warps_before = m_sim.state().warps; + sim_step_once(m_sim, warp.direction); + for (int tap = 0; tap < 2 && m_sim.state().warps == warps_before; tap++){ + sim_step_once(m_sim, warp.direction); + } + if (m_sim.state().warps == warps_before){ + return std::format("no fade in and out after stepping onto the warp to {}.", warp.end.map); + } + m_sim.watch({}, OverworldWalkSteps::AFTER_WARP); + return ""; +} + // A hop() or step_onto(): one step, ending where the table says. std::string OverworldStepSim::step_onto(const StoryStep& step){ sim_step_once(m_sim, Pokemon::story_arg(step.args, "direction")); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h index c151d60494..b4f7327504 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/AutoStory/PokemonFRLG_AutoStoryRowSim.h @@ -143,6 +143,7 @@ class OverworldStepSim : public Pokemon::TableExecutor{ std::string walk(const StoryStep& step); std::string step_ahead(const StoryStep& step); std::string step_onto(const StoryStep& step); + std::string step_onto_warp(const RouteStep& warp); std::string cut(const StoryStep& step); std::string battle(const StoryStep& step); Pokemon::StoryAction hideout_or_stub();