From ccfe85db8c27a7f87557a72168ac3891be90b9c2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:52:49 -0800 Subject: [PATCH 01/14] PLZA AutoStory: 03.08 Wild Zone 1's five species and the far gate (03.08b) --- .../Inference/PokemonLZA_PartyBarDetector.cpp | 188 +++++++++++ .../Inference/PokemonLZA_PartyBarDetector.h | 72 ++++ .../PokemonLZA/PokemonLZA_Tests.cpp | 4 + .../Actions/PokemonLZA_AutoStoryCatches.cpp | 307 ++++++++++++++++++ .../Actions/PokemonLZA_AutoStoryCatches.h | 37 ++- .../PokemonLZA_AutoStoryMarkerWalk.cpp | 91 +++++- .../Actions/PokemonLZA_AutoStoryMarkerWalk.h | 13 + .../PokemonLZA_AutoStoryCaughtMarkReader.cpp | 92 ++++++ .../PokemonLZA_AutoStoryCaughtMarkReader.h | 37 +++ ...monLZA_AutoStoryCaughtMarkReader_Tests.cpp | 186 +++++++++++ ...kemonLZA_AutoStoryCaughtMarkReader_Tests.h | 26 ++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 61 +++- .../AutoStory/PokemonLZA_AutoStoryGame.h | 11 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 23 +- .../AutoStory/StoryData/plza-03.08.plan.json | 26 ++ .../AutoStory/StoryData/plza-03.08b.plan.json | 37 +++ SerialPrograms/cmake/SourceFiles.cmake | 6 + 17 files changed, 1191 insertions(+), 26 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08b.plan.json diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp new file mode 100644 index 0000000000..15a141c553 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp @@ -0,0 +1,188 @@ +/* Party Bar Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "Tests/ImageUnitTest.h" +#include "PokemonLZA_PartyBarDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +namespace{ + +// The slot's HP bar: 52 of 1920 wide from x = 86 + 76.4 * i, rows +// 1028-1031 of 1080; the box stays inside the bar. +constexpr double SLOT_X = 0.045; +constexpr double SLOT_PITCH = 0.0398; +constexpr double BAR_WIDTH = 0.026; +constexpr double BAR_Y = 0.9519; +constexpr double BAR_HEIGHT = 0.0037; +// The card between the icon and the bar: rows 1021-1025. +constexpr double CARD_Y = 0.9454; +constexpr double CARD_HEIGHT = 0.0046; + +// The trough is the card darkened: a black overlay at about half. +constexpr double TROUGH_BRIGHTNESS_RATIO = 0.65; +// A bar's box reads 0.79 and up (a nearly empty red bar over a bright +// teal scene); a slot with none 0.16 at most (the Poke Ball of the slot +// sent out). +constexpr double BAR_SHARE_MIN = 0.5; + +// An HP bar's green, yellow or red. +bool is_hp_color(Color color){ + const uint32_t r = color.red(); + const uint32_t g = color.green(); + const uint32_t b = color.blue(); + const bool green = g > 140 && g > r + 60 && g > b + 60; + const bool yellow = r > 170 && g > 150 && b < 100; + const bool red = r > 170 && g < 110 && b < 110; + return green || yellow || red; +} + +double brightness(Color color){ + return (color.red() + color.green() + color.blue()) / 3.0; +} + +} // namespace + + +PartyBarDetector::PartyBarDetector(Color color, VideoOverlay* overlay) + : m_selection(color, overlay) +{ + for (size_t i = 0; i < 6; i++){ + const double x = SLOT_X + SLOT_PITCH * i; + m_bar_boxes[i] = {x, BAR_Y, BAR_WIDTH, BAR_HEIGHT}; + m_card_boxes[i] = {x, CARD_Y, BAR_WIDTH, CARD_HEIGHT}; + } +} + +void PartyBarDetector::make_overlays(VideoOverlaySet& items) const{ + m_selection.make_overlays(items); + for (size_t i = 0; i < 6; i++){ + items.add(COLOR_GREEN, m_bar_boxes[i]); + } +} + +bool PartyBarDetector::slot_has_hp_bar(const ImageViewRGB32& screen, size_t index) const{ + const ImageViewRGB32 card = extract_box_reference(screen, m_card_boxes[index]); + const ImageViewRGB32 bar = extract_box_reference(screen, m_bar_boxes[index]); + const size_t total = bar.width() * bar.height(); + if (total == 0 || card.width() * card.height() == 0){ + return false; + } + const double trough_max = image_average(card).sum() / 3.0 * TROUGH_BRIGHTNESS_RATIO; + size_t count = 0; + for (size_t y = 0; y < bar.height(); y++){ + for (size_t x = 0; x < bar.width(); x++){ + const Color color(bar.pixel(x, y)); + if (is_hp_color(color) || brightness(color) < trough_max){ + count++; + } + } + } + return (double)count / (double)total >= BAR_SHARE_MIN; +} + +bool PartyBarDetector::detect(const ImageViewRGB32& screen){ + m_filled_slots = 0; + if (screen.width() == 0 || screen.height() == 0){ + return false; + } + if (!m_selection.detect(screen)){ + return false; + } + const uint8_t sent_out = m_selection.dpad_down_idx(); + for (size_t i = 0; i < 6; i++){ + if (i == sent_out || slot_has_hp_bar(screen, i)){ + m_filled_slots++; + } + } + return true; +} + +int party_bar_filled_slots(const ImageViewRGB32& screen){ + PartyBarDetector detector; + detector.detect(screen); + return detector.filled_slots(); +} + + +namespace{ + +struct PartyBarCase{ + std::string name; + struct Input{ + std::string image; // In CommandLineTests/PokemonLZA/PartyBarDetector/. + }; + Input input; + struct Expectation{ + int filled_slots; + }; + Expectation expectation; +}; + +const PartyBarCase PARTY_BAR_CASES[] = { + { + .name = "five filled, slot 0 selected (D-pad up), the sixth empty", + .input = {.image = "party5_slot0_selected.png"}, + .expectation = {.filled_slots = 5}, + }, + { + .name = "five filled, slot 0's partner sent out (Poke Ball, no bar), Mareep's bar red", + .input = {.image = "party5_slot0_sent_out.png"}, + .expectation = {.filled_slots = 5}, + }, + { + .name = "five filled, slot 0's partner sent out, over bright ground", + .input = {.image = "party5_b.png"}, + .expectation = {.filled_slots = 5}, + }, +}; + +class Test_PartyBarDetector : public ImageUnitTest{ +public: + explicit Test_PartyBarDetector(const PartyBarCase& test_case) + : ImageUnitTest( + std::format("PokemonLZA::PartyBarDetector - {}", test_case.name), + {"PokemonLZA/PartyBarDetector/" + test_case.input.image} + ) + , m_case(test_case) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const int filled = party_bar_filled_slots(images[0]); + if (filled != m_case.expectation.filled_slots){ + return std::format("Expected {} filled slots, got {}.", m_case.expectation.filled_slots, filled); + } + return true; + } + +private: + const PartyBarCase& m_case; +}; + +} // namespace + + +void add_tests_PartyBarDetector(UnitTestDatabase& database){ + for (const PartyBarCase& item : PARTY_BAR_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h new file mode 100644 index 0000000000..ffe6295f54 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h @@ -0,0 +1,72 @@ +/* Party Bar Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_PartyBarDetector_H +#define PokemonAutomation_PokemonLZA_PartyBarDetector_H + +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" +#include "PokemonLZA_OverworldPartySelectionDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Counts the filled slots of the overworld party bar (bottom left, 6 +// slots). The bar is on screen when its D-pad marker shows +// (OverworldPartySelectionDetector). A filled slot has an HP bar under +// its icon: green, yellow or red by its HP, over a dark trough. The slot +// whose partner is sent out (the D-pad down marker's) shows a Poke Ball +// and no HP bar: it counts too. An empty slot shows only its card. +// Boxes measured on 1920x1080 frames (console B, 2026-11-14): the bars +// on rows 1028-1031, slot i from x = 86 + 76.4 * i, 52 wide. +class PartyBarDetector : public StaticScreenDetector{ +public: + PartyBarDetector(Color color = COLOR_RED, VideoOverlay* overlay = nullptr); + + virtual void make_overlays(VideoOverlaySet& items) const override; + + // Whether the party bar is on screen; then filled_slots() is its count. + virtual bool detect(const ImageViewRGB32& screen) override; + + virtual void reset_state() override{ + m_selection.reset_state(); + m_filled_slots = 0; + } + + // The filled slots of the bar on the last detect()'s screen: 0 when + // no bar was on it. + int filled_slots() const{ return m_filled_slots; } + +private: + // Whether slot `index`'s HP bar shows: the bar's box is mostly HP + // color or darker than the card above it (the trough). + bool slot_has_hp_bar(const ImageViewRGB32& screen, size_t index) const; + + OverworldPartySelectionDetector m_selection; + // Each slot's HP bar and, above it, the card between icon and bar. + std::array m_bar_boxes; + std::array m_card_boxes; + int m_filled_slots = 0; +}; + +// The filled slots of the party bar on `screen`: 0 when no bar is on it. +int party_bar_filled_slots(const ImageViewRGB32& screen); + + +// Registers the party bar detector's tests on the PartyBarDetector frames. +void add_tests_PartyBarDetector(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 5f3ec894e4..8f8d2e9c6e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -18,7 +18,9 @@ #include "Inference/Map/PokemonLZA_MapDetector.h" #include "Inference/Map/PokemonLZA_MapIconDetector.h" #include "Inference/PokemonLZA_OverworldPartySelectionDetector.h" +#include "Inference/PokemonLZA_PartyBarDetector.h" #include "Inference/PokemonLZA_SelectionArrowDetector.h" +#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.h" @@ -49,10 +51,12 @@ void add_tests(UnitTestDatabase& database){ add_tests_MapDetector(database); add_tests_MapIconDetector(database); add_tests_OverworldPartySelectionDetector(database); + add_tests_PartyBarDetector(database); add_tests_SelectionArrowDetector(database); add_tests_AutoStoryDetectors(database); add_tests_AutoStoryDialogChoiceBox(database); add_tests_AutoStoryConfirmChoicesReader(database); + add_tests_AutoStoryCaughtMarkReader(database); add_tests_AutoStoryDialogDetector(database); add_tests_AutoStoryGame(database); add_tests_AutoStoryLines(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 e9207cc8f8..3ffd01f38c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -4,13 +4,23 @@ * */ +#include #include +#include +#include +#include +#include #include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonLZA/Inference/Battles/PokemonLZA_RunFromBattleDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_AlertEyeDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h" #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" namespace PokemonAutomation{ @@ -109,6 +119,303 @@ 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. +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; +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); + +// 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). +class HeldZl{ +public: + explicit HeldZl(StoryEnv& env) + : m_env(env) + , m_end(current_time()) + {} + + // Holds ZL until 0.6 s after what was queued and reads the plate locked + // on to (lock_target_caught()), with 0.4 s more of ZL queued. + std::optional read(){ + hold(Milliseconds(1000), /*right_x=*/0); + const WallClock at = m_end - Milliseconds(400); + const WallClock now = current_time(); + if (at > now){ + m_env.context.wait_for(std::chrono::duration_cast(at - now)); + } + const VideoSnapshot frame = m_env.env.console.video().snapshot(); + if (!frame){ + return std::nullopt; + } + return lock_target_caught(frame); + } + + // read() until a plate shows or `limit` passes. + std::optional wait_for_plate(Milliseconds limit){ + const WallClock end = current_time() + limit; + while (true){ + const std::optional plate = read(); + if (plate || current_time() >= end){ + return plate; + } + } + } + + // Flicks the right stick right with ZL held: the lock moves on to the + // next target. Returns the plate after it. + std::optional flick(){ + hold(Milliseconds(150), TARGET_FLICK); + return read(); + } + +private: + void hold(Milliseconds time, double right_x){ + pbf_controller_state( + m_env.context, BUTTON_ZL, DPAD_NONE, + /*left_joystick=*/{0, 0}, /*right_joystick=*/{right_x, 0}, time + ); + m_end = std::max(m_end, current_time()) + time; + } + + StoryEnv& m_env; + 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){ + 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; + } + if (*caught){ + backend.log("[PLZA] catch_in_zone: only species already caught lock on"); + return LockOn::ALL_CAUGHT; + } + return LockOn::NOT_CAUGHT; +} + +// A ZL lock-on and throw leave the camera looking steeply down: the +// right stick down held 1500 ms pins the pitch at its lowest, then up +// 600 ms gives the walking pitch (console B, 2026-11-14). +void level_camera(StoryEnv& env){ + pbf_move_right_joystick(env.context, /*position=*/{0, -1}, /*hold=*/Milliseconds(1500), /*release=*/Milliseconds(100)); + pbf_move_right_joystick(env.context, /*position=*/{0, 1}, /*hold=*/Milliseconds(600), /*release=*/Milliseconds(300)); +} + +// Rounds of weaken_target() and a throw, with A through the lines, while +// a wild battle is on: until it is over (caught, or the target gone), a +// round lands nothing, or `max_throws`. Returns the throws. +int weaken_and_throw(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& battle_state, int max_throws){ + int throws = 0; + while (throws < max_throws && wild_battle_on(env)){ + const int landed = weaken_target(env, backend, battle_state); + if (landed == 0 && throws > 0){ + break; + } + press_a_through_lines(backend, LINES_QUIET, LINES_LIMIT); + throw_ball(env.context, STORY_THROW); + throws++; + press_a_through_lines(backend, LINES_QUIET, LINES_LIMIT); + backend.log(std::format("[PLZA] catch_in_zone: battle round {}: {} attacks landed, then a throw", throws, landed)); + } + return throws; +} + +// A wild battle at the stop (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. +int fight_back(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& battle_state, int max_throws){ + const std::optional caught = HeldZl(env).wait_for_plate(LOCK_ON_WAIT); + if (caught != true){ + backend.log("[PLZA] catch_in_zone: a wild battle at the stop: weakening and throwing"); + return weaken_and_throw(env, backend, battle_state, max_throws); + } + backend.log("[PLZA] catch_in_zone: a wild battle with a species already caught: fighting it off"); + for (int round = 0; round < 3 && wild_battle_on(env); round++){ + if (weaken_target(env, backend, battle_state) == 0){ + break; + } + press_a_through_lines(backend, LINES_QUIET, LINES_LIMIT); + } + 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, TrainerBattleState& battle_state, int max_throws){ + 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, battle_state, max_throws); + 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, battle_state, max_throws - throws); + } + 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){ + PartyBarDetector bar; + for (int looks = 0; looks < 8; looks++){ + env.context.wait_for_all_requests(); + const VideoSnapshot frame = env.env.console.video().snapshot(); + if (frame && bar.detect(frame) && bar.filled_slots() > 0){ + backend.log(std::format("[PLZA] catch_in_zone: the party bar shows {} filled slots", bar.filled_slots())); + return bar.filled_slots(); + } + env.context.wait_for(Milliseconds(250)); + } + backend.log("[PLZA] catch_in_zone: the party bar did not read within 2 s"); + return std::nullopt; +} + +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); + } + 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; +} + +} // namespace + + +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 = objective_distance_now(env); + if (start && *start >= 115){ + pbf_move_left_joystick(env.context, /*position=*/{1, 0}, /*hold=*/Milliseconds(1000), /*release=*/Milliseconds(300)); + } + 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(); + } + TrainerBattleState battle_state(env.battle_ai); + const WallClock deadline = current_time() + PATROL_LIMIT; + int throws = 0; + std::optional last; + for (size_t visit = 0; visit < PATROL_VISITS && 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, battle_state, goal.max_throws - throws); + throws += thrown; + backend.log(std::format("[PLZA] catch_in_zone: stop {} at {} (for {}): {} throws", visit + 1, at.value_or(-1), stop, thrown)); + if (thrown == 0){ + continue; + } + slots = read_party_slots(env, backend); + if (party_done(slots, goal)){ + return Pokemon::outcome_ok(); + } + } + return Pokemon::outcome_failed("short_of_species", std::format( + "the party bar shows {} of {} species after {} throws", + slots ? std::to_string(*slots) : std::string("no read"), goal.party_species, throws + )); +} + +Pokemon::Outcome walk_back_to_zone_road(StoryEnv& env, PlzaBackend& backend){ + std::optional at = objective_distance_now(env); + std::vector stops; + for (int spot : ROAD_SPOTS){ + if (!at || spot < *at){ + stops.push_back(spot); + } + } + if (stops.empty()){ + // At or past 60: back onto the road there first, as a walk at the + // gate from off the road ran into a building west of the zone + // (console B, 2026-11-13, last read 49). + stops.push_back(ROAD_SPOTS[std::size(ROAD_SPOTS) - 1]); + } + for (int stop : stops){ + 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; + const std::optional reached = walk_to_stop(env, backend, at, stop); + const bool arrived = reached && (toward ? *reached <= stop + ROAD_STOP_SLACK : *reached >= stop - ROAD_STOP_SLACK); + if (!arrived){ + return Pokemon::outcome_failed("road_stop_not_reached", std::format( + "not back on the road at {} (last read {})", stop, reached.value_or(-1) + )); + } + at = reached; + } + return Pokemon::outcome_ok(); +} + + } // namespace PokemonLZA } // namespace NintendoSwitch 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 0a4eac4911..5b3d73a05d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h @@ -2,7 +2,8 @@ * * From: https://github.com/PokemonAutomation/ * - * Wild Zone 1's tutorial catches (03.07), from console B, 2026-11-10. + * Wild Zone 1's catches: 03.07's tutorial, from console B, 2026-11-10, + * and 03.08's two more species, from console B, 2026-11-13 and 14. * Each throw is throw_ball()'s: ZL 0.5 s to lock on, then ZL + ZR 1.5 s * (0.5 s only aims), then 8 s for the flight, the shakes and the banner. * @@ -34,6 +35,40 @@ Pokemon::Outcome catch_tutorial(StoryEnv& env, PlzaBackend& backend, int max_thr // "still_a_target" after `max_rounds`. Pokemon::Outcome battle_then_catch(StoryEnv& env, PlzaBackend& backend, int max_rounds); +// What catch_in_zone() is after: the overworld party bar showing +// `party_species` filled slots, in `max_throws` throws at most. +struct ZoneCatchGoal{ + int party_species = 0; + int max_throws = 0; +}; + +// 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 +// `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. +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 +// the far gate than the player, or at 60 when at or past it, by the +// objective marker (walk_toward_marker(), walk_back_from_marker()). From +// 60 the far gate's pillars are straight down the road; the marker is not +// on the gate but past it and to its left, behind the zone's fence, so a +// walk at the marker was held up at 36 and wandered off (console B, +// 2026-11-13 and 2026-11-14). Fails as "road_stop_not_reached". +Pokemon::Outcome walk_back_to_zone_road(StoryEnv& env, PlzaBackend& backend); + } // namespace PokemonLZA 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 3c94ae2328..247aff2e4b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -68,21 +68,36 @@ class DistanceReads{ // How one step of the walk ended. enum class MarkerStep{ WALKING, - ARRIVED, // an A prompt or a dialog shows + ARRIVED, // the goal's distance read, or (no distance) an A prompt or a dialog shows LOST, // the marker did not show for 12 camera turns }; +// Where a walk ends. +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; +}; + // The walk, one look and one move at a time. class MarkerWalk{ public: - MarkerWalk(StoryEnv& env, PlzaBackend& backend) + MarkerWalk(StoryEnv& env, PlzaBackend& backend, MarkerGoal goal) : m_env(env) , m_backend(backend) + , m_goal(goal) {} + // The last distance taken, if any. + std::optional last() const{ + return m_reads.last(); + } + MarkerStep step(){ const Pokemon::Observation look = m_backend.observe(); - if (look.events.has(ScreenEvent::INTERACT_PROMPT) || look.events.has(ScreenEvent::DIALOG_BOX)){ + if (!m_goal.stop_at && (look.events.has(ScreenEvent::INTERACT_PROMPT) || look.events.has(ScreenEvent::DIALOG_BOX))){ return MarkerStep::ARRIVED; } std::optional marker; @@ -100,6 +115,10 @@ class MarkerWalk{ return MarkerStep::WALKING; } 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; + } on_distance(marker->distance); } steer_and_step(marker->x); @@ -116,10 +135,21 @@ class MarkerWalk{ return MarkerStep::WALKING; } - // A taken read: 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. + 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; + } + + // 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. void on_distance(int distance){ + if (m_goal.back){ + return; + } if (distance < m_best){ m_backend.log(std::format("[PLZA] walk_to_marker: {} to go", distance)); m_best = distance; @@ -137,18 +167,23 @@ class MarkerWalk{ m_sidesteps++; } - // Turns the camera toward the marker at `x` (0 to 1) and walks 0.6 s on. + // 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){ 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, 150ms); + pbf_move_right_joystick(m_env.context, {off > 0 ? 0.4 : -0.4, 0}, turn, /*release=*/150ms); } - pbf_move_left_joystick(m_env.context, /*position=*/{0, 1}, /*hold=*/600ms, /*release=*/0ms); + const double forward = m_goal.back ? -1 : 1; + pbf_move_left_joystick(m_env.context, /*position=*/{0, forward}, /*hold=*/600ms, /*release=*/0ms); } StoryEnv& m_env; PlzaBackend& m_backend; + const MarkerGoal m_goal; DistanceReads m_reads; int m_best = 1 << 30; int m_still = 0; @@ -172,23 +207,43 @@ bool objective_reached(PlzaBackend& backend){ } } -} // namespace - - -Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend){ - MarkerWalk walk(env, backend); - const WallClock deadline = current_time() + MARKER_WALK_LIMIT; +// `walk` until it arrives, loses the marker or `limit` passes. Returns +// whether it arrived. +bool run_marker_walk(MarkerWalk& walk, PlzaBackend& backend, Milliseconds limit){ + const WallClock deadline = current_time() + limit; while (current_time() < deadline){ backend.scope().throw_if_cancelled(); const MarkerStep step = walk.step(); if (step == MarkerStep::LOST){ - backend.log("[PLZA] walk_to_marker: the marker did not show for 12 camera turns"); - break; + backend.log("[PLZA] marker walk: the marker did not show for 12 camera turns"); + return false; } if (step == MarkerStep::ARRIVED){ - break; + return true; } } + backend.log(std::format("[PLZA] marker walk: out of time, last read {}", walk.last().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, .back = false}); + run_marker_walk(walk, backend, limit); + return walk.last(); +} + +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}); + run_marker_walk(walk, backend, limit); + return walk.last(); +} + +Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend){ + MarkerWalk walk(env, backend, MarkerGoal{}); + run_marker_walk(walk, backend, MARKER_WALK_LIMIT); if (!objective_reached(backend)){ return Pokemon::outcome_failed("objective_not_reached", "no A prompt or dialog at the objective marker"); } 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 c011312901..92d61c5f08 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h @@ -11,6 +11,8 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStoryMarkerWalk_H #define PokemonAutomation_PokemonLZA_AutoStoryMarkerWalk_H +#include +#include "Common/Cpp/Time.h" #include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h" @@ -28,6 +30,17 @@ 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. +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. +std::optional walk_back_from_marker(StoryEnv& env, PlzaBackend& backend, int stop_at, Milliseconds limit); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp new file mode 100644 index 0000000000..88679a3978 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp @@ -0,0 +1,92 @@ +/* PokemonLZA AutoStory - Caught mark reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/Images/BinaryImage_FilterRgb32.h" +#include "Kernels/Waterfill/Kernels_Waterfill_Session.h" +#include "PokemonLZA_AutoStoryCaughtMarkReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace Kernels::Waterfill; + + +namespace{ + +// The name plate's HP bar: the widest flat green bar in the upper two +// thirds of the screen, 80 px wide or more at 1080p. The green is kept +// tight (red 0-90, green 175+, blue 90-145; the bar is about 45, 198, +// 115): a wider range took in the bright grass around Bunnelby's plate +// (about 68, 160, 80), so the bar was no longer flat and the lock-on was +// missed (03.08, console B 2026-11-14). The player's own HP bar, over the +// head while a wild Pokemon attacks, is about 63 px wide; the plate's +// some 105-115 (Bunnelby's and Scatterbug's, the same frames). +std::optional find_plate_bar(const ImageViewRGB32& screen){ + if (screen.width() == 0 || screen.height() == 0){ + return std::nullopt; + } + const double scale = screen.height() / 1080.0; + const ImageViewRGB32 upper = extract_box_reference(screen, ImageFloatBox(0, 0, 1, 0.68)); + PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(upper, 0, 90, 175, 255, 90, 145); + std::unique_ptr session = make_WaterfillSession(matrix); + std::unique_ptr iter = session->make_iterator((size_t)(150 * scale * scale)); + std::optional best; + WaterfillObject object; + while (iter->find_next(object, false)){ + const size_t w = object.width() + 1; + const size_t h = object.height() + 1; + const bool flat = w >= 80 * scale && h <= 24 * scale && w >= 4 * h; + if (!flat || object.area * 2 < w * h){ + continue; + } + if (!best || w > best->width()){ + best = ImagePixelBox(object.min_x, object.min_y, object.max_x + 1, object.max_y + 1); + } + } + return best; +} + +} // namespace + + +std::optional lock_target_caught(const ImageViewRGB32& screen){ + const std::optional bar = find_plate_bar(screen); + if (!bar){ + return std::nullopt; + } + const double w = (double)bar->width(); + const size_t min_x = (size_t)(bar->min_x + 0.6 * w); + const size_t max_x = std::min(screen.width(), (size_t)(bar->min_x + 1.5 * w)); + const size_t min_y = (size_t)std::max(0.0, bar->min_y - 0.85 * w); + const size_t max_y = (size_t)std::max(0.0, bar->min_y - 0.45 * w); + size_t red = 0; + size_t white = 0; + for (size_t y = min_y; y < max_y; y++){ + for (size_t x = min_x; x < max_x; x++){ + const Color pixel(screen.pixel(x, y)); + const int r = pixel.red(); + // The ball's red is pinkish (blue about green); the gender + // mark next to it, on every plate, is orange (green well over + // blue) and is not counted (Scatterbug, console B 2026-11-14). + red += r > 190 && r > pixel.green() + 70 && r > pixel.blue() + 50 && pixel.blue() + 15 >= pixel.green(); + white += r > 215 && pixel.green() > 215 && pixel.blue() > 215; + } + } + // 37 red and 42 white at 1280x720 on the caught Mareep. + const double area_scale = (screen.height() / 720.0) * (screen.height() / 720.0); + return red >= 15 * area_scale && white >= 15 * area_scale; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h new file mode 100644 index 0000000000..151c108b5b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h @@ -0,0 +1,37 @@ +/* PokemonLZA AutoStory - Caught mark reader + * + * From: https://github.com/PokemonAutomation/ + * + * Whether the wild Pokemon locked on to is of a species already caught: + * its name plate then shows a Poke Ball after the level and gender. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryCaughtMarkReader_H +#define PokemonAutomation_PokemonLZA_AutoStoryCaughtMarkReader_H + +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// While ZL locks on to a wild Pokemon: true when its name plate shows the +// caught mark, false when the plate shows none, nothing when no plate was +// found. The plate is found by its HP bar, a green bar (about 45, 198, 115) +// at least 80 px wide on 1920x1080, in the upper two thirds of the +// screen; the mark, pinkish red over white, sits above the bar's right end +// (0.6-1.5 bar widths from its left, 0.45-0.85 above it), right of the +// orange gender mark. Tuned on Mareep, caught and not (2026-11-10), and +// Bunnelby and Scatterbug (2026-11-14), on console B. The plate shows +// whether or not the partner is out; the move symbols only when it is. +std::optional lock_target_caught(const ImageViewRGB32& screen); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp new file mode 100644 index 0000000000..bc9b1b98ed --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp @@ -0,0 +1,186 @@ +/* PokemonLZA AutoStory - Caught mark reader Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Synthetic 1920x1080 frames of the lock-on name plate. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "PokemonLZA_AutoStoryCaughtMarkReader.h" +#include "PokemonLZA_AutoStoryCaughtMarkReader_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr size_t WIDTH = 1920; +constexpr size_t HEIGHT = 1080; +constexpr uint32_t WHITE = 0xffffffff; + +void fill_box(size_t min_x, size_t min_y, size_t max_x, size_t max_y, uint32_t color, ImageRGB32& image){ + for (size_t y = min_y; y < max_y; y++){ + for (size_t x = min_x; x < max_x; x++){ + image.pixel(x, y) = color; + } + } +} + +ImageRGB32 solid_frame(uint32_t color){ + ImageRGB32 image(WIDTH, HEIGHT); + image.fill(color); + return image; +} + + +// The lock-on name plate's HP bar (lock_target_caught()'s), drawn as on +// console B's 03.08 frames (2026-11-14, 640 px, scaled here to 1920): +// the bar about 45, 198, 115 and 108 x 18 under the target's name; the +// bright grass around it (68, 160, 80, Bunnelby's plate at 60) and the +// player's own HP bar (63 x 12, over the head while a wild Pokemon +// attacks). Above the bar's right end, the gender mark (an orange disk +// with a white sign, about 255, 118, 68) and, for a species already +// caught, a Poke Ball (pinkish red over white, about 255, 107, 110): +// Scatterbug's plate shows only the first, Bunnelby's both. +constexpr uint32_t PLATE_BAR_GREEN = 0xff2dc673; +constexpr uint32_t GENDER_ORANGE = 0xffff7644; +constexpr uint32_t BALL_RED = 0xffff6b6e; +constexpr uint32_t BRIGHT_GRASS = 0xff44a050; +constexpr uint32_t DARK_GROUND = 0xff303030; + +// What plate_frame() draws besides `ground`. +struct PlateDrawing{ + bool plate_bar = false; // at x 950, y 515 + bool player_bar = false; // at x 990, y 560 + bool gender_mark = false; // at x 1020, y 430 + bool ball_mark = false; // at x 1056, y 430 +}; + +ImageRGB32 plate_frame(uint32_t ground, PlateDrawing drawing){ + ImageRGB32 image = solid_frame(ground); + if (drawing.plate_bar){ + fill_box(950, 515, 1058, 533, PLATE_BAR_GREEN, image); + } + if (drawing.player_bar){ + fill_box(990, 560, 1053, 572, PLATE_BAR_GREEN, image); + } + if (drawing.gender_mark){ + fill_box(1020, 430, 1044, 454, GENDER_ORANGE, image); + fill_box(1028, 438, 1036, 446, WHITE, image); + } + if (drawing.ball_mark){ + fill_box(1056, 430, 1080, 442, BALL_RED, image); + fill_box(1056, 442, 1080, 454, WHITE, image); + } + return image; +} + +struct PlateFrameCase{ + std::string name; + struct Input{ + std::function frame; + }; + Input input; + struct Expectation{ + // lock_target_caught(); none: no plate. + std::optional caught; + }; + Expectation expectation; +}; + +const PlateFrameCase PLATE_FRAME_CASES[] = { + { + .name = "the plate's bar on dark ground", + .input = {.frame = []{ return plate_frame(DARK_GROUND, {.plate_bar = true}); }}, + .expectation = {.caught = false}, + }, + { + .name = "the plate's bar on the bright grass it touches", + .input = {.frame = []{ return plate_frame(BRIGHT_GRASS, {.plate_bar = true}); }}, + .expectation = {.caught = false}, + }, + { + .name = "the plate's bar and the player's HP bar", + .input = {.frame = []{ return plate_frame(BRIGHT_GRASS, {.plate_bar = true, .player_bar = true}); }}, + .expectation = {.caught = false}, + }, + { + .name = "a plate with the gender mark only (Scatterbug, not caught)", + .input = {.frame = []{ return plate_frame(DARK_GROUND, {.plate_bar = true, .gender_mark = true}); }}, + .expectation = {.caught = false}, + }, + { + .name = "a plate with the gender mark and the Poke Ball (Bunnelby, caught)", + .input = {.frame = []{ return plate_frame(DARK_GROUND, {.plate_bar = true, .gender_mark = true, .ball_mark = true}); }}, + .expectation = {.caught = true}, + }, + { + .name = "the player's HP bar alone", + .input = {.frame = []{ return plate_frame(DARK_GROUND, {.player_bar = true}); }}, + .expectation = {.caught = std::nullopt}, + }, + { + .name = "bright grass alone", + .input = {.frame = []{ return plate_frame(BRIGHT_GRASS, {}); }}, + .expectation = {.caught = std::nullopt}, + }, + { + .name = "a frame all in the bar's green", + .input = {.frame = []{ return solid_frame(PLATE_BAR_GREEN); }}, + .expectation = {.caught = std::nullopt}, + }, + { + .name = "an empty frame", + .input = {.frame = []{ return ImageRGB32(); }}, + .expectation = {.caught = std::nullopt}, + }, +}; + +std::string describe(const std::optional& caught){ + if (!caught){ + return "no plate"; + } + return *caught ? "a plate with the caught mark" : "a plate with no caught mark"; +} + +class Test_PlateFrame : public UnitTest{ +public: + explicit Test_PlateFrame(const PlateFrameCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - Caught mark reader: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::optional caught = lock_target_caught(m_test.input.frame()); + if (caught != m_test.expectation.caught){ + return std::format("Expected {}, read {}.", describe(m_test.expectation.caught), describe(caught)); + } + return true; + } + +private: + const PlateFrameCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryCaughtMarkReader(UnitTestDatabase& database){ + for (const PlateFrameCase& test : PLATE_FRAME_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h new file mode 100644 index 0000000000..eb2e106bb2 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Caught mark reader Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryCaughtMarkReader_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryCaughtMarkReader_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the lock-on plate and caught mark reader's tests, on +// synthetic frames. +void add_tests_AutoStoryCaughtMarkReader(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 8151d250dd..9b49b30639 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -75,9 +75,16 @@ std::vector console_specs(){ console_only(game_spec("confirm_new_game")), console_only(game_spec("run_to_gate", { optional_ms("timeout_ms", 8000, "running this long with no A prompt fails the step"), + StoryArgSpec{ + .key = "heading", .type = StoryArgType::INTEGER, .required = false, .fallback = std::nullopt, + .why = "the minimap heading to face first, degrees clockwise from up", + }, })), + console_only(game_spec("leave_zone_gate")), console_only(game_spec("catch_tutorial")), console_only(game_spec("battle_then_catch")), + console_only(game_spec("catch_in_zone")), + console_only(game_spec("walk_back_to_zone_road")), console_only(game_spec("walk_to_marker")), console_only(game_spec("claim_mable_research_reward")), }; @@ -167,10 +174,32 @@ Handler confirm_handler(StoryEnv* env){ } -// "run_to_gate" on the console `env`; none: fails as console_only. Runs -// straight on with upstream's run_towards_gate_with_A_button() until the -// gate's A prompt; once more after a day/night change, which stops the run. -// Fails as "gate_not_reached" when the run ends with no prompt. +// How close to a run's heading the minimap's arrow must read. +constexpr double HEADING_TOLERANCE = 10; + +// Turns the player to `heading` on the minimap (upstream's +// get_facing_direction(): 0 up, 90 right) with story_turn(), 4 turns at +// most, then L puts the camera behind the player, so a run forward goes +// that way (console B, 2026-11-14). Fails as "heading_missed". +Outcome face_heading(StoryEnv& env, PlzaBackend& backend, double heading){ + for (int turns = 0; turns <= 4; turns++){ + const double now = get_facing_direction(env.env.console, env.context); + if (get_angle_between_facing_directions(now, heading) <= HEADING_TOLERANCE){ + backend.press(BUTTON_L, /*hold=*/100ms, /*release=*/150ms); + return Pokemon::outcome_ok(); + } + if (turns < 4){ + story_turn(backend, heading - now); + } + } + return Pokemon::outcome_failed("heading_missed", std::format("not facing {:.0f} deg after 4 turns", heading)); +} + +// "run_to_gate" on the console `env`; none: fails as console_only. Faces +// the arg "heading" first, if given (face_heading()). Runs straight on +// with upstream's run_towards_gate_with_A_button() until the gate's A +// prompt; once more after a day/night change, which stops the run. Fails +// as "gate_not_reached" when the run ends with no prompt. Handler gate_run_handler(StoryEnv* env){ if (env == nullptr){ return [](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ @@ -182,6 +211,13 @@ Handler gate_run_handler(StoryEnv* env){ // 0: the A prompt, 1: a day/night change, else no prompt. int result = 1; try{ + const auto heading = call.args.find("heading"); + if (heading != call.args.end()){ + const Outcome faced = face_heading(*env, backend, (double)std::get(heading->second)); + if (!faced.succeeded()){ + return faced; + } + } for (size_t runs = 0; runs < 2 && result == 1; runs++){ result = run_towards_gate_with_A_button( env->env.console, env->context, /*run_direction_x=*/0, /*run_direction_y=*/1, timeout @@ -225,6 +261,17 @@ Outcome claim_research_reward(StoryEnv& env, PlzaBackend& backend){ return Pokemon::outcome_ok(); } +// At a wild zone's gate on the way out, its "A Leave" prompt up: A +// through the gate to the street with upstream's leave_zone_gate(). +// Fails as "gate_left_unsure" when a day/night change came on the way +// (upstream cannot tell then whether the player left). +Outcome leave_gate(StoryEnv& env, PlzaBackend&){ + if (!leave_zone_gate(env.env.console, env.context)){ + return Pokemon::outcome_failed("gate_left_unsure", "a day/night change while leaving the zone's gate"); + } + return Pokemon::outcome_ok(); +} + // A console action's body. using ConsoleStep = Outcome (*)(StoryEnv& env, PlzaBackend& backend); @@ -237,6 +284,12 @@ const std::map& console_steps(){ {"battle_then_catch", [](StoryEnv& env, PlzaBackend& backend){ return battle_then_catch(env, backend, /*max_rounds=*/6); }}, + {"catch_in_zone", [](StoryEnv& env, PlzaBackend& backend){ + // 5 registered species, 3 after the tutorial; 12 throws. + return catch_in_zone(env, backend, ZoneCatchGoal{.party_species = 5, .max_throws = 12}); + }}, + {"walk_back_to_zone_road", walk_back_to_zone_road}, + {"leave_zone_gate", leave_gate}, {"walk_to_marker", walk_to_marker}, {"claim_mable_research_reward", claim_research_reward}, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 4a447ab709..0c7d0d8c4b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -75,8 +75,15 @@ namespace PokemonLZA{ // Pokedex app (03.04) // "run_to_gate" console_only: straight on to a zone gate's A // prompt (upstream's -// run_towards_gate_with_A_button()), arg -// "timeout_ms" +// run_towards_gate_with_A_button()), args +// "timeout_ms" and "heading", the minimap +// heading faced first +// "leave_zone_gate" console_only: A through a zone's gate on the +// way out (upstream's leave_zone_gate()) +// "catch_in_zone" console_only: 03.08's patrol of Wild Zone 1's +// road until the party bar shows 5 species +// "walk_back_to_zone_road" console_only: back onto Wild Zone 1's +// road at the catch spot by the far gate // // Later slices add rows here, each with its handler. const std::vector& plza_story_specs(); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp index 86f0c6fe08..17eb7dffbb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -69,7 +69,8 @@ const StoryDataCase STORY_DATA_CASES[] = { "02.01:from_save:unverified 02.02:from_save:unverified 02.03:from_save:unverified 02.04:from_save:unverified " "02.05:from_save:unverified 02.06:from_save:autosave 02.07:from_save:unverified " "03.01:from_save:autosave 03.02:from_save 03.03:from_save:autosave 03.04:from_save " - "03.05:from_save:autosave 03.06:from_save 03.07:from_save:autosave 03.09:from_save:unverified " + "03.05:from_save:autosave 03.06:from_save 03.07:from_save:autosave 03.08:from_save:autosave 03.08b:from_save " + "03.09:from_save:unverified " "03.10:from_save:autosave 03.11:from_save:unverified" }, }, @@ -567,6 +568,26 @@ const RunCase RUN_CASES[] = { .input = {.checkpoint = "03.07", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, .expectation = {.verdict = "failed at catch_fletchling: console_only", .inputs = ""}, }, + { + .name = "03.08's patrol for two more species needs a console", + .input = {.checkpoint = "03.08", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at catch_more_species: console_only", .inputs = ""}, + }, + { + .name = "03.08b's walk back to Wild Zone 1's road needs a console", + .input = {.checkpoint = "03.08b", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at zone_1_back_to_road: console_only", .inputs = ""}, + }, + { + .name = "03.08b's run to the far gate needs a console", + .input = {.checkpoint = "03.08b", .first_step = 1, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at zone_1_to_far_gate: console_only", .inputs = ""}, + }, + { + .name = "03.08b's way out of the gate needs a console", + .input = {.checkpoint = "03.08b", .first_step = 2, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at leave_zone_1: console_only", .inputs = ""}, + }, { .name = "03.09's walk to the objective marker needs a console", .input = {.checkpoint = "03.09", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, 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 new file mode 100644 index 0000000000..6e24281532 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08.plan.json @@ -0,0 +1,26 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "plza", + "checkpoint": { + "id": "03.08", + "title": "Wild Zone 1: five species", + "start": { + "place": "WildZone1" + }, + "events": [ + { + "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).", + "action": "catch_in_zone" + } + ], + "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." + } + }, + "execution": { + "save": "autosave" + } +} diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08b.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08b.plan.json new file mode 100644 index 0000000000..ef4d22f676 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.08b.plan.json @@ -0,0 +1,37 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "plza", + "checkpoint": { + "id": "03.08b", + "title": "Out of Wild Zone 1's far gate", + "start": { + "place": "WildZone1" + }, + "events": [ + { + "id": "zone_1_back_to_road", + "kind": "game_action", + "why": "step 62: back onto the road at the catch spots (60, and 100 first when further), by the objective marker. The marker is not on the far gate but past it to its left, behind the zone's fence: a walk at it from 60 was held up at 36 and wandered to 49 inside the zone (console B, 2026-11-13 and 2026-11-14).", + "action": "walk_back_to_zone_road" + }, + { + "id": "zone_1_to_far_gate", + "kind": "game_action", + "why": "step 62: from 60 the far gate is straight down the road; walked by hand to its \"A Leave\" prompt in about 4.7 s, the minimap heading 259 at the prompt with the gate right of centre (console B, 2026-11-14). Faces 265, then runs on to the prompt.", + "action": "run_to_gate", + "args": {"heading": 265, "timeout_ms": 15000} + }, + { + "id": "leave_zone_1", + "kind": "game_action", + "why": "step 62: A Leave, out on the street (a plain scene step ends at once on the gate's prompt with the party bar up; console B, 2026-11-10)", + "action": "leave_zone_gate" + } + ], + "metadata": { + "phase": "testing", + "source": "console B recording, 2026-11-08/09: played step by step from a new game; split from 03.08 at the last catch's autosave, so a checkpoint starts where a save reloads. Starts where that autosave reloads, in Wild Zone 1 at the last catch spot; ends out on the street just through the far gate (user, 2026-11-14), 03.09's start. No save: no autosave at its end was seen in a run log." + } + }, + "execution": {} +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b8dfe93e3d..440a6f6b3b 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2284,6 +2284,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Inference/PokemonLZA_MainMenuDetector.h Source/VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.cpp Source/VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h + Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp + Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h Source/VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.cpp Source/VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h Source/VideoGames/PokemonLZA/Inference/PokemonLZA_WeatherDetector.cpp @@ -2328,6 +2330,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp From c0445428f11becb994ac63d20c941d92e63b41bd Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 17:54:16 -0800 Subject: [PATCH 02/14] PLZA AutoStory: 03.08 code health fixes --- .../Inference/PokemonLZA_PartyBarDetector.cpp | 2 +- .../Actions/PokemonLZA_AutoStoryCatches.cpp | 102 +++++++++++------- .../PokemonLZA_AutoStoryMarkerWalk.cpp | 26 +++-- .../PokemonLZA_AutoStoryCaughtMarkReader.cpp | 42 +++++--- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 40 ++++--- 5 files changed, 131 insertions(+), 81 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp index 15a141c553..a7c74d4c13 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp @@ -152,7 +152,7 @@ class Test_PartyBarDetector : public ImageUnitTest{ explicit Test_PartyBarDetector(const PartyBarCase& test_case) : ImageUnitTest( std::format("PokemonLZA::PartyBarDetector - {}", test_case.name), - {"PokemonLZA/PartyBarDetector/" + test_case.input.image} + {std::format("PokemonLZA/PartyBarDetector/{}", test_case.input.image)} ) , m_case(test_case) {} 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 3ffd01f38c..13dcb3bf63 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.cpp @@ -241,7 +241,7 @@ void level_camera(StoryEnv& env){ // Rounds of weaken_target() and a throw, with A through the lines, while // a wild battle is on: until it is over (caught, or the target gone), a // round lands nothing, or `max_throws`. Returns the throws. -int weaken_and_throw(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& battle_state, int max_throws){ +int weaken_and_throw(StoryEnv& env, PlzaBackend& backend, int max_throws, TrainerBattleState& battle_state){ int throws = 0; while (throws < max_throws && wild_battle_on(env)){ const int landed = weaken_target(env, backend, battle_state); @@ -261,11 +261,11 @@ int weaken_and_throw(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& ba // 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. -int fight_back(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& battle_state, int max_throws){ +int fight_back(StoryEnv& env, PlzaBackend& backend, int max_throws, TrainerBattleState& battle_state){ const std::optional caught = HeldZl(env).wait_for_plate(LOCK_ON_WAIT); if (caught != true){ backend.log("[PLZA] catch_in_zone: a wild battle at the stop: weakening and throwing"); - return weaken_and_throw(env, backend, battle_state, max_throws); + return weaken_and_throw(env, backend, max_throws, battle_state); } backend.log("[PLZA] catch_in_zone: a wild battle with a species already caught: fighting it off"); for (int round = 0; round < 3 && wild_battle_on(env); round++){ @@ -281,11 +281,11 @@ int fight_back(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& battle_s // 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, TrainerBattleState& battle_state, int max_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, battle_state, max_throws); + throws += fight_back(env, backend, max_throws, battle_state); break; } if (lock_on_not_caught(env, backend) != LockOn::NOT_CAUGHT){ @@ -295,7 +295,7 @@ int catch_at_stop(StoryEnv& env, PlzaBackend& backend, TrainerBattleState& battl throw_ball(env.context, STORY_THROW); throws++; press_a_through_lines(backend, LINES_QUIET, LINES_LIMIT); - throws += weaken_and_throw(env, backend, battle_state, max_throws - throws); + throws += weaken_and_throw(env, backend, max_throws - throws, battle_state); } level_camera(env); return throws; @@ -345,6 +345,56 @@ std::optional objective_distance_now(StoryEnv& env){ return marker->distance; } +// What the patrol came to: the party bar's last read, the throws. +struct Patrol{ + 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}; + 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)); + if (thrown > 0){ + patrol.slots = read_party_slots(env, backend); + } + if (party_done(patrol.slots, goal)){ + break; + } + } + return patrol; +} + +// The road stops to walk through from `at` from the objective, in order: +// the spots of ROAD_SPOTS nearer the gate, furthest first; at or past the +// one nearest the gate, that one: back onto the road there first, as a +// walk at the gate from off the road ran into a building west of the zone +// (console B, 2026-11-13, last read 49). With no distance read, every spot. +std::vector road_stops_to_gate(std::optional at){ + std::vector stops; + for (int spot : ROAD_SPOTS){ + if (!at || spot < *at){ + stops.push_back(spot); + } + } + if (stops.empty()){ + stops.push_back(ROAD_SPOTS[std::size(ROAD_SPOTS) - 1]); + } + return stops; +} + } // namespace @@ -356,51 +406,24 @@ Pokemon::Outcome catch_in_zone(StoryEnv& env, PlzaBackend& backend, const ZoneCa if (start && *start >= 115){ pbf_move_left_joystick(env.context, /*position=*/{1, 0}, /*hold=*/Milliseconds(1000), /*release=*/Milliseconds(300)); } - std::optional slots = read_party_slots(env, backend); + 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(); } - TrainerBattleState battle_state(env.battle_ai); - const WallClock deadline = current_time() + PATROL_LIMIT; - int throws = 0; - std::optional last; - for (size_t visit = 0; visit < PATROL_VISITS && 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, battle_state, goal.max_throws - throws); - throws += thrown; - backend.log(std::format("[PLZA] catch_in_zone: stop {} at {} (for {}): {} throws", visit + 1, at.value_or(-1), stop, thrown)); - if (thrown == 0){ - continue; - } - slots = read_party_slots(env, backend); - if (party_done(slots, goal)){ - return Pokemon::outcome_ok(); - } + const Patrol patrol = patrol_road(env, backend, goal, slots); + if (party_done(patrol.slots, goal)){ + return Pokemon::outcome_ok(); } return Pokemon::outcome_failed("short_of_species", std::format( "the party bar shows {} of {} species after {} throws", - slots ? std::to_string(*slots) : std::string("no read"), goal.party_species, throws + patrol.slots ? std::to_string(*patrol.slots) : std::string("no read"), goal.party_species, patrol.throws )); } Pokemon::Outcome walk_back_to_zone_road(StoryEnv& env, PlzaBackend& backend){ std::optional at = objective_distance_now(env); - std::vector stops; - for (int spot : ROAD_SPOTS){ - if (!at || spot < *at){ - stops.push_back(spot); - } - } - if (stops.empty()){ - // At or past 60: back onto the road there first, as a walk at the - // gate from off the road ran into a building west of the zone - // (console B, 2026-11-13, last read 49). - stops.push_back(ROAD_SPOTS[std::size(ROAD_SPOTS) - 1]); - } - for (int stop : stops){ + 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; const std::optional reached = walk_to_stop(env, backend, at, stop); @@ -416,7 +439,6 @@ Pokemon::Outcome walk_back_to_zone_road(StoryEnv& env, PlzaBackend& backend){ } - } // namespace PokemonLZA } // namespace NintendoSwitch } // namespace PokemonAutomation 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 247aff2e4b..bedf7a0bd0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp @@ -114,18 +114,24 @@ class MarkerWalk{ pbf_move_right_joystick(m_env.context, {marker->x < 0.5 ? -0.5 : 0.5, 0}, /*hold=*/400ms, /*release=*/200ms); return MarkerStep::WALKING; } - 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 on_marker(*marker); + } + +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. + 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; } - on_distance(marker->distance); + on_distance(marker.distance); } - steer_and_step(marker->x); + steer_and_step(marker.x); return MarkerStep::WALKING; } -private: // The marker is behind: turn the camera toward where it was last. MarkerStep look_behind(){ if (++m_unseen > 12){ @@ -209,7 +215,7 @@ bool objective_reached(PlzaBackend& backend){ // `walk` until it arrives, loses the marker or `limit` passes. Returns // whether it arrived. -bool run_marker_walk(MarkerWalk& walk, PlzaBackend& backend, Milliseconds limit){ +bool run_marker_walk(Milliseconds limit, MarkerWalk& walk, PlzaBackend& backend){ const WallClock deadline = current_time() + limit; while (current_time() < deadline){ backend.scope().throw_if_cancelled(); @@ -231,19 +237,19 @@ bool run_marker_walk(MarkerWalk& walk, PlzaBackend& backend, Milliseconds limit) 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}); - run_marker_walk(walk, backend, limit); + run_marker_walk(limit, walk, backend); return walk.last(); } 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}); - run_marker_walk(walk, backend, limit); + run_marker_walk(limit, walk, backend); return walk.last(); } Pokemon::Outcome walk_to_marker(StoryEnv& env, PlzaBackend& backend){ MarkerWalk walk(env, backend, MarkerGoal{}); - run_marker_walk(walk, backend, MARKER_WALK_LIMIT); + run_marker_walk(MARKER_WALK_LIMIT, walk, backend); if (!objective_reached(backend)){ return Pokemon::outcome_failed("objective_not_reached", "no A prompt or dialog at the objective marker"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp index 88679a3978..ddff012283 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp @@ -57,18 +57,22 @@ std::optional find_plate_bar(const ImageViewRGB32& screen){ } // namespace -std::optional lock_target_caught(const ImageViewRGB32& screen){ - const std::optional bar = find_plate_bar(screen); - if (!bar){ - return std::nullopt; - } - const double w = (double)bar->width(); - const size_t min_x = (size_t)(bar->min_x + 0.6 * w); - const size_t max_x = std::min(screen.width(), (size_t)(bar->min_x + 1.5 * w)); - const size_t min_y = (size_t)std::max(0.0, bar->min_y - 0.85 * w); - const size_t max_y = (size_t)std::max(0.0, bar->min_y - 0.45 * w); +namespace{ + +// The Poke Ball's pixels in the box where the caught mark sits above +// `bar`: pinkish red and white. +struct MarkPixels{ size_t red = 0; size_t white = 0; +}; + +MarkPixels count_mark_pixels(const ImageViewRGB32& screen, const ImagePixelBox& bar){ + const double w = (double)bar.width(); + const size_t min_x = (size_t)(bar.min_x + 0.6 * w); + const size_t max_x = std::min(screen.width(), (size_t)(bar.min_x + 1.5 * w)); + const size_t min_y = (size_t)std::max(0.0, bar.min_y - 0.85 * w); + const size_t max_y = (size_t)std::max(0.0, bar.min_y - 0.45 * w); + MarkPixels counts; for (size_t y = min_y; y < max_y; y++){ for (size_t x = min_x; x < max_x; x++){ const Color pixel(screen.pixel(x, y)); @@ -76,13 +80,25 @@ std::optional lock_target_caught(const ImageViewRGB32& screen){ // The ball's red is pinkish (blue about green); the gender // mark next to it, on every plate, is orange (green well over // blue) and is not counted (Scatterbug, console B 2026-11-14). - red += r > 190 && r > pixel.green() + 70 && r > pixel.blue() + 50 && pixel.blue() + 15 >= pixel.green(); - white += r > 215 && pixel.green() > 215 && pixel.blue() > 215; + counts.red += r > 190 && r > pixel.green() + 70 && r > pixel.blue() + 50 && pixel.blue() + 15 >= pixel.green(); + counts.white += r > 215 && pixel.green() > 215 && pixel.blue() > 215; } } + return counts; +} + +} // namespace + + +std::optional lock_target_caught(const ImageViewRGB32& screen){ + const std::optional bar = find_plate_bar(screen); + if (!bar){ + return std::nullopt; + } + const MarkPixels counts = count_mark_pixels(screen, *bar); // 37 red and 42 white at 1280x720 on the caught Mareep. const double area_scale = (screen.height() / 720.0) * (screen.height() / 720.0); - return red >= 15 * area_scale && white >= 15 * area_scale; + return counts.red >= 15 * area_scale && counts.white >= 15 * area_scale; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 9b49b30639..c401ff830b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -195,11 +195,27 @@ Outcome face_heading(StoryEnv& env, PlzaBackend& backend, double heading){ return Pokemon::outcome_failed("heading_missed", std::format("not facing {:.0f} deg after 4 turns", heading)); } -// "run_to_gate" on the console `env`; none: fails as console_only. Faces -// the arg "heading" first, if given (face_heading()). Runs straight on -// with upstream's run_towards_gate_with_A_button() until the gate's A -// prompt; once more after a day/night change, which stops the run. Fails -// as "gate_not_reached" when the run ends with no prompt. +// "run_to_gate"'s run: straight on with upstream's +// run_towards_gate_with_A_button() until the gate's A prompt; once more +// after a day/night change, which stops the run. Fails as +// "gate_not_reached" when the run ends with no prompt. +Outcome run_to_gate(StoryEnv& env, Milliseconds timeout){ + // 0: the A prompt, 1: a day/night change, else no prompt. + int result = 1; + for (size_t runs = 0; runs < 2 && result == 1; runs++){ + result = run_towards_gate_with_A_button( + env.env.console, env.context, /*run_direction_x=*/0, /*run_direction_y=*/1, timeout + ); + } + if (result != 0){ + return Pokemon::outcome_failed("gate_not_reached", std::format("no gate A prompt in {} ms of running", timeout.count())); + } + return Pokemon::outcome_ok(); +} + +// The handler of "run_to_gate" on the console `env`; none: fails as +// console_only. Its arg "heading", if given, is faced first +// (face_heading()), then run_to_gate(). Handler gate_run_handler(StoryEnv* env){ if (env == nullptr){ return [](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ @@ -208,29 +224,19 @@ Handler gate_run_handler(StoryEnv* env){ } return [env](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ const Milliseconds timeout(Pokemon::story_arg(call.args, "timeout_ms")); - // 0: the A prompt, 1: a day/night change, else no prompt. - int result = 1; + const auto heading = call.args.find("heading"); try{ - const auto heading = call.args.find("heading"); if (heading != call.args.end()){ const Outcome faced = face_heading(*env, backend, (double)std::get(heading->second)); if (!faced.succeeded()){ return faced; } } - for (size_t runs = 0; runs < 2 && result == 1; runs++){ - result = run_towards_gate_with_A_button( - env->env.console, env->context, /*run_direction_x=*/0, /*run_direction_y=*/1, timeout - ); - } + return run_to_gate(*env, timeout); }catch (OperationFailedException& e){ backend.log(std::format("[PLZA] run_to_gate failed: {}", e.message())); return Pokemon::outcome_failed("gate_not_reached", e.message()); } - if (result != 0){ - return Pokemon::outcome_failed("gate_not_reached", std::format("no gate A prompt in {} ms of running", timeout.count())); - } - return Pokemon::outcome_ok(); }; } From 3e8d835bc8122b4da793186026322206791230b0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 18:11:15 -0800 Subject: [PATCH 03/14] PLZA: style fixes in the 03.08 readers Name the drawn plate boxes in the caught-mark tests, comment the filter range arguments, and keep party_bar_filled_slots in the detector's .cpp, since only its tests call it. --- .../Inference/PokemonLZA_PartyBarDetector.cpp | 6 ++--- .../Inference/PokemonLZA_PartyBarDetector.h | 3 --- .../PokemonLZA_AutoStoryCaughtMarkReader.cpp | 7 ++++- ...monLZA_AutoStoryCaughtMarkReader_Tests.cpp | 27 ++++++++++++------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp index a7c74d4c13..4e4e81e0b1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.cpp @@ -108,15 +108,15 @@ bool PartyBarDetector::detect(const ImageViewRGB32& screen){ return true; } +namespace{ + +// The filled slots of the party bar on `screen`: 0 when no bar is on it. int party_bar_filled_slots(const ImageViewRGB32& screen){ PartyBarDetector detector; detector.detect(screen); return detector.filled_slots(); } - -namespace{ - struct PartyBarCase{ std::string name; struct Input{ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h index ffe6295f54..46ef8b2e88 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Inference/PokemonLZA_PartyBarDetector.h @@ -57,9 +57,6 @@ class PartyBarDetector : public StaticScreenDetector{ int m_filled_slots = 0; }; -// The filled slots of the party bar on `screen`: 0 when no bar is on it. -int party_bar_filled_slots(const ImageViewRGB32& screen); - // Registers the party bar detector's tests on the PartyBarDetector frames. void add_tests_PartyBarDetector(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp index ddff012283..432ed76afa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader.cpp @@ -35,7 +35,12 @@ std::optional find_plate_bar(const ImageViewRGB32& screen){ } const double scale = screen.height() / 1080.0; const ImageViewRGB32 upper = extract_box_reference(screen, ImageFloatBox(0, 0, 1, 0.68)); - PackedBinaryMatrix matrix = compress_rgb32_to_binary_range(upper, 0, 90, 175, 255, 90, 145); + PackedBinaryMatrix matrix = compress_rgb32_to_binary_range( + upper, + /*min_red=*/0, /*max_red=*/90, + /*min_green=*/175, /*max_green=*/255, + /*min_blue=*/90, /*max_blue=*/145 + ); std::unique_ptr session = make_WaterfillSession(matrix); std::unique_ptr iter = session->make_iterator((size_t)(150 * scale * scale)); std::optional best; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp index bc9b1b98ed..aaf1e18901 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryCaughtMarkReader_Tests.cpp @@ -12,6 +12,7 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "PokemonLZA_AutoStoryCaughtMarkReader.h" #include "PokemonLZA_AutoStoryCaughtMarkReader_Tests.h" @@ -27,9 +28,17 @@ constexpr size_t WIDTH = 1920; constexpr size_t HEIGHT = 1080; constexpr uint32_t WHITE = 0xffffffff; -void fill_box(size_t min_x, size_t min_y, size_t max_x, size_t max_y, uint32_t color, ImageRGB32& image){ - for (size_t y = min_y; y < max_y; y++){ - for (size_t x = min_x; x < max_x; x++){ +// Where the drawn frames put the name plate's parts, in 1080p pixels. +const ImagePixelBox PLATE_BAR_BOX(950, 515, 1058, 533); +const ImagePixelBox PLAYER_BAR_BOX(990, 560, 1053, 572); +const ImagePixelBox GENDER_MARK_BOX(1020, 430, 1044, 454); +const ImagePixelBox GENDER_MARK_HOLE_BOX(1028, 438, 1036, 446); +const ImagePixelBox BALL_MARK_TOP_BOX(1056, 430, 1080, 442); +const ImagePixelBox BALL_MARK_BOTTOM_BOX(1056, 442, 1080, 454); + +void fill_box(const ImagePixelBox& box, uint32_t color, ImageRGB32& image){ + for (size_t y = box.min_y; y < box.max_y; y++){ + for (size_t x = box.min_x; x < box.max_x; x++){ image.pixel(x, y) = color; } } @@ -68,18 +77,18 @@ struct PlateDrawing{ ImageRGB32 plate_frame(uint32_t ground, PlateDrawing drawing){ ImageRGB32 image = solid_frame(ground); if (drawing.plate_bar){ - fill_box(950, 515, 1058, 533, PLATE_BAR_GREEN, image); + fill_box(PLATE_BAR_BOX, PLATE_BAR_GREEN, image); } if (drawing.player_bar){ - fill_box(990, 560, 1053, 572, PLATE_BAR_GREEN, image); + fill_box(PLAYER_BAR_BOX, PLATE_BAR_GREEN, image); } if (drawing.gender_mark){ - fill_box(1020, 430, 1044, 454, GENDER_ORANGE, image); - fill_box(1028, 438, 1036, 446, WHITE, image); + fill_box(GENDER_MARK_BOX, GENDER_ORANGE, image); + fill_box(GENDER_MARK_HOLE_BOX, WHITE, image); } if (drawing.ball_mark){ - fill_box(1056, 430, 1080, 442, BALL_RED, image); - fill_box(1056, 442, 1080, 454, WHITE, image); + fill_box(BALL_MARK_TOP_BOX, BALL_RED, image); + fill_box(BALL_MARK_BOTTOM_BOX, WHITE, image); } return image; } From b5338783ffd238167b668a8d8ed0a2cfa081d80d Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:03:42 -0800 Subject: [PATCH 04/14] PLZA scene machine: per-screen lines to the file log only StoryBackend::log_detail() writes the file log only (log() by default); PLZA's console backend skips the overlay there and FakeStoryBackend records it in lines() but not overlay_lines(). The scene machine sends its per-screen lines and press summaries through it; black fades (with their count, "fade 2/3"), the banner and the controls hint showing, and the step's own lines stay on the overlay. --- .../AutoStory/Engine/Pokemon_StoryBackend.h | 5 ++ .../Engine/Pokemon_StoryFakeBackend.cpp | 6 +++ .../Engine/Pokemon_StoryFakeBackend.h | 10 +++- .../AutoStory/PokemonLZA_AutoStoryBackend.cpp | 4 ++ .../AutoStory/PokemonLZA_AutoStoryBackend.h | 2 + .../PokemonLZA_AutoStorySceneMachine.cpp | 41 ++++++++++++-- .../PokemonLZA_AutoStorySceneMachine.h | 4 +- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 53 +++++++++++++++++++ 8 files changed, 117 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h index 154b9d8b2d..65f822decc 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h @@ -83,6 +83,11 @@ class StoryBackend{ // Outcome. virtual Outcome battle() = 0; virtual void log(std::string_view line) = 0; + // A line for the file log only, not the stream's overlay: detail a + // watcher does not need (each screen of a scene). log() by default. + virtual void log_detail(std::string_view line){ + log(line); + } virtual CancellableScope& scope() = 0; }; diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.cpp b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.cpp index d326db3dd0..5e30b6260e 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.cpp +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.cpp @@ -82,6 +82,12 @@ Outcome FakeStoryBackend::battle(){ template void FakeStoryBackend::log(std::string_view line){ m_lines.emplace_back(line); + m_overlay_lines.emplace_back(line); +} + +template +void FakeStoryBackend::log_detail(std::string_view line){ + m_lines.emplace_back(line); } template diff --git a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h index 3ad8c014ed..63c2267d37 100644 --- a/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h +++ b/SerialPrograms/Source/Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h @@ -38,7 +38,7 @@ struct FakeStoryScript{ // The backend of the engine's unit tests and of a game's scripted tests, // for any pose type. -// code-health: allow public_methods -- the backend calls it fakes plus the two recordings tests read; nothing to split +// code-health: allow public_methods -- the backend calls it fakes plus the three recordings tests read; nothing to split // code-health: allow test_only_api -- a test double: the scripted backend the engine and game tests run on template class FakeStoryBackend : public StoryBackend{ @@ -52,10 +52,14 @@ class FakeStoryBackend : public StoryBackend{ const std::vector& inputs() const{ return m_inputs; } - // Each log line, in order. + // Each log line, in order, log_detail()'s too: the file log. const std::vector& lines() const{ return m_lines; } + // The lines log() wrote, in order: the stream's overlay. + const std::vector& overlay_lines() const{ + return m_overlay_lines; + } virtual StoryBackendKind kind() const override; virtual void press(NintendoSwitch::Button button, Milliseconds hold, Milliseconds release) override; @@ -66,6 +70,7 @@ class FakeStoryBackend : public StoryBackend{ virtual Observation observe() override; virtual Outcome battle() override; virtual void log(std::string_view line) override; + virtual void log_detail(std::string_view line) override; virtual CancellableScope& scope() override; private: @@ -74,6 +79,7 @@ class FakeStoryBackend : public StoryBackend{ size_t m_next_look = 0; std::vector m_inputs; std::vector m_lines; + std::vector m_overlay_lines; }; // Instantiated for ZonePose (Pokemon_ZonePose.h), in diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp index 5c19178800..638e5d49e4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp @@ -113,6 +113,10 @@ void PlzaConsoleBackend::log(std::string_view line){ m_env.env.console.overlay().add_log(std::string(line)); } +void PlzaConsoleBackend::log_detail(std::string_view line){ + m_env.env.console.log(std::string(line), COLOR_BLUE); +} + CancellableScope& PlzaConsoleBackend::scope(){ return m_env.context; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h index dc815b9791..4fe02f79e5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -86,6 +86,8 @@ class PlzaConsoleBackend : public PlzaBackend{ // To the console's log and the stream's overlay log: the checkpoint and // the step under way, for whoever watches. virtual void log(std::string_view line) override; + // To the console's log only. + virtual void log_detail(std::string_view line) override; virtual CancellableScope& scope() override; private: diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index f08cdce999..f9dc6b1ba5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -72,6 +72,10 @@ class SceneTimeline{ // Whether end_after_black_fades' last fade has settled by `now`. bool fades_settled(WallClock now) const; + // "fade 2/3": the black fades waited out so far, of + // end_after_black_fades' ("fade 2" without it). + std::string black_fade_count() const; + // Whether the mission banner has shown on any look. bool banner_seen() const{ return m_banner_seen; @@ -234,6 +238,14 @@ bool scene_screen_presses(SceneScreen screen){ return screen == SceneScreen::DIALOG || screen == SceneScreen::MISSION_COMPLETE || screen == SceneScreen::BLIND_PRESS; } +// Whether this state's lines go on the stream's overlay too, for whoever +// watches: a black fade (with its count), the mission banner and the +// controls hint showing. The text, cutscenes, white fades, presses and +// ends go to the file log only; the step's own lines say how it ended. +bool scene_screen_for_watcher(SceneScreen screen){ + return screen == SceneScreen::FADE_BLACK || screen == SceneScreen::BANNER_SHOWING || screen == SceneScreen::HINT_SHOWING; +} + SceneTimeline::SceneTimeline(SceneMachineConfig config, WallClock start) : m_config(std::move(config)) @@ -261,6 +273,13 @@ bool SceneTimeline::fades_settled(WallClock now) const{ return m_settled_since && now - *m_settled_since >= FADE_SETTLE; } +std::string SceneTimeline::black_fade_count() const{ + if (!m_config.end_after_black_fades){ + return std::format("fade {}", m_black_fades); + } + return std::format("fade {}/{}", m_black_fades, *m_config.end_after_black_fades); +} + SceneScreen SceneTimeline::classify(const ScreenObservation& look) const{ if (m_config.stop_at_battle && look.events.has(ScreenEvent::BATTLE_STARTED)){ return SceneScreen::BATTLE; @@ -384,7 +403,10 @@ constexpr std::ptrdiff_t TURN_PERIODS[] = {2, 3}; // that change nothing, are counted and summed up every SUMMARY_EVERY, // and before the next line and at the end when they took turns or // pressed ("[PLZA label] scene_moving x46, blind_press x15 over 30.0s, 15 -// presses"): a wait on one state shows in the next line's time. +// presses"): a wait on one state shows in the next line's time. All of +// it goes to the file log; only the lines of scene_screen_for_watcher()'s +// states go on the overlay too (01.01's arrival put 12 lines of text and +// cutscenes there in 25 s, console B 2026-11-15). class SceneLog{ public: SceneLog(PlzaBackend& backend, std::string_view label, WallClock start) @@ -403,10 +425,15 @@ class SceneLog{ if (gets_line(std::format("{}: {}", scene_screen_name(screen), readings))){ flush(); const double seconds = std::chrono::duration(when - m_start).count(); - m_backend.log(std::format( + const std::string line = std::format( "[PLZA {}] screen {}: {} at {}s: {}", m_label, m_screen_number, scene_screen_name(screen), tostr_fixed(seconds, 1), readings - )); + ); + if (scene_screen_for_watcher(screen)){ + m_backend.log(line); + }else{ + m_backend.log_detail(line); + } return; } count(screen, when, pressed); @@ -433,7 +460,7 @@ class SceneLog{ text += std::format("{}{} x{}", text.empty() ? "" : ", ", scene_screen_name(screen), looks); } const double seconds = std::chrono::duration(m_counted_to - *m_counted_from).count(); - m_backend.log(std::format("[PLZA {}] {} over {}s, {} presses", m_label, text, tostr_fixed(seconds, 1), m_presses)); + m_backend.log_detail(std::format("[PLZA {}] {} over {}s, {} presses", m_label, text, tostr_fixed(seconds, 1), m_presses)); m_counted.clear(); m_counted_from.reset(); m_presses = 0; @@ -520,7 +547,11 @@ class SceneRunner{ // The step of `screen`, the state of `look`. void act(SceneScreen screen, const ScreenObservation& look){ m_timeline.record(look); - m_log.look(screen, describe_look(look), look.when, scene_screen_presses(screen)); + std::string readings = describe_look(look); + if (screen == SceneScreen::FADE_BLACK){ + readings = std::format("{}, {}", readings, m_timeline.black_fade_count()); + } + m_log.look(screen, readings, look.when, scene_screen_presses(screen)); if (scene_screen_terminal(screen)){ return; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 5fe2efc761..94e658c361 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -90,7 +90,9 @@ struct SceneMachineConfig{ // `config.stop_at_battle` the battle HUD, or with // `config.end_after_black_fades` its last fade has lifted and settled, on // run_screen_machine(). `label` names its log lines ("[PLZA -// mash_to_move_hints] screen 2: dialog at 1.5s: text box"). Fails as "scene_quiet" on the +// mash_to_move_hints] screen 2: dialog at 1.5s: text box"), which go to +// the file log (log_detail()) except the black fades, the banner, the +// hint and the end, which go on the overlay too (log()). Fails as "scene_quiet" on the // quiet end (unless `config.quiet_is_control`), "scene_never_started" // past `config.start_window`, "scene_timeout" when `timeout` passes (by // the looks' time), and "scene_stuck" on a state that comes up too often diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index 69f6eae72a..e3f55d8690 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -10,6 +10,7 @@ #include #include +#include #include #include #include @@ -137,6 +138,30 @@ SceneMachineConfig quiet_config(Milliseconds min_length){ return config; } +// 01.01's arrival config: mash_to_move_hints' with end_after_black_fades 3. +SceneMachineConfig three_fades_config(){ + SceneMachineConfig config = arrival_config(); + config.end_after_black_fades = 3; + return config; +} + +// 01.01's arrival in short: text, a black fade, text, a white fade, text, +// a second black fade, the banner, a third black fade, then 5 s of +// nothing. Each fade's wait ends on the look after it. +std::vector> arrival_with_three_fades(){ + return { + look_at(0ms, DIALOG), look_at(500ms), + look_at(1000ms, BLACK), look_at(1500ms), + look_at(2000ms, DIALOG), look_at(2500ms, DIALOG), + look_at(3000ms, WHITE), look_at(3500ms), + look_at(4000ms, DIALOG), + look_at(4500ms, BLACK), look_at(5000ms), + look_at(/*at=*/5500ms, NOTHING, {MISSION_BANNER_READING}), look_at(/*at=*/6000ms, NOTHING, {MISSION_BANNER_READING}), + look_at(6500ms, BLACK), look_at(7000ms), + look_at(7500ms), look_at(12500ms), + }; +} + struct RunCase{ std::string name; @@ -158,6 +183,9 @@ struct RunCase{ // The states the log's lines went through, joined by ", "; empty: // not checked. std::string states = {}; + // The lines the stream's overlay shows (log(), not + // log_detail()), in order, if checked. + std::optional> overlay = std::nullopt; }; Expectation expectation; }; @@ -551,6 +579,26 @@ const RunCase RUN_CASES[] = { .states = "dialog, blind_press, scene_moving, blind_press, hint_showing, controls_hint", }, }, + { + // 01.01's arrival (console B, 2026-11-15): the overlay showed + // every text box, cutscene and white fade. + .name = "the overlay shows the black fades, the banner and the end; the file log every screen", + .input = {.looks = arrival_with_three_fades(), .config = three_fades_config()}, + .expectation = { + .verdict = "done", + .a_presses = 4, + .states = "dialog, scene_moving, fade_black, dialog, fade_white, dialog, fade_black, banner_showing, " + "fade_black, scene_moving, fade_settled", + .overlay = std::vector{ + "[PLZA test] screen 3: fade_black at 1.0s: black fade, fade 1/3", + "[PLZA test] screen 7: fade_black at 4.5s: black fade, fade 2/3", + "[PLZA test] screen 8: banner_showing at 5.5s: mission banner", + "[PLZA test] screen 9: fade_black at 6.5s: black fade, fade 3/3", + "[PLZA test] the mission banner showed.", + "[PLZA test] done on fade_settled.", + }, + }, + }, { .name = "the trace logs each new state", .input = {.looks = { @@ -604,6 +652,11 @@ UnitTestResult check_run(const RunCase& test, CancellableScope& scope){ if (!test.expectation.states.empty() && traced_states(backend.lines()) != test.expectation.states){ return std::format("expected the states \"{}\", got \"{}\"", test.expectation.states, traced_states(backend.lines())); } + if (test.expectation.overlay && backend.overlay_lines() != *test.expectation.overlay){ + return std::format( + "expected the overlay lines:\n{}\ngot:\n{}", joined(*test.expectation.overlay, "\n"), joined(backend.overlay_lines(), "\n") + ); + } if (test.expectation.line.empty()){ return true; } From 1a3ba10cf2f29a997928331c2031e6ca13c608ec Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:06:41 -0800 Subject: [PATCH 05/14] PLZA scene machine: A on a banner that stays, with end_after_black_fades 01.01's arrival on the Italian game waited 110 s on "MISSIONE PRINCIPALE 01" with no press; one A cleared it and the third black fade followed (console B, 2026-11-15). With end_after_black_fades, a banner up 2 s now gets A (banner_press), up to 3 times 1 s apart, and BANNER_SHOWING may come up 120 times before the run fails as scene_stuck: its frames change too much for max_still to end the wait. --- .../PokemonLZA_AutoStorySceneMachine.cpp | 55 +++++++++++++++-- .../PokemonLZA_AutoStorySceneMachine.h | 4 +- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 60 +++++++++++++++++++ 3 files changed, 112 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index f9dc6b1ba5..3e08509c9d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -38,6 +38,7 @@ enum class SceneScreen{ MISSION_COMPLETE, // A: a main mission's "COMPLETE" card MISSION_BANNER, // terminal: a main mission's banner, on a second look BANNER_SHOWING, // wait: the banner, on its first look (every look, with end_after_black_fades) + BANNER_PRESS, // A: with end_after_black_fades, the banner up BANNER_PRESS_AFTER (BANNER_PRESSES times, BANNER_PRESS_EVERY apart) FADE_SETTLED, // terminal: end_after_black_fades' last fade lifted, nothing busy since for FADE_SETTLE CAN_MOVE, // terminal: the party bar, held a second PARTY_BAR, // wait: the party bar, not held a second yet @@ -84,6 +85,9 @@ class SceneTimeline{ private: // classify() past the fades and the text. SceneScreen classify_open(const ScreenObservation& look) const; + // Whether, with end_after_black_fades, the banner showing has an A + // press due at `now`. + bool banner_press_due(WallClock now) const; SceneMachineConfig m_config; WallClock m_quiet_from; @@ -99,6 +103,10 @@ class SceneTimeline{ bool m_scene_seen = false; // The looks in a row with the mission banner. size_t m_banner_looks = 0; + // Since when the banner shows, and the A presses on it since. + std::optional m_banner_since; + size_t m_banner_presses = 0; + std::optional m_last_banner_press; // The black fades the machine has waited out. size_t m_black_fades = 0; // Since when nothing busy and no banner has shown, once @@ -135,6 +143,11 @@ constexpr Milliseconds BANNER_GONE_WAIT = 10000ms; // (console B, 2026-11-10). constexpr size_t BANNER_PRESSES = 3; constexpr Milliseconds BANNER_PRESS_EVERY = 1000ms; +// With end_after_black_fades, the banner up this long gets A (the same +// BANNER_PRESSES, BANNER_PRESS_EVERY apart): the Italian "MISSIONE +// PRINCIPALE 01" stayed 110 s with no press; one A cleared it and the +// third black fade came ~4 s later (console B, 2026-11-15). +constexpr Milliseconds BANNER_PRESS_AFTER = 2000ms; // Text to press on: a box, or the advance chevron without one. bool text_shows(const ScreenObservation& look){ @@ -165,7 +178,7 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::BATTLE, SceneScreen::FADE_BLACK, SceneScreen::FADE_WHITE, SceneScreen::CHOICE, SceneScreen::DIALOG, SceneScreen::MISSION_COMPLETE, - SceneScreen::MISSION_BANNER, SceneScreen::BANNER_SHOWING, SceneScreen::FADE_SETTLED, + SceneScreen::MISSION_BANNER, SceneScreen::BANNER_SHOWING, SceneScreen::BANNER_PRESS, SceneScreen::FADE_SETTLED, SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, @@ -201,6 +214,8 @@ std::string_view scene_screen_name(SceneScreen screen){ return "mission_banner"; case SceneScreen::BANNER_SHOWING: return "banner_showing"; + case SceneScreen::BANNER_PRESS: + return "banner_press"; case SceneScreen::FADE_SETTLED: return "fade_settled"; case SceneScreen::CAN_MOVE: @@ -235,7 +250,8 @@ bool scene_screen_terminal(SceneScreen screen){ // Whether this state's step presses (DIALOG the config's text button, // BLIND_PRESS its blind button, MISSION_COMPLETE A); the others wait. bool scene_screen_presses(SceneScreen screen){ - return screen == SceneScreen::DIALOG || screen == SceneScreen::MISSION_COMPLETE || screen == SceneScreen::BLIND_PRESS; + return screen == SceneScreen::DIALOG || screen == SceneScreen::MISSION_COMPLETE || screen == SceneScreen::BLIND_PRESS || + screen == SceneScreen::BANNER_PRESS; } // Whether this state's lines go on the stream's overlay too, for whoever @@ -243,7 +259,8 @@ bool scene_screen_presses(SceneScreen screen){ // controls hint showing. The text, cutscenes, white fades, presses and // ends go to the file log only; the step's own lines say how it ended. bool scene_screen_for_watcher(SceneScreen screen){ - return screen == SceneScreen::FADE_BLACK || screen == SceneScreen::BANNER_SHOWING || screen == SceneScreen::HINT_SHOWING; + return screen == SceneScreen::FADE_BLACK || screen == SceneScreen::BANNER_SHOWING || screen == SceneScreen::BANNER_PRESS || + screen == SceneScreen::HINT_SHOWING; } @@ -273,6 +290,13 @@ bool SceneTimeline::fades_settled(WallClock now) const{ return m_settled_since && now - *m_settled_since >= FADE_SETTLE; } +bool SceneTimeline::banner_press_due(WallClock now) const{ + if (!m_config.end_after_black_fades || !m_banner_since || now - *m_banner_since < BANNER_PRESS_AFTER){ + return false; + } + return m_banner_presses < BANNER_PRESSES && (!m_last_banner_press || now - *m_last_banner_press >= BANNER_PRESS_EVERY); +} + std::string SceneTimeline::black_fade_count() const{ if (!m_config.end_after_black_fades){ return std::format("fade {}", m_black_fades); @@ -304,8 +328,10 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ return SceneScreen::MISSION_COMPLETE; } if (look.readings.contains(MISSION_BANNER_READING)){ - const bool banner_ends = !m_config.end_after_black_fades && m_banner_looks >= 1; - return banner_ends ? SceneScreen::MISSION_BANNER : SceneScreen::BANNER_SHOWING; + if (!m_config.end_after_black_fades && m_banner_looks >= 1){ + return SceneScreen::MISSION_BANNER; + } + return banner_press_due(look.when) ? SceneScreen::BANNER_PRESS : SceneScreen::BANNER_SHOWING; } if (fades_settled(look.when)){ return SceneScreen::FADE_SETTLED; @@ -336,9 +362,14 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ } void SceneTimeline::record(const ScreenObservation& look){ - if (classify(look) == SceneScreen::BLIND_PRESS){ + const SceneScreen screen = classify(look); + if (screen == SceneScreen::BLIND_PRESS){ m_last_blind_press = look.when; } + if (screen == SceneScreen::BANNER_PRESS){ + m_banner_presses++; + m_last_banner_press = look.when; + } if (busy(look)){ m_last_busy = look.when; } @@ -349,6 +380,11 @@ void SceneTimeline::record(const ScreenObservation& look){ track_since(look.readings.contains(CONTROLS_HINT_READING) && !box, look.when, m_hint_since); m_banner_looks = look.readings.contains(MISSION_BANNER_READING) && !box ? m_banner_looks + 1 : 0; m_banner_seen = m_banner_seen || m_banner_looks > 0; + track_since(m_banner_looks > 0, look.when, m_banner_since); + if (!m_banner_since){ + m_banner_presses = 0; + m_last_banner_press.reset(); + } // Each FADE_BLACK look is a new fade: its state waits until it lifts. m_black_fades += look.events.has(ScreenEvent::FADE_BLACK) ? 1 : 0; const bool fades_done = m_config.end_after_black_fades && m_black_fades >= *m_config.end_after_black_fades; @@ -627,6 +663,12 @@ size_t max_visits(SceneScreen screen){ return 400; case SceneScreen::MISSION_COMPLETE: return 30; + case SceneScreen::BANNER_SHOWING: + // ~30 s of looks on the console: with end_after_black_fades a + // banner its A presses do not clear waits on every look, and its + // frames change too much for max_still (console B, 2026-11-15: + // banner_showing x117 over 30.1 s, again and again). + return 120; default: return SIZE_MAX; } @@ -642,6 +684,7 @@ Milliseconds max_still(SceneScreen screen){ return FADE_WAIT; case SceneScreen::SCENE_STILL: case SceneScreen::BLIND_PRESS: + case SceneScreen::BANNER_PRESS: // A blind A press need not change the screen. return SCENE_STILL_WAIT; case SceneScreen::PARTY_BAR: diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 94e658c361..1ff905136e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -75,7 +75,9 @@ struct SceneMachineConfig{ // Ends once this many black fades have been waited out and the screen // has then shown no text, fade or banner for 5 s (or on the controls // hint, if it comes first), and takes the mission banner for part of - // the scene, not its end; whether it showed is logged. 01.01's arrival + // the scene, not its end; whether it showed is logged. A banner up 2 s + // gets A, up to 3 times 1 s apart (the Italian one stays until A, + // console B 2026-11-15), and one that stays fails. 01.01's arrival // ends on its third black fade after the ad, which follows the banner // (console B, 2026-11-15, English and Italian; the banner detector // missed it on the Italian game). Text after the last fade starts the diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index e3f55d8690..03010c8bde 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -162,6 +162,48 @@ std::vector> arrival_with_three_fades(){ }; } +// 01.01's arrival up to its second black fade: text, a black fade, text, +// a second black fade. +std::vector> arrival_to_second_fade(){ + return { + look_at(0ms, DIALOG), + look_at(1000ms, BLACK), look_at(1500ms), + look_at(2000ms, DIALOG), + look_at(4500ms, BLACK), look_at(5000ms), + }; +} + +// `count` looks with the mission banner, `every` apart from `from`. +std::vector> banner_looks(Milliseconds from, Milliseconds every, size_t count){ + std::vector> looks; + for (size_t look = 0; look < count; look++){ + looks.push_back(look_at(/*at=*/from + every * (int64_t)look, NOTHING, {MISSION_BANNER_READING})); + } + return looks; +} + +// 01.01's arrival on the Italian game (console B, 2026-11-15): the banner +// stays until A, then the third black fade, then 5 s of nothing. +std::vector> arrival_banner_until_a(){ + std::vector> looks = arrival_to_second_fade(); + for (const Observation& look : banner_looks(/*from=*/5500ms, /*every=*/500ms, /*count=*/5)){ + looks.push_back(look); + } + for (const Observation& look : {look_at(8000ms), look_at(8500ms, BLACK), look_at(9000ms), look_at(9500ms), look_at(14500ms)}){ + looks.push_back(look); + } + return looks; +} + +// 01.01's arrival with a banner that A does not clear. +std::vector> arrival_banner_stays(){ + std::vector> looks = arrival_to_second_fade(); + for (const Observation& look : banner_looks(/*from=*/5500ms, /*every=*/500ms, /*count=*/20)){ + looks.push_back(look); + } + return looks; +} + struct RunCase{ std::string name; @@ -599,6 +641,24 @@ const RunCase RUN_CASES[] = { }, }, }, + { + // The Italian banner waited 110 s with no press (console B, + // 2026-11-15); one A cleared it. + .name = "with end_after_black_fades, a banner up 2 s gets A, and the run goes on to the third fade", + .input = {.looks = arrival_banner_until_a(), .config = three_fades_config()}, + .expectation = { + .verdict = "done", + .a_presses = 3, + .line = "[PLZA test] done on fade_settled.", + .states = "dialog, fade_black, dialog, fade_black, banner_showing, banner_press, scene_moving, fade_black, " + "scene_moving, fade_settled", + }, + }, + { + .name = "with end_after_black_fades, a banner that 3 A presses 1 s apart do not clear fails as scene_stuck", + .input = {.looks = arrival_banner_stays(), .config = three_fades_config()}, + .expectation = {.verdict = "failed: scene_stuck", .a_presses = 5}, + }, { .name = "the trace logs each new state", .input = {.looks = { From e66fd6e1af6676c1c4fe36e8de5cbc61e4451753 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:24:03 -0800 Subject: [PATCH 06/14] PLZA autosave reader: cyan tests take only blue-leaning pixels A building banner's mint (about 96, 203, 147) in the strips above and below the icon counted as cyan and hid the English badge on 01.01 (en_t166). Both cyan tests now need blue at least green less 20, which also keeps a green sign's glowing text from matching the icon. Over 6096 console captures and 1173 PokemonLZA test frames: en_t166 found, 3 green-sign false matches dropped, nothing else changed. --- .../PokemonLZA_AutoStoryAutosaveDetector.cpp | 5 +++++ .../PokemonLZA_AutoStoryDetectors_Tests.cpp | 21 +++++++++++++++++++ .../PokemonLZA_AutoStoryPixelShares.cpp | 6 ++++-- .../PokemonLZA_AutoStoryPixelShares.h | 7 +++++-- 4 files changed, 35 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp index 354417e7af..01b16a77c5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp @@ -71,6 +71,11 @@ void AutosaveDetector::make_overlays(VideoOverlaySet& items) const{ // run in Japanese, icon at dx 36), so the icon's glow is dim_cyan_share(): // of the 3569 PLZA captures on the console it finds 11 more // badges, every one a real badge, and no new false one. +// Both cyan tests take only blue-leaning pixels: a building banner's mint +// (about 96, 203, 147) in the strips hid the badge on 01.01 in English, +// and a green sign's white text with its glow matched the icon. Of 6096 +// console captures and 1173 PokemonLZA test frames this finds the English +// badge, drops 3 green-sign matches, and changes nothing else. bool AutosaveDetector::detect(const ImageViewRGB32& screen){ for (double dx = 0; dx <= 240; dx += 4){ if (autosave_icon_at(screen, m_icon, {m_left, m_above, m_below}, dx)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp index a18be18f73..c761cb6921 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp @@ -182,6 +182,16 @@ ImageRGB32 autosave_badge_frame(uint32_t background, uint32_t glow){ return image; } +// autosave_badge_frame() with a bright glow over a dark scene, and bands +// of a building banner's mint green (about 96, 203, 147) 4 px high across +// the strips above and below the icon, as on 01.01 in English. +ImageRGB32 autosave_badge_by_mint_banner_frame(){ + ImageRGB32 image = autosave_badge_frame(/*background=*/0xff101418, /*glow=*/0xff28c8e6); + fill_box(/*min_x=*/1600, /*min_y=*/60, /*max_x=*/1720, /*max_y=*/64, /*color=*/0xff60cb93, image); + fill_box(/*min_x=*/1600, /*min_y=*/112, /*max_x=*/1720, /*max_y=*/116, /*color=*/0xff60cb93, image); + return image; +} + // How mission_banner_frame() draws the icon. enum class BannerIcon{ NONE, @@ -308,6 +318,17 @@ const SyntheticFrameCase SYNTHETIC_FRAME_CASES[] = { .input = {.frame = []{ return autosave_badge_frame(0xff252722, 0xff252722); }}, .expectation = {.reads = {.autosave = false}}, }, + // Mint and sign green have green over blue; the badge's glow does not. + { + .name = "the autosave badge with mint banner bands above and below", + .input = {.frame = autosave_badge_by_mint_banner_frame}, + .expectation = {.reads = {.autosave = true}}, + }, + { + .name = "a white stroke with a green sign's glow", + .input = {.frame = []{ return autosave_badge_frame(0xff252722, 0xff3cf06e); }}, + .expectation = {.reads = {.autosave = false}}, + }, { .name = "the controls hint card", .input = {.frame = controls_hint_frame}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp index 862a5d5fe6..28b439265d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp @@ -13,13 +13,15 @@ namespace PokemonLZA{ double cyan_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ return share_of(screen, box, [](Color pixel){ - return pixel.blue() > pixel.red() + 50 && pixel.green() > pixel.red() + 30 && pixel.blue() > 120; + return pixel.blue() > pixel.red() + 50 && pixel.green() > pixel.red() + 30 && pixel.blue() > 120 && + pixel.blue() + 20 >= pixel.green(); }); } double dim_cyan_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ return share_of(screen, box, [](Color pixel){ - return pixel.blue() > pixel.red() + 40 && pixel.green() > pixel.red() + 25 && pixel.blue() > 70; + return pixel.blue() > pixel.red() + 40 && pixel.green() > pixel.red() + 25 && pixel.blue() > 70 && + pixel.blue() + 20 >= pixel.green(); }); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h index 534298e9e0..6dfbfc07b6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h @@ -24,11 +24,14 @@ template double share_of(const ImageViewRGB32& screen, const ImageFloatBox& box, Matches&& matches); // The share of `box`'s pixels that glow cyan: blue over red by 50, green -// over red by 30, blue over 120. +// over red by 30, blue over 120, and blue at least green less 20. The last +// keeps out mint and sign green (about 96, 203, 147 on a building banner), +// which have green far over blue. double cyan_share(const ImageViewRGB32& screen, const ImageFloatBox& box); // The share of `box`'s pixels that glow cyan, dim too: blue over red by -// 40, green over red by 25, blue over 70. The autosave badge's glow over a +// 40, green over red by 25, blue over 70, blue at least green less 20. +// The autosave badge's glow over a // dark or warm scene (a lamp-lit wall: about 28, 70, 85) is too dim for // cyan_share(). double dim_cyan_share(const ImageViewRGB32& screen, const ImageFloatBox& box); From c9f475e5a1793d72b345d1f46d18ae642f76244c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:36:33 -0800 Subject: [PATCH 07/14] PLZA choice rows: find rows by the menu's geometry, not its text The panel grows left to fit its longest row. In Italian (01.02, Villy) the bottom row's text ran into the right strip the reader sampled, so the row read as "other" and no rows were found. The right strip now sits past any row's text (x 1698-1712), the highlight's left end is found by scanning, and a plain row is told from a blue wall by bright text anywhere between the highlight's left end and the text's right limit. --- .../PokemonLZA_AutoStoryDialogChoiceBox.cpp | 130 +++++++++++++----- .../PokemonLZA_AutoStoryDialogChoiceBox.h | 16 ++- ...emonLZA_AutoStoryDialogChoiceBox_Tests.cpp | 52 +++++-- 3 files changed, 148 insertions(+), 50 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp index e78fe66d4d..e87cd715f5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp @@ -4,6 +4,8 @@ * */ +#include +#include #include "CommonFramework/ImageTools/ImageStats.h" #include "PokemonLZA_AutoStoryDialogChoiceBox.h" @@ -20,37 +22,58 @@ constexpr size_t MAX_CHOICE_ROWS = 6; // pavement reads as a highlighted row (ArrivalToAd 0038). constexpr size_t MIN_CHOICE_ROWS = 2; -// The row pitch and the bottom row's strips at 1920 x 1080. Measured on -// the console on the tourist's two rows (Traditional Chinese) -// and the Research Lab elevator's three (Japanese): the panel x 1408 to -// 1728 ends at y 808 in both, its highlight x 1418 to 1715, the bottom -// row's from y 732 to 800, each row above 80 higher. The text starts at -// x 1443 on every row. +// The menu's geometry at 1920 x 1080. Measured on the console on the +// tourist's two rows (Traditional Chinese), the Research Lab elevator's +// three (Japanese) and Villy's two at 01.02 (Italian). The panel is +// anchored at its bottom right: it ends at x 1728, y 808 whatever its +// rows, and grows left to fit its longest row (x 1408 in Japanese, 1343 +// in Italian). The highlight runs from 10 right of the panel's left to +// x 1715; the bottom row's from y 732 to 800, each row above 80 higher. +// The rows' text starts 35 right of the panel's left and ends at x 1690 +// at most (Italian's longest row: 1688). constexpr double ROW_PITCH = 80.0 / 1080; constexpr double STRIP_TOP = 748.0 / 1080; constexpr double STRIP_HEIGHT = 40.0 / 1080; - -// Right of the row's text, inside the highlight. +constexpr double TEXT_END_X = 1690.0 / 1920; +// Where the leftward scan for the highlight's left end starts, and the +// bottom row's highlight 4 below its top and 4 above its bottom: few +// glyphs reach both. +constexpr double HIGHLIGHT_SCAN_X = 1700.0 / 1920; +constexpr double HIGHLIGHT_TOP_BAND_Y = 736.0 / 1080; +constexpr double HIGHLIGHT_BOTTOM_BAND_Y = 796.0 / 1080; +// A plain row's share of bright text pixels: 0.07 to 0.2 on the console, +// 0 on the elevator's wall above its top row. +constexpr double MIN_TEXT_SHARE = 0.005; + +// Right of any row's text, inside the highlight. ImageFloatBox right_strip(size_t from_bottom){ - return ImageFloatBox(1650.0 / 1920, STRIP_TOP - ROW_PITCH * from_bottom, 55.0 / 1920, STRIP_HEIGHT); + return ImageFloatBox(1698.0 / 1920, STRIP_TOP - ROW_PITCH * from_bottom, 14.0 / 1920, STRIP_HEIGHT); +} + +// Where a row's text can be, from 10 right of the highlight's left end +// (`highlight_left`, a share of the width) to the text's right limit. +ImageFloatBox text_band(size_t from_bottom, double highlight_left){ + const double left = highlight_left + 10.0 / 1920; + return ImageFloatBox(left, STRIP_TOP - ROW_PITCH * from_bottom, TEXT_END_X - left, STRIP_HEIGHT); } -// Where every row's text starts. -ImageFloatBox text_strip(size_t from_bottom){ - return ImageFloatBox(1445.0 / 1920, STRIP_TOP - ROW_PITCH * from_bottom, 80.0 / 1920, STRIP_HEIGHT); +bool bright(uint32_t pixel, uint32_t min_channel){ + const uint32_t red = (pixel >> 16) & 0xff; + const uint32_t green = (pixel >> 8) & 0xff; + const uint32_t blue = pixel & 0xff; + return red >= min_channel && green >= min_channel && blue >= min_channel; } enum class ChoiceSlot{ HIGHLIGHTED, - PLAIN, + PANEL, OTHER, }; // A slot's right strip: the highlighted row 255 white, flat; a plain row -// the panel's dark blue, (35-45, 60-73, 108-120), spread 4-5. Its text -// strip: spread 220-240 on every row. Above the elevator's top row, the -// wall is as dark and blue, (23-24, 58-60, 102-104), but its text strip -// is flat (spread 5); above the tourist's, pavement, spread 34-36. +// the panel's dark blue, (35-45, 60-73, 108-120), spread 3-7. The wall +// above the elevator's top row is as dark and blue, (23-24, 58-62, +// 102-107); `row_has_text` tells it from a row. ChoiceSlot classify_slot(const ImageViewRGB32& frame, size_t from_bottom){ const ImageStats right = image_stats(extract_box_reference(frame, right_strip(from_bottom))); if (right.count == 0 || right.stddev.sum() > 30){ @@ -64,14 +87,40 @@ ChoiceSlot classify_slot(const ImageViewRGB32& frame, size_t from_bottom){ average.r <= 70 && average.g <= 100 && average.b >= 80 && average.b <= 150 && average.b >= average.r + 40; - if (!dark_blue){ - return ChoiceSlot::OTHER; + return dark_blue ? ChoiceSlot::PANEL : ChoiceSlot::OTHER; +} + +// The highlight's left end on the row `from_bottom` slots up, as a share +// of the width: scanned left from inside its right end while its top or +// bottom band is white. +double highlight_left(const ImageViewRGB32& frame, size_t from_bottom){ + const double pitch = ROW_PITCH * from_bottom; + const size_t top_y = (size_t)((HIGHLIGHT_TOP_BAND_Y - pitch) * frame.height()); + const size_t bottom_y = (size_t)((HIGHLIGHT_BOTTOM_BAND_Y - pitch) * frame.height()); + size_t x = (size_t)(HIGHLIGHT_SCAN_X * frame.width()); + while (x > 0 && (bright(frame.pixel(x - 1, top_y), 200) || bright(frame.pixel(x - 1, bottom_y), 200))){ + x--; } - const ImageStats text = image_stats(extract_box_reference(frame, text_strip(from_bottom))); - if (text.count == 0 || text.stddev.sum() < 100){ - return ChoiceSlot::OTHER; + return (double)x / frame.width(); +} + +// Whether a plain row's text band has text: white glyphs on the panel, +// whatever the language or the row's length. +bool row_has_text(const ImageViewRGB32& frame, size_t from_bottom, double highlight_left){ + const ImageViewRGB32 band = extract_box_reference(frame, text_band(from_bottom, highlight_left)); + const size_t area = band.width() * band.height(); + if (area == 0){ + return false; + } + size_t bright_pixels = 0; + for (size_t y = 0; y < band.height(); y++){ + for (size_t x = 0; x < band.width(); x++){ + if (bright(band.pixel(x, y), 180)){ + bright_pixels++; + } + } } - return ChoiceSlot::PLAIN; + return (double)bright_pixels / area >= MIN_TEXT_SHARE; } } // namespace @@ -86,24 +135,37 @@ std::optional read_dialog_choice_rows(const ImageViewRGB32& fr if (!frame || frame.width() < 192 || frame.height() < 108){ return std::nullopt; } - size_t count = 0; - std::optional highlighted_from_bottom; - for (; count < MAX_CHOICE_ROWS; count++){ - const ChoiceSlot slot = classify_slot(frame, count); + // The menu's slots from the bottom up, highlighted or panel blue. + std::vector slots; + std::optional first_highlighted; + while (slots.size() < MAX_CHOICE_ROWS){ + const ChoiceSlot slot = classify_slot(frame, slots.size()); if (slot == ChoiceSlot::OTHER){ break; } - if (slot == ChoiceSlot::HIGHLIGHTED){ - if (highlighted_from_bottom){ - return std::nullopt; - } - highlighted_from_bottom = count; + if (slot == ChoiceSlot::HIGHLIGHTED && !first_highlighted){ + first_highlighted = slots.size(); + } + slots.push_back(slot); + } + if (!first_highlighted){ + return std::nullopt; + } + // The rows end at the first blue slot with no text. + const double left = highlight_left(frame, *first_highlighted); + size_t count = 0; + size_t highlighted = 0; + for (; count < slots.size(); count++){ + if (slots[count] == ChoiceSlot::HIGHLIGHTED){ + highlighted++; + }else if (!row_has_text(frame, count, left)){ + break; } } - if (!highlighted_from_bottom || count < MIN_CHOICE_ROWS){ + if (highlighted != 1 || count < MIN_CHOICE_ROWS){ return std::nullopt; } - return DialogChoiceRows{.count = count, .selected = count - 1 - *highlighted_from_bottom}; + return DialogChoiceRows{.count = count, .selected = count - 1 - *first_highlighted}; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h index 84d441d1d2..2ba49c8066 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h @@ -33,13 +33,15 @@ struct DialogChoiceRows{ size_t selected = 0; }; -// Reads the choice menu on `frame`. The menu's panel is bottom-anchored: -// its last row sits at the same place whatever the row count, and each -// further row adds one row pitch on top. So the rows are counted from the -// bottom up, each either highlighted (white) or plain (dark blue, its -// text's start bright on it), until a slot is neither; the selected row is -// then counted from the top. None for fewer than two rows, or if no row, -// or not exactly one, is highlighted. +// Reads the choice menu on `frame`. The menu's panel is anchored at its +// bottom right: its last row sits at the same place whatever the row +// count, each further row adds one row pitch on top, and the panel grows +// left to fit its longest row, which differs by language. So the rows are +// counted from the bottom up, each either highlighted (white right of any +// text) or plain (dark blue there, with bright text somewhere between the +// highlight's left end and the text's right limit), until a slot is +// neither; the selected row is then counted from the top. None for fewer +// than two rows, or if no row, or not exactly one, is highlighted. std::optional read_dialog_choice_rows(const ImageViewRGB32& frame); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.cpp index 4a4c7062fc..5e5e3db237 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.cpp @@ -47,16 +47,35 @@ void fill_box(size_t min_x, size_t min_y, size_t max_x, size_t max_y, uint32_t c } } +// How wide a choice menu's panel is and how far its rows' text runs: the +// panel grows to the left to fit its longest row. +struct MenuWidth{ + size_t panel_left = 1408; + size_t text_end = 1540; +}; + +// The menus whose rows read on the console in Japanese and Chinese. +constexpr MenuWidth NARROW_MENU{}; +// The Italian 01.02 menu's panel (x 1343), with every row's text running +// to x 1688, near the highlight's right end. +constexpr MenuWidth WIDE_MENU_LONG_ROWS{.panel_left = 1343, .text_end = 1688}; +// The same panel with rows as short as "Si": no text past x 1400. +constexpr MenuWidth WIDE_MENU_SHORT_ROWS{.panel_left = 1343, .text_end = 1400}; + // A choice menu of `rows` rows drawn as the console shows it (1920 x 1080) -// on `background`: the panel x 1408 to 1728, from y 808 up, one 80 pitch -// per row; row k from the bottom highlighted white at y 732 - 80k to -// 800 - 80k, x 1418 to 1715. Each row's text starts at x 1443, in strokes -// one column in three: dark on the highlighted rows (`highlighted`), -// white on the others. -ImageRGB32 choice_menu_frame(uint32_t background, size_t rows, std::initializer_list highlighted){ +// on `background`: the panel from x `width.panel_left` to 1728, from +// y 808 up, one 80 pitch per row; row k from the bottom highlighted white +// at y 732 - 80k to 800 - 80k, from 10 right of the panel's left to +// x 1715. Each row's text runs from 35 right of the panel's left to +// `width.text_end`, in strokes one column in three: dark on the +// highlighted rows (`highlighted`), white on the others. +ImageRGB32 choice_menu_frame( + uint32_t background, size_t rows, std::initializer_list highlighted, + MenuWidth width = NARROW_MENU +){ ImageRGB32 image(1920, 1080); image.fill(background); - fill_box(/*min_x=*/1408, 808 - 80 * rows - 4, /*max_x=*/1728, /*max_y=*/808, PANEL, image); + fill_box(width.panel_left, 808 - 80 * rows - 4, /*max_x=*/1728, /*max_y=*/808, PANEL, image); for (size_t row = 0; row < rows; row++){ const size_t from_bottom = rows - 1 - row; const size_t top = 732 - 80 * from_bottom; @@ -65,9 +84,9 @@ ImageRGB32 choice_menu_frame(uint32_t background, size_t rows, std::initializer_ lit = lit || pick == row; } if (lit){ - fill_box(/*min_x=*/1418, top, /*max_x=*/1715, top + 68, WHITE, image); + fill_box(width.panel_left + 10, top, /*max_x=*/1715, top + 68, WHITE, image); } - for (size_t x = 1443; x < 1540; x += 3){ + for (size_t x = width.panel_left + 35; x < width.text_end; x += 3){ fill_box(x, top + 16, x + 1, top + 52, lit ? DARK_TEXT : WHITE, image); } } @@ -128,6 +147,16 @@ const SyntheticCase SYNTHETIC_CASES[] = { .input = {.frame = []{ return choice_menu_frame(PAVEMENT, /*rows=*/4, /*highlighted=*/{3}); }}, .expectation = {.rows = DialogChoiceRows{.count = 4, .selected = 3}}, }, + { + .name = "two long rows on a wide panel, the top highlighted", + .input = {.frame = []{ return choice_menu_frame(PAVEMENT, /*rows=*/2, /*highlighted=*/{0}, WIDE_MENU_LONG_ROWS); }}, + .expectation = {.rows = DialogChoiceRows{.count = 2, .selected = 0}}, + }, + { + .name = "three short rows on a wide panel, on a blue wall, the bottom highlighted", + .input = {.frame = []{ return choice_menu_frame(BLUE_WALL, /*rows=*/3, /*highlighted=*/{2}, WIDE_MENU_SHORT_ROWS); }}, + .expectation = {.rows = DialogChoiceRows{.count = 3, .selected = 2}}, + }, { .name = "one highlighted row is no menu", .input = {.frame = []{ return choice_menu_frame(PAVEMENT, /*rows=*/1, /*highlighted=*/{0}); }}, @@ -191,6 +220,11 @@ const FrameCase FRAME_CASES[] = { .input = {.file = "AutoStoryDialogChoices/elevator_3rows_row0.png"}, .expectation = {.rows = DialogChoiceRows{.count = 3, .selected = 0}}, }, + { + .name = "Villy's \"I'll get it back\" or \"battle\" at 01.02 (2 rows, Italian: a wider panel)", + .input = {.file = "AutoStoryDialogChoices/it_0102_villy_2rows_row0.png"}, + .expectation = {.rows = DialogChoiceRows{.count = 2, .selected = 0}, .choice_box = true}, + }, { .name = "light pavement, no menu", .input = {.file = "AutoStoryDetectors/ArrivalToAd/0038-nothing+autosave.jpg"}, From 59dfaa05d467be7eb99db08ad67648908ac35ceb Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:36:39 -0800 Subject: [PATCH 08/14] =?UTF-8?q?CI=20(fork=20only):=20pin=20CommandLineTe?= =?UTF-8?q?sts=208b376ff=20(01.02=20Italian=20choice=20menu)=20=E2=80=94?= =?UTF-8?q?=20drop=20before=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cpp-ci-serial-programs-base.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 289cc28931..f0cf18a859 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -246,9 +246,10 @@ jobs: if: inputs.run-tests with: # The fork's fixtures: upstream's plus the PLZA AutoStory frames (Confirm Choices, opening and arrival folders), dayfine/CommandLineTests PR #18, - # and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language). + # and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language), + # and the 01.02 choice menu in Italian (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '2abde09b6bfdf9ae1b372b04c0e6265dc8559556' + ref: '8b376ffb6a7476af5f9cf4c786fb852ef5e49efc' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded From be34e52dd52e85b395da1e7fd539a75544259dfa Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:06:46 -0800 Subject: [PATCH 09/14] PLZA scene machine: an A prompt on the overworld is control, never blind-pressed 01.02's battle area hands control back with only the "A Talk" prompt to Ryon at the gate: no controls hint, and no party bar (no Pokemon yet). The scene machine took the prompt for nothing, blind-pressed A 5 s later and restarted his talk, for 3 min (console B 2026-11-15, Italian). The prompt-as-control fix of 2026-11-10 (13a6c3ca0) was lost when the scene became a ScreenMachine. In machines that end on control (not stop_at_choice / stop_at_battle, whose talk shows the prompt between lines and whose blind A may start it), the prompt is now a sign of control: no blind A while it shows, and held a second past min_length it ends the step (talk_prompt). 01.02's plan says why. Frame test: the Italian "A Parla" prompt (CommandLineTests plza/new-game-intro 848e0b0). --- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 5 ++- .../PokemonLZA_AutoStorySceneMachine.cpp | 41 ++++++++++++++++--- .../PokemonLZA_AutoStorySceneMachine.h | 10 ++++- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 38 +++++++++++++++++ ...PokemonLZA_AutoStoryScreenEvents_Tests.cpp | 8 ++++ .../AutoStory/StoryData/plza-01.02.plan.json | 2 +- 6 files changed, 95 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 0da8a49478..b34d44a381 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -459,7 +459,10 @@ Outcome walk_step(Pokemon::StoryBackend& backend, const StoryActionCal // "mash_to_move_hints": A through the scenes (a choice takes its top // row, the advance chevron its text) until the player has control: the -// controls hint held a second, or a main mission's banner on two looks +// controls hint or the party bar held a second, an A prompt ("A Talk") +// held a second past "min_length_ms" (01.02's battle area: only the +// prompt to Ryon, and A there restarts his talk), or a main mission's +// banner on two looks // (the step returns once it has gone, 10 s at most). With // "end_after_black_fades", that many black fades lifted and settled end // it, 5 s after the last one (or the controls hint, if it comes first), diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index 3e08509c9d..bb0ad0b2f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -44,6 +44,8 @@ enum class SceneScreen{ PARTY_BAR, // wait: the party bar, not held a second yet CONTROLS_HINT, // terminal: the tutorial's controls hint, held a second HINT_SHOWING, // wait: the controls hint, not held a second yet + TALK_PROMPT, // terminal: an A prompt ("A Talk") on the overworld, held a second, past min_length + PROMPT_SHOWING, // wait, no press: the A prompt, not held a second or before min_length NEVER_STARTED, // terminal, failing: no scene within start_window QUIET_END, // terminal, failing unless quiet_is_control: nothing busy for the quiet time, past the minimum length BLIND_PRESS, // blind_button: nothing busy and no sign of control for blind_press_after @@ -94,11 +96,12 @@ class SceneTimeline{ WallClock m_last_busy; WallClock m_start; // The last look busy or with a sign of control (party bar, hint, - // banner). + // banner, A prompt). WallClock m_last_cue; std::optional m_last_blind_press; std::optional m_party_bar_since; std::optional m_hint_since; + std::optional m_prompt_since; // Text, a choice or a battle has shown: the scene has started. bool m_scene_seen = false; // The looks in a row with the mission banner. @@ -121,6 +124,11 @@ constexpr Milliseconds CONTROLS_HINT_HOLD = 1000ms; // The party bar showing this long is free control: it also shows between // the lines of a scene. constexpr Milliseconds PARTY_BAR_HOLD = 1000ms; +// An A prompt ("A Talk") on the overworld showing this long is free +// control. 01.02's battle area hands control back with only the prompt to +// Ryon, no party bar and no controls hint; A there restarts his talk +// (console B, 2026-11-15, Italian: 3 min of it). +constexpr Milliseconds PROMPT_HOLD = 1000ms; // How long the screen stays free of text, fades and the banner after the // last of end_after_black_fades' fades before the scene counts as over: // the player can move 5 s after 01.01's third fade at the latest. @@ -168,12 +176,18 @@ bool scene_shows(const ScreenObservation& look){ return text_shows(look) || look.events.has(ScreenEvent::CHOICE_BOX) || look.events.has(ScreenEvent::BATTLE_STARTED); } -// Whether the party bar is control for `config`: not in a machine that -// stops at a choice or a battle, whose talk shows it between its lines. +// Whether the party bar and the A prompt are control for `config`: not in +// a machine that stops at a choice or a battle, whose talk shows them +// between its lines (and whose blind A may start that talk). bool party_bar_is_control(const SceneMachineConfig& config){ return !config.stop_at_choice && !config.stop_at_battle; } +// An A prompt that is control for `config` shows on `look`. +bool control_prompt_shows(const SceneMachineConfig& config, const ScreenObservation& look){ + return party_bar_is_control(config) && look.events.has(ScreenEvent::INTERACT_PROMPT); +} + constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::BATTLE, SceneScreen::FADE_BLACK, SceneScreen::FADE_WHITE, SceneScreen::CHOICE, SceneScreen::DIALOG, @@ -181,6 +195,7 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::MISSION_BANNER, SceneScreen::BANNER_SHOWING, SceneScreen::BANNER_PRESS, SceneScreen::FADE_SETTLED, SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, + SceneScreen::TALK_PROMPT, SceneScreen::PROMPT_SHOWING, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, }; @@ -226,6 +241,10 @@ std::string_view scene_screen_name(SceneScreen screen){ return "controls_hint"; case SceneScreen::HINT_SHOWING: return "hint_showing"; + case SceneScreen::TALK_PROMPT: + return "talk_prompt"; + case SceneScreen::PROMPT_SHOWING: + return "prompt_showing"; case SceneScreen::NEVER_STARTED: return "never_started"; case SceneScreen::QUIET_END: @@ -243,7 +262,8 @@ std::string_view scene_screen_name(SceneScreen screen){ // Whether the machine ends after this state's step. bool scene_screen_terminal(SceneScreen screen){ return screen == SceneScreen::BATTLE || screen == SceneScreen::CHOICE || screen == SceneScreen::MISSION_BANNER || - screen == SceneScreen::CAN_MOVE || screen == SceneScreen::CONTROLS_HINT || screen == SceneScreen::FADE_SETTLED || + screen == SceneScreen::CAN_MOVE || screen == SceneScreen::CONTROLS_HINT || screen == SceneScreen::TALK_PROMPT || + screen == SceneScreen::FADE_SETTLED || screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END; } @@ -348,6 +368,12 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ } return SceneScreen::HINT_SHOWING; } + if (control_prompt_shows(m_config, look)){ + if (m_prompt_since && look.when - *m_prompt_since >= PROMPT_HOLD && look.when >= m_quiet_from){ + return SceneScreen::TALK_PROMPT; + } + return SceneScreen::PROMPT_SHOWING; + } if (m_config.start_window && !m_scene_seen && look.when - m_start >= *m_config.start_window){ return SceneScreen::NEVER_STARTED; } @@ -378,6 +404,7 @@ void SceneTimeline::record(const ScreenObservation& look){ const bool party_bar = party_bar_is_control(m_config) && look.events.has(ScreenEvent::PLAYER_CAN_MOVE); track_since(party_bar && !box, look.when, m_party_bar_since); track_since(look.readings.contains(CONTROLS_HINT_READING) && !box, look.when, m_hint_since); + track_since(control_prompt_shows(m_config, look) && !box, look.when, m_prompt_since); m_banner_looks = look.readings.contains(MISSION_BANNER_READING) && !box ? m_banner_looks + 1 : 0; m_banner_seen = m_banner_seen || m_banner_looks > 0; track_since(m_banner_looks > 0, look.when, m_banner_since); @@ -389,7 +416,7 @@ void SceneTimeline::record(const ScreenObservation& look){ m_black_fades += look.events.has(ScreenEvent::FADE_BLACK) ? 1 : 0; const bool fades_done = m_config.end_after_black_fades && m_black_fades >= *m_config.end_after_black_fades; track_since(fades_done && !busy(look) && m_banner_looks == 0, look.when, m_settled_since); - if (busy(look) || m_party_bar_since || m_hint_since || m_banner_looks > 0){ + if (busy(look) || m_party_bar_since || m_hint_since || m_prompt_since || m_banner_looks > 0){ m_last_cue = look.when; } } @@ -628,6 +655,7 @@ class SceneRunner{ return; case SceneScreen::PARTY_BAR: case SceneScreen::HINT_SHOWING: + case SceneScreen::PROMPT_SHOWING: case SceneScreen::BANNER_SHOWING: m_backend.wait(POLL); return; @@ -687,6 +715,9 @@ Milliseconds max_still(SceneScreen screen){ case SceneScreen::BANNER_PRESS: // A blind A press need not change the screen. return SCENE_STILL_WAIT; + case SceneScreen::PROMPT_SHOWING: + // The overworld at the prompt can stay still until min_length. + return SCENE_STILL_WAIT; case SceneScreen::PARTY_BAR: case SceneScreen::HINT_SHOWING: case SceneScreen::BANNER_SHOWING: diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 1ff905136e..aa43bbad0e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -10,7 +10,10 @@ * choice, whose top row A takes) or the advance chevron * (ADVANCE_ARROW_READING) gets A. The player has control when the party * bar (PLAYER_CAN_MOVE) or, in the tutorial, which has no party bar, the - * controls hint (CONTROLS_HINT_READING) holds a second, or when + * controls hint (CONTROLS_HINT_READING) holds a second, or an A prompt + * (INTERACT_PROMPT, "A Talk") holds a second past min_length (01.02's + * battle area shows only the prompt to Ryon; A there restarts his talk, + * so no blind A while it shows), or when * a main mission's banner (MISSION_BANNER_READING) shows on two looks in a * row: it shows as the scene hands over control, and the machine then * waits for it to go, pressing A if it stays (01.03's "MAIN MISSION 02"). @@ -85,7 +88,10 @@ struct SceneMachineConfig{ std::optional end_after_black_fades = std::nullopt; }; -// Presses through scenes until the controls hint has held a second, or +// Presses through scenes until the controls hint or the party bar has +// held a second, or an A prompt has held a second past +// `config.min_length` (neither the party bar nor the prompt with +// `config.stop_at_choice` or `config.stop_at_battle`), or // the mission banner has shown on two looks (then waits up to 10 s for it // to go and, if it stays, presses A up to 3 times 1 s apart), or with // `config.stop_at_choice` the choice box shows, or with diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index 03010c8bde..f5aa64daeb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -62,6 +62,8 @@ const ScreenEvents BLACK{ScreenEvent::FADE_BLACK}; const ScreenEvents CHOICE{ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX}; const ScreenEvents BATTLE{ScreenEvent::BATTLE_STARTED}; const ScreenEvents PARTY{ScreenEvent::PLAYER_CAN_MOVE}; +const ScreenEvents PROMPT{ScreenEvent::INTERACT_PROMPT}; +const ScreenEvents STILL_PROMPT{ScreenEvent::INTERACT_PROMPT, ScreenEvent::SCREEN_STILL}; // mash_to_move_hints' config: a minute quiet, blind A after 5 s. SceneMachineConfig arrival_config(){ @@ -130,6 +132,24 @@ std::vector> minute_of_blind_presses(){ return looks; } +// 01.02's battle_area: mash_to_move_hints' config with min_length_ms 20000. +SceneMachineConfig battle_area_config(){ + SceneMachineConfig config = arrival_config(); + config.min_length = 20000ms; + return config; +} + +// 01.02's battle area on the Italian game (console B, 2026-11-15): the +// text, a cutscene, then the overworld with the "A Parla" (talk) prompt +// to Ryon at the gate, still, and no controls hint. +std::vector> battle_area_talk_prompt(){ + return { + look_at(0ms, DIALOG), look_at(500ms), look_at(6000ms), + look_at(6500ms, PROMPT), look_at(7000ms, PROMPT), look_at(8000ms, STILL_PROMPT), + look_at(15000ms, STILL_PROMPT), look_at(20000ms, STILL_PROMPT), look_at(20500ms, STILL_PROMPT), + }; +} + // A quiet time of 8 s after a scene of at least `min_length`, no blind A. SceneMachineConfig quiet_config(Milliseconds min_length){ SceneMachineConfig config; @@ -579,6 +599,24 @@ const RunCase RUN_CASES[] = { }}, .expectation = {.verdict = "done", .a_presses = 2, .line = "[PLZA test] done on can_move."}, }, + { + // console B, 2026-11-15: blind A at the prompt restarted Ryon's + // talk, again and again for 3 min. + .name = "01.02's battle area: the talk prompt held past the minimum length is control, with no A at it", + .input = {.looks = battle_area_talk_prompt(), .config = battle_area_config()}, + .expectation = { + .verdict = "done", + .a_presses = 2, + .line = "[PLZA test] done on talk_prompt.", + .states = "dialog, scene_moving, blind_press, prompt_showing, talk_prompt", + }, + }, + { + // It shows between the lines of a talk, like the party bar. + .name = "a machine that stops at a battle does not take the talk prompt for control", + .input = {.looks = {look_at(0ms, PROMPT), look_at(2500ms, PROMPT), look_at(3000ms, BATTLE)}, .config = battle_config()}, + .expectation = {.verdict = "done", .a_presses = 2, .states = "blind_press, battle"}, + }, { .name = "Hotel Z's room: the quiet end is control", .input = {.looks = {look_at(0ms, DIALOG), look_at(1000ms), look_at(4100ms, STILL)}, .config = quiet_room_config()}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp index faabc22bf2..f45b0f4b00 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp @@ -74,6 +74,14 @@ const FrameCase FRAME_CASES[] = { .input = {.path = "AutoStoryScreenEvents/za2_m3v_s1.png"}, .expectation = {.events = {.interact_prompt = true, .can_move = false}}, }, + { + // console B, 2026-11-15: 01.02's battle area, the scene over; + // "Parla" is Italian for "Talk", Ryon the man at the gate. No + // Pokemon yet, so no party bar. + .name = "the A Talk prompt on the Italian game", + .input = {.path = "AutoStoryScreenEvents/it_0102_parla_talk_prompt.png"}, + .expectation = {.events = {.interact_prompt = true, .can_move = false}}, + }, }; struct FolderCase{ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.02.plan.json index b7e0aa45c3..c173391cbe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.02.plan.json @@ -32,7 +32,7 @@ { "id": "battle_area", "kind": "game_action", - "why": "the scene until free control in the battle area (the controls hint); autosave", + "why": "the scene until free control in the battle area: no controls hint shows here, and no party bar (no Pokemon yet); control is the A Talk prompt to Ryon at the gate, held a second past 20 s (min_length_ms, past the cutscene). No A at that prompt: it restarts his talk (console B 2026-11-15, Italian). Autosave", "action": "mash_to_move_hints", "args": { "min_length_ms": 20000 From 4afd5d6461f0539712632a42c7758a567639a7d4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:08:34 -0800 Subject: [PATCH 10/14] PLZA scene machine: fail fast as scene_loop when blind A keeps restarting a talk 01.02's battle area blind-pressed Ryon's talk open again and again for 3 min (console B 2026-11-15); reproducing it needs a wiped save. Now when blind presses (after a quiet spell, blind_press_after above zero) bring back text 4 times in a row with only text and cutscenes between (no fade, banner, choice or sign of control), the machine stops with "scene_loop" at that frame instead of pressing on. story_battle_start and talk_to_pokedex_screen, whose blind press every 2 s is their pace through a talk, are not watched. Sim tests: the loop from the log, a fade resetting the count, and a long battle talk. --- .../PokemonLZA_AutoStorySceneMachine.cpp | 63 +++++++++++++++++- .../PokemonLZA_AutoStorySceneMachine.h | 5 +- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 65 +++++++++++++++++++ 3 files changed, 130 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index bb0ad0b2f7..0af5c8fb4b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -47,6 +47,7 @@ enum class SceneScreen{ TALK_PROMPT, // terminal: an A prompt ("A Talk") on the overworld, held a second, past min_length PROMPT_SHOWING, // wait, no press: the A prompt, not held a second or before min_length NEVER_STARTED, // terminal, failing: no scene within start_window + SCENE_LOOP, // terminal, failing: blind presses each followed by text, MAX_BLIND_TEXT_LOOPS times, nothing else between QUIET_END, // terminal, failing unless quiet_is_control: nothing busy for the quiet time, past the minimum length BLIND_PRESS, // blind_button: nothing busy and no sign of control for blind_press_after SCENE_MOVING, // wait: no text, the screen changing @@ -87,6 +88,9 @@ class SceneTimeline{ private: // classify() past the fades and the text. SceneScreen classify_open(const ScreenObservation& look) const; + // Counts a blind press followed by text, and clears the count on any + // state but text, cutscenes and blind presses. + void track_blind_text_loop(SceneScreen screen); // Whether, with end_after_black_fades, the banner showing has an A // press due at `now`. bool banner_press_due(WallClock now) const; @@ -112,6 +116,11 @@ class SceneTimeline{ std::optional m_last_banner_press; // The black fades the machine has waited out. size_t m_black_fades = 0; + // The blind presses in a row each followed by text, with only text + // and cutscenes between (see blind_presses_recover()); whether the + // last blind press has been followed by text yet. + size_t m_blind_text_loops = 0; + bool m_blind_press_open = false; // Since when nothing busy and no banner has shown, once // end_after_black_fades' fades have all lifted. std::optional m_settled_since; @@ -156,6 +165,12 @@ constexpr Milliseconds BANNER_PRESS_EVERY = 1000ms; // PRINCIPALE 01" stayed 110 s with no press; one A cleared it and the // third black fade came ~4 s later (console B, 2026-11-15). constexpr Milliseconds BANNER_PRESS_AFTER = 2000ms; +// Blind presses in a row each followed by text, with no fade, banner, +// choice or sign of control between, past which the machine fails +// ("scene_loop"): the blind A restarts a talk. 01.02's battle area with +// the A prompt missed blind-pressed Ryon's talk open again for 3 min +// (console B, 2026-11-15); the failure stops the run there, at the frame. +constexpr size_t MAX_BLIND_TEXT_LOOPS = 3; // Text to press on: a box, or the advance chevron without one. bool text_shows(const ScreenObservation& look){ @@ -183,6 +198,15 @@ bool party_bar_is_control(const SceneMachineConfig& config){ return !config.stop_at_choice && !config.stop_at_battle; } +// Whether `config`'s blind presses recover from text the detectors miss +// after a quiet spell (blind_press_after above zero), which the loop +// guard watches, rather than set its pace: story_battle_start and +// talk_to_pokedex_screen press every 2 s where no text shows, between +// every two lines of a talk. +bool blind_presses_recover(const SceneMachineConfig& config){ + return config.blind_press_after && *config.blind_press_after > Milliseconds::zero(); +} + // An A prompt that is control for `config` shows on `look`. bool control_prompt_shows(const SceneMachineConfig& config, const ScreenObservation& look){ return party_bar_is_control(config) && look.events.has(ScreenEvent::INTERACT_PROMPT); @@ -196,7 +220,7 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::TALK_PROMPT, SceneScreen::PROMPT_SHOWING, - SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, + SceneScreen::SCENE_LOOP, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, }; @@ -247,6 +271,8 @@ std::string_view scene_screen_name(SceneScreen screen){ return "prompt_showing"; case SceneScreen::NEVER_STARTED: return "never_started"; + case SceneScreen::SCENE_LOOP: + return "scene_loop"; case SceneScreen::QUIET_END: return "quiet_end"; case SceneScreen::BLIND_PRESS: @@ -264,7 +290,7 @@ bool scene_screen_terminal(SceneScreen screen){ return screen == SceneScreen::BATTLE || screen == SceneScreen::CHOICE || screen == SceneScreen::MISSION_BANNER || screen == SceneScreen::CAN_MOVE || screen == SceneScreen::CONTROLS_HINT || screen == SceneScreen::TALK_PROMPT || screen == SceneScreen::FADE_SETTLED || - screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END; + screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END || screen == SceneScreen::SCENE_LOOP; } // Whether this state's step presses (DIALOG the config's text button, @@ -328,6 +354,9 @@ SceneScreen SceneTimeline::classify(const ScreenObservation& look) const{ if (m_config.stop_at_battle && look.events.has(ScreenEvent::BATTLE_STARTED)){ return SceneScreen::BATTLE; } + if (m_blind_text_loops > MAX_BLIND_TEXT_LOOPS){ + return SceneScreen::SCENE_LOOP; + } if (look.events.has(ScreenEvent::FADE_BLACK)){ return SceneScreen::FADE_BLACK; } @@ -392,6 +421,7 @@ void SceneTimeline::record(const ScreenObservation& look){ if (screen == SceneScreen::BLIND_PRESS){ m_last_blind_press = look.when; } + track_blind_text_loop(screen); if (screen == SceneScreen::BANNER_PRESS){ m_banner_presses++; m_last_banner_press = look.when; @@ -421,6 +451,28 @@ void SceneTimeline::record(const ScreenObservation& look){ } } +void SceneTimeline::track_blind_text_loop(SceneScreen screen){ + if (!blind_presses_recover(m_config)){ + return; + } + switch (screen){ + case SceneScreen::BLIND_PRESS: + m_blind_press_open = true; + return; + case SceneScreen::DIALOG: + m_blind_text_loops += m_blind_press_open ? 1 : 0; + m_blind_press_open = false; + return; + case SceneScreen::SCENE_MOVING: + case SceneScreen::SCENE_STILL: + return; + default: + m_blind_text_loops = 0; + m_blind_press_open = false; + return; + } +} + // "text box, advance arrow": a look's events and readings for the log. std::string describe_look(const ScreenObservation& look){ @@ -770,6 +822,13 @@ Pokemon::Outcome scene_outcome( label, config.start_window ? config.start_window->count() : 0 )); } + if (result.terminal == scene_screen_name(SceneScreen::SCENE_LOOP)){ + return Pokemon::outcome_failed("scene_loop", std::format( + "{}: blind {} brought back the same kind of text {} times in a row with nothing else between: " + "it restarts a talk (an A prompt the detectors miss?).", + label, button_to_string(config.blind_button), MAX_BLIND_TEXT_LOOPS + 1 + )); + } if (result.terminal == scene_screen_name(SceneScreen::QUIET_END) && config.quiet_is_control){ backend.log(std::format("[PLZA {}] done: quiet, taken as control.", label)); return Pokemon::outcome_ok(); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index aa43bbad0e..47cee3eaa8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -102,7 +102,10 @@ struct SceneMachineConfig{ // the file log (log_detail()) except the black fades, the banner, the // hint and the end, which go on the overlay too (log()). Fails as "scene_quiet" on the // quiet end (unless `config.quiet_is_control`), "scene_never_started" -// past `config.start_window`, "scene_timeout" when `timeout` passes (by +// past `config.start_window`, "scene_loop" when blind presses after +// `config.blind_press_after` (above zero) bring back text 4 times in a +// row with nothing else between (they restart a talk), "scene_timeout" +// when `timeout` passes (by // the looks' time), and "scene_stuck" on a state that comes up too often // or a screen that stops changing. Pokemon::Outcome run_scene_machine( diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index f5aa64daeb..f3a56ff9eb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -150,6 +150,52 @@ std::vector> battle_area_talk_prompt(){ }; } +// `cycles` times from `from`, 7 s apart: a text box, a screen with no +// text, and 6 s after the text another (a blind A). +std::vector> blind_press_then_text(Milliseconds from, size_t cycles){ + std::vector> looks; + for (size_t cycle = 0; cycle < cycles; cycle++){ + const Milliseconds base = from + 7000ms * (int64_t)cycle; + looks.push_back(look_at(base, DIALOG)); + looks.push_back(look_at(base + 500ms)); + looks.push_back(look_at(base + 6000ms)); + } + return looks; +} + +// 01.02's battle area with the talk prompt missed (console B, 2026-11-15): +// each blind A restarted the talk, the same text came back, for 3 min. +std::vector> talk_restarting(){ + return blind_press_then_text(/*from=*/0ms, /*cycles=*/8); +} + +// Three blind A presses each followed by text, a black fade, three more, +// then the controls hint. +std::vector> blind_presses_split_by_a_fade(){ + std::vector> looks = blind_press_then_text(/*from=*/0ms, /*cycles=*/3); + looks.push_back(look_at(21000ms, BLACK)); + looks.push_back(look_at(21500ms)); + for (const Observation& look : blind_press_then_text(/*from=*/22000ms, /*cycles=*/3)){ + looks.push_back(look); + } + looks.push_back(look_at(/*at=*/43000ms, NOTHING, {CONTROLS_HINT_READING})); + looks.push_back(look_at(/*at=*/44100ms, NOTHING, {CONTROLS_HINT_READING})); + return looks; +} + +// story_battle_start's talk: `lines` text boxes 2.5 s apart with a look +// with no text after each (a blind A), then the battle HUD. +std::vector> talk_with_gaps(size_t lines){ + std::vector> looks; + for (size_t line = 0; line < lines; line++){ + const Milliseconds base = 2500ms * (int64_t)line; + looks.push_back(look_at(base, DIALOG)); + looks.push_back(look_at(base + 500ms)); + } + looks.push_back(look_at(2500ms * (int64_t)lines, BATTLE)); + return looks; +} + // A quiet time of 8 s after a scene of at least `min_length`, no blind A. SceneMachineConfig quiet_config(Milliseconds min_length){ SceneMachineConfig config; @@ -617,6 +663,25 @@ const RunCase RUN_CASES[] = { .input = {.looks = {look_at(0ms, PROMPT), look_at(2500ms, PROMPT), look_at(3000ms, BATTLE)}, .config = battle_config()}, .expectation = {.verdict = "done", .a_presses = 2, .states = "blind_press, battle"}, }, + { + // console B, 2026-11-15: with the prompt missed, each blind A + // restarted Ryon's talk, the same text came back, for 3 min. + .name = "blind A followed by text 4 times with nothing else between fails fast as scene_loop", + .input = {.looks = talk_restarting()}, + .expectation = {.verdict = "failed: scene_loop", .a_presses = 9}, + }, + { + .name = "a black fade between blind presses followed by text is progress, not a loop", + .input = {.looks = blind_presses_split_by_a_fade()}, + .expectation = {.verdict = "done", .a_presses = 12, .line = "[PLZA test] done on controls_hint."}, + }, + { + // Its blind A every 2 s is its pace through the talk, not a + // recovery. + .name = "story_battle_start: blind A between the lines of a long talk is not a loop", + .input = {.looks = talk_with_gaps(/*lines=*/6), .config = battle_config()}, + .expectation = {.verdict = "done", .a_presses = 12, .line = "[PLZA test] done on battle."}, + }, { .name = "Hotel Z's room: the quiet end is control", .input = {.looks = {look_at(0ms, DIALOG), look_at(1000ms), look_at(4100ms, STILL)}, .config = quiet_room_config()}, From 3f7cc8b5ce8d01fb7efa29ce462c9b6af21fbc9b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:09:04 -0800 Subject: [PATCH 11/14] =?UTF-8?q?CI=20(fork=20only):=20pin=20CommandLineTe?= =?UTF-8?q?sts=20848e0b0=20(01.02=20Italian=20talk=20prompt)=20=E2=80=94?= =?UTF-8?q?=20drop=20before=20upstream?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/cpp-ci-serial-programs-base.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index f0cf18a859..1262007a8a 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -247,9 +247,9 @@ jobs: with: # The fork's fixtures: upstream's plus the PLZA AutoStory frames (Confirm Choices, opening and arrival folders), dayfine/CommandLineTests PR #18, # and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language), - # and the 01.02 choice menu in Italian (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.02 choice menu and talk prompt in Italian (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '8b376ffb6a7476af5f9cf4c786fb852ef5e49efc' + ref: '848e0b03a03d9cdca580f21f3389486478d52f4d' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded From fd653ee3548b861abf711a52ff3a142eeff0c808 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:29:54 -0800 Subject: [PATCH 12/14] Revert "PLZA scene machine: fail fast as scene_loop when blind A keeps restarting a talk" This reverts commit 4afd5d6461f0539712632a42c7758a567639a7d4. --- .../PokemonLZA_AutoStorySceneMachine.cpp | 63 +----------------- .../PokemonLZA_AutoStorySceneMachine.h | 5 +- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 65 ------------------- 3 files changed, 3 insertions(+), 130 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index 0af5c8fb4b..bb0ad0b2f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -47,7 +47,6 @@ enum class SceneScreen{ TALK_PROMPT, // terminal: an A prompt ("A Talk") on the overworld, held a second, past min_length PROMPT_SHOWING, // wait, no press: the A prompt, not held a second or before min_length NEVER_STARTED, // terminal, failing: no scene within start_window - SCENE_LOOP, // terminal, failing: blind presses each followed by text, MAX_BLIND_TEXT_LOOPS times, nothing else between QUIET_END, // terminal, failing unless quiet_is_control: nothing busy for the quiet time, past the minimum length BLIND_PRESS, // blind_button: nothing busy and no sign of control for blind_press_after SCENE_MOVING, // wait: no text, the screen changing @@ -88,9 +87,6 @@ class SceneTimeline{ private: // classify() past the fades and the text. SceneScreen classify_open(const ScreenObservation& look) const; - // Counts a blind press followed by text, and clears the count on any - // state but text, cutscenes and blind presses. - void track_blind_text_loop(SceneScreen screen); // Whether, with end_after_black_fades, the banner showing has an A // press due at `now`. bool banner_press_due(WallClock now) const; @@ -116,11 +112,6 @@ class SceneTimeline{ std::optional m_last_banner_press; // The black fades the machine has waited out. size_t m_black_fades = 0; - // The blind presses in a row each followed by text, with only text - // and cutscenes between (see blind_presses_recover()); whether the - // last blind press has been followed by text yet. - size_t m_blind_text_loops = 0; - bool m_blind_press_open = false; // Since when nothing busy and no banner has shown, once // end_after_black_fades' fades have all lifted. std::optional m_settled_since; @@ -165,12 +156,6 @@ constexpr Milliseconds BANNER_PRESS_EVERY = 1000ms; // PRINCIPALE 01" stayed 110 s with no press; one A cleared it and the // third black fade came ~4 s later (console B, 2026-11-15). constexpr Milliseconds BANNER_PRESS_AFTER = 2000ms; -// Blind presses in a row each followed by text, with no fade, banner, -// choice or sign of control between, past which the machine fails -// ("scene_loop"): the blind A restarts a talk. 01.02's battle area with -// the A prompt missed blind-pressed Ryon's talk open again for 3 min -// (console B, 2026-11-15); the failure stops the run there, at the frame. -constexpr size_t MAX_BLIND_TEXT_LOOPS = 3; // Text to press on: a box, or the advance chevron without one. bool text_shows(const ScreenObservation& look){ @@ -198,15 +183,6 @@ bool party_bar_is_control(const SceneMachineConfig& config){ return !config.stop_at_choice && !config.stop_at_battle; } -// Whether `config`'s blind presses recover from text the detectors miss -// after a quiet spell (blind_press_after above zero), which the loop -// guard watches, rather than set its pace: story_battle_start and -// talk_to_pokedex_screen press every 2 s where no text shows, between -// every two lines of a talk. -bool blind_presses_recover(const SceneMachineConfig& config){ - return config.blind_press_after && *config.blind_press_after > Milliseconds::zero(); -} - // An A prompt that is control for `config` shows on `look`. bool control_prompt_shows(const SceneMachineConfig& config, const ScreenObservation& look){ return party_bar_is_control(config) && look.events.has(ScreenEvent::INTERACT_PROMPT); @@ -220,7 +196,7 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::TALK_PROMPT, SceneScreen::PROMPT_SHOWING, - SceneScreen::SCENE_LOOP, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, + SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, }; @@ -271,8 +247,6 @@ std::string_view scene_screen_name(SceneScreen screen){ return "prompt_showing"; case SceneScreen::NEVER_STARTED: return "never_started"; - case SceneScreen::SCENE_LOOP: - return "scene_loop"; case SceneScreen::QUIET_END: return "quiet_end"; case SceneScreen::BLIND_PRESS: @@ -290,7 +264,7 @@ bool scene_screen_terminal(SceneScreen screen){ return screen == SceneScreen::BATTLE || screen == SceneScreen::CHOICE || screen == SceneScreen::MISSION_BANNER || screen == SceneScreen::CAN_MOVE || screen == SceneScreen::CONTROLS_HINT || screen == SceneScreen::TALK_PROMPT || screen == SceneScreen::FADE_SETTLED || - screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END || screen == SceneScreen::SCENE_LOOP; + screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END; } // Whether this state's step presses (DIALOG the config's text button, @@ -354,9 +328,6 @@ SceneScreen SceneTimeline::classify(const ScreenObservation& look) const{ if (m_config.stop_at_battle && look.events.has(ScreenEvent::BATTLE_STARTED)){ return SceneScreen::BATTLE; } - if (m_blind_text_loops > MAX_BLIND_TEXT_LOOPS){ - return SceneScreen::SCENE_LOOP; - } if (look.events.has(ScreenEvent::FADE_BLACK)){ return SceneScreen::FADE_BLACK; } @@ -421,7 +392,6 @@ void SceneTimeline::record(const ScreenObservation& look){ if (screen == SceneScreen::BLIND_PRESS){ m_last_blind_press = look.when; } - track_blind_text_loop(screen); if (screen == SceneScreen::BANNER_PRESS){ m_banner_presses++; m_last_banner_press = look.when; @@ -451,28 +421,6 @@ void SceneTimeline::record(const ScreenObservation& look){ } } -void SceneTimeline::track_blind_text_loop(SceneScreen screen){ - if (!blind_presses_recover(m_config)){ - return; - } - switch (screen){ - case SceneScreen::BLIND_PRESS: - m_blind_press_open = true; - return; - case SceneScreen::DIALOG: - m_blind_text_loops += m_blind_press_open ? 1 : 0; - m_blind_press_open = false; - return; - case SceneScreen::SCENE_MOVING: - case SceneScreen::SCENE_STILL: - return; - default: - m_blind_text_loops = 0; - m_blind_press_open = false; - return; - } -} - // "text box, advance arrow": a look's events and readings for the log. std::string describe_look(const ScreenObservation& look){ @@ -822,13 +770,6 @@ Pokemon::Outcome scene_outcome( label, config.start_window ? config.start_window->count() : 0 )); } - if (result.terminal == scene_screen_name(SceneScreen::SCENE_LOOP)){ - return Pokemon::outcome_failed("scene_loop", std::format( - "{}: blind {} brought back the same kind of text {} times in a row with nothing else between: " - "it restarts a talk (an A prompt the detectors miss?).", - label, button_to_string(config.blind_button), MAX_BLIND_TEXT_LOOPS + 1 - )); - } if (result.terminal == scene_screen_name(SceneScreen::QUIET_END) && config.quiet_is_control){ backend.log(std::format("[PLZA {}] done: quiet, taken as control.", label)); return Pokemon::outcome_ok(); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 47cee3eaa8..aa43bbad0e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -102,10 +102,7 @@ struct SceneMachineConfig{ // the file log (log_detail()) except the black fades, the banner, the // hint and the end, which go on the overlay too (log()). Fails as "scene_quiet" on the // quiet end (unless `config.quiet_is_control`), "scene_never_started" -// past `config.start_window`, "scene_loop" when blind presses after -// `config.blind_press_after` (above zero) bring back text 4 times in a -// row with nothing else between (they restart a talk), "scene_timeout" -// when `timeout` passes (by +// past `config.start_window`, "scene_timeout" when `timeout` passes (by // the looks' time), and "scene_stuck" on a state that comes up too often // or a screen that stops changing. Pokemon::Outcome run_scene_machine( diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index f3a56ff9eb..f5aa64daeb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -150,52 +150,6 @@ std::vector> battle_area_talk_prompt(){ }; } -// `cycles` times from `from`, 7 s apart: a text box, a screen with no -// text, and 6 s after the text another (a blind A). -std::vector> blind_press_then_text(Milliseconds from, size_t cycles){ - std::vector> looks; - for (size_t cycle = 0; cycle < cycles; cycle++){ - const Milliseconds base = from + 7000ms * (int64_t)cycle; - looks.push_back(look_at(base, DIALOG)); - looks.push_back(look_at(base + 500ms)); - looks.push_back(look_at(base + 6000ms)); - } - return looks; -} - -// 01.02's battle area with the talk prompt missed (console B, 2026-11-15): -// each blind A restarted the talk, the same text came back, for 3 min. -std::vector> talk_restarting(){ - return blind_press_then_text(/*from=*/0ms, /*cycles=*/8); -} - -// Three blind A presses each followed by text, a black fade, three more, -// then the controls hint. -std::vector> blind_presses_split_by_a_fade(){ - std::vector> looks = blind_press_then_text(/*from=*/0ms, /*cycles=*/3); - looks.push_back(look_at(21000ms, BLACK)); - looks.push_back(look_at(21500ms)); - for (const Observation& look : blind_press_then_text(/*from=*/22000ms, /*cycles=*/3)){ - looks.push_back(look); - } - looks.push_back(look_at(/*at=*/43000ms, NOTHING, {CONTROLS_HINT_READING})); - looks.push_back(look_at(/*at=*/44100ms, NOTHING, {CONTROLS_HINT_READING})); - return looks; -} - -// story_battle_start's talk: `lines` text boxes 2.5 s apart with a look -// with no text after each (a blind A), then the battle HUD. -std::vector> talk_with_gaps(size_t lines){ - std::vector> looks; - for (size_t line = 0; line < lines; line++){ - const Milliseconds base = 2500ms * (int64_t)line; - looks.push_back(look_at(base, DIALOG)); - looks.push_back(look_at(base + 500ms)); - } - looks.push_back(look_at(2500ms * (int64_t)lines, BATTLE)); - return looks; -} - // A quiet time of 8 s after a scene of at least `min_length`, no blind A. SceneMachineConfig quiet_config(Milliseconds min_length){ SceneMachineConfig config; @@ -663,25 +617,6 @@ const RunCase RUN_CASES[] = { .input = {.looks = {look_at(0ms, PROMPT), look_at(2500ms, PROMPT), look_at(3000ms, BATTLE)}, .config = battle_config()}, .expectation = {.verdict = "done", .a_presses = 2, .states = "blind_press, battle"}, }, - { - // console B, 2026-11-15: with the prompt missed, each blind A - // restarted Ryon's talk, the same text came back, for 3 min. - .name = "blind A followed by text 4 times with nothing else between fails fast as scene_loop", - .input = {.looks = talk_restarting()}, - .expectation = {.verdict = "failed: scene_loop", .a_presses = 9}, - }, - { - .name = "a black fade between blind presses followed by text is progress, not a loop", - .input = {.looks = blind_presses_split_by_a_fade()}, - .expectation = {.verdict = "done", .a_presses = 12, .line = "[PLZA test] done on controls_hint."}, - }, - { - // Its blind A every 2 s is its pace through the talk, not a - // recovery. - .name = "story_battle_start: blind A between the lines of a long talk is not a loop", - .input = {.looks = talk_with_gaps(/*lines=*/6), .config = battle_config()}, - .expectation = {.verdict = "done", .a_presses = 12, .line = "[PLZA test] done on battle."}, - }, { .name = "Hotel Z's room: the quiet end is control", .input = {.looks = {look_at(0ms, DIALOG), look_at(1000ms), look_at(4100ms, STILL)}, .config = quiet_room_config()}, From cc86801995126b04158225b10deca5aa30d1528b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:42:15 -0800 Subject: [PATCH 13/14] PLZA scene machine: act on classified screens, no blind A in story scenes The scene_loop guard (reverted in the commit before) stopped a passing 01.01 run at Jacinthe's subtitles: the blind A every 2 s it watched was the problem, not the text. Now every screen the machine presses on is one a detector classifies: text box or advance chevron (subtitles too) A, mission complete card A, tutorial card A (new state, TUTORIAL_CARD_READING), banner up 2 s with end_after_black_fades A. Nothing classified waits and is logged. mash_to_move_hints and story_battle_start drop their blind presses; only talk_to_pokedex_screen keeps blind B, for Pokedex screens no detector reads. A still screen's wait ends on any other state (a still subtitle with its chevron). Each run logs the states its step ends on ("start, expecting ...") and its failures name them. Replay tests (PokemonLZA_AutoStorySceneReplay_Tests): the machine's logs of two passing Italian 01.01 runs, the run the guard stopped, 01.02's A Parla loop and an English 01.02 pass, replayed look by look, must reach the plan's end state. --- .../PokemonLZA/PokemonLZA_Tests.cpp | 2 + .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 18 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 5 +- .../PokemonLZA_AutoStorySceneMachine.cpp | 77 +- .../PokemonLZA_AutoStorySceneMachine.h | 11 +- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 46 +- .../PokemonLZA_AutoStorySceneReplay_Tests.cpp | 667 ++++++++++++++++++ .../PokemonLZA_AutoStorySceneReplay_Tests.h | 28 + SerialPrograms/cmake/SourceFiles.cmake | 2 + 9 files changed, 807 insertions(+), 49 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 8f8d2e9c6e..35b7bf5acc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -29,6 +29,7 @@ #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h" +#include "Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.h" namespace PokemonAutomation{ @@ -62,6 +63,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStoryLines(database); add_tests_AutoStoryObjectiveMarkerReader(database); add_tests_AutoStorySceneMachine(database); + add_tests_AutoStorySceneReplay(database); add_tests_AutoStoryScreenEvents(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index b34d44a381..3d61fb30ce 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -473,9 +473,10 @@ Outcome walk_step(Pokemon::StoryBackend& backend, const StoryActionCal // on the Italian game). The next step's walk waits for control (check_can_walk()). // 01.01's arrival takes ~240 s on the console, hence // 360 s. A text-free cutscene (01.01's city flyover, ~20 s) is not -// control: a minute with nothing busy fails the step. After 5 s with -// nothing busy and no sign of control, A every 2 s, for text the detectors -// miss (01.01's ad). +// control: a minute with nothing busy fails the step. No blind A: the +// ad's subtitles show the advance chevron, which gets A like a text box, +// and a blind A at the end of a talk restarts it (01.02's battle area, +// console B 2026-11-15). // "min_length_ms" holds the quiet failure off for a long still scene; // "quiet_ms" is the quiet time, which with "quiet_is_control" ends the // step with control (Hotel Z shows no party bar). "press_a_first" presses @@ -489,7 +490,6 @@ Outcome move_hints_step(Pokemon::StoryBackend& backend, const StoryAct config.quiet = Milliseconds(Pokemon::story_arg(call.args, "quiet_ms")); config.quiet_is_control = Pokemon::story_arg(call.args, "quiet_is_control"); config.min_length = Milliseconds(Pokemon::story_arg(call.args, "min_length_ms")); - config.blind_press_after = 5s; const auto fades = call.args.find("end_after_black_fades"); if (fades != call.args.end()){ config.end_after_black_fades = (size_t)std::get(fades->second); @@ -527,13 +527,12 @@ Outcome walk_to_prompt_step(Pokemon::StoryBackend& backend, const Stor // "story_battle_start": A through the talk before a story battle (a -// choice takes its top row) and, every 2 s where no text shows, through -// the battle tutorial's cards and the VS splash, until the battle HUD -// shows, 90 s at most. +// choice takes its top row) and the battle tutorial's cards +// (TUTORIAL_CARD_READING), waiting out the VS splash, until the battle +// HUD shows, 90 s at most. Outcome battle_start_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ SceneMachineConfig config; config.stop_at_battle = true; - config.blind_press_after = Milliseconds(0); return run_scene_machine(backend, "story_battle_start", config, 90s); } @@ -557,7 +556,8 @@ Outcome ladder_step(Pokemon::StoryBackend& backend, const StoryActionC // "talk_to_pokedex_screen": the nurse's talk and the Pokedex app (03.04) // until the party bar holds a second, 90 s at most: B at its text and, // every 2 s while neither text nor control shows, at the Pokedex screens, -// which only B closes (A plays the entry's motions). +// which only B closes (A plays the entry's motions). The one blind press +// left: no detector reads the Pokedex screens yet. Outcome pokedex_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ SceneMachineConfig config; config.text_button = BUTTON_B; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp index c29191986c..366c74d635 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -23,6 +23,7 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h" #include "PokemonLZA_AutoStoryGame.h" +#include "Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h" #include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStoryGame_Tests.h" @@ -373,7 +374,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, press A, wait 250ms, wait 250ms, wait 500ms, press A, wait 250ms, wait 500ms", + .inputs = "press A, wait 250ms, wait 250ms, press A, wait 250ms, wait 250ms, wait 500ms, wait 500ms, wait 250ms, wait 500ms", .line = "[PLZA mash_to_move_hints] done on fade_settled.", }, }, @@ -510,7 +511,7 @@ const RunCase RUN_CASES[] = { .name = "01.03's battle start: A through the talk and the tutorial card, done on the battle HUD", .input = {.checkpoint = "01.03", .first_step = 2, .steps = 1, .looks = { look({ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX}, /*readings=*/{}, Milliseconds(0)), - look(/*events=*/{}, /*readings=*/{}, Milliseconds(500)), + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(500)), look({ScreenEvent::BATTLE_STARTED}, /*readings=*/{}, Milliseconds(1000)), }}, .expectation = { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index bb0ad0b2f7..d62ae74cab 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -16,6 +16,7 @@ #include #include "Common/Cpp/PrettyPrint.h" #include "CommonTools/ScreenMachine/ScreenMachine.h" +#include "Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h" #include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStorySceneMachine.h" @@ -36,6 +37,7 @@ enum class SceneScreen{ CHOICE, // terminal: the choice box, with stop_at_choice DIALOG, // the text button: a box (A: its choice's top row too), or the advance chevron MISSION_COMPLETE, // A: a main mission's "COMPLETE" card + TUTORIAL_CARD, // A: a tutorial card (only A turns its pages) MISSION_BANNER, // terminal: a main mission's banner, on a second look BANNER_SHOWING, // wait: the banner, on its first look (every look, with end_after_black_fades) BANNER_PRESS, // A: with end_after_black_fades, the banner up BANNER_PRESS_AFTER (BANNER_PRESSES times, BANNER_PRESS_EVERY apart) @@ -48,9 +50,9 @@ enum class SceneScreen{ PROMPT_SHOWING, // wait, no press: the A prompt, not held a second or before min_length NEVER_STARTED, // terminal, failing: no scene within start_window QUIET_END, // terminal, failing unless quiet_is_control: nothing busy for the quiet time, past the minimum length - BLIND_PRESS, // blind_button: nothing busy and no sign of control for blind_press_after - SCENE_MOVING, // wait: no text, the screen changing - SCENE_STILL, // wait: no text, the screen still since the look before + BLIND_PRESS, // blind_button: nothing busy and no sign of control for blind_press_after (only talk_to_pokedex_screen's Pokedex screens) + SCENE_MOVING, // wait, no press: no text, the screen changing + SCENE_STILL, // wait, no press: no text, the screen still since the look before }; // The time-dependent part of the machine: when the screen was last busy, @@ -166,9 +168,11 @@ bool fade_shows(const ScreenObservation& look){ return look.events.has(ScreenEvent::FADE_BLACK) || look.events.has(ScreenEvent::FADE_WHITE); } -// Something holds the player: text, a fade, or the mission complete card. +// Something holds the player: text, a fade, the mission complete card or +// a tutorial card. bool busy(const ScreenObservation& look){ - return text_shows(look) || fade_shows(look) || look.readings.contains(MISSION_COMPLETE_READING); + return text_shows(look) || fade_shows(look) || look.readings.contains(MISSION_COMPLETE_READING) || + look.readings.contains(TUTORIAL_CARD_READING); } // A scene has started: text, a choice or a battle. @@ -191,7 +195,7 @@ bool control_prompt_shows(const SceneMachineConfig& config, const ScreenObservat constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::BATTLE, SceneScreen::FADE_BLACK, SceneScreen::FADE_WHITE, SceneScreen::CHOICE, SceneScreen::DIALOG, - SceneScreen::MISSION_COMPLETE, + SceneScreen::MISSION_COMPLETE, SceneScreen::TUTORIAL_CARD, SceneScreen::MISSION_BANNER, SceneScreen::BANNER_SHOWING, SceneScreen::BANNER_PRESS, SceneScreen::FADE_SETTLED, SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, @@ -225,6 +229,8 @@ std::string_view scene_screen_name(SceneScreen screen){ return "dialog"; case SceneScreen::MISSION_COMPLETE: return "mission_complete"; + case SceneScreen::TUTORIAL_CARD: + return "tutorial_card"; case SceneScreen::MISSION_BANNER: return "mission_banner"; case SceneScreen::BANNER_SHOWING: @@ -268,10 +274,44 @@ bool scene_screen_terminal(SceneScreen screen){ } // Whether this state's step presses (DIALOG the config's text button, -// BLIND_PRESS its blind button, MISSION_COMPLETE A); the others wait. +// BLIND_PRESS its blind button, MISSION_COMPLETE, TUTORIAL_CARD and +// BANNER_PRESS A); the others wait. bool scene_screen_presses(SceneScreen screen){ - return screen == SceneScreen::DIALOG || screen == SceneScreen::MISSION_COMPLETE || screen == SceneScreen::BLIND_PRESS || - screen == SceneScreen::BANNER_PRESS; + return screen == SceneScreen::DIALOG || screen == SceneScreen::MISSION_COMPLETE || screen == SceneScreen::TUTORIAL_CARD || + screen == SceneScreen::BLIND_PRESS || screen == SceneScreen::BANNER_PRESS; +} + +// "the controls hint, the party bar, the A prompt or the mission banner": +// the states `config` ends on, for the log and the failures, so they say +// where the step stands against where it should end. +std::string expected_end(const SceneMachineConfig& config){ + std::vector ends; + if (config.stop_at_battle){ + ends.push_back("the battle HUD"); + } + if (config.stop_at_choice){ + ends.push_back("the choice box"); + } + if (config.end_after_black_fades){ + ends.push_back(std::format("black fade {} settled", *config.end_after_black_fades)); + } + ends.push_back("the controls hint"); + if (party_bar_is_control(config)){ + ends.push_back("the party bar"); + ends.push_back("the A prompt"); + } + if (!config.end_after_black_fades){ + ends.push_back("the mission banner"); + } + if (config.quiet_is_control){ + ends.push_back("quiet"); + } + std::string text; + for (size_t index = 0; index < ends.size(); index++){ + const std::string_view separator = index == 0 ? "" : index + 1 == ends.size() ? " or " : ", "; + text += std::format("{}{}", separator, ends[index]); + } + return text; } // Whether this state's lines go on the stream's overlay too, for whoever @@ -347,6 +387,9 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (look.readings.contains(MISSION_COMPLETE_READING)){ return SceneScreen::MISSION_COMPLETE; } + if (look.readings.contains(TUTORIAL_CARD_READING)){ + return SceneScreen::TUTORIAL_CARD; + } if (look.readings.contains(MISSION_BANNER_READING)){ if (!m_config.end_after_black_fades && m_banner_looks >= 1){ return SceneScreen::MISSION_BANNER; @@ -647,10 +690,10 @@ class SceneRunner{ }); return; case SceneScreen::SCENE_STILL: + // Until the look is any other state: also a still screen with + // the chevron (01.01's subtitles), a hint or the banner. wait_until(STILL_WAIT, [this](const ScreenObservation& look){ - const std::optional due = m_timeline.quiet_end_due(); - return (due && look.when >= *due) || m_timeline.blind_press_due(look.when) || - m_timeline.fades_settled(look.when) || !look.events.has(ScreenEvent::SCREEN_STILL); + return m_timeline.classify(look) != SceneScreen::SCENE_STILL; }); return; case SceneScreen::PARTY_BAR: @@ -760,14 +803,15 @@ void wait_banner_gone(PlzaBackend& backend, std::string_view label){ Pokemon::Outcome scene_outcome( PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, const ScreenMachineResult& result ){ + const std::string expected = expected_end(config); if (!result.succeeded()){ const std::string_view kind = result.failure.starts_with("Did not finish") ? "scene_timeout" : "scene_stuck"; - return Pokemon::outcome_failed(std::string(kind), std::format("{}: {}", label, result.failure)); + return Pokemon::outcome_failed(std::string(kind), std::format("{}: {} (expecting {}).", label, result.failure, expected)); } if (result.terminal == scene_screen_name(SceneScreen::NEVER_STARTED)){ return Pokemon::outcome_failed("scene_never_started", std::format( - "{}: the scene never started (player not at its trigger?): no text, choice or battle in {} ms.", - label, config.start_window ? config.start_window->count() : 0 + "{}: the scene never started (player not at its trigger?): no text, choice or battle in {} ms (expecting {}).", + label, config.start_window ? config.start_window->count() : 0, expected )); } if (result.terminal == scene_screen_name(SceneScreen::QUIET_END) && config.quiet_is_control){ @@ -779,7 +823,7 @@ Pokemon::Outcome scene_outcome( // or banner: // a cutscene with no text, or control the detectors miss. return Pokemon::outcome_failed("scene_quiet", std::format( - "{}: nothing busy for {} ms and no sign of control.", label, config.quiet ? config.quiet->count() : 0 + "{}: nothing busy for {} ms and no sign of control (expecting {}).", label, config.quiet ? config.quiet->count() : 0, expected )); } if (result.terminal == scene_screen_name(SceneScreen::MISSION_BANNER)){ @@ -795,6 +839,7 @@ Pokemon::Outcome scene_outcome( Pokemon::Outcome run_scene_machine( PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, Milliseconds timeout ){ + backend.log(std::format("[PLZA {}] start, expecting {}.", label, expected_end(config))); // The look the states match and act on. Pokemon::Observation look = backend.observe(); bool first = true; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index aa43bbad0e..e04a417d25 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -53,8 +53,11 @@ struct SceneMachineConfig{ // still frame longer than `quiet`. Milliseconds min_length = Milliseconds(0); // Presses `blind_button` every 2 s once nothing busy and no sign of - // control has shown for this long, for text the detectors miss (01.01's - // ad). A does not skip a cutscene. + // control has shown for this long, for a screen no detector reads + // (03.04's Pokedex screens). Every screen a detector reads gets its + // own state and press instead; nothing else is pressed blind: a blind + // A at the end of a talk restarts it (01.02's battle area, console B + // 2026-11-15). A does not skip a cutscene. std::optional blind_press_after = std::nullopt; // The button of those blind presses: B on a screen that A does not // close (03.04's Pokedex entry, where A only plays its motions). @@ -88,7 +91,9 @@ struct SceneMachineConfig{ std::optional end_after_black_fades = std::nullopt; }; -// Presses through scenes until the controls hint or the party bar has +// Logs where the step should end ("[PLZA label] start, expecting the +// controls hint, ..."), then presses through scenes (a tutorial card, +// TUTORIAL_CARD_READING, gets A) until the controls hint or the party bar has // held a second, or an A prompt has held a second past // `config.min_length` (neither the party bar nor the prompt with // `config.stop_at_choice` or `config.stop_at_battle`), or diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index f5aa64daeb..eb69ca6244 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -17,6 +17,7 @@ #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h" +#include "Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h" #include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStorySceneMachine.h" #include "PokemonLZA_AutoStorySceneMachine_Tests.h" @@ -65,11 +66,10 @@ const ScreenEvents PARTY{ScreenEvent::PLAYER_CAN_MOVE}; const ScreenEvents PROMPT{ScreenEvent::INTERACT_PROMPT}; const ScreenEvents STILL_PROMPT{ScreenEvent::INTERACT_PROMPT, ScreenEvent::SCREEN_STILL}; -// mash_to_move_hints' config: a minute quiet, blind A after 5 s. +// mash_to_move_hints' config: a minute quiet, no blind A. SceneMachineConfig arrival_config(){ SceneMachineConfig config; config.quiet = 60000ms; - config.blind_press_after = 5000ms; return config; } @@ -81,12 +81,11 @@ SceneMachineConfig choice_config(){ return config; } -// story_battle_start's config: A through the talk, A every 2 s on screens -// with no text, ending on the battle HUD. +// story_battle_start's config: A through the talk and the tutorial cards, +// ending on the battle HUD. SceneMachineConfig battle_config(){ SceneMachineConfig config; config.stop_at_battle = true; - config.blind_press_after = 0ms; return config; } @@ -120,6 +119,13 @@ SceneMachineConfig blind_press_config(){ return config; } +// Blind A after 5 s and a minute quiet. +SceneMachineConfig quiet_blind_press_config(){ + SceneMachineConfig config = blind_press_config(); + config.quiet = 60000ms; + return config; +} + // The advance chevron, then a cutscene with nothing on it, looked at every // 500 ms from 5 s to 65 s, then the controls hint held a second. std::vector> minute_of_blind_presses(){ @@ -335,7 +341,7 @@ const RunCase RUN_CASES[] = { }, }, { - .name = "01.01's ad: A at the chevron, blind A after 5 s, none once the hint shows", + .name = "01.01's ad: A at the chevron, none on the still screen after it or once the hint shows", .input = {.looks = { look_at(0ms), look_at(/*at=*/1000ms, NOTHING, {ADVANCE_ARROW_READING}), @@ -351,8 +357,8 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .a_presses = 2, - .states = "scene_moving, dialog, scene_still, blind_press, scene_still, hint_showing, controls_hint", + .a_presses = 1, + .states = "scene_moving, dialog, scene_still, hint_showing, controls_hint", }, }, { @@ -381,7 +387,7 @@ const RunCase RUN_CASES[] = { look_at(6000ms, STILL), look_at(59000ms, STILL), look_at(60000ms, STILL), - }}, + }, .config = quiet_blind_press_config()}, .expectation = { .verdict = "failed: scene_quiet", .a_presses = 2, @@ -402,7 +408,7 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .a_presses = 0, .states = "scene_still, hint_showing, controls_hint"}, }, { - .name = "01.01's arrival: A at the text, in the flyover and at the choice, done on the controls hint", + .name = "01.01's arrival: A at the text and at the choice, none in the flyover, done on the controls hint", .input = {.looks = { look_at(0ms, DIALOG), look_at(1000ms), @@ -413,7 +419,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/24500ms, NOTHING, {CONTROLS_HINT_READING}), look_at(/*at=*/25100ms, NOTHING, {CONTROLS_HINT_READING}), }}, - .expectation = {.verdict = "done", .a_presses = 3, .line = "[PLZA test] done on controls_hint."}, + .expectation = {.verdict = "done", .a_presses = 2, .line = "[PLZA test] done on controls_hint."}, }, { .name = "the mission banner ends the scene, which then waits for it to go", @@ -461,7 +467,7 @@ const RunCase RUN_CASES[] = { { .name = "story_battle_start: A through the talk and the tutorial card, done on the battle HUD", .input = {.looks = { - look_at(0ms, CHOICE), look_at(500ms, DIALOG), look_at(1000ms), look_at(1500ms, BATTLE), + look_at(0ms, CHOICE), look_at(500ms, DIALOG), look_at(/*at=*/1000ms, NOTHING, {TUTORIAL_CARD_READING}), look_at(1500ms, BATTLE), }, .config = battle_config()}, .expectation = {.verdict = "done", .a_presses = 3, .line = "[PLZA test] done on battle."}, }, @@ -508,7 +514,7 @@ const RunCase RUN_CASES[] = { }, }, { - .name = "a machine that stops at a battle ends on the battle HUD, with A every 2 s where no text shows", + .name = "a machine that stops at a battle ends on the battle HUD, with no A where no text shows", .input = { .looks = { look_at(0ms, DIALOG), look_at(500ms), look_at(1000ms, STILL), look_at(2500ms, STILL), @@ -518,8 +524,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 3, - .states = "dialog, blind_press, scene_still, blind_press, battle", + .a_presses = 1, + .states = "dialog, scene_moving, scene_still, battle", }, }, { @@ -555,7 +561,7 @@ const RunCase RUN_CASES[] = { .looks = {look_at(0ms, STILL), look_at(1000ms, PARTY), look_at(2500ms, PARTY), look_at(3000ms, BATTLE)}, .config = battle_config(), }, - .expectation = {.verdict = "done", .a_presses = 2, .states = "blind_press, scene_moving, blind_press, battle"}, + .expectation = {.verdict = "done", .a_presses = 0, .states = "scene_still, scene_moving, battle"}, }, { .name = "a machine that stops at a choice does not take the party bar for control", @@ -606,16 +612,16 @@ const RunCase RUN_CASES[] = { .input = {.looks = battle_area_talk_prompt(), .config = battle_area_config()}, .expectation = { .verdict = "done", - .a_presses = 2, + .a_presses = 1, .line = "[PLZA test] done on talk_prompt.", - .states = "dialog, scene_moving, blind_press, prompt_showing, talk_prompt", + .states = "dialog, scene_moving, prompt_showing, talk_prompt", }, }, { // It shows between the lines of a talk, like the party bar. .name = "a machine that stops at a battle does not take the talk prompt for control", .input = {.looks = {look_at(0ms, PROMPT), look_at(2500ms, PROMPT), look_at(3000ms, BATTLE)}, .config = battle_config()}, - .expectation = {.verdict = "done", .a_presses = 2, .states = "blind_press, battle"}, + .expectation = {.verdict = "done", .a_presses = 0, .states = "scene_moving, battle"}, }, { .name = "Hotel Z's room: the quiet end is control", @@ -670,6 +676,7 @@ const RunCase RUN_CASES[] = { .states = "dialog, scene_moving, fade_black, dialog, fade_white, dialog, fade_black, banner_showing, " "fade_black, scene_moving, fade_settled", .overlay = std::vector{ + "[PLZA test] start, expecting black fade 3 settled, the controls hint, the party bar or the A prompt.", "[PLZA test] screen 3: fade_black at 1.0s: black fade, fade 1/3", "[PLZA test] screen 7: fade_black at 4.5s: black fade, fade 2/3", "[PLZA test] screen 8: banner_showing at 5.5s: mission banner", @@ -780,6 +787,7 @@ class RunTest : public UnitTest{ const RunCase& m_test; }; + } // namespace diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp new file mode 100644 index 0000000000..e748f17179 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp @@ -0,0 +1,667 @@ +/* PokemonLZA AutoStory - Scene machine replay Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Console runs of the scene machine replayed from their logs: each + * recorded look in order, whatever the machine presses (open loop). A + * guard or a press the screens do not call for shows as a wrong end here + * before it reaches the console. + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h" +#include "PokemonLZA_AutoStoryReadings.h" +#include "PokemonLZA_AutoStorySceneMachine.h" +#include "PokemonLZA_AutoStorySceneReplay_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +namespace{ + +using Pokemon::Observation; +using Pokemon::ZonePose; + + +std::string joined(const std::vector& texts, std::string_view separator){ + std::string text; + for (const std::string& part : texts){ + text += (text.empty() ? "" : std::string(separator)) + part; + } + return text; +} + +Observation look_at(Milliseconds at, ScreenEvents events = {}, std::vector readings = {}){ + Observation look; + look.when = WallClock::min() + at; + look.events = events; + for (std::string_view reading : readings){ + look.readings[std::string(reading)] = 1; + } + return look; +} + +// 01.01 arrival_scenes' config (mash_to_move_hints, end_after_black_fades +// 3, the action's defaults: a minute quiet). +SceneMachineConfig arrival_scenes_config(){ + SceneMachineConfig config; + config.quiet = 60000ms; + config.end_after_black_fades = 3; + return config; +} + +// 01.02 battle_area's config (mash_to_move_hints, min_length_ms 20000). +SceneMachineConfig battle_area_config(){ + SceneMachineConfig config; + config.quiet = 60000ms; + config.min_length = 20000ms; + return config; +} + + +// 01.01 arrival_scenes, passed (console B 2026-11-15 21:29, Italian). +constexpr std::string_view PASS_0101_IT_A = R"( +screen 1: fade_white at 0.0s: white fade, still +screen 2: dialog at 4.6s: text box, still +dialog x4 over 1.2s, 4 presses +screen 2: dialog at 6.6s: text box +dialog x11 over 4.1s, 11 presses +screen 2: dialog at 11.5s: text box, still +dialog x20 over 7.8s, 20 presses +screen 3: fade_white at 20.1s: white fade +screen 4: scene_moving at 20.9s: nothing +screen 5: blind_press at 25.4s: nothing +screen 6: scene_moving at 25.8s: nothing +scene_moving x50, blind_press x12 over 29.8s, 12 presses +screen 31: dialog at 56.6s: text box, advance arrow +screen 32: scene_moving at 57.0s: nothing +screen 33: dialog at 57.5s: text box +screen 33: dialog at 57.9s: text box, advance arrow +screen 34: scene_moving at 58.4s: nothing +screen 35: dialog at 61.4s: text box, advance arrow +screen 37: dialog at 62.8s: text box +screen 37: dialog at 63.2s: text box, advance arrow +screen 38: scene_moving at 63.6s: nothing +scene_moving x2, dialog x1 over 1.0s, 1 presses +screen 40: scene_moving at 65.5s: nothing +scene_moving x3, dialog x3 over 2.3s, 3 presses +screen 41: dialog at 68.8s: text box, advance arrow +screen 41: dialog at 69.2s: text box +dialog x4 over 1.2s, 4 presses +screen 42: scene_moving at 71.2s: nothing +screen 43: dialog at 73.3s: text box +dialog x10 over 3.7s, 10 presses +screen 44: scene_moving at 77.8s: nothing +scene_moving x16, dialog x6 over 10.2s, 6 presses +screen 49: dialog at 88.8s: text box, advance arrow +screen 49: dialog at 89.2s: text box +dialog x5 over 1.6s, 5 presses +screen 50: scene_moving at 91.7s: nothing +screen 51: dialog at 94.2s: text box +dialog x3 over 0.8s, 3 presses +screen 51: dialog at 95.8s: text box, advance arrow +screen 52: scene_moving at 96.2s: nothing +screen 53: dialog at 97.3s: text box +dialog x10, scene_moving x1 over 4.2s, 10 presses +screen 56: scene_moving at 102.2s: nothing +scene_moving x14, dialog x5 over 8.7s, 5 presses +screen 59: dialog at 111.9s: text box, advance arrow +screen 60: scene_moving at 112.3s: nothing +screen 61: fade_black at 113.3s: black fade, fade 1/3 +screen 62: scene_still at 115.6s: still +screen 63: scene_moving at 116.1s: nothing +screen 64: scene_still at 117.7s: still +screen 65: blind_press at 118.4s: still +screen 66: scene_moving at 118.8s: nothing +screen 67: blind_press at 120.9s: nothing +screen 68: scene_moving at 121.3s: nothing +scene_moving x7, blind_press x1 over 3.4s, 1 presses +screen 71: dialog at 125.7s: advance arrow +screen 72: scene_moving at 126.1s: nothing +scene_moving x16, dialog x1 over 8.0s, 1 presses +screen 75: blind_press at 135.2s: nothing +screen 76: scene_moving at 135.6s: nothing +screen 77: dialog at 137.6s: advance arrow +screen 78: scene_moving at 138.0s: nothing +screen 79: blind_press at 143.1s: nothing +screen 80: scene_moving at 143.5s: nothing +scene_moving x6, blind_press x1 over 2.9s, 1 presses +screen 83: dialog at 147.5s: advance arrow +screen 84: scene_moving at 147.9s: nothing +scene_moving x19, dialog x1 over 9.6s, 1 presses +screen 87: blind_press at 158.5s: nothing +screen 88: scene_moving at 158.9s: nothing +scene_moving x13, blind_press x3 over 7.3s, 3 presses +screen 95: dialog at 167.2s: advance arrow +screen 96: scene_moving at 167.7s: nothing +scene_moving x37, dialog x3 over 19.5s, 3 presses +screen 103: blind_press at 188.2s: nothing +screen 104: scene_moving at 188.6s: nothing +screen 105: dialog at 189.1s: advance arrow +dialog x2 over 0.4s, 2 presses +screen 106: scene_moving at 190.3s: nothing +scene_moving x13, dialog x1 over 6.5s, 1 presses +screen 109: scene_still at 197.8s: still +screen 110: blind_press at 199.6s: still +screen 111: dialog at 200.0s: advance arrow +screen 112: scene_moving at 200.4s: nothing +screen 113: fade_black at 201.4s: black fade, fade 2/3 +screen 114: blind_press at 211.4s: still +screen 115: dialog at 211.8s: text box +dialog x3 over 0.8s, 3 presses +screen 115: dialog at 213.5s: text box, advance arrow +screen 116: scene_moving at 213.9s: nothing +screen 117: dialog at 215.9s: text box +dialog x4 over 1.2s, 4 presses +screen 117: dialog at 217.9s: text box, advance arrow +scene_moving x1, dialog x2 over 0.9s, 2 presses +screen 120: scene_moving at 219.7s: nothing +screen 121: blind_press at 224.8s: nothing +screen 122: scene_moving at 225.2s: nothing +scene_moving x17, blind_press x4 over 9.8s, 4 presses +screen 131: dialog at 235.9s: text box +dialog x1 over 0.0s, 1 presses +screen 131: dialog at 236.8s: text box, advance arrow +screen 131: dialog at 237.2s: text box +screen 132: scene_moving at 237.6s: nothing +screen 133: dialog at 239.6s: text box +dialog x5, scene_moving x4 over 3.7s, 5 presses +screen 135: dialog at 244.1s: text box, advance arrow +screen 136: scene_moving at 244.5s: nothing +screen 137: banner_showing at 245.5s: mission banner +screen 138: banner_press at 247.6s: mission banner +screen 139: scene_moving at 248.0s: nothing +screen 140: fade_black at 252.6s: black fade, fade 3/3 +screen 141: scene_moving at 255.4s: nothing +screen 142: hint_showing at 256.4s: controls hint +screen 143: controls_hint at 257.4s: controls hint +)"; + +// 01.01 arrival_scenes, passed (console B 2026-11-15 21:55, Italian). +constexpr std::string_view PASS_0101_IT_B = R"( +screen 1: fade_white at 0.0s: white fade, still +screen 2: dialog at 4.3s: text box, still +dialog x5 over 1.6s, 5 presses +screen 2: dialog at 6.8s: text box +dialog x6 over 2.0s, 6 presses +screen 2: dialog at 9.7s: text box, still +dialog x24 over 9.4s, 24 presses +screen 3: fade_white at 19.9s: white fade +screen 4: dialog at 20.6s: text box, still +screen 5: scene_moving at 21.0s: nothing +screen 6: blind_press at 26.1s: nothing +screen 7: scene_moving at 26.5s: nothing +scene_moving x48, blind_press x12 over 28.8s, 12 presses +screen 32: dialog at 56.3s: text box +dialog x3 over 0.8s, 3 presses +screen 33: scene_moving at 57.9s: nothing +dialog x2, scene_moving x6 over 3.3s, 2 presses +screen 36: dialog at 62.3s: text box, advance arrow +screen 37: scene_moving at 62.7s: nothing +screen 38: dialog at 63.7s: text box +screen 38: dialog at 64.1s: text box, advance arrow +screen 39: scene_moving at 64.5s: nothing +scene_moving x2, dialog x1 over 1.0s, 1 presses +screen 41: scene_moving at 66.4s: nothing +scene_moving x3, dialog x4 over 2.7s, 4 presses +screen 42: dialog at 70.1s: text box, advance arrow +screen 42: dialog at 70.5s: text box +dialog x3 over 0.8s, 3 presses +screen 43: scene_moving at 72.1s: nothing +screen 44: dialog at 74.2s: text box +dialog x10 over 3.7s, 10 presses +screen 45: scene_moving at 78.6s: nothing +scene_moving x16, dialog x7 over 10.6s, 7 presses +screen 50: dialog at 90.1s: text box, advance arrow +screen 50: dialog at 90.5s: text box +dialog x4 over 1.2s, 4 presses +screen 51: scene_moving at 92.6s: nothing +screen 52: dialog at 95.1s: text box +dialog x3 over 0.8s, 3 presses +screen 53: scene_moving at 96.7s: nothing +scene_moving x1, dialog x7 over 3.0s, 7 presses +screen 54: dialog at 100.6s: text box, advance arrow +screen 55: scene_moving at 101.0s: nothing +screen 56: dialog at 101.5s: text box +dialog x3 over 0.8s, 3 presses +screen 57: scene_moving at 103.2s: nothing +scene_moving x16, dialog x6 over 10.1s, 6 presses +screen 62: fade_black at 114.2s: black fade, fade 1/3 +screen 63: scene_still at 116.5s: still +screen 64: blind_press at 119.4s: still +screen 65: scene_moving at 119.8s: nothing +screen 66: blind_press at 121.8s: nothing +screen 67: scene_moving at 122.2s: nothing +scene_moving x7, blind_press x1 over 3.5s, 1 presses +screen 70: dialog at 126.7s: advance arrow +screen 71: scene_moving at 127.1s: nothing +scene_moving x16, dialog x1 over 8.0s, 1 presses +screen 74: blind_press at 136.1s: nothing +screen 75: scene_moving at 136.6s: nothing +screen 76: dialog at 138.6s: advance arrow +screen 77: scene_moving at 139.0s: nothing +screen 78: blind_press at 143.6s: nothing +screen 79: scene_moving at 144.0s: nothing +scene_moving x6, blind_press x1 over 3.0s, 1 presses +screen 82: dialog at 148.0s: advance arrow +screen 83: scene_moving at 148.4s: nothing +screen 84: blind_press at 153.1s: nothing +screen 85: dialog at 153.5s: advance arrow +screen 86: scene_moving at 153.9s: nothing +scene_moving x8, blind_press x1 over 4.1s, 1 presses +screen 88: scene_moving at 159.0s: nothing +screen 89: dialog at 159.5s: advance arrow +screen 90: scene_moving at 159.9s: nothing +screen 91: blind_press at 164.5s: nothing +screen 92: scene_moving at 164.9s: nothing +scene_moving x5, blind_press x1 over 2.5s, 1 presses +screen 95: dialog at 168.4s: advance arrow +screen 96: scene_moving at 168.9s: nothing +scene_moving x16, dialog x1 over 8.2s, 1 presses +screen 99: blind_press at 178.0s: nothing +screen 100: scene_moving at 178.5s: nothing +scene_moving x7, blind_press x2 over 4.0s, 2 presses +screen 104: dialog at 183.4s: advance arrow +screen 105: scene_moving at 183.8s: nothing +screen 106: blind_press at 188.4s: nothing +screen 107: scene_moving at 188.8s: nothing +screen 108: dialog at 189.8s: advance arrow +dialog x2 over 0.4s, 2 presses +screen 109: scene_moving at 191.1s: nothing +scene_moving x13, dialog x1 over 6.6s, 1 presses +screen 112: scene_still at 198.7s: still +screen 113: blind_press at 200.2s: still +screen 114: scene_still at 200.7s: still +screen 115: dialog at 200.9s: still, advance arrow +screen 116: scene_moving at 201.3s: nothing +screen 117: fade_black at 202.3s: black fade, fade 2/3 +screen 118: blind_press at 212.2s: still +screen 119: dialog at 212.6s: text box +dialog x3 over 0.8s, 3 presses +screen 120: scene_moving at 214.2s: nothing +screen 121: dialog at 216.3s: text box +dialog x2 over 0.4s, 2 presses +screen 121: dialog at 217.5s: text box, advance arrow +screen 121: dialog at 217.9s: text box +dialog x1 over 0.0s, 1 presses +screen 122: scene_moving at 218.8s: nothing +screen 123: dialog at 219.3s: text box +dialog x1 over 0.0s, 1 presses +screen 123: dialog at 220.1s: text box, advance arrow +dialog x1 over 0.0s, 1 presses +screen 124: scene_moving at 220.9s: nothing +screen 125: blind_press at 225.6s: nothing +screen 126: scene_moving at 226.0s: nothing +scene_moving x16, blind_press x4 over 9.5s, 4 presses +screen 135: dialog at 236.5s: text box +screen 135: dialog at 236.9s: text box, advance arrow +screen 135: dialog at 237.3s: text box +dialog x3 over 0.8s, 3 presses +screen 136: scene_moving at 239.0s: nothing +screen 137: dialog at 241.0s: text box +dialog x5, scene_moving x6 over 4.6s, 5 presses +screen 141: banner_showing at 246.6s: mission banner +screen 142: banner_press at 248.7s: mission banner +screen 143: scene_moving at 249.1s: nothing +screen 144: fade_black at 253.7s: black fade, fade 3/3 +screen 145: scene_still at 256.5s: still +screen 146: hint_showing at 257.1s: still, controls hint +screen 146: hint_showing at 257.4s: controls hint +screen 147: controls_hint at 258.1s: controls hint +)"; + +// 01.01 arrival_scenes up to the scene_loop guard's false stop at +// Jacinthe's subtitles (console B 2026-11-15 22:27, Italian). +constexpr std::string_view FAIL_0101_IT_SUBTITLES = R"( +screen 1: fade_white at 0.0s: white fade, still +screen 2: dialog at 4.3s: text box, still +dialog x3 over 0.8s, 3 presses +screen 2: dialog at 6.0s: text box +screen 2: dialog at 6.4s: text box, still +dialog x32 over 12.7s, 32 presses +screen 3: fade_white at 19.9s: white fade +screen 4: scene_still at 20.7s: still +screen 5: scene_moving at 22.0s: nothing +screen 6: blind_press at 25.0s: nothing +screen 7: scene_moving at 25.4s: nothing +scene_moving x50, blind_press x12 over 30.0s, 12 presses +screen 32: dialog at 56.4s: text box +dialog x2 over 0.4s, 2 presses +screen 32: dialog at 57.7s: text box, advance arrow +screen 33: scene_moving at 58.1s: nothing +screen 34: dialog at 58.6s: text box +dialog x1 over 0.0s, 1 presses +screen 35: scene_moving at 59.4s: nothing +screen 36: dialog at 62.4s: text box, advance arrow +screen 37: scene_moving at 62.9s: nothing +screen 38: dialog at 63.9s: text box +screen 38: dialog at 64.3s: text box, advance arrow +screen 39: scene_moving at 64.7s: nothing +scene_moving x2, dialog x1 over 1.0s, 1 presses +screen 41: scene_moving at 66.6s: nothing +scene_moving x3, dialog x4 over 2.8s, 4 presses +screen 42: dialog at 70.3s: text box, advance arrow +screen 42: dialog at 70.7s: text box +dialog x3 over 0.8s, 3 presses +screen 43: scene_moving at 72.3s: nothing +screen 44: dialog at 74.4s: text box +dialog x17, scene_moving x17 over 15.2s, 17 presses +screen 50: dialog at 90.4s: text box, advance arrow +screen 50: dialog at 90.8s: text box +dialog x4 over 1.2s, 4 presses +screen 51: scene_moving at 92.8s: nothing +screen 52: dialog at 95.3s: text box +dialog x3 over 0.8s, 3 presses +screen 53: scene_moving at 97.0s: nothing +scene_moving x1, dialog x7 over 3.0s, 7 presses +screen 54: dialog at 100.8s: text box, advance arrow +screen 55: scene_moving at 101.3s: nothing +screen 56: dialog at 101.8s: text box +dialog x3 over 0.8s, 3 presses +screen 57: scene_moving at 103.4s: nothing +scene_moving x16, dialog x6 over 10.0s, 6 presses +screen 62: fade_black at 114.4s: black fade, fade 1/3 +screen 63: scene_moving at 116.8s: nothing +screen 64: scene_still at 118.3s: still +screen 65: blind_press at 119.6s: still +screen 66: scene_moving at 120.0s: nothing +screen 67: blind_press at 122.0s: nothing +screen 68: scene_moving at 122.4s: nothing +scene_moving x7, blind_press x1 over 3.5s, 1 presses +screen 71: dialog at 126.9s: advance arrow +screen 72: scene_moving at 127.3s: nothing +scene_moving x16, dialog x1 over 8.0s, 1 presses +screen 75: blind_press at 136.3s: nothing +screen 76: scene_moving at 136.7s: nothing +screen 77: dialog at 138.8s: advance arrow +screen 78: scene_moving at 139.2s: nothing +screen 79: blind_press at 144.3s: nothing +screen 80: scene_moving at 144.7s: nothing +scene_moving x6, blind_press x1 over 2.9s, 1 presses +screen 83: dialog at 148.6s: advance arrow +screen 84: scene_moving at 149.1s: nothing +screen 85: blind_press at 153.7s: nothing +screen 86: dialog at 154.1s: advance arrow +)"; + +// 01.02 battle_area's first 50 s, blind A at Ryon's "A Parla" prompt +// restarting his talk (console B 2026-11-15 21:56, Italian). +constexpr std::string_view LOOP_0102_IT_TALK_PROMPT = R"( +screen 1: dialog at 0.0s: text box +dialog x2 over 0.4s, 2 presses +screen 1: dialog at 1.2s: text box, advance arrow +screen 2: scene_moving at 1.7s: nothing +screen 3: dialog at 2.2s: text box +dialog x1 over 0.0s, 1 presses +screen 3: dialog at 3.0s: text box, advance arrow +scene_moving x1, dialog x4 over 1.8s, 4 presses +screen 6: scene_moving at 5.6s: nothing +screen 7: fade_black at 7.1s: black fade, fade 1 +screen 8: blind_press at 12.8s: still +screen 9: scene_moving at 13.2s: nothing +screen 9: scene_moving at 13.7s: A prompt +screen 10: blind_press at 15.3s: A prompt +screen 11: scene_moving at 15.7s: nothing +screen 12: dialog at 16.2s: text box +dialog x1 over 0.0s, 1 presses +screen 12: dialog at 17.0s: text box, advance arrow +screen 13: scene_moving at 17.4s: nothing +screen 13: scene_moving at 18.4s: A prompt +screen 14: blind_press at 22.0s: A prompt +screen 15: scene_moving at 22.4s: nothing +screen 16: dialog at 22.9s: text box +dialog x1 over 0.0s, 1 presses +screen 16: dialog at 23.8s: text box, advance arrow +screen 17: scene_moving at 24.2s: nothing +screen 17: scene_moving at 25.2s: A prompt +screen 18: blind_press at 28.8s: A prompt +screen 19: scene_moving at 29.3s: nothing +screen 20: dialog at 29.8s: text box +dialog x1 over 0.0s, 1 presses +screen 20: dialog at 30.6s: text box, advance arrow +screen 21: scene_moving at 31.1s: nothing +screen 21: scene_moving at 32.1s: A prompt +screen 22: blind_press at 35.7s: A prompt +screen 23: scene_moving at 36.2s: nothing +screen 24: dialog at 36.7s: text box +dialog x1 over 0.0s, 1 presses +screen 24: dialog at 37.5s: text box, advance arrow +screen 25: scene_moving at 37.9s: nothing +)"; + +// 01.02 battle_area, passed (console B 2026-11-13 12:02, English). That +// day's log put the readings on lines of their own, without the hint's: +// these lines carry them, the hint's from its state. +constexpr std::string_view PASS_0102_EN = R"( +screen 1: dialog at 0.0s: text box +screen 2: scene_moving at 1.8s: nothing +screen 3: dialog at 2.4s: text box +screen 4: scene_moving at 3.3s: nothing +screen 5: dialog at 3.8s: text box +screen 6: scene_moving at 5.1s: nothing +screen 7: fade_black at 6.7s: black fade, fade 1 +screen 8: blind_press at 12.4s: nothing +screen 9: hint_showing at 12.9s: controls hint +screen 10: controls_hint at 14.0s: controls hint +)"; + +// The looks of one screen in a scene machine's log: the state's events +// and readings by their names in the log ("text box", "advance arrow"; +// describe_look()). The fade count ("fade 1/3") is the machine's own. +Observation look_from_log(Milliseconds at, std::string_view readings){ + const std::pair events[] = { + {"black fade", ScreenEvent::FADE_BLACK}, {"white fade", ScreenEvent::FADE_WHITE}, + {"text box", ScreenEvent::DIALOG_BOX}, {"choice box", ScreenEvent::CHOICE_BOX}, + {"battle", ScreenEvent::BATTLE_STARTED}, {"party bar", ScreenEvent::PLAYER_CAN_MOVE}, + {"A prompt", ScreenEvent::INTERACT_PROMPT}, {"still", ScreenEvent::SCREEN_STILL}, + }; + const std::pair named_readings[] = { + {"controls hint", CONTROLS_HINT_READING}, {"advance arrow", ADVANCE_ARROW_READING}, + {"mission banner", MISSION_BANNER_READING}, {"mission complete", MISSION_COMPLETE_READING}, + }; + Observation look = look_at(at); + size_t from = 0; + while (from < readings.size()){ + const size_t comma = std::min(readings.find(", ", from), readings.size()); + const std::string_view name = readings.substr(from, comma - from); + from = comma + 2; + for (const auto& [event_name, event] : events){ + if (name == event_name){ + look.events.set(event, true); + } + } + for (const auto& [reading_name, reading] : named_readings){ + if (name == reading_name){ + look.readings[std::string(reading)] = 1; + } + } + } + return look; +} + +// What a look summed up as `state` showed: the screen the state is named +// for ("dialog" a text box). +std::string_view readings_of_state(std::string_view state){ + const std::pair states[] = { + {"dialog", "text box"}, {"scene_still", "still"}, {"fade_black", "black fade"}, {"fade_white", "white fade"}, + {"banner_showing", "mission banner"}, {"banner_press", "mission banner"}, {"hint_showing", "controls hint"}, + {"prompt_showing", "A prompt"}, {"party_bar", "party bar"}, {"mission_complete", "mission complete"}, + }; + for (const auto& [name, readings] : states){ + if (name == state){ + return readings; + } + } + return "nothing"; +} + +Milliseconds seconds_in_log(std::string_view text){ + return Milliseconds((int64_t)(std::stod(std::string(text)) * 1000 + 0.5)); +} + +// The looks of a console run from its scene machine's log, one line each +// ("screen 3: scene_still at 12.5s: still"), the looks a line sums up +// ("dialog x3, scene_moving x2 over 1.2s, 3 presses") spread over its time +// in turns. Opened loop: the run's presses are not replayed, the looks +// come as recorded whatever the machine presses. +std::vector> replay_log(std::string_view log){ + std::vector> looks; + Milliseconds last = 0ms; + size_t from = 0; + while (from < log.size()){ + const size_t end = std::min(log.find('\n', from), log.size()); + const std::string_view line = log.substr(from, end - from); + from = end + 1; + if (line.starts_with("screen ")){ + const size_t name = line.find(": ") + 2; + const size_t at = line.find(" at ", name) + 4; + const size_t seconds_end = line.find("s: ", at); + last = seconds_in_log(line.substr(at, seconds_end - at)); + looks.push_back(look_from_log(last, line.substr(seconds_end + 3))); + continue; + } + const size_t over = line.find(" over "); + if (over == std::string_view::npos){ + continue; + } + std::vector> counts; + size_t total = 0; + size_t item = 0; + while (item < over){ + const size_t item_end = std::min(line.find(", ", item), over); + const size_t times = line.find(" x", item); + const size_t count = (size_t)std::stoul(std::string(line.substr(times + 2, item_end - times - 2))); + counts.emplace_back(line.substr(item, times - item), count); + total += count; + item = item_end + 2; + } + const Milliseconds span = seconds_in_log(line.substr(over + 6, line.find("s, ", over) - over - 6)); + const Milliseconds step = std::max(span / (int64_t)std::max(total, 1), 10ms); + for (size_t turn = 0; turn < total;){ + for (auto& [state, left] : counts){ + if (left > 0){ + left--; + turn++; + last += step; + looks.push_back(look_from_log(last, readings_of_state(state))); + } + } + } + } + return looks; +} + +// The looks of `log`, then `then`. +std::vector> replay_then(std::string_view log, std::vector> then){ + std::vector> looks = replay_log(log); + for (Observation& look : then){ + looks.push_back(std::move(look)); + } + return looks; +} + +// Recorded console runs replayed: the machine must reach the state the +// plan's step ends on, with no press the screen did not call for. +struct ReplayCase{ + std::string name; + struct Input{ + std::vector> looks; + SceneMachineConfig config; + }; + Input input; + struct Expectation{ + // "done", or "failed: ". + std::string verdict; + // The run's last line: "[PLZA test] done on controls_hint.". + std::string end; + }; + Expectation expectation; +}; + +const ReplayCase REPLAY_CASES[] = { + { + .name = "01.01 arrival_scenes, Italian pass at 21:29", + .input = {.looks = replay_log(PASS_0101_IT_A), .config = arrival_scenes_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on controls_hint."}, + }, + { + .name = "01.01 arrival_scenes, Italian pass at 21:55", + .input = {.looks = replay_log(PASS_0101_IT_B), .config = arrival_scenes_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on controls_hint."}, + }, + { + // The scene_loop guard stopped it at 154.5 s; the run goes on to + // the controls hint. + .name = "01.01 arrival_scenes, Italian, Jacinthe's subtitles each after a quiet spell, then the controls hint", + .input = { + .looks = replay_then(FAIL_0101_IT_SUBTITLES, { + look_at(/*at=*/155000ms, /*events=*/{}, {CONTROLS_HINT_READING}), + look_at(/*at=*/156100ms, /*events=*/{}, {CONTROLS_HINT_READING}), + }), + .config = arrival_scenes_config(), + }, + .expectation = {.verdict = "done", .end = "[PLZA test] done on controls_hint."}, + }, + { + .name = "01.02 battle_area, Italian, the A Parla prompt past 20 s ends the step", + .input = {.looks = replay_log(LOOP_0102_IT_TALK_PROMPT), .config = battle_area_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on talk_prompt."}, + }, + { + .name = "01.02 battle_area, English pass on 2026-11-13: the controls hint ends the step", + .input = {.looks = replay_log(PASS_0102_EN), .config = battle_area_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on controls_hint."}, + }, +}; + +UnitTestResult check_replay(const ReplayCase& test, CancellableScope& scope){ + Pokemon::FakeStoryBackend backend({.looks = test.input.looks}, scope); + const Pokemon::Outcome outcome = run_scene_machine(backend, "test", test.input.config, 360s); + const std::string verdict = outcome.succeeded() ? "done" : std::format("failed: {}", outcome.failure); + if (verdict != test.expectation.verdict){ + return std::format("expected \"{}\", got \"{}\"; log:\n{}", test.expectation.verdict, verdict, joined(backend.lines(), "\n")); + } + if (backend.lines().empty() || backend.lines().back() != test.expectation.end){ + return std::format("expected the run to end with \"{}\"; log:\n{}", test.expectation.end, joined(backend.lines(), "\n")); + } + return true; +} + +class ReplayTest : public UnitTest{ +public: + explicit ReplayTest(const ReplayCase& test) + : UnitTest(std::format("PokemonLZA::AutoStorySceneMachine replay - {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ + return check_replay(m_test, scope); + } +private: + const ReplayCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStorySceneReplay(UnitTestDatabase& database){ + for (const ReplayCase& test : REPLAY_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h new file mode 100644 index 0000000000..ffa6745149 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h @@ -0,0 +1,28 @@ +/* PokemonLZA AutoStory - Scene machine replay Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStorySceneReplay_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStorySceneReplay_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the scene machine's replays of console runs: the looks its log +// recorded, played back on a scripted backend, must reach the state the +// plan's step ends on (passing runs, and runs a guard stopped or a blind +// press looped). No frames needed. +void add_tests_AutoStorySceneReplay(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 440a6f6b3b..52513f872f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2377,6 +2377,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp From 7e7fc0d3a49da5fc740fe8e59fff3ca2e0d99600 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 23:30:37 -0800 Subject: [PATCH 14/14] PLZA scene machine: a textless cutscene is a scene under way, not never_started 02.02's street scene moved 41 s with no text and no HUD after its black fade; the scene step failed as scene_never_started at 45 s (console B, 2026-11-15). With no HUD (party bar, controls hint, A prompt), a fade or a moving screen now counts as the scene under way. A step with a start window waits on the HUD before its scene (awaiting_scene) and fails as scene_never_started only when the HUD has shown for the window with no scene. The 02.02 log is a replay case (the controls hint after the cutscene is synthetic). --- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 7 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 8 +- .../PokemonLZA_AutoStorySceneMachine.cpp | 119 ++++++++++-------- .../PokemonLZA_AutoStorySceneMachine.h | 14 ++- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 36 ++++-- .../PokemonLZA_AutoStorySceneReplay_Tests.cpp | 31 +++++ 6 files changed, 138 insertions(+), 77 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 3d61fb30ce..0db9c55eb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -511,9 +511,10 @@ Outcome text_to_choice_step(Pokemon::StoryBackend& backend, const Stor // A step's scene ("scene" "a"): A through its text until the party bar -// holds a second, 120 s at most. Fails as "scene_never_started" when -// neither text, a choice, a battle nor control shows within 45 s: the -// player is not at the scene's trigger. +// holds a second, 120 s at most; a cutscene with no text and no HUD is +// waited out. Fails as "scene_never_started" when the HUD shows 45 s with +// no text, choice, battle or cutscene: the player is not at the scene's +// trigger. Outcome scene_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ SceneMachineConfig config; config.start_window = 45s; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp index 366c74d635..90b23155a0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -564,11 +564,9 @@ const RunCase RUN_CASES[] = { { // console B, 2026-11-13: 02.02 after the Brigitte battle walked // past the street scene's trigger and A-mashed for two minutes. - .name = "02.02's street scene fails when it never starts", - .input = {.checkpoint = "02.02", .first_step = 1, .steps = 1, .looks = { - look(/*events=*/{}, /*readings=*/{}, Milliseconds(0)), look(/*events=*/{}, /*readings=*/{}, Milliseconds(46000)), - }}, - .expectation = {.verdict = "failed at street_scene: scene_never_started", .inputs = "wait 500ms"}, + .name = "02.02's street scene fails when the party bar shows 45 s and it never starts", + .input = {.checkpoint = "02.02", .first_step = 1, .steps = 1, .looks = {party_bar(Milliseconds(0)), party_bar(Milliseconds(46000))}}, + .expectation = {.verdict = "failed at street_scene: scene_never_started", .inputs = "wait 250ms"}, }, { .name = "02.02 walks on to the gate's A prompt", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index d62ae74cab..a78939b5b4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -48,7 +48,8 @@ enum class SceneScreen{ HINT_SHOWING, // wait: the controls hint, not held a second yet TALK_PROMPT, // terminal: an A prompt ("A Talk") on the overworld, held a second, past min_length PROMPT_SHOWING, // wait, no press: the A prompt, not held a second or before min_length - NEVER_STARTED, // terminal, failing: no scene within start_window + AWAITING_SCENE, // wait, no press: with start_window, the HUD up and no scene yet + NEVER_STARTED, // terminal, failing: with start_window, the HUD up and no scene for that long QUIET_END, // terminal, failing unless quiet_is_control: nothing busy for the quiet time, past the minimum length BLIND_PRESS, // blind_button: nothing busy and no sign of control for blind_press_after (only talk_to_pokedex_screen's Pokedex screens) SCENE_MOVING, // wait, no press: no text, the screen changing @@ -104,7 +105,7 @@ class SceneTimeline{ std::optional m_party_bar_since; std::optional m_hint_since; std::optional m_prompt_since; - // Text, a choice or a battle has shown: the scene has started. + // A scene is under way or has been (scene_under_way()). bool m_scene_seen = false; // The looks in a row with the mission banner. size_t m_banner_looks = 0; @@ -180,6 +181,29 @@ bool scene_shows(const ScreenObservation& look){ return text_shows(look) || look.events.has(ScreenEvent::CHOICE_BOX) || look.events.has(ScreenEvent::BATTLE_STARTED); } +// The HUD the player has in control: the party bar, the controls hint or +// an A prompt. +bool hud_shows(const ScreenObservation& look){ + return look.events.has(ScreenEvent::PLAYER_CAN_MOVE) || look.readings.contains(CONTROLS_HINT_READING) || + look.events.has(ScreenEvent::INTERACT_PROMPT); +} + +// A scene is under way: text, a choice or a battle, or, with no HUD up, a +// fade or a moving screen. A cutscene can play a minute with no text: +// 02.02's street scene moved 41 s with no HUD after its black fade +// (console B, 2026-11-15). A step that plays a scene (start_window) does +// not end on the HUD before one is: the HUD up for start_window with no +// scene is the player away from its trigger. +bool scene_under_way(const ScreenObservation& look){ + if (scene_shows(look)){ + return true; + } + if (hud_shows(look)){ + return false; + } + return fade_shows(look) || !look.events.has(ScreenEvent::SCREEN_STILL); +} + // Whether the party bar and the A prompt are control for `config`: not in // a machine that stops at a choice or a battle, whose talk shows them // between its lines (and whose blind A may start that talk). @@ -200,7 +224,7 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::TALK_PROMPT, SceneScreen::PROMPT_SHOWING, - SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, + SceneScreen::AWAITING_SCENE, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, }; @@ -216,51 +240,35 @@ void track_since(bool shows, WallClock when, std::optional& since){ // "fade_black", the state's name in the log. std::string_view scene_screen_name(SceneScreen screen){ - switch (screen){ - case SceneScreen::BATTLE: - return "battle"; - case SceneScreen::FADE_BLACK: - return "fade_black"; - case SceneScreen::FADE_WHITE: - return "fade_white"; - case SceneScreen::CHOICE: - return "choice"; - case SceneScreen::DIALOG: - return "dialog"; - case SceneScreen::MISSION_COMPLETE: - return "mission_complete"; - case SceneScreen::TUTORIAL_CARD: - return "tutorial_card"; - case SceneScreen::MISSION_BANNER: - return "mission_banner"; - case SceneScreen::BANNER_SHOWING: - return "banner_showing"; - case SceneScreen::BANNER_PRESS: - return "banner_press"; - case SceneScreen::FADE_SETTLED: - return "fade_settled"; - case SceneScreen::CAN_MOVE: - return "can_move"; - case SceneScreen::PARTY_BAR: - return "party_bar"; - case SceneScreen::CONTROLS_HINT: - return "controls_hint"; - case SceneScreen::HINT_SHOWING: - return "hint_showing"; - case SceneScreen::TALK_PROMPT: - return "talk_prompt"; - case SceneScreen::PROMPT_SHOWING: - return "prompt_showing"; - case SceneScreen::NEVER_STARTED: - return "never_started"; - case SceneScreen::QUIET_END: - return "quiet_end"; - case SceneScreen::BLIND_PRESS: - return "blind_press"; - case SceneScreen::SCENE_MOVING: - return "scene_moving"; - case SceneScreen::SCENE_STILL: - return "scene_still"; + constexpr std::pair NAMES[] = { + {SceneScreen::BATTLE, "battle"}, + {SceneScreen::FADE_BLACK, "fade_black"}, + {SceneScreen::FADE_WHITE, "fade_white"}, + {SceneScreen::CHOICE, "choice"}, + {SceneScreen::DIALOG, "dialog"}, + {SceneScreen::MISSION_COMPLETE, "mission_complete"}, + {SceneScreen::TUTORIAL_CARD, "tutorial_card"}, + {SceneScreen::MISSION_BANNER, "mission_banner"}, + {SceneScreen::BANNER_SHOWING, "banner_showing"}, + {SceneScreen::BANNER_PRESS, "banner_press"}, + {SceneScreen::FADE_SETTLED, "fade_settled"}, + {SceneScreen::CAN_MOVE, "can_move"}, + {SceneScreen::PARTY_BAR, "party_bar"}, + {SceneScreen::CONTROLS_HINT, "controls_hint"}, + {SceneScreen::HINT_SHOWING, "hint_showing"}, + {SceneScreen::TALK_PROMPT, "talk_prompt"}, + {SceneScreen::PROMPT_SHOWING, "prompt_showing"}, + {SceneScreen::AWAITING_SCENE, "awaiting_scene"}, + {SceneScreen::NEVER_STARTED, "never_started"}, + {SceneScreen::QUIET_END, "quiet_end"}, + {SceneScreen::BLIND_PRESS, "blind_press"}, + {SceneScreen::SCENE_MOVING, "scene_moving"}, + {SceneScreen::SCENE_STILL, "scene_still"}, + }; + for (const auto& [state, name] : NAMES){ + if (state == screen){ + return name; + } } return "unknown"; } @@ -399,6 +407,10 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (fades_settled(look.when)){ return SceneScreen::FADE_SETTLED; } + if (m_config.start_window && !m_scene_seen && hud_shows(look)){ + const bool past_window = look.when - m_start >= *m_config.start_window; + return past_window ? SceneScreen::NEVER_STARTED : SceneScreen::AWAITING_SCENE; + } if (party_bar_is_control(m_config) && look.events.has(ScreenEvent::PLAYER_CAN_MOVE)){ if (m_party_bar_since && look.when - *m_party_bar_since >= PARTY_BAR_HOLD){ return SceneScreen::CAN_MOVE; @@ -417,9 +429,6 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ } return SceneScreen::PROMPT_SHOWING; } - if (m_config.start_window && !m_scene_seen && look.when - m_start >= *m_config.start_window){ - return SceneScreen::NEVER_STARTED; - } const std::optional due = quiet_end_due(); if (due && look.when >= *due){ return SceneScreen::QUIET_END; @@ -442,7 +451,7 @@ void SceneTimeline::record(const ScreenObservation& look){ if (busy(look)){ m_last_busy = look.when; } - m_scene_seen = m_scene_seen || scene_shows(look); + m_scene_seen = m_scene_seen || scene_under_way(look); const bool box = look.events.has(ScreenEvent::DIALOG_BOX); const bool party_bar = party_bar_is_control(m_config) && look.events.has(ScreenEvent::PLAYER_CAN_MOVE); track_since(party_bar && !box, look.when, m_party_bar_since); @@ -699,6 +708,7 @@ class SceneRunner{ case SceneScreen::PARTY_BAR: case SceneScreen::HINT_SHOWING: case SceneScreen::PROMPT_SHOWING: + case SceneScreen::AWAITING_SCENE: case SceneScreen::BANNER_SHOWING: m_backend.wait(POLL); return; @@ -761,6 +771,9 @@ Milliseconds max_still(SceneScreen screen){ case SceneScreen::PROMPT_SHOWING: // The overworld at the prompt can stay still until min_length. return SCENE_STILL_WAIT; + case SceneScreen::AWAITING_SCENE: + // The HUD can stay unchanged through start_window. + return SCENE_STILL_WAIT; case SceneScreen::PARTY_BAR: case SceneScreen::HINT_SHOWING: case SceneScreen::BANNER_SHOWING: @@ -810,7 +823,7 @@ Pokemon::Outcome scene_outcome( } if (result.terminal == scene_screen_name(SceneScreen::NEVER_STARTED)){ return Pokemon::outcome_failed("scene_never_started", std::format( - "{}: the scene never started (player not at its trigger?): no text, choice or battle in {} ms (expecting {}).", + "{}: the scene never started (player not at its trigger?): the HUD up and no text, choice, battle or cutscene for {} ms (expecting {}).", label, config.start_window ? config.start_window->count() : 0, expected )); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index e04a417d25..78b278cd01 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -73,10 +73,14 @@ struct SceneMachineConfig{ // rooms show no party bar or prompt (02.04-02.06, console B // 2026-11-10). bool quiet_is_control = false; - // Fails ("scene_never_started") when no text, choice or battle has - // shown this long after the start, and no sign of control either: the - // player is not at the scene's trigger (02.02 run after the Brigitte - // battle walked past the street scene's, console B 2026-11-13). + // The step plays a scene: the HUD (the party bar, the controls hint, + // an A prompt) ends it only once a scene is under way: text, a choice, + // a battle, or with no HUD a fade or a moving screen (a textless + // cutscene: 02.02's street scene, console B 2026-11-15). Fails + // ("scene_never_started") when the HUD shows this long after the start + // with no scene: the player is not at the scene's trigger (02.02 run + // after the Brigitte battle walked past the street scene's, console B + // 2026-11-13). std::optional start_window = std::nullopt; // Ends once this many black fades have been waited out and the screen // has then shown no text, fade or banner for 5 s (or on the controls @@ -107,7 +111,7 @@ struct SceneMachineConfig{ // the file log (log_detail()) except the black fades, the banner, the // hint and the end, which go on the overlay too (log()). Fails as "scene_quiet" on the // quiet end (unless `config.quiet_is_control`), "scene_never_started" -// past `config.start_window`, "scene_timeout" when `timeout` passes (by +// on the HUD past `config.start_window` with no scene, "scene_timeout" when `timeout` passes (by // the looks' time), and "scene_stuck" on a state that comes up too often // or a screen that stops changing. Pokemon::Outcome run_scene_machine( diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp index eb69ca6244..8f42fa569c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -572,15 +572,15 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .a_presses = 0, .states = "scene_moving, choice"}, }, { - .name = "no text, choice or battle within the start window: the scene never started", + .name = "the party bar up through the start window and no scene: the scene never started", .input = { - .looks = {look_at(0ms), look_at(10000ms, BLACK), look_at(44900ms, STILL), look_at(45000ms, STILL)}, + .looks = {look_at(0ms, PARTY), look_at(10000ms, PARTY), look_at(44900ms, PARTY), look_at(45000ms, PARTY)}, .config = scene_step_config(), }, .expectation = { .verdict = "failed: scene_never_started", .a_presses = 0, - .states = "scene_moving, fade_black, never_started", + .states = "awaiting_scene, never_started", }, }, { @@ -629,16 +629,30 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] done: quiet, taken as control."}, }, { - // console B, 2026-11-13: 02.02 after the Brigitte battle walked - // past the street scene's trigger and A-mashed for two minutes. - .name = "a scene step past its trigger fails as scene_never_started", - .input = {.looks = {look_at(0ms, BLACK), look_at(2000ms), look_at(46000ms)}, .config = scene_step_config()}, - .expectation = {.verdict = "failed: scene_never_started", .a_presses = 0}, + // console B, 2026-11-15: 02.02's street scene moved 41 s with no + // text and no HUD after its black fade. + .name = "a scene step's textless cutscene past the start window: the scene is under way, done on the party bar", + .input = { + .looks = { + look_at(0ms, BLACK), look_at(2000ms), look_at(46000ms), look_at(47000ms, PARTY), look_at(48100ms, PARTY), + }, + .config = scene_step_config(), + }, + .expectation = {.verdict = "done", .a_presses = 0, .line = "[PLZA test] done on can_move."}, }, { - .name = "a scene step whose scene played out before it ends on the party bar", - .input = {.looks = {look_at(0ms, PARTY), look_at(1000ms, PARTY)}, .config = scene_step_config()}, - .expectation = {.verdict = "done", .a_presses = 0, .line = "[PLZA test] done on can_move."}, + // console B, 2026-11-13: 02.02 after the Brigitte battle walked + // past the street scene's trigger and A-mashed for two minutes. + .name = "a scene step past its trigger, the controls hint up for the start window, fails as scene_never_started", + .input = { + .looks = { + look_at(/*at=*/0ms, NOTHING, {CONTROLS_HINT_READING}), + look_at(/*at=*/1500ms, NOTHING, {CONTROLS_HINT_READING}), + look_at(/*at=*/45000ms, NOTHING, {CONTROLS_HINT_READING}), + }, + .config = scene_step_config(), + }, + .expectation = {.verdict = "failed: scene_never_started", .a_presses = 0, .states = "awaiting_scene, never_started"}, }, { .name = "a minute with nothing going on fails as scene_quiet", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp index e748f17179..5a9301fd25 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneReplay_Tests.cpp @@ -69,6 +69,13 @@ SceneMachineConfig battle_area_config(){ return config; } +// A "scene" step's config (scene_step(): the scene must start within 45 s). +SceneMachineConfig scene_step_config(){ + SceneMachineConfig config; + config.start_window = 45000ms; + return config; +} + // 01.01 arrival_scenes, passed (console B 2026-11-15 21:29, Italian). constexpr std::string_view PASS_0101_IT_A = R"( @@ -456,6 +463,17 @@ screen 9: hint_showing at 12.9s: controls hint screen 10: controls_hint at 14.0s: controls hint )"; +// 02.02 street_scene, failed as scene_never_started (console B 2026-11-15 +// 23:23, English): a Pokemon with a red staff drives the trainers off in +// a cutscene with no text and no HUD for 41 s after the black fade. +constexpr std::string_view FAIL_0202_STREET_CUTSCENE = R"( +screen 1: fade_black at 0.0s: black fade, still, fade 1 +screen 2: scene_still at 3.8s: still +screen 3: scene_moving at 4.9s: nothing +scene_moving x61 over 30.5s, 0 presses +screen 4: never_started at 45.0s: nothing +)"; + // The looks of one screen in a scene machine's log: the state's events // and readings by their names in the log ("text box", "advance arrow"; // describe_look()). The fade count ("fade 1/3") is the machine's own. @@ -623,6 +641,19 @@ const ReplayCase REPLAY_CASES[] = { .input = {.looks = replay_log(PASS_0102_EN), .config = battle_area_config()}, .expectation = {.verdict = "done", .end = "[PLZA test] done on controls_hint."}, }, + { + // The run stopped at 45.0 s; the controls hint after the cutscene + // is synthetic (the run never got there). + .name = "02.02 street_scene, English, a textless cutscene past the start window, then the controls hint", + .input = { + .looks = replay_then(FAIL_0202_STREET_CUTSCENE, { + look_at(/*at=*/46000ms, /*events=*/{}, {CONTROLS_HINT_READING}), + look_at(/*at=*/47100ms, /*events=*/{}, {CONTROLS_HINT_READING}), + }), + .config = scene_step_config(), + }, + .expectation = {.verdict = "done", .end = "[PLZA test] done on controls_hint."}, + }, }; UnitTestResult check_replay(const ReplayCase& test, CancellableScope& scope){