From 1b5fdb6ed6f63c5d8a94dc47094ba81487754c3e Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 07:31:11 -0800 Subject: [PATCH 1/8] PLZA marker walk: count steps with no distance read toward the stop 03.08's catch_more_species walked out of Wild Zone 1 (console B, 2026-11-16): the walk to the 100 stop read 109, then the marker's digits did not read for 13 s while it kept stepping, and it stopped on the first reads it took again, 37, in the city by a market stall. No Pokemon locked on there, so ten stops threw nothing. The badge 20 s in was the game's autosave on leaving the zone. MarkerDistance (replacing DistanceReads) counts each 0.6 s step since the last read taken as 3 of the distance, so a walk to a stop ends there when the digits stop reading. The 03.08 plan notes the autosave; it keeps the catches' autosave as its save. --- .../PokemonLZA/PokemonLZA_Tests.cpp | 2 + .../PokemonLZA_AutoStoryMarkerDistance.cpp | 66 +++++++++ .../PokemonLZA_AutoStoryMarkerDistance.h | 81 +++++++++++ ...kemonLZA_AutoStoryMarkerDistance_Tests.cpp | 131 ++++++++++++++++++ ...PokemonLZA_AutoStoryMarkerDistance_Tests.h | 26 ++++ .../PokemonLZA_AutoStoryMarkerWalk.cpp | 107 ++++++-------- .../Actions/PokemonLZA_AutoStoryMarkerWalk.h | 10 +- .../AutoStory/StoryData/plza-03.08.plan.json | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 4 + 9 files changed, 360 insertions(+), 69 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 49315b53f9..683a98cd49 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -29,6 +29,7 @@ #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h" @@ -67,6 +68,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStoryNewGame(database); add_tests_AutoStoryGame(database); add_tests_AutoStoryLines(database); + add_tests_AutoStoryMarkerDistance(database); add_tests_AutoStoryObjectiveMarkerReader(database); add_tests_AutoStorySceneMachine(database); add_tests_AutoStorySceneReplay(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp new file mode 100644 index 0000000000..b850817ff6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp @@ -0,0 +1,66 @@ +/* PokemonLZA AutoStory - Marker distance + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryMarkerDistance.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// A 0.6 s step covers about 3 of the marker's distance (console B, +// 2026-11-16: 109 to 42 in about 20 steps). +constexpr int STEP_COVERS = 3; + +bool near(int a, int b){ + return a >= b - 12 && a <= b + 12; +} + +} // namespace + + +bool MarkerDistance::read(int distance){ + if (m_last && !near(distance, *m_last)){ + m_rejected = m_rejected_read && near(distance, *m_rejected_read) ? m_rejected + 1 : 1; + m_rejected_read = distance; + if (m_rejected < 3){ + return false; + } + } + m_rejected_read.reset(); + m_rejected = 0; + m_last = distance; + m_steps_unread = 0; + return true; +} + +void MarkerDistance::stepped(){ + m_steps_unread++; +} + +std::optional MarkerDistance::position() const{ + if (!m_last){ + return std::nullopt; + } + const int moved = STEP_COVERS * m_steps_unread; + return m_direction == MarkerDirection::BACK ? *m_last + moved : *m_last - moved; +} + +bool MarkerDistance::reached(int stop_at) const{ + const std::optional at = position(); + if (!at){ + return false; + } + return m_direction == MarkerDirection::BACK ? *at >= stop_at : *at <= stop_at; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h new file mode 100644 index 0000000000..db98909897 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h @@ -0,0 +1,81 @@ +/* PokemonLZA AutoStory - Marker distance + * + * From: https://github.com/PokemonAutomation/ + * + * Where a walk by the objective marker is, by the marker's distance + * reads: misreads dropped, and steps taken with no read counted on from + * the last read. The marker's digits do not read for stretches (03.08 on + * console B, 2026-11-16: nothing taken for 13 s between 109 and 42), and + * a walk to a stop that went on blind walked past it and out of Wild + * Zone 1 into the city. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryMarkerDistance_H +#define PokemonAutomation_PokemonLZA_AutoStoryMarkerDistance_H + +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Which way a walk by the marker goes: on toward it (the distance drops) +// or back away from it (the distance grows). +enum class MarkerDirection{ + TOWARD, + BACK, +}; + +// Where a walk by the marker is: its distance reads, misreads dropped, +// and the 0.6 s steps taken since the last read taken. +class MarkerDistance{ +public: + explicit MarkerDistance(MarkerDirection direction) + : m_direction(direction) + {} + + // A distance read (above 0) on a look. A read more than 12 from the + // last one taken is a misread (a step covers about 3; 36 read as "3", + // 110 as "1110" on console B, 2026-11-13), unless three in a row + // agree: then the last one taken was the wrong one. Returns whether + // the read is taken. + bool read(int distance); + + // A step on, in the walk's direction: counted until the next read is + // taken. + void stepped(); + + // The last read taken, if any. + std::optional last_read() const{ + return m_last; + } + + // Where the walk is: the last read taken, moved on by 3 (what a step + // covers) for each step since it. None before a read. + std::optional position() const; + + // Steps since the last read taken. + int steps_unread() const{ + return m_steps_unread; + } + + // Whether position() is at `stop_at` or past it in the walk's + // direction. Not before a read. + bool reached(int stop_at) const; + +private: + const MarkerDirection m_direction; + std::optional m_last; + std::optional m_rejected_read; + int m_rejected = 0; + int m_steps_unread = 0; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp new file mode 100644 index 0000000000..f76ebcd241 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp @@ -0,0 +1,131 @@ +/* PokemonLZA AutoStory - Marker distance Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryMarkerDistance.h" +#include "PokemonLZA_AutoStoryMarkerDistance_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// No digits on a look: the marker shows, its distance does not read. +constexpr std::optional NO_DIGITS = std::nullopt; + + +struct StopWalkCase{ + std::string name; + struct Input{ + MarkerDirection direction = MarkerDirection::TOWARD; + int stop_at = 0; + // The distance OCR read on each look, misreads included. + std::vector> reads; + }; + Input input; + struct Expectation{ + // The look the walk stops on (1-based); none: it walks on past + // every look. + std::optional stopped_on; + std::optional position; + }; + Expectation expectation; +}; + +const StopWalkCase STOP_WALK_CASES[] = { + { + .name = "03.08's walk to 100 stops at 100 when the digits stop reading after 109", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + // console B, 2026-11-16 07:17:10 to 07:17:32: the walk went on + // blind to a read of 37, out of Wild Zone 1 into the city. + .reads = { + 120, 120, 120, NO_DIGITS, 5, 120, 120, NO_DIGITS, NO_DIGITS, NO_DIGITS, 109, + NO_DIGITS, NO_DIGITS, 1, NO_DIGITS, NO_DIGITS, NO_DIGITS, 181, 21, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, 42, 39, 37, + }, + }, + .expectation = {.stopped_on = 14, .position = 100}, + }, + { + .name = "a walk back stops on the read at its stop", + .input = {.direction = MarkerDirection::BACK, .stop_at = 100, .reads = {60, 66, 75, 84, 93, 101, 108}}, + .expectation = {.stopped_on = 6, .position = 101}, + }, + { + .name = "a walk with no distance read walks on", + .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .reads = {NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS}}, + .expectation = {.stopped_on = std::nullopt, .position = std::nullopt}, + }, +}; + +template +std::string text(const std::optional& value){ + return value ? std::to_string(*value) : "none"; +} + +// The walk's loop: a look's read, the stop checked, else a step on. +UnitTestResult check_stop_walk(const StopWalkCase& test){ + MarkerDistance distance(test.input.direction); + std::optional stopped_on; + for (size_t look = 0; look < test.input.reads.size(); look++){ + const std::optional read = test.input.reads[look]; + if (read){ + distance.read(*read); + } + if (distance.reached(test.input.stop_at)){ + stopped_on = look + 1; + break; + } + distance.stepped(); + } + const StopWalkCase::Expectation& expected = test.expectation; + if (stopped_on != expected.stopped_on || distance.position() != expected.position){ + return std::format( + "expected stopped on look {} at {}, got look {} at {}", + text(expected.stopped_on), text(expected.position), text(stopped_on), text(distance.position()) + ); + } + return true; +} + + +class StopWalkTest : public UnitTest{ +public: + explicit StopWalkTest(StopWalkCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStory - MarkerDistance: {}", test_case.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_stop_walk(m_case); + } +private: + StopWalkCase m_case; +}; + +} // namespace + + +void add_tests_AutoStoryMarkerDistance(UnitTestDatabase& database){ + for (const StopWalkCase& test : STOP_WALK_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h new file mode 100644 index 0000000000..848c3586c8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Marker distance Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryMarkerDistance_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryMarkerDistance_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers MarkerDistance's tests: walks to a stop replayed from the +// marker's distance reads, one look and one step at a time. +void add_tests_AutoStoryMarkerDistance(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp index bedf7a0bd0..053131aef3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -10,6 +10,7 @@ #include #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader.h" +#include "PokemonLZA_AutoStoryMarkerDistance.h" #include "PokemonLZA_AutoStoryMarkerWalk.h" namespace PokemonAutomation{ @@ -29,46 +30,10 @@ constexpr Milliseconds MARKER_WALK_LIMIT(90000); constexpr Milliseconds MARKER_SCENE_WAIT(15000); constexpr Milliseconds MARKER_POLL(250); -// The marker's distance reads, with misreads dropped. A read far from the -// last one is a misread: a 0.6 s step covers about 3. Below: 36 as "3" or -// 29 on console B; above: 110 as "1110" (2026-11-13), which then rejected -// every true read after it. So three agreeing reads in a row far from the -// last mean the last read was the wrong one, and they are taken. -class DistanceReads{ -public: - std::optional last() const{ - return m_last; - } - - // Whether `distance` (a read above 0) is taken as the last read. - bool accept(int distance){ - if (m_last && !near(distance, *m_last)){ - m_rejected = m_rejected_read && near(distance, *m_rejected_read) ? m_rejected + 1 : 1; - m_rejected_read = distance; - if (m_rejected < 3){ - return false; - } - } - m_rejected_read.reset(); - m_rejected = 0; - m_last = distance; - return true; - } - -private: - static bool near(int a, int b){ - return a >= b - 12 && a <= b + 12; - } - - std::optional m_last; - std::optional m_rejected_read; - int m_rejected = 0; -}; - // How one step of the walk ended. enum class MarkerStep{ WALKING, - ARRIVED, // the goal's distance read, or (no distance) an A prompt or a dialog shows + ARRIVED, // at the goal's distance (MarkerDistance::reached()), or (no distance) an A prompt or a dialog shows LOST, // the marker did not show for 12 camera turns }; @@ -76,9 +41,9 @@ enum class MarkerStep{ struct MarkerGoal{ // The distance that ends it; none: an A prompt or a dialog does. std::optional stop_at; - // Walking back away from the marker, until it reads `stop_at` or - // more; else toward it, until `stop_at` or less. - bool back = false; + // Back away from the marker, until it is `stop_at` or more; or on + // toward it, until `stop_at` or less. + MarkerDirection direction = MarkerDirection::TOWARD; }; // The walk, one look and one move at a time. @@ -88,11 +53,12 @@ class MarkerWalk{ : m_env(env) , m_backend(backend) , m_goal(goal) + , m_distance(goal.direction) {} - // The last distance taken, if any. - std::optional last() const{ - return m_reads.last(); + // Where the walk is (MarkerDistance::position()), if a distance read. + std::optional position() const{ + return m_distance.position(); } MarkerStep step(){ @@ -118,20 +84,37 @@ class MarkerWalk{ } private: - // A marker on screen with its digits: a distance read is taken (or - // dropped as a misread), then the camera turned to it and a step on. + // A marker on screen: its distance read is taken (or dropped as a + // misread); at the goal's distance, by the last read and the steps + // since, the walk ends; else the camera is turned to it and a step on. + // With the digits not read for a stretch, the steps count on from the + // last read: walking on blind took 03.08's walk to 100 past it and out + // of Wild Zone 1 (console B, 2026-11-16, 109 to 37). MarkerStep on_marker(const ObjectiveMarker& marker){ - if (marker.distance > 0 && m_reads.accept(marker.distance)){ - if (reached(marker.distance)){ - m_backend.log(std::format("[PLZA] marker walk: {} from the objective", marker.distance)); - return MarkerStep::ARRIVED; - } + const bool taken = marker.distance > 0 && m_distance.read(marker.distance); + if (reached()){ + log_arrival(); + return MarkerStep::ARRIVED; + } + if (taken){ on_distance(marker.distance); } steer_and_step(marker.x); return MarkerStep::WALKING; } + void log_arrival() const{ + const int at = *m_distance.position(); + if (m_distance.steps_unread() == 0){ + m_backend.log(std::format("[PLZA] marker walk: {} from the objective", at)); + return; + } + m_backend.log(std::format( + "[PLZA] marker walk: about {} from the objective ({} steps since the last read, {})", + at, m_distance.steps_unread(), *m_distance.last_read() + )); + } + // The marker is behind: turn the camera toward where it was last. MarkerStep look_behind(){ if (++m_unseen > 12){ @@ -141,11 +124,8 @@ class MarkerWalk{ return MarkerStep::WALKING; } - bool reached(int distance) const{ - if (!m_goal.stop_at){ - return false; - } - return m_goal.back ? distance >= *m_goal.stop_at : distance <= *m_goal.stop_at; + bool reached() const{ + return m_goal.stop_at && m_distance.reached(*m_goal.stop_at); } // A taken read toward the marker: logged when it changes; 4 reads with @@ -153,7 +133,7 @@ class MarkerWalk{ // console B 2026-11-10), which steps sideways: right, then left twice // as far, 4 at most. void on_distance(int distance){ - if (m_goal.back){ + if (m_goal.direction == MarkerDirection::BACK){ return; } if (distance < m_best){ @@ -183,14 +163,15 @@ class MarkerWalk{ const Milliseconds turn((int)(std::min(1.0, std::abs(off) * 4) * 400) + 80); pbf_move_right_joystick(m_env.context, {off > 0 ? 0.4 : -0.4, 0}, turn, /*release=*/150ms); } - const double forward = m_goal.back ? -1 : 1; + const double forward = m_goal.direction == MarkerDirection::BACK ? -1 : 1; pbf_move_left_joystick(m_env.context, /*position=*/{0, forward}, /*hold=*/600ms, /*release=*/0ms); + m_distance.stepped(); } StoryEnv& m_env; PlzaBackend& m_backend; const MarkerGoal m_goal; - DistanceReads m_reads; + MarkerDistance m_distance; int m_best = 1 << 30; int m_still = 0; int m_sidesteps = 0; @@ -228,7 +209,7 @@ bool run_marker_walk(Milliseconds limit, MarkerWalk& walk, PlzaBackend& backend) return true; } } - backend.log(std::format("[PLZA] marker walk: out of time, last read {}", walk.last().value_or(-1))); + backend.log(std::format("[PLZA] marker walk: out of time, at {}", walk.position().value_or(-1))); return false; } @@ -236,15 +217,15 @@ bool run_marker_walk(Milliseconds limit, MarkerWalk& walk, PlzaBackend& backend) std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit){ - MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .back = false}); + MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::TOWARD}); run_marker_walk(limit, walk, backend); - return walk.last(); + return walk.position(); } std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit){ - MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .back = true}); + MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::BACK}); run_marker_walk(limit, walk, backend); - return walk.last(); + return walk.position(); } Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h index 92d61c5f08..4f3d47295a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h @@ -30,15 +30,15 @@ namespace PokemonLZA{ // Fails as "objective_not_reached" when neither shows. Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend); -// Toward the objective marker, steered as walk_to_marker() is, until its -// distance reads `stop_at` or less, the marker is lost, or `limit`. -// A read more than 12 from the last is a misread, unless three in a row -// agree. Returns the last distance taken; none when none read. +// Toward the objective marker, steered as walk_to_marker() is, until it is +// `stop_at` or less away (MarkerDistance: the last read taken, less 3 for +// each step since it with no read), the marker is lost, or `limit`. +// Returns where it ended, by that count; none when no distance read. std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); // Back away from the objective marker (the stick down, toward the // camera, the camera turned back onto the marker before each step) until -// its distance reads `stop_at` or more, as walk_toward_marker() reads it. +// it is `stop_at` or more away, counted as walk_toward_marker() counts it. std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json index 6fce99c9e8..b63caaeab8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json @@ -17,7 +17,7 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends at the last catch: each catch autosaves, and the 2026-11-14 run logs showed that autosave after the catches, logged at the far-gate walk (zone_1_to_far_gate) on plza/autostory, so 03.08 is split there (03.08b walks out). Short on species, it fails inside the zone." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends at the last catch: each catch autosaves, and the 2026-11-14 run logs showed that autosave after the catches, logged at the far-gate walk (zone_1_to_far_gate) on plza/autostory, so 03.08 is split there (03.08b walks out). Short on species, it fails inside the zone. The catches' autosave stays the save (03.07's catch autosaves at after_catches, four run logs); the badge 20 s into catch_more_species on console B, 2026-11-16, was the game's autosave on leaving the zone: the walk to the 100 stop lost the marker's digits after 109, walked on blind out into the city and read 37 there, by a market stall, with no catch before it. No split: a run that stays in the zone sees no badge before its catches." } }, "execution": { diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 2095e12c13..d75c54763e 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2330,6 +2330,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp From 2ba7ab2a91783b2a67cdfa271d62b64d64e69f0a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 07:39:18 -0800 Subject: [PATCH 2/8] PLZA marker distance: take the first read only once three agree 03.08 run 2 (console B, 2026-11-16) read a lone "1" at about 135 on the walk's first look, took it as the start and ended the walk to 100 at once. A read is now taken when it is near the position (the last read moved on by the steps since), or when two of the last three reads not taken agree with it, each moved on by its steps; so the first read needs three that agree, and a lone misread among them does not hold the start back. --- .../PokemonLZA_AutoStoryMarkerDistance.cpp | 31 +++++++++++++++---- .../PokemonLZA_AutoStoryMarkerDistance.h | 27 +++++++++++----- ...kemonLZA_AutoStoryMarkerDistance_Tests.cpp | 16 ++++++++++ 3 files changed, 61 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp index b850817ff6..6f6d30ed15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp @@ -21,25 +21,44 @@ bool near(int a, int b){ return a >= b - 12 && a <= b + 12; } +// How many reads not taken a read must agree with to be taken anyway, +// and how many are kept. +constexpr size_t AGREEING_UNTAKEN = 2; +constexpr size_t UNTAKEN_KEPT = 3; + } // namespace +int MarkerDistance::moved_on(const Untaken& read) const{ + const int moved = STEP_COVERS * (m_steps - read.step); + return m_direction == MarkerDirection::BACK ? read.distance + moved : read.distance - moved; +} + bool MarkerDistance::read(int distance){ - if (m_last && !near(distance, *m_last)){ - m_rejected = m_rejected_read && near(distance, *m_rejected_read) ? m_rejected + 1 : 1; - m_rejected_read = distance; - if (m_rejected < 3){ + const std::optional at = position(); + if (!at || !near(distance, *at)){ + size_t agreeing = 0; + for (const Untaken& untaken : m_untaken){ + if (near(distance, moved_on(untaken))){ + agreeing++; + } + } + if (agreeing < AGREEING_UNTAKEN){ + if (m_untaken.size() == UNTAKEN_KEPT){ + m_untaken.erase(m_untaken.begin()); + } + m_untaken.push_back(Untaken{.distance = distance, .step = m_steps}); return false; } } - m_rejected_read.reset(); - m_rejected = 0; + m_untaken.clear(); m_last = distance; m_steps_unread = 0; return true; } void MarkerDistance::stepped(){ + m_steps++; m_steps_unread++; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h index db98909897..0ab831f167 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h @@ -15,6 +15,7 @@ #define PokemonAutomation_PokemonLZA_AutoStoryMarkerDistance_H #include +#include namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -36,11 +37,14 @@ class MarkerDistance{ : m_direction(direction) {} - // A distance read (above 0) on a look. A read more than 12 from the - // last one taken is a misread (a step covers about 3; 36 read as "3", - // 110 as "1110" on console B, 2026-11-13), unless three in a row - // agree: then the last one taken was the wrong one. Returns whether - // the read is taken. + // A distance read (above 0) on a look. It is taken when it is within + // 12 of position(), or when two of the last three reads not taken + // agree with it (each within 12, moved on by the steps since it). + // Else it is a misread (a step covers about 3; 36 read as "3", 110 as + // "1110" on console B, 2026-11-13): so the first read is taken only + // once three agree (03.08 run 2, console B 2026-11-16: a lone "1" at + // about 135 ended the walk to 100 at once), and three that agree + // replace a wrong last one. Returns whether the read is taken. bool read(int distance); // A step on, in the walk's direction: counted until the next read is @@ -66,10 +70,19 @@ class MarkerDistance{ bool reached(int stop_at) const; private: + // A read not taken, and the walk's step count when it came. + struct Untaken{ + int distance; + int step; + }; + + // `read` moved on by the steps since it. + int moved_on(const Untaken& read) const; + const MarkerDirection m_direction; std::optional m_last; - std::optional m_rejected_read; - int m_rejected = 0; + std::vector m_untaken; // the last three, oldest first + int m_steps = 0; int m_steps_unread = 0; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp index f76ebcd241..3c34ea22f3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp @@ -59,6 +59,22 @@ const StopWalkCase STOP_WALK_CASES[] = { }, .expectation = {.stopped_on = 14, .position = 100}, }, + { + .name = "03.08's walk to 100 takes no lone 1 at its start", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + // console B, 2026-11-16 07:33:56: the first look read "1" with + // the marker at about 135, and the walk stopped there at once. + .reads = {1, 135, 132, 129, 126, 123, 120, 117, 114, 111, 108, 105, 102, 99}, + }, + .expectation = {.stopped_on = 14, .position = 99}, + }, + { + .name = "a lone misread among a walk's first reads does not hold back the start", + .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .reads = {130, 7, 124, 121, 118, 115, 112, 109, 106, 103, 100}}, + .expectation = {.stopped_on = 11, .position = 100}, + }, { .name = "a walk back stops on the read at its stop", .input = {.direction = MarkerDirection::BACK, .stop_at = 100, .reads = {60, 66, 75, 84, 93, 101, 108}}, From 2ce45fad7c0e83a25c23e6355a5a05bba941b2ad Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 07:46:10 -0800 Subject: [PATCH 3/8] PLZA marker distance: no agreement past the objective; start read via MarkerDistance 03.08 run 3 read 1, 1 and 4 with the marker at 120 behind a rock; those agreed within 12 and ended the walk to 100 at once. A read not taken that, moved on, is at 0 or less now agrees with nothing. The catch steps' start read (Taunie's rocks, the walk back to the road) goes through MarkerDistance too, and the lines after a throw press B, not A, on an A prompt over the scene (a zone gate's "A Leave"). --- .../Actions/PokemonLZA_AutoStoryCatches.cpp | 19 ++------------- .../Actions/PokemonLZA_AutoStoryLines.cpp | 5 ++++ .../Actions/PokemonLZA_AutoStoryLines.h | 3 ++- .../PokemonLZA_AutoStoryLines_Tests.cpp | 10 ++++++++ .../PokemonLZA_AutoStoryMarkerDistance.cpp | 5 +++- .../PokemonLZA_AutoStoryMarkerDistance.h | 5 +++- ...kemonLZA_AutoStoryMarkerDistance_Tests.cpp | 23 +++++++++++++++++++ .../PokemonLZA_AutoStoryMarkerWalk.cpp | 18 +++++++++++++++ .../Actions/PokemonLZA_AutoStoryMarkerWalk.h | 6 +++++ 9 files changed, 74 insertions(+), 20 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp index 13dcb3bf63..fe8c261ffb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -18,7 +18,6 @@ #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BallThrow.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h" -#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader.h" #include "PokemonLZA_AutoStoryLines.h" #include "PokemonLZA_AutoStoryMarkerWalk.h" #include "PokemonLZA_AutoStoryCatches.h" @@ -331,20 +330,6 @@ std::optional walk_to_stop(StoryEnv& env, PlzaBackend& backend, std::option return walk_toward_marker(env, backend, stop, last ? STOP_WALK_LIMIT : FIRST_WALK_LIMIT); } -// The objective's distance on the screen now, if it reads. -std::optional objective_distance_now(StoryEnv& env){ - env.context.wait_for_all_requests(); - const VideoSnapshot frame = env.env.console.video().snapshot(); - if (!frame){ - return std::nullopt; - } - const std::optional marker = read_objective_marker(env.env.console, frame); - if (!marker || marker->distance <= 0){ - return std::nullopt; - } - return marker->distance; -} - // What the patrol came to: the party bar's last read, the throws. struct Patrol{ std::optional slots; @@ -402,7 +387,7 @@ Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCa // Taunie's two rocks stand between 03.07's end and the marker: a step // right first, around them (a catch's autosave can leave the save // further on). - const std::optional start = objective_distance_now(env); + const std::optional start = read_marker_distance(env, backend); if (start && *start >= 115){ pbf_move_left_joystick(env.context, /*position=*/{1, 0}, /*hold=*/Milliseconds(1000), /*release=*/Milliseconds(300)); } @@ -422,7 +407,7 @@ Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCa } Pokemon::Outcome walk_back_to_zone_road(StoryEnv& env, PlzaBackend& backend){ - std::optional at = objective_distance_now(env); + std::optional at = read_marker_distance(env, backend); for (int stop : road_stops_to_gate(at)){ backend.log(std::format("[PLZA] walk_back_to_zone_road: to {} on the road, from {}", stop, at.value_or(-1))); const bool toward = !at || stop <= *at; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp index b7e7afbbea..3cc1728d4d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp @@ -39,6 +39,11 @@ LinesPassed press_a_through_lines(PlzaBackend& backend, Milliseconds quiet, Mill backend.press(BUTTON_A, /*hold=*/160ms, /*release=*/240ms); }else if (look.when - *last_busy >= quiet){ return passed; + }else if (look.events.has(ScreenEvent::INTERACT_PROMPT)){ + // An A prompt over the scene: A acts on it, and a zone gate's + // "A Leave" takes the catches out of the zone (03.08, console + // B 2026-11-16). B leaves it. + backend.press(BUTTON_B, /*hold=*/160ms, /*release=*/240ms); } if (look.when - *start >= limit){ break; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h index 36a3f0f7c7..0d1d2308ea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h @@ -30,7 +30,8 @@ struct LinesPassed{ // A at each look, LINES_POLL apart, with a text box, the advance chevron // or a tutorial card, until none has shown for `quiet`, by the looks' -// times; `limit` at most. +// times; `limit` at most. B instead at a look with an A prompt over the +// scene (a zone gate's "A Leave"), where A would act on it. LinesPassed press_a_through_lines(PlzaBackend& backend, Milliseconds quiet, Milliseconds limit); // B, a second apart, until the party bar or a text box shows: out of a diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp index 585d0a416f..ee4454172c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp @@ -50,6 +50,11 @@ Observation nothing(Milliseconds at){ return look(/*events=*/{}, /*readings=*/{}, at); } +// An A prompt over the scene: a zone gate's "A Leave". +Observation prompt(Milliseconds at){ + return look({ScreenEvent::INTERACT_PROMPT}, /*readings=*/{}, at); +} + Observation party_bar(Milliseconds at){ return look({ScreenEvent::PLAYER_CAN_MOVE}, /*readings=*/{}, at); } @@ -96,6 +101,11 @@ const LinesCase LINES_CASES[] = { .input = {.looks = {nothing(Milliseconds(0)), nothing(Milliseconds(3000))}}, .expectation = {.text = false, .card = false, .timed_out = false, .inputs = "wait 250ms"}, }, + { + .name = "a zone gate's Leave prompt after the text gets B, not A", + .input = {.looks = {dialog(Milliseconds(0)), prompt(Milliseconds(500)), nothing(Milliseconds(3000))}}, + .expectation = {.text = true, .card = false, .timed_out = false, .inputs = "press A, wait 250ms, press B, wait 250ms"}, + }, { .name = "text past the limit times out", .input = { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp index 6f6d30ed15..d742b58f86 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp @@ -39,7 +39,10 @@ bool MarkerDistance::read(int distance){ if (!at || !near(distance, *at)){ size_t agreeing = 0; for (const Untaken& untaken : m_untaken){ - if (near(distance, moved_on(untaken))){ + // A read that, moved on, puts the walk at or past the + // objective agrees with nothing. + const int predicted = moved_on(untaken); + if (predicted > 0 && near(distance, predicted)){ agreeing++; } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h index 0ab831f167..97e9980fc4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h @@ -44,7 +44,10 @@ class MarkerDistance{ // "1110" on console B, 2026-11-13): so the first read is taken only // once three agree (03.08 run 2, console B 2026-11-16: a lone "1" at // about 135 ended the walk to 100 at once), and three that agree - // replace a wrong last one. Returns whether the read is taken. + // replace a wrong last one. A read not taken that, moved on, is at 0 + // or less agrees with none: the marker half behind a rock read 1, 1 + // and 4 while it showed 120, which agree within 12 (03.08 run 3, + // console B 2026-11-16). Returns whether the read is taken. bool read(int distance); // A step on, in the walk's direction: counted until the next read is diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp index 3c34ea22f3..ed5f079588 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp @@ -70,6 +70,29 @@ const StopWalkCase STOP_WALK_CASES[] = { }, .expectation = {.stopped_on = 14, .position = 99}, }, + { + .name = "03.08's walk to 100 takes no 1, 1, 4 at the rocks as a start", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + // console B, 2026-11-16 07:41:06 to 07:41:08: the marker showed + // 120 between Taunie's two rocks; "1", "f1F" and "{#4*" read 1, + // 1 and 4, which agreed within 12 and ended the walk at once. + .reads = {1, 1, 4, 120, 120, 117, 114, 111, 108, 105, 102, 99}, + }, + .expectation = {.stopped_on = 12, .position = 99}, + }, + { + .name = "03.08's walk to 100 takes no run of 1s at its start", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + // console B, 2026-11-16 07:33:56: "1^" read 1 on the first + // looks with the marker at about 146. + .reads = {1, 1, 1, 146, 143, 140, 137, 134, 131, 128, 125, 122, 119, 116, 113, 110, 107, 104, 101, 98}, + }, + .expectation = {.stopped_on = 20, .position = 98}, + }, { .name = "a lone misread among a walk's first reads does not hold back the start", .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .reads = {130, 7, 124, 121, 118, 115, 112, 109, 106, 103, 100}}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp index 053131aef3..c4e6d4a5bd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -228,6 +228,24 @@ std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, in return walk.position(); } +std::optional read_marker_distance(StoryEnv& env, PlzaBackend& backend){ + MarkerDistance distance(MarkerDirection::TOWARD); + for (int looks = 0; looks < 8; looks++){ + backend.scope().throw_if_cancelled(); + const Pokemon::Observation look = backend.observe(); + if (look.frame && *look.frame){ + const std::optional marker = read_objective_marker(env.env.console, *look.frame->frame); + if (marker && marker->distance > 0 && distance.read(marker->distance)){ + backend.log(std::format("[PLZA] marker distance: {}", marker->distance)); + return marker->distance; + } + } + backend.wait(MARKER_POLL); + } + backend.log("[PLZA] marker distance: no read taken in 8 looks"); + return std::nullopt; +} + Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend){ MarkerWalk walk(env, backend, MarkerGoal{}); run_marker_walk(MARKER_WALK_LIMIT, walk, backend); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h index 4f3d47295a..8e129c48f2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h @@ -41,6 +41,12 @@ std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int s // it is `stop_at` or more away, counted as walk_toward_marker() counts it. std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); +// The objective marker's distance where the player stands: up to 8 looks, +// 250 ms apart, until MarkerDistance takes a read (two of three agree). +// None when it takes none: a lone read at the start of 03.08 read 1 with +// the marker at 120, half behind a rock (console B, 2026-11-16). +std::optional read_marker_distance(StoryEnv& env, PlzaBackend& backend); + } // namespace PokemonLZA From 9004d3d563447976d4354c4a9569d9cd32f52006 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 12:36:06 -0800 Subject: [PATCH 4/8] PLZA marker walk: step only on a read taken; floor at the far gate 03.08's walk to 100 stepped on through 13 s of unread and garbage digits after 109 and came out at 37 in the city (console B, 2026-11-16). Dead reckoning is gone: the walk steps only on a distance read taken, and with none it stands, turns the camera back onto the marker and reads again. The patrol's walks toward the objective never go below 57 (60, just before the far gate, less the stop slack), and reads below it are not taken, so the lone 1 and 4 at Taunie's rocks (runs 2 and 3) give no start. The A-prompt B guard in press_a_through_lines is dropped: the walk out had no A press. The 03.08 plan drops the zone-exit autosave note: that badge was a false one on the zone walls; its start save is 03.07's after_catches autosave. --- .../Actions/PokemonLZA_AutoStoryCatches.cpp | 10 +- .../Actions/PokemonLZA_AutoStoryLines.cpp | 5 - .../Actions/PokemonLZA_AutoStoryLines.h | 3 +- .../PokemonLZA_AutoStoryLines_Tests.cpp | 10 -- .../PokemonLZA_AutoStoryMarkerDistance.cpp | 47 +++----- .../PokemonLZA_AutoStoryMarkerDistance.h | 80 ++++++-------- ...kemonLZA_AutoStoryMarkerDistance_Tests.cpp | 102 +++++++++++------- .../PokemonLZA_AutoStoryMarkerWalk.cpp | 102 +++++++++++------- .../Actions/PokemonLZA_AutoStoryMarkerWalk.h | 25 +++-- .../AutoStory/StoryData/plza-03.08.plan.json | 2 +- 10 files changed, 193 insertions(+), 193 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp index fe8c261ffb..e7025c77de 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -133,6 +133,10 @@ constexpr Milliseconds PATROL_LIMIT(600000); // How far short of a road stop still counts as there: the walk back to 60 // from nearer the gate stopped at 58 once (console B, 2026-11-14). constexpr int ROAD_STOP_SLACK = 3; +// The patrol never walks toward the objective below this, read or not: +// 60 is just before the far gate, and past it is the city (console B, +// 2026-11-16, a walk to 100 came out at 37). +constexpr int ROAD_FLOOR = ROAD_SPOTS[std::size(ROAD_SPOTS) - 1] - ROAD_STOP_SLACK; constexpr Milliseconds STOP_WALK_LIMIT(30000); // The first walk, from where 03.07 left the player, is the longest. constexpr Milliseconds FIRST_WALK_LIMIT(90000); @@ -327,7 +331,7 @@ std::optional walk_to_stop(StoryEnv& env, PlzaBackend& backend, std::option if (last && stop > *last){ return walk_back_from_marker(env, backend, stop, STOP_WALK_LIMIT); } - return walk_toward_marker(env, backend, stop, last ? STOP_WALK_LIMIT : FIRST_WALK_LIMIT); + return walk_toward_marker(env, backend, stop, ROAD_FLOOR, last ? STOP_WALK_LIMIT : FIRST_WALK_LIMIT); } // What the patrol came to: the party bar's last read, the throws. @@ -387,7 +391,7 @@ Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCa // Taunie's two rocks stand between 03.07's end and the marker: a step // right first, around them (a catch's autosave can leave the save // further on). - const std::optional start = read_marker_distance(env, backend); + const std::optional start = read_marker_distance(env, backend, ROAD_FLOOR); if (start && *start >= 115){ pbf_move_left_joystick(env.context, /*position=*/{1, 0}, /*hold=*/Milliseconds(1000), /*release=*/Milliseconds(300)); } @@ -407,7 +411,7 @@ Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCa } Pokemon::Outcome walk_back_to_zone_road(StoryEnv& env, PlzaBackend& backend){ - std::optional at = read_marker_distance(env, backend); + std::optional at = read_marker_distance(env, backend, std::nullopt); for (int stop : road_stops_to_gate(at)){ backend.log(std::format("[PLZA] walk_back_to_zone_road: to {} on the road, from {}", stop, at.value_or(-1))); const bool toward = !at || stop <= *at; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp index 3cc1728d4d..b7e7afbbea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.cpp @@ -39,11 +39,6 @@ LinesPassed press_a_through_lines(PlzaBackend& backend, Milliseconds quiet, Mill backend.press(BUTTON_A, /*hold=*/160ms, /*release=*/240ms); }else if (look.when - *last_busy >= quiet){ return passed; - }else if (look.events.has(ScreenEvent::INTERACT_PROMPT)){ - // An A prompt over the scene: A acts on it, and a zone gate's - // "A Leave" takes the catches out of the zone (03.08, console - // B 2026-11-16). B leaves it. - backend.press(BUTTON_B, /*hold=*/160ms, /*release=*/240ms); } if (look.when - *start >= limit){ break; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h index 0d1d2308ea..36a3f0f7c7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h @@ -30,8 +30,7 @@ struct LinesPassed{ // A at each look, LINES_POLL apart, with a text box, the advance chevron // or a tutorial card, until none has shown for `quiet`, by the looks' -// times; `limit` at most. B instead at a look with an A prompt over the -// scene (a zone gate's "A Leave"), where A would act on it. +// times; `limit` at most. LinesPassed press_a_through_lines(PlzaBackend& backend, Milliseconds quiet, Milliseconds limit); // B, a second apart, until the party bar or a text box shows: out of a diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp index ee4454172c..585d0a416f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp @@ -50,11 +50,6 @@ Observation nothing(Milliseconds at){ return look(/*events=*/{}, /*readings=*/{}, at); } -// An A prompt over the scene: a zone gate's "A Leave". -Observation prompt(Milliseconds at){ - return look({ScreenEvent::INTERACT_PROMPT}, /*readings=*/{}, at); -} - Observation party_bar(Milliseconds at){ return look({ScreenEvent::PLAYER_CAN_MOVE}, /*readings=*/{}, at); } @@ -101,11 +96,6 @@ const LinesCase LINES_CASES[] = { .input = {.looks = {nothing(Milliseconds(0)), nothing(Milliseconds(3000))}}, .expectation = {.text = false, .card = false, .timed_out = false, .inputs = "wait 250ms"}, }, - { - .name = "a zone gate's Leave prompt after the text gets B, not A", - .input = {.looks = {dialog(Milliseconds(0)), prompt(Milliseconds(500)), nothing(Milliseconds(3000))}}, - .expectation = {.text = true, .card = false, .timed_out = false, .inputs = "press A, wait 250ms, press B, wait 250ms"}, - }, { .name = "text past the limit times out", .input = { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp index d742b58f86..713c908100 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp @@ -4,6 +4,7 @@ * */ +#include #include "PokemonLZA_AutoStoryMarkerDistance.h" namespace PokemonAutomation{ @@ -13,10 +14,6 @@ namespace PokemonLZA{ namespace{ -// A 0.6 s step covers about 3 of the marker's distance (console B, -// 2026-11-16: 109 to 42 in about 20 steps). -constexpr int STEP_COVERS = 3; - bool near(int a, int b){ return a >= b - 12 && a <= b + 12; } @@ -29,20 +26,14 @@ constexpr size_t UNTAKEN_KEPT = 3; } // namespace -int MarkerDistance::moved_on(const Untaken& read) const{ - const int moved = STEP_COVERS * (m_steps - read.step); - return m_direction == MarkerDirection::BACK ? read.distance + moved : read.distance - moved; -} - bool MarkerDistance::read(int distance){ - const std::optional at = position(); - if (!at || !near(distance, *at)){ + if (m_floor && distance < *m_floor){ + return false; + } + if (!m_last || !near(distance, *m_last)){ size_t agreeing = 0; - for (const Untaken& untaken : m_untaken){ - // A read that, moved on, puts the walk at or past the - // objective agrees with nothing. - const int predicted = moved_on(untaken); - if (predicted > 0 && near(distance, predicted)){ + for (int untaken : m_untaken){ + if (near(distance, untaken)){ agreeing++; } } @@ -50,35 +41,27 @@ bool MarkerDistance::read(int distance){ if (m_untaken.size() == UNTAKEN_KEPT){ m_untaken.erase(m_untaken.begin()); } - m_untaken.push_back(Untaken{.distance = distance, .step = m_steps}); + m_untaken.push_back(distance); return false; } } m_untaken.clear(); m_last = distance; - m_steps_unread = 0; return true; } -void MarkerDistance::stepped(){ - m_steps++; - m_steps_unread++; -} - -std::optional MarkerDistance::position() const{ - if (!m_last){ - return std::nullopt; +MarkerMove MarkerDistance::next(std::optional distance, int stop_at){ + if (!distance || !read(*distance)){ + return MarkerMove::RECENTER; } - const int moved = STEP_COVERS * m_steps_unread; - return m_direction == MarkerDirection::BACK ? *m_last + moved : *m_last - moved; + return reached(stop_at) ? MarkerMove::ARRIVED : MarkerMove::STEP; } bool MarkerDistance::reached(int stop_at) const{ - const std::optional at = position(); - if (!at){ - return false; + if (m_direction == MarkerDirection::BACK){ + return *m_last >= stop_at; } - return m_direction == MarkerDirection::BACK ? *at >= stop_at : *at <= stop_at; + return *m_last <= std::max(stop_at, m_floor.value_or(stop_at)); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h index 97e9980fc4..9db6beb9c2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h @@ -3,11 +3,11 @@ * From: https://github.com/PokemonAutomation/ * * Where a walk by the objective marker is, by the marker's distance - * reads: misreads dropped, and steps taken with no read counted on from - * the last read. The marker's digits do not read for stretches (03.08 on - * console B, 2026-11-16: nothing taken for 13 s between 109 and 42), and - * a walk to a stop that went on blind walked past it and out of Wild - * Zone 1 into the city. + * reads with misreads dropped, and whether it steps on. It steps only on + * a read taken: with none, it stands, re-centers the camera on the marker + * and reads again. On 03.08's walk to 100 (console B, 2026-11-16) the + * digits read 109, then nothing or garbage for 13 s while the walk kept + * stepping, and it came out at 37 in the city, through the far gate. * */ @@ -29,64 +29,50 @@ enum class MarkerDirection{ BACK, }; -// Where a walk by the marker is: its distance reads, misreads dropped, -// and the 0.6 s steps taken since the last read taken. +// What a walk by the marker does after a look. +enum class MarkerMove{ + STEP, // a read taken, the stop not reached: a step on + RECENTER, // no read taken on this look: stand, re-center, read again + ARRIVED, // a read taken at the stop (or, toward, at the floor) +}; + +// Where a walk by the marker is: its last distance read taken. class MarkerDistance{ public: - explicit MarkerDistance(MarkerDirection direction) + // `floor`: reads below it are never taken, and a walk toward the + // objective ends at it. + MarkerDistance(MarkerDirection direction, std::optional floor) : m_direction(direction) + , m_floor(floor) {} - // A distance read (above 0) on a look. It is taken when it is within - // 12 of position(), or when two of the last three reads not taken - // agree with it (each within 12, moved on by the steps since it). - // Else it is a misread (a step covers about 3; 36 read as "3", 110 as - // "1110" on console B, 2026-11-13): so the first read is taken only - // once three agree (03.08 run 2, console B 2026-11-16: a lone "1" at - // about 135 ended the walk to 100 at once), and three that agree - // replace a wrong last one. A read not taken that, moved on, is at 0 - // or less agrees with none: the marker half behind a rock read 1, 1 - // and 4 while it showed 120, which agree within 12 (03.08 run 3, - // console B 2026-11-16). Returns whether the read is taken. + // A distance read (above 0) on a look. Below the floor it is not + // taken: the marker half behind Taunie's rocks read 1, 1 and 4 at + // the start of 03.08 while it showed 120 (runs 2 and 3, console B + // 2026-11-16). Else it is taken when within 12 of position(), or when + // two of the last three reads not taken agree with it (each within + // 12): so the first read is taken only once three agree, and three + // that agree replace a wrong last one (110 read as "1110" on console + // B, 2026-11-13). Returns whether the read is taken. bool read(int distance); - // A step on, in the walk's direction: counted until the next read is - // taken. - void stepped(); + // A look with `distance` read (none: no digits): STEP or ARRIVED + // only when the read is taken, ARRIVED at `stop_at` or past it in the + // walk's direction (toward: at the floor too); else RECENTER. + MarkerMove next(std::optional distance, int stop_at); // The last read taken, if any. - std::optional last_read() const{ + std::optional position() const{ return m_last; } - // Where the walk is: the last read taken, moved on by 3 (what a step - // covers) for each step since it. None before a read. - std::optional position() const; - - // Steps since the last read taken. - int steps_unread() const{ - return m_steps_unread; - } - - // Whether position() is at `stop_at` or past it in the walk's - // direction. Not before a read. - bool reached(int stop_at) const; - private: - // A read not taken, and the walk's step count when it came. - struct Untaken{ - int distance; - int step; - }; - - // `read` moved on by the steps since it. - int moved_on(const Untaken& read) const; + bool reached(int stop_at) const; const MarkerDirection m_direction; + const std::optional m_floor; std::optional m_last; - std::vector m_untaken; // the last three, oldest first - int m_steps = 0; - int m_steps_unread = 0; + std::vector m_untaken; // the last three reads not taken, oldest first }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp index ed5f079588..630abdeab6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp @@ -29,27 +29,35 @@ struct StopWalkCase{ struct Input{ MarkerDirection direction = MarkerDirection::TOWARD; int stop_at = 0; + std::optional floor; // The distance OCR read on each look, misreads included. std::vector> reads; }; Input input; struct Expectation{ - // The look the walk stops on (1-based); none: it walks on past - // every look. - std::optional stopped_on; + // The look the walk arrives on (1-based); none: it never does. + std::optional arrived_on; std::optional position; + // The steps on, toward or back, before it arrived or ran out of + // looks. + int steps = 0; }; Expectation expectation; }; +// Wild Zone 1's floor: 3 short of the stop at 60, just before the far gate. +constexpr int ZONE_FLOOR = 57; + const StopWalkCase STOP_WALK_CASES[] = { { - .name = "03.08's walk to 100 stops at 100 when the digits stop reading after 109", + .name = "03.08's walk to 100 stands and re-reads when the digits stop reading after 109", .input = { .direction = MarkerDirection::TOWARD, .stop_at = 100, - // console B, 2026-11-16 07:17:10 to 07:17:32: the walk went on - // blind to a read of 37, out of Wild Zone 1 into the city. + .floor = ZONE_FLOOR, + // console B, 2026-11-16 07:17:10 to 07:17:32: the walk stepped + // on through the unread and garbage looks to a read of 37, out + // of Wild Zone 1 through the far gate into the city. .reads = { 120, 120, 120, NO_DIGITS, 5, 120, 120, NO_DIGITS, NO_DIGITS, NO_DIGITS, 109, NO_DIGITS, NO_DIGITS, 1, NO_DIGITS, NO_DIGITS, NO_DIGITS, 181, 21, @@ -57,56 +65,67 @@ const StopWalkCase STOP_WALK_CASES[] = { NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, 42, 39, 37, }, }, - .expectation = {.stopped_on = 14, .position = 100}, + .expectation = {.arrived_on = std::nullopt, .position = 109, .steps = 4}, + }, + { + .name = "03.08's walk to 100 goes on to 100 once the digits read again after the garbage", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + .floor = ZONE_FLOOR, + .reads = {120, 120, 120, 109, NO_DIGITS, 1, 181, 21, NO_DIGITS, 109, 106, 103, 100}, + }, + .expectation = {.arrived_on = 13, .position = 100, .steps = 5}, }, { .name = "03.08's walk to 100 takes no lone 1 at its start", .input = { .direction = MarkerDirection::TOWARD, .stop_at = 100, + .floor = ZONE_FLOOR, // console B, 2026-11-16 07:33:56: the first look read "1" with // the marker at about 135, and the walk stopped there at once. - .reads = {1, 135, 132, 129, 126, 123, 120, 117, 114, 111, 108, 105, 102, 99}, + .reads = {1, 135, 135, 135, 132, 129, 126, 123, 120, 117, 114, 111, 108, 105, 102, 99}, }, - .expectation = {.stopped_on = 14, .position = 99}, + .expectation = {.arrived_on = 16, .position = 99, .steps = 12}, }, { .name = "03.08's walk to 100 takes no 1, 1, 4 at the rocks as a start", .input = { .direction = MarkerDirection::TOWARD, .stop_at = 100, + .floor = ZONE_FLOOR, // console B, 2026-11-16 07:41:06 to 07:41:08: the marker showed // 120 between Taunie's two rocks; "1", "f1F" and "{#4*" read 1, - // 1 and 4, which agreed within 12 and ended the walk at once. - .reads = {1, 1, 4, 120, 120, 117, 114, 111, 108, 105, 102, 99}, + // 1 and 4, and the walk ended at once. + .reads = {1, 1, 4, 120, 120, 120, 117, 114, 111, 108, 105, 102, 99}, }, - .expectation = {.stopped_on = 12, .position = 99}, + .expectation = {.arrived_on = 13, .position = 99, .steps = 7}, }, { - .name = "03.08's walk to 100 takes no run of 1s at its start", - .input = { - .direction = MarkerDirection::TOWARD, - .stop_at = 100, - // console B, 2026-11-16 07:33:56: "1^" read 1 on the first - // looks with the marker at about 146. - .reads = {1, 1, 1, 146, 143, 140, 137, 134, 131, 128, 125, 122, 119, 116, 113, 110, 107, 104, 101, 98}, - }, - .expectation = {.stopped_on = 20, .position = 98}, + .name = "03.08's start reads of 1, 1 and 4 at the rocks give no position", + .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {1, 1, 4, 1, 4}}, + .expectation = {.arrived_on = std::nullopt, .position = std::nullopt, .steps = 0}, + }, + { + .name = "a walk toward stops at its floor on reads that agree below the stop", + .input = {.direction = MarkerDirection::TOWARD, .stop_at = 40, .floor = ZONE_FLOOR, .reads = {70, 70, 70, 64, 60, 57, 54}}, + .expectation = {.arrived_on = 6, .position = 57, .steps = 3}, }, { .name = "a lone misread among a walk's first reads does not hold back the start", - .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .reads = {130, 7, 124, 121, 118, 115, 112, 109, 106, 103, 100}}, - .expectation = {.stopped_on = 11, .position = 100}, + .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {130, 7, 130, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100}}, + .expectation = {.arrived_on = 14, .position = 100, .steps = 10}, }, { .name = "a walk back stops on the read at its stop", - .input = {.direction = MarkerDirection::BACK, .stop_at = 100, .reads = {60, 66, 75, 84, 93, 101, 108}}, - .expectation = {.stopped_on = 6, .position = 101}, + .input = {.direction = MarkerDirection::BACK, .stop_at = 100, .floor = std::nullopt, .reads = {49, 49, 49, 55, 62, 70, 79, 88, 96, 101}}, + .expectation = {.arrived_on = 10, .position = 101, .steps = 7}, }, { - .name = "a walk with no distance read walks on", - .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .reads = {NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS}}, - .expectation = {.stopped_on = std::nullopt, .position = std::nullopt}, + .name = "a walk with no distance read never steps", + .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS}}, + .expectation = {.arrived_on = std::nullopt, .position = std::nullopt, .steps = 0}, }, }; @@ -115,26 +134,27 @@ std::string text(const std::optional& value){ return value ? std::to_string(*value) : "none"; } -// The walk's loop: a look's read, the stop checked, else a step on. +// The walk's loop: each look's read decides a step, a re-read or the end. UnitTestResult check_stop_walk(const StopWalkCase& test){ - MarkerDistance distance(test.input.direction); - std::optional stopped_on; + MarkerDistance distance(test.input.direction, test.input.floor); + std::optional arrived_on; + int steps = 0; for (size_t look = 0; look < test.input.reads.size(); look++){ - const std::optional read = test.input.reads[look]; - if (read){ - distance.read(*read); - } - if (distance.reached(test.input.stop_at)){ - stopped_on = look + 1; + const MarkerMove move = distance.next(test.input.reads[look], test.input.stop_at); + if (move == MarkerMove::ARRIVED){ + arrived_on = look + 1; break; } - distance.stepped(); + if (move == MarkerMove::STEP){ + steps++; + } } const StopWalkCase::Expectation& expected = test.expectation; - if (stopped_on != expected.stopped_on || distance.position() != expected.position){ + if (arrived_on != expected.arrived_on || distance.position() != expected.position || steps != expected.steps){ return std::format( - "expected stopped on look {} at {}, got look {} at {}", - text(expected.stopped_on), text(expected.position), text(stopped_on), text(distance.position()) + "expected arrived on look {} at {} after {} steps, got look {} at {} after {} steps", + text(expected.arrived_on), text(expected.position), expected.steps, + text(arrived_on), text(distance.position()), steps ); } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp index c4e6d4a5bd..f440b6416f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -33,7 +33,7 @@ constexpr Milliseconds MARKER_POLL(250); // How one step of the walk ended. enum class MarkerStep{ WALKING, - ARRIVED, // at the goal's distance (MarkerDistance::reached()), or (no distance) an A prompt or a dialog shows + ARRIVED, // at the goal's distance (MarkerMove::ARRIVED), or (no distance) an A prompt or a dialog shows LOST, // the marker did not show for 12 camera turns }; @@ -44,6 +44,8 @@ struct MarkerGoal{ // Back away from the marker, until it is `stop_at` or more; or on // toward it, until `stop_at` or less. MarkerDirection direction = MarkerDirection::TOWARD; + // Reads below it are not taken; a walk toward ends at it. + std::optional floor; }; // The walk, one look and one move at a time. @@ -53,10 +55,10 @@ class MarkerWalk{ : m_env(env) , m_backend(backend) , m_goal(goal) - , m_distance(goal.direction) + , m_distance(goal.direction, goal.floor) {} - // Where the walk is (MarkerDistance::position()), if a distance read. + // The last distance read taken, if any. std::optional position() const{ return m_distance.position(); } @@ -84,35 +86,53 @@ class MarkerWalk{ } private: - // A marker on screen: its distance read is taken (or dropped as a - // misread); at the goal's distance, by the last read and the steps - // since, the walk ends; else the camera is turned to it and a step on. - // With the digits not read for a stretch, the steps count on from the - // last read: walking on blind took 03.08's walk to 100 past it and out - // of Wild Zone 1 (console B, 2026-11-16, 109 to 37). + // A marker on screen. With no distance to stop at (the walk ends at a + // prompt), a read taken counts toward a held-up walk, and the camera + // is turned to it and a step on. Else its read decides + // (MarkerDistance): a step on only on a read taken; with none, the + // walk stands, turns the camera back onto the marker and reads again. + // Stepping on blind took 03.08's walk to 100 from 109 out through the + // far gate of Wild Zone 1 (console B, 2026-11-16, 37 by a market + // stall). MarkerStep on_marker(const ObjectiveMarker& marker){ - const bool taken = marker.distance > 0 && m_distance.read(marker.distance); - if (reached()){ - log_arrival(); - return MarkerStep::ARRIVED; + if (!m_goal.stop_at){ + if (marker.distance > 0 && m_distance.read(marker.distance)){ + on_distance(marker.distance); + } + steer(marker.x); + step_on(); + return MarkerStep::WALKING; } - if (taken){ - on_distance(marker.distance); + const std::optional read = marker.distance > 0 ? std::optional(marker.distance) : std::nullopt; + switch (m_distance.next(read, *m_goal.stop_at)){ + case MarkerMove::ARRIVED: + m_backend.log(std::format("[PLZA] marker walk: {} from the objective", *m_distance.position())); + return MarkerStep::ARRIVED; + case MarkerMove::RECENTER: + recenter(marker, read); + return MarkerStep::WALKING; + case MarkerMove::STEP: + break; } - steer_and_step(marker.x); + m_unread = 0; + on_distance(marker.distance); + steer(marker.x); + step_on(); return MarkerStep::WALKING; } - void log_arrival() const{ - const int at = *m_distance.position(); - if (m_distance.steps_unread() == 0){ - m_backend.log(std::format("[PLZA] marker walk: {} from the objective", at)); - return; + // No read taken on this look: the camera back onto the marker, no + // step, a look again after MARKER_POLL. Logged at the first look of a + // stretch and every 8th. + void recenter(const ObjectiveMarker& marker, std::optional read){ + if (m_unread++ % 8 == 0){ + m_backend.log(std::format( + "[PLZA] marker walk: no distance taken (read {}, at {}): standing, re-centering", + read.value_or(-1), m_distance.position().value_or(-1) + )); } - m_backend.log(std::format( - "[PLZA] marker walk: about {} from the objective ({} steps since the last read, {})", - at, m_distance.steps_unread(), *m_distance.last_read() - )); + steer(marker.x); + m_backend.wait(MARKER_POLL); } // The marker is behind: turn the camera toward where it was last. @@ -124,10 +144,6 @@ class MarkerWalk{ return MarkerStep::WALKING; } - bool reached() const{ - return m_goal.stop_at && m_distance.reached(*m_goal.stop_at); - } - // A taken read toward the marker: logged when it changes; 4 reads with // no new best is a walk held up (the Research Lab's front fence, // console B 2026-11-10), which steps sideways: right, then left twice @@ -153,19 +169,22 @@ class MarkerWalk{ m_sidesteps++; } - // Turns the camera toward the marker at `x` (0 to 1) and walks 0.6 s - // on, or back toward the camera. Walking back turns the camera, so it - // is turned back onto the marker before each step: unsteered, the walk - // from 60 to 100 bent off Wild Zone 1's road (console B, 2026-11-14). - void steer_and_step(double x){ + // Turns the camera toward the marker at `x` (0 to 1). Walking back + // turns the camera, so it is turned back onto the marker before each + // step: unsteered, the walk from 60 to 100 bent off Wild Zone 1's road + // (console B, 2026-11-14). + void steer(double x){ const double off = x - 0.5; if (off > 0.06 || off < -0.06){ const Milliseconds turn((int)(std::min(1.0, std::abs(off) * 4) * 400) + 80); pbf_move_right_joystick(m_env.context, {off > 0 ? 0.4 : -0.4, 0}, turn, /*release=*/150ms); } + } + + // 0.6 s on, or back toward the camera. + void step_on(){ const double forward = m_goal.direction == MarkerDirection::BACK ? -1 : 1; pbf_move_left_joystick(m_env.context, /*position=*/{0, forward}, /*hold=*/600ms, /*release=*/0ms); - m_distance.stepped(); } StoryEnv& m_env; @@ -176,6 +195,7 @@ class MarkerWalk{ int m_still = 0; int m_sidesteps = 0; int m_unseen = 0; + int m_unread = 0; double m_last_x = 0.5; }; @@ -209,27 +229,27 @@ bool run_marker_walk(Milliseconds limit, MarkerWalk& walk, PlzaBackend& backend) return true; } } - backend.log(std::format("[PLZA] marker walk: out of time, at {}", walk.position().value_or(-1))); + backend.log(std::format("[PLZA] marker walk: out of time, last read taken {}", walk.position().value_or(-1))); return false; } } // namespace -std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit){ - MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::TOWARD}); +std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, int floor, Milliseconds limit){ + MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::TOWARD, .floor = floor}); run_marker_walk(limit, walk, backend); return walk.position(); } std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit){ - MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::BACK}); + MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::BACK, .floor = std::nullopt}); run_marker_walk(limit, walk, backend); return walk.position(); } -std::optional read_marker_distance(StoryEnv& env, PlzaBackend& backend){ - MarkerDistance distance(MarkerDirection::TOWARD); +std::optional read_marker_distance(StoryEnv& env, PlzaBackend& backend, std::optional floor){ + MarkerDistance distance(MarkerDirection::TOWARD, floor); for (int looks = 0; looks < 8; looks++){ backend.scope().throw_if_cancelled(); const Pokemon::Observation look = backend.observe(); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h index 8e129c48f2..36f0872a51 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h @@ -30,23 +30,26 @@ namespace PokemonLZA{ // Fails as "objective_not_reached" when neither shows. Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend); -// Toward the objective marker, steered as walk_to_marker() is, until it is -// `stop_at` or less away (MarkerDistance: the last read taken, less 3 for -// each step since it with no read), the marker is lost, or `limit`. -// Returns where it ended, by that count; none when no distance read. -std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); +// Toward the objective marker, steered as walk_to_marker() is, until a +// distance read taken (MarkerDistance) is `stop_at` or less, or `floor` +// or less, the marker is lost, or `limit`. It steps only on a read taken: +// with none, it stands, turns the camera back onto the marker and reads +// again. Reads below `floor` are never taken. Returns the last read +// taken; none when none was. +std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, int floor, Milliseconds limit); // Back away from the objective marker (the stick down, toward the // camera, the camera turned back onto the marker before each step) until -// it is `stop_at` or more away, counted as walk_toward_marker() counts it. +// a read taken is `stop_at` or more, stepping only on reads taken as +// walk_toward_marker() does. std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); // The objective marker's distance where the player stands: up to 8 looks, -// 250 ms apart, until MarkerDistance takes a read (two of three agree). -// None when it takes none: a lone read at the start of 03.08 read 1 with -// the marker at 120, half behind a rock (console B, 2026-11-16). -std::optional read_marker_distance(StoryEnv& env, PlzaBackend& backend); - +// 250 ms apart, until MarkerDistance takes a read (two of three agree, +// none below `floor`). None when it takes none: the marker half behind a +// rock read 1, 1 and 4 at the start of 03.08 with the marker at 120 +// (console B, 2026-11-16). +std::optional read_marker_distance(StoryEnv& env, PlzaBackend& backend, std::optional floor); } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json index b63caaeab8..3aa522fc7e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json @@ -17,7 +17,7 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends at the last catch: each catch autosaves, and the 2026-11-14 run logs showed that autosave after the catches, logged at the far-gate walk (zone_1_to_far_gate) on plza/autostory, so 03.08 is split there (03.08b walks out). Short on species, it fails inside the zone. The catches' autosave stays the save (03.07's catch autosaves at after_catches, four run logs); the badge 20 s into catch_more_species on console B, 2026-11-16, was the game's autosave on leaving the zone: the walk to the 100 stop lost the marker's digits after 109, walked on blind out into the city and read 37 there, by a market stall, with no catch before it. No split: a run that stays in the zone sees no badge before its catches." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends at the last catch: each catch autosaves, and the 2026-11-14 run logs showed that autosave after the catches, logged at the far-gate walk (zone_1_to_far_gate) on plza/autostory, so 03.08 is split there (03.08b walks out). Short on species, it fails inside the zone. Its start save is 03.07's after_catches autosave: runs 2 and 3 on console B, 2026-11-16, reloaded the latest save at Taunie's rocks inside the zone." } }, "execution": { From a2e05a47699ddebc8ae03d3d6aa46f304edc66ea Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 12:51:53 -0800 Subject: [PATCH 5/8] PLZA marker walk: nudge the camera, then sidestep, when the read is blocked Run 4 of 03.08 (console B, 2026-11-16) stood with the marker's digits under an NPC's speech bubble; re-centering put the marker right back under it. MarkerDistance now answers every third look in a row with no read taken with a new view: the camera nudged left, then right (the marker kept 0.12 of the width off the middle, by its own x), then a short sidestep across the line to the marker, left then right, out to two steps each side. After those it is BLOCKED and the walk ends, logged, without a step on. Every nudge and sidestep is logged. --- .../PokemonLZA_AutoStoryMarkerDistance.cpp | 32 +++++- .../PokemonLZA_AutoStoryMarkerDistance.h | 26 ++++- ...kemonLZA_AutoStoryMarkerDistance_Tests.cpp | 91 ++++++++++++--- .../PokemonLZA_AutoStoryMarkerWalk.cpp | 104 ++++++++++++++---- .../Actions/PokemonLZA_AutoStoryMarkerWalk.h | 6 +- 5 files changed, 217 insertions(+), 42 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp index 713c908100..2e0cd2ef1d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "PokemonLZA_AutoStoryMarkerDistance.h" namespace PokemonAutomation{ @@ -23,6 +24,22 @@ bool near(int a, int b){ constexpr size_t AGREEING_UNTAKEN = 2; constexpr size_t UNTAKEN_KEPT = 3; +// The looks in a row with no read taken that each new view gets, and the +// views in turn; after the last, the walk is blocked. +constexpr size_t LOOKS_PER_VIEW = 3; +constexpr MarkerMove NEW_VIEWS[] = { + MarkerMove::NUDGE_CAMERA_LEFT, + MarkerMove::NUDGE_CAMERA_RIGHT, + MarkerMove::SIDESTEP_LEFT, + MarkerMove::SIDESTEP_RIGHT, + MarkerMove::SIDESTEP_LEFT, + MarkerMove::SIDESTEP_RIGHT, +}; + +bool is_nudge(MarkerMove move){ + return move == MarkerMove::NUDGE_CAMERA_LEFT || move == MarkerMove::NUDGE_CAMERA_RIGHT; +} + } // namespace @@ -52,11 +69,24 @@ bool MarkerDistance::read(int distance){ MarkerMove MarkerDistance::next(std::optional distance, int stop_at){ if (!distance || !read(*distance)){ - return MarkerMove::RECENTER; + return unread_move(); } + m_unread_looks = 0; return reached(stop_at) ? MarkerMove::ARRIVED : MarkerMove::STEP; } +MarkerMove MarkerDistance::unread_move(){ + m_unread_looks++; + const size_t views = m_unread_looks / LOOKS_PER_VIEW; + if (m_unread_looks % LOOKS_PER_VIEW != 0){ + // Between new views: a nudged camera stays, else re-centered. + return views > 0 && views <= std::size(NEW_VIEWS) && is_nudge(NEW_VIEWS[views - 1]) + ? MarkerMove::REREAD + : MarkerMove::RECENTER; + } + return views <= std::size(NEW_VIEWS) ? NEW_VIEWS[views - 1] : MarkerMove::BLOCKED; +} + bool MarkerDistance::reached(int stop_at) const{ if (m_direction == MarkerDirection::BACK){ return *m_last >= stop_at; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h index 9db6beb9c2..c6cbbb912e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h @@ -29,11 +29,24 @@ enum class MarkerDirection{ BACK, }; -// What a walk by the marker does after a look. +// What a walk by the marker does after a look. With no read taken, it +// stands and reads again, and every third look in a row with none it +// tries a new view: the camera nudged a little left, then right, then a +// short step to the side of the marker's line, left then right, each +// further out, 4 at most; then it ends. Never a step toward or away +// without a read taken: in run 4 of 03.08 (console B, 2026-11-16) an +// NPC's speech bubble sat over the marker's digits, and re-centering put +// the marker right back under it. enum class MarkerMove{ - STEP, // a read taken, the stop not reached: a step on - RECENTER, // no read taken on this look: stand, re-center, read again - ARRIVED, // a read taken at the stop (or, toward, at the floor) + STEP, // a read taken, the stop not reached: a step on + RECENTER, // no read taken: stand, the camera back onto the marker, read again + REREAD, // no read taken after a nudge: stand, the camera kept where it is, read again + NUDGE_CAMERA_LEFT, // the third look with none: the camera a little left, read again + NUDGE_CAMERA_RIGHT, + SIDESTEP_LEFT, // still none after both nudges: re-center, a short step left, read again + SIDESTEP_RIGHT, + BLOCKED, // still none after every sidestep: the walk ends + ARRIVED, // a read taken at the stop (or, toward, at the floor) }; // Where a walk by the marker is: its last distance read taken. @@ -58,7 +71,8 @@ class MarkerDistance{ // A look with `distance` read (none: no digits): STEP or ARRIVED // only when the read is taken, ARRIVED at `stop_at` or past it in the - // walk's direction (toward: at the floor too); else RECENTER. + // walk's direction (toward: at the floor too); else what the walk + // does for a new view (MarkerMove), by the looks in a row with none. MarkerMove next(std::optional distance, int stop_at); // The last read taken, if any. @@ -68,11 +82,13 @@ class MarkerDistance{ private: bool reached(int stop_at) const; + MarkerMove unread_move(); const MarkerDirection m_direction; const std::optional m_floor; std::optional m_last; std::vector m_untaken; // the last three reads not taken, oldest first + size_t m_unread_looks = 0; // looks in a row with no read taken }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp index 630abdeab6..9f434745fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp @@ -38,9 +38,12 @@ struct StopWalkCase{ // The look the walk arrives on (1-based); none: it never does. std::optional arrived_on; std::optional position; - // The steps on, toward or back, before it arrived or ran out of - // looks. + // The steps on, toward or back, before it arrived, was blocked or + // ran out of looks. int steps = 0; + // The new views tried with no read taken (nudges, sidesteps), and + // BLOCKED last when the walk ends on it. + std::vector views; }; Expectation expectation; }; @@ -48,9 +51,15 @@ struct StopWalkCase{ // Wild Zone 1's floor: 3 short of the stop at 60, just before the far gate. constexpr int ZONE_FLOOR = 57; +constexpr MarkerMove NUDGE_LEFT = MarkerMove::NUDGE_CAMERA_LEFT; +constexpr MarkerMove NUDGE_RIGHT = MarkerMove::NUDGE_CAMERA_RIGHT; +constexpr MarkerMove SIDESTEP_LEFT = MarkerMove::SIDESTEP_LEFT; +constexpr MarkerMove SIDESTEP_RIGHT = MarkerMove::SIDESTEP_RIGHT; +constexpr MarkerMove BLOCKED = MarkerMove::BLOCKED; + const StopWalkCase STOP_WALK_CASES[] = { { - .name = "03.08's walk to 100 stands and re-reads when the digits stop reading after 109", + .name = "03.08's walk to 100 stands, tries new views and ends blocked when the digits stop reading after 109", .input = { .direction = MarkerDirection::TOWARD, .stop_at = 100, @@ -65,7 +74,10 @@ const StopWalkCase STOP_WALK_CASES[] = { NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, 42, 39, 37, }, }, - .expectation = {.arrived_on = std::nullopt, .position = 109, .steps = 4}, + .expectation = { + .arrived_on = std::nullopt, .position = 109, .steps = 4, + .views = {NUDGE_LEFT, NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, BLOCKED}, + }, }, { .name = "03.08's walk to 100 goes on to 100 once the digits read again after the garbage", @@ -75,7 +87,7 @@ const StopWalkCase STOP_WALK_CASES[] = { .floor = ZONE_FLOOR, .reads = {120, 120, 120, 109, NO_DIGITS, 1, 181, 21, NO_DIGITS, 109, 106, 103, 100}, }, - .expectation = {.arrived_on = 13, .position = 100, .steps = 5}, + .expectation = {.arrived_on = 13, .position = 100, .steps = 5, .views = {NUDGE_LEFT}}, }, { .name = "03.08's walk to 100 takes no lone 1 at its start", @@ -87,7 +99,7 @@ const StopWalkCase STOP_WALK_CASES[] = { // the marker at about 135, and the walk stopped there at once. .reads = {1, 135, 135, 135, 132, 129, 126, 123, 120, 117, 114, 111, 108, 105, 102, 99}, }, - .expectation = {.arrived_on = 16, .position = 99, .steps = 12}, + .expectation = {.arrived_on = 16, .position = 99, .steps = 12, .views = {NUDGE_LEFT}}, }, { .name = "03.08's walk to 100 takes no 1, 1, 4 at the rocks as a start", @@ -100,12 +112,12 @@ const StopWalkCase STOP_WALK_CASES[] = { // 1 and 4, and the walk ended at once. .reads = {1, 1, 4, 120, 120, 120, 117, 114, 111, 108, 105, 102, 99}, }, - .expectation = {.arrived_on = 13, .position = 99, .steps = 7}, + .expectation = {.arrived_on = 13, .position = 99, .steps = 7, .views = {NUDGE_LEFT}}, }, { .name = "03.08's start reads of 1, 1 and 4 at the rocks give no position", .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {1, 1, 4, 1, 4}}, - .expectation = {.arrived_on = std::nullopt, .position = std::nullopt, .steps = 0}, + .expectation = {.arrived_on = std::nullopt, .position = std::nullopt, .steps = 0, .views = {NUDGE_LEFT}}, }, { .name = "a walk toward stops at its floor on reads that agree below the stop", @@ -115,17 +127,51 @@ const StopWalkCase STOP_WALK_CASES[] = { { .name = "a lone misread among a walk's first reads does not hold back the start", .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {130, 7, 130, 130, 127, 124, 121, 118, 115, 112, 109, 106, 103, 100}}, - .expectation = {.arrived_on = 14, .position = 100, .steps = 10}, + .expectation = {.arrived_on = 14, .position = 100, .steps = 10, .views = {NUDGE_LEFT}}, }, { .name = "a walk back stops on the read at its stop", .input = {.direction = MarkerDirection::BACK, .stop_at = 100, .floor = std::nullopt, .reads = {49, 49, 49, 55, 62, 70, 79, 88, 96, 101}}, .expectation = {.arrived_on = 10, .position = 101, .steps = 7}, }, + { + .name = "03.08's walk to 100 nudges the camera, then sidesteps, when a speech bubble hides the digits", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + .floor = ZONE_FLOOR, + // run 4, console B, 2026-11-16 12:44 to 12:46: taken at 120 and + // 114, then an NPC's bubble over the marker read nothing, 1, 4, + // 5, 7, 14 and 22; a step to the side clears it. + .reads = { + 120, 120, 120, 117, 114, + NO_DIGITS, 1, 4, 5, 7, 14, 22, NO_DIGITS, 4, + 111, 108, 105, 102, 99, + }, + }, + .expectation = {.arrived_on = 19, .position = 99, .steps = 7, .views = {NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT}}, + }, + { + .name = "a walk whose digits stay hidden ends after two nudges and four sidesteps", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 100, + .floor = ZONE_FLOOR, + .reads = { + 120, 120, 120, 114, + 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, 22, + 111, 108, + }, + }, + .expectation = { + .arrived_on = std::nullopt, .position = 114, .steps = 2, + .views = {NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, BLOCKED}, + }, + }, { .name = "a walk with no distance read never steps", .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS}}, - .expectation = {.arrived_on = std::nullopt, .position = std::nullopt, .steps = 0}, + .expectation = {.arrived_on = std::nullopt, .position = std::nullopt, .steps = 0, .views = {NUDGE_LEFT}}, }, }; @@ -134,11 +180,21 @@ std::string text(const std::optional& value){ return value ? std::to_string(*value) : "none"; } -// The walk's loop: each look's read decides a step, a re-read or the end. +std::string text(const std::vector& views){ + std::string out; + for (MarkerMove view : views){ + out += std::format("{}{}", out.empty() ? "" : ",", (int)view); + } + return std::format("{{{}}}", out); +} + +// The walk's loop: each look's read decides a step, a re-read, a new view +// or the end. UnitTestResult check_stop_walk(const StopWalkCase& test){ MarkerDistance distance(test.input.direction, test.input.floor); std::optional arrived_on; int steps = 0; + std::vector views; for (size_t look = 0; look < test.input.reads.size(); look++){ const MarkerMove move = distance.next(test.input.reads[look], test.input.stop_at); if (move == MarkerMove::ARRIVED){ @@ -147,14 +203,19 @@ UnitTestResult check_stop_walk(const StopWalkCase& test){ } if (move == MarkerMove::STEP){ steps++; + }else if (move != MarkerMove::RECENTER && move != MarkerMove::REREAD){ + views.push_back(move); + } + if (move == MarkerMove::BLOCKED){ + break; } } const StopWalkCase::Expectation& expected = test.expectation; - if (arrived_on != expected.arrived_on || distance.position() != expected.position || steps != expected.steps){ + if (arrived_on != expected.arrived_on || distance.position() != expected.position || steps != expected.steps || views != expected.views){ return std::format( - "expected arrived on look {} at {} after {} steps, got look {} at {} after {} steps", - text(expected.arrived_on), text(expected.position), expected.steps, - text(arrived_on), text(distance.position()), steps + "expected arrived on look {} at {} after {} steps and views {}, got look {} at {} after {} steps and views {}", + text(expected.arrived_on), text(expected.position), expected.steps, text(expected.views), + text(arrived_on), text(distance.position()), steps, text(views) ); } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp index f440b6416f..6443646b93 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" @@ -30,11 +31,22 @@ constexpr Milliseconds MARKER_WALK_LIMIT(90000); constexpr Milliseconds MARKER_SCENE_WAIT(15000); constexpr Milliseconds MARKER_POLL(250); +// A camera nudge (MarkerMove::NUDGE_CAMERA_*) turns the camera until the +// marker sits this far (of the screen's width) off the middle, by the +// marker's own x, so it stays well on screen (0.38 or 0.62; the game pins +// it to the edge below 0.10 and above 0.90). Not measured on console in +// degrees; about 8 if the view spans 70. +constexpr double NUDGE_OFFSET = 0.12; +// One sidestep (MarkerMove::SIDESTEP_*), the stick full left or right. +// Not measured on console: shorter than a 600 ms step on. +constexpr Milliseconds SIDESTEP_HOLD(500); + // How one step of the walk ended. enum class MarkerStep{ WALKING, ARRIVED, // at the goal's distance (MarkerMove::ARRIVED), or (no distance) an A prompt or a dialog shows LOST, // the marker did not show for 12 camera turns + BLOCKED, // no distance read taken through every new view (MarkerMove::BLOCKED) }; // Where a walk ends. @@ -90,7 +102,8 @@ class MarkerWalk{ // prompt), a read taken counts toward a held-up walk, and the camera // is turned to it and a step on. Else its read decides // (MarkerDistance): a step on only on a read taken; with none, the - // walk stands, turns the camera back onto the marker and reads again. + // walk stands and reads again, trying new views (new_view()) until + // one reads or it is blocked. // Stepping on blind took 03.08's walk to 100 from 109 out through the // far gate of Wild Zone 1 (console B, 2026-11-16, 37 by a market // stall). @@ -99,42 +112,89 @@ class MarkerWalk{ if (marker.distance > 0 && m_distance.read(marker.distance)){ on_distance(marker.distance); } - steer(marker.x); + steer(marker.x, /*aim=*/0.5); step_on(); return MarkerStep::WALKING; } const std::optional read = marker.distance > 0 ? std::optional(marker.distance) : std::nullopt; - switch (m_distance.next(read, *m_goal.stop_at)){ + const MarkerMove move = m_distance.next(read, *m_goal.stop_at); + switch (move){ case MarkerMove::ARRIVED: m_backend.log(std::format("[PLZA] marker walk: {} from the objective", *m_distance.position())); return MarkerStep::ARRIVED; - case MarkerMove::RECENTER: - recenter(marker, read); - return MarkerStep::WALKING; + case MarkerMove::BLOCKED: + m_backend.log(std::format( + "[PLZA] marker walk: blocked, no distance taken after 2 camera nudges and 4 sidesteps (read {}, at {})", + read.value_or(-1), m_distance.position().value_or(-1) + )); + return MarkerStep::BLOCKED; case MarkerMove::STEP: break; + default: + new_view(move, marker, read); + return MarkerStep::WALKING; } m_unread = 0; + m_side = 0; + m_aim = 0.5; on_distance(marker.distance); - steer(marker.x); + steer(marker.x, m_aim); step_on(); return MarkerStep::WALKING; } - // No read taken on this look: the camera back onto the marker, no - // step, a look again after MARKER_POLL. Logged at the first look of a - // stretch and every 8th. - void recenter(const ObjectiveMarker& marker, std::optional read){ + // No read taken on this look: no step on, the view `move` asks for + // (MarkerMove), the camera turned to the walk's aim, a look again + // after MARKER_POLL. Logged at the first look of a stretch, every + // 8th, and at each new view. + void new_view(MarkerMove move, const ObjectiveMarker& marker, std::optional read){ if (m_unread++ % 8 == 0){ m_backend.log(std::format( - "[PLZA] marker walk: no distance taken (read {}, at {}): standing, re-centering", + "[PLZA] marker walk: no distance taken (read {}, at {}): standing, re-reading", read.value_or(-1), m_distance.position().value_or(-1) )); } - steer(marker.x); + switch (move){ + case MarkerMove::RECENTER: + m_aim = 0.5; + break; + case MarkerMove::NUDGE_CAMERA_LEFT: + case MarkerMove::NUDGE_CAMERA_RIGHT: + // The camera turned left moves the marker right on screen. + m_aim = move == MarkerMove::NUDGE_CAMERA_LEFT ? 0.5 + NUDGE_OFFSET : 0.5 - NUDGE_OFFSET; + m_backend.log(std::format( + "[PLZA] marker walk: nudging the camera {}, the marker to {:.2f}", + move == MarkerMove::NUDGE_CAMERA_LEFT ? "left" : "right", m_aim + )); + break; + case MarkerMove::SIDESTEP_LEFT: + case MarkerMove::SIDESTEP_RIGHT: + m_aim = 0.5; + steer(marker.x, m_aim); + sidestep(move == MarkerMove::SIDESTEP_LEFT); + m_backend.wait(MARKER_POLL); + return; + default: + break; + } + steer(marker.x, m_aim); m_backend.wait(MARKER_POLL); } + // A step across the line to the marker (the camera on it), to the + // next spot out on that side of where the reads stopped: 1 left, 1 + // right, 2 left, 2 right. + void sidestep(bool left){ + const int target = left ? std::min(m_side, 0) - 1 : std::max(m_side, 0) + 1; + const int steps = std::abs(target - m_side); + m_backend.log(std::format( + "[PLZA] marker walk: sidestepping {} {} step(s), to {} {} of where the reads stopped", + left ? "left" : "right", steps, std::abs(target), target < 0 ? "left" : "right" + )); + pbf_move_left_joystick(m_env.context, /*position=*/{left ? -1.0 : 1.0, 0}, SIDESTEP_HOLD * steps, /*release=*/200ms); + m_side = target; + } + // The marker is behind: turn the camera toward where it was last. MarkerStep look_behind(){ if (++m_unseen > 12){ @@ -169,12 +229,13 @@ class MarkerWalk{ m_sidesteps++; } - // Turns the camera toward the marker at `x` (0 to 1). Walking back - // turns the camera, so it is turned back onto the marker before each - // step: unsteered, the walk from 60 to 100 bent off Wild Zone 1's road - // (console B, 2026-11-14). - void steer(double x){ - const double off = x - 0.5; + // Turns the camera until the marker at `x` (0 to 1) sits at `aim` + // (the middle, or a nudge off it). Walking back turns the camera, so + // it is turned back onto the marker before each step: unsteered, the + // walk from 60 to 100 bent off Wild Zone 1's road (console B, + // 2026-11-14). + void steer(double x, double aim){ + const double off = x - aim; if (off > 0.06 || off < -0.06){ const Milliseconds turn((int)(std::min(1.0, std::abs(off) * 4) * 400) + 80); pbf_move_right_joystick(m_env.context, {off > 0 ? 0.4 : -0.4, 0}, turn, /*release=*/150ms); @@ -196,6 +257,8 @@ class MarkerWalk{ int m_sidesteps = 0; int m_unseen = 0; int m_unread = 0; + int m_side = 0; // sidesteps right (left: below 0) of where the reads stopped + double m_aim = 0.5; // where on screen the camera keeps the marker double m_last_x = 0.5; }; @@ -225,6 +288,9 @@ bool run_marker_walk(Milliseconds limit, MarkerWalk& walk, PlzaBackend& backend) backend.log("[PLZA] marker walk: the marker did not show for 12 camera turns"); return false; } + if (step == MarkerStep::BLOCKED){ + return false; + } if (step == MarkerStep::ARRIVED){ return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h index 36f0872a51..d2504be55b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h @@ -34,8 +34,10 @@ Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend); // distance read taken (MarkerDistance) is `stop_at` or less, or `floor` // or less, the marker is lost, or `limit`. It steps only on a read taken: // with none, it stands, turns the camera back onto the marker and reads -// again. Reads below `floor` are never taken. Returns the last read -// taken; none when none was. +// again; still none, it nudges the camera a little, then sidesteps, and +// past those (MarkerMove::BLOCKED) it ends, logged, without a step on. +// Reads below `floor` are never taken. Returns the last read taken; none +// when none was. std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, int floor, Milliseconds limit); // Back away from the objective marker (the stick down, toward the From 3d0bcd7a66e78bbe3a372afb6488d025a0eeca01 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 13:17:57 -0800 Subject: [PATCH 6/8] PLZA marker walk: sidestep lanes around the marker's line; held up walking back Run 5 of 03.08 (console B, 2026-11-16) ended 7 sidesteps left, against a wall off Wild Zone 1's road: sidesteps were never undone and each stretch started left of where the last left off. MarkerDistance now gives the lane across the marker's line (1 left, 1 right, 2 left, 2 right, around the line), back to 0 after each read taken and when the walk ends; the walk steps to that lane. The walk back from 60 read 65 on every look for 15 steps back, twice, and ran out of time: the reads kept coming, the walk was held up, and held-up detection skipped walks back. MarkerDistance now treats 4 reads taken with none further on, in either direction, as held up and sidesteps to the next lane, kept until the walk is 6 further on. --- .../PokemonLZA_AutoStoryMarkerDistance.cpp | 65 +++++++++++---- .../PokemonLZA_AutoStoryMarkerDistance.h | 28 ++++++- ...kemonLZA_AutoStoryMarkerDistance_Tests.cpp | 79 ++++++++++++++++--- .../PokemonLZA_AutoStoryMarkerWalk.cpp | 57 +++++++------ .../Actions/PokemonLZA_AutoStoryMarkerWalk.h | 11 ++- 5 files changed, 187 insertions(+), 53 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp index 2e0cd2ef1d..bd1e53eb6c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.cpp @@ -25,20 +25,23 @@ constexpr size_t AGREEING_UNTAKEN = 2; constexpr size_t UNTAKEN_KEPT = 3; // The looks in a row with no read taken that each new view gets, and the -// views in turn; after the last, the walk is blocked. +// views in turn: the camera nudges, then the sidesteps; after the last, +// the walk is blocked. constexpr size_t LOOKS_PER_VIEW = 3; -constexpr MarkerMove NEW_VIEWS[] = { +constexpr MarkerMove CAMERA_NUDGES[] = { MarkerMove::NUDGE_CAMERA_LEFT, MarkerMove::NUDGE_CAMERA_RIGHT, - MarkerMove::SIDESTEP_LEFT, - MarkerMove::SIDESTEP_RIGHT, - MarkerMove::SIDESTEP_LEFT, - MarkerMove::SIDESTEP_RIGHT, }; +// The lanes (MarkerDistance::lane()) the sidesteps go to in turn, around +// the marker's line rather than from where the walk stands, so a walk +// does not drift to one side. +constexpr int SIDESTEP_LANES[] = {-1, 1, -2, 2}; +constexpr size_t NEW_VIEWS = std::size(CAMERA_NUDGES) + std::size(SIDESTEP_LANES); -bool is_nudge(MarkerMove move){ - return move == MarkerMove::NUDGE_CAMERA_LEFT || move == MarkerMove::NUDGE_CAMERA_RIGHT; -} +// Reads taken in a row with none further on that make a walk held up, +// and how much further on it then is before it leaves the held-up lane. +constexpr size_t HELD_UP_READS = 4; +constexpr int HELD_UP_CLEARED = 6; } // namespace @@ -72,7 +75,25 @@ MarkerMove MarkerDistance::next(std::optional distance, int stop_at){ return unread_move(); } m_unread_looks = 0; - return reached(stop_at) ? MarkerMove::ARRIVED : MarkerMove::STEP; + if (reached(stop_at)){ + m_lane = 0; + return MarkerMove::ARRIVED; + } + if (!m_best || progress(*m_best, *m_last) > 0){ + m_best = m_last; + m_unmoved_reads = 0; + }else if (++m_unmoved_reads >= HELD_UP_READS && m_held_ups < std::size(SIDESTEP_LANES)){ + m_unmoved_reads = 0; + m_held_at = m_best; + return sidestep_to(SIDESTEP_LANES[m_held_ups++]); + } + if (m_held_at && progress(*m_held_at, *m_best) >= HELD_UP_CLEARED){ + m_held_at.reset(); + } + if (!m_held_at){ + m_lane = 0; + } + return MarkerMove::STEP; } MarkerMove MarkerDistance::unread_move(){ @@ -80,11 +101,27 @@ MarkerMove MarkerDistance::unread_move(){ const size_t views = m_unread_looks / LOOKS_PER_VIEW; if (m_unread_looks % LOOKS_PER_VIEW != 0){ // Between new views: a nudged camera stays, else re-centered. - return views > 0 && views <= std::size(NEW_VIEWS) && is_nudge(NEW_VIEWS[views - 1]) - ? MarkerMove::REREAD - : MarkerMove::RECENTER; + return views > 0 && views <= std::size(CAMERA_NUDGES) ? MarkerMove::REREAD : MarkerMove::RECENTER; + } + if (views <= std::size(CAMERA_NUDGES)){ + return CAMERA_NUDGES[views - 1]; } - return views <= std::size(NEW_VIEWS) ? NEW_VIEWS[views - 1] : MarkerMove::BLOCKED; + if (views > NEW_VIEWS){ + m_lane = 0; + return MarkerMove::BLOCKED; + } + m_held_at.reset(); + return sidestep_to(SIDESTEP_LANES[views - 1 - std::size(CAMERA_NUDGES)]); +} + +MarkerMove MarkerDistance::sidestep_to(int lane){ + const bool left = lane < m_lane; + m_lane = lane; + return left ? MarkerMove::SIDESTEP_LEFT : MarkerMove::SIDESTEP_RIGHT; +} + +int MarkerDistance::progress(int from, int to) const{ + return m_direction == MarkerDirection::BACK ? to - from : from - to; } bool MarkerDistance::reached(int stop_at) const{ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h index c6cbbb912e..896bccaf1a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance.h @@ -32,8 +32,8 @@ enum class MarkerDirection{ // What a walk by the marker does after a look. With no read taken, it // stands and reads again, and every third look in a row with none it // tries a new view: the camera nudged a little left, then right, then a -// short step to the side of the marker's line, left then right, each -// further out, 4 at most; then it ends. Never a step toward or away +// short step to a lane beside the marker's line (lane()): 1 left, 1 +// right, 2 left, 2 right; then it ends. Never a step toward or away // without a read taken: in run 4 of 03.08 (console B, 2026-11-16) an // NPC's speech bubble sat over the marker's digits, and re-centering put // the marker right back under it. @@ -43,7 +43,7 @@ enum class MarkerMove{ REREAD, // no read taken after a nudge: stand, the camera kept where it is, read again NUDGE_CAMERA_LEFT, // the third look with none: the camera a little left, read again NUDGE_CAMERA_RIGHT, - SIDESTEP_LEFT, // still none after both nudges: re-center, a short step left, read again + SIDESTEP_LEFT, // still none after both nudges, or held up: re-center, step left to lane(), read again SIDESTEP_RIGHT, BLOCKED, // still none after every sidestep: the walk ends ARRIVED, // a read taken at the stop (or, toward, at the floor) @@ -73,6 +73,10 @@ class MarkerDistance{ // only when the read is taken, ARRIVED at `stop_at` or past it in the // walk's direction (toward: at the floor too); else what the walk // does for a new view (MarkerMove), by the looks in a row with none. + // 4 reads taken in a row with none further on in the walk's direction + // is a walk held up: a sidestep to the next lane, kept until the walk + // is 6 further on. In run 5 of 03.08 (console B, 2026-11-16) the walk + // back from 60 read 65 for 15 steps back, twice, and ran out of time. MarkerMove next(std::optional distance, int stop_at); // The last read taken, if any. @@ -80,15 +84,33 @@ class MarkerDistance{ return m_last; } + // Where the walk should stand across the marker's line, in sidesteps + // (right above 0, left below), at most 2 out. A read taken brings it + // back to 0 (but for a held-up walk's lane), and so do ARRIVED and + // BLOCKED. In run 5 of 03.08 every sidestep was kept and each new + // stretch started left, so the walk ended 7 steps left, against a + // wall off Wild Zone 1's road (console B, 2026-11-16). + int lane() const{ + return m_lane; + } + private: bool reached(int stop_at) const; + // How much further on `to` is than `from` in the walk's direction. + int progress(int from, int to) const; MarkerMove unread_move(); + MarkerMove sidestep_to(int lane); const MarkerDirection m_direction; const std::optional m_floor; std::optional m_last; std::vector m_untaken; // the last three reads not taken, oldest first size_t m_unread_looks = 0; // looks in a row with no read taken + std::optional m_best; // the furthest-on read taken + size_t m_unmoved_reads = 0; // reads taken in a row with none further on than m_best + size_t m_held_ups = 0; // held-up sidesteps so far + std::optional m_held_at; // m_best when the walk was last held up, while it keeps that lane + int m_lane = 0; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp index 9f434745fe..c3d6dd96a2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.cpp @@ -41,9 +41,12 @@ struct StopWalkCase{ // The steps on, toward or back, before it arrived, was blocked or // ran out of looks. int steps = 0; - // The new views tried with no read taken (nudges, sidesteps), and - // BLOCKED last when the walk ends on it. + // The new views tried with no read taken or held up (nudges, + // sidesteps), and BLOCKED last when the walk ends on it. std::vector views; + // The lanes across the marker's line (MarkerDistance::lane()) the + // walk moved to, in turn. + std::vector lanes; }; Expectation expectation; }; @@ -77,6 +80,7 @@ const StopWalkCase STOP_WALK_CASES[] = { .expectation = { .arrived_on = std::nullopt, .position = 109, .steps = 4, .views = {NUDGE_LEFT, NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, BLOCKED}, + .lanes = {-1, 1, -2, 2, 0}, }, }, { @@ -149,7 +153,7 @@ const StopWalkCase STOP_WALK_CASES[] = { 111, 108, 105, 102, 99, }, }, - .expectation = {.arrived_on = 19, .position = 99, .steps = 7, .views = {NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT}}, + .expectation = {.arrived_on = 19, .position = 99, .steps = 7, .views = {NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT}, .lanes = {-1, 0}}, }, { .name = "a walk whose digits stay hidden ends after two nudges and four sidesteps", @@ -166,8 +170,56 @@ const StopWalkCase STOP_WALK_CASES[] = { .expectation = { .arrived_on = std::nullopt, .position = 114, .steps = 2, .views = {NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, BLOCKED}, + .lanes = {-1, 1, -2, 2, 0}, }, }, + { + .name = "03.08's walk to 60 steps back onto the marker's line after each read taken", + .input = { + .direction = MarkerDirection::TOWARD, + .stop_at = 60, + .floor = ZONE_FLOOR, + // run 5, console B, 2026-11-16 13:06:44 to 13:07:12: each + // stretch with no read taken sidestepped from where the last + // left off, starting left, and none was undone; by the end of + // the run the walk stood 7 sidesteps left, against a wall. + .reads = { + 100, 100, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, 1, NO_DIGITS, + 100, 98, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, + 93, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, + 90, 88, 85, 82, 78, + NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS, + 72, 70, 67, 63, 60, + }, + }, + .expectation = { + .arrived_on = 54, .position = 60, .steps = 12, + .views = { + NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, SIDESTEP_RIGHT, SIDESTEP_LEFT, + NUDGE_LEFT, NUDGE_RIGHT, + NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, + NUDGE_LEFT, NUDGE_RIGHT, SIDESTEP_LEFT, + }, + .lanes = {-1, 1, -2, 0, -1, 0, -1, 0}, + }, + }, + { + .name = "03.08's walk back to 100 held up at 65 sidesteps, then goes on to 100 and back onto the line", + .input = { + .direction = MarkerDirection::BACK, + .stop_at = 100, + .floor = std::nullopt, + // run 5, console B, 2026-11-16 13:07:44 to 13:08:00: the walk + // back read 65 on every look for 15 steps back and ran out of + // time; here a step to the side gets it past. + .reads = {57, 57, 57, 59, 61, 63, 65, 65, 65, 65, 65, 66, 68, 71, 74, 77, 80, 83, 86, 89, 92, 95, 98, 101}, + }, + .expectation = {.arrived_on = 24, .position = 101, .steps = 20, .views = {SIDESTEP_LEFT}, .lanes = {-1, 0}}, + }, { .name = "a walk with no distance read never steps", .input = {.direction = MarkerDirection::TOWARD, .stop_at = 100, .floor = ZONE_FLOOR, .reads = {NO_DIGITS, NO_DIGITS, NO_DIGITS, NO_DIGITS}}, @@ -180,10 +232,11 @@ std::string text(const std::optional& value){ return value ? std::to_string(*value) : "none"; } -std::string text(const std::vector& views){ +template +std::string text(const std::vector& values){ std::string out; - for (MarkerMove view : views){ - out += std::format("{}{}", out.empty() ? "" : ",", (int)view); + for (Type value : values){ + out += std::format("{}{}", out.empty() ? "" : ",", (int)value); } return std::format("{{{}}}", out); } @@ -195,8 +248,12 @@ UnitTestResult check_stop_walk(const StopWalkCase& test){ std::optional arrived_on; int steps = 0; std::vector views; + std::vector lanes; for (size_t look = 0; look < test.input.reads.size(); look++){ const MarkerMove move = distance.next(test.input.reads[look], test.input.stop_at); + if (distance.lane() != (lanes.empty() ? 0 : lanes.back())){ + lanes.push_back(distance.lane()); + } if (move == MarkerMove::ARRIVED){ arrived_on = look + 1; break; @@ -211,11 +268,13 @@ UnitTestResult check_stop_walk(const StopWalkCase& test){ } } const StopWalkCase::Expectation& expected = test.expectation; - if (arrived_on != expected.arrived_on || distance.position() != expected.position || steps != expected.steps || views != expected.views){ + if (arrived_on != expected.arrived_on || distance.position() != expected.position || steps != expected.steps + || views != expected.views || lanes != expected.lanes + ){ return std::format( - "expected arrived on look {} at {} after {} steps and views {}, got look {} at {} after {} steps and views {}", - text(expected.arrived_on), text(expected.position), expected.steps, text(expected.views), - text(arrived_on), text(distance.position()), steps, text(views) + "expected arrived on look {} at {} after {} steps, views {} and lanes {}, got look {} at {} after {} steps, views {} and lanes {}", + text(expected.arrived_on), text(expected.position), expected.steps, text(expected.views), text(expected.lanes), + text(arrived_on), text(distance.position()), steps, text(views), text(lanes) ); } return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp index 6443646b93..30786002bc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -37,8 +37,8 @@ constexpr Milliseconds MARKER_POLL(250); // it to the edge below 0.10 and above 0.90). Not measured on console in // degrees; about 8 if the view spans 70. constexpr double NUDGE_OFFSET = 0.12; -// One sidestep (MarkerMove::SIDESTEP_*), the stick full left or right. -// Not measured on console: shorter than a 600 ms step on. +// One lane of a sidestep (MarkerMove::SIDESTEP_*), the stick full left +// or right. Not measured on console: shorter than a 600 ms step on. constexpr Milliseconds SIDESTEP_HOLD(500); // How one step of the walk ended. @@ -75,6 +75,11 @@ class MarkerWalk{ return m_distance.position(); } + // Back onto the marker's line, so the next walk starts on it. + void to_line(){ + to_lane(0); + } + MarkerStep step(){ const Pokemon::Observation look = m_backend.observe(); if (!m_goal.stop_at && (look.events.has(ScreenEvent::INTERACT_PROMPT) || look.events.has(ScreenEvent::DIALOG_BOX))){ @@ -121,12 +126,14 @@ class MarkerWalk{ switch (move){ case MarkerMove::ARRIVED: m_backend.log(std::format("[PLZA] marker walk: {} from the objective", *m_distance.position())); + to_line(); return MarkerStep::ARRIVED; case MarkerMove::BLOCKED: m_backend.log(std::format( "[PLZA] marker walk: blocked, no distance taken after 2 camera nudges and 4 sidesteps (read {}, at {})", read.value_or(-1), m_distance.position().value_or(-1) )); + to_line(); return MarkerStep::BLOCKED; case MarkerMove::STEP: break; @@ -135,10 +142,13 @@ class MarkerWalk{ return MarkerStep::WALKING; } m_unread = 0; - m_side = 0; m_aim = 0.5; - on_distance(marker.distance); + if (m_distance.position() != m_logged){ + m_logged = m_distance.position(); + m_backend.log(std::format("[PLZA] marker walk: {} to go", *m_logged)); + } steer(marker.x, m_aim); + to_lane(m_distance.lane()); step_on(); return MarkerStep::WALKING; } @@ -171,7 +181,7 @@ class MarkerWalk{ case MarkerMove::SIDESTEP_RIGHT: m_aim = 0.5; steer(marker.x, m_aim); - sidestep(move == MarkerMove::SIDESTEP_LEFT); + to_lane(m_distance.lane()); m_backend.wait(MARKER_POLL); return; default: @@ -181,18 +191,20 @@ class MarkerWalk{ m_backend.wait(MARKER_POLL); } - // A step across the line to the marker (the camera on it), to the - // next spot out on that side of where the reads stopped: 1 left, 1 - // right, 2 left, 2 right. - void sidestep(bool left){ - const int target = left ? std::min(m_side, 0) - 1 : std::max(m_side, 0) + 1; - const int steps = std::abs(target - m_side); + // Steps across the marker's line (the camera on the marker) to + // `lane` (MarkerDistance::lane()), from the lane the walk stands in. + void to_lane(int lane){ + if (lane == m_lane){ + return; + } + const bool left = lane < m_lane; + const int steps = std::abs(lane - m_lane); m_backend.log(std::format( - "[PLZA] marker walk: sidestepping {} {} step(s), to {} {} of where the reads stopped", - left ? "left" : "right", steps, std::abs(target), target < 0 ? "left" : "right" + "[PLZA] marker walk: sidestepping {} {} step(s), to lane {} (at {})", + left ? "left" : "right", steps, lane, m_distance.position().value_or(-1) )); pbf_move_left_joystick(m_env.context, /*position=*/{left ? -1.0 : 1.0, 0}, SIDESTEP_HOLD * steps, /*release=*/200ms); - m_side = target; + m_lane = lane; } // The marker is behind: turn the camera toward where it was last. @@ -204,14 +216,12 @@ class MarkerWalk{ return MarkerStep::WALKING; } - // A taken read toward the marker: logged when it changes; 4 reads with - // no new best is a walk held up (the Research Lab's front fence, - // console B 2026-11-10), which steps sideways: right, then left twice - // as far, 4 at most. + // A taken read on a walk to the objective's prompt (no stop_at; a + // walk to a stop is held up by MarkerDistance): logged when it + // changes; 4 reads with no new best is a walk held up (the Research + // Lab's front fence, console B 2026-11-10), which steps sideways: + // right, then left twice as far, 4 at most. void on_distance(int distance){ - if (m_goal.direction == MarkerDirection::BACK){ - return; - } if (distance < m_best){ m_backend.log(std::format("[PLZA] walk_to_marker: {} to go", distance)); m_best = distance; @@ -257,7 +267,8 @@ class MarkerWalk{ int m_sidesteps = 0; int m_unseen = 0; int m_unread = 0; - int m_side = 0; // sidesteps right (left: below 0) of where the reads stopped + int m_lane = 0; // the lane the walk stands in (MarkerDistance::lane()) + std::optional m_logged; // the last read taken that was logged double m_aim = 0.5; // where on screen the camera keeps the marker double m_last_x = 0.5; }; @@ -305,12 +316,14 @@ bool run_marker_walk(Milliseconds limit, MarkerWalk& walk, PlzaBackend& backend) std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, int floor, Milliseconds limit){ MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::TOWARD, .floor = floor}); run_marker_walk(limit, walk, backend); + walk.to_line(); return walk.position(); } std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit){ MarkerWalk walk(env, backend, MarkerGoal{.stop_at = stop_at, .direction = MarkerDirection::BACK, .floor = std::nullopt}); run_marker_walk(limit, walk, backend); + walk.to_line(); return walk.position(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h index d2504be55b..5795ba5a3e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h @@ -36,13 +36,16 @@ Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend); // with none, it stands, turns the camera back onto the marker and reads // again; still none, it nudges the camera a little, then sidesteps, and // past those (MarkerMove::BLOCKED) it ends, logged, without a step on. -// Reads below `floor` are never taken. Returns the last read taken; none -// when none was. +// Held up, it sidesteps too. It walks the lane MarkerDistance::lane() +// gives, back on the marker's line after each read taken, and ends on +// the line. Reads below `floor` are never taken. Returns the last read +// taken; none when none was. std::optional walk_toward_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, int floor, Milliseconds limit); // Back away from the objective marker (the stick down, toward the -// camera, the camera turned back onto the marker before each step) until -// a read taken is `stop_at` or more, stepping only on reads taken as +// camera, the camera turned back onto the marker before each step, so its +// digits keep reading) until a read taken is `stop_at` or more, stepping +// only on reads taken, sidestepping and ending on the line as // walk_toward_marker() does. std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); From 43f8ad357062b8a3925fa65686184c21444772ee Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 13:34:51 -0800 Subject: [PATCH 7/8] PLZA 03.08: search the zone by camera scans and short out-and-back legs catch_in_zone no longer walks between marker-distance stops: it turns the camera in 8 steps with a ZL lock-on after each, throws at species not caught, and takes one short leg only after a full turn finds nothing new (each leg out walked back; none toward the objective at an agreed read of 60 or less; a pause for spawns after each round). ZoneSearch holds the state and is tested by replayed scans. --- .../PokemonLZA/PokemonLZA_Tests.cpp | 2 + .../Actions/PokemonLZA_AutoStoryCatches.cpp | 275 ++++++++++++------ .../Actions/PokemonLZA_AutoStoryCatches.h | 26 +- .../PokemonLZA_AutoStoryZoneSearch.cpp | 101 +++++++ .../Actions/PokemonLZA_AutoStoryZoneSearch.h | 110 +++++++ .../PokemonLZA_AutoStoryZoneSearch_Tests.cpp | 201 +++++++++++++ .../PokemonLZA_AutoStoryZoneSearch_Tests.h | 26 ++ .../AutoStory/StoryData/plza-03.08.plan.json | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 4 + 9 files changed, 642 insertions(+), 105 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 683a98cd49..a4db4e412b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -31,6 +31,7 @@ #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerDistance_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h" @@ -73,6 +74,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStorySceneMachine(database); add_tests_AutoStorySceneReplay(database); add_tests_AutoStoryScreenEvents(database); + add_tests_AutoStoryZoneSearch(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp index e7025c77de..d07b02e152 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -5,10 +5,12 @@ */ #include +#include #include #include #include #include +#include #include #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" @@ -18,8 +20,10 @@ #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BallThrow.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader.h" #include "PokemonLZA_AutoStoryLines.h" #include "PokemonLZA_AutoStoryMarkerWalk.h" +#include "PokemonLZA_AutoStoryZoneSearch.h" #include "PokemonLZA_AutoStoryCatches.h" namespace PokemonAutomation{ @@ -120,36 +124,43 @@ Pokemon::Outcome battle_then_catch(StoryEnv& env, PlzaBackend& backend, int max_ namespace{ -// Wild Zone 1's two catch spots on its road, as distances from the -// objective marker, the user's pick (2026-11-13): 100, the plaza by the -// green advertising column (Scatterbug on the road), and 60, just before -// the far gate (Mareep in the grass right of the road). The patrol goes -// 100, 60, 100, 60, ...: walking to 100 and back brings the Pokemon at 60 -// back when none showed there. +// Wild Zone 1's two spots on its road, as distances from the objective +// marker, the user's pick (2026-11-13): 100, the plaza by the green +// advertising column, and 60, just before the far gate. +// walk_back_to_zone_road() walks back onto the road at them. constexpr int ROAD_SPOTS[] = {100, 60}; -constexpr size_t PATROL_VISITS = 10; -constexpr Milliseconds PATROL_LIMIT(600000); // How far short of a road stop still counts as there: the walk back to 60 // from nearer the gate stopped at 58 once (console B, 2026-11-14). constexpr int ROAD_STOP_SLACK = 3; -// The patrol never walks toward the objective below this, read or not: -// 60 is just before the far gate, and past it is the city (console B, +// Walks toward the objective never go below this, read or not: 60 is +// just before the far gate, and past it is the city (console B, // 2026-11-16, a walk to 100 came out at 37). constexpr int ROAD_FLOOR = ROAD_SPOTS[std::size(ROAD_SPOTS) - 1] - ROAD_STOP_SLACK; constexpr Milliseconds STOP_WALK_LIMIT(30000); -// The first walk, from where 03.07 left the player, is the longest. +// A walk with no distance read to start from is the longest. constexpr Milliseconds FIRST_WALK_LIMIT(90000); +// catch_in_zone()'s time in the zone: spawns come back, so a search that +// finds nothing new keeps going until this runs out. +constexpr Milliseconds SEARCH_LIMIT(600000); +// A scan's camera steps, the right stick full right for SCAN_STEP_TURN +// each: meant as a full turn in all; not measured on console in degrees. +constexpr size_t SCAN_STEPS = 8; +constexpr Milliseconds SCAN_STEP_TURN(300); +// One leg of the search (ZoneLeg), the left stick full one way, with the +// camera on the objective marker: a few steps into the grass, short of +// the 30 s walks that left the zone (console B, 2026-11-16). +constexpr Milliseconds LEG_HOLD(2000); +// A ZoneMove::PAUSE: standing for spawns to come back. +constexpr Milliseconds SEARCH_PAUSE(15000); + // How long ZL is held for the lock to show: over 1.5 s at times (the // user, console B 2026-11-14). constexpr Milliseconds LOCK_ON_WAIT(3000); // A full flick of the right stick with ZL held moves the lock to the next // target that way (the user, 2026-11-13). constexpr double TARGET_FLICK = 0.8; -// The looks of a stop, the camera turned right between two. -constexpr int STOP_LOOKS = 4; - // ZL held across reads of the screen: each hold is queued before the last // one ends, so ZL is never let go from the lock to the throw (throw_ball() // queues its own ZL first). @@ -207,30 +218,19 @@ class HeldZl{ WallClock m_end; }; -// What ZL locked on to at a stop. -enum class LockOn{ - NO_PLATE, - ALL_CAUGHT, // 3 flicks found only plates with the caught mark - NOT_CAUGHT, // locked on, ZL still held, to one not caught -}; - // ZL held until a plate shows (LOCK_ON_WAIT at most), then flicks on -// while it shows the caught mark (3 at most). -LockOn lock_on_not_caught(StoryEnv& env, PlzaBackend& backend){ +// while it shows the caught mark (3 at most): NO_PLATE, ALL_CAUGHT, or +// NOT_CAUGHT with ZL still held on the target. +ZoneLook lock_on_not_caught(StoryEnv& env){ HeldZl held(env); std::optional caught = held.wait_for_plate(LOCK_ON_WAIT); for (int flicks = 0; caught == true && flicks < 3; flicks++){ caught = held.flick(); } if (!caught){ - backend.log(std::format("[PLZA] catch_in_zone: ZL held {} ms, no name plate", LOCK_ON_WAIT.count())); - return LockOn::NO_PLATE; + return ZoneLook::NO_PLATE; } - if (*caught){ - backend.log("[PLZA] catch_in_zone: only species already caught lock on"); - return LockOn::ALL_CAUGHT; - } - return LockOn::NOT_CAUGHT; + return *caught ? ZoneLook::ALL_CAUGHT : ZoneLook::NOT_CAUGHT; } // A ZL lock-on and throw leave the camera looking steeply down: the @@ -260,7 +260,7 @@ int weaken_and_throw(StoryEnv& env, PlzaBackend& backend, int max_throws, Traine return throws; } -// A wild battle at the stop (a Mareep often turns on the player, the +// A wild battle on (a Mareep often turns on the player, the // user's walk on console B, 2026-11-13; Bunnelby, 2026-11-14): one of a // species already caught is fought off with no throws (3 rounds at // most); else weaken_and_throw(). Returns the throws. @@ -280,30 +280,6 @@ int fight_back(StoryEnv& env, PlzaBackend& backend, int max_throws, TrainerBattl return 0; } -// One stop: a wild battle on is fought (fight_back()); else, look by -// look (STOP_LOOKS, the camera turned right between two), a throw at the -// first target not caught (lock_on_not_caught()), then weaken_and_throw() -// when it broke out into a wild battle. Returns the throws. -int catch_at_stop(StoryEnv& env, PlzaBackend& backend, int max_throws, TrainerBattleState& battle_state){ - int throws = 0; - for (int look = 0; look < STOP_LOOKS && throws == 0 && max_throws > 0; look++){ - if (wild_battle_on(env)){ - throws += fight_back(env, backend, max_throws, battle_state); - break; - } - if (lock_on_not_caught(env, backend) != LockOn::NOT_CAUGHT){ - pbf_move_right_joystick(env.context, /*position=*/{0.5, 0}, /*hold=*/Milliseconds(400), /*release=*/Milliseconds(300)); - continue; - } - throw_ball(env.context, STORY_THROW); - throws++; - press_a_through_lines(backend, LINES_QUIET, LINES_LIMIT); - throws += weaken_and_throw(env, backend, max_throws - throws, battle_state); - } - level_camera(env); - return throws; -} - // The party bar's filled slots, when it shows within 2 s and reads a // slot; none otherwise (a text box or a fade still on). std::optional read_party_slots(StoryEnv& env, PlzaBackend& backend){ @@ -325,45 +301,169 @@ bool party_done(const std::optional& slots, const ZoneCatchGoal& goal){ return slots && *slots >= goal.party_species; } -// Walks to stop `stop` from `last` (none: from the start, further out -// than every stop): back from the objective when the stop is further. -std::optional walk_to_stop(StoryEnv& env, PlzaBackend& backend, std::optional last, int stop){ - if (last && stop > *last){ - return walk_back_from_marker(env, backend, stop, STOP_WALK_LIMIT); +std::string_view look_name(ZoneLook look){ + switch (look){ + case ZoneLook::NO_PLATE: + return "no name plate"; + case ZoneLook::ALL_CAUGHT: + return "only species already caught"; + case ZoneLook::NOT_CAUGHT: + return "a species not caught"; + case ZoneLook::WILD_BATTLE: + return "a wild battle"; } - return walk_toward_marker(env, backend, stop, ROAD_FLOOR, last ? STOP_WALK_LIMIT : FIRST_WALK_LIMIT); + return "?"; } -// What the patrol came to: the party bar's last read, the throws. -struct Patrol{ +std::string_view leg_name(ZoneLeg leg){ + switch (leg){ + case ZoneLeg::TOWARD: + return "toward the objective"; + case ZoneLeg::AWAY: + return "away from the objective"; + case ZoneLeg::LEFT: + return "left"; + case ZoneLeg::RIGHT: + return "right"; + } + return "?"; +} + +// A look at the scan's camera step: a wild battle on, else the ZL +// lock-on's plates (lock_on_not_caught()). +ZoneLook look_in_zone(StoryEnv& env){ + if (wild_battle_on(env)){ + return ZoneLook::WILD_BATTLE; + } + return lock_on_not_caught(env); +} + +// The left stick for `leg`, the camera on the objective marker. +JoystickPosition leg_stick(ZoneLeg leg){ + switch (leg){ + case ZoneLeg::TOWARD: + return {0, 1}; + case ZoneLeg::AWAY: + return {0, -1}; + case ZoneLeg::LEFT: + return {-1, 0}; + case ZoneLeg::RIGHT: + return {1, 0}; + } + return {0, 0}; +} + +// Turns the camera until the objective marker is in the middle of the +// screen, 12 turns at most. Returns whether it is. +bool face_marker(StoryEnv& env, PlzaBackend& backend){ + for (int turns = 0; turns < 12; turns++){ + backend.scope().throw_if_cancelled(); + const Pokemon::Observation look = backend.observe(); + std::optional marker; + if (look.frame && *look.frame){ + marker = read_objective_marker(env.env.console, *look.frame->frame); + } + if (!marker){ + pbf_move_right_joystick(env.context, /*position=*/{0.5, 0}, /*hold=*/Milliseconds(500), /*release=*/Milliseconds(200)); + continue; + } + const double off = marker->x - 0.5; + if (off > -0.06 && off < 0.06){ + return true; + } + const Milliseconds turn((int)(std::min(1.0, std::abs(off) * 4) * 400) + 80); + pbf_move_right_joystick(env.context, /*position=*/{off > 0 ? 0.4 : -0.4, 0}, turn, /*release=*/Milliseconds(150)); + } + return false; +} + +// One leg of the search: the camera onto the objective marker, an agreed +// distance read (read_marker_distance()) for ZoneSearch::leg()'s floor, +// then LEG_HOLD that way. With no marker found the leg is taken by the +// camera as it is, logged. +void walk_leg(StoryEnv& env, PlzaBackend& backend, ZoneSearch& search){ + level_camera(env); + const bool faced = face_marker(env, backend); + const std::optional distance = faced ? read_marker_distance(env, backend, std::nullopt) : std::nullopt; + const ZoneLeg leg = search.leg(distance); + const ZoneOffset at = search.offset(); + backend.log(std::format( + "[PLZA] catch_in_zone: nothing new in a full turn: a leg {} ({}, distance {}), now {} toward and {} right of the start in legs", + leg_name(leg), faced ? "facing the marker" : "no marker: by the camera as it is", + distance ? std::to_string(*distance) : std::string("not read"), at.toward, at.right + )); + pbf_move_left_joystick(env.context, leg_stick(leg), LEG_HOLD, /*release=*/Milliseconds(300)); +} + +// A throw at the target ZL is held on, then weaken_and_throw() when it +// broke out into a wild battle. Returns the throws. +int throw_at_lock(StoryEnv& env, PlzaBackend& backend, int max_throws, TrainerBattleState& battle_state){ + throw_ball(env.context, STORY_THROW); + press_a_through_lines(backend, LINES_QUIET, LINES_LIMIT); + return 1 + weaken_and_throw(env, backend, max_throws - 1, battle_state); +} + +// What the search came to: the party bar's last read, the throws. +struct SearchResult{ std::optional slots; int throws = 0; }; -// catch_at_stop() at ROAD_SPOTS in turn, until the party bar, read after -// each stop that threw, shows `goal.party_species`, or PATROL_VISITS, -// `goal.max_throws` or PATROL_LIMIT run out. `slots` is the bar's read -// before the first stop. -Patrol patrol_road(StoryEnv& env, PlzaBackend& backend, const ZoneCatchGoal& goal, std::optional slots){ - Patrol patrol{.slots = slots}; +// The search (ZoneSearch), look by look, until the party bar, read after +// each catch or fight that threw, shows `goal.party_species`, or +// `goal.max_throws` or SEARCH_LIMIT run out. `slots` is the bar's read +// before the first look. +SearchResult search_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCatchGoal& goal, std::optional slots){ + SearchResult result{.slots = slots}; + ZoneSearch search(SCAN_STEPS); TrainerBattleState battle_state(env.battle_ai); - const WallClock deadline = current_time() + PATROL_LIMIT; - std::optional last; - for (size_t visit = 0; visit < PATROL_VISITS && patrol.throws < goal.max_throws && current_time() < deadline; visit++){ - const int stop = ROAD_SPOTS[visit % std::size(ROAD_SPOTS)]; - const std::optional at = walk_to_stop(env, backend, last, stop); - last = at ? at : stop; - const int thrown = catch_at_stop(env, backend, goal.max_throws - patrol.throws, battle_state); - patrol.throws += thrown; - backend.log(std::format("[PLZA] catch_in_zone: stop {} at {} (for {}): {} throws", visit + 1, at.value_or(-1), stop, thrown)); + const WallClock deadline = current_time() + SEARCH_LIMIT; + while (result.throws < goal.max_throws && current_time() < deadline){ + backend.scope().throw_if_cancelled(); + const size_t step = search.step(); + const ZoneLook look = look_in_zone(env); + const ZoneMove move = search.look(look); + backend.log(std::format("[PLZA] catch_in_zone: scan step {} of {}: {}", step + 1, SCAN_STEPS, look_name(look))); + int thrown = 0; + switch (move){ + case ZoneMove::TURN: + pbf_move_right_joystick(env.context, /*position=*/{1, 0}, SCAN_STEP_TURN, /*release=*/Milliseconds(300)); + continue; + case ZoneMove::CATCH: + thrown = throw_at_lock(env, backend, goal.max_throws - result.throws, battle_state); + break; + case ZoneMove::FIGHT: + thrown = fight_back(env, backend, goal.max_throws - result.throws, battle_state); + break; + case ZoneMove::WALK: + walk_leg(env, backend, search); + continue; + case ZoneMove::PAUSE: + backend.log(std::format("[PLZA] catch_in_zone: every leg walked out and back: standing {} s for spawns", SEARCH_PAUSE.count() / 1000)); + level_camera(env); + backend.wait(SEARCH_PAUSE); + continue; + } + level_camera(env); + result.throws += thrown; + backend.log(std::format("[PLZA] catch_in_zone: {} throws ({} in all)", thrown, result.throws)); if (thrown > 0){ - patrol.slots = read_party_slots(env, backend); + result.slots = read_party_slots(env, backend); } - if (party_done(patrol.slots, goal)){ + if (party_done(result.slots, goal)){ break; } } - return patrol; + return result; +} + +// Walks to stop `stop` from `last` (none: from the start, further out +// than every stop): back from the objective when the stop is further. +std::optional walk_to_stop(StoryEnv& env, PlzaBackend& backend, std::optional last, int stop){ + if (last && stop > *last){ + return walk_back_from_marker(env, backend, stop, STOP_WALK_LIMIT); + } + return walk_toward_marker(env, backend, stop, ROAD_FLOOR, last ? STOP_WALK_LIMIT : FIRST_WALK_LIMIT); } // The road stops to walk through from `at` from the objective, in order: @@ -388,25 +488,18 @@ std::vector road_stops_to_gate(std::optional at){ Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCatchGoal& goal){ - // Taunie's two rocks stand between 03.07's end and the marker: a step - // right first, around them (a catch's autosave can leave the save - // further on). - const std::optional start = read_marker_distance(env, backend, ROAD_FLOOR); - if (start && *start >= 115){ - pbf_move_left_joystick(env.context, /*position=*/{1, 0}, /*hold=*/Milliseconds(1000), /*release=*/Milliseconds(300)); - } const std::optional slots = read_party_slots(env, backend); if (party_done(slots, goal)){ backend.log("[PLZA] catch_in_zone: the party already holds the species: nothing to catch"); return Pokemon::outcome_ok(); } - const Patrol patrol = patrol_road(env, backend, goal, slots); - if (party_done(patrol.slots, goal)){ + const SearchResult result = search_zone(env, backend, goal, slots); + if (party_done(result.slots, goal)){ return Pokemon::outcome_ok(); } return Pokemon::outcome_failed("short_of_species", std::format( "the party bar shows {} of {} species after {} throws", - patrol.slots ? std::to_string(*patrol.slots) : std::string("no read"), goal.party_species, patrol.throws + result.slots ? std::to_string(*result.slots) : std::string("no read"), goal.party_species, result.throws )); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h index 5b3d73a05d..60622f9d31 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h @@ -43,21 +43,21 @@ struct ZoneCatchGoal{ }; // 03.08's catches for the "register five species" quest (3/5 after the -// tutorial): back and forth between the user's two catch spots on Wild -// Zone 1's road, by the objective marker's distance (100: Scatterbug on -// the plaza's road; 60: Mareep by the far gate), 10 visits and 10 minutes -// at most. At each stop a wild battle that is on is fought: one of a -// species already caught (its lock-on plate shows the caught mark, -// lock_target_caught()) is fought off, others weakened and caught. -// Else ZL is held until a plate shows, the right stick flicked to the -// next target while the plate shows the caught mark, and the ball thrown -// at the first one not caught, the camera turned right between looks (4 -// at most). The party bar's filled slots (PartyBarDetector), read before -// the first stop and after each stop that threw, end the patrol at +// tutorial), in Wild Zone 1 from Taunie's rocks, by ZoneSearch: the +// camera turned in 8 steps with a ZL lock-on after each; a target whose +// plate shows no caught mark (lock_target_caught()) is thrown at, and a +// wild battle on is fought (one of a species already caught is fought +// off). A full turn with nothing new takes one short leg, each leg out +// walked back, none toward the objective at an agreed distance read of +// 60 or less (the far gate is at ~55), and a round of legs is followed by +// a pause for spawns. The marker's distance never steers it: walks +// between distance stops left the zone or stuck (console B, six runs, +// 2026-11-16). The party bar's filled slots (PartyBarDetector), read +// before the first look and after each look that threw, end it at // `goal.party_species`: the throws go only at species not caught, so // each catch is a new species (the Pokedex's "Registered!" banner is -// missed at times; console B 2026-11-14). Fails as "short_of_species", -// still in the zone. +// missed at times; console B 2026-11-14). 10 minutes at most; fails as +// "short_of_species", still in the zone. Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCatchGoal& goal); // After 03.08's catches: back onto the road at the catch spots nearer diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp new file mode 100644 index 0000000000..27ce80c943 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp @@ -0,0 +1,101 @@ +/* PokemonLZA AutoStory - Zone search + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "PokemonLZA_AutoStoryZoneSearch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The ways out of a round, in turn: away first, as the start spot +// (Taunie's rocks, ~120 to 146 from the objective) has the far gate +// ahead and grass behind and beside it. +constexpr ZoneLeg OUT_LEGS[] = {ZoneLeg::AWAY, ZoneLeg::LEFT, ZoneLeg::RIGHT, ZoneLeg::TOWARD}; + +void apply(ZoneOffset& offset, ZoneLeg leg){ + switch (leg){ + case ZoneLeg::TOWARD: + offset.toward++; + return; + case ZoneLeg::AWAY: + offset.toward--; + return; + case ZoneLeg::LEFT: + offset.right--; + return; + case ZoneLeg::RIGHT: + offset.right++; + return; + } +} + +// The leg that takes `offset` one leg nearer the start spot, if it is +// off it: along the objective's line first. +std::optional leg_back(const ZoneOffset& offset){ + if (offset.toward > 0){ + return ZoneLeg::AWAY; + } + if (offset.toward < 0){ + return ZoneLeg::TOWARD; + } + if (offset.right > 0){ + return ZoneLeg::LEFT; + } + if (offset.right < 0){ + return ZoneLeg::RIGHT; + } + return std::nullopt; +} + +} // namespace + + +ZoneMove ZoneSearch::look(ZoneLook look){ + switch (look){ + case ZoneLook::WILD_BATTLE: + m_step = 0; + return ZoneMove::FIGHT; + case ZoneLook::NOT_CAUGHT: + m_step = 0; + return ZoneMove::CATCH; + case ZoneLook::NO_PLATE: + case ZoneLook::ALL_CAUGHT: + break; + } + if (++m_step < m_steps_per_turn){ + return ZoneMove::TURN; + } + m_step = 0; + if (m_outs >= std::size(OUT_LEGS) && !leg_back(m_offset)){ + m_outs = 0; + return ZoneMove::PAUSE; + } + return ZoneMove::WALK; +} + +ZoneLeg ZoneSearch::leg(std::optional distance){ + const bool floored = distance && *distance <= TOWARD_FLOOR_DISTANCE; + std::optional leg = leg_back(m_offset); + if (!leg){ + leg = OUT_LEGS[m_outs % std::size(OUT_LEGS)]; + m_outs++; + } + if (floored && *leg == ZoneLeg::TOWARD){ + leg = ZoneLeg::AWAY; + } + apply(m_offset, *leg); + return *leg; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h new file mode 100644 index 0000000000..378d9b73e5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h @@ -0,0 +1,110 @@ +/* PokemonLZA AutoStory - Zone search + * + * From: https://github.com/PokemonAutomation/ + * + * How 03.08 looks for new species in Wild Zone 1 without walking by the + * objective marker's digits: stand, turn the camera in steps through a + * full turn with a ZL lock-on after each, catch a species not caught yet, + * and only when a full turn finds none take one short leg into the grass, + * each leg out followed by one back. Six runs walking between distance + * stops (console B, 2026-11-16) left the zone or stood stuck: the digits + * read nothing for long stretches (speech bubbles, the marker at the + * screen's edge), and run 6 ended 4 of 5 with only species already + * caught locking on at its last stops. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryZoneSearch_H +#define PokemonAutomation_PokemonLZA_AutoStoryZoneSearch_H + +#include +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// What one look of a scan found. +enum class ZoneLook{ + NO_PLATE, // ZL held, no name plate showed + ALL_CAUGHT, // every plate the lock moved through shows the caught mark + NOT_CAUGHT, // locked on, ZL still held, to a species not caught + WILD_BATTLE, // a wild battle is on +}; + +// What the search does after a look. +enum class ZoneMove{ + TURN, // the camera one step on, then a look + CATCH, // a throw at the target locked on + FIGHT, // the wild battle on is fought (weakened and caught, or fought off) + WALK, // a full turn found nothing new: one leg (ZoneSearch::leg()), then a scan + PAUSE, // every leg of a round walked: stand a while for spawns, then a scan +}; + +// A leg's way, with the camera turned onto the objective marker: on +// toward it, back away from it, or across its line. +enum class ZoneLeg{ + TOWARD, + AWAY, + LEFT, + RIGHT, +}; + +// Where the search stands, in legs from where it started: on toward the +// objective (above 0) and right of its line (above 0). +struct ZoneOffset{ + int toward = 0; + int right = 0; + + bool operator==(const ZoneOffset&) const = default; +}; + +// The search, one look and one leg at a time. A scan is `steps_per_turn` +// looks, the camera turned one step between two. A catch or a fight +// starts the scan over. A scan with nothing new is a WALK; legs go out +// from the start spot and back in turn (away, left, right, toward), and +// once every way has been out and back, the next empty scan is a PAUSE +// and the round starts over. +class ZoneSearch{ +public: + explicit ZoneSearch(size_t steps_per_turn) + : m_steps_per_turn(steps_per_turn) + {} + + // What to do after a look at camera step step(). + ZoneMove look(ZoneLook look); + + // The leg after a WALK: back toward the start spot when away from it, + // else the round's next way out. `distance` is an agreed read of the + // objective marker's distance, if any: at or below + // TOWARD_FLOOR_DISTANCE no leg goes toward the objective (the far + // gate is at ~55 and the city past it), and an away leg takes its + // place. + ZoneLeg leg(std::optional distance); + + // The camera step of the scan, from 0. + size_t step() const{ + return m_step; + } + + ZoneOffset offset() const{ + return m_offset; + } + +private: + const size_t m_steps_per_turn; + size_t m_step = 0; + size_t m_outs = 0; // legs out walked this round + ZoneOffset m_offset; +}; + +// An agreed distance read at or below this: no leg toward the objective. +constexpr int TOWARD_FLOOR_DISTANCE = 60; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp new file mode 100644 index 0000000000..c8d76ad669 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp @@ -0,0 +1,201 @@ +/* PokemonLZA AutoStory - Zone search Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryZoneSearch.h" +#include "PokemonLZA_AutoStoryZoneSearch_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// 8 camera steps to a full turn, as catch_in_zone() scans. +constexpr size_t STEPS = 8; + +constexpr ZoneLook NONE = ZoneLook::NO_PLATE; +constexpr ZoneLook CAUGHT = ZoneLook::ALL_CAUGHT; +constexpr ZoneLook NEW = ZoneLook::NOT_CAUGHT; +constexpr ZoneLook BATTLE = ZoneLook::WILD_BATTLE; + +constexpr ZoneMove TURN = ZoneMove::TURN; +constexpr ZoneMove CATCH = ZoneMove::CATCH; +constexpr ZoneMove FIGHT = ZoneMove::FIGHT; +constexpr ZoneMove WALK = ZoneMove::WALK; +constexpr ZoneMove PAUSE = ZoneMove::PAUSE; + +constexpr ZoneLeg TOWARD = ZoneLeg::TOWARD; +constexpr ZoneLeg AWAY = ZoneLeg::AWAY; +constexpr ZoneLeg LEFT = ZoneLeg::LEFT; +constexpr ZoneLeg RIGHT = ZoneLeg::RIGHT; + +// A round of legs with no distance read: each way out, then back. +const std::vector ROUND = {AWAY, TOWARD, LEFT, RIGHT, RIGHT, LEFT, TOWARD, AWAY}; + +// `scans` full turns of looks that find nothing new (no plate and caught +// plates in turn), after `before`. +std::vector empty_scans(size_t scans, std::vector before = {}){ + for (size_t i = 0; i < scans * STEPS; i++){ + before.push_back(i % 2 == 0 ? NONE : CAUGHT); + } + return before; +} + +// The moves of full turns that find nothing new, one per entry of `ends`: +// 7 turns, then the entry; after `before`. +std::vector empty_scan_moves(const std::vector& ends, std::vector before = {}){ + for (ZoneMove end : ends){ + before.insert(before.end(), STEPS - 1, TURN); + before.push_back(end); + } + return before; +} + +template +std::vector repeated(const std::vector& values, size_t times){ + std::vector out; + for (size_t i = 0; i < times; i++){ + out.insert(out.end(), values.begin(), values.end()); + } + return out; +} + +// The 8 walks of a round with no read, then its pause. +const std::vector ROUND_ENDS = {WALK, WALK, WALK, WALK, WALK, WALK, WALK, WALK, PAUSE}; + + +struct SearchCase{ + std::string name; + struct Input{ + std::vector looks; + // The agreed marker distance read before each leg (none: no read). + std::optional distance; + }; + Input input; + struct Expectation{ + std::vector moves; + std::vector legs; + // The furthest the search got from its start, in legs either way. + int furthest = 0; + ZoneOffset end; + }; + Expectation expectation; +}; + +const SearchCase SEARCH_CASES[] = { + { + .name = "a new species locked on at the third camera step is caught", + .input = {.looks = {CAUGHT, NONE, NEW}}, + .expectation = {.moves = {TURN, TURN, CATCH}}, + }, + { + .name = "a catch or a wild battle starts the scan over at the first camera step", + .input = {.looks = empty_scans(1, {NONE, NEW, CAUGHT, BATTLE})}, + .expectation = {.moves = empty_scan_moves({WALK}, {TURN, CATCH, TURN, FIGHT}), .legs = {AWAY}, .furthest = 1, .end = {.toward = -1}}, + }, + { + .name = "a full turn with nothing new walks one leg, then scans again", + .input = {.looks = empty_scans(1, {}), .distance = 130}, + .expectation = {.moves = {TURN, TURN, TURN, TURN, TURN, TURN, TURN, WALK}, .legs = {AWAY}, .furthest = 1, .end = {.toward = -1}}, + }, + { + .name = "with no distance read each leg out is walked back before the next, then the search pauses", + .input = {.looks = empty_scans(18)}, + .expectation = {.moves = empty_scan_moves(repeated(ROUND_ENDS, 2)), .legs = repeated(ROUND, 2), .furthest = 1, .end = {}}, + }, + { + .name = "at a distance of 60 or less no leg goes toward the objective", + .input = {.looks = empty_scans(8), .distance = 55}, + .expectation = { + .moves = empty_scan_moves({WALK, WALK, WALK, WALK, WALK, WALK, WALK, WALK}), + .legs = {AWAY, AWAY, AWAY, AWAY, AWAY, AWAY, AWAY, AWAY}, + .furthest = 8, .end = {.toward = -8}, + }, + }, + { + .name = "at a distance over 60 legs toward the objective are walked", + .input = {.looks = empty_scans(9), .distance = 61}, + .expectation = {.moves = empty_scan_moves(ROUND_ENDS), .legs = ROUND, .furthest = 1, .end = {}}, + }, +}; + +template +std::string text(const std::vector& values){ + std::string out; + for (Type value : values){ + out += std::format("{}{}", out.empty() ? "" : ",", (int)value); + } + return std::format("{{{}}}", out); +} + +std::string text(const ZoneOffset& offset){ + return std::format("({} toward, {} right)", offset.toward, offset.right); +} + +// catch_in_zone()'s loop: each look decides a move; a WALK takes a leg. +UnitTestResult check_search(const SearchCase& test){ + ZoneSearch search(STEPS); + std::vector moves; + std::vector legs; + int furthest = 0; + for (ZoneLook look : test.input.looks){ + const ZoneMove move = search.look(look); + moves.push_back(move); + if (move != ZoneMove::WALK){ + continue; + } + legs.push_back(search.leg(test.input.distance)); + const ZoneOffset at = search.offset(); + furthest = std::max({furthest, std::abs(at.toward), std::abs(at.right)}); + } + const SearchCase::Expectation& expected = test.expectation; + if (moves != expected.moves || legs != expected.legs || furthest != expected.furthest || search.offset() != expected.end){ + return std::format( + "expected moves {}, legs {}, furthest {}, end {}; got moves {}, legs {}, furthest {}, end {}", + text(expected.moves), text(expected.legs), expected.furthest, text(expected.end), + text(moves), text(legs), furthest, text(search.offset()) + ); + } + return true; +} + + +class SearchTest : public UnitTest{ +public: + explicit SearchTest(SearchCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStory - ZoneSearch: {}", test_case.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_search(m_case); + } +private: + SearchCase m_case; +}; + +} // namespace + + +void add_tests_AutoStoryZoneSearch(UnitTestDatabase& database){ + for (const SearchCase& test : SEARCH_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.h new file mode 100644 index 0000000000..83dea34461 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Zone search Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryZoneSearch_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryZoneSearch_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers ZoneSearch's tests: searches replayed look by look, each WALK +// taking the leg ZoneSearch picks. +void add_tests_AutoStoryZoneSearch(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json index 3aa522fc7e..84413dd411 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json @@ -11,7 +11,7 @@ { "id": "catch_more_species", "kind": "game_action", - "why": "step 64: the lab gate asks for five registered species, 3/5 after the tutorial: two new ones here in Wild Zone 1 before leaving, Scatterbug (on the road at 100 from the objective marker) and Mareep (in the grass right of the road at 60), so the gate's scene finds 5/5 (user, 2026-11-13). Patrol 100, 60, 100, 60, ...: walking to 100 and back brings Pokemon back at 60; 10 visits, 10 minutes, 12 throws at most. The party bar's filled slots decide, read before the first stop and after each stop that threw: 5 means done, since the throws go only at targets whose plate shows no caught mark, and the \"Registered!\" banner is missed at times (console B 2026-11-14 19:36: Mareep in the party, no banner seen).", + "why": "step 64: the lab gate asks for five registered species, 3/5 after the tutorial: two new ones here in Wild Zone 1 before leaving, so the gate's scene finds 5/5 (user, 2026-11-13). From Taunie's rocks the search stays in the zone: it turns the camera in 8 steps with a ZL lock-on after each and throws only at targets whose plate shows no caught mark; a full turn with nothing new takes one short leg, each leg out walked back, none toward the objective at an agreed marker read of 60 or less (far gate ~55); after a round of legs it stands for spawns. 10 minutes, 12 throws at most. The marker's distance no longer steers it: six runs walking between distance stops on console B (2026-11-16) left the zone or stuck at ~87-89 with the digits unread (user's pick, 2026-11-16). The party bar's filled slots decide, read before the first look and after each throw: 5 means done, since the \"Registered!\" banner is missed at times (console B 2026-11-14 19:36: Mareep in the party, no banner seen).", "action": "catch_in_zone" } ], diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index d75c54763e..6e65f91840 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2348,6 +2348,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp From 43898fb802309fd53581ed848f30281efefc1f71 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 13:37:43 -0800 Subject: [PATCH 8/8] PLZA 03.08: zone search legs stay on the road (away and toward only) --- .../Actions/PokemonLZA_AutoStoryZoneSearch.cpp | 5 +++-- .../AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h | 2 +- .../Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp | 10 ++++------ 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp index 27ce80c943..2909da9a7a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.cpp @@ -16,8 +16,9 @@ namespace{ // The ways out of a round, in turn: away first, as the start spot // (Taunie's rocks, ~120 to 146 from the objective) has the far gate -// ahead and grass behind and beside it. -constexpr ZoneLeg OUT_LEGS[] = {ZoneLeg::AWAY, ZoneLeg::LEFT, ZoneLeg::RIGHT, ZoneLeg::TOWARD}; +// ahead and grass behind and beside it. Both ways are along the road: +// the search stays on it (the user, 2026-11-16). +constexpr ZoneLeg OUT_LEGS[] = {ZoneLeg::AWAY, ZoneLeg::TOWARD}; void apply(ZoneOffset& offset, ZoneLeg leg){ switch (leg){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h index 378d9b73e5..105a93165f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch.h @@ -5,7 +5,7 @@ * How 03.08 looks for new species in Wild Zone 1 without walking by the * objective marker's digits: stand, turn the camera in steps through a * full turn with a ZL lock-on after each, catch a species not caught yet, - * and only when a full turn finds none take one short leg into the grass, + * and only when a full turn finds none take one short leg along the road, * each leg out followed by one back. Six runs walking between distance * stops (console B, 2026-11-16) left the zone or stood stuck: the digits * read nothing for long stretches (speech bubbles, the marker at the diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp index c8d76ad669..3024a12d7a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryZoneSearch_Tests.cpp @@ -38,11 +38,9 @@ constexpr ZoneMove PAUSE = ZoneMove::PAUSE; constexpr ZoneLeg TOWARD = ZoneLeg::TOWARD; constexpr ZoneLeg AWAY = ZoneLeg::AWAY; -constexpr ZoneLeg LEFT = ZoneLeg::LEFT; -constexpr ZoneLeg RIGHT = ZoneLeg::RIGHT; // A round of legs with no distance read: each way out, then back. -const std::vector ROUND = {AWAY, TOWARD, LEFT, RIGHT, RIGHT, LEFT, TOWARD, AWAY}; +const std::vector ROUND = {AWAY, TOWARD, TOWARD, AWAY}; // `scans` full turns of looks that find nothing new (no plate and caught // plates in turn), after `before`. @@ -73,7 +71,7 @@ std::vector repeated(const std::vector& values, size_t times){ } // The 8 walks of a round with no read, then its pause. -const std::vector ROUND_ENDS = {WALK, WALK, WALK, WALK, WALK, WALK, WALK, WALK, PAUSE}; +const std::vector ROUND_ENDS = {WALK, WALK, WALK, WALK, PAUSE}; struct SearchCase{ @@ -112,7 +110,7 @@ const SearchCase SEARCH_CASES[] = { }, { .name = "with no distance read each leg out is walked back before the next, then the search pauses", - .input = {.looks = empty_scans(18)}, + .input = {.looks = empty_scans(10)}, .expectation = {.moves = empty_scan_moves(repeated(ROUND_ENDS, 2)), .legs = repeated(ROUND, 2), .furthest = 1, .end = {}}, }, { @@ -126,7 +124,7 @@ const SearchCase SEARCH_CASES[] = { }, { .name = "at a distance over 60 legs toward the objective are walked", - .input = {.looks = empty_scans(9), .distance = 61}, + .input = {.looks = empty_scans(5), .distance = 61}, .expectation = {.moves = empty_scan_moves(ROUND_ENDS), .legs = ROUND, .furthest = 1, .end = {}}, }, };