From 24187dd7bb117adb06bfbcfe3218569a4d716f42 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 08:30:47 -0800 Subject: [PATCH 01/24] Switch system keyboard: detector, cursor reader and closed-loop typer Games open the Switch's own keyboard for names (BDSP, Legends: Z-A), and keyboard_enter_code() types on it blind from an assumed starting key. This adds SystemKeyboardDetector/Watcher, read_system_keyboard_cursor() (every key, including the right column and the bottom row), system_keyboard_field_has_text() and FastCodeEntry::type_on_system_keyboard(), which reads the cursor before each key, moves it along keyboard_get_path() (now declared in its header), and checks that each press reached the text field. Image tests for the detector and readers are in CommandLineTests under NintendoSwitch/SystemKeyboardDetector/. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../NintendoSwitch_SystemKeyboardDetector.cpp | 280 ++++++++++++++++++ .../NintendoSwitch_SystemKeyboardDetector.h | 99 +++++++ .../NintendoSwitch_KeyboardCodeEntry.h | 9 + .../NintendoSwitch_SystemKeyboardTyping.cpp | 249 ++++++++++++++++ .../NintendoSwitch_SystemKeyboardTyping.h | 56 ++++ SerialPrograms/cmake/SourceFiles.cmake | 4 + 7 files changed, 699 insertions(+) create mode 100644 SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp create mode 100644 SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h create mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp create mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index d2a39b8cba..93f8522bb6 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -27,6 +27,7 @@ #include "NintendoSwitch/Inference/NintendoSwitch_CheckOnlineDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_FailedToConnectDetector.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h" #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" @@ -72,6 +73,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ Pokemon::add_tests_AutoStorySelect(ret); NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); + NintendoSwitch::add_tests_SystemKeyboardDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); NintendoSwitch::Typewriter::add_tests_TypewriterTextMapping(ret); NintendoSwitch::PokemonBDSP::add_tests_DialogDetector(ret); diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp new file mode 100644 index 0000000000..b08bee33a4 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp @@ -0,0 +1,280 @@ +/* System Keyboard Detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "Tests/ImageUnitTest.h" +#include "NintendoSwitch_SystemKeyboardDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + +namespace{ + +// Centres of the five rows of keys, and of the first column and the spacing +// between columns, as fractions of the screen. +constexpr double KEY_ROW_Y[] = {0.500, 0.593, 0.681, 0.770, 0.858}; +constexpr double KEY_COL_X0 = 0.077; +constexpr double KEY_COL_STEP = 0.075; + +// In the right column, Return spans rows 1-2 and OK rows 3-4. These are the +// gaps between those keys. +constexpr double RIGHT_COLUMN_RETURN_TOP = 0.548; +constexpr double RIGHT_COLUMN_OK_TOP = 0.725; + +// The cursor border and everything else the reader looks at, from the top of the +// digit row to the bottom of the bottom row. +const ImageFloatBox KEYS_AREA(0.0, 0.43, 1.0, 0.49); + +// The cursor border pulses between bright cyan (about 50, 240, 220) and a darker +// teal (about 0, 185, 210), measured on Legends: Z-A. The blue of the OK button +// and of the ABC underline (40, 90, 250) is not green enough to match. +bool is_cursor_pixel(uint32_t pixel){ + const int red = (pixel >> 16) & 0xff; + const int green = (pixel >> 8) & 0xff; + const int blue = pixel & 0xff; + return red < 130 && green > 160 && blue > 170 && green - red > 60; +} + +uint8_t nearest_row(double y){ + uint8_t row = 0; + for (uint8_t r = 1; r < 5; r++){ + if (std::abs(KEY_ROW_Y[r] - y) < std::abs(KEY_ROW_Y[row] - y)){ + row = r; + } + } + return row; +} + +// The key whose cursor border has its centre at (x, y), or nothing if that is +// off the keyboard. +std::optional key_at(double x, double y){ + const long col = std::lround((x - KEY_COL_X0) / KEY_COL_STEP); + if (col < 0 || col > 11){ + return std::nullopt; + } + if (col < 11){ + return SystemKeyboardKey{nearest_row(y), (uint8_t)col}; + } + if (y < RIGHT_COLUMN_RETURN_TOP){ + return SystemKeyboardKey{0, 11}; + } + if (y < RIGHT_COLUMN_OK_TOP){ + return SystemKeyboardKey{1, 11}; + } + return SystemKeyboardKey{3, 11}; +} + +} // namespace + + + +SystemKeyboardDetector::SystemKeyboardDetector(Color color) + : m_color(color) + , m_key_panel_upper(0.15, 0.532, 0.65, 0.036) + , m_key_panel_lower(0.15, 0.715, 0.65, 0.032) + , m_bottom_bar(0.10, 0.935, 0.35, 0.030) + , m_ok_button(0.875, 0.760, 0.045, 0.020) +{} +void SystemKeyboardDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_key_panel_upper); + items.add(m_color, m_key_panel_lower); + items.add(m_color, m_bottom_bar); + items.add(m_color, m_ok_button); +} +bool SystemKeyboardDetector::detect(const ImageViewRGB32& screen){ + // Each strip crosses white keys and the slightly brighter gaps between them, + // which gives a stddev sum of about 11 (measured on BDSP and Legends: Z-A). + const double max_panel_stddev = 20; + const bool panel = + is_white(extract_box_reference(screen, m_key_panel_upper), 500, max_panel_stddev) || + is_white(extract_box_reference(screen, m_key_panel_lower), 500, max_panel_stddev); + if (!panel || !is_white(extract_box_reference(screen, m_bottom_bar))){ + return false; + } + // OK is blue (40, 93, 255), or flat grey (221, 221, 221) while the field is + // empty (disabled). Measured on BDSP and Legends: Z-A. + const ImageStats ok = image_stats(extract_box_reference(screen, m_ok_button)); + return is_solid(ok, {0.103, 0.240, 0.657}) || is_grey(ok, 600, 690); +} + + +std::optional read_system_keyboard_cursor(const ImageViewRGB32& screen){ + // The cursor is a cyan border around one key. Neighbouring keys overlap that border, + // so take the centroid of all cyan pixels and map it to the nearest key. + const ImageViewRGB32 keys = extract_box_reference(screen, KEYS_AREA); + double count = 0, sum_x = 0, sum_y = 0; + for (size_t y = 0; y < keys.height(); y++){ + for (size_t x = 0; x < keys.width(); x++){ + if (is_cursor_pixel(keys.pixel(x, y))){ + count++; + sum_x += (double)x; + sum_y += (double)y; + } + } + } + // The border is about 0.18% of the screen; a few stray pixels are not a cursor. + if (count < 0.0005 * screen.width() * screen.height()){ + return std::nullopt; + } + return key_at( + KEYS_AREA.x + sum_x / count / keys.width() * KEYS_AREA.width, + KEYS_AREA.y + sum_y / count / keys.height() * KEYS_AREA.height + ); +} + +bool system_keyboard_field_has_text(const ImageViewRGB32& screen){ + // Left part of the backspace key, clear of its icon and of the cursor border. + // Light grey (221) with an empty field, dark grey (52) with text. + const ImageStats stats = image_stats(extract_box_reference(screen, ImageFloatBox(0.878, 0.470, 0.008, 0.060))); + return stats.average.sum() < 400; +} + +size_t system_keyboard_text_pixels(const ImageViewRGB32& screen){ + // The field, above its underline, which is white in some games. + const ImageViewRGB32 field = extract_box_reference(screen, ImageFloatBox(0.03, 0.17, 0.87, 0.105)); + size_t count = 0; + for (size_t y = 0; y < field.height(); y++){ + for (size_t x = 0; x < field.width(); x++){ + const uint32_t pixel = field.pixel(x, y); + if (((pixel >> 16) & 0xff) > 190 && ((pixel >> 8) & 0xff) > 190 && (pixel & 0xff) > 190){ + count++; + } + } + } + return count; +} + + + +namespace{ + +// One screenshot and what each function should read from it. +class Test_SystemKeyboardDetector : public ImageUnitTest{ +public: + // `cursor`: the key under the cursor, or nothing for a screen without the keyboard. + Test_SystemKeyboardDetector(const std::string& image, std::optional cursor, bool has_text) + : ImageUnitTest(std::format("NintendoSwitch::SystemKeyboardDetector - {}", image), {image}) + , m_cursor(cursor) + , m_has_text(has_text) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + const ImageRGB32& image = images[0]; + const bool keyboard = SystemKeyboardDetector().detect(image); + if (keyboard != m_cursor.has_value()){ + return std::format("detect() returned {}.", keyboard); + } + if (!keyboard){ + return true; + } + const std::optional cursor = read_system_keyboard_cursor(image); + if (cursor != m_cursor){ + return cursor + ? std::format("Read the cursor at ({}, {}).", cursor->row, cursor->col) + : std::format("Read no cursor."); + } + const bool has_text = system_keyboard_field_has_text(image); + if (has_text != m_has_text){ + return std::format("system_keyboard_field_has_text() returned {}.", has_text); + } + // An empty field has no white text pixels; one typed character has many. + const size_t text_pixels = system_keyboard_text_pixels(image); + if ((text_pixels >= 20) != m_has_text){ + return std::format("system_keyboard_text_pixels() returned {}.", text_pixels); + } + return true; + } + +private: + std::optional m_cursor; + bool m_has_text; +}; + +std::string test_image_path(std::string_view image){ + return std::format("NintendoSwitch/SystemKeyboardDetector/{}", image); +} + +// The cursor on keys other than "1". +void add_cursor_tests(UnitTestDatabase& database){ + // Legends: Z-A, English and Spanish prompts. The + // border pulses between bright cyan and a darker teal; T, / and ! are dark. + const std::pair cursors[] = { + {"PLZA-Cursor-T.png", {1, 4}}, + {"PLZA-Cursor-Slash.png", {1, 10}}, + {"PLZA-Cursor-Exclamation.png", {3, 10}}, + {"PLZA-Cursor-0.png", {0, 9}}, + {"PLZA-Cursor-Minus.png", {0, 10}}, + {"PLZA-Cursor-Backspace.png", {0, 11}}, + {"PLZA-Cursor-Return.png", {1, 11}}, + {"PLZA-Cursor-OK.png", {3, 11}}, + {"PLZA-Cursor-Globe.png", {4, 0}}, + {"PLZA-Cursor-NTilde.png", {4, 5}}, + {"PLZA-Cursor-Space.png", {4, 8}}, + }; + for (const auto& [image, cursor] : cursors){ + database.add(test_image_path(image), cursor, false); + } +} + +// Tests whose screen is not captured yet. +void add_planned_tests(UnitTestDatabase& database){ + const SystemKeyboardKey key_1{0, 0}; + // Screens still to be captured: AZERTY needs a console whose system language + // uses it (the layout follows the system, not the game). Each test is added + // once its image is in the test repo. + struct Planned{ + std::string_view image; + std::optional cursor; + bool has_text; + }; + const Planned planned[] = { + {"AZERTY-Empty.png", key_1, false}, + {"PLZA-Korean.png", std::nullopt, false}, + }; + for (const Planned& test : planned){ + const std::string image = test_image_path(test.image); + if (Filesystem::exists(std::format("{}{}", UNIT_TEST_RESOURCE_PATH(), image))){ + database.add(image, test.cursor, test.has_text); + } + } +} + +} // namespace + + +void add_tests_SystemKeyboardDetector(UnitTestDatabase& database){ + const SystemKeyboardKey key_1{0, 0}; + // The OK button is blue with text in the field and grey without. + database.add(test_image_path("BDSP-PlayerName-Empty.png"), key_1, false); + database.add(test_image_path("BDSP-FriendName-Typed.png"), key_1, true); + for (std::string_view language : {"English", "French", "German", "Italian", "Japanese", "Spanish"}){ + database.add(test_image_path(std::format("PLZA-{}-Empty.png", language)), key_1, false); + } + for (std::string_view image : {"BDSP-Dialog.png", "HomeMenu.png", "HomeMenu-OnlineLicensePopup.png", "UserSelect.png"}){ + database.add(test_image_path(image), std::nullopt, false); + } + add_cursor_tests(database); + add_planned_tests(database); +} + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h new file mode 100644 index 0000000000..3a5bbf7f03 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h @@ -0,0 +1,99 @@ +/* System Keyboard Detector + * + * From: https://github.com/PokemonAutomation/ + * + * The Switch's own on-screen keyboard, which games open for names (e.g. the + * player's name in BDSP and in Legends: Z-A): detect it, read the key under its + * cursor, and tell whether its text field is empty. Typing with it is in + * Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h. + * + * Supported: the Latin keyboard (QWERTY; AZERTY shares the key grid but has no + * test screenshot yet). Its layout follows the console's system language, not + * the game's. Measured on 1920x1080 Switch 1 captures of BDSP's and Legends: + * Z-A's name entry, the latter with the game in English, Spanish, German, + * Italian, French and Japanese (all QWERTY on an English console). Not + * supported: the Korean keyboard, whose candidate strip + * moves the keys down (the detector returns false on it), and probably the + * Chinese ones (not tested). Switch 2 is not tested. + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_SystemKeyboardDetector_H +#define PokemonAutomation_NintendoSwitch_SystemKeyboardDetector_H + +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +// The white key panel, the white bar below it, and the OK button (blue, or grey +// while the field is empty). Works wherever the cursor is. +class SystemKeyboardDetector : public StaticScreenDetector{ +public: + SystemKeyboardDetector(Color color = COLOR_CYAN); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + // Two strips across the key panel, one over the gap between rows 0 and 1 and + // one over the gap between rows 2 and 3. The cursor's border reaches into at + // most one of them, so the panel is white if either is. + ImageFloatBox m_key_panel_upper; + ImageFloatBox m_key_panel_lower; + ImageFloatBox m_bottom_bar; + ImageFloatBox m_ok_button; +}; + +// Finds SystemKeyboardDetector on the video, checking every 250 ms. +class SystemKeyboardWatcher : public DetectorToFinder{ +public: + SystemKeyboardWatcher(Color color = COLOR_CYAN) + : DetectorToFinder("SystemKeyboardWatcher", std::chrono::milliseconds(250), color) + {} +}; + + +// A key of the keyboard. +// Rows 0-3 are the character rows (0: digits .. 3: "zxcv"), row 4 is the bottom +// row (globe, Shift, ABC, #+=, the accent pages and Space). +// Columns 0-10 are the character columns. Column 11 is the right column, whose +// keys are taller: backspace is (0, 11), Return (1, 11) and OK (3, 11). +// A row-4 key reports the character column nearest its centre (Space: 8). +struct SystemKeyboardKey{ + uint8_t row; + uint8_t col; + + bool operator==(const SystemKeyboardKey&) const = default; +}; + +// The key under the cursor, or nothing if no cursor border is visible. +// The keyboard remembers the cursor between uses, so read it, don't assume it. +std::optional read_system_keyboard_cursor(const ImageViewRGB32& screen); + +// Whether the text field holds any text: the backspace key is dark then and light +// grey while the field is empty. Pressing B on an empty field closes the +// keyboard, so delete only while this is true. +bool system_keyboard_field_has_text(const ImageViewRGB32& screen); + +// The number of white pixels in the text field. Each typed character adds some +// (a "1" adds about 110 at 1920x1080), so comparing two counts tells whether a +// key press reached the field. +size_t system_keyboard_text_pixels(const ImageViewRGB32& screen); + + + +// Register the tests of this file. +void add_tests_SystemKeyboardDetector(UnitTestDatabase& database); + + + +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h index 7048582ea0..1aa290cdc1 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h @@ -8,10 +8,12 @@ #define PokemonAutomation_NintendoSwitch_KeyboardCodeEntry_H #include +#include #include "Controllers/StandardHid/StandardHid_Keyboard.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardEntryMappings.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -19,6 +21,13 @@ namespace FastCodeEntry{ +// The D-pad moves from "source" to "destination" on the on-screen keyboard, +// wrapping around the sides when that is shorter, then ENTER_CHAR. +std::vector keyboard_get_path( + KeyboardEntryPosition source, + KeyboardEntryPosition destination +); + // Automatically select between keyboard or pro controller depending on the // controller type. void keyboard_enter_code( diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp new file mode 100644 index 0000000000..511e36ecad --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp @@ -0,0 +1,249 @@ +/* System Keyboard Typing + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/NintendoSwitch_Settings.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_CodeEntryTools.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" +#include "NintendoSwitch_SystemKeyboardTyping.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace FastCodeEntry{ + +using namespace std::chrono_literals; + + +namespace{ + +// Waits after each press. They are longer than the code entry delays because +// the next step reads the screen: the cursor animation and the capture latency +// must be over first. +constexpr Milliseconds MOVE_RELEASE = 200ms; +constexpr Milliseconds WRAP_RELEASE = 400ms; // Wrapping around a side animates for longer. +constexpr Milliseconds SETTLE = 300ms; // Before reading the cursor after moving it. +constexpr Milliseconds SHIFT_RELEASE = 250ms; +constexpr Milliseconds KEY_RELEASE = 300ms; + +// A press made while the keyboard is still sliding in is ignored, so the +// cursor is read again after each try until it is on the target. +constexpr size_t MAX_MOVE_TRIES = 10; + +// Reads of the text field after a key press, SETTLE apart, before giving up. +constexpr size_t MAX_FIELD_READS = 3; + +// The fewest white pixels a typed character adds to the field ("." or "'"). +constexpr size_t MIN_CHARACTER_PIXELS = 10; + + +// The key of each character of `text`. Throws UserSetupError, listing every +// character that has no key, before anything is typed. +std::vector text_keys(Logger& logger, const std::string& text, KeyboardLayout layout){ + const std::map& positions = KEYBOARD_POSITIONS(layout); + std::vector keys; + std::string missing; + for (char ch : text){ + // Letters are listed under their uppercase key. + auto iter = positions.find((char)std::toupper((unsigned char)ch)); + if (iter == positions.end()){ + missing += ch; + }else{ + keys.emplace_back(iter->second); + } + } + if (!missing.empty()){ + throw UserSetupError( + logger, + std::format("System keyboard: \"{}\" has characters with no key on the keyboard: \"{}\".", text, missing) + ); + } + return keys; +} + +// How long to hold each button: the hold of the code entry timings for Switch 1. +Milliseconds button_hold(ProControllerContext& context){ + const ConsoleSettings& settings = ConsoleSettings::instance(); + const CodeEntryDelays delays = context->performance_class() == ControllerPerformanceClass::SerialPABotBase_Wired + ? CodeEntryDelays(settings.CODEBOARD_ENTRY_SWITCH1_WIRED) + : CodeEntryDelays(settings.CODEBOARD_ENTRY_SWITCH1_WIRELESS); + return delays.hold; +} + +// The D-pad direction of a move. +DpadPosition move_direction(CodeEntryAction action){ + switch (action){ + case CodeEntryAction::NORM_MOVE_UP: + case CodeEntryAction::WRAP_MOVE_UP: + return DpadPosition::DPAD_UP; + case CodeEntryAction::NORM_MOVE_RIGHT: + case CodeEntryAction::WRAP_MOVE_RIGHT: + return DpadPosition::DPAD_RIGHT; + case CodeEntryAction::NORM_MOVE_DOWN: + case CodeEntryAction::WRAP_MOVE_DOWN: + return DpadPosition::DPAD_DOWN; + case CodeEntryAction::NORM_MOVE_LEFT: + case CodeEntryAction::WRAP_MOVE_LEFT: + return DpadPosition::DPAD_LEFT; + default: + return DpadPosition::DPAD_NONE; + } +} + +// The moves toward `target`. Off the character grid (the right column or the +// bottom row), one step back onto it, after which the cursor is read again. +std::vector path_toward(SystemKeyboardKey cursor, KeyboardEntryPosition target){ + if (cursor.col == 11){ + return {CodeEntryAction::NORM_MOVE_LEFT}; + } + if (cursor.row == 4){ + return {CodeEntryAction::NORM_MOVE_UP}; + } + std::vector path = keyboard_get_path({cursor.row, cursor.col}, target); + std::erase_if(path, [](CodeEntryAction action){ return !is_move(action); }); + return path; +} + +// The moves as letters for the log, e.g. "DLL" or "R*" for a wrap to the right. +std::string path_to_string(const std::vector& path){ + std::string ret; + for (CodeEntryAction action : path){ + switch (move_direction(action)){ + case DpadPosition::DPAD_UP: + ret += 'U'; + break; + case DpadPosition::DPAD_RIGHT: + ret += 'R'; + break; + case DpadPosition::DPAD_DOWN: + ret += 'D'; + break; + case DpadPosition::DPAD_LEFT: + ret += 'L'; + break; + default: + ret += '?'; + break; + } + if (is_wrap(action)){ + ret += '*'; + } + } + return ret; +} + +std::optional read_cursor(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot screen = stream.video().snapshot(); + if (!screen){ + return std::nullopt; + } + return read_system_keyboard_cursor(screen); +} + +[[noreturn]] void throw_cursor_failure( + VideoStream& stream, + std::optional last, KeyboardEntryPosition target, char ch +){ + std::string message = last + ? std::format("the cursor is at ({}, {}), not on '{}' at ({}, {})", last->row, last->col, ch, target.row, target.col) + : std::format("the cursor could not be read while moving to '{}' at ({}, {})", ch, target.row, target.col); + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("System keyboard: {}, after {} tries.", message, MAX_MOVE_TRIES), + stream + ); +} + +void move_cursor( + VideoStream& stream, ProControllerContext& context, Milliseconds hold, + KeyboardEntryPosition target, char ch +){ + std::optional last; + for (size_t attempt = 0; attempt < MAX_MOVE_TRIES; attempt++){ + const std::optional cursor = read_cursor(stream, context); + if (!cursor){ + stream.logger().log(std::format("System keyboard: no cursor seen, try {}.", attempt + 1)); + pbf_wait(context, SETTLE); + continue; + } + last = cursor; + if (cursor->row == target.row && cursor->col == target.col){ + return; + } + const std::vector path = path_toward(*cursor, target); + stream.logger().log(std::format( + "System keyboard: cursor ({}, {}) -> '{}' ({}, {}): {}, try {}.", + cursor->row, cursor->col, ch, target.row, target.col, path_to_string(path), attempt + 1 + )); + for (CodeEntryAction action : path){ + pbf_press_dpad(context, move_direction(action), hold, is_wrap(action) ? WRAP_RELEASE : MOVE_RELEASE); + } + pbf_wait(context, SETTLE); + } + throw_cursor_failure(stream, last, target, ch); +} + +size_t read_text_pixels(VideoStream& stream, ProControllerContext& context){ + context.wait_for_all_requests(); + VideoSnapshot screen = stream.video().snapshot(); + return screen ? system_keyboard_text_pixels(screen) : 0; +} + +// Types `ch` with the cursor on its key, and checks that the text field grew. +void press_key(VideoStream& stream, ProControllerContext& context, Milliseconds hold, char ch){ + const size_t before = read_text_pixels(stream, context); + if (std::isupper((unsigned char)ch)){ + pbf_press_button(context, BUTTON_LCLICK, hold, SHIFT_RELEASE); + } + pbf_press_button(context, BUTTON_A, hold, KEY_RELEASE); + size_t after = 0; + for (size_t read = 0; read < MAX_FIELD_READS; read++){ + after = read_text_pixels(stream, context); + if (after >= before + MIN_CHARACTER_PIXELS){ + return; + } + pbf_wait(context, SETTLE); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("System keyboard: pressed '{}', but the text field did not change ({} -> {} white pixels).", ch, before, after), + stream + ); +} + +} // namespace + + + +void type_on_system_keyboard( + VideoStream& stream, ProControllerContext& context, + const std::string& text, + KeyboardLayout layout +){ + const std::vector keys = text_keys(stream.logger(), text, layout); + const Milliseconds hold = button_hold(context); + for (size_t c = 0; c < text.size(); c++){ + move_cursor(stream, context, hold, keys[c], text[c]); + press_key(stream, context, hold, text[c]); + } + context.wait_for_all_requests(); +} + + + +} // namespace FastCodeEntry +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h new file mode 100644 index 0000000000..3d2e2dcc2f --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h @@ -0,0 +1,56 @@ +/* System Keyboard Typing + * + * From: https://github.com/PokemonAutomation/ + * + * Types text on the Switch's on-screen keyboard with a Pro Controller, reading + * the cursor from the video before each key. Unlike keyboard_enter_code(), + * which moves blind from an assumed starting key, it starts wherever the + * keyboard left its cursor and corrects moves the keyboard ignored. + * + * Supported keyboards are those of NintendoSwitch_SystemKeyboardDetector.h: the + * Latin keyboard, QWERTY or AZERTY. Console-tested on Switch 1 (2026-11-13): + * the player's name in Legends: Z-A with the game in English, Spanish, German, + * Italian, French and Japanese (QWERTY, English system language), and earlier + * the player's and rival's names in BDSP. AZERTY is not tested. Not + * supported: the Korean and Chinese keyboards. Switch 2 is not tested. + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_SystemKeyboardTyping_H +#define PokemonAutomation_NintendoSwitch_SystemKeyboardTyping_H + +#include +#include "CommonFramework/Tools/VideoStream.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardEntryMappings.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace FastCodeEntry{ + + +// Types `text` on the open keyboard: letters, digits and the symbols on the +// keyboard's first page. An uppercase letter is typed with Shift (left stick +// click), which assumes the keyboard opened with Shift off, as BDSP's and +// Legends: Z-A's do. +// +// Before the first press, throws UserSetupError if `text` has a character with +// no key. While typing, throws OperationFailedException, with a screenshot, if +// the cursor can't be read or doesn't reach a key, or if a key press doesn't +// add to the text field. The check counts the field's white pixels, so it +// catches a dropped press but not a wrong case. +// +// Presses are held for the "Fast Code Entry Timings" hold of Switch 1 with the +// controller's connection type, as keyboard_enter_code() does. The waits after +// them are fixed, since each move is read back from the video. +void type_on_system_keyboard( + VideoStream& stream, ProControllerContext& context, + const std::string& text, + KeyboardLayout layout = KeyboardLayout::QWERTY +); + + +} // namespace FastCodeEntry +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 03a76d8719..8101a46d7a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1358,6 +1358,8 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Inference/NintendoSwitch_SelectedSettingDetector.h Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.cpp Source/NintendoSwitch/Inference/NintendoSwitch_StartGameUserSelectDetector.h + Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.cpp + Source/NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.cpp Source/NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h Source/NintendoSwitch/NintendoSwitch_ConsoleHandle.cpp @@ -1409,6 +1411,8 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.cpp Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_NumberCodeEntry.h + Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.cpp + Source/NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.cpp Source/NintendoSwitch/Programs/NintendoSwitch_FriendCodeAdder.h Source/NintendoSwitch/Programs/NintendoSwitch_FriendDelete.cpp From 0053160dd237c920236a8584b5e04260bfdee6f6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 20:05:58 -0800 Subject: [PATCH 02/24] PLZA AutoStory 01.00: start the new game from HOME or the language list 01.00 gains a first step, new_game_intro: from the Switch HOME (game closed, no save) it launches the selected tile and waits out the screens before the language list (no press for 30 s, then at most 5 A presses), picks the panel's language on the list, the look on the picker (stick) and types the name on the Switch keyboard (D-pad on a model of its key grid, Shift for capitals, PLUS for OK) after reading its 0/N counter. On Confirm Choices it presses nothing. The confirm step now also reads the name and language Confirm Choices shows (OCR) and stops if they differ. New panel options: game language (10; Korean refused as not supported), player look 1-8, player name (Kosmos), and a developer capture mode that saves each language's screens from the launch to the keyboard. Name limits from the console's keyboard frames: 12 for es-ES, es-419, fr, de, it (en taken as 12, no frame); 6 for ja, ko, zh-Hans, zh-Hant. Test frames: dayfine/CommandLineTests plza/new-game-intro 36d2d9cc3. --- .../workflows/cpp-ci-serial-programs-base.yml | 5 +- .../PokemonLZA/PokemonLZA_Tests.cpp | 4 + .../PokemonLZA_AutoStoryConfirmChoices.cpp | 41 +- .../PokemonLZA_AutoStoryConfirmChoices.h | 21 +- .../Actions/PokemonLZA_AutoStoryNameKeys.cpp | 101 +++++ .../Actions/PokemonLZA_AutoStoryNameKeys.h | 46 ++ .../Actions/PokemonLZA_AutoStoryNewGame.cpp | 400 ++++++++++++++++++ .../Actions/PokemonLZA_AutoStoryNewGame.h | 92 ++++ .../PokemonLZA_AutoStoryNewGameChoices.cpp | 117 +++++ .../PokemonLZA_AutoStoryNewGameChoices.h | 106 +++++ .../PokemonLZA_AutoStoryNewGame_Tests.cpp | 377 +++++++++++++++++ .../PokemonLZA_AutoStoryNewGame_Tests.h | 27 ++ .../PokemonLZA_AutoStoryIntroScreens.cpp | 344 +++++++++++++++ .../PokemonLZA_AutoStoryIntroScreens.h | 63 +++ ...PokemonLZA_AutoStoryIntroScreens_Tests.cpp | 150 +++++++ .../PokemonLZA_AutoStoryIntroScreens_Tests.h | 27 ++ .../AutoStory/PokemonLZA_AutoStory.cpp | 70 ++- .../Programs/AutoStory/PokemonLZA_AutoStory.h | 7 + .../AutoStory/PokemonLZA_AutoStoryBackend.h | 3 + .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 32 +- .../AutoStory/PokemonLZA_AutoStoryGame.h | 7 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 15 +- .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 2 +- .../AutoStory/PokemonLZA_AutoStoryTable.h | 6 +- .../AutoStory/StoryData/plza-01.00.plan.json | 10 +- SerialPrograms/cmake/SourceFiles.cmake | 12 + 26 files changed, 2042 insertions(+), 43 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 289cc28931..169e0461b9 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). + # the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language), + # and the new game's language list and name keyboard (branch plza/new-game-intro). repository: 'dayfine/CommandLineTests' - ref: '2abde09b6bfdf9ae1b372b04c0e6265dc8559556' + ref: '36d2d9cc3a9f82058d02e656184e9fde5e87113b' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 8f8d2e9c6e..c2c9e67e3e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -25,8 +25,10 @@ #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector_Tests.h" +#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.h" @@ -58,6 +60,8 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStoryConfirmChoicesReader(database); add_tests_AutoStoryCaughtMarkReader(database); add_tests_AutoStoryDialogDetector(database); + add_tests_AutoStoryIntroScreens(database); + add_tests_AutoStoryNewGame(database); add_tests_AutoStoryGame(database); add_tests_AutoStoryLines(database); add_tests_AutoStoryObjectiveMarkerReader(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp index 7baab9c8f5..e1cbe67eae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp @@ -11,8 +11,10 @@ #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/OCR/OCR_Routines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryConfirmChoices.h" namespace PokemonAutomation{ @@ -43,6 +45,38 @@ std::optional read_confirm_choices_now( } } +// Fails, having pressed nothing, unless "Confirm Choices" shows the name +// and the language of `choices`. +void check_profile(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (!frame){ + return; + } + const std::string name = read_confirm_choices_name(frame); + if (name != choices.name){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: Confirm Choices shows the name \"{}\", not \"{}\". Nothing was confirmed.", name, choices.name), + console + ); + } + const NewGameLanguageInfo& info = new_game_language_info(choices.language); + if (!OCR::ocr_language_available(info.ocr_language)){ + console.log(std::format("AutoStory intro: Confirm Choices: no OCR for {}; its language is not checked.", info.tag)); + return; + } + const std::string language = read_confirm_choices_language(frame, info.ocr_language); + if (language.find(info.confirm_text) == std::string::npos){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: Confirm Choices shows the language \"{}\", not {}. Nothing was confirmed.", language, info.tag), + console + ); + } + console.log(std::format("AutoStory intro: Confirm Choices shows \"{}\" in {}.", name, info.tag)); +} + } // namespace @@ -51,16 +85,17 @@ size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& con if (!cursor){ throw UserSetupError( console, - "AutoStory: 01.00 starts on the new game's \"Confirm Choices\" screen, with the language, look and name " - "already chosen by hand. It is not on screen; nothing was pressed." + "AutoStory: 01.00's confirm step needs the new game's \"Confirm Choices\" screen, after the language, look " + "and name. It is not on screen; nothing was pressed." ); } console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); return *cursor; } -void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ std::optional cursor = require_confirm_choices(console, context); + check_profile(console, context, choices); for (size_t press = 0; press < 6 && cursor; press++){ if (*cursor == CONFIRM_CHOICES_READY_ROW){ console.log("AutoStory intro: Confirm Choices: A on \"Ready!\"."); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h index e9c40d6812..ca01ea911e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h @@ -2,8 +2,8 @@ * * From: https://github.com/PokemonAutomation/ * - * 01.00's start: the new game's "Confirm Choices" screen, after the - * language, look and name were chosen by hand. Its reader is in + * The new game's "Confirm Choices" screen, after the language, look and + * name (PokemonLZA_AutoStoryNewGame.h). Its reader is in * Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h. * */ @@ -14,6 +14,7 @@ #include #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -24,14 +25,16 @@ namespace PokemonLZA{ // 2 s with no press. Throws UserSetupError if the screen does not show. size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context); -// 01.00's first step: the new game's language, look and name were chosen -// by hand and "Confirm Choices" is on screen. Checks that screen first -// (require_confirm_choices()): on any other screen throws UserSetupError -// and presses nothing. Then moves the highlight to "Ready!" one DOWN at a -// time, reading it after each, and presses A there: the save's only -// change is this press, on a screen it has read. Throws +// 01.00's step after the intro: "Confirm Choices" is on screen. Checks +// that screen first (require_confirm_choices()): on any other screen +// throws UserSetupError and presses nothing. Then reads the name and the +// language it shows (OCR) and, if either is not `choices`', throws +// OperationFailedException having pressed nothing (the language is not +// checked when its OCR is not installed). Then moves the highlight to +// "Ready!" one DOWN at a time, reading it after each, and presses A there: +// the save's only change is this press, on a screen it has read. Throws // OperationFailedException if the highlight is lost on the way. -void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context); +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp new file mode 100644 index 0000000000..a08eb7ba6f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp @@ -0,0 +1,101 @@ +/* PokemonLZA AutoStory - Name keys + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonLZA_AutoStoryNameKeys.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The first page's character rows, as the header draws them. +constexpr std::string_view KEY_ROWS[] = { + "1234567890-", + "qwertyuiop/", + "asdfghjkl:'", + "zxcvbnm,.?!", +}; +constexpr size_t BOTTOM_ROW = 4; + +// Simplified Chinese's "English" mode key: the bottom row's fourth key, +// under "4". +constexpr size_t ENGLISH_MODE_COLUMN = 3; + +struct KeyPosition{ + size_t row = 0; + size_t col = 0; +}; + +std::optional key_position(char lower){ + for (size_t row = 0; row < std::size(KEY_ROWS); row++){ + const size_t col = KEY_ROWS[row].find(lower); + if (col != std::string_view::npos){ + return KeyPosition{.row = row, .col = col}; + } + } + return std::nullopt; +} + +// Across, then up or down; but up first off the bottom row, whose keys +// are wider than a column: "English" is the fourth key along it, and the +// key above it is "4" (the frames). +void move_to(std::vector& presses, KeyPosition& cursor, KeyPosition target){ + for (; cursor.row == BOTTOM_ROW && cursor.row > target.row; cursor.row--){ + presses.push_back(IntroKey::UP); + } + for (; cursor.col < target.col; cursor.col++){ + presses.push_back(IntroKey::RIGHT); + } + for (; cursor.col > target.col; cursor.col--){ + presses.push_back(IntroKey::LEFT); + } + for (; cursor.row < target.row; cursor.row++){ + presses.push_back(IntroKey::DOWN); + } + for (; cursor.row > target.row; cursor.row--){ + presses.push_back(IntroKey::UP); + } +} + +} // namespace + + +std::optional> name_key_presses(std::string_view name, NewGameLanguage language){ + if (name.empty()){ + return std::nullopt; + } + std::vector presses; + KeyPosition cursor; + if (language == NewGameLanguage::ChineseSimplified){ + move_to(presses, cursor, KeyPosition{.row = BOTTOM_ROW, .col = 0}); + move_to(presses, cursor, KeyPosition{.row = BOTTOM_ROW, .col = ENGLISH_MODE_COLUMN}); + presses.push_back(IntroKey::A); + } + for (const char ch : name){ + const unsigned char byte = (unsigned char)ch; + const std::optional target = key_position((char)std::tolower(byte)); + if (byte >= 0x80 || !target){ + return std::nullopt; + } + move_to(presses, cursor, *target); + if (std::isupper(byte)){ + presses.push_back(IntroKey::SHIFT); + } + presses.push_back(IntroKey::A); + } + presses.push_back(IntroKey::PLUS); + return presses; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h new file mode 100644 index 0000000000..422332786a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h @@ -0,0 +1,46 @@ +/* PokemonLZA AutoStory - Name keys + * + * From: https://github.com/PokemonAutomation/ + * + * The player's name as presses on the Switch's name keyboard, a pure + * function on a model of its key grid (the console's frames in nine + * languages, 2026-11-13). Its first page has four rows of 11 keys: + * + * 1 2 3 4 5 6 7 8 9 0 - + * q w e r t y u i o p / + * a s d f g h j k l : ' + * z x c v b n m , . ? ! + * + * and a bottom row (globe, Shift, the keyboard's modes, Space). The cursor + * starts on "1". Letters type lower case; Shift (a left stick click) makes + * the next letter a capital. Simplified Chinese opens in Pinyin mode: its + * bottom row's fourth key ("English") switches to letters first. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNameKeys_H +#define PokemonAutomation_PokemonLZA_AutoStoryNameKeys_H + +#include +#include +#include +#include "PokemonLZA_AutoStoryNewGameChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The presses that type `name` on the keyboard of `language` and press OK +// (PLUS): per character D-pad moves from the last key (across, then up or +// down; never round an edge), SHIFT before a capital, then A. Nullopt for +// an empty name or a character with no key on the first page (a space +// included). +std::optional> name_key_presses(std::string_view name, NewGameLanguage language); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp new file mode 100644 index 0000000000..ca2cb631fb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp @@ -0,0 +1,400 @@ +/* PokemonLZA AutoStory - New game + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "CommonFramework/ImageTools/ImageDiff.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" +#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryNameKeys.h" +#include "PokemonLZA_AutoStoryNewGame.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +using FrameCheck = std::function; + +constexpr std::string_view DUMP_FOLDER = "PokemonLZA/AutoStory/Intro"; + +// From the launch to the language list (the boot, logos, prompts): no +// press for LAUNCH_QUIET, then A at most LAUNCH_A_PRESSES times, +// LAUNCH_A_EVERY apart, on any screen that is not the list, until +// LAUNCH_LIMIT. With no save the game goes straight to the list (the +// console, 2026-11-09); the A presses are for a prompt in between. +constexpr Milliseconds LAUNCH_QUIET = 30000ms; +constexpr Milliseconds LAUNCH_A_EVERY = 6000ms; +constexpr size_t LAUNCH_A_PRESSES = 5; +constexpr Milliseconds LAUNCH_LIMIT = 90000ms; + +// Capture mode: a frame this far (pixel RMSD) from the last saved one is +// a new screen. +constexpr double CAPTURE_CHANGE = 4; +constexpr Milliseconds CAPTURE_EVERY = 1000ms; + +VideoSnapshot snapshot(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + return console.video().snapshot(); +} + +// Until `check` holds on a frame, up to `timeout`, reading every 250 ms. +bool wait_for_frame(ConsoleHandle& console, ProControllerContext& context, const FrameCheck& check, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + while (true){ + const VideoSnapshot frame = snapshot(console, context); + if (frame && check(frame)){ + return true; + } + if (current_time() >= deadline){ + return false; + } + context.wait_for(250ms); + } +} + +[[noreturn]] void fail(ConsoleHandle& console, const std::string& message){ + OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, std::format("AutoStory intro: {}", message), console); +} + +void press(ConsoleHandle& console, ProControllerContext& context, IntroKey key, Milliseconds release){ + switch (key){ + case IntroKey::UP: + pbf_press_dpad(context, DPAD_UP, /*hold=*/80ms, release); + break; + case IntroKey::DOWN: + pbf_press_dpad(context, DPAD_DOWN, /*hold=*/80ms, release); + break; + case IntroKey::LEFT: + pbf_press_dpad(context, DPAD_LEFT, /*hold=*/80ms, release); + break; + case IntroKey::RIGHT: + pbf_press_dpad(context, DPAD_RIGHT, /*hold=*/80ms, release); + break; + case IntroKey::A: + pbf_press_button(context, BUTTON_A, /*hold=*/80ms, release); + break; + case IntroKey::SHIFT: + pbf_press_button(context, BUTTON_LCLICK, /*hold=*/80ms, release); + break; + case IntroKey::PLUS: + console.log("AutoStory intro: keyboard: PLUS (OK)."); + pbf_press_button(context, BUTTON_PLUS, /*hold=*/80ms, release); + break; + } +} + +// The look picker's presses are left stick tilts (it says "Use the Left +// Stick"; the D-pad does not move it). +void tilt(ProControllerContext& context, IntroKey key){ + switch (key){ + case IntroKey::UP: + pbf_move_left_joystick(context, /*position=*/{0, +1}, /*hold=*/200ms, /*release=*/500ms); + break; + case IntroKey::DOWN: + pbf_move_left_joystick(context, /*position=*/{0, -1}, /*hold=*/200ms, /*release=*/500ms); + break; + case IntroKey::LEFT: + pbf_move_left_joystick(context, /*position=*/{-1, 0}, /*hold=*/200ms, /*release=*/500ms); + break; + case IntroKey::RIGHT: + pbf_move_left_joystick(context, /*position=*/{+1, 0}, /*hold=*/200ms, /*release=*/500ms); + break; + default: + break; + } +} + +// From HOME with the game closed: A on the selected tile, through the +// user select (start_game_from_home(), slot 0: the cursor does not move), +// until the game's black screen. +void launch_from_home(ConsoleHandle& console, ProControllerContext& context){ + console.log("AutoStory intro: launching the selected HOME tile."); + start_game_from_home(console, context, /*tolerate_update_menu=*/true, /*game_slot=*/0, /*user_slot=*/0); +} + +// After the launch, until the language list (tolerant: see LAUNCH_QUIET). +// `recorder` and `language`: capture mode, save each new screen on the way. +void wait_for_language_list( + ConsoleHandle& console, ProControllerContext& context, + IntroFrameRecorder* recorder, NewGameLanguage language +){ + const WallClock start = current_time(); + size_t a_presses = 0; + WallClock next_a = start + LAUNCH_QUIET; + std::optional last_saved; + while (current_time() - start < LAUNCH_LIMIT){ + const VideoSnapshot frame = snapshot(console, context); + if (frame && read_language_list_cursor(frame)){ + console.log("AutoStory intro: the language list shows."); + dump_debug_image(console, std::string(DUMP_FOLDER), "language-list", frame); + return; + } + if (frame && recorder){ + const Milliseconds at = std::chrono::duration_cast(current_time() - start); + const std::optional change = last_saved + ? std::optional(ImageMatch::pixel_RMSD(*last_saved, frame)) + : std::nullopt; + if (recorder->see(at, change)){ + const std::string file = intro_capture_file(language, std::format("{:02}", recorder->saved() - 1)); + frame->save(SCREENSHOTS_PATH() + file); + console.log(std::format("AutoStory capture: {} ({} ms after the launch).", file, at.count())); + last_saved = frame->copy(); + } + } + if (current_time() >= next_a && a_presses < LAUNCH_A_PRESSES){ + a_presses++; + console.log(std::format("AutoStory intro: no language list yet; A ({} of {}).", a_presses, LAUNCH_A_PRESSES)); + pbf_press_button(context, BUTTON_A, /*hold=*/80ms, /*release=*/500ms); + next_a = current_time() + LAUNCH_A_EVERY; + } + context.wait_for(250ms); + } + fail(console, std::format("the language list did not show within {} s of the launch.", LAUNCH_LIMIT.count() / 1000)); +} + +// On the language list: one press at a time to `language`, reading the +// highlight after each, then A. +void pick_language(ConsoleHandle& console, ProControllerContext& context, NewGameLanguage language){ + const NewGameLanguageInfo& info = new_game_language_info(language); + for (size_t attempt = 0; attempt < 20; attempt++){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional cursor = frame ? read_language_list_cursor(frame) : std::nullopt; + if (!cursor){ + context.wait_for(250ms); + continue; + } + if (*cursor == info.list_entry){ + console.log(std::format("AutoStory intro: language {} (entry {}): A.", info.tag, info.list_entry)); + press(console, context, IntroKey::A, 500ms); + return; + } + const std::optional> moves = language_list_moves(*cursor, info.list_entry); + if (!moves || moves->empty()){ + break; + } + press(console, context, moves->front(), 400ms); + } + fail(console, std::format("the language list's highlight did not reach {}.", info.tag)); +} + +// The look picker's highlight once settled: two reads in a row agree, +// 150 ms apart, within 2 s. +std::optional read_settled_look(ConsoleHandle& console, ProControllerContext& context){ + std::optional previous; + for (size_t read = 0; read < 14; read++){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional cursor = frame ? read_look_picker_cursor(frame) : std::nullopt; + if (cursor && cursor == previous){ + return cursor; + } + previous = cursor; + context.wait_for(150ms); + } + return std::nullopt; +} + +// On the look picker (it opens with no portrait highlighted; a tilt +// brings the highlight up): tilts toward `look`, reading the highlight +// after each, then A. +void pick_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ + if (!wait_for_frame(console, context, is_look_picker, 20000ms)){ + fail(console, "the look picker did not show within 20 s of the language's A."); + } + const VideoSnapshot picker = snapshot(console, context); + if (picker){ + dump_debug_image(console, std::string(DUMP_FOLDER), "look-picker", picker); + } + size_t unread = 0; + for (size_t attempt = 0; attempt < 24 && unread <= 6; attempt++){ + const std::optional cursor = read_settled_look(console, context); + if (!cursor){ + unread++; + tilt(context, IntroKey::UP); + continue; + } + if (*cursor == look){ + console.log(std::format("AutoStory intro: look {}: A.", look)); + press(console, context, IntroKey::A, 500ms); + return; + } + const std::optional> moves = look_picker_moves(*cursor, look); + if (!moves || moves->empty()){ + break; + } + tilt(context, moves->front()); + } + fail(console, std::format("the look picker's highlight was not read on look {}.", look)); +} + +// Until the name keyboard has shown and finished sliding in (presses +// during that are dropped). +void wait_for_keyboard(ConsoleHandle& console, ProControllerContext& context){ + if (!wait_for_frame(console, context, is_name_keyboard, 20000ms)){ + fail(console, "the name keyboard did not show within 20 s of the look's A."); + } + context.wait_for(1000ms); +} + +// On the keyboard: checks its counter, then types the name and OK. +void type_name(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + wait_for_keyboard(console, context); + const VideoSnapshot frame = snapshot(console, context); + if (frame){ + dump_debug_image(console, std::string(DUMP_FOLDER), "keyboard", frame); + } + const std::optional limit = frame ? read_name_keyboard_limit(frame) : std::nullopt; + if (!limit){ + console.log("AutoStory intro: keyboard: the 0/N counter did not read; the language's limit holds."); + }else if (*limit < choices.name.size()){ + throw UserSetupError(console, std::format( + "AutoStory: the name keyboard takes {} characters; the player name \"{}\" has {}. Nothing was typed.", + *limit, choices.name, choices.name.size() + )); + }else{ + console.log(std::format("AutoStory intro: keyboard: takes {} characters.", *limit)); + } + const std::optional> presses = name_key_presses(choices.name, choices.language); + if (!presses){ + throw UserSetupError(console, std::format("AutoStory: the player name \"{}\" cannot be typed.", choices.name)); + } + console.log(std::format("AutoStory intro: typing \"{}\" ({} presses).", choices.name, presses->size())); + for (const IntroKey key : *presses){ + press(console, context, key, key == IntroKey::A ? 400ms : 250ms); + } + context.wait_for_all_requests(); +} + +// Capture mode: the screen now as `language`'s `screen`. +void save_capture(ConsoleHandle& console, ProControllerContext& context, NewGameLanguage language, std::string_view screen){ + const VideoSnapshot frame = snapshot(console, context); + const std::string file = intro_capture_file(language, screen); + if (frame){ + frame->save(SCREENSHOTS_PATH() + file); + console.log(std::format("AutoStory capture: {}.", file)); + } +} + +std::optional read_start(ConsoleHandle& console, const ImageViewRGB32& frame){ + if (read_confirm_choices_cursor(frame)){ + return NewGameStart::CONFIRM_CHOICES; + } + if (read_language_list_cursor(frame)){ + return NewGameStart::LANGUAGE_LIST; + } + HomeMenuDetector home(console, COLOR_RED); + if (home.detect_only(frame)){ + return NewGameStart::HOME; + } + return std::nullopt; +} + +} // namespace + + +NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext& context){ + const WallClock deadline = current_time() + 2000ms; + while (true){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional start = frame ? read_start(console, frame) : std::nullopt; + if (start){ + console.log(std::format("AutoStory intro: starting on screen {} (0 HOME, 1 language list, 2 Confirm Choices).", (int)*start)); + return *start; + } + if (current_time() >= deadline){ + throw UserSetupError( + console, + "AutoStory: 01.00 starts a new game (no save) from the Switch HOME with PLZA's tile selected and the game " + "closed, from the language list, or from \"Confirm Choices\". None of them is on screen; nothing was pressed." + ); + } + context.wait_for(250ms); + } +} + +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + if (const std::optional problem = new_game_problem(choices)){ + throw UserSetupError(console, *problem); + } + switch (require_new_game_start(console, context)){ + case NewGameStart::CONFIRM_CHOICES: + console.log("AutoStory intro: already on Confirm Choices; its check reads the language and name."); + return; + case NewGameStart::HOME: + close_game_from_home(console, context); + launch_from_home(console, context); + wait_for_language_list(console, context, /*recorder=*/nullptr, choices.language); + break; + case NewGameStart::LANGUAGE_LIST: + break; + } + pick_language(console, context, choices.language); + pick_look(console, context, choices.look); + type_name(console, context, choices); + if (!wait_for_frame(console, context, [](const ImageViewRGB32& frame){ return read_confirm_choices_cursor(frame).has_value(); }, 15000ms)){ + fail(console, "Confirm Choices did not show within 15 s of the name's OK."); + } +} + + +bool IntroFrameRecorder::see(Milliseconds at, std::optional from_saved){ + if (m_last_saved && at - *m_last_saved < m_every){ + return false; + } + if (from_saved && *from_saved <= m_change){ + return false; + } + m_last_saved = at; + m_saved++; + return true; +} + +std::string intro_capture_file(NewGameLanguage language, std::string_view screen){ + return std::format("{}_{}.png", new_game_language_info(language).tag, screen); +} + +void capture_intro_screens(ConsoleHandle& console, ProControllerContext& context, size_t look){ + for (size_t index = 0; index < 10; index++){ + const NewGameLanguage language = (NewGameLanguage)index; + const NewGameLanguageInfo& info = new_game_language_info(language); + console.log(std::format("AutoStory capture: {}: closing the game and launching it from HOME.", info.tag)); + go_home(console, context); + close_game_from_home(console, context); + launch_from_home(console, context); + IntroFrameRecorder recorder(CAPTURE_CHANGE, CAPTURE_EVERY); + wait_for_language_list(console, context, &recorder, language); + save_capture(console, context, language, "language-list"); + pick_language(console, context, language); + if (!wait_for_frame(console, context, is_look_picker, 20000ms)){ + fail(console, "the look picker did not show within 20 s of the language's A."); + } + save_capture(console, context, language, "look-picker"); + pick_look(console, context, look); + wait_for_keyboard(console, context); + save_capture(console, context, language, "keyboard"); + console.log(std::format("AutoStory capture: {}: {} screens before the language list.", info.tag, recorder.saved())); + } + go_home(console, context); + close_game_from_home(console, context); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h new file mode 100644 index 0000000000..65a4e0dcef --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h @@ -0,0 +1,92 @@ +/* PokemonLZA AutoStory - New game + * + * From: https://github.com/PokemonAutomation/ + * + * 01.00's steps before "Confirm Choices": launch the game from HOME, pick + * the language, the look and type the name (PokemonLZA_AutoStoryNewGameChoices.h), + * and a developer mode that saves each language's intro screens. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNewGame_H +#define PokemonAutomation_PokemonLZA_AutoStoryNewGame_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The screens a new game (no save) may start on. +enum class NewGameStart{ + HOME, // The Switch's HOME, PLZA's tile selected, the game closed. + LANGUAGE_LIST, + CONFIRM_CHOICES, // The language, look and name chosen already. +}; + +// The screen now, read over up to 2 s with no press. Throws UserSetupError, +// having pressed nothing, if it is none of NewGameStart's. +NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext& context); + +// 01.00's first step: from HOME (the selected tile launched, never moving +// HOME's cursor) or the language list, plays the language, the look and +// the name of `choices` up to "Confirm Choices"; on "Confirm Choices" it +// presses nothing. Throws UserSetupError before any press if `choices` +// cannot be played (new_game_problem()) or the keyboard's counter takes +// fewer characters than the name, OperationFailedException (with a +// screenshot) if a screen does not show or its highlight does not reach +// the choice. +void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices); + +// Capture mode's recording of the screens between the launch and the +// language list: a polled frame is saved when it differs from the last +// saved one by more than `change` (pixel RMSD), at most one per `every`. +class IntroFrameRecorder{ +public: + IntroFrameRecorder(double change, Milliseconds every) + : m_change(change) + , m_every(every) + {} + + // Whether to save the frame polled at `at` (since the recording + // began), `from_saved` from the last saved one (none: nothing saved + // yet). Counts it as saved when so. + bool see(Milliseconds at, std::optional from_saved); + + // How many frames were saved. + size_t saved() const{ + return m_saved; + } + +private: + double m_change; + Milliseconds m_every; + std::optional m_last_saved; + size_t m_saved = 0; +}; + +// The file capture mode saves `language`'s screen `screen` to, in the +// Screenshots folder: "_.png". +std::string intro_capture_file(NewGameLanguage language, std::string_view screen); + +// Developer: for each of the 10 languages (Korean too: nothing is typed), +// closes the game, launches it from HOME and saves each distinct screen +// up to the language list as "_NN.png" (NN from 00, in order), then +// "_language-list.png"; picks the language and look `look`, saves +// "_look-picker.png" and "_keyboard.png", and goes back to HOME. +// Nothing is typed or confirmed, so no save is made. +void capture_intro_screens(ConsoleHandle& console, ProControllerContext& context, size_t look); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp new file mode 100644 index 0000000000..d9c912fc1e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp @@ -0,0 +1,117 @@ +/* PokemonLZA AutoStory - New game choices + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "PokemonLZA_AutoStoryNameKeys.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The language list's rows per column. +constexpr size_t LANGUAGE_LIST_ROWS = 5; +constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; + +// The look picker: 2 rows of LOOK_COLUMNS portraits. +constexpr size_t LOOK_COLUMNS = 4; +constexpr size_t LOOK_COUNT = 2 * LOOK_COLUMNS; + +// The presses from (column, row) `from` to `to` on a grid: across first, +// then up or down. +std::vector grid_moves(size_t from_column, size_t from_row, size_t to_column, size_t to_row){ + std::vector moves; + for (size_t c = from_column; c < to_column; c++){ + moves.push_back(IntroKey::RIGHT); + } + for (size_t c = to_column; c < from_column; c++){ + moves.push_back(IntroKey::LEFT); + } + for (size_t r = from_row; r < to_row; r++){ + moves.push_back(IntroKey::DOWN); + } + for (size_t r = to_row; r < from_row; r++){ + moves.push_back(IntroKey::UP); + } + return moves; +} + +} // namespace + + +const NewGameLanguageInfo& new_game_language_info(NewGameLanguage language){ + static const std::array table{{ + {.tag = "en", .list_entry = 0, .name_limit = 12, .ocr_language = Language::English, .confirm_text = "English"}, + {.tag = "es-ES", .list_entry = 1, .name_limit = 12, .ocr_language = Language::Spanish, .confirm_text = "Espa\xc3\xb1" "a)"}, + {.tag = "es-419", .list_entry = 2, .name_limit = 12, .ocr_language = Language::Spanish, .confirm_text = "Latino"}, + {.tag = "fr", .list_entry = 3, .name_limit = 12, .ocr_language = Language::French, .confirm_text = "Fran"}, + {.tag = "de", .list_entry = 4, .name_limit = 12, .ocr_language = Language::German, .confirm_text = "Deutsch"}, + {.tag = "it", .list_entry = 5, .name_limit = 12, .ocr_language = Language::Italian, .confirm_text = "Italiano"}, + {.tag = "ja", .list_entry = 6, .name_limit = 6, .ocr_language = Language::Japanese, .confirm_text = "\xe6\x97\xa5\xe6\x9c\xac"}, + {.tag = "ko", .list_entry = 7, .name_limit = 6, .ocr_language = Language::Korean, .confirm_text = "\xed\x95\x9c\xea\xb5\xad", .supported = false}, + {.tag = "zh-Hans", .list_entry = 8, .name_limit = 6, .ocr_language = Language::ChineseSimplified, .confirm_text = "\xe7\xae\x80\xe4\xbd\x93"}, + {.tag = "zh-Hant", .list_entry = 9, .name_limit = 6, .ocr_language = Language::ChineseTraditional, .confirm_text = "\xe7\xb9\x81\xe9\xab\x94"}, + }}; + const size_t index = (size_t)language; + return table[index < table.size() ? index : 0]; +} + +std::optional new_game_problem(const NewGameChoices& choices){ + const NewGameLanguageInfo& info = new_game_language_info(choices.language); + if (!info.supported){ + return std::format("AutoStory: Korean ({}) is not supported yet: its name keyboard is Hangul.", info.tag); + } + if (choices.look < 1 || choices.look > LOOK_COUNT){ + return std::format("AutoStory: the player look must be 1 to {}, not {}.", LOOK_COUNT, choices.look); + } + if (choices.name.empty()){ + return std::string("AutoStory: the player name is empty."); + } + if (choices.name.size() > info.name_limit){ + return std::format( + "AutoStory: the player name \"{}\" has {} characters; the game takes at most {} in this language ({}).", + choices.name, choices.name.size(), info.name_limit, info.tag + ); + } + if (!name_key_presses(choices.name, choices.language)){ + return std::format( + "AutoStory: the player name \"{}\" has a character that is not on the name keyboard's first page " + "(letters, digits and - / : ' , . ? !).", + choices.name + ); + } + return std::nullopt; +} + +std::optional> language_list_moves(size_t from, size_t to){ + if (from >= LANGUAGE_LIST_SIZE || to >= LANGUAGE_LIST_SIZE){ + return std::nullopt; + } + return grid_moves( + from / LANGUAGE_LIST_ROWS, from % LANGUAGE_LIST_ROWS, + to / LANGUAGE_LIST_ROWS, to % LANGUAGE_LIST_ROWS + ); +} + +std::optional> look_picker_moves(size_t from, size_t to){ + if (from < 1 || from > LOOK_COUNT || to < 1 || to > LOOK_COUNT){ + return std::nullopt; + } + return grid_moves( + (from - 1) % LOOK_COLUMNS, (from - 1) / LOOK_COLUMNS, + (to - 1) % LOOK_COLUMNS, (to - 1) / LOOK_COLUMNS + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h new file mode 100644 index 0000000000..0621c36c2c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h @@ -0,0 +1,106 @@ +/* PokemonLZA AutoStory - New game choices + * + * From: https://github.com/PokemonAutomation/ + * + * The new game's choices (language, look, name) and the presses each takes + * on its screen, as pure functions. The screens' readers are in + * Detectors/PokemonLZA_AutoStoryIntroScreens.h; the name's key presses in + * PokemonLZA_AutoStoryNameKeys.h. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNewGameChoices_H +#define PokemonAutomation_PokemonLZA_AutoStoryNewGameChoices_H + +#include +#include +#include +#include +#include +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The game's 10 languages, in the language list's order: down the left +// column (English, Espanol (Espana), Espanol (Latinoamerica), Francais, +// Deutsch), then down the right one (Italiano, Japanese, Korean, +// Simplified and Traditional Chinese). The cursor starts on English. +enum class NewGameLanguage{ + English, + SpanishSpain, + SpanishLatinAmerica, + French, + German, + Italian, + Japanese, + Korean, + ChineseSimplified, + ChineseTraditional, +}; + +// What the intro needs to know of one language. +struct NewGameLanguageInfo{ + // Short name for logs and capture files: "en", "es-ES", "ja", ... + std::string_view tag; + // Its entry on the language list (the order of NewGameLanguage). + size_t list_entry = 0; + // The name keyboard's character limit: its "0/N" counter (the + // console's frames: 12 for the European languages, 6 for Japanese, + // Korean and Chinese; English's is not in the frames and taken as 12). + size_t name_limit = 0; + // The OCR language that reads its name on Confirm Choices. + Language ocr_language = Language::None; + // A part of its name as Confirm Choices shows it ("Deutsch", "Latino"). + std::string_view confirm_text; + // The program can play it (Korean: not yet; its keyboard is Hangul). + bool supported = true; +}; + +// `language`'s row of the table above. +const NewGameLanguageInfo& new_game_language_info(NewGameLanguage language); + +// One press on an intro screen. SHIFT is the left stick click (the name +// keyboard's Shift: the next letter is a capital); PLUS the keyboard's OK. +enum class IntroKey{ + UP, + DOWN, + LEFT, + RIGHT, + A, + SHIFT, + PLUS, +}; + +// The new game's choices, from the program's options. +struct NewGameChoices{ + NewGameLanguage language = NewGameLanguage::English; + // 1 to 8: the look picker's portraits, left to right along the top + // row, then the bottom one. + size_t look = 1; + // Keys of the name keyboard's QWERTY layer (name_key_presses()), at + // most the language's name_limit. + std::string name = "Kosmos"; +}; + +// Why `choices` cannot be played, before any press; nullopt when they can. +std::optional new_game_problem(const NewGameChoices& choices); + +// The presses that move the language list's cursor from entry `from` to +// entry `to`: LEFT or RIGHT to the column, then UP or DOWN to the row. +// Nullopt for an entry outside the list. +std::optional> language_list_moves(size_t from, size_t to); + +// The presses (stick tilts) that move the look picker's highlight from +// look `from` to look `to` (1 to 8): LEFT or RIGHT, then UP or DOWN. +// Nullopt for a look outside 1 to 8. +std::optional> look_picker_moves(size_t from, size_t to); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp new file mode 100644 index 0000000000..256e49a4f1 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp @@ -0,0 +1,377 @@ +/* PokemonLZA AutoStory - New game Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryNameKeys.h" +#include "PokemonLZA_AutoStoryNewGame.h" +#include "PokemonLZA_AutoStoryNewGameChoices.h" +#include "PokemonLZA_AutoStoryNewGame_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// Presses as letters: U D L R, A, S for Shift, + for OK. +std::string press_text(const std::optional>& presses){ + if (!presses){ + return "none"; + } + std::string text; + for (const IntroKey key : *presses){ + switch (key){ + case IntroKey::UP: + text += 'U'; + break; + case IntroKey::DOWN: + text += 'D'; + break; + case IntroKey::LEFT: + text += 'L'; + break; + case IntroKey::RIGHT: + text += 'R'; + break; + case IntroKey::A: + text += 'A'; + break; + case IntroKey::SHIFT: + text += 'S'; + break; + case IntroKey::PLUS: + text += '+'; + break; + } + } + return text; +} + + +// name_key_presses(): the cursor starts on "1". +struct NameKeysCase{ + std::string name; + struct Input{ + std::string text; + NewGameLanguage language = NewGameLanguage::English; + }; + Input input; + struct Expectation{ + std::string presses; // press_text(); "none" when it cannot be typed. + }; + Expectation expectation; +}; + +const NameKeysCase NAME_KEYS_CASES[] = { + { + .name = "a capital first letter takes Shift; the cursor moves from key to key", + .input = {.text = "Kosmos"}, + .expectation = {.presses = "RRRRRRRDDSA" "RUA" "LLLLLLLDA" "RRRRRDA" "RRUUA" "LLLLLLLDA" "+"}, + }, + {.name = "the starting key takes no move", .input = {.text = "1"}, .expectation = {.presses = "A+"}}, + {.name = "a capital in the middle takes Shift", .input = {.text = "aB"}, .expectation = {.presses = "DDARRRRDSA+"}}, + {.name = "punctuation on the first page", .input = {.text = "-!"}, .expectation = {.presses = "RRRRRRRRRRADDDA+"}}, + { + .name = "Simplified Chinese switches to letters first", + .input = {.text = "ab", .language = NewGameLanguage::ChineseSimplified}, + .expectation = {.presses = "DDDDRRRA" "ULLLUA" "RRRRDA" "+"}, + }, + { + .name = "Traditional Chinese opens on letters", + .input = {.text = "a", .language = NewGameLanguage::ChineseTraditional}, + .expectation = {.presses = "DDA+"}, + }, + {.name = "a space has no key", .input = {.text = "a b"}, .expectation = {.presses = "none"}}, + {.name = "an accented letter is not on the first page", .input = {.text = "Jos\xc3\xa9"}, .expectation = {.presses = "none"}}, + {.name = "a symbol of the second page", .input = {.text = "a#"}, .expectation = {.presses = "none"}}, + {.name = "an empty name", .input = {.text = ""}, .expectation = {.presses = "none"}}, +}; + +class Test_NameKeys : public UnitTest{ +public: + explicit Test_NameKeys(const NameKeysCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - name keys: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string presses = press_text(name_key_presses(m_test.input.text, m_test.input.language)); + if (presses != m_test.expectation.presses){ + return std::format("\"{}\": expected {}, got {}.", m_test.input.text, m_test.expectation.presses, presses); + } + return true; + } + +private: + const NameKeysCase& m_test; +}; + + +// new_game_problem(): whether the program refuses the choices before any +// press. +struct ProblemCase{ + std::string name; + struct Input{ + NewGameChoices choices; + }; + Input input; + struct Expectation{ + bool refused = false; + }; + Expectation expectation; +}; + +const ProblemCase PROBLEM_CASES[] = { + {.name = "the defaults", .input = {.choices = {}}, .expectation = {.refused = false}}, + { + .name = "12 characters in English", + .input = {.choices = {.name = "Abcdefghijkl"}}, + .expectation = {.refused = false}, + }, + { + .name = "13 characters in English", + .input = {.choices = {.name = "Abcdefghijklm"}}, + .expectation = {.refused = true}, + }, + { + .name = "12 characters in German", + .input = {.choices = {.language = NewGameLanguage::German, .name = "Abcdefghijkl"}}, + .expectation = {.refused = false}, + }, + { + .name = "6 characters in Japanese", + .input = {.choices = {.language = NewGameLanguage::Japanese, .name = "Kosmos"}}, + .expectation = {.refused = false}, + }, + { + .name = "7 characters in Japanese", + .input = {.choices = {.language = NewGameLanguage::Japanese, .name = "Kosmoss"}}, + .expectation = {.refused = true}, + }, + { + .name = "7 characters in Traditional Chinese", + .input = {.choices = {.language = NewGameLanguage::ChineseTraditional, .name = "Kosmoss"}}, + .expectation = {.refused = true}, + }, + { + .name = "Korean is not supported", + .input = {.choices = {.language = NewGameLanguage::Korean, .name = "Kosmos"}}, + .expectation = {.refused = true}, + }, + {.name = "an empty name", .input = {.choices = {.name = ""}}, .expectation = {.refused = true}}, + {.name = "a space in the name", .input = {.choices = {.name = "Kos mos"}}, .expectation = {.refused = true}}, + {.name = "look 8", .input = {.choices = {.look = 8}}, .expectation = {.refused = false}}, + {.name = "look 0", .input = {.choices = {.look = 0}}, .expectation = {.refused = true}}, + {.name = "look 9", .input = {.choices = {.look = 9}}, .expectation = {.refused = true}}, +}; + +class Test_NewGameProblem : public UnitTest{ +public: + explicit Test_NewGameProblem(const ProblemCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - new game choices: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::optional problem = new_game_problem(m_test.input.choices); + if (problem.has_value() != m_test.expectation.refused){ + return std::format( + "Expected {}, got {}.", + m_test.expectation.refused ? "a refusal" : "no problem", + problem ? *problem : std::string("no problem") + ); + } + return true; + } + +private: + const ProblemCase& m_test; +}; + + +// The language list's moves (entries down the left column, then the right +// one) and the look picker's (looks along the top row, then the bottom). +enum class Grid{ + LANGUAGE_LIST, + LOOK_PICKER, +}; + +struct GridCase{ + std::string name; + struct Input{ + Grid grid = Grid::LANGUAGE_LIST; + size_t from = 0; + size_t to = 0; + }; + Input input; + struct Expectation{ + std::string presses; + }; + Expectation expectation; +}; + +const GridCase GRID_CASES[] = { + {.name = "English to Deutsch", .input = {.from = 0, .to = 4}, .expectation = {.presses = "DDDD"}}, + {.name = "English to Italiano", .input = {.from = 0, .to = 5}, .expectation = {.presses = "R"}}, + {.name = "English to Traditional Chinese", .input = {.from = 0, .to = 9}, .expectation = {.presses = "RDDDD"}}, + {.name = "Simplified Chinese to Francais", .input = {.from = 8, .to = 3}, .expectation = {.presses = "L"}}, + {.name = "an entry past the list", .input = {.from = 0, .to = 10}, .expectation = {.presses = "none"}}, + {.name = "look 1 to look 8", .input = {.grid = Grid::LOOK_PICKER, .from = 1, .to = 8}, .expectation = {.presses = "RRRD"}}, + {.name = "look 7 to look 2", .input = {.grid = Grid::LOOK_PICKER, .from = 7, .to = 2}, .expectation = {.presses = "LU"}}, + {.name = "look 0", .input = {.grid = Grid::LOOK_PICKER, .from = 0, .to = 2}, .expectation = {.presses = "none"}}, +}; + +class Test_GridMoves : public UnitTest{ +public: + explicit Test_GridMoves(const GridCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - intro moves: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string presses = press_text(m_test.input.grid == Grid::LANGUAGE_LIST + ? language_list_moves(m_test.input.from, m_test.input.to) + : look_picker_moves(m_test.input.from, m_test.input.to) + ); + if (presses != m_test.expectation.presses){ + return std::format("Expected {}, got {}.", m_test.expectation.presses, presses); + } + return true; + } + +private: + const GridCase& m_test; +}; + + +// Capture mode's recording: change 4, at most one frame a second. Each +// frame is (ms since the launch, RMSD from the last saved; -1: none yet). +struct RecorderCase{ + std::string name; + struct Input{ + std::vector> frames; + }; + Input input; + struct Expectation{ + std::string saved; // One letter per frame: s saved, . not. + }; + Expectation expectation; +}; + +const RecorderCase RECORDER_CASES[] = { + {.name = "the first frame is saved", .input = {.frames = {{0, -1}}}, .expectation = {.saved = "s"}}, + { + .name = "a still screen is saved once", + .input = {.frames = {{0, -1}, {1500, 1}, {3000, 2}}}, + .expectation = {.saved = "s.."}, + }, + { + .name = "each new screen is saved", + .input = {.frames = {{0, -1}, {1500, 30}, {3000, 3}, {4500, 25}}}, + .expectation = {.saved = "ss.s"}, + }, + { + .name = "a change within a second of the last save waits", + .input = {.frames = {{0, -1}, {500, 30}, {1250, 30}}}, + .expectation = {.saved = "s.s"}, + }, +}; + +class Test_IntroRecorder : public UnitTest{ +public: + explicit Test_IntroRecorder(const RecorderCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - capture recording: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + IntroFrameRecorder recorder(/*change=*/4, /*every=*/Milliseconds(1000)); + std::string saved; + for (const auto& [at, change] : m_test.input.frames){ + const std::optional from_saved = change < 0 ? std::nullopt : std::optional(change); + saved += recorder.see(Milliseconds(at), from_saved) ? 's' : '.'; + } + if (saved != m_test.expectation.saved){ + return std::format("Expected {}, got {}.", m_test.expectation.saved, saved); + } + return true; + } + +private: + const RecorderCase& m_test; +}; + + +// Capture mode's file names, which sort each language's screens in order. +struct CaptureFileCase{ + std::string name; + struct Input{ + NewGameLanguage language = NewGameLanguage::English; + std::string screen; + }; + Input input; + struct Expectation{ + std::string file; + }; + Expectation expectation; +}; + +const CaptureFileCase CAPTURE_FILE_CASES[] = { + {.name = "a screen before the list", .input = {.language = NewGameLanguage::German, .screen = "03"}, .expectation = {.file = "de_03.png"}}, + {.name = "Korean is captured", .input = {.language = NewGameLanguage::Korean, .screen = "keyboard"}, .expectation = {.file = "ko_keyboard.png"}}, + { + .name = "Latin American Spanish", + .input = {.language = NewGameLanguage::SpanishLatinAmerica, .screen = "language-list"}, + .expectation = {.file = "es-419_language-list.png"}, + }, +}; + +class Test_CaptureFile : public UnitTest{ +public: + explicit Test_CaptureFile(const CaptureFileCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - capture file: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::string file = intro_capture_file(m_test.input.language, m_test.input.screen); + if (file != m_test.expectation.file){ + return std::format("Expected {}, got {}.", m_test.expectation.file, file); + } + return true; + } + +private: + const CaptureFileCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryNewGame(UnitTestDatabase& database){ + for (const NameKeysCase& test : NAME_KEYS_CASES){ + database.add(test); + } + for (const ProblemCase& test : PROBLEM_CASES){ + database.add(test); + } + for (const GridCase& test : GRID_CASES){ + database.add(test); + } + for (const RecorderCase& test : RECORDER_CASES){ + database.add(test); + } + for (const CaptureFileCase& test : CAPTURE_FILE_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h new file mode 100644 index 0000000000..8dcb17eb58 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h @@ -0,0 +1,27 @@ +/* PokemonLZA AutoStory - New game Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryNewGame_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryNewGame_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the new game's tests: the choices' checks, the language list's +// and look picker's moves, the name's key presses and capture mode's +// recording and file names. +void add_tests_AutoStoryNewGame(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp new file mode 100644 index 0000000000..e7a7981f91 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp @@ -0,0 +1,344 @@ +/* PokemonLZA AutoStory - New game intro screens + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/Images/ImageFilter.h" +#include "CommonTools/OCR/OCR_Routines.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr size_t LANGUAGE_LIST_ROWS = 5; +constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; +constexpr size_t LOOK_COLUMNS = 4; +constexpr size_t LOOK_COUNT = 2 * LOOK_COLUMNS; + +bool usable(const ImageViewRGB32& frame){ + return frame && frame.width() >= 160 && frame.height() >= 90; +} + +double brightness(const ImageStats& stats){ + return stats.average.sum() / 3; +} + +ImageStats box_stats(const ImageViewRGB32& frame, const ImageFloatBox& box){ + return image_stats(extract_box_reference(frame, box)); +} + +enum class ListBox{ + HIGHLIGHTED, + PLAIN, + OTHER, +}; + +// A strip at the left end of entry `index`'s box, left of its text and +// right of the cursor's arrow. The boxes are 576 x 84 at 1920 x 1080, the +// columns' left edges at x 347 and 996, the rows' tops 108 apart from +// y 342; the strip is 65 x 54 from 38 right of the edge and 15 down. +ImageFloatBox language_box_strip(size_t index){ + const size_t column = index / LANGUAGE_LIST_ROWS; + const size_t row = index % LANGUAGE_LIST_ROWS; + return ImageFloatBox(column == 0 ? 0.2005 : 0.5365, 0.331 + 0.1 * (double)row, 0.034, 0.05); +} + +// The highlighted box is 255 white, flat; the others slate blue, about +// (54, 60-76, 82-107), each channel's spread under 3. +ListBox classify_list_box(const ImageStats& stats){ + if (stats.count == 0){ + return ListBox::OTHER; + } + const FloatPixel& average = stats.average; + const double spread = stats.stddev.sum(); + if (average.r >= 200 && average.g >= 200 && average.b >= 200 && spread <= 30){ + return ListBox::HIGHLIGHTED; + } + const bool slate = + average.r >= 35 && average.r <= 90 && + average.g >= 45 && average.g <= 110 && + average.b >= 65 && average.b <= 140 && + average.b >= average.r + 15; + if (slate && spread <= 20){ + return ListBox::PLAIN; + } + return ListBox::OTHER; +} + +// The dark blue background between the columns (about (9, 24, 56)). +bool column_gap_dark(const ImageViewRGB32& frame){ + const ImageStats gap = box_stats(frame, ImageFloatBox(0.4896, 0.331, 0.0208, 0.447)); + return gap.count > 0 && brightness(gap) < 70; +} + +// The look picker's tiles are 240 x 240 at 1920 x 1080, their left edges +// at x 373, 685, 997 and 1309, their tops at y 324 and 609. +double look_tile_left(size_t look){ + return (373.0 + 312.0 * (double)((look - 1) % LOOK_COLUMNS)) / 1920; +} +double look_tile_top(size_t look){ + return (look <= LOOK_COLUMNS ? 324.0 : 609.0) / 1080; +} + +// Corner `corner` of look `look`'s tile (0 top left, 1 top right, 2 bottom +// left, 3 bottom right): 12 x 12, 10 in from both edges. The highlighted +// look's white card reaches about 12 past the tile on every side, so the +// patches stay on it while it is enlarged. +ImageFloatBox look_corner_patch(size_t look, size_t corner){ + const double dx = (corner % 2 == 0 ? 10.0 : 218.0) / 1920; + const double dy = (corner < 2 ? 10.0 : 218.0) / 1080; + return ImageFloatBox(look_tile_left(look) + dx, look_tile_top(look) + dy, 12.0 / 1920, 12.0 / 1080); +} + +// The face in the middle of look `look`'s tile: 60 x 60 from 90 right of +// its edge and 100 down. +ImageFloatBox look_face_patch(size_t look){ + return ImageFloatBox(look_tile_left(look) + 90.0 / 1920, look_tile_top(look) + 100.0 / 1080, 60.0 / 1920, 60.0 / 1080); +} + +enum class LookCorner{ + WHITE, + DARK, + OTHER, +}; + +// Measured on the console's look pickers (67 frames in English, German +// and Japanese): the highlighted card's corners (240-248, 245-250, +// 246-251), spread under 17; the others slate or, past a tile's rounded +// corner, the background: (21-34, 29-57, 56-91), spread under 32. +LookCorner classify_look_corner(const ImageStats& stats){ + if (stats.count == 0){ + return LookCorner::OTHER; + } + const FloatPixel& average = stats.average; + const double spread = stats.stddev.sum(); + if (average.r >= 200 && average.g >= 200 && average.b >= 200 && spread <= 40){ + return LookCorner::WHITE; + } + if (brightness(stats) < 90 && average.r <= 50 && average.b >= average.r + 20 && spread <= 50){ + return LookCorner::DARK; + } + return LookCorner::OTHER; +} + +// How many of look `look`'s 4 corners are white; nullopt if the tile is +// not a look picker tile: a corner neither white nor dark, or no face in +// its middle (on the same frames brightness 108-196, spread over 117). +std::optional look_white_corners(const ImageViewRGB32& frame, size_t look){ + const ImageStats face = box_stats(frame, look_face_patch(look)); + if (face.count == 0 || brightness(face) < 80 || face.stddev.sum() < 60){ + return std::nullopt; + } + size_t white = 0; + for (size_t corner = 0; corner < 4; corner++){ + switch (classify_look_corner(box_stats(frame, look_corner_patch(look, corner)))){ + case LookCorner::WHITE: + white++; + break; + case LookCorner::DARK: + break; + case LookCorner::OTHER: + return std::nullopt; + } + } + return white; +} + +// The look picker as read from `frame`: whether it shows, and the look +// highlighted, the one with 4 white corners while the other 7 have none. +struct LookPickerReading{ + bool shows = false; + std::optional highlighted; +}; + +LookPickerReading read_look_picker(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return {}; + } + std::optional card; + size_t lit_tiles = 0; + for (size_t look = 1; look <= LOOK_COUNT; look++){ + const std::optional white = look_white_corners(frame, look); + if (!white){ + return {}; + } + if (*white > 0){ + lit_tiles++; + } + if (*white == 4){ + card = look; + } + } + LookPickerReading reading{.shows = true}; + if (lit_tiles == 1 && card){ + reading.highlighted = card; + } + return reading; +} + +// The number at `text[pos]`, moving `pos` past it; nullopt when no digit +// is there. +std::optional read_digits(std::string_view text, size_t& pos){ + const size_t start = pos; + size_t value = 0; + while (pos < text.size() && text[pos] >= '0' && text[pos] <= '9' && pos - start < 4){ + value = value * 10 + (size_t)(text[pos] - '0'); + pos++; + } + if (pos == start){ + return std::nullopt; + } + return value; +} + +void skip_spaces(std::string_view text, size_t& pos){ + while (pos < text.size() && (text[pos] == ' ' || text[pos] == '\n' || text[pos] == '\r')){ + pos++; + } +} + +// The limit N in a counter's text "0/N"; nullopt for any other text. +std::optional parse_counter(std::string_view text){ + size_t pos = 0; + skip_spaces(text, pos); + if (!read_digits(text, pos)){ + return std::nullopt; + } + skip_spaces(text, pos); + if (pos >= text.size() || text[pos] != '/'){ + return std::nullopt; + } + pos++; + skip_spaces(text, pos); + const std::optional limit = read_digits(text, pos); + skip_spaces(text, pos); + if (!limit || *limit == 0 || pos != text.size()){ + return std::nullopt; + } + return limit; +} + +// `box` of `frame` as black text on white for OCR: the pixels with every +// channel at least `min_channel` are the text. +std::string read_light_text(const ImageViewRGB32& frame, const ImageFloatBox& box, Language language, uint8_t min_channel){ + const uint32_t mins = 0xff000000 | ((uint32_t)min_channel << 16) | ((uint32_t)min_channel << 8) | min_channel; + const ImageRGB32 filtered = to_blackwhite_rgb32_range( + extract_box_reference(frame, box), /*in_range_black=*/true, mins, /*maxs=*/0xffffffff + ); + return OCR::ocr_read(language, filtered); +} + +} // namespace + + +std::optional read_language_list_cursor(const ImageViewRGB32& frame){ + if (!usable(frame) || !column_gap_dark(frame)){ + return std::nullopt; + } + std::optional highlighted; + for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ + switch (classify_list_box(box_stats(frame, language_box_strip(index)))){ + case ListBox::HIGHLIGHTED: + if (highlighted){ + return std::nullopt; + } + highlighted = index; + break; + case ListBox::PLAIN: + break; + case ListBox::OTHER: + return std::nullopt; + } + } + return highlighted; +} + +std::optional read_look_picker_cursor(const ImageViewRGB32& frame){ + return read_look_picker(frame).highlighted; +} + +bool is_look_picker(const ImageViewRGB32& frame){ + return read_look_picker(frame).shows; +} + +// The question area (x 1056-1824, y 54-184 at 1920 x 1080) is dark and +// flat: 27, spread 3 on all ten languages' keyboards; the intro's other +// screens are 46 or brighter there, or busy. The keys' bottom row +// (y 929-950) averages 205-211; elsewhere 160 at most. +bool is_name_keyboard(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return false; + } + const ImageStats question = box_stats(frame, ImageFloatBox(0.55, 0.05, 0.40, 0.12)); + if (question.count == 0 || brightness(question) > 40 || question.stddev.sum() > 15){ + return false; + } + const ImageStats keys = box_stats(frame, ImageFloatBox(0.03, 0.86, 0.80, 0.02)); + return keys.count > 0 && brightness(keys) >= 185; +} + +// The counter is grey (about 128) on the dark question area: with a +// 12-character field ("0/12") at x 1645-1725, y 325-355; with a 6-character +// one ("0/6") at x 1275-1335, y 355-385 (Japanese) or 340-370 (Korean, +// Chinese, whose keyboards are taller). The field's underline runs just +// above each, so each layout gets its own box. +std::optional read_name_keyboard_limit(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return std::nullopt; + } + const ImageFloatBox boxes[] = { + ImageFloatBox(1625.0 / 1920, 312.0 / 1080, 120.0 / 1920, 53.0 / 1080), + ImageFloatBox(1258.0 / 1920, 345.0 / 1080, 115.0 / 1920, 50.0 / 1080), + ImageFloatBox(1258.0 / 1920, 328.0 / 1080, 115.0 / 1920, 50.0 / 1080), + }; + for (const ImageFloatBox& box : boxes){ + const std::optional limit = parse_counter(read_light_text(frame, box, Language::English, /*min_channel=*/90)); + if (limit){ + return limit; + } + } + return std::nullopt; +} + +// The values right of the "Language" and "Name" labels: white, from x 345; +// the language's row y 400-450, the name's 468-522. +std::string read_confirm_choices_name(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return ""; + } + const std::string text = read_light_text( + frame, ImageFloatBox(340.0 / 1920, 468.0 / 1080, 760.0 / 1920, 54.0 / 1080), Language::English, /*min_channel=*/150 + ); + std::string name; + for (const char ch : text){ + if (ch != ' ' && ch != '\n' && ch != '\r'){ + name += ch; + } + } + return name; +} + +std::string read_confirm_choices_language(const ImageViewRGB32& frame, Language language){ + if (!usable(frame)){ + return ""; + } + return read_light_text( + frame, ImageFloatBox(340.0 / 1920, 400.0 / 1080, 760.0 / 1920, 50.0 / 1080), language, /*min_channel=*/150 + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h new file mode 100644 index 0000000000..96c0ac4f29 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h @@ -0,0 +1,63 @@ +/* PokemonLZA AutoStory - New game intro screens + * + * From: https://github.com/PokemonAutomation/ + * + * Readers of the new game's screens before "Confirm Choices" (whose + * highlight is in PokemonLZA_AutoStoryConfirmChoicesReader.h): the + * language list, the look picker and the Switch's name keyboard, and the + * name and language "Confirm Choices" shows. Measured on the console's + * frames in ten languages (2026-11-13). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H + +#include +#include +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// On "Which language will you play in?", the highlighted entry (numbered +// down the left column, then down the right one): the one white box of +// the 10, the others slate. Nullopt for any other frame, an empty one +// included. +std::optional read_language_list_cursor(const ImageViewRGB32& frame); + +// On the look picker ("LOOKS"), the look (1 to 8) whose portrait is +// highlighted: the one tile whose 4 corners are on the white card. Nullopt +// while none is (the screen opens so), while the card moves, and for any +// other frame. +std::optional read_look_picker_cursor(const ImageViewRGB32& frame); + +// The look picker's 2 x 4 portraits on dark blue, highlighted or not. +bool is_look_picker(const ImageViewRGB32& frame); + +// The Switch's name keyboard: the dark question area on top, the light +// key panel below. Any of its layouts (Latin, Hangul, Chinese). +bool is_name_keyboard(const ImageViewRGB32& frame); + +// The name keyboard's character limit, read with OCR from its "0/N" +// counter right under the text field (it sits further right with a +// 12-character field). Nullopt when no counter reads as one. +std::optional read_name_keyboard_limit(const ImageViewRGB32& frame); + +// The player name "Confirm Choices" shows, read with OCR (English), its +// spaces dropped. Empty when nothing reads. +std::string read_confirm_choices_name(const ImageViewRGB32& frame); + +// The language "Confirm Choices" shows, read with OCR in `language`. +std::string read_confirm_choices_language(const ImageViewRGB32& frame, Language language); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp new file mode 100644 index 0000000000..2b6bcdf6a7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp @@ -0,0 +1,150 @@ +/* PokemonLZA AutoStory - New game intro screens Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Tests/ImageUnitTest.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryIntroScreens_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +std::string describe(std::optional value){ + return value ? std::format("{}", *value) : std::string("none"); +} + +// One console frame and what each reader makes of it. +struct FrameCase{ + std::string name; + struct Input{ + std::string file; // Under the test images' PokemonLZA/. + }; + Input input; + struct Expectation{ + std::optional language_entry = std::nullopt; + bool look_picker = false; + std::optional look = std::nullopt; + bool keyboard = false; + std::optional name_limit = std::nullopt; + }; + Expectation expectation; +}; + +const FrameCase FRAME_CASES[] = { + {.name = "language list on English", .input = {.file = "AutoStoryLanguageList/0_en.png"}, .expectation = {.language_entry = 0}}, + {.name = "language list on Espanol (Espana)", .input = {.file = "AutoStoryLanguageList/1_es-ES.png"}, .expectation = {.language_entry = 1}}, + {.name = "language list on Espanol (Latinoamerica)", .input = {.file = "AutoStoryLanguageList/2_es-419.png"}, .expectation = {.language_entry = 2}}, + {.name = "language list on Francais", .input = {.file = "AutoStoryLanguageList/3_fr.png"}, .expectation = {.language_entry = 3}}, + {.name = "language list on Deutsch", .input = {.file = "AutoStoryLanguageList/4_de.png"}, .expectation = {.language_entry = 4}}, + {.name = "language list on Italiano", .input = {.file = "AutoStoryLanguageList/5_it.png"}, .expectation = {.language_entry = 5}}, + {.name = "language list on Japanese", .input = {.file = "AutoStoryLanguageList/6_ja.png"}, .expectation = {.language_entry = 6}}, + {.name = "language list on Korean", .input = {.file = "AutoStoryLanguageList/7_ko.png"}, .expectation = {.language_entry = 7}}, + {.name = "language list on Simplified Chinese", .input = {.file = "AutoStoryLanguageList/8_zh-Hans.png"}, .expectation = {.language_entry = 8}}, + {.name = "language list on Traditional Chinese", .input = {.file = "AutoStoryLanguageList/9_zh-Hant.png"}, .expectation = {.language_entry = 9}}, + {.name = "look picker as it opens", .input = {.file = "AutoStoryLookPicker/English_1_0.png"}, .expectation = {.look_picker = true}}, + {.name = "look picker on look 3", .input = {.file = "AutoStoryLookPicker/English_2_3.png"}, .expectation = {.look_picker = true, .look = 3}}, + {.name = "look picker on look 7", .input = {.file = "AutoStoryLookPicker/German_2_7.png"}, .expectation = {.look_picker = true, .look = 7}}, + {.name = "look picker on look 6 in Japanese", .input = {.file = "AutoStoryLookPicker/Japanese_2_6.png"}, .expectation = {.look_picker = true, .look = 6}}, + {.name = "keyboard in German", .input = {.file = "AutoStoryNameKeyboard/de_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Spanish (Spain)", .input = {.file = "AutoStoryNameKeyboard/es-ES_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Latin American Spanish", .input = {.file = "AutoStoryNameKeyboard/es-419_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in French", .input = {.file = "AutoStoryNameKeyboard/fr_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Italian", .input = {.file = "AutoStoryNameKeyboard/it_12.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "keyboard in Japanese", .input = {.file = "AutoStoryNameKeyboard/ja_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "keyboard in Korean", .input = {.file = "AutoStoryNameKeyboard/ko_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "keyboard in Simplified Chinese", .input = {.file = "AutoStoryNameKeyboard/zh-Hans_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "keyboard in Traditional Chinese", .input = {.file = "AutoStoryNameKeyboard/zh-Hant_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "Confirm Choices is none of them", .input = {.file = "AutoStoryConfirmChoices/German_0.png"}, .expectation = {}}, +}; + +class Test_IntroScreenFrame : public ImageUnitTest{ +public: + explicit Test_IntroScreenFrame(const FrameCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - intro screens: {}", test.name), + {std::format("PokemonLZA/{}", test.input.file)} + ) + , m_test(test) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32& frame = images[0]; + const FrameCase::Expectation& expected = m_test.expectation; + const std::optional entry = read_language_list_cursor(frame); + if (entry != expected.language_entry){ + return std::format("Language list: expected entry {}, read {}.", describe(expected.language_entry), describe(entry)); + } + if (is_look_picker(frame) != expected.look_picker){ + return std::format("Look picker: expected {}, read {}.", expected.look_picker, !expected.look_picker); + } + const std::optional look = read_look_picker_cursor(frame); + if (look != expected.look){ + return std::format("Look picker: expected look {}, read {}.", describe(expected.look), describe(look)); + } + if (is_name_keyboard(frame) != expected.keyboard){ + return std::format("Name keyboard: expected {}, read {}.", expected.keyboard, !expected.keyboard); + } + if (expected.keyboard){ + const std::optional limit = read_name_keyboard_limit(frame); + if (limit != expected.name_limit){ + return std::format("Name keyboard: expected a limit of {}, read {}.", describe(expected.name_limit), describe(limit)); + } + } + return true; + } + +private: + const FrameCase& m_test; +}; + + +// Confirm Choices' name and language, read with OCR. The console's frames +// were taken with the name "q". +class Test_ConfirmChoicesProfile : public ImageUnitTest{ +public: + Test_ConfirmChoicesProfile() + : ImageUnitTest( + "PokemonLZA::AutoStory - intro screens: Confirm Choices shows the name and language", + {"PokemonLZA/AutoStoryConfirmChoices/English_0.png"} + ) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const std::string name = read_confirm_choices_name(images[0]); + if (name != "q"){ + return std::format("Expected the name \"q\", read \"{}\".", name); + } + const std::string language = read_confirm_choices_language(images[0], Language::English); + if (language.find("English") == std::string::npos){ + return std::format("Expected the language \"English\", read \"{}\".", language); + } + return true; + } +}; + +} // namespace + + +void add_tests_AutoStoryIntroScreens(UnitTestDatabase& database){ + for (const FrameCase& test : FRAME_CASES){ + database.add(test); + } + database.add(); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h new file mode 100644 index 0000000000..803a8cb509 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h @@ -0,0 +1,27 @@ +/* PokemonLZA AutoStory - New game intro screens Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the intro screen readers' tests on the console's frames +// (PokemonLZA/AutoStoryLanguageList/, AutoStoryLookPicker/, +// AutoStoryNameKeyboard/ and AutoStoryConfirmChoices/ in the test images). +void add_tests_AutoStoryIntroScreens(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index e8ccbd48d9..e1e4808980 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -5,6 +5,7 @@ */ #include +#include #include #include #include @@ -14,7 +15,7 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/Pokemon_Strings.h" -#include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" +#include "Actions/PokemonLZA_AutoStoryNewGame.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStory.h" @@ -32,8 +33,9 @@ AutoStory_Descriptor::AutoStory_Descriptor() std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", "Play the main story of Pokemon Legends: Z-A. Prototype: from a new game to the end of Main Mission 01, picking Chikorita. " - "Start a new game and pick its language, look and name by hand: checkpoint 01.00 starts on the Confirm Choices screen that follows. " - "It checks that screen, presses nothing anywhere else, and picks Ready!. Later checkpoints load the latest save first, unless that is turned off.", + "Checkpoint 01.00 starts a new game (delete the save first) from the HOME screen with the game closed and its tile selected, " + "from the language list, or from Confirm Choices, with the language, look and name below. " + "Later checkpoints load the latest save first, unless that is turned off.", PanelQualityStanding::DEVELOPER, ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, @@ -68,12 +70,40 @@ void check_checkpoint_range(ConsoleHandle& console, size_t first, size_t last, s } } +// The game language dropdown's entries, in the language list's order. +const EnumDropdownDatabase& new_game_language_database(){ + static const EnumDropdownDatabase database{ + {NewGameLanguage::English, "en", "English"}, + {NewGameLanguage::SpanishSpain, "es-ES", "Espa\xc3\xb1ol (Espa\xc3\xb1" "a)"}, + {NewGameLanguage::SpanishLatinAmerica, "es-419", "Espa\xc3\xb1ol (Latinoam\xc3\xa9rica)"}, + {NewGameLanguage::French, "fr", "Fran\xc3\xa7" "ais"}, + {NewGameLanguage::German, "de", "Deutsch"}, + {NewGameLanguage::Italian, "it", "Italiano"}, + {NewGameLanguage::Japanese, "ja", "Japanese"}, + {NewGameLanguage::Korean, "ko", "Korean (not supported yet)"}, + {NewGameLanguage::ChineseSimplified, "zh-Hans", "Chinese (Simplified)"}, + {NewGameLanguage::ChineseTraditional, "zh-Hant", "Chinese (Traditional)"}, + }; + return database; +} + +// Throws UserSetupError, before any press, if a run from `first_row` plays +// a new game that `choices` cannot. +void check_new_game_choices(ConsoleHandle& console, const StoryCheckpoint& first_row, const NewGameChoices& choices){ + if (!story_row_starts_without_save(first_row)){ + return; + } + if (const std::optional problem = new_game_problem(choices)){ + throw UserSetupError(console, *problem); + } +} + // Connects the controller for a run from `first_row`. 01.00 starts on a // screen that proves the save is fresh, so it is checked before any press, // the connect press included. void connect_controller(ConsoleHandle& console, ProControllerContext& context, const StoryCheckpoint& first_row){ if (story_row_starts_without_save(first_row)){ - require_confirm_choices(console, context); + require_new_game_start(console, context); } require_player(console, context, BUTTON_L); } @@ -83,6 +113,25 @@ void connect_controller(ConsoleHandle& console, ProControllerContext& context, c AutoStory::AutoStory() : RANGE("Checkpoints", checkpoint_database()) + , GAME_LANGUAGE( + "Game Language:
01.00 picks it on the new game's language list.", + new_game_language_database(), + LockMode::LOCK_WHILE_RUNNING, + NewGameLanguage::English + ) + , PLAYER_LOOK( + "Player Look:
01.00 picks it on the look picker: 1 to 4 along the top row, 5 to 8 along the bottom.", + LockMode::LOCK_WHILE_RUNNING, + 1, 1, 8 + ) + , PLAYER_NAME( + /*is_password=*/false, "Player Name:
Letters, digits and - / : ' , . ? ! (the keyboard's first page); at most 12 characters, 6 in Japanese and Chinese.", + LockMode::LOCK_WHILE_RUNNING, /*default_value=*/"Kosmos", /*placeholder_text=*/"Kosmos" + ) + , CAPTURE_INTRO_SCREENS( + "Developer: capture intro screens:
Instead of the story: for each language, close the game, launch it from HOME and save its screens up to the name keyboard to the Screenshots folder. Nothing is typed, so no save is made.", + LockMode::LOCK_WHILE_RUNNING, /*default_value=*/false + ) , ATTEMPTS_PER_CHECKPOINT( "Attempts per Checkpoint:
A failed checkpoint that started from a save reloads it and tries again, up to this many times in all.", LockMode::LOCK_WHILE_RUNNING, @@ -102,6 +151,10 @@ AutoStory::AutoStory() }) { PA_ADD_OPTION(RANGE); + PA_ADD_OPTION(GAME_LANGUAGE); + PA_ADD_OPTION(PLAYER_LOOK); + PA_ADD_OPTION(PLAYER_NAME); + PA_ADD_OPTION(CAPTURE_INTRO_SCREENS); PA_ADD_OPTION(ATTEMPTS_PER_CHECKPOINT); PA_ADD_OPTION(LOAD_SAVE_FIRST); PA_ADD_OPTION(BATTLE_AI); @@ -110,14 +163,21 @@ AutoStory::AutoStory() } void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + if (CAPTURE_INTRO_SCREENS){ + require_player(env.console, context, BUTTON_L); + capture_intro_screens(env.console, context, PLAYER_LOOK); + return; + } + const NewGameChoices new_game{.language = GAME_LANGUAGE, .look = PLAYER_LOOK, .name = PLAYER_NAME}; const StoryData& story_data = builtin_story_data(); const std::vector& rows = story_data.checkpoints; const size_t first = RANGE.start_index(); const size_t last = RANGE.end_index(); check_checkpoint_range(env.console, first, last, rows.size()); + check_new_game_choices(env.console, rows[first], new_game); connect_controller(env.console, context, rows[first]); - StoryEnv story{.env = env, .context = context, .battle_ai = BATTLE_AI}; + StoryEnv story{.env = env, .context = context, .battle_ai = BATTLE_AI, .new_game = new_game}; PlzaConsoleBackend backend(story); const StoryGame game = make_plza_story_game(story, story_data); StoryEngine engine(game, backend); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index f140022d0f..8da8039099 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -12,12 +12,15 @@ #define PokemonAutomation_PokemonLZA_AutoStory_H #include "Common/Cpp/Options/BooleanCheckBoxOption.h" +#include "Common/Cpp/Options/EnumDropdownOption.h" #include "Common/Cpp/Options/SimpleIntegerOption.h" +#include "Common/Cpp/Options/StringOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/AutoStory/Options/Pokemon_StoryRangeOptions.h" #include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -42,6 +45,10 @@ class AutoStory : public SingleSwitchProgramInstance{ private: Pokemon::StoryRangeOptions RANGE; + EnumDropdownOption GAME_LANGUAGE; + SimpleIntegerOption PLAYER_LOOK; + StringOption PLAYER_NAME; + BooleanCheckBoxOption CAPTURE_INTRO_SCREENS; SimpleIntegerOption ATTEMPTS_PER_CHECKPOINT; BooleanCheckBoxOption LOAD_SAVE_FIRST; BattleAIOption BATTLE_AI; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h index dc815b9791..912d6c0208 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -23,6 +23,7 @@ #include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h" #include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h" @@ -42,6 +43,8 @@ struct StoryEnv{ SingleSwitchProgramEnvironment& env; ProControllerContext& context; BattleAIOption& battle_ai; + // 01.00's new game: the language, look and name to pick. + NewGameChoices new_game = {}; }; // The engine's backend for PLZA's pose. diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 0da8a49478..dccf6b8f7d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -7,6 +7,7 @@ #include #include #include +#include #include #include #include @@ -25,6 +26,7 @@ #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h" #include "PokemonLZA_AutoStoryReadings.h" @@ -77,6 +79,7 @@ StoryActionSpec console_only(StoryActionSpec spec){ // The GAME actions that run only on a console. std::vector console_specs(){ return { + console_only(game_spec("new_game_intro")), 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"), @@ -156,21 +159,21 @@ Outcome reload_latest_save(StoryEnv& env){ } -// "confirm_new_game" on the console `env`; none: fails as console_only. -// An OperationFailedException becomes a failed Outcome, so the run can -// report it. -Handler confirm_handler(StoryEnv* env){ +// 01.00's new game step `name` on the console `env`, running `step`; +// none: fails as console_only. An OperationFailedException becomes a +// failed Outcome, so the run can report it. +Handler new_game_handler(StoryEnv* env, std::string name, std::function step){ if (env == nullptr){ - return [](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ - return Pokemon::outcome_failed(std::string(Pokemon::CONSOLE_ONLY), "confirm_new_game runs only on a console"); + return [name](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ + return Pokemon::outcome_failed(std::string(Pokemon::CONSOLE_ONLY), name + " runs only on a console"); }; } - return [env](Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + return [env, name, step](Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ try{ - confirm_new_game_choices(env->env.console, env->context); + step(*env); }catch (OperationFailedException& e){ - backend.log(std::format("[PLZA] confirm_new_game failed: {}", e.message())); - return Pokemon::outcome_failed("confirm_new_game_failed", e.message()); + backend.log(std::format("[PLZA] {} failed: {}", name, e.message())); + return Pokemon::outcome_failed(name + "_failed", e.message()); } return Pokemon::outcome_ok(); }; @@ -673,8 +676,15 @@ const std::map& step_functions(){ // The handler of each of plza_story_specs(), by name. Handler plza_handler(StoryEnv* env, const StoryActionSpec& spec){ + if (spec.name == "new_game_intro"){ + return new_game_handler(env, spec.name, [](StoryEnv& story){ + play_new_game_intro(story.env.console, story.context, story.new_game); + }); + } if (spec.name == "confirm_new_game"){ - return confirm_handler(env); + return new_game_handler(env, spec.name, [](StoryEnv& story){ + confirm_new_game_choices(story.env.console, story.context, story.new_game); + }); } if (spec.name == "run_to_gate"){ return gate_run_handler(env); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 09cf45d5d8..16ee0946fc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -36,8 +36,11 @@ namespace PokemonLZA{ // Every action a PLZA checkpoint may name, GAME actions but for "talk": // -// "confirm_new_game" console_only: 01.00's first step, on the new -// game's "Confirm Choices" (confirm_new_game_choices()) +// "new_game_intro" console_only: 01.00's first step, from HOME or +// the language list to "Confirm Choices" +// (play_new_game_intro()) +// "confirm_new_game" console_only: on the new game's "Confirm +// Choices" (confirm_new_game_choices()) // "opening_to_platform" the opening cutscene until the autosave badge // has shown and the station platform holds // "wait_for_platform" the station platform holds: a start check 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..246af46e4a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -248,13 +248,18 @@ struct RunCase{ const RunCase RUN_CASES[] = { { - .name = "01.00 stops at Confirm Choices off a console", + .name = "01.00 stops at the new game off a console", .input = {.checkpoint = "01.00", .first_step = 0, .looks = {CUTSCENE}}, + .expectation = {.verdict = "failed at new_game: console_only", .inputs = ""}, + }, + { + .name = "01.00 stops at Confirm Choices off a console", + .input = {.checkpoint = "01.00", .first_step = 1, .looks = {CUTSCENE}}, .expectation = {.verdict = "failed at confirm: console_only", .inputs = ""}, }, { .name = "01.00's opening ends on the platform after the autosave", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {CUTSCENE, PLATFORM, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {CUTSCENE, PLATFORM, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = { .verdict = "done", .inputs = "wait 300ms, wait 300ms, wait 300ms, wait 300ms, wait 300ms", @@ -263,12 +268,12 @@ const RunCase RUN_CASES[] = { }, { .name = "01.00's opening presses A once for the text waiting for it", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {TEXT_FOR_A, TEXT_FOR_A, AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {TEXT_FOR_A, TEXT_FOR_A, AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = {.verdict = "done", .inputs = "press A, wait 300ms, wait 300ms, wait 300ms, wait 300ms"}, }, { .name = "01.00's opening fails with no autosave", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {PLATFORM}}, .expectation = {.verdict = "failed at opening: platform_not_seen"}, }, { @@ -441,7 +446,7 @@ const RunCase RUN_CASES[] = { }, { .name = "01.00 ends on its autosave", - .input = {.checkpoint = "01.00", .first_step = 1, .looks = {AUTOSAVE, PLATFORM, PLATFORM}}, + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {AUTOSAVE, PLATFORM, PLATFORM}}, .expectation = {.verdict = "done", .line = "[Save] 01.00: the game autosaved at its end"}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index a0ac9d043e..f010a83691 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -16,7 +16,7 @@ bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row){ return false; } const Pokemon::StoryStep& first = row.steps.front(); - return first.kind == Pokemon::StoryStepKind::GAME && first.action == "confirm_new_game"; + return first.kind == Pokemon::StoryStepKind::GAME && (first.action == "new_game_intro" || first.action == "confirm_new_game"); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index 58337eaf08..d02c9c624f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -30,9 +30,9 @@ namespace PokemonLZA{ // execution marks (Pokemon_StoryRowExecution.h). using StoryData = Pokemon::StoryData; -// Whether `row` starts with no save to load: it starts on the new game's -// "Confirm Choices" screen, the language, look and name chosen by hand -// (its first step is the GAME action "confirm_new_game"): 01.00. +// Whether `row` starts with no save to load: it starts a new game (its +// first step is the GAME action "new_game_intro", or "confirm_new_game" +// on "Confirm Choices"): 01.00. bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json index 07a5ccae00..43033888a4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json @@ -3,12 +3,18 @@ "game": "plza", "checkpoint": { "id": "01.00", - "title": "New game from Confirm Choices to the station platform", + "title": "New game to the station platform", "events": [ + { + "id": "new_game", + "kind": "game_action", + "why": "from HOME (the game closed, no save) launch the selected tile, then the language list, the look picker and the name keyboard with the panel's choices; on Confirm Choices already, nothing", + "action": "new_game_intro" + }, { "id": "confirm", "kind": "game_action", - "why": "the language, look and name were chosen by hand and Confirm Choices shows (so the save is fresh): check that screen with no press (anything else is a setup error), then DOWN to Ready!, reading the highlight after each, and A", + "why": "Confirm Choices shows (so the save is fresh): check that screen with no press (anything else is a setup error) and that it shows the panel's name and language, then DOWN to Ready!, reading the highlight after each, and A", "action": "confirm_new_game" }, { diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 440a6f6b3b..8e04fa9b4f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2322,6 +2322,14 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -2350,6 +2358,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.cpp From ff2c7f52cc92392dd5dba3dc477916da87521a4b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 20:34:13 -0800 Subject: [PATCH 03/24] PLZA AutoStory 01.00: intro as the console showed it; name typed with #62's typer - Launch: no blind A presses after the user select; wait up to 60 s for the language list (about 15 s of logos on the console, 2026-11-15). - Language list: D-pad taps 600 ms apart. - Look picker: tilt left (150 ms) until a highlight reads, since the first tilt lands on a different portrait each launch; A only once the target reads. - Name: type_on_system_keyboard() (switch/system-keyboard), Simplified Chinese switched to letters first; + until Confirm Choices shows (Chinese takes one + to accept the text, one to submit). - Drop the blind name typer (PokemonLZA_AutoStoryNameKeys) and its tests; new_game_problem() checks the name against the typer's key map. - Revert this PR's CommandLineTests pin bump. - Tests on the 2026-11-15 frames: language list, look highlight (10), keyboard counter (10), the system keyboard reader (9), Confirm Choices (12). --- .../workflows/cpp-ci-serial-programs-base.yml | 5 +- .../Actions/PokemonLZA_AutoStoryNameKeys.cpp | 101 ----------- .../Actions/PokemonLZA_AutoStoryNameKeys.h | 46 ----- .../Actions/PokemonLZA_AutoStoryNewGame.cpp | 163 ++++++++++++------ .../Actions/PokemonLZA_AutoStoryNewGame.h | 12 +- .../PokemonLZA_AutoStoryNewGameChoices.cpp | 19 +- .../PokemonLZA_AutoStoryNewGameChoices.h | 20 +-- .../PokemonLZA_AutoStoryNewGame_Tests.cpp | 73 +------- ...PokemonLZA_AutoStoryIntroScreens_Tests.cpp | 158 ++++++++++++++++- SerialPrograms/cmake/SourceFiles.cmake | 2 - 10 files changed, 305 insertions(+), 294 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 169e0461b9..289cc28931 100644 --- a/.github/workflows/cpp-ci-serial-programs-base.yml +++ b/.github/workflows/cpp-ci-serial-programs-base.yml @@ -246,10 +246,9 @@ 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, - # the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language), - # and the new game's language list and name keyboard (branch plza/new-game-intro). + # and the 01.01 banner and controls hint in English and Italian (branch plza/hint-banner-any-language). repository: 'dayfine/CommandLineTests' - ref: '36d2d9cc3a9f82058d02e656184e9fde5e87113b' + ref: '2abde09b6bfdf9ae1b372b04c0e6265dc8559556' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp deleted file mode 100644 index a08eb7ba6f..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp +++ /dev/null @@ -1,101 +0,0 @@ -/* PokemonLZA AutoStory - Name keys - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include "PokemonLZA_AutoStoryNameKeys.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -namespace{ - -// The first page's character rows, as the header draws them. -constexpr std::string_view KEY_ROWS[] = { - "1234567890-", - "qwertyuiop/", - "asdfghjkl:'", - "zxcvbnm,.?!", -}; -constexpr size_t BOTTOM_ROW = 4; - -// Simplified Chinese's "English" mode key: the bottom row's fourth key, -// under "4". -constexpr size_t ENGLISH_MODE_COLUMN = 3; - -struct KeyPosition{ - size_t row = 0; - size_t col = 0; -}; - -std::optional key_position(char lower){ - for (size_t row = 0; row < std::size(KEY_ROWS); row++){ - const size_t col = KEY_ROWS[row].find(lower); - if (col != std::string_view::npos){ - return KeyPosition{.row = row, .col = col}; - } - } - return std::nullopt; -} - -// Across, then up or down; but up first off the bottom row, whose keys -// are wider than a column: "English" is the fourth key along it, and the -// key above it is "4" (the frames). -void move_to(std::vector& presses, KeyPosition& cursor, KeyPosition target){ - for (; cursor.row == BOTTOM_ROW && cursor.row > target.row; cursor.row--){ - presses.push_back(IntroKey::UP); - } - for (; cursor.col < target.col; cursor.col++){ - presses.push_back(IntroKey::RIGHT); - } - for (; cursor.col > target.col; cursor.col--){ - presses.push_back(IntroKey::LEFT); - } - for (; cursor.row < target.row; cursor.row++){ - presses.push_back(IntroKey::DOWN); - } - for (; cursor.row > target.row; cursor.row--){ - presses.push_back(IntroKey::UP); - } -} - -} // namespace - - -std::optional> name_key_presses(std::string_view name, NewGameLanguage language){ - if (name.empty()){ - return std::nullopt; - } - std::vector presses; - KeyPosition cursor; - if (language == NewGameLanguage::ChineseSimplified){ - move_to(presses, cursor, KeyPosition{.row = BOTTOM_ROW, .col = 0}); - move_to(presses, cursor, KeyPosition{.row = BOTTOM_ROW, .col = ENGLISH_MODE_COLUMN}); - presses.push_back(IntroKey::A); - } - for (const char ch : name){ - const unsigned char byte = (unsigned char)ch; - const std::optional target = key_position((char)std::tolower(byte)); - if (byte >= 0x80 || !target){ - return std::nullopt; - } - move_to(presses, cursor, *target); - if (std::isupper(byte)){ - presses.push_back(IntroKey::SHIFT); - } - presses.push_back(IntroKey::A); - } - presses.push_back(IntroKey::PLUS); - return presses; -} - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h deleted file mode 100644 index 422332786a..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h +++ /dev/null @@ -1,46 +0,0 @@ -/* PokemonLZA AutoStory - Name keys - * - * From: https://github.com/PokemonAutomation/ - * - * The player's name as presses on the Switch's name keyboard, a pure - * function on a model of its key grid (the console's frames in nine - * languages, 2026-11-13). Its first page has four rows of 11 keys: - * - * 1 2 3 4 5 6 7 8 9 0 - - * q w e r t y u i o p / - * a s d f g h j k l : ' - * z x c v b n m , . ? ! - * - * and a bottom row (globe, Shift, the keyboard's modes, Space). The cursor - * starts on "1". Letters type lower case; Shift (a left stick click) makes - * the next letter a capital. Simplified Chinese opens in Pinyin mode: its - * bottom row's fourth key ("English") switches to letters first. - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryNameKeys_H -#define PokemonAutomation_PokemonLZA_AutoStoryNameKeys_H - -#include -#include -#include -#include "PokemonLZA_AutoStoryNewGameChoices.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// The presses that type `name` on the keyboard of `language` and press OK -// (PLUS): per character D-pad moves from the last key (across, then up or -// down; never round an edge), SHIFT before a capital, then A. Nullopt for -// an empty name or a character with no key on the first page (a space -// included). -std::optional> name_key_presses(std::string_view name, NewGameLanguage language); - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp index ca2cb631fb..e6fddf280e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp @@ -16,10 +16,11 @@ #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" #include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" -#include "PokemonLZA_AutoStoryNameKeys.h" #include "PokemonLZA_AutoStoryNewGame.h" namespace PokemonAutomation{ @@ -33,15 +34,23 @@ using FrameCheck = std::function; constexpr std::string_view DUMP_FOLDER = "PokemonLZA/AutoStory/Intro"; -// From the launch to the language list (the boot, logos, prompts): no -// press for LAUNCH_QUIET, then A at most LAUNCH_A_PRESSES times, -// LAUNCH_A_EVERY apart, on any screen that is not the list, until -// LAUNCH_LIMIT. With no save the game goes straight to the list (the -// console, 2026-11-09); the A presses are for a prompt in between. -constexpr Milliseconds LAUNCH_QUIET = 30000ms; -constexpr Milliseconds LAUNCH_A_EVERY = 6000ms; -constexpr size_t LAUNCH_A_PRESSES = 5; -constexpr Milliseconds LAUNCH_LIMIT = 90000ms; +// From the user select to the language list: about 15 s of logos, with no +// press needed (the console, 2026-11-15, all ten languages). +constexpr Milliseconds LAUNCH_LIMIT = 60000ms; + +// The language list's D-pad taps: each registered at this pace (the +// console, 2026-11-15). +constexpr Milliseconds LANGUAGE_TAP_RELEASE = 600ms; + +// The look picker's stick tilts: one portrait each. +constexpr Milliseconds LOOK_TILT_HOLD = 150ms; +constexpr Milliseconds LOOK_TILT_RELEASE = 500ms; + +// The + presses after the name. One submits the European languages' and +// Japanese's keyboard; the Chinese ones first take one to accept the typed +// text (the button reads "Accept"), then one to submit. Each is checked. +constexpr size_t SUBMIT_PRESSES = 3; +constexpr Milliseconds SUBMIT_WAIT = 5000ms; // Capture mode: a frame this far (pixel RMSD) from the last saved one is // a new screen. @@ -72,7 +81,7 @@ bool wait_for_frame(ConsoleHandle& console, ProControllerContext& context, const OperationFailedExceptionWithScreenshot::fire(ErrorReportMode::SEND_ERROR_REPORT, std::format("AutoStory intro: {}", message), console); } -void press(ConsoleHandle& console, ProControllerContext& context, IntroKey key, Milliseconds release){ +void press(ProControllerContext& context, IntroKey key, Milliseconds release){ switch (key){ case IntroKey::UP: pbf_press_dpad(context, DPAD_UP, /*hold=*/80ms, release); @@ -89,13 +98,6 @@ void press(ConsoleHandle& console, ProControllerContext& context, IntroKey key, case IntroKey::A: pbf_press_button(context, BUTTON_A, /*hold=*/80ms, release); break; - case IntroKey::SHIFT: - pbf_press_button(context, BUTTON_LCLICK, /*hold=*/80ms, release); - break; - case IntroKey::PLUS: - console.log("AutoStory intro: keyboard: PLUS (OK)."); - pbf_press_button(context, BUTTON_PLUS, /*hold=*/80ms, release); - break; } } @@ -104,16 +106,16 @@ void press(ConsoleHandle& console, ProControllerContext& context, IntroKey key, void tilt(ProControllerContext& context, IntroKey key){ switch (key){ case IntroKey::UP: - pbf_move_left_joystick(context, /*position=*/{0, +1}, /*hold=*/200ms, /*release=*/500ms); + pbf_move_left_joystick(context, /*position=*/{0, +1}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); break; case IntroKey::DOWN: - pbf_move_left_joystick(context, /*position=*/{0, -1}, /*hold=*/200ms, /*release=*/500ms); + pbf_move_left_joystick(context, /*position=*/{0, -1}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); break; case IntroKey::LEFT: - pbf_move_left_joystick(context, /*position=*/{-1, 0}, /*hold=*/200ms, /*release=*/500ms); + pbf_move_left_joystick(context, /*position=*/{-1, 0}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); break; case IntroKey::RIGHT: - pbf_move_left_joystick(context, /*position=*/{+1, 0}, /*hold=*/200ms, /*release=*/500ms); + pbf_move_left_joystick(context, /*position=*/{+1, 0}, LOOK_TILT_HOLD, LOOK_TILT_RELEASE); break; default: break; @@ -128,15 +130,14 @@ void launch_from_home(ConsoleHandle& console, ProControllerContext& context){ start_game_from_home(console, context, /*tolerate_update_menu=*/true, /*game_slot=*/0, /*user_slot=*/0); } -// After the launch, until the language list (tolerant: see LAUNCH_QUIET). -// `recorder` and `language`: capture mode, save each new screen on the way. +// After the launch, until the language list, pressing nothing (see +// LAUNCH_LIMIT). `recorder` and `language`: capture mode, save each new +// screen on the way. void wait_for_language_list( ConsoleHandle& console, ProControllerContext& context, IntroFrameRecorder* recorder, NewGameLanguage language ){ const WallClock start = current_time(); - size_t a_presses = 0; - WallClock next_a = start + LAUNCH_QUIET; std::optional last_saved; while (current_time() - start < LAUNCH_LIMIT){ const VideoSnapshot frame = snapshot(console, context); @@ -157,19 +158,14 @@ void wait_for_language_list( last_saved = frame->copy(); } } - if (current_time() >= next_a && a_presses < LAUNCH_A_PRESSES){ - a_presses++; - console.log(std::format("AutoStory intro: no language list yet; A ({} of {}).", a_presses, LAUNCH_A_PRESSES)); - pbf_press_button(context, BUTTON_A, /*hold=*/80ms, /*release=*/500ms); - next_a = current_time() + LAUNCH_A_EVERY; - } context.wait_for(250ms); } fail(console, std::format("the language list did not show within {} s of the launch.", LAUNCH_LIMIT.count() / 1000)); } -// On the language list: one press at a time to `language`, reading the -// highlight after each, then A. +// On the language list (it opens on English): one tap at a time to +// `language`, reading the highlight after each, then A, which opens the +// look picker with no confirmation. void pick_language(ConsoleHandle& console, ProControllerContext& context, NewGameLanguage language){ const NewGameLanguageInfo& info = new_game_language_info(language); for (size_t attempt = 0; attempt < 20; attempt++){ @@ -181,14 +177,14 @@ void pick_language(ConsoleHandle& console, ProControllerContext& context, NewGam } if (*cursor == info.list_entry){ console.log(std::format("AutoStory intro: language {} (entry {}): A.", info.tag, info.list_entry)); - press(console, context, IntroKey::A, 500ms); + press(context, IntroKey::A, 500ms); return; } const std::optional> moves = language_list_moves(*cursor, info.list_entry); if (!moves || moves->empty()){ break; } - press(console, context, moves->front(), 400ms); + press(context, moves->front(), LANGUAGE_TAP_RELEASE); } fail(console, std::format("the language list's highlight did not reach {}.", info.tag)); } @@ -209,9 +205,12 @@ std::optional read_settled_look(ConsoleHandle& console, ProControllerCon return std::nullopt; } -// On the look picker (it opens with no portrait highlighted; a tilt -// brings the highlight up): tilts toward `look`, reading the highlight -// after each, then A. +// On the look picker: it opens with no portrait highlighted, and the first +// tilt highlights one that differs from launch to launch (the console, +// 2026-11-15: looks 1, 2, 5, 6, 7 and 8 after a tilt left). So it tilts +// left until a highlight reads, then toward `look`, reading the highlight +// after each tilt, and presses A only once it reads `look` (A opens the +// name keyboard). void pick_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ if (!wait_for_frame(console, context, is_look_picker, 20000ms)){ fail(console, "the look picker did not show within 20 s of the language's A."); @@ -225,12 +224,12 @@ void pick_look(ConsoleHandle& console, ProControllerContext& context, size_t loo const std::optional cursor = read_settled_look(console, context); if (!cursor){ unread++; - tilt(context, IntroKey::UP); + tilt(context, IntroKey::LEFT); continue; } if (*cursor == look){ console.log(std::format("AutoStory intro: look {}: A.", look)); - press(console, context, IntroKey::A, 500ms); + press(context, IntroKey::A, 500ms); return; } const std::optional> moves = look_picker_moves(*cursor, look); @@ -251,9 +250,10 @@ void wait_for_keyboard(ConsoleHandle& console, ProControllerContext& context){ context.wait_for(1000ms); } -// On the keyboard: checks its counter, then types the name and OK. -void type_name(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ - wait_for_keyboard(console, context); +// The keyboard's "0/N" counter (12 in the European languages, 6 in +// Japanese, Korean and Chinese): throws UserSetupError, nothing typed, if +// the name is longer. +void check_name_limit(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ const VideoSnapshot frame = snapshot(console, context); if (frame){ dump_debug_image(console, std::string(DUMP_FOLDER), "keyboard", frame); @@ -269,15 +269,73 @@ void type_name(ConsoleHandle& console, ProControllerContext& context, const NewG }else{ console.log(std::format("AutoStory intro: keyboard: takes {} characters.", *limit)); } - const std::optional> presses = name_key_presses(choices.name, choices.language); - if (!presses){ - throw UserSetupError(console, std::format("AutoStory: the player name \"{}\" cannot be typed.", choices.name)); +} + +// Simplified Chinese's keyboard opens in Pinyin, where letters compose +// Chinese; the bottom row's English key, under column 3, switches it to +// letters (Traditional Chinese's opens on letters). Moves the cursor +// there one D-pad tap at a time, reading it after each, then A. +void switch_to_letters(ConsoleHandle& console, ProControllerContext& context){ + constexpr SystemKeyboardKey LETTERS_KEY{.row = 4, .col = 3}; + for (size_t attempt = 0; attempt < 16; attempt++){ + const VideoSnapshot frame = snapshot(console, context); + const std::optional cursor = frame ? read_system_keyboard_cursor(frame) : std::nullopt; + if (!cursor){ + context.wait_for(300ms); + continue; + } + if (*cursor == LETTERS_KEY){ + console.log("AutoStory intro: keyboard: English (letters) key: A."); + press(context, IntroKey::A, 400ms); + return; + } + if (cursor->col == 11 || cursor->col > LETTERS_KEY.col){ + press(context, IntroKey::LEFT, 300ms); + }else if (cursor->row < LETTERS_KEY.row){ + press(context, IntroKey::DOWN, 300ms); + }else{ + press(context, IntroKey::RIGHT, 300ms); + } + } + fail(console, "the keyboard's cursor did not reach the English (letters) key."); +} + +// After the name: + until Confirm Choices shows, checking the screen after +// each press (see SUBMIT_PRESSES). +void submit_name(ConsoleHandle& console, ProControllerContext& context){ + const FrameCheck confirm_choices = [](const ImageViewRGB32& frame){ + return read_confirm_choices_cursor(frame).has_value(); + }; + for (size_t pressed = 1; pressed <= SUBMIT_PRESSES; pressed++){ + console.log(std::format("AutoStory intro: keyboard: + ({} of at most {}).", pressed, SUBMIT_PRESSES)); + pbf_press_button(context, BUTTON_PLUS, /*hold=*/80ms, /*release=*/500ms); + if (wait_for_frame(console, context, confirm_choices, SUBMIT_WAIT)){ + console.log("AutoStory intro: Confirm Choices shows."); + return; + } + const VideoSnapshot frame = snapshot(console, context); + if (!frame || !is_name_keyboard(frame)){ + break; + } + console.log("AutoStory intro: keyboard: still open after +."); + } + if (!wait_for_frame(console, context, confirm_choices, 15000ms)){ + fail(console, "Confirm Choices did not show after the name's +."); } - console.log(std::format("AutoStory intro: typing \"{}\" ({} presses).", choices.name, presses->size())); - for (const IntroKey key : *presses){ - press(console, context, key, key == IntroKey::A ? 400ms : 250ms); +} + +// On the keyboard: checks its counter, types the name with the Switch +// keyboard typer (which reads the cursor before each key and checks each +// press reached the field), then submits it. +void type_name(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices){ + wait_for_keyboard(console, context); + check_name_limit(console, context, choices); + if (choices.language == NewGameLanguage::ChineseSimplified){ + switch_to_letters(console, context); } - context.wait_for_all_requests(); + console.log(std::format("AutoStory intro: typing \"{}\".", choices.name)); + FastCodeEntry::type_on_system_keyboard(console, context, choices.name); + submit_name(console, context); } // Capture mode: the screen now as `language`'s `screen`. @@ -346,9 +404,6 @@ void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, pick_language(console, context, choices.language); pick_look(console, context, choices.look); type_name(console, context, choices); - if (!wait_for_frame(console, context, [](const ImageViewRGB32& frame){ return read_confirm_choices_cursor(frame).has_value(); }, 15000ms)){ - fail(console, "Confirm Choices did not show within 15 s of the name's OK."); - } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h index 65a4e0dcef..5ecc490465 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h @@ -38,11 +38,13 @@ NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext // 01.00's first step: from HOME (the selected tile launched, never moving // HOME's cursor) or the language list, plays the language, the look and // the name of `choices` up to "Confirm Choices"; on "Confirm Choices" it -// presses nothing. Throws UserSetupError before any press if `choices` -// cannot be played (new_game_problem()) or the keyboard's counter takes -// fewer characters than the name, OperationFailedException (with a -// screenshot) if a screen does not show or its highlight does not reach -// the choice. +// presses nothing. Each screen's highlight is read before and after each +// press; the name is typed with the Switch keyboard typer. Throws +// UserSetupError before any press if `choices` cannot be played +// (new_game_problem()) or the keyboard's counter takes fewer characters +// than the name, OperationFailedException (with a screenshot) if a screen +// does not show, its highlight does not reach the choice, or a key press +// does not reach the name's field. void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, const NewGameChoices& choices); // Capture mode's recording of the screens between the launch and the diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp index d9c912fc1e..45aac4ceaa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.cpp @@ -5,8 +5,10 @@ */ #include +#include +#include #include -#include "PokemonLZA_AutoStoryNameKeys.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardEntryMappings.h" #include "PokemonLZA_AutoStoryNewGameChoices.h" namespace PokemonAutomation{ @@ -24,6 +26,19 @@ constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; constexpr size_t LOOK_COLUMNS = 4; constexpr size_t LOOK_COUNT = 2 * LOOK_COLUMNS; +// Whether every character of `name` has a key on the name keyboard's +// first page, which the Switch keyboard typer types (letters by their +// capital). +bool on_keyboard(std::string_view name){ + const std::map& keys = KEYBOARD_POSITIONS(KeyboardLayout::QWERTY); + for (const char ch : name){ + if (!keys.contains((char)std::toupper((unsigned char)ch))){ + return false; + } + } + return true; +} + // The presses from (column, row) `from` to `to` on a grid: across first, // then up or down. std::vector grid_moves(size_t from_column, size_t from_row, size_t to_column, size_t to_row){ @@ -80,7 +95,7 @@ std::optional new_game_problem(const NewGameChoices& choices){ choices.name, choices.name.size(), info.name_limit, info.tag ); } - if (!name_key_presses(choices.name, choices.language)){ + if (!on_keyboard(choices.name)){ return std::format( "AutoStory: the player name \"{}\" has a character that is not on the name keyboard's first page " "(letters, digits and - / : ' , . ? !).", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h index 0621c36c2c..9ff781006a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGameChoices.h @@ -4,8 +4,8 @@ * * The new game's choices (language, look, name) and the presses each takes * on its screen, as pure functions. The screens' readers are in - * Detectors/PokemonLZA_AutoStoryIntroScreens.h; the name's key presses in - * PokemonLZA_AutoStoryNameKeys.h. + * Detectors/PokemonLZA_AutoStoryIntroScreens.h; the name is typed with the + * Switch keyboard typer (NintendoSwitch_SystemKeyboardTyping.h). * */ @@ -48,30 +48,28 @@ struct NewGameLanguageInfo{ // Its entry on the language list (the order of NewGameLanguage). size_t list_entry = 0; // The name keyboard's character limit: its "0/N" counter (the - // console's frames: 12 for the European languages, 6 for Japanese, - // Korean and Chinese; English's is not in the frames and taken as 12). + // console's frames of 2026-11-15: 12 for English and the other + // European languages, 6 for Japanese, Korean and Chinese). size_t name_limit = 0; // The OCR language that reads its name on Confirm Choices. Language ocr_language = Language::None; // A part of its name as Confirm Choices shows it ("Deutsch", "Latino"). std::string_view confirm_text; - // The program can play it (Korean: not yet; its keyboard is Hangul). + // The program can play it (Korean: not yet; its keyboard is Hangul, + // which the Switch keyboard typer does not read). bool supported = true; }; // `language`'s row of the table above. const NewGameLanguageInfo& new_game_language_info(NewGameLanguage language); -// One press on an intro screen. SHIFT is the left stick click (the name -// keyboard's Shift: the next letter is a capital); PLUS the keyboard's OK. +// One press on an intro screen. enum class IntroKey{ UP, DOWN, LEFT, RIGHT, A, - SHIFT, - PLUS, }; // The new game's choices, from the program's options. @@ -80,8 +78,8 @@ struct NewGameChoices{ // 1 to 8: the look picker's portraits, left to right along the top // row, then the bottom one. size_t look = 1; - // Keys of the name keyboard's QWERTY layer (name_key_presses()), at - // most the language's name_limit. + // Letters, digits and the symbols on the name keyboard's first page + // (- / : ' , . ? !), at most the language's name_limit. std::string name = "Kosmos"; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp index 256e49a4f1..6914b2eaa3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp @@ -10,7 +10,6 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" -#include "PokemonLZA_AutoStoryNameKeys.h" #include "PokemonLZA_AutoStoryNewGame.h" #include "PokemonLZA_AutoStoryNewGameChoices.h" #include "PokemonLZA_AutoStoryNewGame_Tests.h" @@ -22,7 +21,7 @@ namespace PokemonLZA{ namespace{ -// Presses as letters: U D L R, A, S for Shift, + for OK. +// Presses as letters: U D L R, A. std::string press_text(const std::optional>& presses){ if (!presses){ return "none"; @@ -45,76 +44,12 @@ std::string press_text(const std::optional>& presses){ case IntroKey::A: text += 'A'; break; - case IntroKey::SHIFT: - text += 'S'; - break; - case IntroKey::PLUS: - text += '+'; - break; } } return text; } -// name_key_presses(): the cursor starts on "1". -struct NameKeysCase{ - std::string name; - struct Input{ - std::string text; - NewGameLanguage language = NewGameLanguage::English; - }; - Input input; - struct Expectation{ - std::string presses; // press_text(); "none" when it cannot be typed. - }; - Expectation expectation; -}; - -const NameKeysCase NAME_KEYS_CASES[] = { - { - .name = "a capital first letter takes Shift; the cursor moves from key to key", - .input = {.text = "Kosmos"}, - .expectation = {.presses = "RRRRRRRDDSA" "RUA" "LLLLLLLDA" "RRRRRDA" "RRUUA" "LLLLLLLDA" "+"}, - }, - {.name = "the starting key takes no move", .input = {.text = "1"}, .expectation = {.presses = "A+"}}, - {.name = "a capital in the middle takes Shift", .input = {.text = "aB"}, .expectation = {.presses = "DDARRRRDSA+"}}, - {.name = "punctuation on the first page", .input = {.text = "-!"}, .expectation = {.presses = "RRRRRRRRRRADDDA+"}}, - { - .name = "Simplified Chinese switches to letters first", - .input = {.text = "ab", .language = NewGameLanguage::ChineseSimplified}, - .expectation = {.presses = "DDDDRRRA" "ULLLUA" "RRRRDA" "+"}, - }, - { - .name = "Traditional Chinese opens on letters", - .input = {.text = "a", .language = NewGameLanguage::ChineseTraditional}, - .expectation = {.presses = "DDA+"}, - }, - {.name = "a space has no key", .input = {.text = "a b"}, .expectation = {.presses = "none"}}, - {.name = "an accented letter is not on the first page", .input = {.text = "Jos\xc3\xa9"}, .expectation = {.presses = "none"}}, - {.name = "a symbol of the second page", .input = {.text = "a#"}, .expectation = {.presses = "none"}}, - {.name = "an empty name", .input = {.text = ""}, .expectation = {.presses = "none"}}, -}; - -class Test_NameKeys : public UnitTest{ -public: - explicit Test_NameKeys(const NameKeysCase& test) - : UnitTest(std::format("PokemonLZA::AutoStory - name keys: {}", test.name)) - , m_test(test) - {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const std::string presses = press_text(name_key_presses(m_test.input.text, m_test.input.language)); - if (presses != m_test.expectation.presses){ - return std::format("\"{}\": expected {}, got {}.", m_test.input.text, m_test.expectation.presses, presses); - } - return true; - } - -private: - const NameKeysCase& m_test; -}; - - // new_game_problem(): whether the program refuses the choices before any // press. struct ProblemCase{ @@ -168,6 +103,9 @@ const ProblemCase PROBLEM_CASES[] = { }, {.name = "an empty name", .input = {.choices = {.name = ""}}, .expectation = {.refused = true}}, {.name = "a space in the name", .input = {.choices = {.name = "Kos mos"}}, .expectation = {.refused = true}}, + {.name = "digits and the first page's symbols", .input = {.choices = {.name = "a1-/:',.?!"}}, .expectation = {.refused = false}}, + {.name = "an accented letter", .input = {.choices = {.name = "Jos\xc3\xa9"}}, .expectation = {.refused = true}}, + {.name = "a symbol of the second page", .input = {.choices = {.name = "a#"}}, .expectation = {.refused = true}}, {.name = "look 8", .input = {.choices = {.look = 8}}, .expectation = {.refused = false}}, {.name = "look 0", .input = {.choices = {.look = 0}}, .expectation = {.refused = true}}, {.name = "look 9", .input = {.choices = {.look = 9}}, .expectation = {.refused = true}}, @@ -353,9 +291,6 @@ class Test_CaptureFile : public UnitTest{ void add_tests_AutoStoryNewGame(UnitTestDatabase& database){ - for (const NameKeysCase& test : NAME_KEYS_CASES){ - database.add(test); - } for (const ProblemCase& test : PROBLEM_CASES){ database.add(test); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp index 2b6bcdf6a7..2b41649702 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp @@ -11,7 +11,9 @@ #include #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" #include "Tests/ImageUnitTest.h" +#include "PokemonLZA_AutoStoryConfirmChoicesReader.h" #include "PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryIntroScreens_Tests.h" @@ -38,6 +40,7 @@ struct FrameCase{ bool look_picker = false; std::optional look = std::nullopt; bool keyboard = false; + // The counter's limit; nullopt: not checked (the field holds text). std::optional name_limit = std::nullopt; }; Expectation expectation; @@ -68,6 +71,39 @@ const FrameCase FRAME_CASES[] = { {.name = "keyboard in Simplified Chinese", .input = {.file = "AutoStoryNameKeyboard/zh-Hans_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, {.name = "keyboard in Traditional Chinese", .input = {.file = "AutoStoryNameKeyboard/zh-Hant_6.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, {.name = "Confirm Choices is none of them", .input = {.file = "AutoStoryConfirmChoices/German_0.png"}, .expectation = {}}, + // The console's frames of 2026-11-15, one launch per language. + {.name = "2026-11-15: the language list opens on English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_langlist.png"}, .expectation = {.language_entry = 0}}, + {.name = "2026-11-15: the language list on Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_langsel.png"}, .expectation = {.language_entry = 1}}, + {.name = "2026-11-15: the language list on Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_langsel.png"}, .expectation = {.language_entry = 2}}, + {.name = "2026-11-15: the language list on Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_langsel.png"}, .expectation = {.language_entry = 3}}, + {.name = "2026-11-15: the language list on Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_langsel.png"}, .expectation = {.language_entry = 4}}, + {.name = "2026-11-15: the language list on Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_langsel.png"}, .expectation = {.language_entry = 5}}, + {.name = "2026-11-15: the language list on Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_langsel.png"}, .expectation = {.language_entry = 6}}, + {.name = "2026-11-15: the language list on Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_langsel.png"}, .expectation = {.language_entry = 7}}, + {.name = "2026-11-15: the language list on Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_langsel.png"}, .expectation = {.language_entry = 8}}, + {.name = "2026-11-15: the language list on Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_langsel.png"}, .expectation = {.language_entry = 9}}, + {.name = "2026-11-15: the look picker before the stick moves", .input = {.file = "AutoStoryNewGame/2026-11-15/en_look.png"}, .expectation = {.look_picker = true}}, + {.name = "2026-11-15: the look picker after the first tilt in English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_look_hl.png"}, .expectation = {.look_picker = true, .look = 6}}, + {.name = "2026-11-15: the look picker after the first tilt in Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_look_hl.png"}, .expectation = {.look_picker = true, .look = 5}}, + {.name = "2026-11-15: the look picker after the first tilt in Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_look_hl.png"}, .expectation = {.look_picker = true, .look = 6}}, + {.name = "2026-11-15: the look picker after the first tilt in Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_look_hl.png"}, .expectation = {.look_picker = true, .look = 1}}, + {.name = "2026-11-15: the look picker after the first tilt in Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_look_hl.png"}, .expectation = {.look_picker = true, .look = 5}}, + {.name = "2026-11-15: the look picker after the first tilt in Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_look_hl.png"}, .expectation = {.look_picker = true, .look = 1}}, + {.name = "2026-11-15: the look picker after the first tilt in Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_look_hl.png"}, .expectation = {.look_picker = true, .look = 7}}, + {.name = "2026-11-15: the look picker after the first tilt in Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_look_hl.png"}, .expectation = {.look_picker = true, .look = 2}}, + {.name = "2026-11-15: the look picker after the first tilt in Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_look_hl.png"}, .expectation = {.look_picker = true, .look = 1}}, + {.name = "2026-11-15: the look picker after the first tilt in Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_look_hl.png"}, .expectation = {.look_picker = true, .look = 8}}, + {.name = "2026-11-15: the keyboard in English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_kb.png"}, .expectation = {.keyboard = true, .name_limit = 12}}, + {.name = "2026-11-15: the keyboard in Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: the keyboard in Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: the keyboard in Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: the keyboard in Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, + {.name = "2026-11-15: Simplified Chinese keeps the keyboard after the first +", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_plus0.png"}, .expectation = {.keyboard = true, .name_limit = std::nullopt}}, }; class Test_IntroScreenFrame : public ImageUnitTest{ @@ -96,7 +132,7 @@ class Test_IntroScreenFrame : public ImageUnitTest{ if (is_name_keyboard(frame) != expected.keyboard){ return std::format("Name keyboard: expected {}, read {}.", expected.keyboard, !expected.keyboard); } - if (expected.keyboard){ + if (expected.keyboard && expected.name_limit){ const std::optional limit = read_name_keyboard_limit(frame); if (limit != expected.name_limit){ return std::format("Name keyboard: expected a limit of {}, read {}.", describe(expected.name_limit), describe(limit)); @@ -133,6 +169,120 @@ class Test_ConfirmChoicesProfile : public ImageUnitTest{ } }; + +// The name keyboard as the Switch's keyboard typer (type_on_system_keyboard()) +// reads it when it opens: the cursor on "1". Every language the program +// types in (Korean is not one). +struct SystemKeyboardCase{ + std::string name; + struct Input{ + std::string file; // Under the test images' PokemonLZA/. + }; + Input input; +}; + +const SystemKeyboardCase SYSTEM_KEYBOARD_CASES[] = { + {.name = "English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_kb.png"}}, + {.name = "Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_kb.png"}}, + {.name = "Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_kb.png"}}, + {.name = "Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_kb.png"}}, + {.name = "Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_kb.png"}}, + {.name = "Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_kb.png"}}, + {.name = "Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_kb.png"}}, + {.name = "Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_kb.png"}}, + {.name = "Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_kb.png"}}, +}; + +class Test_SystemKeyboardOnNameKeyboard : public ImageUnitTest{ +public: + explicit Test_SystemKeyboardOnNameKeyboard(const SystemKeyboardCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - intro screens: the system keyboard reader in {}", test.name), + {std::format("PokemonLZA/{}", test.input.file)} + ) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32& frame = images[0]; + if (!SystemKeyboardDetector().detect(frame)){ + return std::string("The system keyboard was not detected."); + } + const std::optional cursor = read_system_keyboard_cursor(frame); + if (cursor != SystemKeyboardKey{.row = 0, .col = 0}){ + return std::format( + "Expected the cursor on \"1\" (0, 0), read {}.", + cursor ? std::format("({}, {})", cursor->row, cursor->col) : std::string("none") + ); + } + return true; + } +}; + + +// Confirm Choices after the name "1" was typed and submitted (the console's +// frames of 2026-11-15): its highlight, the name, and for the languages +// English OCR reads, a part of the language's name. +struct ConfirmCase{ + std::string name; + struct Input{ + std::string file; // Under the test images' PokemonLZA/. + }; + Input input; + struct Expectation{ + std::string name; + std::optional language; + }; + Expectation expectation; +}; + +const ConfirmCase CONFIRM_CASES[] = { + {.name = "English", .input = {.file = "AutoStoryNewGame/2026-11-15/en_confirm.png"}, .expectation = {.name = "1", .language = "English"}}, + {.name = "Espanol (Espana)", .input = {.file = "AutoStoryNewGame/2026-11-15/esES_confirm.png"}, .expectation = {.name = "1", .language = "Espa"}}, + {.name = "Espanol (Latinoamerica)", .input = {.file = "AutoStoryNewGame/2026-11-15/esLA_confirm.png"}, .expectation = {.name = "1", .language = "Latino"}}, + {.name = "Francais", .input = {.file = "AutoStoryNewGame/2026-11-15/fr_confirm.png"}, .expectation = {.name = "1", .language = "Fran"}}, + {.name = "Deutsch", .input = {.file = "AutoStoryNewGame/2026-11-15/de_confirm.png"}, .expectation = {.name = "1", .language = "Deutsch"}}, + {.name = "Italiano", .input = {.file = "AutoStoryNewGame/2026-11-15/it_confirm.png"}, .expectation = {.name = "1", .language = "Italiano"}}, + {.name = "Japanese", .input = {.file = "AutoStoryNewGame/2026-11-15/ja_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "Korean", .input = {.file = "AutoStoryNewGame/2026-11-15/ko_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_confirm.png"}, .expectation = {.name = "1", .language = std::nullopt}}, + {.name = "German, one + after the name", .input = {.file = "AutoStoryNewGame/2026-11-15/de_plus0.png"}, .expectation = {.name = "1", .language = "Deutsch"}}, + {.name = "Traditional Chinese, two + after the name", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_plus1.png"}, .expectation = {.name = "1", .language = std::nullopt}}, +}; + +class Test_ConfirmChoicesFrame : public ImageUnitTest{ +public: + explicit Test_ConfirmChoicesFrame(const ConfirmCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - intro screens: Confirm Choices in {}", test.name), + {std::format("PokemonLZA/{}", test.input.file)} + ) + , m_test(test) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + const ImageRGB32& frame = images[0]; + if (!read_confirm_choices_cursor(frame)){ + return std::string("Confirm Choices' highlight did not read."); + } + if (is_name_keyboard(frame)){ + return std::string("Read as the name keyboard."); + } + const std::string name = read_confirm_choices_name(frame); + if (name != m_test.expectation.name){ + return std::format("Expected the name \"{}\", read \"{}\".", m_test.expectation.name, name); + } + if (m_test.expectation.language){ + const std::string language = read_confirm_choices_language(frame, Language::English); + if (language.find(*m_test.expectation.language) == std::string::npos){ + return std::format("Expected the language to have \"{}\", read \"{}\".", *m_test.expectation.language, language); + } + } + return true; + } + +private: + const ConfirmCase& m_test; +}; + } // namespace @@ -141,6 +291,12 @@ void add_tests_AutoStoryIntroScreens(UnitTestDatabase& database){ database.add(test); } database.add(); + for (const SystemKeyboardCase& test : SYSTEM_KEYBOARD_CASES){ + database.add(test); + } + for (const ConfirmCase& test : CONFIRM_CASES){ + database.add(test); + } } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index bfb6de3b32..848453a783 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2326,8 +2326,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNameKeys.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.cpp From fdc0de04cf636c9687077ab478ad7f98d6652490 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 20:56:28 -0800 Subject: [PATCH 04/24] =?UTF-8?q?CI=20(fork=20only):=20pin=20CommandLineTe?= =?UTF-8?q?sts=2041d8566=20=E2=80=94=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..dcc77b67d0 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.00 new game frames (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '2abde09b6bfdf9ae1b372b04c0e6265dc8559556' + ref: '41d8566e03ea6077215f300c950d543fb2fa0de7' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded From 09d3ed0740144f86100b4c6999e9f2c19bdb865b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:29:21 -0800 Subject: [PATCH 05/24] PLZA new game: find Z-A's HOME tile by its title before launching HOME's tiles are in last-played order, so slot 0 launched FireRed on console B. The launch now presses HOME (first tile) and moves right until the OCR'd title above the tile row ends in Z-A, up to 8 tiles, else a UserSetupError. Capture mode's help says it ignores Game Language. --- .../Actions/PokemonLZA_AutoStoryNewGame.cpp | 38 ++++++++++++++++--- .../Actions/PokemonLZA_AutoStoryNewGame.h | 6 +-- .../PokemonLZA_AutoStoryIntroScreens.cpp | 21 ++++++++++ .../PokemonLZA_AutoStoryIntroScreens.h | 6 +++ ...PokemonLZA_AutoStoryIntroScreens_Tests.cpp | 7 ++++ .../AutoStory/PokemonLZA_AutoStory.cpp | 4 +- 6 files changed, 71 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp index e6fddf280e..a3d7f732c4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp @@ -13,6 +13,7 @@ #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/NintendoSwitch_Settings.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" #include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" @@ -38,6 +39,11 @@ constexpr std::string_view DUMP_FOLDER = "PokemonLZA/AutoStory/Intro"; // press needed (the console, 2026-11-15, all ten languages). constexpr Milliseconds LAUNCH_LIMIT = 60000ms; +// HOME's tiles are in last-played order, so PLZA's is not always the +// first: it is searched for among this many. +constexpr size_t HOME_TILES_SEARCHED = 8; +constexpr Milliseconds HOME_TILE_RELEASE = 500ms; + // The language list's D-pad taps: each registered at this pace (the // console, 2026-11-15). constexpr Milliseconds LANGUAGE_TAP_RELEASE = 600ms; @@ -122,11 +128,31 @@ void tilt(ProControllerContext& context, IntroKey key){ } } -// From HOME with the game closed: A on the selected tile, through the -// user select (start_game_from_home(), slot 0: the cursor does not move), -// until the game's black screen. +// On HOME: HOME puts the cursor on the first tile (as +// start_game_from_home() does for a game slot), then right one tile at a +// time until the highlighted tile's title is PLZA's. +void select_plza_tile(ConsoleHandle& console, ProControllerContext& context){ + pbf_press_button(context, BUTTON_HOME, /*hold=*/160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); + for (size_t tile = 0; tile < HOME_TILES_SEARCHED; tile++){ + const VideoSnapshot frame = snapshot(console, context); + if (frame && is_home_tile_plza(frame)){ + console.log(std::format("AutoStory intro: PLZA is HOME's tile {}.", tile)); + return; + } + pbf_press_dpad(context, DPAD_RIGHT, /*hold=*/80ms, HOME_TILE_RELEASE); + } + throw UserSetupError( + console, + std::format("AutoStory: Pokemon Legends: Z-A is not on HOME's first {} tiles. Play it once so its tile moves to the front.", HOME_TILES_SEARCHED) + ); +} + +// From HOME with the game closed: selects PLZA's tile, then A on it, +// through the user select (start_game_from_home(), slot 0: the cursor +// does not move), until the game's black screen. void launch_from_home(ConsoleHandle& console, ProControllerContext& context){ - console.log("AutoStory intro: launching the selected HOME tile."); + select_plza_tile(console, context); + console.log("AutoStory intro: launching PLZA's HOME tile."); start_game_from_home(console, context, /*tolerate_update_menu=*/true, /*game_slot=*/0, /*user_slot=*/0); } @@ -377,8 +403,8 @@ NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext if (current_time() >= deadline){ throw UserSetupError( console, - "AutoStory: 01.00 starts a new game (no save) from the Switch HOME with PLZA's tile selected and the game " - "closed, from the language list, or from \"Confirm Choices\". None of them is on screen; nothing was pressed." + "AutoStory: 01.00 starts a new game (no save) from the Switch HOME (the game closed; PLZA's tile among " + "the first 8), from the language list, or from \"Confirm Choices\". None of them is on screen; nothing was pressed." ); } context.wait_for(250ms); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h index 5ecc490465..a663ce08e5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h @@ -26,7 +26,7 @@ namespace PokemonLZA{ // The screens a new game (no save) may start on. enum class NewGameStart{ - HOME, // The Switch's HOME, PLZA's tile selected, the game closed. + HOME, // The Switch's HOME, the game closed (PLZA's tile is searched for). LANGUAGE_LIST, CONFIRM_CHOICES, // The language, look and name chosen already. }; @@ -35,8 +35,8 @@ enum class NewGameStart{ // having pressed nothing, if it is none of NewGameStart's. NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext& context); -// 01.00's first step: from HOME (the selected tile launched, never moving -// HOME's cursor) or the language list, plays the language, the look and +// 01.00's first step: from HOME (PLZA's tile found by its title, then +// launched) or the language list, plays the language, the look and // the name of `choices` up to "Confirm Choices"; on "Confirm Choices" it // presses nothing. Each screen's highlight is read before and after each // press; the name is typed with the Switch keyboard typer. Throws diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp index e7a7981f91..7773980351 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include "CommonFramework/ImageTools/ImageBoxes.h" @@ -241,6 +242,26 @@ std::string read_light_text(const ImageViewRGB32& frame, const ImageFloatBox& bo } // namespace +// The title line runs y 215-266 at 1920 x 1080, from the highlighted +// tile's left edge; the tile row's cyan border starts at y 277. The text +// is about (10, 212, 224) on (241, 241, 241). +bool is_home_tile_plza(const ImageViewRGB32& frame){ + if (!usable(frame)){ + return false; + } + const ImageRGB32 filtered = to_blackwhite_rgb32_range( + extract_box_reference(frame, ImageFloatBox(0.02, 205.0 / 1080, 0.96, 67.0 / 1080)), + /*in_range_black=*/true, /*mins=*/0xff009696, /*maxs=*/0xff7fffff + ); + std::string letters; + for (const char ch : OCR::ocr_read(Language::English, filtered)){ + if (std::isalnum((unsigned char)ch)){ + letters += (char)std::tolower((unsigned char)ch); + } + } + return letters.ends_with("za"); +} + std::optional read_language_list_cursor(const ImageViewRGB32& frame){ if (!usable(frame) || !column_gap_dark(frame)){ return std::nullopt; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h index 96c0ac4f29..9bc37d9a69 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h @@ -24,6 +24,12 @@ namespace NintendoSwitch{ namespace PokemonLZA{ +// On the Switch HOME, whether the highlighted tile is PLZA: the title the +// HOME prints above the tile row (cyan) ends in "Z-A", read with OCR +// (English; measured on an English system). False for any other tile or +// frame. +bool is_home_tile_plza(const ImageViewRGB32& frame); + // On "Which language will you play in?", the highlighted entry (numbered // down the left column, then down the right one): the one white box of // the 10, the others slate. Nullopt for any other frame, an empty one diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp index 2b41649702..72dbabac5c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.cpp @@ -42,6 +42,7 @@ struct FrameCase{ bool keyboard = false; // The counter's limit; nullopt: not checked (the field holds text). std::optional name_limit = std::nullopt; + bool home_plza = false; }; Expectation expectation; }; @@ -104,6 +105,9 @@ const FrameCase FRAME_CASES[] = { {.name = "2026-11-15: the keyboard in Simplified Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, {.name = "2026-11-15: the keyboard in Traditional Chinese", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHant_kb.png"}, .expectation = {.keyboard = true, .name_limit = 6}}, {.name = "2026-11-15: Simplified Chinese keeps the keyboard after the first +", .input = {.file = "AutoStoryNewGame/2026-11-15/zhHans_plus0.png"}, .expectation = {.keyboard = true, .name_limit = std::nullopt}}, + // HOME's tiles in last-played order: FireRed first, Z-A second. + {.name = "2026-11-15: HOME on FireRed's tile", .input = {.file = "AutoStoryNewGame/2026-11-15/home_firered.png"}, .expectation = {}}, + {.name = "2026-11-15: HOME on Z-A's tile", .input = {.file = "AutoStoryNewGame/2026-11-15/home_plza.png"}, .expectation = {.home_plza = true}}, }; class Test_IntroScreenFrame : public ImageUnitTest{ @@ -138,6 +142,9 @@ class Test_IntroScreenFrame : public ImageUnitTest{ return std::format("Name keyboard: expected a limit of {}, read {}.", describe(expected.name_limit), describe(limit)); } } + if (is_home_tile_plza(frame) != expected.home_plza){ + return std::format("HOME tile: expected PLZA {}, read {}.", expected.home_plza, !expected.home_plza); + } return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index e1e4808980..e84fc9cd0f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -33,7 +33,7 @@ AutoStory_Descriptor::AutoStory_Descriptor() std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", "Play the main story of Pokemon Legends: Z-A. Prototype: from a new game to the end of Main Mission 01, picking Chikorita. " - "Checkpoint 01.00 starts a new game (delete the save first) from the HOME screen with the game closed and its tile selected, " + "Checkpoint 01.00 starts a new game (delete the save first) from the HOME screen with the game closed, its tile among the first 8, " "from the language list, or from Confirm Choices, with the language, look and name below. " "Later checkpoints load the latest save first, unless that is turned off.", PanelQualityStanding::DEVELOPER, @@ -129,7 +129,7 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, /*default_value=*/"Kosmos", /*placeholder_text=*/"Kosmos" ) , CAPTURE_INTRO_SCREENS( - "Developer: capture intro screens:
Instead of the story: for each language, close the game, launch it from HOME and save its screens up to the name keyboard to the Screenshots folder. Nothing is typed, so no save is made.", + "Developer: capture intro screens:
A separate collection mode, not a capture during a run: it ignores Game Language and, for each of the ten languages in turn (English first), closes the game, launches it from HOME and saves its screens up to the name keyboard to the Screenshots folder. Nothing is typed, so no save is made.", LockMode::LOCK_WHILE_RUNNING, /*default_value=*/false ) , ATTEMPTS_PER_CHECKPOINT( From 84925e6928d21de7a1b77643d7af97577cbf5d3b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:29:21 -0800 Subject: [PATCH 06/24] =?UTF-8?q?CI=20(fork=20only):=20pin=20CommandLineTe?= =?UTF-8?q?sts=20989adaf=20(HOME=20tile=20frames)=20=E2=80=94=20drop=20bef?= =?UTF-8?q?ore=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 dcc77b67d0..09159e0a61 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.00 new game frames (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames and HOME tiles (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '41d8566e03ea6077215f300c950d543fb2fa0de7' + ref: '989adafaeb13f46943052d12396421841944436d' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded From 7636a2169e54aafd8ada5af801e69f0d0f1d56e5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 21:36:53 -0800 Subject: [PATCH 07/24] =?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 | 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 09159e0a61..31e19b0228 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.00 new game frames and HOME tiles (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames, HOME tiles and the 01.02 Italian choice menu (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '989adafaeb13f46943052d12396421841944436d' + ref: '8b376ffb6a7476af5f9cf4c786fb852ef5e49efc' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded From f4cf19695b3a6ecbe136863ef95c30e3350c2e59 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 22:09:23 -0800 Subject: [PATCH 08/24] =?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 31e19b0228..2690ca1ad9 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.00 new game frames, HOME tiles and the 01.02 Italian choice menu (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames, HOME tiles and the 01.02 Italian choice menu and talk prompt (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 7d47855b22b136df666a0e73df92af69d8075a28 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 23:16:00 -0800 Subject: [PATCH 09/24] PLZA AutoStory: one launch from HOME for every start and reload The 01.01 load (LOAD_SAVE_FIRST) reloaded with reset_game_from_home(), which closes and launches HOME's first tile: FireRed, played last on console B, so 01.01 failed at on_platform with a FireRed battle on screen. #610's tile search covered only the new game. launch_plza_from_home() is now the only way AutoStory starts PLZA: HOME, close whatever game runs (logging whether it was PLZA), find PLZA's tile by its title among the first 8, launch it. The new game, capture mode and the latest-save reload all go through it; the reload then runs PLZA's title and load as reset_game_from_home() did (gamemenu_to_ingame() is now declared in PokemonLZA_GameEntry.h). Test: the tile search over console frames, FireRed first and Z-A second (new CommandLineTests frame; fork-only pin d0deaeb). --- .../workflows/cpp-ci-serial-programs-base.yml | 4 +- .../PokemonLZA/PokemonLZA_Tests.cpp | 2 + .../Actions/PokemonLZA_AutoStoryLaunch.cpp | 84 ++++++++++++ .../Actions/PokemonLZA_AutoStoryLaunch.h | 51 ++++++++ .../PokemonLZA_AutoStoryLaunch_Tests.cpp | 122 ++++++++++++++++++ .../PokemonLZA_AutoStoryLaunch_Tests.h | 25 ++++ .../Actions/PokemonLZA_AutoStoryNewGame.cpp | 49 ++----- .../Actions/PokemonLZA_AutoStoryNewGame.h | 5 +- .../AutoStory/PokemonLZA_AutoStory.cpp | 2 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 20 ++- .../Programs/PokemonLZA_GameEntry.h | 7 + SerialPrograms/cmake/SourceFiles.cmake | 4 + 12 files changed, 324 insertions(+), 51 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 2690ca1ad9..b69b4e394f 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.00 new game frames, HOME tiles and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames, HOME tiles (FireRed first, Z-A second too) and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '848e0b03a03d9cdca580f21f3389486478d52f4d' + ref: 'd0deaebe6fa2f623770b1233cc76cd056cc97ecc' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index 8a1d507804..49315b53f9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -28,6 +28,7 @@ #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryObjectiveMarkerReader_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h" #include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.h" @@ -62,6 +63,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStoryCaughtMarkReader(database); add_tests_AutoStoryDialogDetector(database); add_tests_AutoStoryIntroScreens(database); + add_tests_AutoStoryLaunch(database); add_tests_AutoStoryNewGame(database); add_tests_AutoStoryGame(database); add_tests_AutoStoryLines(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp new file mode 100644 index 0000000000..4ef422c54a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp @@ -0,0 +1,84 @@ +/* PokemonLZA AutoStory - Launch + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/NintendoSwitch_Settings.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLaunch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr Milliseconds HOME_TILE_RELEASE = 500ms; + +// The highlighted HOME tile is PLZA's; false without a frame. +bool highlighted_tile_is_plza(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + return frame && is_home_tile_plza(frame); +} + +} // namespace + + +std::optional find_plza_tile( + const std::function& highlighted_is_plza, + const std::function& move_right +){ + for (size_t tile = 0; tile < HOME_TILES_SEARCHED; tile++){ + if (tile > 0){ + move_right(); + } + if (highlighted_is_plza()){ + return tile; + } + } + return std::nullopt; +} + +void launch_plza_from_home(ConsoleHandle& console, ProControllerContext& context){ + // HOME from the game or from HOME: the cursor on the first tile, the + // running game's when one runs. + go_home(console, context); + const bool first_is_plza = highlighted_tile_is_plza(console, context); + console.log(std::format( + "AutoStory launch: HOME's first tile (the running game, if any) is {}; closing it.", + first_is_plza ? "PLZA" : "another game" + )); + close_game_from_home(console, context); + + pbf_press_button(context, BUTTON_HOME, /*hold=*/160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); + const std::optional tile = find_plza_tile( + [&]{ return highlighted_tile_is_plza(console, context); }, + [&]{ pbf_press_dpad(context, DPAD_RIGHT, /*hold=*/80ms, HOME_TILE_RELEASE); } + ); + if (!tile){ + throw UserSetupError( + console, + std::format( + "AutoStory: Pokemon Legends: Z-A is not on HOME's first {} tiles. Play it once so its tile moves to the front.", + HOME_TILES_SEARCHED + ) + ); + } + console.log(std::format("AutoStory launch: launching PLZA, HOME's tile {}.", *tile)); + // Slot 0: the cursor stays on PLZA's tile. + start_game_from_home(console, context, /*tolerate_update_menu=*/true, /*game_slot=*/0, /*user_slot=*/0); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h new file mode 100644 index 0000000000..914e7dbc35 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h @@ -0,0 +1,51 @@ +/* PokemonLZA AutoStory - Launch + * + * From: https://github.com/PokemonAutomation/ + * + * The one way AutoStory starts or restarts PLZA from the Switch HOME: for + * a new game, for the latest save and for capture mode. HOME's tiles are + * in last-played order, so the first tile is not always PLZA's (console B, + * 2026-11-15: FireRed's, played last, launched instead). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_H +#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_H + +#include +#include +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// How many of HOME's tiles, from the first, are searched for PLZA's. +constexpr size_t HOME_TILES_SEARCHED = 8; + +// HOME's tile search from the highlighted tile rightward: reads each tile +// with `highlighted_is_plza`, moving one tile right with `move_right` +// between reads, and returns how many moves put PLZA's tile under the +// cursor; nullopt if none of HOME_TILES_SEARCHED tiles is PLZA's. +std::optional find_plza_tile( + const std::function& highlighted_is_plza, + const std::function& move_right +); + +// From the game or HOME: goes HOME, closes the running game whichever it +// is (the first tile, the last played), selects PLZA's tile by its title +// and launches it through the user select, until the game's black screen. +// Logs whether the closed game was PLZA. Throws UserSetupError, having +// launched nothing, if PLZA's tile is not among HOME's first +// HOME_TILES_SEARCHED. +void launch_plza_from_home(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp new file mode 100644 index 0000000000..258583a424 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp @@ -0,0 +1,122 @@ +/* PokemonLZA AutoStory - Launch Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Tests/ImageUnitTest.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLaunch.h" +#include "PokemonLZA_AutoStoryLaunch_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +std::string describe(std::optional value){ + return value ? std::format("{}", *value) : std::string("none"); +} + +// HOME as the console showed it, one frame per tile from the first: the +// search reads each frame in turn, a right move showing the next one. +struct TileSearchCase{ + std::string name; + struct Input{ + std::vector files; // Under the test images' PokemonLZA/. + // The last frame repeats past the end (HOME's row ends there). + }; + Input input; + struct Expectation{ + std::optional tile; + }; + Expectation expectation; +}; + +const TileSearchCase TILE_SEARCH_CASES[] = { + { + // The 01.01 load that launched FireRed (console B, 2026-11-15): + // FireRed played last, Z-A second. + .name = "FireRed first, Z-A second", + .input = {.files = { + "AutoStoryNewGame/2026-11-15/home_firered_first.png", + "AutoStoryNewGame/2026-11-15/home_plza.png", + }}, + .expectation = {.tile = 1}, + }, + { + .name = "Z-A first", + .input = {.files = {"AutoStoryNewGame/2026-11-15/home_plza.png"}}, + .expectation = {.tile = 0}, + }, + { + .name = "no Z-A tile", + .input = {.files = {"AutoStoryNewGame/2026-11-15/home_firered.png"}}, + .expectation = {.tile = std::nullopt}, + }, +}; + +std::vector image_paths(const TileSearchCase& test){ + std::vector paths; + for (const std::string& file : test.input.files){ + paths.push_back(std::format("PokemonLZA/{}", file)); + } + return paths; +} + +class Test_HomeTileSearch : public ImageUnitTest{ +public: + explicit Test_HomeTileSearch(const TileSearchCase& test) + : ImageUnitTest(std::format("PokemonLZA::AutoStory - launch: HOME tile search, {}", test.name), image_paths(test)) + , m_test(test) + {} + virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ + size_t shown = 0; + size_t moves = 0; + const std::optional tile = find_plza_tile( + [&]{ + return is_home_tile_plza(images[shown]); + }, + [&]{ + moves++; + if (shown + 1 < images.size()){ + shown++; + } + } + ); + if (tile != m_test.expectation.tile){ + return std::format("Expected PLZA on tile {}, found {}.", describe(m_test.expectation.tile), describe(tile)); + } + const size_t expected_moves = tile ? *tile : HOME_TILES_SEARCHED - 1; + if (moves != expected_moves){ + return std::format("Expected {} right moves, made {}.", expected_moves, moves); + } + return true; + } + +private: + const TileSearchCase& m_test; +}; + +} // namespace + + +void add_tests_AutoStoryLaunch(UnitTestDatabase& database){ + for (const TileSearchCase& test : TILE_SEARCH_CASES){ + database.add(test); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h new file mode 100644 index 0000000000..717b123506 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h @@ -0,0 +1,25 @@ +/* PokemonLZA AutoStory - Launch Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the launch's tests: HOME's tile search over console frames. +void add_tests_AutoStoryLaunch(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp index a3d7f732c4..70fd43e58d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.cpp @@ -13,7 +13,6 @@ #include "CommonFramework/ImageTypes/ImageRGB32.h" #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" -#include "NintendoSwitch/NintendoSwitch_Settings.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_Superscalar.h" #include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" @@ -22,6 +21,7 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLaunch.h" #include "PokemonLZA_AutoStoryNewGame.h" namespace PokemonAutomation{ @@ -39,11 +39,6 @@ constexpr std::string_view DUMP_FOLDER = "PokemonLZA/AutoStory/Intro"; // press needed (the console, 2026-11-15, all ten languages). constexpr Milliseconds LAUNCH_LIMIT = 60000ms; -// HOME's tiles are in last-played order, so PLZA's is not always the -// first: it is searched for among this many. -constexpr size_t HOME_TILES_SEARCHED = 8; -constexpr Milliseconds HOME_TILE_RELEASE = 500ms; - // The language list's D-pad taps: each registered at this pace (the // console, 2026-11-15). constexpr Milliseconds LANGUAGE_TAP_RELEASE = 600ms; @@ -128,34 +123,6 @@ void tilt(ProControllerContext& context, IntroKey key){ } } -// On HOME: HOME puts the cursor on the first tile (as -// start_game_from_home() does for a game slot), then right one tile at a -// time until the highlighted tile's title is PLZA's. -void select_plza_tile(ConsoleHandle& console, ProControllerContext& context){ - pbf_press_button(context, BUTTON_HOME, /*hold=*/160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - for (size_t tile = 0; tile < HOME_TILES_SEARCHED; tile++){ - const VideoSnapshot frame = snapshot(console, context); - if (frame && is_home_tile_plza(frame)){ - console.log(std::format("AutoStory intro: PLZA is HOME's tile {}.", tile)); - return; - } - pbf_press_dpad(context, DPAD_RIGHT, /*hold=*/80ms, HOME_TILE_RELEASE); - } - throw UserSetupError( - console, - std::format("AutoStory: Pokemon Legends: Z-A is not on HOME's first {} tiles. Play it once so its tile moves to the front.", HOME_TILES_SEARCHED) - ); -} - -// From HOME with the game closed: selects PLZA's tile, then A on it, -// through the user select (start_game_from_home(), slot 0: the cursor -// does not move), until the game's black screen. -void launch_from_home(ConsoleHandle& console, ProControllerContext& context){ - select_plza_tile(console, context); - console.log("AutoStory intro: launching PLZA's HOME tile."); - start_game_from_home(console, context, /*tolerate_update_menu=*/true, /*game_slot=*/0, /*user_slot=*/0); -} - // After the launch, until the language list, pressing nothing (see // LAUNCH_LIMIT). `recorder` and `language`: capture mode, save each new // screen on the way. @@ -403,8 +370,11 @@ NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext if (current_time() >= deadline){ throw UserSetupError( console, - "AutoStory: 01.00 starts a new game (no save) from the Switch HOME (the game closed; PLZA's tile among " - "the first 8), from the language list, or from \"Confirm Choices\". None of them is on screen; nothing was pressed." + std::format( + "AutoStory: 01.00 starts a new game (no save) from the Switch HOME (PLZA's tile among the first {}), " + "from the language list, or from \"Confirm Choices\". None of them is on screen; nothing was pressed.", + HOME_TILES_SEARCHED + ) ); } context.wait_for(250ms); @@ -420,8 +390,7 @@ void play_new_game_intro(ConsoleHandle& console, ProControllerContext& context, console.log("AutoStory intro: already on Confirm Choices; its check reads the language and name."); return; case NewGameStart::HOME: - close_game_from_home(console, context); - launch_from_home(console, context); + launch_plza_from_home(console, context); wait_for_language_list(console, context, /*recorder=*/nullptr, choices.language); break; case NewGameStart::LANGUAGE_LIST: @@ -454,9 +423,7 @@ void capture_intro_screens(ConsoleHandle& console, ProControllerContext& context const NewGameLanguage language = (NewGameLanguage)index; const NewGameLanguageInfo& info = new_game_language_info(language); console.log(std::format("AutoStory capture: {}: closing the game and launching it from HOME.", info.tag)); - go_home(console, context); - close_game_from_home(console, context); - launch_from_home(console, context); + launch_plza_from_home(console, context); IntroFrameRecorder recorder(CAPTURE_CHANGE, CAPTURE_EVERY); wait_for_language_list(console, context, &recorder, language); save_capture(console, context, language, "language-list"); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h index a663ce08e5..002dea846f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h @@ -26,7 +26,7 @@ namespace PokemonLZA{ // The screens a new game (no save) may start on. enum class NewGameStart{ - HOME, // The Switch's HOME, the game closed (PLZA's tile is searched for). + HOME, // The Switch's HOME (launch_plza_from_home() closes any game and finds PLZA's tile). LANGUAGE_LIST, CONFIRM_CHOICES, // The language, look and name chosen already. }; @@ -35,8 +35,7 @@ enum class NewGameStart{ // having pressed nothing, if it is none of NewGameStart's. NewGameStart require_new_game_start(ConsoleHandle& console, ProControllerContext& context); -// 01.00's first step: from HOME (PLZA's tile found by its title, then -// launched) or the language list, plays the language, the look and +// 01.00's first step: from HOME (launch_plza_from_home()) or the language list, plays the language, the look and // the name of `choices` up to "Confirm Choices"; on "Confirm Choices" it // presses nothing. Each screen's highlight is read before and after each // press; the name is typed with the Switch keyboard typer. Throws diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index e84fc9cd0f..e58aec9bb6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -33,7 +33,7 @@ AutoStory_Descriptor::AutoStory_Descriptor() std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", "Play the main story of Pokemon Legends: Z-A. Prototype: from a new game to the end of Main Mission 01, picking Chikorita. " - "Checkpoint 01.00 starts a new game (delete the save first) from the HOME screen with the game closed, its tile among the first 8, " + "Checkpoint 01.00 starts a new game (delete the save first) from the HOME screen (its tile among the first 8; a running game is closed), " "from the language list, or from Confirm Choices, with the language, look and name below. " "Later checkpoints load the latest save first, unless that is turned off.", PanelQualityStanding::DEVELOPER, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 422d2c99b1..6a3aa9f290 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -19,11 +19,13 @@ #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "Pokemon/AutoStory/Data/Pokemon_StoryFiles.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h" +#include "VideoGames/PokemonLZA/PokemonLZA_Settings.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_MenuNavigation.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryCatches.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryNewGame.h" @@ -51,6 +53,10 @@ using Handler = Pokemon::StoryActionHandler; namespace{ +// After a reload reaches the overworld, before the first look: the wait +// reset_game_from_home() takes by default. +constexpr Milliseconds RELOAD_SETTLE = 1000ms; + StoryActionSpec game_spec(std::string name, std::vector args = {}){ return StoryActionSpec{.kind = StoryStepKind::GAME, .name = std::move(name), .args = std::move(args)}; @@ -148,13 +154,19 @@ std::vector make_specs(){ } -// The game onto its latest save by reset_game_from_home(). Fails as -// "launch_failed". +// The game onto its latest save: PLZA launched by launch_plza_from_home() +// (its own tile, whichever game ran), then reset_game_from_home()'s title +// and load. Fails as "launch_failed". Outcome reload_latest_save(StoryEnv& env){ - go_home(env.env.console, env.context); - if (!reset_game_from_home(env.env, env.env.console, env.context, /*backup_save=*/false)){ + ConsoleHandle& console = env.env.console; + launch_plza_from_home(console, env.context); + const bool loaded = + openedgame_to_gamemenu(console, env.context, GameSettings::instance().START_GAME_WAIT) && + gamemenu_to_ingame(console, env.context, GameSettings::instance().ENTER_GAME_WAIT0); + if (!loaded){ return Pokemon::outcome_failed("launch_failed", "the game did not reach the overworld after the reload"); } + env.context.wait_for(RELOAD_SETTLE); return Pokemon::outcome_ok(); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h index 34a85d5547..3a537beeb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h @@ -25,6 +25,13 @@ bool reset_game_to_gamemenu( ConsoleHandle& console, ProControllerContext& context ); +// From the game menu screen (where "Press A" is displayed to enter the game), +// mash A to enter the game and wait until the black screen is gone. +bool gamemenu_to_ingame( + VideoStream& stream, ProControllerContext& context, + Milliseconds enter_game_timeout +); + // From Switch Home menu, start game and wait until the player character // appears in game. // post_wait_time: how many ticks to wait after the black screen diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index bf695a9827..039ee9d315 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2322,6 +2322,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLines_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMarkerWalk.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp From 7db5b1cfa775ce4ea8b210abf7654559e02b483f Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 23:16:26 -0800 Subject: [PATCH 10/24] PLZA AutoStory launch: UserSetupError's header; the test expectation defaults --- .../Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp | 2 +- .../AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp index 4ef422c54a..d29703a693 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp @@ -5,7 +5,7 @@ */ #include -#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Common/Cpp/Exceptions.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/NintendoSwitch_Settings.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp index 258583a424..6b26072daf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp @@ -36,7 +36,7 @@ struct TileSearchCase{ }; Input input; struct Expectation{ - std::optional tile; + std::optional tile = std::nullopt; }; Expectation expectation; }; From c2ec1d3fbc6cab8837c82ca8634dd00b9216d4de Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 23:32:16 -0800 Subject: [PATCH 11/24] PLZA AutoStory: rename the launch test's image list so the base class's image_paths() doesn't hide it --- .../AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp index 6b26072daf..8181f656e9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch_Tests.cpp @@ -64,7 +64,7 @@ const TileSearchCase TILE_SEARCH_CASES[] = { }, }; -std::vector image_paths(const TileSearchCase& test){ +std::vector home_tile_images(const TileSearchCase& test){ std::vector paths; for (const std::string& file : test.input.files){ paths.push_back(std::format("PokemonLZA/{}", file)); @@ -75,7 +75,7 @@ std::vector image_paths(const TileSearchCase& test){ class Test_HomeTileSearch : public ImageUnitTest{ public: explicit Test_HomeTileSearch(const TileSearchCase& test) - : ImageUnitTest(std::format("PokemonLZA::AutoStory - launch: HOME tile search, {}", test.name), image_paths(test)) + : ImageUnitTest(std::format("PokemonLZA::AutoStory - launch: HOME tile search, {}", test.name), home_tile_images(test)) , m_test(test) {} virtual UnitTestResult run_on_images(Logger&, CancellableScope&, const std::vector& images) const override{ From a9f619526330e6cf78477c60b018ba1694f5288b Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 23:56:52 -0800 Subject: [PATCH 12/24] PLZA AutoStory: the run's autosave sightings decide saves and chain reloads Every look of every step of a checkpoint goes through AutosaveSightings (a backend wrapper the story game puts around each action): a badge with none in the 5 s before it logs "[PLZA] autosave badge at s in ". A checkpoint whose badge showed saves for the run ("[Save] X: the game autosaved (seen)"); else not saved, whatever the plan claims. run_plza_segments() decides between rows instead of the plan's reload_when_chained true: on from the live screen when the next row's start check passes or cannot tell (logged "START UNCHECKED"); a reload only onto an autosave seen in this run; otherwise fail as no_start_save rather than rewind to an older save. "always" stays for 03.04 (commit b99791ad1) and now 03.11 (facing after the ride); 02.07 and 03.02 lose their flags. 03.01's autosave claim becomes unverified: a chained run on console B saw none there. --- .../AutoStory/PokemonLZA_AutoStory.cpp | 6 +- .../PokemonLZA_AutoStoryAutosaves.cpp | 145 +++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryAutosaves.h | 68 +++++++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 172 +++++++++++++----- .../AutoStory/PokemonLZA_AutoStoryGame.h | 39 ++-- .../PokemonLZA_AutoStoryGame_Tests.cpp | 96 +++++++--- .../AutoStory/StoryData/plza-02.07.plan.json | 3 +- .../AutoStory/StoryData/plza-03.01.plan.json | 4 +- .../AutoStory/StoryData/plza-03.02.plan.json | 4 +- .../AutoStory/StoryData/plza-03.11.plan.json | 4 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 11 files changed, 447 insertions(+), 96 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index e58aec9bb6..c5e556db15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -179,8 +179,8 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex StoryEnv story{.env = env, .context = context, .battle_ai = BATTLE_AI, .new_game = new_game}; PlzaConsoleBackend backend(story); - const StoryGame game = make_plza_story_game(story, story_data); - StoryEngine engine(game, backend); + AutosaveSightings sightings; + const StoryGame game = make_plza_story_game(story, story_data, sightings); RunState state; // A run that starts after the new game starts from the latest save @@ -199,7 +199,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex } const std::vector checkpoints = story_run_rows(std::span(rows), first, last); - const SegmentReport report = run_plza_segments(game, story_data, checkpoints, ATTEMPTS_PER_CHECKPOINT, engine, backend, state); + const SegmentReport report = run_plza_segments(game, story_data, checkpoints, ATTEMPTS_PER_CHECKPOINT, backend, state, sightings); if (!report.completed){ throw OperationFailedException( ErrorReportMode::NO_ERROR_REPORT, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp new file mode 100644 index 0000000000..3205673a3d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp @@ -0,0 +1,145 @@ +/* PokemonLZA AutoStory - Autosaves + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "PokemonLZA_AutoStoryReadings.h" +#include "PokemonLZA_AutoStoryAutosaves.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using Pokemon::Outcome; +using Pokemon::StoryActionCall; +using Pokemon::ZonePose; + + +namespace{ + +// The autosave badge shows 1-3 s: a badge this soon after the last one is +// the same autosave. +constexpr Milliseconds AUTOSAVE_DEBOUNCE = 5000ms; + +// `inner` with every look noted in `sightings` as taken in step `step`. +// code-health: allow public_methods -- forwards every call of the engine's backend to the wrapped one unchanged +class SightingBackend : public PlzaBackend{ +public: + SightingBackend(PlzaBackend& inner, AutosaveSightings& sightings, std::string_view step) + : m_inner(inner) + , m_sightings(sightings) + , m_step(step) + {} + + virtual Pokemon::StoryBackendKind kind() const override{ + return m_inner.kind(); + } + virtual void press(Button button, Milliseconds hold, Milliseconds release) override{ + m_inner.press(button, hold, release); + } + virtual void tap(Pokemon::Direction direction) override{ + m_inner.tap(direction); + } + virtual void hold(Pokemon::Direction direction, Milliseconds duration, Pokemon::StoryPace pace) override{ + m_inner.hold(direction, duration, pace); + } + virtual void stick(double degrees, Milliseconds duration, Milliseconds release, Pokemon::StoryPace pace) override{ + m_inner.stick(degrees, duration, release, pace); + } + virtual void wait(Milliseconds duration) override{ + m_inner.wait(duration); + } + virtual Pokemon::Observation observe() override{ + Pokemon::Observation look = m_inner.observe(); + m_sightings.note(m_inner, look, m_step); + return look; + } + virtual Outcome battle() override{ + return m_inner.battle(); + } + virtual void log(std::string_view line) override{ + m_inner.log(line); + } + virtual void log_detail(std::string_view line) override{ + m_inner.log_detail(line); + } + virtual CancellableScope& scope() override{ + return m_inner.scope(); + } + +private: + PlzaBackend& m_inner; + AutosaveSightings& m_sightings; + std::string_view m_step; +}; + +} // namespace + + +void AutosaveSightings::restart(){ + m_origin.reset(); + m_last_badge.reset(); + m_seen = false; +} + +void AutosaveSightings::note(PlzaBackend& backend, const Pokemon::Observation& look, std::string_view step){ + if (!m_origin){ + m_origin = look.when; + } + if (!look.readings.contains(AUTOSAVE_READING)){ + return; + } + const bool new_sighting = !m_last_badge || look.when - *m_last_badge >= AUTOSAVE_DEBOUNCE; + m_last_badge = look.when; + m_seen = true; + if (new_sighting){ + const double seconds = (double)std::chrono::duration_cast(look.when - *m_origin).count() / 1000; + backend.log(std::format("[PLZA] autosave badge at {:.1f}s in {}", seconds, step)); + } +} + +bool AutosaveSightings::finish(){ + m_last_end_seen = m_seen; + restart(); + return m_last_end_seen; +} + + +Pokemon::StoryGame with_autosave_sightings( + Pokemon::StoryGame game, const Pokemon::StoryRows& rows, AutosaveSightings& sightings +){ + for (Pokemon::StoryAction& action : game.actions){ + action.handler = [&sightings, handler = std::move(action.handler)]( + Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState& state + ){ + SightingBackend noted(backend, sightings, call.step.name); + return handler(noted, call, state); + }; + } + game.save = [rows, &sightings](Pokemon::StoryBackend& backend, const Pokemon::StoryCheckpoint& checkpoint){ + if (sightings.finish()){ + backend.log(std::format("[Save] {}: the game autosaved (seen)", checkpoint.id)); + return Pokemon::outcome_ok(); + } + if (rows.unverified_autosaves.contains(checkpoint.id)){ + return Pokemon::outcome_not_saved("save unverified"); + } + if (rows.autosaves.contains(checkpoint.id)){ + return Pokemon::outcome_not_saved("the plan's autosave was not seen"); + } + return Pokemon::outcome_not_saved("no autosave seen"); + }; + return game; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h new file mode 100644 index 0000000000..54d2be8b45 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h @@ -0,0 +1,68 @@ +/* PokemonLZA AutoStory - Autosaves + * + * From: https://github.com/PokemonAutomation/ + * + * The game's own autosaves, as a run sees them: the badge (a pencil and + * "Saving...", top right) on any look of any step of a checkpoint. A + * checkpoint whose badge showed is saved for that run; a chained run + * reloads only onto such a save (run_plza_segments()). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryAutosaves_H +#define PokemonAutomation_PokemonLZA_AutoStoryAutosaves_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "Pokemon/AutoStory/Data/Pokemon_StoryRowExecution.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" +#include "PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The game's autosave badges (AUTOSAVE_READING) a run sees in the +// checkpoint under way. The story game made with it notes every look of +// every step, and its save counts a checkpoint saved when the badge showed +// during it: the save is verified for this run. +class AutosaveSightings{ +public: + // A checkpoint starts: no badge seen in it yet. + void restart(); + // `look`, taken during step `step`. A badge with none in the 5 s + // before it (the badge shows 1-3 s) is a new sighting, logged as + // "[PLZA] autosave badge at s in ", t from the checkpoint's + // first look. + void note(PlzaBackend& backend, const Pokemon::Observation& look, std::string_view step); + // The checkpoint ends: whether a badge showed during it, kept for + // last_end_seen(). + bool finish(); + // Whether the badge showed during the checkpoint that last ended. + bool last_end_seen() const{ + return m_last_end_seen; + } + +private: + std::optional m_origin; + std::optional m_last_badge; + bool m_seen = false; + bool m_last_end_seen = false; +}; + +// `game` with every action's looks noted in `sightings`, which must +// outlive it, and its save counting the autosave `sightings` saw in the +// checkpoint ("[Save] : the game autosaved (seen)"); else nothing +// saved (Pokemon::NOT_SAVED), worded by the plan's "save" in `rows`. +Pokemon::StoryGame with_autosave_sightings( + Pokemon::StoryGame game, const Pokemon::StoryRows& rows, AutosaveSightings& sightings +); + + + +} // 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 eba452a677..dfa3463bad 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -14,10 +14,10 @@ #include #include #include +#include #include #include "CommonFramework/Exceptions/OperationFailedException.h" #include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" -#include "Pokemon/AutoStory/Data/Pokemon_StoryFiles.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h" #include "VideoGames/PokemonLZA/PokemonLZA_Settings.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" @@ -782,22 +782,6 @@ std::optional walk_end_event(std::string_view end){ namespace{ -// The game's own autosave at the end of the rows `rows` marks "autosave"; -// the others are not saved, an "unverified" one for that reason. -Pokemon::StoryGame with_autosaves(Pokemon::StoryGame game, const Pokemon::StoryRows& rows){ - game.save = [rows](Pokemon::StoryBackend& backend, const Pokemon::StoryCheckpoint& checkpoint){ - if (rows.autosaves.contains(checkpoint.id)){ - backend.log(std::format("[Save] {}: the game autosaved at its end", checkpoint.id)); - return Pokemon::outcome_ok(); - } - if (rows.unverified_autosaves.contains(checkpoint.id)){ - return Pokemon::outcome_not_saved("save unverified"); - } - return Pokemon::outcome_not_saved("no autosave at its end"); - }; - return game; -} - // Whether `row` starts on the station platform: its first step checks it // (01.01). bool starts_on_platform(const Pokemon::StoryCheckpoint& row){ @@ -808,6 +792,31 @@ bool starts_on_platform(const Pokemon::StoryCheckpoint& row){ // later one: right after a load the platform reads on the first two. constexpr size_t START_LOOKS = 4; +// What the screen says about a row's start. +enum class StartCheck{ + PASSED, // 01.01: its first step checks the platform + FAILED, // the station platform holds: 01.01's start, not this row's + UNCHECKED, // off the platform; nothing checks the row's own start yet +}; + +// START_LOOKS looks at the screen for `row`'s start. Only the station +// platform is read so far: a later row's place is not checked. +StartCheck check_start(PlzaBackend& backend, const Pokemon::StoryCheckpoint& row){ + if (starts_on_platform(row)){ + return StartCheck::PASSED; + } + size_t streak = 0; + for (size_t looks = 0; looks < START_LOOKS; looks++){ + backend.scope().throw_if_cancelled(); + streak = backend.observe().readings.contains(PLATFORM_READING) ? streak + 1 : 0; + if (streak >= PLATFORM_LOOKS){ + return StartCheck::FAILED; + } + backend.wait(PLATFORM_POLL); + } + return StartCheck::UNCHECKED; +} + void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& total){ total.checkpoints_run += part.checkpoints_run; total.reloads += part.reloads; @@ -819,16 +828,22 @@ void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& tot } // namespace -Pokemon::StoryGame make_plza_story_game(StoryEnv& env, const Pokemon::StoryRows& rows){ - Pokemon::StoryGame game = with_autosaves(plza_game_actions(&env), rows); - game.reload = [&env](Pokemon::StoryBackend&){ + +Pokemon::StoryGame make_plza_story_game( + StoryEnv& env, const Pokemon::StoryRows& rows, AutosaveSightings& sightings +){ + Pokemon::StoryGame game = with_autosave_sightings(plza_game_actions(&env), rows, sightings); + game.reload = [&env, &sightings](Pokemon::StoryBackend&){ + sightings.restart(); return reload_latest_save(env); }; return game; } -Pokemon::StoryGame make_plza_story_game_without_console(const Pokemon::StoryRows& rows){ - return with_autosaves(plza_game_actions(nullptr), rows); +Pokemon::StoryGame make_plza_story_game_without_console( + const Pokemon::StoryRows& rows, AutosaveSightings& sightings +){ + return with_autosave_sightings(plza_game_actions(nullptr), rows, sightings); } Outcome load_checkpoint_start(const Pokemon::StoryGame& game, PlzaBackend& backend, const Pokemon::StoryCheckpoint& row){ @@ -840,49 +855,108 @@ Outcome load_checkpoint_start(const Pokemon::StoryGame& game, PlzaBack if (!loaded.succeeded()){ return loaded; } - if (starts_on_platform(row)){ + switch (check_start(backend, row)){ + case StartCheck::PASSED: return Pokemon::outcome_ok(); - } - size_t streak = 0; - for (size_t looks = 0; looks < START_LOOKS; looks++){ - backend.scope().throw_if_cancelled(); - streak = backend.observe().readings.contains(PLATFORM_READING) ? streak + 1 : 0; - if (streak >= PLATFORM_LOOKS){ - backend.log(std::format("[Checkpoint] {}: the save is on the station platform, not at its start", row.id)); - return Pokemon::outcome_failed("older_save", std::format( - "the latest save is on the station platform (01.01's start), older than {}'s start", row.id - )); - } - backend.wait(PLATFORM_POLL); + case StartCheck::FAILED: + backend.log(std::format("[Checkpoint] {}: the save is on the station platform, not at its start", row.id)); + return Pokemon::outcome_failed("older_save", std::format( + "the latest save is on the station platform (01.01's start), older than {}'s start", row.id + )); + case StartCheck::UNCHECKED: + break; } backend.log(std::format("[Checkpoint] {}: off the station platform, as at its start", row.id)); return Pokemon::outcome_ok(); } +namespace{ + +// How a run goes on into `row` from the row before. +enum class Chain{ + ON, // from the live screen + RELOAD, // from `row`'s start save +}; + +// Chain::ON or RELOAD into `row`, `seen` whether the row before's +// autosave showed; a failure when only a reload would do and there is no +// save to load. Logs the decision. +std::variant decide_chain( + PlzaBackend& backend, const Pokemon::StoryRows& story, const Pokemon::StoryCheckpoint& row, bool seen +){ + const auto no_save = [&](std::string_view why){ + backend.log(std::format("[Checkpoint] {}: no save at its start: {}", row.id, why)); + return Pokemon::outcome_failed("no_start_save", std::format( + "no save at {}'s start: {}; a reload would rewind to an older save", row.id, why + )); + }; + if (story.reload_always.contains(row.id)){ + if (!seen){ + return no_save("it always reloads, and the autosave before it was not seen"); + } + backend.log(std::format("[Checkpoint] {}: reloads its start save (reload_when_chained always)", row.id)); + return Chain::RELOAD; + } + switch (check_start(backend, row)){ + case StartCheck::PASSED: + backend.log(std::format("[Checkpoint] {}: start check passed; on from the live screen", row.id)); + return Chain::ON; + case StartCheck::UNCHECKED: + backend.log(std::format( + "[Checkpoint] {}: START UNCHECKED: nothing reads this row's start; on from the live screen (autosave before it {})", + row.id, seen ? "seen" : "not seen" + )); + return Chain::ON; + case StartCheck::FAILED: + break; + } + if (!seen){ + return no_save("the start check failed and the autosave before it was not seen"); + } + backend.log(std::format("[Checkpoint] {}: start check failed; reloads its start save", row.id)); + return Chain::RELOAD; +} + +} // namespace + Pokemon::SegmentReport run_plza_segments( const Pokemon::StoryGame& game, const Pokemon::StoryRows& story, std::span rows, size_t attempts_per_checkpoint, - Pokemon::StoryEngine& engine, PlzaBackend& backend, Pokemon::RunState& state + PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings ){ + Pokemon::StoryEngine engine(game, backend); Pokemon::SegmentReport total; - const std::vector> segments = Pokemon::story_run_segments(rows, story); - for (size_t index = 0; index < segments.size(); index++){ - const std::vector& segment = segments[index]; + for (size_t index = 0; index < rows.size(); index++){ + const Pokemon::StoryCheckpoint& row = rows[index]; + bool start_saved = true; if (index > 0){ - const Pokemon::StoryCheckpoint& row = segment.front(); - backend.log(std::format("[Event] {}/0 reload_when_chained: start", row.id)); - const Outcome loaded = load_checkpoint_start(game, backend, row); - if (!loaded.succeeded()){ - backend.log(std::format("[Event] {}/0 reload_when_chained: failed: {}", row.id, to_string(loaded))); + const auto fail = [&](const Outcome& failure){ + backend.log(std::format("[Event] {}/0 chain: failed: {}", row.id, to_string(failure))); total.failed_checkpoint = row.id; - total.failed_event = "reload_when_chained"; - total.failure = loaded; + total.failed_event = "chain"; + total.failure = failure; return total; + }; + start_saved = sightings.last_end_seen(); + const std::variant chain = decide_chain(backend, story, row, start_saved); + if (const Outcome* failure = std::get_if(&chain)){ + return fail(*failure); + } + if (std::get(chain) == Chain::RELOAD){ + const Outcome loaded = load_checkpoint_start(game, backend, row); + if (!loaded.succeeded()){ + return fail(loaded); + } + state = Pokemon::RunState{}; } - backend.log(std::format("[Event] {}/0 reload_when_chained: done", row.id)); - state = Pokemon::RunState{}; } - const Pokemon::SegmentReport part = engine.run_segment("PLZA", segment, attempts_per_checkpoint, state); + if (!start_saved && attempts_per_checkpoint > 1){ + backend.log(std::format("[Checkpoint] {}: no autosave seen at its start, so no reload if it fails", row.id)); + } + sightings.restart(); + const Pokemon::SegmentReport part = engine.run_segment( + "PLZA", std::span(&row, 1), start_saved ? attempts_per_checkpoint : 1, state + ); add_segment(part, total); if (!part.completed){ return total; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 16ee0946fc..baffa3e19c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -27,6 +27,7 @@ #include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" +#include "PokemonLZA_AutoStoryAutosaves.h" #include "PokemonLZA_AutoStoryBackend.h" namespace PokemonAutomation{ @@ -99,17 +100,22 @@ std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpo // "dialog". None for any other word. std::optional walk_end_event(std::string_view end); -// PLZA as a StoryGame on the console `env`, which must outlive it. The -// save counts the game's autosave at the end of the "autosave" rows of -// `rows`; after the others nothing saves (Pokemon::NOT_SAVED, "save -// unverified" for the "unverified" ones). The reload resets the game from -// HOME onto the latest save. -Pokemon::StoryGame make_plza_story_game(StoryEnv& env, const Pokemon::StoryRows& rows); +// PLZA as a StoryGame on the console `env`, which must outlive it, as must +// `sightings`. Every step's looks go to `sightings`; the save at a +// checkpoint's end counts the game's autosave when its badge was seen +// there ("[Save] : the game autosaved (seen)"), else nothing saved +// (Pokemon::NOT_SAVED, "save unverified" for the plan's "unverified" +// rows). The reload resets the game from HOME onto the latest save. +Pokemon::StoryGame make_plza_story_game( + StoryEnv& env, const Pokemon::StoryRows& rows, AutosaveSightings& sightings +); // The same with no console, for tests and simulations: the console_only // actions fail as "console_only", and there is no reload. // code-health: allow test_only_api -- a test double: the game the scripted tests and simulations run -Pokemon::StoryGame make_plza_story_game_without_console(const Pokemon::StoryRows& rows); +Pokemon::StoryGame make_plza_story_game_without_console( + const Pokemon::StoryRows& rows, AutosaveSightings& sightings +); // Loads the save `row` starts from with `game`'s reload (the latest // save), then, unless `row` starts on the station platform (01.01, whose @@ -121,16 +127,21 @@ Pokemon::Outcome load_checkpoint_start( const Pokemon::StoryGame& game, PlzaBackend& backend, const Pokemon::StoryCheckpoint& row ); -// `rows` in order from the save the game is on, as -// StoryEngine::run_segment() runs them, `attempts_per_checkpoint` each, -// cut at the rows `story` marks reload_when_chained -// (Pokemon::story_run_segments()): before each, the event -// "reload_when_chained" loads its start with load_checkpoint_start(). A -// failed load fails the run there. +// `rows` in order from the save the game is on, each with the story +// engine's run_segment() on `backend`, `attempts_per_checkpoint` each when a reload +// returns to its start (the first row, or one after a row whose autosave +// `sightings` saw), else once. Between two rows, the event "chain": +// - a row `story` marks reload_when_chained "always" loads its start +// (load_checkpoint_start()) when the row before's autosave was seen; +// - any other row runs on from the live screen when its start check +// passes or cannot tell (logged as "start unchecked"); when it fails, +// the row's start is loaded if the row before's autosave was seen. +// With no autosave seen, a reload would rewind to an older save: the run +// fails there as "no_start_save". A failed load fails the run too. Pokemon::SegmentReport run_plza_segments( const Pokemon::StoryGame& game, const Pokemon::StoryRows& story, std::span rows, size_t attempts_per_checkpoint, - Pokemon::StoryEngine& engine, PlzaBackend& backend, Pokemon::RunState& state + PlzaBackend& backend, Pokemon::RunState& state, AutosaveSightings& sightings ); 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 6d3ddff16f..4458e9e063 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -8,6 +8,7 @@ * console. * */ +// code-health: allow file_lines -- one table per story game behavior, sharing the scripted looks above them #include #include @@ -69,7 +70,7 @@ const StoryDataCase STORY_DATA_CASES[] = { "01.00:new_game:autosave 01.01:from_save:unverified 01.02:from_save:unverified 01.03:from_save:unverified " "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.01:from_save:unverified 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.08:from_save:autosave 03.08b:from_save " "03.09:from_save:unverified " "03.10:from_save:autosave 03.11:from_save:unverified" @@ -445,10 +446,15 @@ const RunCase RUN_CASES[] = { }}, .expectation = {.verdict = "failed at arrival_scenes: scene_quiet"}, }, + { + .name = "01.00's autosave badge is logged in the step it shows in", + .input = {.checkpoint = "01.00", .first_step = 2, .looks = {CUTSCENE, AUTOSAVE, AUTOSAVE, PLATFORM, PLATFORM}}, + .expectation = {.verdict = "done", .line = "[PLZA] autosave badge at 0.0s in opening"}, + }, { .name = "01.00 ends on its autosave", .input = {.checkpoint = "01.00", .first_step = 2, .looks = {AUTOSAVE, PLATFORM, PLATFORM}}, - .expectation = {.verdict = "done", .line = "[Save] 01.00: the game autosaved at its end"}, + .expectation = {.verdict = "done", .line = "[Save] 01.00: the game autosaved (seen)"}, }, { .name = "01.01 is not saved: its autosave is unverified", @@ -622,11 +628,30 @@ const RunCase RUN_CASES[] = { }, }, { - .name = "02.06 ends on the game's autosave", + .name = "02.06 with no autosave badge seen is not saved", .input = {.checkpoint = "02.06", .first_step = 4, .looks = { look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), look({ScreenEvent::SCREEN_STILL}, /*readings=*/{}, Milliseconds(21000)), }}, - .expectation = {.verdict = "done", .line = "[Save] 02.06: the game autosaved at its end"}, + .expectation = {.verdict = "done", .line = "[Save] 02.06: not saved (the plan's autosave was not seen)"}, + }, + { + .name = "an autosave badge mid-scene saves the checkpoint", + .input = {.checkpoint = "02.06", .first_step = 4, .looks = { + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), + look(/*events=*/{}, {AUTOSAVE_READING}, Milliseconds(1000)), + look({ScreenEvent::SCREEN_STILL}, /*readings=*/{}, Milliseconds(21000)), + }}, + .expectation = {.verdict = "done", .line = "[Save] 02.06: the game autosaved (seen)"}, + }, + { + .name = "a badge mid-scene is logged once, at its time in its step", + .input = {.checkpoint = "02.06", .first_step = 4, .looks = { + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), + look(/*events=*/{}, {AUTOSAVE_READING}, Milliseconds(1000)), + look(/*events=*/{}, {AUTOSAVE_READING}, Milliseconds(2000)), + look({ScreenEvent::SCREEN_STILL}, /*readings=*/{}, Milliseconds(21000)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA] autosave badge at 1.0s in wake_up"}, }, { .name = "03.02's map talk: A and B in turn, done on the party bar held a second", @@ -715,7 +740,8 @@ const RunCase RUN_CASES[] = { }; UnitTestResult check_run(const RunCase& test, CancellableScope& scope){ - const Pokemon::StoryGame game = make_plza_story_game_without_console(builtin_story_data()); + AutosaveSightings sightings; + const Pokemon::StoryGame game = make_plza_story_game_without_console(builtin_story_data(), sightings); Pokemon::FakeStoryBackend backend({.looks = test.input.looks, .battle = test.input.battle}, scope); Pokemon::StoryEngine engine(game, backend); Pokemon::RunState state; @@ -745,8 +771,8 @@ UnitTestResult check_run(const RunCase& test, CancellableScope& scope){ // The console-less game with a reload that presses HOME, as the console's // does first, and succeeds. -Pokemon::StoryGame game_with_reload(const Pokemon::StoryRows& rows){ - Pokemon::StoryGame game = make_plza_story_game_without_console(rows); +Pokemon::StoryGame game_with_reload(const Pokemon::StoryRows& rows, AutosaveSightings& sightings){ + Pokemon::StoryGame game = make_plza_story_game_without_console(rows, sightings); game.reload = [](Pokemon::StoryBackend& backend){ backend.press(BUTTON_HOME, Milliseconds(80), Milliseconds(80)); return Pokemon::outcome_ok(); @@ -815,9 +841,10 @@ const LoadCase LOAD_CASES[] = { UnitTestResult check_load(const LoadCase& test, CancellableScope& scope){ const StoryData& story = builtin_story_data(); + AutosaveSightings sightings; const Pokemon::StoryGame game = test.input.has_reload - ? game_with_reload(story) - : make_plza_story_game_without_console(story); + ? game_with_reload(story, sightings) + : make_plza_story_game_without_console(story, sightings); Pokemon::FakeStoryBackend backend({.looks = test.input.looks}, scope); const Pokemon::Outcome loaded = load_checkpoint_start(game, backend, builtin_row(test.input.checkpoint, /*first_step=*/0, /*steps=*/99)); const std::string verdict = loaded.succeeded() ? "done" : loaded.failure; @@ -841,10 +868,11 @@ UnitTestResult check_load(const LoadCase& test, CancellableScope& scope){ // Two rows: "01.01" waits for the platform, "01.02" runs to a choice. +// 01.01's autosave shows when a look has both the platform and the badge. struct ChainCase{ std::string name; struct Input{ - std::set> reload_when_chained; + std::set> reload_always; std::vector> looks; }; Input input; @@ -857,33 +885,59 @@ struct ChainCase{ Expectation expectation; }; +const Observation PLATFORM_SAVING = look({}, {PLATFORM_READING, AUTOSAVE_READING}); + const ChainCase CHAIN_CASES[] = { { - .name = "straight through without reload_when_chained", - .input = {.reload_when_chained = {}, .looks = {PLATFORM, PLATFORM, choice(0)}}, + .name = "autosave seen and the start check does not fail: on without a reload", + .input = {.reload_always = {}, .looks = {PLATFORM_SAVING, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, .expectation = {.verdict = "done", .reloads = 0}, }, { - .name = "reload_when_chained loads the second row's start first", - .input = {.reload_when_chained = {"01.02"}, .looks = {PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, + .name = "no autosave seen and the start check does not fail: on without a reload", + .input = {.reload_always = {}, .looks = {PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, + .expectation = {.verdict = "done", .reloads = 0}, + }, + { + .name = "autosave seen and the start check fails: reloads the start", + .input = {.reload_always = {}, .looks = { + PLATFORM_SAVING, PLATFORM, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0), + }}, + .expectation = {.verdict = "done", .reloads = 1}, + }, + { + .name = "no autosave seen and the start check fails: no reload, no save to start from", + .input = {.reload_always = {}, .looks = {PLATFORM}}, + .expectation = {.verdict = "failed at 01.02 chain: no_start_save", .reloads = 0}, + }, + { + .name = "reload always, autosave seen: reloads the start", + .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, .expectation = {.verdict = "done", .reloads = 1}, }, { - .name = "reload_when_chained stops on an older save", - .input = {.reload_when_chained = {"01.02"}, .looks = {PLATFORM}}, - .expectation = {.verdict = "failed at 01.02 reload_when_chained: older_save", .reloads = 1}, + .name = "reload always, no autosave seen: no reload, no save to start from", + .input = {.reload_always = {"01.02"}, .looks = {PLATFORM}}, + .expectation = {.verdict = "failed at 01.02 chain: no_start_save", .reloads = 0}, + }, + { + .name = "a reload onto an older save stops", + .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM}}, + .expectation = {.verdict = "failed at 01.02 chain: older_save", .reloads = 1}, }, }; UnitTestResult check_chain(const ChainCase& test, CancellableScope& scope){ Pokemon::StoryRows story; - story.reload_when_chained = test.input.reload_when_chained; - const Pokemon::StoryGame game = game_with_reload(story); + story.reload_always = test.input.reload_always; + AutosaveSightings sightings; + const Pokemon::StoryGame game = game_with_reload(story, sightings); Pokemon::FakeStoryBackend backend({.looks = test.input.looks}, scope); - Pokemon::StoryEngine engine(game, backend); Pokemon::RunState state; const std::vector rows{one_step_row("01.01", "wait_for_platform"), one_step_row("01.02", "text_to_choice")}; - const Pokemon::SegmentReport report = run_plza_segments(game, story, rows, /*attempts_per_checkpoint=*/1, engine, backend, state); + const Pokemon::SegmentReport report = run_plza_segments( + game, story, rows, /*attempts_per_checkpoint=*/1, backend, state, sightings + ); const std::string verdict = report.completed ? "done" : std::format("failed at {} {}: {}", report.failed_checkpoint, report.failed_event, report.failure.failure); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.07.plan.json index c0e7f4d8a9..9b35cc3f71 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.07.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.07.plan.json @@ -29,7 +29,6 @@ } }, "execution": { - "save": "unverified", - "reload_when_chained": true + "save": "unverified" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json index 0bcb261402..f7ce2c2d71 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json @@ -61,10 +61,10 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. Autosave: seen in a run log at lobby_scene's end (2026-11-15 save review). No reload_when_chained: 02.07 before it is unverified, so a reload could load an older save." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Save unverified: a run log showed an autosave at lobby_scene's end (2026-11-15 save review), but a chained run on console B (2026-11-15) saw none there, and the reload rewound to 02.06's save; the run's own sighting decides. No reload_when_chained: 02.07 before it is unverified, so a reload could load an older save." } }, "execution": { - "save": "autosave" + "save": "unverified" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json index f41a7bc06e..72feac8078 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json @@ -68,7 +68,5 @@ "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: the game does not autosave at its end (2026-11-15 save review); the menu save of plza/autostory is dropped." } }, - "execution": { - "reload_when_chained": true - } + "execution": {} } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.11.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.11.plan.json index 77fcd7f9e8..a1031b27fa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.11.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.11.plan.json @@ -52,11 +52,11 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game; split from 03.10 at its 3F autosave (user, 2026-11-14). Starts on 3F at the elevator in the Director's Office, as the reloaded autosave leaves the player: facing the desk, the objective marker beyond it, the elevator panel on the right. to_mable's legs were measured from there; after the ride the facing differs, so a run from 03.10 reloads the save first (reload_when_chained). Save unverified: the one run log (console B, 2026-11-14 22:17) shows the game's autosave at mable_talk, before the reward is claimed, not at its end; the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game; split from 03.10 at its 3F autosave (user, 2026-11-14). Starts on 3F at the elevator in the Director's Office, as the reloaded autosave leaves the player: facing the desk, the objective marker beyond it, the elevator panel on the right. to_mable's legs were measured from there; after the ride the facing differs, so a run from 03.10 reloads the save first (reload_when_chained \"always\": no start check reads the facing). Save unverified: the one run log (console B, 2026-11-14 22:17) shows the game's autosave at mable_talk, before the reward is claimed, not at its end; the menu save of plza/autostory is dropped." } }, "execution": { "save": "unverified", - "reload_when_chained": true + "reload_when_chained": "always" } } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 039ee9d315..0c157dd25e 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2383,6 +2383,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryAutosaves.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h From 589597b0b4dff9c6964ba4671a201fa91a18d93d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 01:17:00 -0800 Subject: [PATCH 13/24] PLZA AutoStory: a talk presses A only on its prompt; 03.02 split at its autosave 03.02 failed on console B at talk_to_taunie (2026-11-16): the timed 3 s walk stopped short of Taunie, who stood a few steps ahead under the Quartiere Verde arch with no "A Talk" prompt, and the talk's A found no one. - A walk's "end" may be "prompt": the last leg is held until the A prompt shows, its ms the bound; a last leg that only turns is looked at once after the turn; a HELD last leg is held at its angle. - "talk" looks for the A prompt for 1 s first and presses nothing without it ("talk_no_prompt"). - The lint fails a talk not right after a step that ends on its A prompt (a walk to "prompt", or walk_to_prompt). Every walk before a talk now ends on the prompt: 01.03, 02.04, 02.05, 02.06, 03.01, 03.02b, 03.04, 03.05, 03.10 (02.02 already used walk_to_prompt). - 03.02 ends at the autosave seen in leave_hotel_z; 03.02b starts outside Hotel Z and walks on to Taunie's prompt, 8 s at most. --- .../Actions/PokemonLZA_AutoStoryMoves.cpp | 39 +++++- .../Actions/PokemonLZA_AutoStoryMoves.h | 11 ++ .../Actions/PokemonLZA_AutoStoryScenes.h | 4 +- .../PokemonLZA_AutoStoryWalkScreenChecks.cpp | 33 +++-- .../PokemonLZA_AutoStoryWalkScreenChecks.h | 15 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 32 ++++- .../AutoStory/PokemonLZA_AutoStoryGame.h | 17 ++- .../PokemonLZA_AutoStoryGame_Tests.cpp | 132 +++++++++++++++--- .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 31 ++++ .../AutoStory/PokemonLZA_AutoStoryTable.h | 9 ++ .../AutoStory/StoryData/plza-01.03.plan.json | 5 +- .../AutoStory/StoryData/plza-02.04.plan.json | 4 +- .../AutoStory/StoryData/plza-02.05.plan.json | 4 +- .../AutoStory/StoryData/plza-02.06.plan.json | 4 +- .../AutoStory/StoryData/plza-03.01.plan.json | 5 +- .../AutoStory/StoryData/plza-03.02.plan.json | 46 +----- .../AutoStory/StoryData/plza-03.02b.plan.json | 57 ++++++++ .../AutoStory/StoryData/plza-03.04.plan.json | 5 +- .../AutoStory/StoryData/plza-03.05.plan.json | 5 +- .../AutoStory/StoryData/plza-03.10.plan.json | 7 +- 20 files changed, 360 insertions(+), 105 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp index 2a10ed02c8..c79330e295 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp @@ -43,14 +43,20 @@ void play_checked(PlzaBackend& backend, std::string_view what, Input&& input){ } } +// StoryWalkStyle::HELD: L before leg `index` when it turns after an +// earlier leg. +void recenter_before_held_leg(PlzaBackend& backend, size_t index, const StoryWalkLeg& leg){ + if (index > 0 && leg.turn != 0){ + backend.press(BUTTON_L, /*hold=*/100ms, /*release=*/150ms); + } +} + // StoryWalkStyle::HELD: each leg's stick held at its angle for its time // (a turn-only leg a 150 ms tap); L before each later leg that turns. void run_held_legs(PlzaBackend& backend, const std::vector& legs){ for (size_t index = 0; index < legs.size(); index++){ const StoryWalkLeg& leg = legs[index]; - if (index > 0 && leg.turn != 0){ - backend.press(BUTTON_L, /*hold=*/100ms, /*release=*/150ms); - } + recenter_before_held_leg(backend, index, leg); if (leg.walk > 0ms){ backend.stick(leg.turn, leg.walk, /*release=*/0ms, Pokemon::StoryPace::WALK); }else if (leg.turn != 0){ @@ -96,6 +102,33 @@ Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move){ return Pokemon::outcome_ok(); } +Pokemon::Outcome run_story_move_but_last_walk(PlzaBackend& backend, const StoryMove& move){ + if (move.legs.empty()){ + return Pokemon::outcome_ok(); + } + StoryMove head = move; + if (move.style == StoryWalkStyle::HELD){ + if (move.legs.back().walk == 0ms){ + run_held_legs(backend, move.legs); + return Pokemon::outcome_ok(); + } + head.legs.pop_back(); + run_held_legs(backend, head.legs); + recenter_before_held_leg(backend, head.legs.size(), move.legs.back()); + return Pokemon::outcome_ok(); + } + head.legs.back().walk = 0ms; + return run_story_move(backend, head); +} + +void hold_last_leg(PlzaBackend& backend, const StoryMove& move, Milliseconds slice){ + if (move.style == StoryWalkStyle::HELD && !move.legs.empty()){ + backend.stick(move.legs.back().turn, slice, /*release=*/0ms, Pokemon::StoryPace::WALK); + }else{ + backend.hold(Pokemon::Direction::NORTH, slice, Pokemon::StoryPace::WALK); + } +} + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h index 434c83f5c4..ab7f79abcf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h @@ -63,6 +63,17 @@ struct StoryMove{ // that needs a prompt after the walk fails there instead. Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move); +// `move` as run_story_move() plays it, but for its last leg's walk, which +// the caller holds a slice at a time (hold_last_leg()) until what it walks +// to shows: TURN_THEN_WALK plays the last leg's turn; HELD presses L +// before the last leg when it turns after an earlier one. A HELD last leg +// with no walk is played whole, its turn a tap. +Pokemon::Outcome run_story_move_but_last_walk(PlzaBackend& backend, const StoryMove& move); + +// `slice` of `move`'s last leg's walk: the stick forward after the leg's +// turn (TURN_THEN_WALK), or at the leg's angle (HELD). +void hold_last_leg(PlzaBackend& backend, const StoryMove& move, Milliseconds slice); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h index a28a29da55..a9abb1828d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * Story steps that press through one particular screen of the story, on - * the engine's backend: Taunie's first map (03.02) and the side street's + * the engine's backend: Taunie's first map (03.02b) and the side street's * ladder (03.03). * */ @@ -19,7 +19,7 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -// Taunie's talk after her battle (03.02), the "Map & Missions" card, the +// Taunie's talk after her battle (03.02b), the "Map & Missions" card, the // first map and the rest of her talk: A then B, a second each, until the // party bar shows with no text box on looks a second apart. A pages the // talk and the card; B closes the map, where A would place a pin. The map diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp index fa455acff6..353aa0399c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -128,22 +128,26 @@ void finish_walk(PlzaBackend& backend, std::string_view walk){ } Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const StoryMove& move, ScreenEvent end){ - StoryMove head = move; - Milliseconds hold = 0ms; - if (!head.legs.empty()){ - hold = head.legs.back().walk; - head.legs.back().walk = 0ms; - } - const Pokemon::Outcome walked = run_story_move(backend, head); + const Milliseconds hold = move.legs.empty() ? 0ms : move.legs.back().walk; + const Pokemon::Outcome walked = run_story_move_but_last_walk(backend, move); if (!walked.succeeded()){ return walked; } + if (hold == 0ms){ + // A last leg that only turns (to face the clerk): what the walk + // goes to shows once the turn is done, or the walk missed it. + if (backend.observe().events.has(end)){ + backend.log(std::format("[PLZA] {}: the end event after the last turn.", walk)); + return Pokemon::outcome_ok(); + } + return Pokemon::outcome_failed("walk_no_end", std::format("{}: no end event after the last turn", walk)); + } // The slices stop the stick between them for as long as a look takes; // the player barely slows. for (Milliseconds held = 0ms; held < hold;){ // The last slice holds only what is left, so the leg walks its time. const Milliseconds slice = std::min(HOLD_SLICE, hold - held); - backend.hold(Pokemon::Direction::NORTH, slice, Pokemon::StoryPace::WALK); + hold_last_leg(backend, move, slice); held += slice; const Pokemon::Observation look = backend.observe(); if (look.events.has(end)){ @@ -173,6 +177,19 @@ Pokemon::Outcome walk_to_prompt(PlzaBackend& backend, Milliseconds timeout){ return Pokemon::outcome_failed("no_prompt", std::format("walk_to_prompt: no A prompt in {} ms of walking", timeout.count())); } +bool prompt_shows_within(PlzaBackend& backend, Milliseconds within){ + for (Milliseconds waited = 0ms; ; waited += PROMPT_POLL){ + backend.scope().throw_if_cancelled(); + if (backend.observe().events.has(ScreenEvent::INTERACT_PROMPT)){ + return true; + } + if (waited >= within){ + return false; + } + backend.wait(PROMPT_POLL); + } +} + void press_through_prompt(PlzaBackend& backend){ for (size_t press = 1; press <= PROMPT_PRESSES; press++){ if (!press_at_prompt(backend)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h index d423c836d0..baafb17aa1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h @@ -38,11 +38,12 @@ Pokemon::Outcome check_can_walk(PlzaBackend& backend, std::string_view walk); // shows there. void finish_walk(PlzaBackend& backend, std::string_view walk); -// Walks `move`, holding its last leg in slices of 250 ms until a look -// shows `end` (a fade, or the box of a talk the walk runs into), the -// leg's time as the upper bound. A black fade ends it too: the scene at -// the walk's end takes over. Fails as "walk_no_end" if neither shows -// within it. +// Walks `move`, holding its last leg in slices of 250 ms +// (hold_last_leg()) until a look shows `end` (a fade, the box of a talk +// the walk runs into, or the A prompt of what it walks to), the leg's +// time as the upper bound. A black fade ends it too: the scene at the +// walk's end takes over. A last leg that only turns is looked at once, +// after the turn. Fails as "walk_no_end" if neither shows within it. Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const StoryMove& move, ScreenEvent end); // Walks straight on, 250 ms at a time, until an A prompt shows @@ -51,6 +52,10 @@ Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const S // one. Pokemon::Outcome walk_to_prompt(PlzaBackend& backend, Milliseconds timeout); +// Whether an A prompt shows within `within`, looking every 250 ms: +// "talk" presses A only on one. +bool prompt_shows_within(PlzaBackend& backend, Milliseconds within); + // A at the A prompt the player stands at (a door's "A Enter"), then looks // for up to 3 s for a fade or text; while the prompt stays with neither, // A again, 3 times at most. The party bar shows under the prompt, so a diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index dfa3463bad..34b3a98262 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -33,6 +33,7 @@ #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h" #include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStorySceneMachine.h" +#include "PokemonLZA_AutoStoryTable.h" #include "PokemonLZA_AutoStoryGame.h" namespace PokemonAutomation{ @@ -119,7 +120,7 @@ std::vector make_specs(){ }, StoryArgSpec{ .key = "end", .type = StoryArgType::WORD, .required = false, .fallback = std::nullopt, - .why = "\"fade_white\", \"fade_black\" or \"dialog\": the last leg is held until it shows, its ms the bound", + .why = "\"fade_white\", \"fade_black\", \"dialog\" or \"prompt\" (an A prompt): the last leg is held until it shows, its ms the bound", }, flag("held", "hold the stick at each leg's angle (L only before a later turning leg), not tap-and-forward"), optional_int("wait_ms", "wait this long before looking for free control: NPCs moving off"), @@ -583,14 +584,22 @@ Outcome pokedex_step(Pokemon::StoryBackend& backend, const StoryAction } -// After A at what the player faces, how long "talk" waits for its text -// box, and how often it looks. +// How long "talk" looks for its A prompt before A, how long it waits for +// its text box after A, and how often it looks. +constexpr Milliseconds TALK_PROMPT_WAIT(1000); constexpr Milliseconds TALK_WAIT(5000); constexpr Milliseconds TALK_POLL(250); -// "talk": A at what the player faces, then a text box within TALK_WAIT; -// fails as "talk_no_text" without one. +// "talk": on the A prompt of what the player faces, A, then a text box +// within TALK_WAIT. With no prompt within TALK_PROMPT_WAIT it presses +// nothing and fails as "talk_no_prompt": the walk before it stopped short +// (03.02, console B 2026-11-16); with no text box, as "talk_no_text". Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + if (!prompt_shows_within(backend, TALK_PROMPT_WAIT)){ + return Pokemon::outcome_failed( + "talk_no_prompt", std::format("no A prompt within {} ms: not at what the talk is for", TALK_PROMPT_WAIT.count()) + ); + } backend.press(BUTTON_A, /*hold=*/160ms, /*release=*/240ms); for (Milliseconds waited(0); ; waited += TALK_POLL){ backend.scope().throw_if_cancelled(); @@ -761,9 +770,17 @@ std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpo } const std::string* word = std::get_if(&end->second); if (word == nullptr || !walk_end_event(*word)){ - errors.push_back(std::format("{} {}: \"end\" must be \"fade_white\", \"fade_black\" or \"dialog\"", checkpoint.id, step.name)); + errors.push_back(std::format( + "{} {}: \"end\" must be \"fade_white\", \"fade_black\", \"dialog\" or \"prompt\"", checkpoint.id, step.name + )); } } + for (std::string_view talk : story_row_talks_without_prompt(checkpoint)){ + errors.push_back(std::format( + "{} {}: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)", + checkpoint.id, talk + )); + } return errors; } @@ -777,6 +794,9 @@ std::optional walk_end_event(std::string_view end){ if (end == "dialog"){ return ScreenEvent::DIALOG_BOX; } + if (end == "prompt"){ + return ScreenEvent::INTERACT_PROMPT; + } return std::nullopt; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index baffa3e19c..f338518ff2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -48,7 +48,8 @@ namespace PokemonLZA{ // "walk" args "legs", [[turn, ms], ...] as // story_walk_move() reads them, "held", // "wait_ms", and "end", -// "fade_white", "fade_black" or "dialog"; +// "fade_white", "fade_black", "dialog" or +// "prompt" (an A prompt); // walked once the screen shows free control // (check_can_walk()), until its end event if it // has one (walk_until()), else until its legs @@ -65,7 +66,9 @@ namespace PokemonLZA{ // "choose_0", "choose_1" that row of the choice box on screen (0 the // top), by the D-pad from the highlighted row, // then A -// "talk" (TALK) A at what the player faces, then its text box +// "talk" (TALK) on the A prompt of what the player faces +// (none: nothing pressed, "talk_no_prompt"), +// A, then its text box // "a" (MASH, "scene") A through a scene until control; it must // start within 45 s // "story_battle_start" A through the talk before a story battle and @@ -73,7 +76,7 @@ namespace PokemonLZA{ // HUD (run_scene_machine()) // "story_battle" the battle, by the backend's battle() // "talk_through_map_screen" A and B in turn through Taunie's talk -// and the first map (03.02) +// and the first map (03.02b) // "climb_ladder" the side street's ladder (03.03) // "talk_to_pokedex_screen" B through the nurse's talk and the // Pokedex app (03.04) @@ -93,11 +96,13 @@ namespace PokemonLZA{ const std::vector& plza_story_specs(); // What is wrong with `checkpoint` for PLZA's engine -// (StoryActionRegistry::lint), then with a walk's "end". +// (StoryActionRegistry::lint), then with a walk's "end", then a talk not +// right after a step that ends on its A prompt (a walk to "prompt", or +// "walk_to_prompt"): a talk never presses A blind. std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpoint); -// The event a walk's "end" arg names: "fade_white", "fade_black" or -// "dialog". None for any other word. +// The event a walk's "end" arg names: "fade_white", "fade_black", +// "dialog" or "prompt" (INTERACT_PROMPT). None for any other word. std::optional walk_end_event(std::string_view end); // PLZA as a StoryGame on the console `env`, which must outlive it, as must 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 4458e9e063..996c63a240 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -70,7 +70,7 @@ const StoryDataCase STORY_DATA_CASES[] = { "01.00:new_game:autosave 01.01:from_save:unverified 01.02:from_save:unverified 01.03:from_save:unverified " "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:unverified 03.02:from_save 03.03:from_save:autosave 03.04:from_save " + "03.01:from_save:unverified 03.02:from_save:autosave 03.02b: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.08:from_save:autosave 03.08b:from_save " "03.09:from_save:unverified " "03.10:from_save:autosave 03.11:from_save:unverified" @@ -103,6 +103,8 @@ UnitTestResult check_story_data(const StoryDataCase& test){ struct LintCase{ std::string name; struct Input{ + // The steps before `step` in its checkpoint. + std::vector before = {}; StoryStep step; }; Input input; @@ -126,13 +128,50 @@ const LintCase LINT_CASES[] = { .input = {.step = {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { {"legs", std::vector{{.turn = 0, .walk = Milliseconds(4500)}}}, {"end", std::string("sideways")}, }}}, - .expectation = {.errors = "01.01 w: \"end\" must be \"fade_white\", \"fade_black\" or \"dialog\""}, + .expectation = {.errors = "01.01 w: \"end\" must be \"fade_white\", \"fade_black\", \"dialog\" or \"prompt\""}, }, { - .name = "a talk with no action passes", - .input = {.step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}}, + .name = "a walk to an A prompt passes", + .input = {.step = {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { + {"legs", std::vector{{.turn = 0, .walk = Milliseconds(3000)}}}, {"end", std::string("prompt")}, + }}}, + .expectation = {.errors = ""}, + }, + { + .name = "a talk after a walk to its A prompt passes", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { + {"legs", std::vector{{.turn = 0, .walk = Milliseconds(3000)}}}, {"end", std::string("prompt")}, + }}}, + .step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .expectation = {.errors = ""}, + }, + { + .name = "a talk after walk_to_prompt passes", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}}, + .step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, .expectation = {.errors = ""}, }, + { + // console B, 2026-11-16: 03.02's timed walk to Taunie stopped + // short of her, and the talk's A found no one. + .name = "a talk after a timed walk fails", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk", .args = { + {"legs", std::vector{{.turn = 0, .walk = Milliseconds(3000)}}}, + }}}, + .step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .expectation = {.errors = "01.01 t: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)"}, + }, + { + .name = "a checkpoint's first step cannot be a talk", + .input = {.step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}}, + .expectation = {.errors = "01.01 t: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)"}, + }, { .name = "an action PLZA does not have fails", .input = {.step = {.kind = Pokemon::StoryStepKind::GAME, .name = "m", .why = "", .action = "choose_7", .args = {}}}, @@ -144,6 +183,7 @@ UnitTestResult check_lint(const LintCase& test){ StoryCheckpoint checkpoint; checkpoint.id = "01.01"; checkpoint.title = "Test"; + checkpoint.steps = test.input.before; checkpoint.steps.push_back(test.input.step); const std::string got = joined(plza_story_lint(checkpoint), "; "); if (got != test.expectation.errors){ @@ -501,21 +541,29 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .line = "[Save] 01.02: not saved (save unverified)"}, }, { - .name = "01.03 walks to Chikorita: a turn left, then 750 ms", - .input = {.checkpoint = "01.03", .first_step = 0, .steps = 1, .looks = {look(/*events=*/{}, {CONTROLS_HINT_READING})}}, + .name = "01.03 walks to Chikorita: a turn left, then on to its A prompt", + .input = {.checkpoint = "01.03", .first_step = 0, .steps = 1, .looks = concat( + std::vector>(5, look(/*events=*/{}, {CONTROLS_HINT_READING})), {A_PROMPT} + )}, .expectation = { .verdict = "done", - .inputs = "wait 250ms, press L, stick -70deg 150ms walk, release 100ms, press L, hold north 750ms walk", + .inputs = "wait 250ms, press L, stick -70deg 150ms walk, release 100ms, press L, hold north 250ms walk, hold north 250ms walk", + .line = "[PLZA] approach_starter: the end event after 500 ms of the last leg.", }, }, { - .name = "01.03's talk to the starter: A, then the text box", - .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {CUTSCENE, DIALOG}}, - .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, + .name = "01.03's walk to Chikorita fails with no A prompt in its 750 ms", + .input = {.checkpoint = "01.03", .first_step = 0, .steps = 1, .looks = {look(/*events=*/{}, {CONTROLS_HINT_READING})}}, + .expectation = {.verdict = "failed at approach_starter: walk_no_end"}, + }, + { + .name = "01.03's talk to the starter: A at its prompt, then the text box", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, DIALOG}}, + .expectation = {.verdict = "done", .inputs = "press A"}, }, { .name = "01.03's talk fails when no text box shows", - .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {CUTSCENE}}, + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT}}, .expectation = {.verdict = "failed at talk_to_starter: talk_no_text"}, }, { @@ -601,6 +649,23 @@ const RunCase RUN_CASES[] = { }}, .expectation = {.verdict = "done", .inputs = "press A, wait 250ms, press A, wait 250ms"}, }, + { + .name = "02.04's walk to the clerk: along the counter, then the turn to her A prompt", + .input = {.checkpoint = "02.04", .first_step = 0, .steps = 1, .looks = concat( + std::vector>(6, party_bar(Milliseconds(0))), {A_PROMPT} + )}, + .expectation = { + .verdict = "done", + .inputs = "wait 250ms, press L, stick -5deg 150ms walk, release 100ms, press L, hold north 2500ms walk, " + "press L, stick -85deg 150ms walk, release 100ms, press L", + .line = "[PLZA] to_front_counter: the end event after the last turn.", + }, + }, + { + .name = "02.04's walk to the clerk fails with no A prompt after its last turn", + .input = {.checkpoint = "02.04", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at to_front_counter: walk_no_end"}, + }, { .name = "02.05's elevator: A through its line to the floor choice", .input = {.checkpoint = "02.05", .first_step = 2, .steps = 1, .looks = {DIALOG, choice(0, 3)}}, @@ -627,6 +692,13 @@ const RunCase RUN_CASES[] = { .line = "[PLZA mash_to_move_hints] done: quiet, taken as control.", }, }, + { + .name = "02.06 holds the stick at 45 degrees to the bed's A prompt", + .input = {.checkpoint = "02.06", .first_step = 0, .steps = 1, .looks = { + party_bar(Milliseconds(0)), party_bar(Milliseconds(0)), party_bar(Milliseconds(0)), A_PROMPT, + }}, + .expectation = {.verdict = "done", .inputs = "wait 250ms, stick 45deg 250ms walk, stick 45deg 250ms walk"}, + }, { .name = "02.06 with no autosave badge seen is not saved", .input = {.checkpoint = "02.06", .first_step = 4, .looks = { @@ -654,8 +726,34 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .line = "[PLZA] autosave badge at 1.0s in wake_up"}, }, { - .name = "03.02's map talk: A and B in turn, done on the party bar held a second", - .input = {.checkpoint = "03.02", .first_step = 6, .steps = 1, .looks = { + .name = "03.02b walks on to Taunie's A prompt", + .input = {.checkpoint = "03.02b", .first_step = 0, .steps = 1, .looks = concat( + std::vector>(4, party_bar(Milliseconds(0))), {A_PROMPT} + )}, + .expectation = { + .verdict = "done", + .inputs = "wait 250ms, hold north 250ms walk, hold north 250ms walk", + .line = "[PLZA] to_taunie_at_gate: the end event after 500 ms of the last leg.", + }, + }, + { + .name = "03.02b's walk to Taunie fails with no A prompt within its bound", + .input = {.checkpoint = "03.02b", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at to_taunie_at_gate: walk_no_end"}, + }, + { + // console B, 2026-11-16: the walk stopped short of Taunie, under + // the Quartiere Verde arch, and the talk's A found no one. + .name = "03.02b's talk presses nothing without Taunie's A prompt", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = { + .verdict = "failed at talk_to_taunie: talk_no_prompt", + .inputs = "wait 250ms, wait 250ms, wait 250ms, wait 250ms", + }, + }, + { + .name = "03.02b's map talk: A and B in turn, done on the party bar held a second", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { DIALOG, look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, .expectation = { @@ -665,8 +763,8 @@ const RunCase RUN_CASES[] = { }, }, { - .name = "03.02's map talk goes on through the party bar under a text box", - .input = {.checkpoint = "03.02", .first_step = 6, .steps = 1, .looks = { + .name = "03.02b's map talk goes on through the party bar under a text box", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), @@ -674,8 +772,8 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .inputs = "press A, press B, press A, press B, wait 250ms"}, }, { - .name = "03.02's map talk fails with no party bar in 120 s", - .input = {.checkpoint = "03.02", .first_step = 6, .steps = 1, .looks = { + .name = "03.02b's map talk fails with no party bar in 120 s", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { look(/*events=*/{}, /*readings=*/{}, Milliseconds(0)), look(/*events=*/{}, /*readings=*/{}, Milliseconds(121000)), }}, .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press A, press B"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index f010a83691..2384973b15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -4,6 +4,8 @@ * */ +#include +#include #include "PokemonLZA_AutoStoryTable.h" namespace PokemonAutomation{ @@ -19,6 +21,35 @@ bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row){ return first.kind == Pokemon::StoryStepKind::GAME && (first.action == "new_game_intro" || first.action == "confirm_new_game"); } +namespace{ + +// Whether `step` ends on an A prompt: a walk to "prompt", or +// walk_to_prompt. +bool ends_on_prompt(const Pokemon::StoryStep& step){ + if (step.action == "walk_to_prompt"){ + return true; + } + const auto end = step.args.find("end"); + if (step.action != "walk" || end == step.args.end()){ + return false; + } + const std::string* word = std::get_if(&end->second); + return word != nullptr && *word == "prompt"; +} + +} // namespace + +std::vector story_row_talks_without_prompt(const Pokemon::StoryCheckpoint& row){ + std::vector talks; + for (size_t index = 0; index < row.steps.size(); index++){ + const Pokemon::StoryStep& step = row.steps[index]; + if (step.kind == Pokemon::StoryStepKind::TALK && (index == 0 || !ends_on_prompt(row.steps[index - 1]))){ + talks.push_back(step.name); + } + } + return talks; +} + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index d02c9c624f..f7ed044b7b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -18,6 +18,8 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStoryTable_H #define PokemonAutomation_PokemonLZA_AutoStoryTable_H +#include +#include #include "Pokemon/AutoStory/Data/Pokemon_StoryRowExecution.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" @@ -35,6 +37,13 @@ using StoryData = Pokemon::StoryData; // on "Confirm Choices"): 01.00. bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); +// The names of `row`'s TALK steps that do not come right after a step +// that ends on an A prompt: a "walk" to "end" "prompt", or +// "walk_to_prompt". A talk presses A only at the prompt the walk before +// reached: a timed walk can stop short of who the talk is for (03.02, +// console B 2026-11-16). The names live as long as `row`. +std::vector story_row_talks_without_prompt(const Pokemon::StoryCheckpoint& row); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json index 72db6c34c8..6de9af2b28 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.03.plan.json @@ -11,10 +11,11 @@ { "id": "approach_starter", "kind": "game_action", - "why": "walk up to Chikorita, the starter the run picks (the only walk recorded: console B, 2026-11-08), to its \"A Talk\" prompt", + "why": "walk up to Chikorita, the starter the run picks (the only walk recorded: console B, 2026-11-08), to its \"A Talk\" prompt not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[-70, 750]] + "legs": [[-70, 750]], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json index b29b1ffd4d..446fb92528 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.04.plan.json @@ -11,9 +11,9 @@ { "id": "to_front_counter", "kind": "game_action", - "why": "step 26: along the counter to the clerk's \"A Talk\". 2.25 s was one step short. Measured 2026-11-08 on console B, walk not run.", + "why": "step 26: along the counter to the clerk's \"A Talk\". 2.25 s was one step short. Measured 2026-11-08 on console B, walk not run. Ends on the A prompt after the turn, or fails. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", - "args": {"legs": [[-5, 2500], [-85, 0]]} + "args": {"legs": [[-5, 2500], [-85, 0]], "end": "prompt"} }, { "id": "talk_to_clerk", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json index 2996652502..23f0990b2c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.05.plan.json @@ -11,9 +11,9 @@ { "id": "to_lobby_elevator", "kind": "game_action", - "why": "step 28: to the elevator's \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run.", + "why": "step 28: to the elevator's \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run: 2 s; on until the prompt, 3 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", - "args": {"legs": [[0, 2000]]} + "args": {"legs": [[0, 3000]], "end": "prompt"} }, { "id": "take_elevator_up", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json index 1992801f66..f953f4c022 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-02.06.plan.json @@ -11,9 +11,9 @@ { "id": "to_bed", "kind": "game_action", - "why": "step 31: to the bed's \"A Rest\". 1.5 s explored, 1 s enough. Measured 2026-11-08 on console B, walk not run.", + "why": "step 31: to the bed's \"A Rest\". 1.5 s explored, 1 s enough. Measured 2026-11-08 on console B, walk not run. On until the prompt, 1.5 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", - "args": {"legs": [[45, 1000]], "held": true} + "args": {"legs": [[45, 1500]], "held": true, "end": "prompt"} }, { "id": "rest", diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json index f7ce2c2d71..b072167084 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.01.plan.json @@ -27,10 +27,11 @@ { "id": "to_2f_elevator", "kind": "game_action", - "why": "step 37: down the 2F hallway to \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run.", + "why": "step 37: down the 2F hallway to \"A Take Elevator\". Measured 2026-11-08 on console B, walk not run: 2 s; on until the prompt, 3 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[-15, 2000]] + "legs": [[-15, 3000]], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json index 72feac8078..959508c7ae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02.plan.json @@ -3,7 +3,7 @@ "game": "plza", "checkpoint": { "id": "03.02", - "title": "Out of Hotel Z, battle Taunie", + "title": "Out of Hotel Z", "start": { "place": "HotelZ" }, @@ -23,50 +23,14 @@ "why": "steps 40-41: A Leave at the door (a scene step ends at once on its prompt), the Main Menu tutorial card", "action": "mash_to_move_hints", "args": {"press_a_first": true} - }, - { - "id": "to_taunie_at_gate", - "kind": "game_action", - "why": "step 41: to Taunie at the gate, \"A Talk Taunie\". Measured 2026-11-08 on console B, walk not run.", - "action": "walk", - "args": { - "legs": [[0, 3000]] - } - }, - { - "id": "talk_to_taunie", - "kind": "talk", - "why": "step 42: A at Taunie" - }, - { - "id": "battle_totodile", - "kind": "game_action", - "why": "steps 42-43: A through her talk and challenge (no A hint, a subtitle with no text box), then beat Totodile, until \"We're not done just yet!\"", - "action": "story_battle" - }, - { - "id": "battle_tepig", - "kind": "game_action", - "why": "step 44: A through the Type Matchups tutorial (3 pages) and Tepig's send-out, then beat Tepig, until Taunie's speech", - "action": "story_battle" - }, - { - "id": "after_taunie_battle", - "kind": "game_action", - "why": "step 45: Taunie's talk and the Map & Missions card with A, the map closed with B, her talk with B", - "action": "talk_through_map_screen" - }, - { - "id": "taunie_runs_off", - "kind": "game_action", - "why": "step 45: the Main Missions card (A turns its pages; a scene step only waits on it), Taunie runs off (console B, 2026-11-10)", - "action": "mash_to_move_hints" } ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: the game does not autosave at its end (2026-11-15 save review); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends outside Hotel Z at the autosave seen in leave_hotel_z, after the Main Menu card (console B, 2026-11-16: badge at 116 s in the step), so a checkpoint starts where that save reloads; 03.02b goes on to Taunie." } }, - "execution": {} + "execution": { + "save": "autosave" + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json new file mode 100644 index 0000000000..1e140a689f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json @@ -0,0 +1,57 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "plza", + "checkpoint": { + "id": "03.02b", + "title": "Battle Taunie", + "start": { + "place": "LumioseCity" + }, + "events": [ + { + "id": "to_taunie_at_gate", + "kind": "game_action", + "why": "step 41: on to Taunie at the gate until her \"A Talk Taunie\". Measured 2026-11-08 on console B as 3 s, walk not run; on 2026-11-16 those 3 s stopped short of her, under the Quartiere Verde arch with Taunie a few steps ahead and no prompt. 8 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", + "action": "walk", + "args": { + "legs": [[0, 8000]], + "end": "prompt" + } + }, + { + "id": "talk_to_taunie", + "kind": "talk", + "why": "step 42: A at Taunie" + }, + { + "id": "battle_totodile", + "kind": "game_action", + "why": "steps 42-43: A through her talk and challenge (no A hint, a subtitle with no text box), then beat Totodile, until \"We're not done just yet!\"", + "action": "story_battle" + }, + { + "id": "battle_tepig", + "kind": "game_action", + "why": "step 44: A through the Type Matchups tutorial (3 pages) and Tepig's send-out, then beat Tepig, until Taunie's speech", + "action": "story_battle" + }, + { + "id": "after_taunie_battle", + "kind": "game_action", + "why": "step 45: Taunie's talk and the Map & Missions card with A, the map closed with B, her talk with B", + "action": "talk_through_map_screen" + }, + { + "id": "taunie_runs_off", + "kind": "game_action", + "why": "step 45: the Main Missions card (A turns its pages; a scene step only waits on it), Taunie runs off (console B, 2026-11-10)", + "action": "mash_to_move_hints" + } + ], + "metadata": { + "phase": "testing", + "source": "console B recording, 2026-11-08/09: played step by step from a new game; split from 03.02 at the autosave outside Hotel Z (console B, 2026-11-16), so a checkpoint starts where that save reloads. Starts outside Hotel Z after the Main Menu card; nothing reads that spot yet, so its start is unchecked. No save: the game does not autosave at its end (2026-11-15 save review)." + } + }, + "execution": {} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json index 837d27c2ce..40580b0003 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json @@ -11,10 +11,11 @@ { "id": "into_pokemon_center", "kind": "game_action", - "why": "step 53: into the Pokemon Center, to the nurse's \"A Talk\". The last turn (\"right\") had no angle recorded: 90 is a guess. Measured 2026-11-08 on console B, walk not run.", + "why": "step 53: into the Pokemon Center, to the nurse's \"A Talk\". The last turn (\"right\") had no angle recorded: 90 is a guess. Measured 2026-11-08 on console B, walk not run. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[0, 3000], [20, 2000], [-90, 2000], [90, 0]] + "legs": [[0, 3000], [20, 2000], [-90, 2000], [90, 0]], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json index 22c57540b5..c4f83148fa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json @@ -12,10 +12,11 @@ { "id": "back_to_nurse", "kind": "game_action", - "why": "back to the nurse after 03.04's scene: turn right and walk into the counter, which faces her (user, console B, 2026-11-13); the counter stops the walk, so 2 s is safe.", + "why": "back to the nurse after 03.04's scene: turn right and walk into the counter, which faces her (user, console B, 2026-11-13); the counter stops the walk, so 2 s is safe; on until the prompt, 3 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[90, 2000]] + "legs": [[90, 3000]], + "end": "prompt" } }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json index 19ba7b0406..0ac58d0bf9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.10.plan.json @@ -11,15 +11,16 @@ { "id": "to_lab_elevator", "kind": "game_action", - "why": "step 66: to the elevator's \"A Take Elevator\". Measured 2026-11-09 on console B, walk not run.", + "why": "step 66: to the elevator's \"A Take Elevator\". Measured 2026-11-09 on console B, walk not run: 1 s; on until the prompt, 1.5 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { "legs": [ [ 0, - 1000 + 1500 ] - ] + ], + "end": "prompt" } }, { From 0f9f38292d317540fd2ddd41c6c8795b56a1467a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 01:23:19 -0800 Subject: [PATCH 14/24] PLZA AutoStory: a talk has started on any scene, not only a text box 03.02b on console B (2026-11-16): the walk ended on Taunie's prompt, A opened her talk on a dimmed "Smart Rotom" card with no text box, and talk_to_taunie failed as talk_no_text. "talk" now takes the shared scene-start rule (scene_under_way(), now public and counting a tutorial card) for its talk having started: text, a subtitle's chevron, a choice, a battle, a card, a fade, or a moving screen with no HUD. The HUD staying after A is the failure, "talk_no_scene". Every TALK step runs this one handler. --- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 16 +++++---- .../AutoStory/PokemonLZA_AutoStoryGame.h | 4 ++- .../PokemonLZA_AutoStoryGame_Tests.cpp | 35 +++++++++++++++++-- .../PokemonLZA_AutoStorySceneMachine.cpp | 26 ++++++-------- .../PokemonLZA_AutoStorySceneMachine.h | 13 +++++++ 5 files changed, 68 insertions(+), 26 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 34b3a98262..c9fe09536b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -585,15 +585,17 @@ Outcome pokedex_step(Pokemon::StoryBackend& backend, const StoryAction // How long "talk" looks for its A prompt before A, how long it waits for -// its text box after A, and how often it looks. +// its scene to start after A, and how often it looks. constexpr Milliseconds TALK_PROMPT_WAIT(1000); constexpr Milliseconds TALK_WAIT(5000); constexpr Milliseconds TALK_POLL(250); -// "talk": on the A prompt of what the player faces, A, then a text box -// within TALK_WAIT. With no prompt within TALK_PROMPT_WAIT it presses -// nothing and fails as "talk_no_prompt": the walk before it stopped short -// (03.02, console B 2026-11-16); with no text box, as "talk_no_text". +// "talk": on the A prompt of what the player faces, A, then its scene +// under way within TALK_WAIT (scene_under_way(): text, a subtitle, a +// card, a fade or a textless cutscene; Taunie's opens on a card, 03.02b). +// With no prompt within TALK_PROMPT_WAIT it presses nothing and fails as +// "talk_no_prompt": the walk before it stopped short (03.02, console B +// 2026-11-16); with nothing started after A, as "talk_no_scene". Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ if (!prompt_shows_within(backend, TALK_PROMPT_WAIT)){ return Pokemon::outcome_failed( @@ -603,7 +605,7 @@ Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCal backend.press(BUTTON_A, /*hold=*/160ms, /*release=*/240ms); for (Milliseconds waited(0); ; waited += TALK_POLL){ backend.scope().throw_if_cancelled(); - if (backend.observe().events.has(ScreenEvent::DIALOG_BOX)){ + if (scene_under_way(backend.observe())){ return Pokemon::outcome_ok(); } if (waited >= TALK_WAIT){ @@ -611,7 +613,7 @@ Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCal } backend.wait(TALK_POLL); } - return Pokemon::outcome_failed("talk_no_text", std::format("no text box within {} ms of A", TALK_WAIT.count())); + return Pokemon::outcome_failed("talk_no_scene", std::format("nothing started within {} ms of A: the HUD stayed", TALK_WAIT.count())); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index f338518ff2..eb3af393c5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -68,7 +68,9 @@ namespace PokemonLZA{ // then A // "talk" (TALK) on the A prompt of what the player faces // (none: nothing pressed, "talk_no_prompt"), -// A, then its text box +// A, then its scene under way +// (scene_under_way(): text, a subtitle, a +// card, a fade or a textless cutscene) // "a" (MASH, "scene") A through a scene until control; it must // start within 45 s // "story_battle_start" A through the talk before a story battle and 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 996c63a240..ef98142712 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -562,9 +562,14 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .inputs = "press A"}, }, { - .name = "01.03's talk fails when no text box shows", + .name = "01.03's talk fails when nothing starts after A: the prompt stays", .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT}}, - .expectation = {.verdict = "failed at talk_to_starter: talk_no_text"}, + .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, + }, + { + .name = "a talk fails when the party bar stays after A", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, }, { .name = "01.03's battle start: A through the talk and the tutorial card, done on the battle HUD", @@ -751,6 +756,32 @@ const RunCase RUN_CASES[] = { .inputs = "wait 250ms, wait 250ms, wait 250ms, wait 250ms", }, }, + { + // console B, 2026-11-16: A at Taunie dimmed the screen into a + // "Smart Rotom" card, with no text box: her talk had started. + .name = "03.02b's talk to Taunie starts on a tutorial card with no text box", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { + A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {TUTORIAL_CARD_READING}), + }}, + .expectation = {.verdict = "done", .inputs = "press A"}, + }, + { + .name = "03.02b's talk to Taunie starts on a subtitle: the advance chevron with no text box", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { + A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {ADVANCE_ARROW_READING}), + }}, + .expectation = {.verdict = "done", .inputs = "press A"}, + }, + { + .name = "03.02b's talk to Taunie starts on a fade", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {A_PROMPT, BLACK_FADE}}, + .expectation = {.verdict = "done", .inputs = "press A"}, + }, + { + .name = "03.02b's talk to Taunie starts on a textless cutscene: the screen moving with no HUD", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {A_PROMPT, CUTSCENE}}, + .expectation = {.verdict = "done", .inputs = "press A"}, + }, { .name = "03.02b's map talk: A and B in turn, done on the party bar held a second", .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index a78939b5b4..4e019d2e29 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -188,22 +188,6 @@ bool hud_shows(const ScreenObservation& look){ 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). @@ -849,6 +833,16 @@ Pokemon::Outcome scene_outcome( } // namespace +bool scene_under_way(const ScreenObservation& look){ + if (scene_shows(look) || look.readings.contains(TUTORIAL_CARD_READING)){ + return true; + } + if (hud_shows(look)){ + return false; + } + return fade_shows(look) || !look.events.has(ScreenEvent::SCREEN_STILL); +} + Pokemon::Outcome run_scene_machine( PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, Milliseconds timeout ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 78b278cd01..ea8b0304d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -34,6 +34,7 @@ #include #include #include "Common/Cpp/Time.h" +#include "CommonTools/ScreenMachine/ScreenObservation.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" #include "PokemonLZA_AutoStoryBackend.h" @@ -95,6 +96,18 @@ struct SceneMachineConfig{ std::optional end_after_black_fades = std::nullopt; }; +// A scene is under way on `look`: text (a box, or a subtitle's advance +// chevron), a choice, a battle or a tutorial card, or, with no HUD up (the +// party bar, the controls hint, an A prompt), 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. "talk" takes it for its talk having started: Taunie's +// (03.02b) opens on a dimmed "Smart Rotom" card with no text box (console +// B, 2026-11-16). +bool scene_under_way(const ScreenObservation& look); + // 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 From 9145e7fa4e68a8e15c716ff7566464f6781adcbd Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 01:43:51 -0800 Subject: [PATCH 15/24] PLZA AutoStory: story battles start from story_battle_start; a talk's start holds two looks 03.02b run 2 on console B (2026-11-16): the walk ended on an A prompt at 3250 ms (as in run 1, where A at it opened a dimmed "Smart Rotom" card), the talk counted as started 0.4 s after A, and story_battle ran the battle code on the overworld for 2 min ("Failed to lock on"). - 03.02b presses through Taunie's talk and cards to the battle HUD with story_battle_start before each battle, as 01.03 and 02.01 do. - The lint fails a story_battle not right after story_battle_start. - story_battle fights only on the battle HUD within 10 s, else "battle_never_started", nothing pressed. - "talk" needs its scene under way on two looks in a row, not one look of the press, and logs the look it started on; a walk to an end event logs the look it ended on. --- .../PokemonLZA_AutoStoryWalkScreenChecks.cpp | 6 +- .../PokemonLZA_AutoStoryWalkScreenChecks.h | 8 ++- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 30 ++++++---- .../AutoStory/PokemonLZA_AutoStoryGame.h | 5 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 60 ++++++++++++++++--- .../PokemonLZA_AutoStorySceneMachine.cpp | 5 ++ .../PokemonLZA_AutoStorySceneMachine.h | 5 ++ .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 17 ++++-- .../AutoStory/PokemonLZA_AutoStoryTable.h | 17 +++--- .../AutoStory/StoryData/plza-03.02b.plan.json | 16 ++++- 10 files changed, 128 insertions(+), 41 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp index 353aa0399c..82cd671c29 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -10,6 +10,7 @@ #include #include #include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h" #include "PokemonLZA_AutoStoryWalkScreenChecks.h" namespace PokemonAutomation{ @@ -152,6 +153,7 @@ Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const S const Pokemon::Observation look = backend.observe(); if (look.events.has(end)){ backend.log(std::format("[PLZA] {}: the end event after {} ms of the last leg.", walk, held.count())); + backend.log_detail(std::format("[PLZA] {}: ended on: {}", walk, describe_scene_look(look))); return Pokemon::outcome_ok(); } if (look.events.has(ScreenEvent::FADE_BLACK)){ @@ -177,10 +179,10 @@ Pokemon::Outcome walk_to_prompt(PlzaBackend& backend, Milliseconds timeout){ return Pokemon::outcome_failed("no_prompt", std::format("walk_to_prompt: no A prompt in {} ms of walking", timeout.count())); } -bool prompt_shows_within(PlzaBackend& backend, Milliseconds within){ +bool event_shows_within(PlzaBackend& backend, ScreenEvent event, Milliseconds within){ for (Milliseconds waited = 0ms; ; waited += PROMPT_POLL){ backend.scope().throw_if_cancelled(); - if (backend.observe().events.has(ScreenEvent::INTERACT_PROMPT)){ + if (backend.observe().events.has(event)){ return true; } if (waited >= within){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h index baafb17aa1..f86d417c2e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h @@ -52,9 +52,11 @@ Pokemon::Outcome walk_until(PlzaBackend& backend, std::string_view walk, const S // one. Pokemon::Outcome walk_to_prompt(PlzaBackend& backend, Milliseconds timeout); -// Whether an A prompt shows within `within`, looking every 250 ms: -// "talk" presses A only on one. -bool prompt_shows_within(PlzaBackend& backend, Milliseconds within); +// Whether a look shows `event` within `within`, looking every 250 ms and +// pressing nothing: "talk" presses A only on an A prompt +// (INTERACT_PROMPT), "story_battle" fights only on the battle HUD +// (BATTLE_STARTED). +bool event_shows_within(PlzaBackend& backend, ScreenEvent event, Milliseconds within); // A at the A prompt the player stands at (a door's "A Enter"), then looks // for up to 3 s for a fade or text; while the prompt stays with neither, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index c9fe09536b..03102c1329 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -553,8 +553,12 @@ Outcome battle_start_step(Pokemon::StoryBackend& backend, const StoryA return run_scene_machine(backend, "story_battle_start", config, 90s); } -// "story_battle": the battle on screen, by the backend's battle code. +// "story_battle": the backend's battle code, on the battle HUD within 10 s; +// else "battle_never_started" (03.02b looked 2 min on the overworld, 2026-11-16). Outcome battle_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + if (!event_shows_within(backend, ScreenEvent::BATTLE_STARTED, 10s)){ + return Pokemon::outcome_failed("battle_never_started", "no battle HUD within 10 s"); + } return backend.battle(); } @@ -591,21 +595,24 @@ constexpr Milliseconds TALK_WAIT(5000); constexpr Milliseconds TALK_POLL(250); // "talk": on the A prompt of what the player faces, A, then its scene -// under way within TALK_WAIT (scene_under_way(): text, a subtitle, a -// card, a fade or a textless cutscene; Taunie's opens on a card, 03.02b). -// With no prompt within TALK_PROMPT_WAIT it presses nothing and fails as -// "talk_no_prompt": the walk before it stopped short (03.02, console B -// 2026-11-16); with nothing started after A, as "talk_no_scene". +// under way (scene_under_way(): Taunie's opens on a card, 03.02b) on two +// looks in a row within TALK_WAIT, not one look of the press itself. No +// prompt within TALK_PROMPT_WAIT: nothing pressed, "talk_no_prompt" (the +// walk stopped short, 03.02, 2026-11-16); nothing after A: "talk_no_scene". Outcome talk_step(Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ - if (!prompt_shows_within(backend, TALK_PROMPT_WAIT)){ + if (!event_shows_within(backend, ScreenEvent::INTERACT_PROMPT, TALK_PROMPT_WAIT)){ return Pokemon::outcome_failed( "talk_no_prompt", std::format("no A prompt within {} ms: not at what the talk is for", TALK_PROMPT_WAIT.count()) ); } backend.press(BUTTON_A, /*hold=*/160ms, /*release=*/240ms); + size_t scene_looks = 0; for (Milliseconds waited(0); ; waited += TALK_POLL){ backend.scope().throw_if_cancelled(); - if (scene_under_way(backend.observe())){ + const Pokemon::Observation look = backend.observe(); + scene_looks = scene_under_way(look) ? scene_looks + 1 : 0; + if (scene_looks >= 2){ + backend.log_detail(std::format("[PLZA] talk: started {} ms after A: {}", waited.count(), describe_scene_look(look))); return Pokemon::outcome_ok(); } if (waited >= TALK_WAIT){ @@ -777,11 +784,8 @@ std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpo )); } } - for (std::string_view talk : story_row_talks_without_prompt(checkpoint)){ - errors.push_back(std::format( - "{} {}: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)", - checkpoint.id, talk - )); + for (const std::string& error : story_row_lead_in_errors(checkpoint)){ + errors.push_back(std::format("{} {}", checkpoint.id, error)); } return errors; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index eb3af393c5..89a56f34d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -76,7 +76,10 @@ namespace PokemonLZA{ // "story_battle_start" A through the talk before a story battle and // the battle tutorial's cards until the battle // HUD (run_scene_machine()) -// "story_battle" the battle, by the backend's battle() +// "story_battle" the battle, by the backend's battle(), on +// the battle HUD within 10 s, else +// "battle_never_started"; right after +// "story_battle_start" (the lint) // "talk_through_map_screen" A and B in turn through Taunie's talk // and the first map (03.02b) // "climb_ladder" the side street's ladder (03.03) 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 ef98142712..f22f4a191a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -167,6 +167,27 @@ const LintCase LINT_CASES[] = { }, .expectation = {.errors = "01.01 t: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)"}, }, + { + .name = "a story battle after story_battle_start passes", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "s", .why = "", .action = "story_battle_start", .args = {}}}, + .step = {.kind = Pokemon::StoryStepKind::GAME, .name = "b", .why = "", .action = "story_battle", .args = {}}, + }, + .expectation = {.errors = ""}, + }, + { + // console B, 2026-11-16 (03.02b run 2): the battle ran right after + // the talk, with no battle on screen. + .name = "a story battle right after a talk fails", + .input = { + .before = { + {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}, + {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .step = {.kind = Pokemon::StoryStepKind::GAME, .name = "b", .why = "", .action = "story_battle", .args = {}}, + }, + .expectation = {.errors = "01.01 b: a story battle must follow story_battle_start, which ends on the battle HUD"}, + }, { .name = "a checkpoint's first step cannot be a talk", .input = {.step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}}, @@ -559,13 +580,20 @@ const RunCase RUN_CASES[] = { { .name = "01.03's talk to the starter: A at its prompt, then the text box", .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, DIALOG}}, - .expectation = {.verdict = "done", .inputs = "press A"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "01.03's talk fails when nothing starts after A: the prompt stays", .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT}}, .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, }, + { + // console B, 2026-11-16 (03.02b run 2): the talk counted as + // started 0.4 s after A, and no battle followed. + .name = "a talk does not start on one moving look that the party bar follows", + .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, CUTSCENE, party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at talk_to_starter: talk_no_scene"}, + }, { .name = "a talk fails when the party bar stays after A", .input = {.checkpoint = "01.03", .first_step = 1, .steps = 1, .looks = {A_PROMPT, party_bar(Milliseconds(0))}}, @@ -589,6 +617,13 @@ const RunCase RUN_CASES[] = { .input = {.checkpoint = "01.03", .first_step = 3, .steps = 1, .looks = {BATTLE_HUD}}, .expectation = {.verdict = "done", .inputs = "battle"}, }, + { + // console B, 2026-11-16 (03.02b run 2): the battle code looked for + // a battle for 2 min on the overworld. + .name = "a story battle with no battle HUD in 10 s fails as battle_never_started, the battle code not run", + .input = {.checkpoint = "01.03", .first_step = 3, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .expectation = {.verdict = "failed at andi_battle: battle_never_started", .inputs = repeated("wait 250ms", 40)}, + }, { .name = "01.03's battle fails as the backend's battle does", .input = {.checkpoint = "01.03", .first_step = 3, .steps = 1, .looks = {BATTLE_HUD}, @@ -763,28 +798,37 @@ const RunCase RUN_CASES[] = { .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {TUTORIAL_CARD_READING}), }}, - .expectation = {.verdict = "done", .inputs = "press A"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's talk to Taunie starts on a subtitle: the advance chevron with no text box", .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {ADVANCE_ARROW_READING}), }}, - .expectation = {.verdict = "done", .inputs = "press A"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's talk to Taunie starts on a fade", .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {A_PROMPT, BLACK_FADE}}, - .expectation = {.verdict = "done", .inputs = "press A"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's talk to Taunie starts on a textless cutscene: the screen moving with no HUD", .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {A_PROMPT, CUTSCENE}}, - .expectation = {.verdict = "done", .inputs = "press A"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, + }, + { + .name = "03.02b's battle start: A through Taunie's subtitles and the card, done on the battle HUD", + .input = {.checkpoint = "03.02b", .first_step = 2, .steps = 1, .looks = { + look(/*events=*/{}, {ADVANCE_ARROW_READING}, Milliseconds(0)), + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(500)), + look({ScreenEvent::BATTLE_STARTED}, /*readings=*/{}, Milliseconds(1000)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA story_battle_start] done on battle."}, }, { .name = "03.02b's map talk: A and B in turn, done on the party bar held a second", - .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 6, .steps = 1, .looks = { DIALOG, look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, .expectation = { @@ -795,7 +839,7 @@ const RunCase RUN_CASES[] = { }, { .name = "03.02b's map talk goes on through the party bar under a text box", - .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 6, .steps = 1, .looks = { look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), @@ -804,7 +848,7 @@ const RunCase RUN_CASES[] = { }, { .name = "03.02b's map talk fails with no party bar in 120 s", - .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 6, .steps = 1, .looks = { look(/*events=*/{}, /*readings=*/{}, Milliseconds(0)), look(/*events=*/{}, /*readings=*/{}, Milliseconds(121000)), }}, .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press A, press B"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index 4e019d2e29..b3c66f3150 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -469,6 +469,7 @@ std::string describe_look(const ScreenObservation& look){ const std::pair readings[] = { {CONTROLS_HINT_READING, "controls hint"}, {ADVANCE_ARROW_READING, "advance arrow"}, {MISSION_BANNER_READING, "mission banner"}, {MISSION_COMPLETE_READING, "mission complete"}, + {TUTORIAL_CARD_READING, "tutorial card"}, }; std::string text; const auto add = [&text](std::string_view name){ @@ -833,6 +834,10 @@ Pokemon::Outcome scene_outcome( } // namespace +std::string describe_scene_look(const ScreenObservation& look){ + return describe_look(look); +} + bool scene_under_way(const ScreenObservation& look){ if (scene_shows(look) || look.readings.contains(TUTORIAL_CARD_READING)){ return true; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index ea8b0304d7..58b67e5d62 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -32,6 +32,7 @@ #define PokemonAutomation_PokemonLZA_AutoStorySceneMachine_H #include +#include #include #include "Common/Cpp/Time.h" #include "CommonTools/ScreenMachine/ScreenObservation.h" @@ -108,6 +109,10 @@ struct SceneMachineConfig{ // B, 2026-11-16). bool scene_under_way(const ScreenObservation& look); +// "text box, advance arrow": `look`'s events and readings, as the scene +// machine logs them; "nothing" for none. +std::string describe_scene_look(const ScreenObservation& look); + // 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index 2384973b15..798a41c156 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include "PokemonLZA_AutoStoryTable.h" @@ -39,15 +40,21 @@ bool ends_on_prompt(const Pokemon::StoryStep& step){ } // namespace -std::vector story_row_talks_without_prompt(const Pokemon::StoryCheckpoint& row){ - std::vector talks; +std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint& row){ + std::vector errors; for (size_t index = 0; index < row.steps.size(); index++){ const Pokemon::StoryStep& step = row.steps[index]; - if (step.kind == Pokemon::StoryStepKind::TALK && (index == 0 || !ends_on_prompt(row.steps[index - 1]))){ - talks.push_back(step.name); + const Pokemon::StoryStep* before = index == 0 ? nullptr : &row.steps[index - 1]; + if (step.kind == Pokemon::StoryStepKind::TALK && (before == nullptr || !ends_on_prompt(*before))){ + errors.push_back(std::format( + "{}: a talk must follow a step that ends on its A prompt (a walk to \"end\": \"prompt\", or walk_to_prompt)", step.name + )); + } + if (step.action == "story_battle" && (before == nullptr || before->action != "story_battle_start")){ + errors.push_back(std::format("{}: a story battle must follow story_battle_start, which ends on the battle HUD", step.name)); } } - return talks; + return errors; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index f7ed044b7b..d7dd20d231 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -18,7 +18,7 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStoryTable_H #define PokemonAutomation_PokemonLZA_AutoStoryTable_H -#include +#include #include #include "Pokemon/AutoStory/Data/Pokemon_StoryRowExecution.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" @@ -37,12 +37,15 @@ using StoryData = Pokemon::StoryData; // on "Confirm Choices"): 01.00. bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); -// The names of `row`'s TALK steps that do not come right after a step -// that ends on an A prompt: a "walk" to "end" "prompt", or -// "walk_to_prompt". A talk presses A only at the prompt the walk before -// reached: a timed walk can stop short of who the talk is for (03.02, -// console B 2026-11-16). The names live as long as `row`. -std::vector story_row_talks_without_prompt(const Pokemon::StoryCheckpoint& row); +// ": " for each step of `row` that does not come right after +// the step it needs (console B, 2026-11-16): +// - a TALK after a step that ends on an A prompt (a "walk" to "end" +// "prompt", or "walk_to_prompt"): a timed walk can stop short of who +// the talk is for (03.02); +// - a "story_battle" after "story_battle_start", which presses through +// the talk and cards to the battle HUD: the battle code run on the +// overworld looks for a battle for 2 min (03.02b). +std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint& row); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json index 1e140a689f..c4bfcb8467 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json @@ -23,16 +23,28 @@ "kind": "talk", "why": "step 42: A at Taunie" }, + { + "id": "taunie_battle_start", + "kind": "game_action", + "why": "steps 42-43: A through her talk and challenge (no A hint, subtitles with no text box, the Smart Rotom card) until the battle HUD (console B, 2026-11-16: the talk opened on the card; the battle code run straight after it looked 2 min for a battle on the overworld)", + "action": "story_battle_start" + }, { "id": "battle_totodile", "kind": "game_action", - "why": "steps 42-43: A through her talk and challenge (no A hint, a subtitle with no text box), then beat Totodile, until \"We're not done just yet!\"", + "why": "step 43: beat Totodile, until \"We're not done just yet!\"", "action": "story_battle" }, + { + "id": "tepig_battle_start", + "kind": "game_action", + "why": "step 44: A through \"We're not done just yet!\", the Type Matchups tutorial (3 pages) and Tepig's send-out until the battle HUD", + "action": "story_battle_start" + }, { "id": "battle_tepig", "kind": "game_action", - "why": "step 44: A through the Type Matchups tutorial (3 pages) and Tepig's send-out, then beat Tepig, until Taunie's speech", + "why": "step 44: beat Tepig, until Taunie's speech", "action": "story_battle" }, { From edcd305a0218204c6aa72ec70c1326a795adc2f0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 01:52:06 -0800 Subject: [PATCH 16/24] PLZA AutoStory: 03.02b walks to Taunie after the plaza scene; a battle start ending in control fails at once 03.02b run 3 on console B (2026-11-16): the first A prompt 3.25 s from the reload spot starts a scene (a fade, the Smart Rotom card, a fade) that hands control back at the Quartiere Verde arch, Taunie a few steps ahead; story_battle_start then waited 90 s on the party bar. - 03.02b: to_plaza_scene_prompt, plaza_scene (A at its prompt, the scene to control), to_taunie (walk_to_prompt, 8 s), then her talk and the battles. - The scene machine with stop_at_battle or stop_at_choice ends at once, failing as "scene_ended_in_control", when the party bar holds 5 s with nothing busy; shorter shows between a talk's lines go on. --- .../PokemonLZA_AutoStoryGame_Tests.cpp | 65 +++++++++++++++---- .../PokemonLZA_AutoStorySceneMachine.cpp | 29 ++++++++- .../AutoStory/StoryData/plza-03.02b.plan.json | 31 +++++++-- 3 files changed, 105 insertions(+), 20 deletions(-) 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 f22f4a191a..fccc7aa07e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -766,26 +766,44 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .line = "[PLZA] autosave badge at 1.0s in wake_up"}, }, { - .name = "03.02b walks on to Taunie's A prompt", + .name = "03.02b walks on to the plaza scene's A prompt", .input = {.checkpoint = "03.02b", .first_step = 0, .steps = 1, .looks = concat( std::vector>(4, party_bar(Milliseconds(0))), {A_PROMPT} )}, .expectation = { .verdict = "done", .inputs = "wait 250ms, hold north 250ms walk, hold north 250ms walk", - .line = "[PLZA] to_taunie_at_gate: the end event after 500 ms of the last leg.", + .line = "[PLZA] to_plaza_scene_prompt: the end event after 500 ms of the last leg.", }, }, { - .name = "03.02b's walk to Taunie fails with no A prompt within its bound", + .name = "03.02b's walk to the plaza scene fails with no A prompt within its bound", .input = {.checkpoint = "03.02b", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, - .expectation = {.verdict = "failed at to_taunie_at_gate: walk_no_end"}, + .expectation = {.verdict = "failed at to_plaza_scene_prompt: walk_no_end"}, + }, + { + // console B, 2026-11-16 (run 3): the first prompt from the reload + // spot starts a scene (a fade, the Smart Rotom card, a fade) that + // hands control back at the arch, Taunie a few steps ahead. + .name = "03.02b's plaza scene: A at its prompt, through the fades, done on the party bar held a second", + .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { + A_PROMPT, BLACK_FADE, + look({ScreenEvent::SCREEN_STILL}, /*readings=*/{}, Milliseconds(1000)), + look({ScreenEvent::FADE_BLACK}, /*readings=*/{}, Milliseconds(11200)), + party_bar(Milliseconds(11800)), party_bar(Milliseconds(12900)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA mash_to_move_hints] done on can_move."}, + }, + { + .name = "03.02b walks on from the arch to Taunie's A prompt", + .input = {.checkpoint = "03.02b", .first_step = 2, .steps = 1, .looks = {party_bar(Milliseconds(0)), party_bar(Milliseconds(0)), A_PROMPT}}, + .expectation = {.verdict = "done", .inputs = "hold north 250ms walk, hold north 250ms walk"}, }, { // console B, 2026-11-16: the walk stopped short of Taunie, under // the Quartiere Verde arch, and the talk's A found no one. .name = "03.02b's talk presses nothing without Taunie's A prompt", - .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, .expectation = { .verdict = "failed at talk_to_taunie: talk_no_prompt", .inputs = "wait 250ms, wait 250ms, wait 250ms, wait 250ms", @@ -795,40 +813,61 @@ const RunCase RUN_CASES[] = { // console B, 2026-11-16: A at Taunie dimmed the screen into a // "Smart Rotom" card, with no text box: her talk had started. .name = "03.02b's talk to Taunie starts on a tutorial card with no text box", - .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = { A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {TUTORIAL_CARD_READING}), }}, .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's talk to Taunie starts on a subtitle: the advance chevron with no text box", - .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = { A_PROMPT, look({ScreenEvent::SCREEN_STILL}, {ADVANCE_ARROW_READING}), }}, .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's talk to Taunie starts on a fade", - .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {A_PROMPT, BLACK_FADE}}, + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = {A_PROMPT, BLACK_FADE}}, .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's talk to Taunie starts on a textless cutscene: the screen moving with no HUD", - .input = {.checkpoint = "03.02b", .first_step = 1, .steps = 1, .looks = {A_PROMPT, CUTSCENE}}, + .input = {.checkpoint = "03.02b", .first_step = 3, .steps = 1, .looks = {A_PROMPT, CUTSCENE}}, .expectation = {.verdict = "done", .inputs = "press A, wait 250ms"}, }, { .name = "03.02b's battle start: A through Taunie's subtitles and the card, done on the battle HUD", - .input = {.checkpoint = "03.02b", .first_step = 2, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { look(/*events=*/{}, {ADVANCE_ARROW_READING}, Milliseconds(0)), look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(500)), look({ScreenEvent::BATTLE_STARTED}, /*readings=*/{}, Milliseconds(1000)), }}, .expectation = {.verdict = "done", .line = "[PLZA story_battle_start] done on battle."}, }, + { + // console B, 2026-11-16 (run 3): the scene before Taunie handed + // control back with no battle, and the battle start waited 90 s. + .name = "a battle start that ends in control, the party bar held 5 s, fails at once", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + look({ScreenEvent::FADE_BLACK}, /*readings=*/{}, Milliseconds(0)), + party_bar(Milliseconds(1000)), party_bar(Milliseconds(3000)), party_bar(Milliseconds(6100)), + }}, + .expectation = {.verdict = "failed at taunie_battle_start: scene_ended_in_control"}, + }, + { + .name = "a battle start goes on through the party bar between the talk's lines", + .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), + party_bar(Milliseconds(1000)), party_bar(Milliseconds(4000)), + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(5000)), + party_bar(Milliseconds(6000)), + look({ScreenEvent::BATTLE_STARTED}, /*readings=*/{}, Milliseconds(9000)), + }}, + .expectation = {.verdict = "done", .line = "[PLZA story_battle_start] done on battle."}, + }, { .name = "03.02b's map talk: A and B in turn, done on the party bar held a second", - .input = {.checkpoint = "03.02b", .first_step = 6, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { DIALOG, look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, .expectation = { @@ -839,7 +878,7 @@ const RunCase RUN_CASES[] = { }, { .name = "03.02b's map talk goes on through the party bar under a text box", - .input = {.checkpoint = "03.02b", .first_step = 6, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), @@ -848,7 +887,7 @@ const RunCase RUN_CASES[] = { }, { .name = "03.02b's map talk fails with no party bar in 120 s", - .input = {.checkpoint = "03.02b", .first_step = 6, .steps = 1, .looks = { + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { look(/*events=*/{}, /*readings=*/{}, Milliseconds(0)), look(/*events=*/{}, /*readings=*/{}, Milliseconds(121000)), }}, .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press A, press B"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index b3c66f3150..0435c850e6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -48,6 +48,7 @@ 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 + ENDED_IN_CONTROL, // terminal, failing: with stop_at_battle or stop_at_choice, the party bar held CONTROL_INSTEAD_HOLD with nothing busy 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 @@ -105,6 +106,9 @@ class SceneTimeline{ std::optional m_party_bar_since; std::optional m_hint_since; std::optional m_prompt_since; + // With stop_at_battle or stop_at_choice: since when the party bar + // shows with nothing busy. + std::optional m_control_since; // 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. @@ -132,6 +136,12 @@ constexpr Milliseconds PARTY_BAR_HOLD = 1000ms; // 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; +// With stop_at_battle or stop_at_choice, the party bar showing this long +// with nothing busy is the scene over with no battle or choice: it shows +// for a moment between a talk's lines, but 03.02b's scene before Taunie +// handed control back and the battle start waited 90 s for a battle +// (console B, 2026-11-16). +constexpr Milliseconds CONTROL_INSTEAD_HOLD = 5000ms; // 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. @@ -208,8 +218,8 @@ constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::TALK_PROMPT, SceneScreen::PROMPT_SHOWING, - SceneScreen::AWAITING_SCENE, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, - SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, + SceneScreen::ENDED_IN_CONTROL, SceneScreen::AWAITING_SCENE, SceneScreen::NEVER_STARTED, SceneScreen::QUIET_END, + SceneScreen::BLIND_PRESS, SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, }; // Starts `since` when `shows` starts, clears it when it stops. @@ -242,6 +252,7 @@ std::string_view scene_screen_name(SceneScreen screen){ {SceneScreen::HINT_SHOWING, "hint_showing"}, {SceneScreen::TALK_PROMPT, "talk_prompt"}, {SceneScreen::PROMPT_SHOWING, "prompt_showing"}, + {SceneScreen::ENDED_IN_CONTROL, "ended_in_control"}, {SceneScreen::AWAITING_SCENE, "awaiting_scene"}, {SceneScreen::NEVER_STARTED, "never_started"}, {SceneScreen::QUIET_END, "quiet_end"}, @@ -262,7 +273,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::ENDED_IN_CONTROL; } // Whether this state's step presses (DIALOG the config's text button, @@ -391,6 +402,10 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (fades_settled(look.when)){ return SceneScreen::FADE_SETTLED; } + const bool control_held = m_control_since && look.when - *m_control_since >= CONTROL_INSTEAD_HOLD; + if (control_held && look.events.has(ScreenEvent::PLAYER_CAN_MOVE)){ + return SceneScreen::ENDED_IN_CONTROL; + } 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; @@ -439,6 +454,8 @@ void SceneTimeline::record(const ScreenObservation& 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); + const bool control_instead = !party_bar_is_control(m_config) && look.events.has(ScreenEvent::PLAYER_CAN_MOVE) && !busy(look); + track_since(control_instead, look.when, m_control_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; @@ -812,6 +829,12 @@ Pokemon::Outcome scene_outcome( label, config.start_window ? config.start_window->count() : 0, expected )); } + if (result.terminal == scene_screen_name(SceneScreen::ENDED_IN_CONTROL)){ + return Pokemon::outcome_failed("scene_ended_in_control", std::format( + "{}: the scene ended in control, the party bar up {} ms with nothing busy (expecting {}).", + label, CONTROL_INSTEAD_HOLD.count(), expected + )); + } 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/StoryData/plza-03.02b.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json index c4bfcb8467..e9dfb18bb4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.02b.plan.json @@ -9,19 +9,42 @@ }, "events": [ { - "id": "to_taunie_at_gate", + "id": "to_plaza_scene_prompt", "kind": "game_action", - "why": "step 41: on to Taunie at the gate until her \"A Talk Taunie\". Measured 2026-11-08 on console B as 3 s, walk not run; on 2026-11-16 those 3 s stopped short of her, under the Quartiere Verde arch with Taunie a few steps ahead and no prompt. 8 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", + "why": "step 41: on from the reload spot outside Hotel Z to the first A prompt, which starts a scene, not Taunie's talk: it was 3.25 s ahead on all three 03.02b runs (console B, 2026-11-16). The 2026-11-08 recording's 3 s leg from the live exit stopped short of Taunie at the Quartiere Verde arch. 8 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { - "legs": [[0, 8000]], + "legs": [ + [ + 0, + 8000 + ] + ], "end": "prompt" } }, + { + "id": "plaza_scene", + "kind": "game_action", + "why": "step 41: A at that prompt starts a scene: a black fade, the dimmed Smart Rotom card, a second black fade, then control at the Quartiere Verde arch with Taunie a few steps ahead inside it (console B, 2026-11-16, run 3: control 12 s after A)", + "action": "mash_to_move_hints", + "args": { + "press_a_first": true + } + }, + { + "id": "to_taunie", + "kind": "game_action", + "why": "step 42: straight on through the arch to Taunie's \"A Talk\" (run 3's frame: she stands a few steps ahead, facing the player), 8 s at most", + "action": "walk_to_prompt", + "args": { + "timeout_ms": 8000 + } + }, { "id": "talk_to_taunie", "kind": "talk", - "why": "step 42: A at Taunie" + "why": "step 42: A at Taunie's prompt" }, { "id": "taunie_battle_start", From 18e3073b1c1b956c39ad8b3e983d0e0980357390 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 01:52:30 -0800 Subject: [PATCH 17/24] PLZA AutoStory: scene machine's classify_open back under 50 lines --- .../Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index 0435c850e6..a01fe24651 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -402,8 +402,7 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (fades_settled(look.when)){ return SceneScreen::FADE_SETTLED; } - const bool control_held = m_control_since && look.when - *m_control_since >= CONTROL_INSTEAD_HOLD; - if (control_held && look.events.has(ScreenEvent::PLAYER_CAN_MOVE)){ + if (m_control_since && look.events.has(ScreenEvent::PLAYER_CAN_MOVE) && look.when - *m_control_since >= CONTROL_INSTEAD_HOLD){ return SceneScreen::ENDED_IN_CONTROL; } if (m_config.start_window && !m_scene_seen && hud_shows(look)){ From 73a04a5b7075edac8181a6950d702d99d3c33ee4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 02:00:50 -0800 Subject: [PATCH 18/24] PLZA AutoStory: a battle shows by the player's Pokemon panel, not only the move hints 03.02b run 4 on console B (2026-11-16): Taunie's battle ran 70 s with the player not locked on, so no move list or "A: Select Move" hint showed, and story_battle_start waited out its 90 s. - BattlePanelDetector: the panel at the bottom left, its sky blue level badge and its HP bar (fill or grey trough), measured on that frame (badge 0.78, bar 0.95; overworld frames 0.18 and 0.20 at most). - BATTLE_STARTED is the move hints or the panel, so story_battle_start ends on a battle whether or not the player is locked on; fight_story_battle already locks on with ZL (upstream's TrainerBattleState). - Frame tests: the run 4 frame reads as a battle, two prompt frames do not. CI (fork only) pins CommandLineTests 721bb64, which adds the frame (branch plza/battle-panel). --- .../workflows/cpp-ci-serial-programs-base.yml | 4 +- ...okemonLZA_AutoStoryBattlePanelDetector.cpp | 56 +++++++++++++++++ .../PokemonLZA_AutoStoryBattlePanelDetector.h | 47 ++++++++++++++ .../PokemonLZA_AutoStoryScreenEvents.cpp | 4 +- .../PokemonLZA_AutoStoryScreenEvents.h | 9 ++- ...PokemonLZA_AutoStoryScreenEvents_Tests.cpp | 61 +++++++++++++++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 7 files changed, 178 insertions(+), 5 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index b69b4e394f..92cec231e5 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.00 new game frames, HOME tiles (FireRed first, Z-A second too) and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames, HOME tiles (FireRed first, Z-A second too) and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro), and the 03.02b battle frame with no lock-on (branch plza/battle-panel). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: 'd0deaebe6fa2f623770b1233cc76cd056cc97ecc' + ref: '721bb647d58ef86ba992703575a56b14af8085f2' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp new file mode 100644 index 0000000000..e5020e54f8 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.cpp @@ -0,0 +1,56 @@ +/* PokemonLZA AutoStory - Battle panel detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryBattlePanelDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The shares of the badge's and the bar's pixels that make the panel. +constexpr double BADGE_SHARE = 0.5; +constexpr double BAR_SHARE = 0.8; + +// An HP bar pixel: its fill (red, yellow or green: channels 90 or more +// apart), or its grey trough (channels within 25, mean 60 to 140). +bool hp_bar_pixel(Color color){ + const int r = color.red(); + const int g = color.green(); + const int b = color.blue(); + const int spread = std::max({r, g, b}) - std::min({r, g, b}); + const int mean = (r + g + b) / 3; + return spread >= 90 || (spread <= 25 && mean >= 60 && mean <= 140); +} + +} // namespace + + +BattlePanelDetector::BattlePanelDetector(Color color) + : m_color(color) + , m_badge(240.0 / 1920, 799.0 / 1080, 80.0 / 1920, 19.0 / 1080) + , m_bar(236.0 / 1920, 882.0 / 1080, 204.0 / 1920, 20.0 / 1080) +{} + +void BattlePanelDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_badge); + items.add(m_color, m_bar); +} + +bool BattlePanelDetector::detect(const ImageViewRGB32& screen){ + return sky_blue_share(screen, m_badge) >= BADGE_SHARE && share_of(screen, m_bar, hp_bar_pixel) >= BAR_SHARE; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h new file mode 100644 index 0000000000..13fb048562 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h @@ -0,0 +1,47 @@ +/* PokemonLZA AutoStory - Battle panel detector + * + * From: https://github.com/PokemonAutomation/ + * + * The player's Pokemon's panel at the bottom left in a battle: its level + * badge ("L. 7") and HP bar. It shows the whole battle, locked on or not; + * the move list and its hints show only while the player is locked on. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryBattlePanelDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryBattlePanelDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The panel's level badge, sky blue (about 140, 210, 235) at x 240-320, +// y 799-818 on 1920x1080, over half its pixels; and its HP bar at x +// 236-440, y 882-902 (left of the "4/24"), over 80% its HP color or its +// grey trough (about 95, 95, 95). Taunie's battle not locked on (03.02b, +// console B 2026-11-16): badge 0.78, bar 0.95; overworld frames: badge +// 0.18 at most, bar 0.20 at most. +class BattlePanelDetector : public StaticScreenDetector{ +public: + explicit BattlePanelDetector(Color color = COLOR_GREEN); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + ImageFloatBox m_badge; + ImageFloatBox m_bar; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp index c7b494f91a..e937df20a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp @@ -34,6 +34,7 @@ PlzaScreenObserver::PlzaScreenObserver() , m_choice_arrow(COLOR_YELLOW, nullptr, SelectionArrowType::RIGHT, dialog_choice_box()) , m_interact(COLOR_RED, ButtonType::ButtonA, INTERACT_PROMPT_BOX) , m_battle_hint(COLOR_CYAN, ButtonType::ButtonA, BATTLE_HINT_BOX) + , m_battle_panel(COLOR_GREEN) , m_party(COLOR_WHITE) {} @@ -53,7 +54,7 @@ ScreenEvents PlzaScreenObserver::read(const ImageViewRGB32& screen){ out.set(ScreenEvent::DIALOG_BOX, box); out.set(ScreenEvent::CHOICE_BOX, m_choice_arrow.detect(screen)); out.set(ScreenEvent::INTERACT_PROMPT, !box && m_interact.detect(screen)); - out.set(ScreenEvent::BATTLE_STARTED, m_battle_hint.detect(screen)); + out.set(ScreenEvent::BATTLE_STARTED, m_battle_hint.detect(screen) || m_battle_panel.detect(screen)); out.set(ScreenEvent::PLAYER_CAN_MOVE, !box && m_party.detect(screen)); return out; } @@ -63,6 +64,7 @@ void PlzaScreenObserver::make_overlays(VideoOverlaySet& items) const{ m_choice_arrow.make_overlays(items); m_interact.make_overlays(items); m_battle_hint.make_overlays(items); + m_battle_panel.make_overlays(items); m_party.make_overlays(items); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h index 9f10dfbc2c..2ab436e3cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h @@ -15,6 +15,7 @@ #include "VideoGames/PokemonLZA/Inference/PokemonLZA_ButtonDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogDetector.h" namespace PokemonAutomation{ @@ -35,8 +36,11 @@ namespace PokemonLZA{ // (OverworldPartySelectionDetector), with no box. Hotel Z's lobby, // halls and rooms do not show it; // - BATTLE_STARTED: the battle HUD's hints at the bottom centre ("X A: -// Select Move"), read by their A icon. Story battles show no Run -// prompt, so RunFromBattleDetector misses them. +// Select Move"), read by their A icon, or the player's Pokemon's panel +// at the bottom left (BattlePanelDetector): the hints show only while +// the player is locked on, and Taunie's battle (03.02b) ran 70 s with +// none (console B, 2026-11-16). Story battles show no Run prompt, so +// RunFromBattleDetector misses them. // A fading screen has no box to read. class PlzaScreenObserver : public ScreenEventObserver{ public: @@ -54,6 +58,7 @@ class PlzaScreenObserver : public ScreenEventObserver{ SelectionArrowDetector m_choice_arrow; ButtonDetector m_interact; ButtonDetector m_battle_hint; + BattlePanelDetector m_battle_panel; OverworldPartySelectionDetector m_party; }; 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 f45b0f4b00..6598c58189 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp @@ -84,6 +84,50 @@ const FrameCase FRAME_CASES[] = { }, }; +struct BattleFrameCase{ + std::string name; + struct Input{ + std::string_view path; // In CommandLineTests/PokemonLZA/. + }; + Input input; + struct Expectation{ + bool battle = false; + }; + Expectation expectation; +}; + +const BattleFrameCase BATTLE_FRAME_CASES[] = { + { + // console B, 2026-11-16 (03.02b run 4): Taunie's Totodile + // attacking, the player not locked on, so no move list or its + // hints; only Chikorita's panel at the bottom left shows the + // battle. story_battle_start waited 90 s for it. + .name = "a battle with the player not locked on: the panel, no move hints", + .input = {.path = "AutoStoryScreenEvents/it_0302b_battle_no_lock_on.png"}, + .expectation = {.battle = true}, + }, + { + .name = "no battle at the A Talk prompt on the Italian game", + .input = {.path = "AutoStoryScreenEvents/it_0102_parla_talk_prompt.png"}, + .expectation = {.battle = false}, + }, + { + .name = "no battle at an A prompt while the player is held", + .input = {.path = "AutoStoryScreenEvents/za2_m3v_s1.png"}, + .expectation = {.battle = false}, + }, +}; + +UnitTestResult check_battle_frame(const BattleFrameCase& test){ + const std::string path = std::format("{}PokemonLZA/{}", UNIT_TEST_RESOURCE_PATH(), test.input.path); + PlzaScreenObserver observer; + const bool battle = observer.read(ImageRGB32(path)).has(ScreenEvent::BATTLE_STARTED); + if (battle != test.expectation.battle){ + return std::format("{}: expected battle {}, got {}", test.input.path, test.expectation.battle ? "yes" : "no", battle ? "yes" : "no"); + } + return true; +} + struct FolderCase{ std::string name; struct Input{ @@ -158,6 +202,20 @@ class Test_Frame : public UnitTest{ const FrameCase& m_test; }; +class Test_BattleFrame : public UnitTest{ +public: + explicit Test_BattleFrame(const BattleFrameCase& test) + : UnitTest(std::format("PokemonLZA::AutoStoryScreenEvents - battle frame: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_battle_frame(m_test); + } + +private: + const BattleFrameCase& m_test; +}; + class Test_Folder : public UnitTest{ public: explicit Test_Folder(const FolderCase& test) @@ -179,6 +237,9 @@ void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database){ for (const FrameCase& test : FRAME_CASES){ database.add(test); } + for (const BattleFrameCase& test : BATTLE_FRAME_CASES){ + database.add(test); + } for (const FolderCase& test : FOLDER_CASES){ database.add(test); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 0c157dd25e..c8843b49c0 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2344,6 +2344,8 @@ 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_AutoStoryBattlePanelDetector.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryBattlePanelDetector.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 From a7a72c3eee12c7b13d281b09f827f40ceadf0f1d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 02:49:37 -0800 Subject: [PATCH 19/24] PLZA AutoStory tests: chain and battle-start fixtures match the platform wait and the fade wait Four AutoStoryGame tests failed on CI since they were added; the code behaves as before, the scripted looks were short. - Chain cases (a9f619526): 01.01's platform wait does not count a look with the autosave badge (platform_look() since e37c765ae), so PLATFORM_SAVING, PLATFORM is one platform look, not two. Each script gets the second PLATFORM; "start check fails" gets two more for 01.02's check to read. - "a battle start that ends in control" (edcd305a0): the FADE_BLACK state's wait reads the first look after the fade without recording it, so the party bar's 5 s ran from 3000 ms and the frozen 6100 ms look never reached it. The script repeats the 1000 ms look. --- .../AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 fccc7aa07e..16b8ed79ae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -848,9 +848,11 @@ const RunCase RUN_CASES[] = { // console B, 2026-11-16 (run 3): the scene before Taunie handed // control back with no battle, and the battle start waited 90 s. .name = "a battle start that ends in control, the party bar held 5 s, fails at once", + // The fade's wait takes the first look after it: the party bar's + // 5 s run from the look after that. .input = {.checkpoint = "03.02b", .first_step = 4, .steps = 1, .looks = { look({ScreenEvent::FADE_BLACK}, /*readings=*/{}, Milliseconds(0)), - party_bar(Milliseconds(1000)), party_bar(Milliseconds(3000)), party_bar(Milliseconds(6100)), + party_bar(Milliseconds(1000)), party_bar(Milliseconds(1000)), party_bar(Milliseconds(3000)), party_bar(Milliseconds(6100)), }}, .expectation = {.verdict = "failed at taunie_battle_start: scene_ended_in_control"}, }, @@ -1080,7 +1082,8 @@ UnitTestResult check_load(const LoadCase& test, CancellableScope& scope){ // Two rows: "01.01" waits for the platform, "01.02" runs to a choice. -// 01.01's autosave shows when a look has both the platform and the badge. +// 01.01's autosave shows when a look has both the platform and the badge; +// its platform wait then needs two platform looks without the badge. struct ChainCase{ std::string name; struct Input{ @@ -1102,7 +1105,7 @@ const Observation PLATFORM_SAVING = look({}, {PLATFORM_READING, AUTOSA const ChainCase CHAIN_CASES[] = { { .name = "autosave seen and the start check does not fail: on without a reload", - .input = {.reload_always = {}, .looks = {PLATFORM_SAVING, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, + .input = {.reload_always = {}, .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, .expectation = {.verdict = "done", .reloads = 0}, }, { @@ -1113,7 +1116,7 @@ const ChainCase CHAIN_CASES[] = { { .name = "autosave seen and the start check fails: reloads the start", .input = {.reload_always = {}, .looks = { - PLATFORM_SAVING, PLATFORM, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0), + PLATFORM_SAVING, PLATFORM, PLATFORM, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0), }}, .expectation = {.verdict = "done", .reloads = 1}, }, @@ -1124,7 +1127,7 @@ const ChainCase CHAIN_CASES[] = { }, { .name = "reload always, autosave seen: reloads the start", - .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, + .input = {.reload_always = {"01.02"}, .looks = {PLATFORM_SAVING, PLATFORM, PLATFORM, CUTSCENE, CUTSCENE, CUTSCENE, CUTSCENE, choice(0)}}, .expectation = {.verdict = "done", .reloads = 1}, }, { From bb1e2757b7f808f69bc09a4d01db015660d49f84 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 03:21:22 -0800 Subject: [PATCH 20/24] PLZA AutoStory: 03.02b map talk pages the Map & Missions card with A only 03.02b run 5 on console B (2026-11-16): after_taunie_battle pressed A and B in turn for 120 s on the "Map & Missions" tutorial card over the map app. A turns the card's page, B turns it back, so it never left page 1. - talk_through_map_screen presses one button a look by what shows: A on a tutorial card (TUTORIAL_CARD_READING) and on text before the card, B on the rest: the map app, which B closes and where A places a pin, and her talk after it, as played by hand (step 45). The scene machine and the talk's lines already press A on a card. - Frame test: the run 5 frame reads as a tutorial card (its panel 240, the map's blue edges 69-75 with spread under 6); a battle frame and the A Talk prompt do not. - Sim tests: the card paged with A only, then B on the map and the talk. CI (fork only) pins CommandLineTests 0414d97, which adds the frame (branch plza/battle-panel). --- .../workflows/cpp-ci-serial-programs-base.yml | 4 +- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 26 ++++++-- .../Actions/PokemonLZA_AutoStoryScenes.h | 16 +++-- .../PokemonLZA_AutoStoryDetectors_Tests.cpp | 60 +++++++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryGame.h | 4 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 23 +++++-- 6 files changed, 115 insertions(+), 18 deletions(-) diff --git a/.github/workflows/cpp-ci-serial-programs-base.yml b/.github/workflows/cpp-ci-serial-programs-base.yml index 92cec231e5..e79d72c70a 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.00 new game frames, HOME tiles (FireRed first, Z-A second too) and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro), and the 03.02b battle frame with no lock-on (branch plza/battle-panel). Fork-only pin: dropped at upstream handoff. + # and the 01.00 new game frames, HOME tiles (FireRed first, Z-A second too) and the 01.02 Italian choice menu and talk prompt (branch plza/new-game-intro), and the 03.02b battle frame with no lock-on and Map & Missions card (branch plza/battle-panel). Fork-only pin: dropped at upstream handoff. repository: 'dayfine/CommandLineTests' - ref: '721bb647d58ef86ba992703575a56b14af8085f2' + ref: '0414d97e16f77d6405d7f456147007ae317b1e72' path: 'CommandLineTests' # The unit tests assume the downloadable resources they need are already downloaded diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp index 47c11443c9..c2d1d9cb1e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -6,6 +6,8 @@ #include #include +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -32,15 +34,29 @@ bool shows_control(const ScreenObservation& look){ return look.events.has(ScreenEvent::PLAYER_CAN_MOVE) && !look.events.has(ScreenEvent::DIALOG_BOX); } +// The button for what shows: A on a tutorial card, whose pages B turns +// back, and on text until the card has shown; B on the rest: the map +// app, where A places a pin, and her talk after it (as played by hand, +// 03.02b step 45). +enum class MapTalkPart{BEFORE_CARD, AFTER_CARD}; +Button map_talk_button(const ScreenObservation& look, MapTalkPart part){ + if (look.readings.contains(TUTORIAL_CARD_READING)){ + return BUTTON_A; + } + const bool text = look.events.has(ScreenEvent::DIALOG_BOX) || look.readings.contains(ADVANCE_ARROW_READING); + return text && part == MapTalkPart::BEFORE_CARD ? BUTTON_A : BUTTON_B; +} + } // namespace Pokemon::Outcome talk_through_map_screen(PlzaBackend& backend){ - // Each look presses for 2 s or waits; the looks bound a script whose + // Each look presses for 1 s or waits; the looks bound a script whose // time stands still. const size_t max_looks = (size_t)(MAP_TALK_TIMEOUT / MAP_TALK_POLL) + 1; std::optional start; std::optional control_since; + MapTalkPart part = MapTalkPart::BEFORE_CARD; for (size_t looks = 0; looks < max_looks; looks++){ backend.scope().throw_if_cancelled(); const Pokemon::Observation look = backend.observe(); @@ -58,11 +74,13 @@ Pokemon::Outcome talk_through_map_screen(PlzaBackend& backend){ if (look.when - *start >= MAP_TALK_TIMEOUT){ break; } - backend.press(BUTTON_A, MAP_TALK_HOLD, MAP_TALK_RELEASE); - backend.press(BUTTON_B, MAP_TALK_HOLD, MAP_TALK_RELEASE); + backend.press(map_talk_button(look, part), MAP_TALK_HOLD, MAP_TALK_RELEASE); + if (look.readings.contains(TUTORIAL_CARD_READING)){ + part = MapTalkPart::AFTER_CARD; + } } return Pokemon::outcome_failed("map_talk_timeout", std::format( - "no party bar held {} ms within {} ms of A and B in turn", + "no party bar held {} ms within {} ms of A on the talk and the card, B on the map", MAP_TALK_CONTROL_HOLD.count(), MAP_TALK_TIMEOUT.count() )); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h index a9abb1828d..d61f6521b5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -20,12 +20,16 @@ namespace PokemonLZA{ // Taunie's talk after her battle (03.02b), the "Map & Missions" card, the -// first map and the rest of her talk: A then B, a second each, until the -// party bar shows with no text box on looks a second apart. A pages the -// talk and the card; B closes the map, where A would place a pin. The map -// is not looked for: MapDetector needs the Travel Spots icon, which the -// first map lacks (console B, 2026-11-13). No presses once the party bar -// shows. Fails as "map_talk_timeout" after 120 s (by the looks' time). +// first map and the rest of her talk, one press a second by what shows, +// until the party bar shows with no text box on looks a second apart: a +// tutorial card (TUTORIAL_CARD_READING) and text (a box or the advance +// chevron) before the card get A, anything else B. A pages the card and +// closes it on its last page, where B would turn back (console B +// 2026-11-16: A and B in turn held it on page 1 for 120 s); B closes the +// map, where A would place a pin. The map is not looked for: MapDetector +// needs the Travel Spots icon, which the first map lacks (console B, +// 2026-11-13). No presses once the party bar shows. Fails as +// "map_talk_timeout" after 120 s (by the looks' time). Pokemon::Outcome talk_through_map_screen(PlzaBackend& backend); // Facing the side street's wall (03.03): sidestep right to the ladder 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 c761cb6921..4296c0c239 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 @@ -28,6 +28,7 @@ #include "PokemonLZA_AutoStoryMainMissionBannerDetector.h" #include "PokemonLZA_AutoStoryMissionCompleteDetector.h" #include "PokemonLZA_AutoStoryPlatformArrivalDetector.h" +#include "PokemonLZA_AutoStoryTutorialCardDetector.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -603,6 +604,48 @@ UnitTestResult check_frame_folder(const FrameFolderCase& test, Logger& logger){ } +struct TutorialCardFrameCase{ + std::string name; + struct Input{ + std::string_view path; // In CommandLineTests/PokemonLZA/. + }; + Input input; + struct Expectation{ + bool card = false; + }; + Expectation expectation; +}; + +const TutorialCardFrameCase TUTORIAL_CARD_FRAME_CASES[] = { + { + // console B, 2026-11-16 (03.02b run 5): the "Map & Missions" card, + // page 1 of 2, over the map app's blue screen, not a dark one. + .name = "the Map & Missions card over the map app (Italian)", + .input = {.path = "AutoStoryScreenEvents/it_0302b_map_missions_card.png"}, + .expectation = {.card = true}, + }, + { + .name = "no card in a battle", + .input = {.path = "AutoStoryScreenEvents/it_0302b_battle_no_lock_on.png"}, + .expectation = {.card = false}, + }, + { + .name = "no card at the A Talk prompt", + .input = {.path = "AutoStoryScreenEvents/it_0102_parla_talk_prompt.png"}, + .expectation = {.card = false}, + }, +}; + +UnitTestResult check_tutorial_card_frame(const TutorialCardFrameCase& test){ + const std::string path = std::format("{}PokemonLZA/{}", UNIT_TEST_RESOURCE_PATH(), test.input.path); + const bool card = tutorial_card_shows(ImageRGB32(path)); + if (card != test.expectation.card){ + return std::format("{}: expected card {}, got {}", test.input.path, test.expectation.card ? "yes" : "no", card ? "yes" : "no"); + } + return true; +} + + class Test_SyntheticFrame : public UnitTest{ public: explicit Test_SyntheticFrame(const SyntheticFrameCase& test) @@ -617,6 +660,20 @@ class Test_SyntheticFrame : public UnitTest{ const SyntheticFrameCase& m_test; }; +class Test_TutorialCardFrame : public UnitTest{ +public: + explicit Test_TutorialCardFrame(const TutorialCardFrameCase& test) + : UnitTest(std::format("PokemonLZA::AutoStoryDetectors - tutorial card frame: {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + return check_tutorial_card_frame(m_test); + } + +private: + const TutorialCardFrameCase& m_test; +}; + class Test_FrameFolder : public UnitTest{ public: explicit Test_FrameFolder(const FrameFolderCase& test) @@ -641,6 +698,9 @@ void add_tests_AutoStoryDetectors(UnitTestDatabase& database){ for (const FrameFolderCase& test : FRAME_FOLDER_CASES){ database.add(test); } + for (const TutorialCardFrameCase& test : TUTORIAL_CARD_FRAME_CASES){ + database.add(test); + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 89a56f34d1..36f7b16d5d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -80,8 +80,8 @@ namespace PokemonLZA{ // the battle HUD within 10 s, else // "battle_never_started"; right after // "story_battle_start" (the lint) -// "talk_through_map_screen" A and B in turn through Taunie's talk -// and the first map (03.02b) +// "talk_through_map_screen" A on Taunie's talk and the Map & +// Missions card, B on the first map (03.02b) // "climb_ladder" the side street's ladder (03.03) // "talk_to_pokedex_screen" B through the nurse's talk and the // Pokedex app (03.04) 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 16b8ed79ae..d5815329f2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -868,13 +868,13 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .line = "[PLZA story_battle_start] done on battle."}, }, { - .name = "03.02b's map talk: A and B in turn, done on the party bar held a second", + .name = "03.02b's map talk: A on the text, B on the map, done on the party bar held a second", .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { DIALOG, look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, .expectation = { .verdict = "done", - .inputs = "press A, press B, press A, press B, wait 250ms", + .inputs = "press A, press B, wait 250ms", .line = "[PLZA] talk_through_map_screen: the party bar held: back in the overworld", }, }, @@ -885,14 +885,29 @@ const RunCase RUN_CASES[] = { look({ScreenEvent::PLAYER_CAN_MOVE, ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(2000)), party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), }}, - .expectation = {.verdict = "done", .inputs = "press A, press B, press A, press B, wait 250ms"}, + .expectation = {.verdict = "done", .inputs = "press A, press A, wait 250ms"}, + }, + { + // console B, 2026-11-16 (03.02b run 5): the "Map & Missions" card + // (2 pages) over the map app. A turns its pages and closes it on + // the last; B turns back, so A and B in turn held it on page 1 + // for 120 s. Then B closes the map and goes through her talk. + .name = "03.02b's map talk pages the Map & Missions card with A only, then B on the map and her talk", + .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(0)), + look(/*events=*/{}, {TUTORIAL_CARD_READING}, Milliseconds(1000)), + look(/*events=*/{}, /*readings=*/{}, Milliseconds(2000)), + look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(3000)), + party_bar(Milliseconds(4000)), party_bar(Milliseconds(5100)), + }}, + .expectation = {.verdict = "done", .inputs = "press A, press A, press B, press B, wait 250ms"}, }, { .name = "03.02b's map talk fails with no party bar in 120 s", .input = {.checkpoint = "03.02b", .first_step = 8, .steps = 1, .looks = { look(/*events=*/{}, /*readings=*/{}, Milliseconds(0)), look(/*events=*/{}, /*readings=*/{}, Milliseconds(121000)), }}, - .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press A, press B"}, + .expectation = {.verdict = "failed at after_taunie_battle: map_talk_timeout", .inputs = "press B"}, }, { .name = "03.03 climbs the ladder: sidestep right, face it, A, then up to the top", From 615a767bdfea41bb80875080b4648205d1ed7db8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 03:57:53 -0800 Subject: [PATCH 21/24] PLZA AutoStory: a scene step must follow what starts it 03.04's after_pokedex waited 45 s on the party bar (scene_never_started, console B 2026-11-16): talk_to_pokedex_screen had already played the nurse's wrap-up and Taunie's scene to control, through two black fades and the autosave. A lint rule now rejects a scene (MASH) step right after a step that presses through its scenes to control; 03.04's after_pokedex and 03.09's five_registered fold into the step before them. --- .../PokemonLZA_AutoStoryGame_Tests.cpp | 34 +++++++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 14 ++++++++ .../AutoStory/PokemonLZA_AutoStoryTable.h | 8 ++++- .../AutoStory/StoryData/plza-03.04.plan.json | 8 +---- .../AutoStory/StoryData/plza-03.09.plan.json | 8 +---- 5 files changed, 57 insertions(+), 15 deletions(-) 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 d5815329f2..0a47e94755 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -188,6 +188,40 @@ const LintCase LINT_CASES[] = { }, .expectation = {.errors = "01.01 b: a story battle must follow story_battle_start, which ends on the battle HUD"}, }, + { + .name = "a scene after a talk passes", + .input = { + .before = { + {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}, + {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + }, + .step = {.kind = Pokemon::StoryStepKind::MASH, .name = "s", .why = "", .action = "a", .args = {}}, + }, + .expectation = {.errors = ""}, + }, + { + // console B, 2026-11-16: 03.04's talk_to_pokedex_screen played the + // nurse's wrap-up and Taunie's scene to control, and the scene step + // after it waited 45 s on the party bar for a scene already played. + .name = "a scene after talk_to_pokedex_screen fails", + .input = { + .before = {{.kind = Pokemon::StoryStepKind::GAME, .name = "p", .why = "", .action = "talk_to_pokedex_screen", .args = {}}}, + .step = {.kind = Pokemon::StoryStepKind::MASH, .name = "s", .why = "", .action = "a", .args = {}}, + }, + .expectation = {.errors = "01.01 s: a scene must follow what starts it, not talk_to_pokedex_screen, which plays its scenes through to control"}, + }, + { + .name = "a scene after a scene fails", + .input = { + .before = { + {.kind = Pokemon::StoryStepKind::GAME, .name = "w", .why = "", .action = "walk_to_prompt", .args = {}}, + {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}, + {.kind = Pokemon::StoryStepKind::MASH, .name = "s1", .why = "", .action = "a", .args = {}}, + }, + .step = {.kind = Pokemon::StoryStepKind::MASH, .name = "s2", .why = "", .action = "a", .args = {}}, + }, + .expectation = {.errors = "01.01 s2: a scene must follow what starts it, not a, which plays its scenes through to control"}, + }, { .name = "a checkpoint's first step cannot be a talk", .input = {.step = {.kind = Pokemon::StoryStepKind::TALK, .name = "t", .why = "", .action = "", .args = {}}}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index 798a41c156..f8ac14d8b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -38,6 +38,15 @@ bool ends_on_prompt(const Pokemon::StoryStep& step){ return word != nullptr && *word == "prompt"; } +// Whether `step` presses through its scenes until control: a scene that +// needs nothing from the player to start plays inside it. +bool plays_to_control(const Pokemon::StoryStep& step){ + return step.kind == Pokemon::StoryStepKind::MASH + || step.action == "mash_to_move_hints" + || step.action == "talk_to_pokedex_screen" + || step.action == "talk_through_map_screen"; +} + } // namespace std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint& row){ @@ -53,6 +62,11 @@ std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint if (step.action == "story_battle" && (before == nullptr || before->action != "story_battle_start")){ errors.push_back(std::format("{}: a story battle must follow story_battle_start, which ends on the battle HUD", step.name)); } + if (step.kind == Pokemon::StoryStepKind::MASH && before != nullptr && plays_to_control(*before)){ + errors.push_back(std::format( + "{}: a scene must follow what starts it, not {}, which plays its scenes through to control", step.name, before->action + )); + } } return errors; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index d7dd20d231..8a40f4ba64 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -44,7 +44,13 @@ bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); // the talk is for (03.02); // - a "story_battle" after "story_battle_start", which presses through // the talk and cards to the battle HUD: the battle code run on the -// overworld looks for a battle for 2 min (03.02b). +// overworld looks for a battle for 2 min (03.02b); +// - a scene ("a", MASH) after what starts it (a walk, a talk, a choice, +// a battle), not after a step that presses through its scenes until +// control (a scene, "mash_to_move_hints", "talk_to_pokedex_screen", +// "talk_through_map_screen"): a scene that follows with nothing to +// start it plays inside that step, and the scene step then waits 45 s +// on the party bar for it (03.04's after_pokedex). std::vector story_row_lead_in_errors(const Pokemon::StoryCheckpoint& row); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json index 40580b0003..e4b17c9622 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json @@ -26,14 +26,8 @@ { "id": "pokedex_app", "kind": "game_action", - "why": "step 54: the Pokedex app (\"Ready!\"), Chikorita's entry, B on its screen", + "why": "steps 54-55: the Pokedex app (\"Ready!\"), Chikorita's entry, B on its screen, then the nurse's wrap-up and Taunie's scene outside, until control outside the Center. Nothing starts step 55's scene, so it plays inside this step: console B 2026-11-16 saw its text, two black fades and the autosave badge, then the party bar outside the Center, and a scene step after it waited 45 s on the party bar.", "action": "talk_to_pokedex_screen" - }, - { - "id": "after_pokedex", - "kind": "scene", - "why": "step 55: the nurse's wrap-up, Taunie outside", - "action": "a" } ], "metadata": { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json index e09f1abeb7..5b6982b35c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.09.plan.json @@ -17,13 +17,7 @@ { "id": "research_lab_gate", "kind": "scene", - "why": "step 63: Taunie at the lab gate; with five species registered she goes on", - "action": "a" - }, - { - "id": "five_registered", - "kind": "scene", - "why": "step 65: Taunie's scene at the lab gate after 5/5", + "why": "steps 63-65: Taunie at the lab gate; with five species registered she goes on to her scene after 5/5, until control. One scene step: nothing starts the 5/5 part, so a scene step for it would wait 45 s on the party bar, as 03.04's after_pokedex did (console B 2026-11-16). UNVERIFIED, NEEDS CONSOLE: no control between the two parts was checked.", "action": "a" }, { From 1cc23916c22205f90dcbf999e2646aa8b37aaa91 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 04:00:14 -0800 Subject: [PATCH 22/24] PLZA AutoStory: 03.04 ends on its autosave outside the Center Console B 2026-11-16 saw 03.04 end outside the Pokemon Center, in control, after the game's autosave. 03.04 is marked autosave; 03.05 starts by the Center's door, and its walk back to the nurse and 03.06's walk out are marked UNVERIFIED: their legs were measured inside the Center, and Lumiose has no tile grid to plan a route target on. --- .../Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp | 2 +- .../Programs/AutoStory/StoryData/plza-03.04.plan.json | 5 +++-- .../Programs/AutoStory/StoryData/plza-03.05.plan.json | 6 +++--- .../Programs/AutoStory/StoryData/plza-03.06.plan.json | 2 +- 4 files changed, 8 insertions(+), 7 deletions(-) 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 0a47e94755..a773107dea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -70,7 +70,7 @@ const StoryDataCase STORY_DATA_CASES[] = { "01.00:new_game:autosave 01.01:from_save:unverified 01.02:from_save:unverified 01.03:from_save:unverified " "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:unverified 03.02:from_save:autosave 03.02b:from_save 03.03:from_save:autosave 03.04:from_save " + "03.01:from_save:unverified 03.02:from_save:autosave 03.02b:from_save 03.03:from_save:autosave 03.04:from_save:autosave " "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" diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json index e4b17c9622..f6465a01dd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.04.plan.json @@ -32,10 +32,11 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: no autosave at its end was seen in a run log (2026-11-15 save review); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends outside the Pokemon Center, in control, on the game's autosave: console B 2026-11-16 logged the autosave badge after Taunie's scene's last black fade, then the party bar outside the Center." } }, "execution": { - "reload_when_chained": "always" + "reload_when_chained": "always", + "save": "autosave" } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json index c4f83148fa..b70f662047 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.05.plan.json @@ -6,13 +6,13 @@ "title": "Heal at the Pokemon Center", "start": { "place": "LumioseCity", - "spot": "PokemonCenter" + "spot": "PokemonCenterDoor" }, "events": [ { "id": "back_to_nurse", "kind": "game_action", - "why": "back to the nurse after 03.04's scene: turn right and walk into the counter, which faces her (user, console B, 2026-11-13); the counter stops the walk, so 2 s is safe; on until the prompt, 3 s at most. not planned: Lumiose has no tile grid to plan on; the walk ends on the A prompt it goes to.", + "why": "UNVERIFIED, NEEDS CONSOLE: from 03.04's end outside the Pokemon Center (console B 2026-11-16) back in to the nurse. These legs are from inside the Center (turn right, walk into the counter that faces her; user, console B, 2026-11-13) and do not reach her from outside; the walk in from the door is not measured. not planned: Lumiose has no tile grid to plan a route target on; the walk ends on the A prompt it goes to.", "action": "walk", "args": { "legs": [[90, 3000]], @@ -33,7 +33,7 @@ ], "metadata": { "phase": "testing", - "source": "added 2026-11-13 so Main Mission 03 has a backup save to retry from; no console recording of its steps: every step is unverified and needs console. Autosave: the heal's save was seen in a run log (2026-11-15 save review)." + "source": "added 2026-11-13 so Main Mission 03 has a backup save to retry from; no console recording of its steps: every step is unverified and needs console. It is not in the 2026-11-08 recording (03.04 is steps 53-55, 03.06 starts at step 56), and 03.04 now ends on the game's autosave outside the Center (console B 2026-11-16), which may already give Main Mission 03 the save to retry from: whether the heal is still needed is the user's call. Autosave: the heal's save was seen in a run log (2026-11-15 save review)." } }, "execution": { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json index 28234db3c9..7188bb9cb5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json @@ -12,7 +12,7 @@ { "id": "out_of_pokemon_center", "kind": "game_action", - "why": "UNVERIFIED, NEEDS CONSOLE: from the nurse's counter after 03.05's heal back to where 03.04's scene left the player, facing as it did, so the legs below (measured from there) still hold. Reverses 03.05's back_to_nurse (right, then into the counter): turn around, walk back 1.5 s (that walk is under 2 s; the time back is a guess), then right to face as the scene left the player.", + "why": "UNVERIFIED, NEEDS CONSOLE: from the nurse's counter after 03.05's heal, out of the Center to where 03.04's scene left the player (outside, by the door; console B 2026-11-16), facing as it did, so the legs below (step 56, recorded right after 03.04's scene) still hold. These legs only reverse an in-Center walk to the counter and do not leave the Center; the way out is not measured. not planned: Lumiose has no tile grid to plan a route target on.", "action": "walk", "args": { "legs": [[180, 1500], [90, 0]] From 223fc84ff290063046cd80d9ee691b5525419323 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 06:57:03 -0800 Subject: [PATCH 23/24] PLZA AutoStory: B through a scene's text box, so a closing box cannot talk again 03.05's heal_party pressed A on the nurse's closing box; the A landed on her A prompt and started her talk again ("your Pokemon is already in great shape") until the 120 s timeout (console B 2026-11-16). In every scene machine that ends in control, a text box now gets B (it turns a line like A, and does nothing once the box closes) and a choice gets A (its top row). Machines that stop at a choice or a battle keep their text button. A closed-loop test models the nurse: A at the closing box or the prompt talks again, B does not. --- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 7 +- .../AutoStory/PokemonLZA_AutoStoryGame.h | 6 +- .../PokemonLZA_AutoStoryGame_Tests.cpp | 18 +- .../PokemonLZA_AutoStorySceneMachine.cpp | 36 ++- .../PokemonLZA_AutoStorySceneMachine.h | 17 +- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 210 ++++++++++++++++-- 6 files changed, 240 insertions(+), 54 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 03102c1329..188596b30e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -473,8 +473,8 @@ 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 +// "mash_to_move_hints": through the scenes (B at a text box, A at a +// choice's top row and the advance chevron) until the player has control: the // 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 @@ -526,7 +526,8 @@ Outcome text_to_choice_step(Pokemon::StoryBackend& backend, const Stor } -// A step's scene ("scene" "a"): A through its text until the party bar +// A step's scene ("scene" "a"): B through its text (A at a choice; B +// cannot talk again once the text ends) until the party bar // 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 36f7b16d5d..a920f00bee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -54,7 +54,8 @@ namespace PokemonLZA{ // (check_can_walk()), until its end event if it // has one (walk_until()), else until its legs // have run (finish_walk()) -// "mash_to_move_hints" A through scenes until the player has control +// "mash_to_move_hints" B through scenes' text (A at a choice) until +// the player has control // (run_scene_machine()): 01.01's arrival; args // "min_length_ms", no quiet failure before it, // "quiet_ms", "quiet_is_control" and @@ -71,7 +72,8 @@ namespace PokemonLZA{ // A, then its scene under way // (scene_under_way(): text, a subtitle, a // card, a fade or a textless cutscene) -// "a" (MASH, "scene") A through a scene until control; it must +// "a" (MASH, "scene") B through a scene's text (A at a choice) +// until control; it must // start within 45 s // "story_battle_start" A through the talk before a story battle and // the battle tutorial's cards until the battle 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 a773107dea..e911991b27 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -475,7 +475,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, press A, wait 250ms, wait 250ms, wait 500ms, wait 500ms, wait 250ms, wait 500ms", + .inputs = "press B, wait 250ms, wait 250ms, press B, wait 250ms, wait 250ms, wait 500ms, wait 500ms, wait 250ms, wait 500ms", .line = "[PLZA mash_to_move_hints] done on fade_settled.", }, }, @@ -496,7 +496,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, wait 500ms, wait 250ms, press A, wait 500ms", + .inputs = "press B, wait 250ms, wait 250ms, wait 500ms, wait 250ms, press B, wait 500ms", .line = "[PLZA mash_to_move_hints] the mission banner did not show (the detector may have missed it).", }, }, @@ -515,7 +515,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms, wait 250ms, wait 250ms", + .inputs = "press B, wait 250ms, wait 250ms, wait 250ms, wait 250ms", .line = "[PLZA mash_to_move_hints] done on controls_hint.", }, }, @@ -529,7 +529,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 250ms, wait 250ms", + .inputs = "press B, wait 250ms, wait 250ms", .line = "[PLZA mash_to_move_hints] done on controls_hint.", }, }, @@ -675,7 +675,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, press A, wait 250ms", + .inputs = "press B, press A, wait 250ms", .line = "[Save] 01.03: not saved (save unverified)", }, }, @@ -688,11 +688,11 @@ const RunCase RUN_CASES[] = { }, }, { - .name = "02.01's scene after Brigitte: A at the text, done on the party bar held a second, not saved", + .name = "02.01's scene after Brigitte: B at the text, done on the party bar held a second, not saved", .input = {.checkpoint = "02.01", .first_step = 3, .looks = { look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(0)), party_bar(Milliseconds(500)), party_bar(Milliseconds(1600)), }}, - .expectation = {.verdict = "done", .inputs = "press A, wait 250ms", .line = "[Save] 02.01: not saved (save unverified)"}, + .expectation = {.verdict = "done", .inputs = "press B, wait 250ms", .line = "[Save] 02.01: not saved (save unverified)"}, }, { // console B, 2026-11-13: 02.02 after the Brigitte battle walked @@ -721,7 +721,7 @@ const RunCase RUN_CASES[] = { A_PROMPT, BLACK_FADE, look({ScreenEvent::DIALOG_BOX}, /*readings=*/{}, Milliseconds(1000)), party_bar(Milliseconds(1500)), party_bar(Milliseconds(2600)), }}, - .expectation = {.verdict = "done", .inputs = "press A, wait 250ms, press A, wait 250ms"}, + .expectation = {.verdict = "done", .inputs = "press A, wait 250ms, press B, wait 250ms"}, }, { .name = "02.04's walk to the clerk: along the counter, then the turn to her A prompt", @@ -762,7 +762,7 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .inputs = "press A, wait 500ms", + .inputs = "press B, wait 500ms", .line = "[PLZA mash_to_move_hints] done: quiet, taken as control.", }, }, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index a01fe24651..8d7c9ae8fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -35,7 +35,7 @@ enum class SceneScreen{ FADE_BLACK, // wait until it lifts FADE_WHITE, // wait until it lifts 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 + DIALOG, // a box or the advance chevron: dialog_button() 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 @@ -210,6 +210,22 @@ bool control_prompt_shows(const SceneMachineConfig& config, const ScreenObservat return party_bar_is_control(config) && look.events.has(ScreenEvent::INTERACT_PROMPT); } +// The button DIALOG presses on `look`: A on a choice (its top row); B on a +// text box in a machine that ends in control; else config.text_button. B +// turns a line like A, but on a box that is closing it does nothing, where +// A lands on the A prompt the talk leaves and starts it again: 03.05's +// nurse ("your Pokemon is already in great shape", 110 s of it, console B +// 2026-11-16). +Button dialog_button(const SceneMachineConfig& config, const ScreenObservation& look){ + if (look.events.has(ScreenEvent::CHOICE_BOX)){ + return BUTTON_A; + } + if (party_bar_is_control(config) && look.events.has(ScreenEvent::DIALOG_BOX)){ + return BUTTON_B; + } + return config.text_button; +} + constexpr SceneScreen ALL_SCREENS[] = { SceneScreen::BATTLE, SceneScreen::FADE_BLACK, SceneScreen::FADE_WHITE, SceneScreen::CHOICE, SceneScreen::DIALOG, @@ -276,7 +292,7 @@ bool scene_screen_terminal(SceneScreen screen){ screen == SceneScreen::NEVER_STARTED || screen == SceneScreen::QUIET_END || screen == SceneScreen::ENDED_IN_CONTROL; } -// Whether this state's step presses (DIALOG the config's text button, +// Whether this state's step presses (DIALOG dialog_button(), // BLIND_PRESS its blind button, MISSION_COMPLETE, TUTORIAL_CARD and // BANNER_PRESS A); the others wait. bool scene_screen_presses(SceneScreen screen){ @@ -645,8 +661,7 @@ class SceneRunner{ public: SceneRunner(PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, WallClock start) : m_backend(backend) - , m_text_button(config.text_button) - , m_blind_button(config.blind_button) + , m_config(config) , m_timeline(config, start) , m_log(backend, label, start) {} @@ -672,20 +687,20 @@ class SceneRunner{ return; } if (scene_screen_presses(screen)){ - m_backend.press(button_of(screen), /*hold=*/160ms, /*release=*/240ms); + m_backend.press(button_of(screen, look), /*hold=*/160ms, /*release=*/240ms); return; } wait(screen); } private: - // The button `screen`'s step presses. - Button button_of(SceneScreen screen) const{ + // The button `screen`'s step presses on `look`. + Button button_of(SceneScreen screen, const ScreenObservation& look) const{ switch (screen){ case SceneScreen::DIALOG: - return m_text_button; + return dialog_button(m_config, look); case SceneScreen::BLIND_PRESS: - return m_blind_button; + return m_config.blind_button; default: return BUTTON_A; } @@ -731,8 +746,7 @@ class SceneRunner{ } PlzaBackend& m_backend; - Button m_text_button; - Button m_blind_button; + SceneMachineConfig m_config; SceneTimeline m_timeline; SceneLog m_log; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index 58b67e5d62..a672da0bff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -6,10 +6,13 @@ * states (CommonTools/ScreenMachine) that match on what the backend * observed, so they run on the console and on a scripted backend alike: * every look picks one state, the state takes one step, and each change of - * state or of the look's events is logged (repeats are summed up). A text box (with or without a - * 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 + * state or of the look's events is logged (repeats are summed up). A + * choice gets A (its top row); a text box gets B in a machine that ends + * in control (B turns a line like A, but cannot talk again once the box + * closes: A at the closing box restarted 03.05's nurse's talk), else the + * text button, as does the advance chevron (ADVANCE_ARROW_READING). 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 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, @@ -68,8 +71,10 @@ struct SceneMachineConfig{ bool stop_at_choice = false; // Ends at the battle HUD (BATTLE_STARTED), before anything else. bool stop_at_battle = false; - // The button that advances text: B where an A could land on a choice - // that shows the moment the text ends. + // The button that advances text in a machine that stops at a choice + // or a battle, and the advance chevron with no box: B where an A could + // land on a choice that shows the moment the text ends. A text box in + // any other machine gets B, a choice A. Button text_button = BUTTON_A; // The quiet end is control, not a failure: Hotel Z's lobby, halls and // rooms show no party bar or prompt (02.04-02.06, console B 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 8f42fa569c..1e329cf85d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -270,7 +270,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "failed: scene_quiet", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 4: quiet_end at 60.0s: still", .states = "scene_moving, dialog, scene_still, quiet_end", }, @@ -286,7 +287,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "failed: scene_quiet", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 5: quiet_end at 23.0s: still", .states = "dialog, scene_still, fade_white, scene_still, quiet_end", }, @@ -317,7 +319,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 4: controls_hint at 9.0s: still, controls hint", .states = "hint_showing, dialog, hint_showing, controls_hint", }, @@ -374,7 +377,8 @@ const RunCase RUN_CASES[] = { }}, .expectation = { .verdict = "done", - .a_presses = 2, + .a_presses = 0, + .b_presses = 2, .line = "[PLZA test] screen 6: mission_banner at 12.0s: still, mission banner", .states = "dialog, scene_moving, banner_showing, dialog, banner_showing, mission_banner", }, @@ -408,7 +412,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 and at the choice, none in the flyover, done on the controls hint", + .name = "01.01's arrival: B at the text, none in the flyover, done on the controls hint", .input = {.looks = { look_at(0ms, DIALOG), look_at(1000ms), @@ -419,7 +423,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 = 2, .line = "[PLZA test] done on controls_hint."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 2, .line = "[PLZA test] done on controls_hint."}, }, { .name = "the mission banner ends the scene, which then waits for it to go", @@ -430,7 +434,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/1000ms, NOTHING, {MISSION_BANNER_READING}), look_at(1250ms), }}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] the mission banner has gone after 250 ms."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] the mission banner has gone after 250 ms."}, }, { // Two looks end the scene, 40 more are the 10 s wait. @@ -447,7 +451,7 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .a_presses = 3, .line = "[PLZA test] the mission banner still shows after 3 A presses; going on."}, }, { - .name = "01.03's end: A at the text and the mission complete card, done on the next banner", + .name = "01.03's end: B at the text, A at the mission complete card, done on the next banner", .input = {.looks = { look_at(0ms, DIALOG), look_at(/*at=*/500ms, NOTHING, {MISSION_COMPLETE_READING}), @@ -457,7 +461,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/2250ms, NOTHING, {MISSION_BANNER_READING}), look_at(2500ms), }}, - .expectation = {.verdict = "done", .a_presses = 3, .line = "[PLZA test] done on mission_banner."}, + .expectation = {.verdict = "done", .a_presses = 2, .b_presses = 1, .line = "[PLZA test] done on mission_banner."}, }, { .name = "a mission complete card that A does not get past fails as scene_stuck", @@ -482,7 +486,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/17250ms, NOTHING, {MISSION_BANNER_READING}), look_at(17500ms), }}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] screen 1: fade_white at 0.0s: white fade"}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] screen 1: fade_white at 0.0s: white fade"}, }, { .name = "a machine that stops at choices ends on the choice box, after the text before it", @@ -549,7 +553,8 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] screen 4: can_move at 1.9s: party bar", .states = "party_bar, dialog, party_bar, can_move", }, @@ -594,16 +599,17 @@ const RunCase RUN_CASES[] = { }, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .states = "scene_moving, dialog, scene_still, party_bar, can_move", }, }, { - .name = "after Brigitte: A at the text, done on the party bar held a second", + .name = "after Brigitte: B at the text, done on the party bar held a second", .input = {.looks = { look_at(0ms, DIALOG), look_at(500ms, DIALOG), look_at(1000ms, PARTY), look_at(1500ms, PARTY), look_at(2100ms, PARTY), }}, - .expectation = {.verdict = "done", .a_presses = 2, .line = "[PLZA test] done on can_move."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 2, .line = "[PLZA test] done on can_move."}, }, { // console B, 2026-11-15: blind A at the prompt restarted Ryon's @@ -612,7 +618,8 @@ const RunCase RUN_CASES[] = { .input = {.looks = battle_area_talk_prompt(), .config = battle_area_config()}, .expectation = { .verdict = "done", - .a_presses = 1, + .a_presses = 0, + .b_presses = 1, .line = "[PLZA test] done on talk_prompt.", .states = "dialog, scene_moving, prompt_showing, talk_prompt", }, @@ -626,7 +633,7 @@ const RunCase RUN_CASES[] = { { .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()}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] done: quiet, taken as control."}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] done: quiet, taken as control."}, }, { // console B, 2026-11-15: 02.02's street scene moved 41 s with no @@ -660,14 +667,14 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "failed: scene_quiet", .a_presses = 0}, }, { - .name = "a box that A does not get past fails as scene_stuck", + .name = "a box that B does not get past fails as scene_stuck", .input = {.looks = {look_at(0ms, DIALOG)}}, - .expectation = {.verdict = "failed: scene_stuck", .a_presses = 400}, + .expectation = {.verdict = "failed: scene_stuck", .a_presses = 0, .b_presses = 400}, }, { .name = "past 360 s it fails as scene_timeout", .input = {.looks = {look_at(0ms, DIALOG), look_at(361000ms, DIALOG)}}, - .expectation = {.verdict = "failed: scene_timeout", .a_presses = 1}, + .expectation = {.verdict = "failed: scene_timeout", .a_presses = 0, .b_presses = 1}, }, { .name = "a minute of blind A in a still cutscene is summed up every 30 s", @@ -686,7 +693,8 @@ const RunCase RUN_CASES[] = { .input = {.looks = arrival_with_three_fades(), .config = three_fades_config()}, .expectation = { .verdict = "done", - .a_presses = 4, + .a_presses = 0, + .b_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{ @@ -707,7 +715,8 @@ const RunCase RUN_CASES[] = { .input = {.looks = arrival_banner_until_a(), .config = three_fades_config()}, .expectation = { .verdict = "done", - .a_presses = 3, + .a_presses = 1, + .b_presses = 2, .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", @@ -716,7 +725,7 @@ const RunCase RUN_CASES[] = { { .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}, + .expectation = {.verdict = "failed: scene_stuck", .a_presses = 3, .b_presses = 2}, }, { .name = "the trace logs each new state", @@ -726,7 +735,7 @@ const RunCase RUN_CASES[] = { look_at(/*at=*/800ms, NOTHING, {MISSION_BANNER_READING}), look_at(1000ms), }}, - .expectation = {.verdict = "done", .a_presses = 1, .line = "[PLZA test] screen 3: mission_banner at 0.8s: mission banner"}, + .expectation = {.verdict = "done", .a_presses = 0, .b_presses = 1, .line = "[PLZA test] screen 3: mission_banner at 0.8s: mission banner"}, }, }; @@ -802,6 +811,158 @@ class RunTest : public UnitTest{ }; +// 03.05's nurse as a closed loop, on the screens of the console run's log +// (console B 2026-11-16): her greeting, a black fade (the heal), her last +// lines, then her box closing over one look and the A prompt to her at +// the counter. A at the closing box or at the prompt talks to her again +// ("Your Pokemon is already in great shape!", one line); B there does +// nothing. +class NurseCounter : public Pokemon::FakeStoryBackend{ +public: + explicit NurseCounter(CancellableScope& scope) + : FakeStoryBackend({}, scope) + {} + + // The talks started after the heal's. + size_t talks_again() const{ + return m_talks_again; + } + + virtual void press(Button button, Milliseconds hold, Milliseconds release) override{ + FakeStoryBackend::press(button, hold, release); + m_now += hold + release; + switch (m_phase){ + case Phase::GREETING: + case Phase::LAST_LINES: + case Phase::AGAIN: + m_lines--; + if (m_lines == 0 && m_phase == Phase::GREETING){ + m_phase = Phase::HEAL_FADE; + m_fade_until = m_now + 3000ms; + }else if (m_lines == 0){ + m_phase = Phase::CLOSING; + } + return; + case Phase::CLOSING: + case Phase::AT_PROMPT: + if (button == BUTTON_A){ + m_phase = Phase::AGAIN; + m_lines = 1; + m_talks_again++; + } + return; + case Phase::HEAL_FADE: + return; + } + } + virtual void wait(Milliseconds duration) override{ + FakeStoryBackend::wait(duration); + m_now += duration; + } + virtual Pokemon::Observation observe() override{ + Pokemon::Observation look; + look.when = WallClock::min() + m_now; + if (m_phase == Phase::HEAL_FADE && m_now >= m_fade_until){ + m_phase = Phase::LAST_LINES; + m_lines = 2; + } + switch (m_phase){ + case Phase::HEAL_FADE: + look.events.set(ScreenEvent::FADE_BLACK, true); + return look; + case Phase::GREETING: + case Phase::LAST_LINES: + case Phase::AGAIN: + look.events.set(ScreenEvent::DIALOG_BOX, true); + look.readings[std::string(ADVANCE_ARROW_READING)] = 1; + return look; + case Phase::CLOSING: + look.events.set(ScreenEvent::DIALOG_BOX, true); + m_phase = Phase::AT_PROMPT; + return look; + case Phase::AT_PROMPT: + look.events.set(ScreenEvent::INTERACT_PROMPT, true); + return look; + } + return look; + } + +private: + enum class Phase{GREETING, HEAL_FADE, LAST_LINES, CLOSING, AT_PROMPT, AGAIN}; + + Milliseconds m_now = 0ms; + Phase m_phase = Phase::GREETING; + size_t m_lines = 5; + Milliseconds m_fade_until = 0ms; + size_t m_talks_again = 0; +}; + +// Scene machines at 03.05's nurse (NurseCounter), on the screens as they +// follow from its presses. +struct NurseCase{ + std::string name; + struct Input{ + SceneMachineConfig config; + }; + Input input; + struct Expectation{ + // "done", or "failed: ". + std::string verdict; + // The run's last line. + std::string end; + // The talks started after the heal's. + size_t talks_again = 0; + }; + Expectation expectation; +}; + +const NurseCase NURSE_CASES[] = { + { + // console B 2026-11-16: A at the closing box talked to her again + // for 110 s, until the 120 s timeout. + .name = "03.05's heal_party (scene): done on her A prompt, no talk again", + .input = {.config = scene_step_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on talk_prompt.", .talks_again = 0}, + }, + { + .name = "mash_to_move_hints at a talk's end: done on the A prompt, no talk again", + .input = {.config = arrival_config()}, + .expectation = {.verdict = "done", .end = "[PLZA test] done on talk_prompt.", .talks_again = 0}, + }, +}; + +UnitTestResult check_nurse(const NurseCase& test, CancellableScope& scope){ + NurseCounter backend(scope); + const Pokemon::Outcome outcome = run_scene_machine(backend, "test", test.input.config, 120s); + 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.talks_again() != test.expectation.talks_again){ + return std::format( + "expected {} talks after the heal's, got {}: {}", test.expectation.talks_again, backend.talks_again(), joined(backend.inputs(), ", ") + ); + } + 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 NurseTest : public UnitTest{ +public: + explicit NurseTest(const NurseCase& test) + : UnitTest(std::format("PokemonLZA::AutoStorySceneMachine closed loop - {}", test.name)) + , m_test(test) + {} + virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ + return check_nurse(m_test, scope); + } +private: + const NurseCase& m_test; +}; + + } // namespace @@ -809,6 +970,9 @@ void add_tests_AutoStorySceneMachine(UnitTestDatabase& database){ for (const RunCase& test : RUN_CASES){ database.add(test); } + for (const NurseCase& test : NURSE_CASES){ + database.add(test); + } } From 6162fe260ca2445868aa92627a1804ecc4590bd4 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 16 Nov 2026 07:06:53 -0800 Subject: [PATCH 24/24] PLZA 03.06/03.07: split at the Wild Zones card autosave 03.06 now ends on the autosave seen in wild_zones_tutorial (console B, 2026-11-16, badge at 41.4 s). The run to Wild Zone 1's gate and the entry move to the start of 03.07, which reloads that save: 03.07 had reloaded outside the gate and thrown Poke Balls there (no_catch). --- .../PokemonLZA_AutoStoryGame_Tests.cpp | 8 +++---- .../AutoStory/StoryData/plza-03.06.plan.json | 24 ++++--------------- .../AutoStory/StoryData/plza-03.07.plan.json | 23 +++++++++++++++--- 3 files changed, 29 insertions(+), 26 deletions(-) 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 e911991b27..8c0755ab30 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame_Tests.cpp @@ -71,7 +71,7 @@ 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:unverified 03.02:from_save:autosave 03.02b:from_save 03.03:from_save:autosave 03.04:from_save:autosave " - "03.05:from_save:autosave 03.06:from_save 03.07:from_save:autosave 03.08:from_save:autosave 03.08b:from_save " + "03.05:from_save:autosave 03.06:from_save:autosave 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" }, @@ -961,13 +961,13 @@ const RunCase RUN_CASES[] = { .expectation = {.verdict = "done", .inputs = "press B, press B, wait 250ms"}, }, { - .name = "03.06's run to the gate needs a console", - .input = {.checkpoint = "03.06", .first_step = 4, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .name = "03.07's run to the gate needs a console", + .input = {.checkpoint = "03.07", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, .expectation = {.verdict = "failed at to_zone_1_gate: console_only", .inputs = ""}, }, { .name = "03.07's tutorial catch needs a console", - .input = {.checkpoint = "03.07", .first_step = 0, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, + .input = {.checkpoint = "03.07", .first_step = 2, .steps = 1, .looks = {party_bar(Milliseconds(0))}}, .expectation = {.verdict = "failed at catch_fletchling: console_only", .inputs = ""}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json index 7188bb9cb5..8f10ebd082 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.06.plan.json @@ -3,7 +3,7 @@ "game": "plza", "checkpoint": { "id": "03.06", - "title": "To Wild Zone 1", + "title": "To the Wild Zones card", "start": { "place": "LumioseCity", "spot": "PokemonCenter" @@ -41,28 +41,14 @@ "kind": "scene", "why": "step 57: Taunie on wild zones, the Wild Zones card", "action": "a" - }, - { - "id": "to_zone_1_gate", - "kind": "game_action", - "why": "step 58, after Taunie's scene: runs straight on to Wild Zone 1's gate until its A prompt, by upstream's run_towards_gate_with_A_button (user, 2026-11-15: try it before plza/autostory's gate-pillar steering). Replaces the timed 4.3 s walk (22 units at ~5.1 units/s, measured 2026-11-08 on console B), so 8 s of running is ample.", - "action": "run_to_gate", - "args": { - "timeout_ms": 8000 - } - }, - { - "id": "enter_zone_1", - "kind": "game_action", - "why": "step 58: A Enter at the gate (a scene step ends at once on its prompt), Taunie, the Throwing Poke Balls card", - "action": "mash_to_move_hints", - "args": {"press_a_first": true} } ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. No save: no autosave at its end was seen in a run log (2026-11-15 save review); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Ends on the autosave in wild_zones_tutorial, its last step (console B, 2026-11-16: badge at 41.4 s), so a checkpoint starts where that save reloads; 03.07 goes on into Wild Zone 1. The menu save of plza/autostory is dropped." } }, - "execution": {} + "execution": { + "save": "autosave" + } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json index 464d2c79f8..f1ad0f34a8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-03.07.plan.json @@ -3,11 +3,28 @@ "game": "plza", "checkpoint": { "id": "03.07", - "title": "Wild Zone 1: first catches", + "title": "Into Wild Zone 1: first catches", "start": { - "place": "WildZone1" + "place": "LumioseCity", + "spot": "WildZone1Gate" }, "events": [ + { + "id": "to_zone_1_gate", + "kind": "game_action", + "why": "step 58, after Taunie's scene: runs straight on to Wild Zone 1's gate until its A prompt, by upstream's run_towards_gate_with_A_button (user, 2026-11-15: try it before plza/autostory's gate-pillar steering). Replaces the timed 4.3 s walk (22 units at ~5.1 units/s, measured 2026-11-08 on console B), so 8 s of running is ample.", + "action": "run_to_gate", + "args": { + "timeout_ms": 8000 + } + }, + { + "id": "enter_zone_1", + "kind": "game_action", + "why": "step 58: A Enter at the gate (a scene step ends at once on its prompt), Taunie, the Throwing Poke Balls card", + "action": "mash_to_move_hints", + "args": {"press_a_first": true} + }, { "id": "catch_fletchling", "kind": "game_action", @@ -29,7 +46,7 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game. Autosave: the game's autosave at after_catches, its last step, was seen in four run logs (console B, 2026-11-13); the menu save of plza/autostory is dropped." + "source": "console B recording, 2026-11-08/09: played step by step from a new game. Starts outside Wild Zone 1's gate, where 03.06's autosave in wild_zones_tutorial reloads (console B, 2026-11-16: 03.07 reloaded there and threw outside the zone when it began at catch_fletchling). Autosave: the game's autosave at after_catches, its last step, was seen in four run logs (console B, 2026-11-13); the menu save of plza/autostory is dropped." } }, "execution": {