From 1ce0b5682a0b8a319f647db48f5f5d69534a6ac7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 19:49:59 -0800 Subject: [PATCH 01/33] PokemonLZA: AutoStory: the program, engine glue, detectors and the new game (01.00) The base of the PLZA AutoStory stack: the program on the shared story engine (backend, story game, scene machine, screen events, observation), the detectors (Detectors/), the dialogue, walk and scene actions (Actions/), the step validator, the story table and its files, with their unit tests, and the first checkpoint, 01.00: a new game from the title screen to the station platform. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- SerialPrograms/CMakeLists.txt | 4 + .../PokemonLZA/PokemonLZA_Panels.cpp | 3 + .../PokemonLZA/PokemonLZA_Tests.cpp | 10 + .../Actions/PokemonLZA_AutoStoryActions.cpp | 175 ++++++ .../Actions/PokemonLZA_AutoStoryActions.h | 76 +++ .../Actions/PokemonLZA_AutoStoryDialogs.cpp | 118 ++++ .../Actions/PokemonLZA_AutoStoryDialogs.h | 50 ++ .../Actions/PokemonLZA_AutoStoryMoves.cpp | 92 +++ .../Actions/PokemonLZA_AutoStoryMoves.h | 78 +++ .../Actions/PokemonLZA_AutoStoryScenes.cpp | 183 ++++++ .../Actions/PokemonLZA_AutoStoryScenes.h | 65 +++ .../PokemonLZA_AutoStoryWalkScreenChecks.cpp | 104 ++++ .../PokemonLZA_AutoStoryWalkScreenChecks.h | 46 ++ ...kemonLZA_AutoStoryAdvanceArrowDetector.cpp | 217 +++++++ ...PokemonLZA_AutoStoryAdvanceArrowDetector.h | 46 ++ .../PokemonLZA_AutoStoryAutosaveDetector.cpp | 83 +++ .../PokemonLZA_AutoStoryAutosaveDetector.h | 46 ++ ...kemonLZA_AutoStoryControlsHintDetector.cpp | 58 ++ ...PokemonLZA_AutoStoryControlsHintDetector.h | 47 ++ .../PokemonLZA_AutoStoryDetectors_Tests.cpp | 542 ++++++++++++++++++ .../PokemonLZA_AutoStoryDetectors_Tests.h | 28 + ...LZA_AutoStoryMainMissionBannerDetector.cpp | 77 +++ ...onLZA_AutoStoryMainMissionBannerDetector.h | 52 ++ ...onLZA_AutoStoryMissionCompleteDetector.cpp | 58 ++ ...emonLZA_AutoStoryMissionCompleteDetector.h | 49 ++ .../PokemonLZA_AutoStoryPixelShares.cpp | 61 ++ .../PokemonLZA_AutoStoryPixelShares.h | 72 +++ ...onLZA_AutoStoryPlatformArrivalDetector.cpp | 204 +++++++ ...emonLZA_AutoStoryPlatformArrivalDetector.h | 83 +++ ...PokemonLZA_AutoStorySkipPromptDetector.cpp | 53 ++ .../PokemonLZA_AutoStorySkipPromptDetector.h | 43 ++ .../AutoStory/PokemonLZA_AutoStory.cpp | 178 ++++++ .../Programs/AutoStory/PokemonLZA_AutoStory.h | 65 +++ .../AutoStory/PokemonLZA_AutoStoryBackend.cpp | 236 ++++++++ .../AutoStory/PokemonLZA_AutoStoryBackend.h | 129 +++++ .../PokemonLZA_AutoStoryDevFiles.cpp | 38 ++ .../AutoStory/PokemonLZA_AutoStoryDevFiles.h | 43 ++ .../PokemonLZA_AutoStoryEngine_Tests.cpp | 303 ++++++++++ .../PokemonLZA_AutoStoryEngine_Tests.h | 26 + .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 512 +++++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryGame.h | 104 ++++ .../PokemonLZA_AutoStoryObservation.cpp | 57 ++ .../PokemonLZA_AutoStoryObservation.h | 66 +++ .../PokemonLZA_AutoStorySceneMachine.cpp | 533 +++++++++++++++++ .../PokemonLZA_AutoStorySceneMachine.h | 156 +++++ ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 420 ++++++++++++++ .../PokemonLZA_AutoStoryScreenEvents.cpp | 114 ++++ .../PokemonLZA_AutoStoryScreenEvents.h | 95 +++ ...PokemonLZA_AutoStoryScreenEvents_Tests.cpp | 130 +++++ .../PokemonLZA_AutoStoryStepValidator.cpp | 106 ++++ .../PokemonLZA_AutoStoryStepValidator.h | 42 ++ .../PokemonLZA_AutoStoryStoryFiles.cpp | 128 +++++ .../PokemonLZA_AutoStoryStoryFiles.h | 61 ++ .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 40 ++ .../AutoStory/PokemonLZA_AutoStoryTable.h | 62 ++ .../PokemonLZA_AutoStoryTable_Tests.cpp | 211 +++++++ .../PokemonLZA_AutoStoryTable_Tests.h | 26 + .../ReferenceData/plza-platform.json | 70 +++ .../AutoStory/StoryData/plza-01.00.plan.json | 44 ++ SerialPrograms/cmake/SourceFiles.cmake | 54 ++ 60 files changed, 6872 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/ReferenceData/plza-platform.json create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json diff --git a/SerialPrograms/CMakeLists.txt b/SerialPrograms/CMakeLists.txt index 6b925e88a3..f253793b04 100644 --- a/SerialPrograms/CMakeLists.txt +++ b/SerialPrograms/CMakeLists.txt @@ -227,6 +227,10 @@ add_library(SerialProgramsLib STATIC ${CORE_LIBRARY_SOURCES} ${LIBRARY_SOURCES}) include(cmake/EmbedTextFiles.cmake) pa_embed_text_files(SerialProgramsLib Source/Pokemon/Navigation/TestMaps Pokemon/Navigation/Pokemon_NavigationTestMaps.h PokemonAutomation::Pokemon navigation_test_map_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData + VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h PokemonAutomation::NintendoSwitch::PokemonLZA autostory_checkpoint_json) +pa_embed_text_files(SerialProgramsLib Source/VideoGames/PokemonLZA/Programs/AutoStory/ReferenceData + VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h PokemonAutomation::NintendoSwitch::PokemonLZA autostory_reference_json) # Create binary target diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp index bd5e98adae..cfc1cd9bd3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Panels.cpp @@ -54,6 +54,7 @@ #include "Programs/TestPrograms/PokemonLZA_MoveBoxArrow.h" #include "Programs/TestPrograms/PokemonLZA_TestBoxCellInfo.h" #include "InferenceTraining/PokemonLZA_GenerateLocationNameOCR.h" +#include "Programs/AutoStory/PokemonLZA_AutoStory.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -68,6 +69,7 @@ PanelListFactory::PanelListFactory() ) {} +// code-health: allow function_lines -- the list reads top to bottom as the program menu does; splitting it by section hides that order std::vector PanelListFactory::make_panels() const{ std::vector ret; @@ -121,6 +123,7 @@ std::vector PanelListFactory::make_panels() const{ ret.emplace_back("---- Public Betas ----"); ret.emplace_back(make_SingleSwitchProgram()); + ret.emplace_back(make_SingleSwitchProgram()); if (STATIC_GLOBALS.DEVELOPER_MODE){ ret.emplace_back("---- Developer Tools ----"); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index ead2ea2d67..b7861d2bff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -19,6 +19,11 @@ #include "Inference/Map/PokemonLZA_MapIconDetector.h" #include "Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "Inference/PokemonLZA_SelectionArrowDetector.h" +#include "Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h" +#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" +#include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h" +#include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h" +#include "Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -41,6 +46,11 @@ void add_tests(UnitTestDatabase& database){ add_tests_MapIconDetector(database); add_tests_OverworldPartySelectionDetector(database); add_tests_SelectionArrowDetector(database); + add_tests_AutoStory_StoryTable(database); + add_tests_AutoStoryScreenEvents(database); + add_tests_AutoStoryDetectors(database); + add_tests_AutoStorySceneMachine(database); + add_tests_AutoStoryEngine(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp new file mode 100644 index 0000000000..9590d82a58 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp @@ -0,0 +1,175 @@ +/* PokemonLZA AutoStory - Actions + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Inference/Battles/PokemonLZA_RunFromBattleDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_TrainerBattle.h" +#include "PokemonLZA_AutoStoryActions.h" +#include "PokemonLZA_AutoStoryDialogs.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +StoryActionNotImplemented::StoryActionNotImplemented(std::string message) + : OperationFailedException(ErrorReportMode::NO_ERROR_REPORT, std::move(message)) +{} + + +void fight_battle( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai +){ + RunFromBattleWatcher battle_menu(COLOR_GREEN, &console.overlay(), 10ms); + OverworldPartySelectionWatcher overworld(COLOR_WHITE, &console.overlay(), 100ms); + TrainerBattleState battle_state(battle_ai); + // The battle's text first: the overworld only ends it once it has + // begun, and it must begin within a minute. + const WallClock start_deadline = current_time() + 60s; + bool started = false; + while (true){ + context.wait_for_all_requests(); + const int ret = run_until( + console, context, + [](ProControllerContext& context){ + pbf_mash_button(context, BUTTON_B, 120s); + }, + {battle_menu, overworld} + ); + if (ret == 0){ + started = true; + if (!battle_state.attempt_one_attack(env, console, context)){ + pbf_press_button(context, BUTTON_UP, 500ms, 1000ms); + } + continue; + } + if (ret == 1 && started){ + return; + } + if (ret < 0 || current_time() > start_deadline){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "fight_battle(): no battle began within a minute, or its menu was gone for two.", + console + ); + } + // The overworld before the battle: its text has not started it yet. + context.wait_for(500ms); + } +} + + + +void fight_battle_in_progress( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, std::chrono::seconds timeout +){ + TrainerBattleState battle_state(battle_ai); + FlatWhiteDialogDetector white_dialog; + BlueDialogDetector blue_dialog; + TealDialogDetector teal_dialog; + const WallClock deadline = current_time() + timeout; + while (true){ + context.wait_for_all_requests(); + const VideoSnapshot screen = console.video().snapshot(); + if (white_dialog.detect(screen) || blue_dialog.detect(screen) || teal_dialog.detect(screen)){ + return; + } + if (current_time() > deadline){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "fight_battle_in_progress(): no dialog after the battle within the timeout.", + console + ); + } + battle_state.attempt_one_attack(env, console, context); + } +} + + + +namespace{ + +// Whether the report page's Save button (its cursor arrow, where +// save_game_to_menu() looks for it) shows within `timeout`. +bool save_button_shows(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + SelectionArrowWatcher save_button( + COLOR_GREEN, &console.overlay(), SelectionArrowType::RIGHT, {0.287118, 0.638835, 0.064410, 0.108738} + ); + return wait_until(console, context, timeout, {save_button}) == 0; +} + +// From the overworld: X opens the menu, R its report page. The first menu +// of a playthrough opens under a save tutorial card that A closes, leaving +// the menu with the cursor on the Bag (console B, 2026-11-10); R does +// nothing over the card. So when R does not bring up the Save button, A +// once, then R again. A is never pressed on the plain menu, where it +// would open the Bag. +void open_save_report(ConsoleHandle& console, ProControllerContext& context){ + pbf_press_button(context, BUTTON_X, 160ms, 2340ms); + pbf_press_button(context, BUTTON_R, 160ms, 240ms); + if (save_button_shows(console, context, 5s)){ + return; + } + console.log("save_story_game(): no Save button after R: the menu's tutorial card; pressing A, then R."); + pbf_press_button(context, BUTTON_A, 160ms, 1340ms); + pbf_press_button(context, BUTTON_R, 160ms, 240ms); + if (!save_button_shows(console, context, 5s)){ + console.log("save_story_game(): still no Save button; save_game_to_menu() takes over.", COLOR_RED); + } +} + +// save_game_to_menu(), its failures as false. +bool try_save(ConsoleHandle& console, ProControllerContext& context){ + try{ + return save_game_to_menu(console, context); + }catch (OperationFailedException& e){ + console.log(std::format("save_story_game(): {}", e.message()), COLOR_RED); + return false; + } +} + +} // namespace + +// Opens the report page (open_save_report(), for the first menu's +// tutorial), then save_game_to_menu() presses Save once its button shows +// and waits for the "Saved!" text, so the save is confirmed. If that +// fails, B back to the overworld (B is harmless while writing) and one +// more try. +void save_story_game(ConsoleHandle& console, ProControllerContext& context){ + open_save_report(console, context); + if (!try_save(console, context)){ + mash_to_overworld(console, context, BUTTON_B, 10s); + if (!save_game_to_menu(console, context)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "save_story_game(): the game did not save.", + console + ); + } + } + mash_to_overworld(console, context, BUTTON_B, 10s); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h new file mode 100644 index 0000000000..19de9d6798 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h @@ -0,0 +1,76 @@ +/* PokemonLZA AutoStory - Actions + * + * From: https://github.com/PokemonAutomation/ + * + * The battle and save actions of the story game (PokemonLZA_AutoStoryGame.h), + * with the dialogue ones in PokemonLZA_AutoStoryDialogs.h, the walks in + * PokemonLZA_AutoStoryMoves.h and the scenes in PokemonLZA_AutoStoryScenes.h. + * Each is a short function over the LZA battle and menu code that already + * exists (TrainerBattle, BasicNavigation, the dialog and selection-arrow + * detectors). An action the game has no code for yet throws + * StoryActionNotImplemented, naming what is missing, instead of pressing + * buttons blind. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryActions_H +#define PokemonAutomation_PokemonLZA_AutoStoryActions_H + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Tools/ProgramEnvironment.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A story action this game has no code for yet. The story executor lets +// it end the run instead of reloading and trying again, since every +// attempt would fail the same way. +class StoryActionNotImplemented : public OperationFailedException{ +public: + explicit StoryActionNotImplemented(std::string message); + + // code-health: allow char_pointer -- the exception base class's name() returns const char* + virtual const char* name() const override{ + return "StoryActionNotImplemented"; + } +}; + + +// From a trainer's or a wild Pokemon's battle starting, fights it with +// TrainerBattleState (`battle_ai`'s moves), pressing B through the text +// around it, until the overworld is back. Throws OperationFailedException +// if neither shows for two minutes. +void fight_battle( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai +); + +// In a battle that is already on screen: attacks with TrainerBattleState +// until a dialog box shows (the speech after a win or a loss). For story +// battles, which show no Run prompt for fight_battle() to start on. +// Throws OperationFailedException after `timeout`. +void fight_battle_in_progress( + ProgramEnvironment& env, ConsoleHandle& console, ProControllerContext& context, + BattleAIOption& battle_ai, std::chrono::seconds timeout +); + +// From the overworld, saves the game (save_game_to_menu()) and returns to +// the overworld. The first menu of a playthrough shows a save tutorial +// card, which it closes with A. If the save fails, B back to the +// overworld and one more try; throws OperationFailedException if that +// fails too. +void save_story_game(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp new file mode 100644 index 0000000000..0d6e456191 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp @@ -0,0 +1,118 @@ +/* PokemonLZA AutoStory - Dialogs + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/Async/InferenceRoutines.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" +#include "PokemonLZA_AutoStoryDialogs.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +void mash_to_overworld(ConsoleHandle& console, ProControllerContext& context, Button button, Milliseconds timeout){ + // The party list shows between lines of a scene too; a second of it is + // the overworld. + OverworldPartySelectionWatcher overworld(COLOR_WHITE, &console.overlay(), 1000ms); + context.wait_for_all_requests(); + const int ret = run_until( + console, context, + [button, timeout](ProControllerContext& context){ + pbf_mash_button(context, button, timeout); + }, + {overworld} + ); + if (ret < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("mash_to_overworld(): no overworld after {} ms.", timeout.count()), + console + ); + } +} + +void talk_to_facing(ConsoleHandle& console, ProControllerContext& context){ + FlatWhiteDialogWatcher white(COLOR_RED, &console.overlay()); + BlueDialogWatcher blue(COLOR_BLUE, &console.overlay()); + TealDialogWatcher teal(COLOR_GREEN, &console.overlay()); + context.wait_for_all_requests(); + const int ret = run_until( + console, context, + [](ProControllerContext& context){ + pbf_press_button(context, BUTTON_A, 160ms, 5000ms); + }, + {white, blue, teal} + ); + if (ret < 0){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "talk_to_facing(): A opened no dialogue.", + console + ); + } +} + + +const ImageFloatBox& dialog_choice_box(){ + static const ImageFloatBox box{0.654308, 0.481553, 0.295529, 0.312621}; + return box; +} + +namespace{ + +// The selection arrow's top among the choices, once it has held still; +// none if it does not show within `timeout`. +std::optional wait_for_choice_arrow(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + SelectionArrowWatcher arrow(COLOR_YELLOW, &console.overlay(), SelectionArrowType::RIGHT, dialog_choice_box()); + context.wait_for_all_requests(); + if (wait_until(console, context, timeout, {arrow}) < 0){ + return std::nullopt; + } + return arrow.last_detected().y; +} + +} // namespace + +void choose_dialog_option(ConsoleHandle& console, ProControllerContext& context, size_t index){ + std::optional row = wait_for_choice_arrow(console, context, 10s); + if (!row){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "choose_dialog_option(): no choices on screen.", + console + ); + } + for (size_t moved = 0; moved < index; moved++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 240ms); + const std::optional next = wait_for_choice_arrow(console, context, 2s); + if (!next || *next <= *row){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("choose_dialog_option(): the arrow did not move down to choice {}.", moved + 1), + console + ); + } + row = next; + } + pbf_press_button(context, BUTTON_A, 160ms, 240ms); + context.wait_for_all_requests(); +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h new file mode 100644 index 0000000000..424c47c4a3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h @@ -0,0 +1,50 @@ +/* PokemonLZA AutoStory - Dialogs + * + * From: https://github.com/PokemonAutomation/ + * + * The story's dialogue actions (PokemonLZA_AutoStoryActions.h has the + * rest): through a scene to the overworld, a talk, a choice. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryDialogs_H +#define PokemonAutomation_PokemonLZA_AutoStoryDialogs_H + +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// From a dialogue or a scene, presses `button` until the overworld is back +// and holds for a second. Throws OperationFailedException if it is not back +// within `timeout`. +void mash_to_overworld(ConsoleHandle& console, ProControllerContext& context, Button button, Milliseconds timeout); + +// From the overworld, presses A at what the player faces. Returns once a +// dialogue box shows; throws OperationFailedException if none does. +void talk_to_facing(ConsoleHandle& console, ProControllerContext& context); + +// Where a dialogue's choices are drawn, and choose_dialog_option() looks +// for the selection arrow: the restaurant receptionist's (RestaurantFarmer). +// Other dialogues' choices are assumed to sit there. +const ImageFloatBox& dialog_choice_box(); + +// With a dialogue's choices on screen, picks choice `index` (0 is the top): +// waits for the selection arrow, presses down until it has moved `index` +// rows, then A. Throws OperationFailedException if the arrow never shows or +// does not move. +void choose_dialog_option(ConsoleHandle& console, ProControllerContext& context, size_t index); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp new file mode 100644 index 0000000000..5e4ab653b9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp @@ -0,0 +1,92 @@ +/* PokemonLZA AutoStory - Moves + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_FastTravelNavigation.h" +#include "PokemonLZA_AutoStoryMoves.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +namespace{ + +// The heading on a fresh look, read by `reader` when there is one. +std::optional read_heading(PlzaBackend& backend, const PlzaReader& reader){ + Pokemon::Observation look = backend.observe(); + if (reader){ + reader(backend, look); + } + return Pokemon::story_heading(look); +} + +} // namespace + + +Pokemon::Outcome face_heading(PlzaBackend& backend, const PlzaReader& reader, double heading, double tolerance){ + std::optional now = read_heading(backend, reader); + for (size_t attempt = 0; attempt < 4 && now && get_angle_between_facing_directions(*now, heading) > tolerance; attempt++){ + story_turn(backend, heading - *now); + now = read_heading(backend, reader); + } + if (!now){ + return Pokemon::outcome_failed("heading_unread", "no look read the minimap's heading"); + } + if (get_angle_between_facing_directions(*now, heading) > tolerance){ + return Pokemon::outcome_failed( + "heading_missed", + std::format("facing {} deg, wanted {:.0f} +/- {:.0f}", *now, heading, tolerance) + ); + } + return Pokemon::outcome_ok(); +} + +Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move, const PlzaReader& heading){ + if (move.heading){ + const Pokemon::Outcome faced = face_heading(backend, heading, *move.heading, 10.0); + if (!faced.succeeded()){ + return faced; + } + } + for (const StoryWalkLeg& leg : move.legs){ + if (leg.turn != 0){ + // The walk goes where the camera looks: recenter it after the turn. + story_turn(backend, leg.turn); + backend.press(BUTTON_L, 100ms, 150ms); + } + if (leg.walk > Milliseconds(0)){ + backend.hold(Pokemon::Direction::NORTH, leg.walk, Pokemon::StoryPace::WALK); + } + } + return Pokemon::outcome_ok(); +} + + +void fly_to(ConsoleHandle& console, ProControllerContext& context, Language language, Location location){ + const FastTravelState state = open_map_and_fly_to(console, context, language, location); + if (state != FastTravelState::SUCCESS){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format( + "fly_to(): could not fly to {} (state {}).", + get_location_item_from_enum(location).slug, static_cast(state) + ), + console + ); + } +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h new file mode 100644 index 0000000000..ca2cc313f3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h @@ -0,0 +1,78 @@ +/* PokemonLZA AutoStory - Moves + * + * From: https://github.com/PokemonAutomation/ + * + * The story's walks in the overworld (PokemonLZA_AutoStoryActions.h has + * the other actions): recorded turns and timed walks, the compass, a + * fast travel. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryMoves_H +#define PokemonAutomation_PokemonLZA_AutoStoryMoves_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "VideoGames/PokemonLZA/Resources/PokemonLZA_Locations.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// One leg of a walk: a turn, then a walk straight on. +struct StoryWalkLeg{ + // Degrees clockwise from where the player faces (negative: left), as + // the story was recorded: L recenters the camera behind the player, + // the stick is tapped that way for 150 ms, and L again. The tap also + // takes a step. 0: no turn. + double turn = 0; + // How long to hold the stick forward after the turn, walking (not + // dashing). 0: the turn only. + Milliseconds walk = Milliseconds(0); +}; + +// A walk in the overworld. Lumiose has no tiles: a move is an optional +// compass heading to face first, then legs of turns and timed walks, as +// recorded on the console. +struct StoryMove{ + // Clockwise from north, as the minimap's arrow reads it + // (get_facing_direction()). None: no compass turn first. + std::optional heading = std::nullopt; + std::vector legs = {}; +}; + +// Turns the player toward `heading`, within `tolerance` degrees: turns by +// the difference (story_turn()) and reads the heading again, a few times. +// The heading is a look's STORY_HEADING reading, filled in by `reader` +// (heading_reader() on a console; none where observe() sets it). Fails as +// "heading_unread" when no look has it and "heading_missed" if it stays +// outside the tolerance. +Pokemon::Outcome face_heading(PlzaBackend& backend, const PlzaReader& reader, double heading, double tolerance); + +// From the overworld, walks as `move` says: faces its heading first, if it +// has one, then each leg's turn (and L to recenter the camera, since the +// walk goes where it looks) and walk. Nothing is read on the way: a leg +// that is cut short or blocked goes unnoticed, and a step that needs a +// prompt after the walk fails there instead. `heading` reads the compass +// (face_heading()). +Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move, const PlzaReader& heading); + +// From the overworld, opens the map and fast travels to `location` +// (open_map_and_fly_to()). Returns in the overworld there; throws +// OperationFailedException if the game would not fly (pursued, or the +// place is not unlocked). +void fly_to(ConsoleHandle& console, ProControllerContext& context, Language language, Location location); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp new file mode 100644 index 0000000000..ac1e57fa70 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -0,0 +1,183 @@ +/* PokemonLZA AutoStory - Scenes + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" +#include "PokemonLZA_AutoStoryScenes.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +namespace{ + +// When an OVERWORLD mash is over: the party bar held a second, or (with a +// quiet time) nothing busy on screen for that long once the scene's +// minimum length has passed. +class OverworldEnd{ +public: + OverworldEnd(std::optional quiet, Milliseconds min_length) + : m_quiet(quiet) + , m_quiet_from(current_time() + min_length) + , m_last_busy(current_time()) + {} + bool reached(ConsoleHandle& console, const Pokemon::ScreenEvents& events, SceneMashAction action, WallClock now){ + if (events.any_of({ + Pokemon::ScreenEvent::DIALOG_BOX, Pokemon::ScreenEvent::CHOICE_BOX, + Pokemon::ScreenEvent::BATTLE_STARTED, Pokemon::ScreenEvent::FADE_BLACK, + Pokemon::ScreenEvent::FADE_WHITE, + })){ + m_last_busy = now; + } + if (action != SceneMashAction::DONE){ + m_can_move_since.reset(); + }else if (!m_can_move_since){ + m_can_move_since = now; + } + if (m_can_move_since && now - *m_can_move_since >= 1000ms){ + return true; + } + if (m_quiet && now >= m_quiet_from && now - m_last_busy >= *m_quiet){ + console.log(std::format("mash_scene(): quiet for {} ms, taking it as the overworld.", m_quiet->count())); + return true; + } + return false; + } + +private: + std::optional m_quiet; + WallClock m_quiet_from; + WallClock m_last_busy; + std::optional m_can_move_since; +}; + +void press_for(ProControllerContext& context, SceneMashAction action, Button text_button){ + switch (action){ + case SceneMashAction::PRESS_TEXT: + pbf_press_button(context, text_button, 160ms, 240ms); + return; + case SceneMashAction::PRESS_A: + pbf_press_button(context, BUTTON_A, 160ms, 240ms); + return; + case SceneMashAction::PRESS_B: + pbf_press_button(context, BUTTON_B, 160ms, 240ms); + return; + case SceneMashAction::WAIT: + case SceneMashAction::DONE: + context.wait_for(250ms); + return; + } +} + +// Logs the frame's events whenever they change (the still-screen flag left +// out), so a run's log shows each scene's fades, boxes and party bar. +void log_event_change(ConsoleHandle& console, const Pokemon::ScreenEvents& events, Pokemon::ScreenEvents& last){ + Pokemon::ScreenEvents shown = events; + shown.set(Pokemon::ScreenEvent::SCREEN_STILL, false); + if (shown == last){ + return; + } + last = shown; + std::string names; + for (size_t i = 0; i < Pokemon::SCREEN_EVENT_COUNT; i++){ + const Pokemon::ScreenEvent event = (Pokemon::ScreenEvent)i; + if (shown.has(event)){ + names += names.empty() ? "" : ", "; + names += Pokemon::screen_event_name(event); + } + } + console.log(std::format("mash_scene(): screen now: {}", names.empty() ? std::string("nothing") : names)); +} + +} // namespace + +void mash_scene( + ConsoleHandle& console, ProControllerContext& context, + SceneMashGoal goal, Button text_button, Milliseconds timeout, + std::optional quiet, Milliseconds min_length +){ + PlzaScreenObserver observer; + OverworldEnd overworld(quiet, min_length); + Pokemon::ScreenEvents last_events; + const WallClock start = current_time(); + while (current_time() - start < timeout){ + context.wait_for_all_requests(); + const WallClock now = current_time(); + const Pokemon::ScreenEvents events = observer.observe(console.video().snapshot(), now); + log_event_change(console, events, last_events); + const SceneMashAction action = scene_mash_action(events, goal, text_button == BUTTON_B); + if (goal == SceneMashGoal::OVERWORLD){ + if (overworld.reached(console, events, action, now)){ + return; + } + }else if (action == SceneMashAction::DONE){ + return; + } + press_for(context, action, text_button); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("mash_scene(): the goal did not show within {} ms.", timeout.count()), + console + ); +} + + +void new_game_language(ConsoleHandle&, ProControllerContext& context){ + // TODO: a title screen and a language list detector; the waits are guesses. + pbf_press_button(context, BUTTON_A, 160ms, 5000ms); + pbf_press_button(context, BUTTON_A, 160ms, 5000ms); + context.wait_for_all_requests(); +} + +void pick_first_look(ConsoleHandle&, ProControllerContext& context){ + // TODO: the shared MenuCursor (BDSP #305) once it reaches this branch, + // to read the highlight instead of relying on the edges clamping. + pbf_press_dpad(context, DPAD_UP, 160ms, 400ms); + for (int i = 0; i < 3; i++){ + pbf_press_dpad(context, DPAD_LEFT, 160ms, 400ms); + } + pbf_press_button(context, BUTTON_A, 160ms, 3000ms); + context.wait_for_all_requests(); +} + +void type_player_name(ConsoleHandle& console, ProControllerContext& context, const std::string& name){ + // TODO: a keyboard detector instead of the wait. + context.wait_for(3000ms); + // The system keyboard types lowercase. Its Shift (stick click) caps + // the next letter only, so it goes right before the name. Code entry + // takes upper case letters only and presses their keys, so the rest of + // the name comes out lower case. + std::string keys = name; + for (char& ch : keys){ + if ('a' <= ch && ch <= 'z'){ + ch = (char)(ch - 'a' + 'A'); + } + } + pbf_press_button(context, BUTTON_LCLICK, 160ms, 400ms); + context.wait_for_all_requests(); + FastCodeEntry::keyboard_enter_code(console, context, true, KeyboardLayout::QWERTY, keys, true); + context.wait_for(1000ms); + // PLUS is the keyboard's OK. "Confirm Choices" opens on "Change hair + // color"; "Ready!" is two rows down (console B, 2026-11-10). + pbf_press_button(context, BUTTON_PLUS, 160ms, 2500ms); + pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); + pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + context.wait_for_all_requests(); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h new file mode 100644 index 0000000000..4e9c905f06 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -0,0 +1,65 @@ +/* PokemonLZA AutoStory - Scenes + * + * From: https://github.com/PokemonAutomation/ + * + * The story actions that press through scenes rather than walk: the scene + * mash over PlzaScreenObserver's events, and the new game's opening, + * which is timed presses as recorded on console B (2026-11-08). None has run on a console as a story step yet. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryScenes_H +#define PokemonAutomation_PokemonLZA_AutoStoryScenes_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// From a scene, presses through it as scene_mash_action() says, reading +// PlzaScreenObserver's events, until `goal` shows (OVERWORLD: the party +// bar held a second). `text_button` advances the text (A or B). With a +// `quiet` time, an OVERWORLD mash also ends once no box, choice, battle or +// fade has shown for that long: the new game's tutorial shows no party bar +// (only the Move / Control Camera hints, which have no detector yet). +// A cutscene can hold a still frame longer than `quiet`, so the quiet end +// waits for `min_length`, the scene's rough recorded length, to pass. +// Throws OperationFailedException if the goal does not show within `timeout`. +void mash_scene( + ConsoleHandle& console, ProControllerContext& context, + SceneMashGoal goal, Button text_button, Milliseconds timeout, + std::optional quiet = std::nullopt, + Milliseconds min_length = Milliseconds(0) +); + + +// The new game's opening, as recorded 2026-11-08 on console B. None of it +// reads the screen: each waits a fixed time for its screen. + +// At the title screen with no save: A into the language list, A on its +// first entry (English, the default). +void new_game_language(ConsoleHandle& console, ProControllerContext& context); + +// On the look picker, whose highlight starts at random: UP, then LEFT x3 +// to the first look (the edges clamp), A. +void pick_first_look(ConsoleHandle& console, ProControllerContext& context); + +// On the name screen: types `name` on the Switch keyboard (upper case +// letters and digits only, keyboard_enter_code()), + to finish, then +// DOWN x2 and A on "Ready!". +void type_player_name(ConsoleHandle& console, ProControllerContext& context, const std::string& name); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp new file mode 100644 index 0000000000..c5e617d2f7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -0,0 +1,104 @@ +/* PokemonLZA AutoStory - Walk screen checks + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "PokemonLZA_AutoStoryWalkScreenChecks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using EngineEvent = PokemonAutomation::ScreenEvent; + + +namespace{ + +// How long each slice of the held last leg is, between looks for its end. +constexpr Milliseconds HOLD_SLICE = 250ms; +// How long a walk waits for free control, and how often it looks. +constexpr Milliseconds FREE_CONTROL_WAIT = 15000ms; +constexpr Milliseconds FREE_CONTROL_LOOK = 250ms; + +// What no walk may start on, by name; empty when free. +std::string not_free_control(const ScreenObservation& look){ + if (look.readings.contains(std::string(MISSION_BANNER_READING))){ + return "a mission banner"; + } + if (look.readings.contains(std::string(ADVANCE_ARROW_READING))){ + return "text waiting for A"; + } + if (look.events.has(EngineEvent::CHOICE_BOX)){ + return "a choice"; + } + if (look.events.has(EngineEvent::TEXT_BOX)){ + return "a text box"; + } + if (look.events.has(EngineEvent::BATTLE)){ + return "a battle"; + } + if (look.events.has(EngineEvent::FADE_BLACK) || look.events.has(EngineEvent::FADE_WHITE)){ + return "a fade"; + } + return ""; +} + +} // namespace + + +// Waits up to FREE_CONTROL_WAIT for two looks in a row on free control: a +// mission banner or the last line of a scene can still be up when the step +// before ends (console B, 2026-11-10: chase_pancham's legs went in under the +// MAIN MISSION 01 banner). +Pokemon::Outcome check_can_walk(PlzaBackend& backend, std::string_view walk){ + std::string busy; + int free_looks = 0; + for (Milliseconds waited = 0ms; waited <= FREE_CONTROL_WAIT; waited += FREE_CONTROL_LOOK){ + busy = not_free_control(backend.observe()); + free_looks = busy.empty() ? free_looks + 1 : 0; + if (free_looks >= 2){ + return Pokemon::outcome_ok(); + } + backend.wait(FREE_CONTROL_LOOK); + } + return Pokemon::outcome_failed( + "walk_not_free", + std::format("{}: no free control within {} ms, last on {}", walk, FREE_CONTROL_WAIT.count(), busy) + ); +} + +Pokemon::Outcome walk_until( + PlzaBackend& backend, std::string_view walk, const StoryMove& move, const PlzaReader& heading, EngineEvent 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, heading); + if (!walked.succeeded()){ + return walked; + } + // The slices stop the stick between them for as long as a look takes; + // the player barely slows. + for (Milliseconds held = 0ms; held < hold; held += HOLD_SLICE){ + backend.hold(Pokemon::Direction::NORTH, HOLD_SLICE, Pokemon::StoryPace::WALK); + if (backend.observe().events.has(end)){ + backend.log(std::format("{}: the end event after {} ms of the last leg.", walk, (held + HOLD_SLICE).count())); + return Pokemon::outcome_ok(); + } + } + return Pokemon::outcome_failed("walk_no_end", std::format("{}: no end event within {} ms of the last leg", walk, hold.count())); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h new file mode 100644 index 0000000000..4d78d5ad30 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h @@ -0,0 +1,46 @@ +/* PokemonLZA AutoStory - Walk screen checks + * + * From: https://github.com/PokemonAutomation/ + * + * What a story walk (run_story_move(), PokemonLZA_AutoStoryMoves.h) reads + * of the screen, since the walk itself reads nothing: before it, that the + * player has free control (check_can_walk()); during its last leg, the + * fade it ends on (walk_until()). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryWalkScreenChecks_H +#define PokemonAutomation_PokemonLZA_AutoStoryWalkScreenChecks_H + +#include +#include "CommonTools/ScreenMachine/ScreenObservation.h" +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h" +#include "PokemonLZA_AutoStoryMoves.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Fails as "walk_not_free" unless two looks 150 ms apart show no box, +// choice, fade or battle: a walk started anywhere else walks blind. The +// tutorial has no party bar, so it is not required. +Pokemon::Outcome check_can_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), the leg's time as the upper bound. Fails as +// "walk_no_end" if `end` does not show within it. `heading` reads the +// compass (face_heading()). +Pokemon::Outcome walk_until( + PlzaBackend& backend, std::string_view walk, const StoryMove& move, const PlzaReader& heading, + PokemonAutomation::ScreenEvent end +); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.cpp new file mode 100644 index 0000000000..933f849543 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.cpp @@ -0,0 +1,217 @@ +/* PokemonLZA AutoStory - Advance arrow detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryAdvanceArrowDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// A 4-connected blob of a mask: its bounds and its pixel count. +struct Blob{ + size_t min_x; + size_t min_y; + size_t max_x; + size_t max_y; + size_t count = 0; +}; + +// An area's mask split into blobs: each pixel's blob label (0 outside the +// mask; blob i has label i + 1). +struct BlobImage{ + size_t width = 0; + size_t height = 0; + std::vector labels; + std::vector blobs; + + uint32_t label(size_t x, size_t y) const{ + return labels[y * width + x]; + } +}; + +// A mask pixel no blob has taken yet. +constexpr uint32_t UNLABELLED = UINT32_MAX; + +// Labels the blob of mask pixels 4-connected to (x, y). +void flood_blob(size_t x, size_t y, BlobImage& image){ + const uint32_t label = (uint32_t)image.blobs.size() + 1; + Blob blob{x, y, x, y, 0}; + std::vector> stack{{x, y}}; + image.labels[y * image.width + x] = label; + const auto take = [&](size_t nx, size_t ny){ + uint32_t& here = image.labels[ny * image.width + nx]; + if (here == UNLABELLED){ + here = label; + stack.emplace_back(nx, ny); + } + }; + while (!stack.empty()){ + const auto [cx, cy] = stack.back(); + stack.pop_back(); + blob.count++; + blob.min_x = std::min(blob.min_x, cx); + blob.max_x = std::max(blob.max_x, cx); + blob.min_y = std::min(blob.min_y, cy); + blob.max_y = std::max(blob.max_y, cy); + if (cx > 0){ + take(cx - 1, cy); + } + if (cx + 1 < image.width){ + take(cx + 1, cy); + } + if (cy > 0){ + take(cx, cy - 1); + } + if (cy + 1 < image.height){ + take(cx, cy + 1); + } + } + image.blobs.push_back(blob); +} + +// The pixels of `area` that `in`, split into blobs. +template +BlobImage find_blobs(const ImageViewRGB32& area, In&& in){ + BlobImage image; + image.width = area.width(); + image.height = area.height(); + image.labels.assign(image.width * image.height, 0); + for (size_t y = 0; y < image.height; y++){ + for (size_t x = 0; x < image.width; x++){ + if (in(Color(area.pixel(x, y)))){ + image.labels[y * image.width + x] = UNLABELLED; + } + } + } + for (size_t y = 0; y < image.height; y++){ + for (size_t x = 0; x < image.width; x++){ + if (image.label(x, y) == UNLABELLED){ + flood_blob(x, y, image); + } + } + } + return image; +} + +// How well blob `label` fills a V across its bounds: its overlap with the +// V over their union. Each arm runs from 10% in at the top to the middle +// at the bottom, 22% of the width across. +double v_match(const BlobImage& image, uint32_t label){ + const Blob& blob = image.blobs[label - 1]; + const double width = double(blob.max_x - blob.min_x + 1); + const double height = double(blob.max_y - blob.min_y + 1); + size_t both = 0; + size_t either = 0; + for (size_t y = blob.min_y; y <= blob.max_y; y++){ + const double v = (double(y - blob.min_y) + 0.5) / height; + for (size_t x = blob.min_x; x <= blob.max_x; x++){ + const double u = (double(x - blob.min_x) + 0.5) / width; + const bool in_v = std::abs(std::abs(u - 0.5) - (0.40 * (1 - v) + 0.03)) <= 0.11; + const bool in_blob = image.label(x, y) == label; + if (in_v && in_blob){ + both++; + } + if (in_v || in_blob){ + either++; + } + } + } + return either == 0 ? 0 : double(both) / double(either); +} + +// The mask pixels of other blobs within `margin` of blob `label`'s +// bounds, per pixel of the blob. +double stray_share(const BlobImage& image, uint32_t label, size_t margin){ + const Blob& blob = image.blobs[label - 1]; + const size_t min_x = blob.min_x > margin ? blob.min_x - margin : 0; + const size_t min_y = blob.min_y > margin ? blob.min_y - margin : 0; + const size_t max_x = std::min(blob.max_x + margin, image.width - 1); + const size_t max_y = std::min(blob.max_y + margin, image.height - 1); + size_t stray = 0; + for (size_t y = min_y; y <= max_y; y++){ + for (size_t x = min_x; x <= max_x; x++){ + const uint32_t here = image.label(x, y); + if (here != 0 && here != label){ + stray++; + } + } + } + return double(stray) / double(blob.count); +} + +// Whether blob `label` is the chevron, on a screen `scale` times 1080p: +// 32x19 measured, 30-33 x 18-20 on every frame with it. +bool chevron_blob(const BlobImage& image, uint32_t label, double scale){ + const Blob& blob = image.blobs[label - 1]; + const double width = double(blob.max_x - blob.min_x + 1) / scale; + const double height = double(blob.max_y - blob.min_y + 1) / scale; + if (width < 26 || width > 40 || height < 15 || height > 24){ + return false; + } + const double aspect = width / height; + if (aspect < 1.4 || aspect > 2.1){ + return false; + } + return stray_share(image, label, size_t(4 * scale + 0.5)) <= 0.05 && v_match(image, label) >= 0.45; +} + +// Whether a blob of the pixels of `area` that `in` is the chevron. +template +bool chevron_in(const ImageViewRGB32& area, double scale, In&& in){ + const BlobImage image = find_blobs(area, in); + for (uint32_t label = 1; label <= image.blobs.size(); label++){ + if (chevron_blob(image, label, scale)){ + return true; + } + } + return false; +} + +} // namespace + + +AdvanceArrowDetector::AdvanceArrowDetector(Color color) + : m_color(color) + , m_area(1370.0 / 1920, 930.0 / 1080, 110.0 / 1920, 120.0 / 1080) +{} + +void AdvanceArrowDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_area); +} + +// Measured on 1920x1080 (console B, 2026-11-10; 01.01's runs 1 and 2, the +// lab's and the user's opening frames, 459 frames): the chevron's 35 +// frames (the ad's subtitles, white boxes, the opening's blue box) fill +// the V 0.53-0.70 with at most 1% stray pixels. Of the rest, the closest +// in size and shape is run 1's 0033 (a dark flyover blade, V 0.49 but +// 16% stray); the closest with nothing around it fill the V 0.43 or less +// and are out of the chevron's size. +bool AdvanceArrowDetector::detect(const ImageViewRGB32& screen){ + const double scale = double(screen.height()) / 1080; + const ImageViewRGB32 area = extract_box_reference(screen, m_area); + const bool white = chevron_in(area, scale, [](Color pixel){ + return pixel.red() >= 235 && pixel.green() >= 235 && pixel.blue() >= 235; + }); + return white || chevron_in(area, scale, [](Color pixel){ + return pixel.red() <= 110 && pixel.green() <= 110 && pixel.blue() <= 110; + }); +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h new file mode 100644 index 0000000000..8debae4975 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h @@ -0,0 +1,46 @@ +/* PokemonLZA AutoStory - Advance arrow detector + * + * From: https://github.com/PokemonAutomation/ + * + * The "press A to go on" chevron at the bottom right of a dialogue box or + * of the boxless subtitles of 01.01's ad. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryAdvanceArrowDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryAdvanceArrowDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The "press A to go on" chevron (a V about 32x19 on 1920x1080) at the +// right end of a dialogue box and of boxless subtitles: dark on a white +// box, white on a blue box and on the ad's subtitles. Found by shape in +// x 1370-1480, y 930-1050: a blob of white (every channel 235+) or dark +// (every channel 110 or under) pixels the size of the chevron, filling a +// V, with no other pixel of its colour around it. Text is not read, so +// any language matches. +class AdvanceArrowDetector : public StaticScreenDetector{ +public: + explicit AdvanceArrowDetector(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_area; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp new file mode 100644 index 0000000000..e76391ea53 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp @@ -0,0 +1,83 @@ +/* PokemonLZA AutoStory - Autosave detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryAutosaveDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The icon, and the strips around it (left, above, below) clear of white +// and cyan, `dx` pixels (of 1920) right of where the Chinese badge has +// them. +bool autosave_icon_at( + const ImageViewRGB32& screen, const ImageFloatBox& icon, + std::initializer_list around, double dx +){ + const ImageFloatBox icon_here = shifted(icon, dx); + const double white = white_share(screen, icon_here); + if (white < 0.08 || white > 0.40 || cyan_share(screen, icon_here) < 0.25){ + return false; + } + for (const ImageFloatBox& box : around){ + const ImageFloatBox here = shifted(box, dx); + if (white_share(screen, here) >= 0.05 || cyan_share(screen, here) >= 0.05){ + return false; + } + } + return true; +} + +} // namespace + + +AutosaveDetector::AutosaveDetector(Color color) + : m_color(color) + , m_icon(1603.0 / 1920, 73.0 / 1080, 27.0 / 1920, 31.0 / 1080) + , m_left(1570.0 / 1920, 73.0 / 1080, 28.0 / 1920, 31.0 / 1080) + , m_above(1603.0 / 1920, 56.0 / 1080, 27.0 / 1920, 14.0 / 1080) + , m_below(1603.0 / 1920, 108.0 / 1080, 27.0 / 1920, 14.0 / 1080) +{} + +void AutosaveDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_icon); + items.add(m_color, m_left); + items.add(m_color, m_above); + items.add(m_color, m_below); +} + +// Measured on the user's run (console B, 2026-11-10, frames 1.5 s apart): +// the badge's one frame (rec1_u132) has the icon 19% white and 48% cyan, +// nothing left of it. The only other frames over the icon bounds (u103, +// u104: a bright cutscene flash) are 70%+ white and 39%+ cyan left of it +// too; none of the opening's 56 lab frames come near. +// The badge is seen in Chinese only; with a shorter text (English +// "Saving...") a right-aligned badge moves the icon right, so the icon is +// looked for from where it is in Chinese to 240 px right of it. +// The 01.01 run (console B, 2026-11-10 13:00) took two flyover frames for +// the badge: 0033, a glowing blade at dx 40, and 0038, the sky at dx +// 152-172. Both glow on past the icon: the strips 14 px above and below it +// are 22%+ white or cyan there, 0% on u132; they must stay under 5%. +bool AutosaveDetector::detect(const ImageViewRGB32& screen){ + for (double dx = 0; dx <= 240; dx += 4){ + if (autosave_icon_at(screen, m_icon, {m_left, m_above, m_below}, dx)){ + return true; + } + } + return false; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h new file mode 100644 index 0000000000..e18115915c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h @@ -0,0 +1,46 @@ +/* PokemonLZA AutoStory - Autosave detector + * + * From: https://github.com/PokemonAutomation/ + * + * The autosave badge, a pencil and "Saving...", which shows for 1-3 s + * after the game autosaves. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryAutosaveDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryAutosaveDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The autosave badge at the top right: a white pencil with a cyan glow at +// x 1603-1630, y 73-104 on 1920x1080, and nothing white or cyan just left +// of it, above it or below it. Only the icon is read, so any language +// matches. +class AutosaveDetector : public StaticScreenDetector{ +public: + explicit AutosaveDetector(Color color = COLOR_YELLOW); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + ImageFloatBox m_icon; + ImageFloatBox m_left; + ImageFloatBox m_above; + ImageFloatBox m_below; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.cpp new file mode 100644 index 0000000000..d1b545c486 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.cpp @@ -0,0 +1,58 @@ +/* PokemonLZA AutoStory - Controls hint detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryControlsHintDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Measured on 1920x1080 (console B, 2026-11-10): the card at x 946-971, +// y 868-901 with its spine at x 974-976; the "?" at x 953-965, y 876-894. +ControlsHintDetector::ControlsHintDetector(Color color) + : m_color(color) + , m_card(947.0 / 1920, 872.0 / 1080, 24.0 / 1920, 28.0 / 1080) + , m_glyph(955.0 / 1920, 879.0 / 1080, 8.0 / 1920, 7.0 / 1080) + , m_around{ + {928.0 / 1920, 872.0 / 1080, 14.0 / 1920, 28.0 / 1080}, + {980.0 / 1920, 872.0 / 1080, 14.0 / 1920, 28.0 / 1080}, + {945.0 / 1920, 856.0 / 1080, 30.0 / 1920, 8.0 / 1080}, + {945.0 / 1920, 906.0 / 1080, 30.0 / 1920, 8.0 / 1080}, + } +{} + +void ControlsHintDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_card); + for (const ImageFloatBox& box : m_around){ + items.add(m_color, box); + } +} + +// The hint's 13 frames (01.01 run 0001-0006, the user's u132-u138): the +// card 88%+ sky blue, the "?" at most 48%, nothing around it. Of the 376 +// frames without it, the closest are the 01.01 run's 0056 (the sky +// behind the girl: card 76%, "?" 100%, around 54%), 0060 (card 35%, +// around 27%) and the user's u126 (card 22%, around 32%). +bool ControlsHintDetector::detect(const ImageViewRGB32& screen){ + if (sky_blue_share(screen, m_card) < 0.80 || sky_blue_share(screen, m_glyph) > 0.70){ + return false; + } + for (const ImageFloatBox& box : m_around){ + if (sky_blue_share(screen, box) > 0.10){ + return false; + } + } + return true; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h new file mode 100644 index 0000000000..5dfe675d07 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h @@ -0,0 +1,47 @@ +/* PokemonLZA AutoStory - Controls hint detector + * + * From: https://github.com/PokemonAutomation/ + * + * The tutorial's controls hint under the player, a "?" card over + * "(L) Move" and "(R) Control Camera", which shows for ~10 s when the + * player gets control. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryControlsHintDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryControlsHintDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The controls hint the tutorial shows under the player when they get +// control: its "?" card, sky blue with a dark "?", at x 947-971, y 872-900 +// on 1920x1080, centred, with no sky blue around it. Only the card is +// read: the rows under it ("(L) Move", "(R) Control Camera") are centred +// too, so their icons move with the text's length. +class ControlsHintDetector : public StaticScreenDetector{ +public: + explicit ControlsHintDetector(Color color = COLOR_BLUE); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + ImageFloatBox m_card; + ImageFloatBox m_glyph; + ImageFloatBox m_around[4]; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif 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 new file mode 100644 index 0000000000..9a74171631 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp @@ -0,0 +1,542 @@ +/* PokemonLZA AutoStory - Detectors Tests + * + * From: https://github.com/PokemonAutomation/ + * + * Synthetic frames always. The opening's frames are not in + * CommandLineTests yet; each set runs when its folder is in the + * environment and is skipped otherwise (console B, 1920x1080): + * - PLZA_OPENING_FRAMES: platform_ref.png and the lab's cutscene, + * 0001-*.png ... 0056-*.png; + * - PLZA_USER_OPENING_FRAMES: the user's run, rec1_u001.png ... + * rec1_u146.png, one per ~1.5 s, with the autosave badge (in Chinese); + * - PLZA_0101_RUN1_FRAMES: 01.01's first run (2026-11-10 13:00, in + * Chinese), 0001-*.png ... 0089-*.png: the platform with the controls + * hint, the walk to the plaza and the arrival scenes; + * - PLZA_0101_RUN2_FRAMES: 01.01's second run (2026-11-10 13:28, in + * Chinese), 0001-*.png ... 0115-*.png: the same, on to the ad's + * subtitles (0090-0115), where the run stopped; + * - PLZA_0101_RUN3_FRAMES: 01.01's third run (2026-11-10 13:49, in + * Chinese), 0001-*.png ... 0181-*.png: the same, through the ad and + * Pancham taking the bag, to the "MAIN MISSION 01" banner (0181); + * - PLZA_0101_RUN4_FRAMES: 01.01's fourth run (2026-11-10, in Chinese), + * 0001-*.png ... 0221-*.png, the "MAIN MISSION 01" banner on + * 0181-0189; + * - PLZA_0103_RUN2_FRAMES: 01.03's second run (2026-11-10, in Chinese), + * 0001-*.png ... 0139-*.png and mission01-complete-fullres.png: the + * "MAIN MISSION 01 COMPLETE" card (0045, 0046, the full-res frame), + * the "MAIN MISSION 02" banner (0133-0139). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "PokemonLZA_AutoStoryAdvanceArrowDetector.h" +#include "PokemonLZA_AutoStoryAutosaveDetector.h" +#include "PokemonLZA_AutoStoryControlsHintDetector.h" +#include "PokemonLZA_AutoStoryDetectors_Tests.h" +#include "PokemonLZA_AutoStoryMainMissionBannerDetector.h" +#include "PokemonLZA_AutoStoryMissionCompleteDetector.h" +#include "PokemonLZA_AutoStoryPlatformArrivalDetector.h" +#include "PokemonLZA_AutoStorySkipPromptDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +namespace{ + +constexpr size_t WIDTH = 1920; +constexpr size_t HEIGHT = 1080; + +void fill_box(size_t min_x, size_t min_y, size_t max_x, size_t max_y, uint32_t color, ImageRGB32& image){ + for (size_t y = min_y; y < max_y; y++){ + for (size_t x = min_x; x < max_x; x++){ + image.pixel(x, y) = color; + } + } +} + +// The skip badge drawn on black: the white icon, white text strokes (one +// column in four), the dark strip under them. +ImageRGB32 skip_badge_frame(){ + ImageRGB32 image(WIDTH, HEIGHT); + image.fill(0xff000000); + fill_box(1500, 100, 1920, 175, 0xff2c2c30, image); + fill_box(1564, 128, 1586, 150, 0xffffffff, image); + for (size_t x = 1630; x < 1875; x += 4){ + fill_box(x, 124, x + 1, 156, 0xffffffff, image); + } + return image; +} + +// The controls hint's card drawn on black: sky blue with a dark block for +// the top of its "?". +ImageRGB32 controls_hint_frame(){ + ImageRGB32 image(WIDTH, HEIGHT); + image.fill(0xff000000); + fill_box(946, 868, 972, 902, 0xff7dd2fa, image); + fill_box(956, 879, 962, 886, 0xff1c7db0, image); + return image; +} + +UnitTestResult test_synthetic_platform(Logger& logger){ + const ImageRGB32 reference = platform_reference_image(WIDTH, HEIGHT); + const PlatformDistances same = platform_distances(reference); + logger.log(std::format("reference: {}", to_string(same))); + if (!platform_matches(same) || same.top > 1 || same.left > 1 || same.right > 1){ + return std::format("Expected the reference's own cells to match at about 0: {}", to_string(same)); + } + ImageRGB32 gray(WIDTH, HEIGHT); + gray.fill(0xff808080); + const PlatformDistances other = platform_distances(gray); + if (platform_matches(other)){ + return std::format("Expected a gray frame not to be the platform: {}", to_string(other)); + } + // The player's area (x 780-1200, y 330-1080) is in no region. + ImageRGB32 with_player = reference.copy(); + fill_box(780, 330, 1200, HEIGHT, 0xffffffff, with_player); + if (!platform_matches(platform_distances(with_player))){ + return "Expected the player's area not to count."; + } + return true; +} + +// The advance chevron drawn in `ink` on `background`: a V 32x19 at +// x 1400, y 1004, each arm 18% of the width across. +ImageRGB32 chevron_frame(uint32_t background, uint32_t ink){ + ImageRGB32 image(WIDTH, HEIGHT); + image.fill(background); + for (size_t y = 0; y < 19; y++){ + const double v = (double(y) + 0.5) / 19; + for (size_t x = 0; x < 32; x++){ + const double u = (double(x) + 0.5) / 32; + if (std::abs(std::abs(u - 0.5) - (0.40 * (1 - v) + 0.03)) <= 0.09){ + image.pixel(1400 + x, 1004 + y) = ink; + } + } + } + return image; +} + +// The chevron white on the ad's light blue and dark on a white box; not a +// plain white or black frame, nor a solid block the chevron's size. +UnitTestResult test_synthetic_arrow(Logger&){ + AdvanceArrowDetector arrow; + if (!arrow.detect(chevron_frame(0xffc1ecf0, 0xffffffff)) || !arrow.detect(chevron_frame(0xfffcfcf7, 0xff323648))){ + return "Expected the drawn chevrons to be the advance arrow."; + } + ImageRGB32 block(WIDTH, HEIGHT); + block.fill(0xffc1ecf0); + fill_box(1400, 1004, 1432, 1023, 0xffffffff, block); + ImageRGB32 white(WIDTH, HEIGHT); + white.fill(0xffffffff); + ImageRGB32 black(WIDTH, HEIGHT); + black.fill(0xff000000); + if (arrow.detect(block) || arrow.detect(white) || arrow.detect(black)){ + return "Expected a white block, a white or a black frame not to be the advance arrow."; + } + return true; +} + +UnitTestResult test_synthetic_badges(Logger&){ + SkipPromptDetector detector; + if (!detector.detect(skip_badge_frame())){ + return "Expected the drawn badge to be the skip prompt."; + } + ImageRGB32 white(WIDTH, HEIGHT); + white.fill(0xffffffff); + ImageRGB32 black(WIDTH, HEIGHT); + black.fill(0xff000000); + if (detector.detect(white) || detector.detect(black)){ + return "Expected a white or black frame not to be the skip prompt."; + } + AutosaveDetector autosave; + if (autosave.detect(white) || autosave.detect(black) || autosave.detect(skip_badge_frame())){ + return "Expected a white, black or skip-badge frame not to be the autosave badge."; + } + ControlsHintDetector hint; + if (!hint.detect(controls_hint_frame()) || hint.detect(white) || hint.detect(black)){ + return "Expected the drawn card, and no white or black frame, to be the controls hint."; + } + ImageRGB32 sky(WIDTH, HEIGHT); + sky.fill(0xff7dd2fa); + if (hint.detect(sky)){ + return "Expected a frame all in the card's blue (a sky) not to be the controls hint."; + } + return true; +} + +// The mission banner drawn on a grey scene: the yellow bar, and the +// icon's white hexagon (as a block) with the orange stroke, `dx` right of +// run 3's; with `icon` false, the bar alone. +ImageRGB32 mission_banner_frame(size_t dx, bool icon){ + ImageRGB32 image(WIDTH, HEIGHT); + image.fill(0xff606060); + fill_box(345, 410, 1590, 600, 0xfffad228, image); + if (icon){ + fill_box(700 + dx, 327, 738 + dx, 370, 0xffffffff, image); + fill_box(716 + dx, 336, 720 + dx, 357, 0xfff07020, image); + } + return image; +} + +// The banner at run 3's place and 40 px right; not the bar without the +// icon, a frame all in the bar's yellow, or a white frame. +UnitTestResult test_synthetic_mission_banner(Logger&){ + MainMissionBannerDetector banner; + if (!banner.detect(mission_banner_frame(0, true)) || !banner.detect(mission_banner_frame(40, true))){ + return "Expected the drawn banners to be the mission banner."; + } + ImageRGB32 yellow(WIDTH, HEIGHT); + yellow.fill(0xfffad228); + ImageRGB32 white(WIDTH, HEIGHT); + white.fill(0xffffffff); + if (banner.detect(mission_banner_frame(0, false)) || banner.detect(yellow) || banner.detect(white)){ + return "Expected a bar without the icon, a yellow or a white frame not to be the mission banner."; + } + return true; +} + +// The mission complete card drawn on a grey scene: the yellow bar, and +// "COMPLETE" as green strokes (three columns in four) above it. +ImageRGB32 mission_complete_frame(){ + ImageRGB32 image(WIDTH, HEIGHT); + image.fill(0xff606060); + fill_box(345, 390, 1590, 585, 0xfffad228, image); + for (size_t x = 615; x < 1300; x += 4){ + fill_box(x, 275, x + 3, 345, 0xffa5f07d, image); + } + return image; +} + +// The drawn card, not the banner; the drawn banner, a frame all in the +// card's green or the bar's yellow, not the card. +UnitTestResult test_synthetic_mission_complete(Logger&){ + MissionCompleteDetector complete; + MainMissionBannerDetector banner; + const ImageRGB32 card = mission_complete_frame(); + if (!complete.detect(card)){ + return "Expected the drawn card to be the mission complete card."; + } + if (banner.detect(card)){ + return "Expected the drawn card not to be the mission banner."; + } + ImageRGB32 green(WIDTH, HEIGHT); + green.fill(0xffa5f07d); + ImageRGB32 yellow(WIDTH, HEIGHT); + yellow.fill(0xfffad228); + if (complete.detect(mission_banner_frame(0, true)) || complete.detect(green) || complete.detect(yellow)){ + return "Expected the banner, a green or a yellow frame not to be the mission complete card."; + } + return true; +} + +// What a frame should show. +struct FrameExpectation{ + bool platform; + bool skip_prompt; + bool autosave; + bool controls_hint; + bool advance_arrow; + bool mission_banner = false; + bool mission_complete = false; +}; + +// The lab's opening: platform_ref.png is the platform, no cutscene frame +// 0001-0056 is; only 0050 shows the skip prompt. The platform reference +// was taken after the controls hint had gone. +std::optional lab_opening(const std::string& name){ + return FrameExpectation{ + .platform = name == "platform_ref.png", .skip_prompt = name.starts_with("0050-"), + .autosave = false, .controls_hint = false, .advance_arrow = false, + }; +} + +// The user's run rec1_u001-u146: the platform settles at u131 (u124-u130 +// are the fade in and the camera moving in; u128 already passes, top 77 +// under 90, as the platform it shows), the autosave badge shows on +// u132 only, the controls hint on u132-u138 (~10 s), no skip prompt. The +// train's blue box has its advance chevron on u116-u122. +// Later frames of the folder are not in the set. +std::optional user_opening(const std::string& name){ + const int index = std::stoi(name.substr(6, 3)); + if (index > 146){ + return std::nullopt; + } + return FrameExpectation{ + .platform = index == 128 || index >= 131, .skip_prompt = false, + .autosave = index == 132, .controls_hint = index >= 132 && index <= 138, + .advance_arrow = index >= 116 && index <= 122, + }; +} + +// 01.01's first run: the platform (0001-0003, as the run read it) and the +// walk with the controls hint (0001-0006; it is gone by 0007), then the +// white fade, the title card, the text-free flyover, the starters and the +// girl, the tourist choice (0065) and the ad (0080-0089): no free control. +// No autosave: the run took flyover frames 0033 and 0038 for one. The +// advance chevron on the one box with its text done, 0040. +std::optional run1_arrival(const std::string& name){ + const int index = std::stoi(name.substr(0, 4)); + return FrameExpectation{ + .platform = name.find("+platform") != std::string::npos, .skip_prompt = false, + .autosave = false, .controls_hint = index <= 6, .advance_arrow = index == 40, + }; +} + +// 01.01's second run: as the first, with the hint on 0001-0006, on to the +// ad (the logo 0088-0089, the president's subtitles 0090-0115). The +// advance chevron on the boxes with their text done (0044, 0049, 0053, +// 0078) and on the ad's subtitles once typed (0093-0115). +std::optional run2_arrival(const std::string& name){ + const int index = std::stoi(name.substr(0, 4)); + const bool box_arrow = index == 44 || index == 49 || index == 53 || index == 78; + return FrameExpectation{ + .platform = name.find("+platform") != std::string::npos, .skip_prompt = false, + .autosave = false, .controls_hint = index <= 6, + .advance_arrow = box_arrow || (index >= 93 && index <= 115), + }; +} + +// 01.01's third run: as the second, on through the ad and the bag scene. +// The platform, the controls hint and the advance chevron as the run read +// them (in each frame's name; checked by eye on the hint and the chevrons +// through 0115 in run 2); the mission banner on 0181 only, the last frame. +std::optional run3_arrival(const std::string& name){ + const int index = std::stoi(name.substr(0, 4)); + return FrameExpectation{ + .platform = name.find("+platform") != std::string::npos, .skip_prompt = false, + .autosave = false, .controls_hint = name.find("+controls_hint") != std::string::npos, + .advance_arrow = name.find("+advance_arrow") != std::string::npos, + .mission_banner = index == 181, + }; +} + +// A frame as a run read it, by its name ("0133-nothing+mission_banner.png"). +FrameExpectation as_named(const std::string& name){ + const auto has = [&name](std::string_view reading){ + return name.find(reading) != std::string::npos; + }; + return FrameExpectation{ + .platform = has("+platform"), .skip_prompt = has("+skip_prompt"), + .autosave = has("+autosave"), .controls_hint = has("+controls_hint"), + .advance_arrow = has("+advance_arrow"), .mission_banner = has("+mission_banner"), + }; +} + +// 01.01's fourth run: every detector as the run read it; the banner on +// 0181-0189 (checked by eye), no complete card. +std::optional run4_arrival(const std::string& name){ + return as_named(name); +} + +// 01.03's second run: as the run read it, and the complete card on 0045, +// 0046 (named "nothing": the run had no detector for it) and the full-res +// frame; the "MAIN MISSION 02" banner on 0133-0139 is not the card. +std::optional run_0103_2(const std::string& name){ + FrameExpectation want = as_named(name); + want.mission_complete = name.starts_with("0045-") || name.starts_with("0046-") || + name == "mission01-complete-fullres.png"; + return want; +} + +// The opening's detectors, one of each. +struct OpeningDetectors{ + PlatformArrivalDetector platform; + SkipPromptDetector skip; + AutosaveDetector autosave; + ControlsHintDetector hint; + AdvanceArrowDetector arrow; + MainMissionBannerDetector banner; + MissionCompleteDetector complete; + + FrameExpectation read(const ImageRGB32& frame){ + return FrameExpectation{ + .platform = platform.detect(frame), .skip_prompt = skip.detect(frame), + .autosave = autosave.detect(frame), .controls_hint = hint.detect(frame), + .advance_arrow = arrow.detect(frame), .mission_banner = banner.detect(frame), + .mission_complete = complete.detect(frame), + }; + } +}; + +bool same_reads(const FrameExpectation& got, const FrameExpectation& want){ + return got.platform == want.platform && got.skip_prompt == want.skip_prompt && + got.autosave == want.autosave && got.controls_hint == want.controls_hint && + got.advance_arrow == want.advance_arrow && got.mission_banner == want.mission_banner && + got.mission_complete == want.mission_complete; +} + +// The frames `prefix`*.png in `folder` that `expect` has an expectation +// for, against it; logs each one. +UnitTestResult check_frames( + Logger& logger, const std::string& folder, const std::string& prefix, + size_t count, const std::function(const std::string&)>& expect +){ + OpeningDetectors detectors; + size_t frames = 0; + std::string failures; + for (const Filesystem::Path& path : Filesystem::list_directory(Filesystem::Path(folder))){ + const std::string name = path.filename().string(); + const std::optional want = + name.starts_with(prefix) && name.ends_with(".png") ? expect(name) : std::nullopt; + if (!want){ + continue; + } + const ImageRGB32 frame(path.string()); + const FrameExpectation got = detectors.read(frame); + logger.log(std::format("{}: {}{}{}{}{}{}{}{}", name, to_string(detectors.platform.last_distances()), + got.platform ? ", platform" : "", got.skip_prompt ? ", skip prompt" : "", + got.autosave ? ", autosave" : "", got.controls_hint ? ", controls hint" : "", + got.advance_arrow ? ", advance arrow" : "", got.mission_banner ? ", mission banner" : "", + got.mission_complete ? ", mission complete" : "")); + if (!same_reads(got, *want)){ + failures += std::format(" {}", name); + } + frames++; + } + if (frames != count){ + return std::format("Expected {} frames in {}, found {}.", count, folder, frames); + } + if (!failures.empty()){ + return std::format("Wrong on:{}", failures); + } + return true; +} + +// The folder in the environment variable `variable`; none when unset. +std::string frames_folder(std::string_view variable){ + const auto* folder = std::getenv(std::string(variable).c_str()); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return ""; + } + return folder; +} + +UnitTestResult test_lab_opening_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_OPENING_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_OPENING_FRAMES is not a folder."); + } + // 0001-0056 and platform_ref.png. + return check_frames(logger, folder, "", 57, lab_opening); +} + +UnitTestResult test_user_opening_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_USER_OPENING_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_USER_OPENING_FRAMES is not a folder."); + } + return check_frames(logger, folder, "rec1_u", 146, user_opening); +} + +UnitTestResult test_run1_arrival_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_0101_RUN1_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_0101_RUN1_FRAMES is not a folder."); + } + return check_frames(logger, folder, "00", 89, run1_arrival); +} + +UnitTestResult test_run2_arrival_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_0101_RUN2_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_0101_RUN2_FRAMES is not a folder."); + } + return check_frames(logger, folder, "0", 115, run2_arrival); +} + +UnitTestResult test_run3_arrival_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_0101_RUN3_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_0101_RUN3_FRAMES is not a folder."); + } + return check_frames(logger, folder, "0", 181, run3_arrival); +} + +UnitTestResult test_run4_arrival_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_0101_RUN4_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_0101_RUN4_FRAMES is not a folder."); + } + return check_frames(logger, folder, "0", 221, run4_arrival); +} + +UnitTestResult test_0103_run2_frames(Logger& logger){ + const std::string folder = frames_folder("PLZA_0103_RUN2_FRAMES"); + if (folder.empty()){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_0103_RUN2_FRAMES is not a folder."); + } + // 0001-0139 and mission01-complete-fullres.png. + return check_frames(logger, folder, "", 140, run_0103_2); +} + + +struct OpeningTestInput{ + std::string name; + std::function body; +}; + +struct OpeningTestExpectation{ +}; + +struct OpeningTestCase{ + OpeningTestInput input; + OpeningTestExpectation expectation; +}; + +class Test_AutoStoryOpeningDetectors : public UnitTest{ +public: + explicit Test_AutoStoryOpeningDetectors(OpeningTestCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStoryDetectors - {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + return m_case.input.body(logger); + } + +private: + OpeningTestCase m_case; +}; + +} // namespace + + +const OpeningTestCase OPENING_TEST_CASES[] = { + {.input = {"platform: synthetic frames", test_synthetic_platform}, .expectation = {}}, + {.input = {"skip prompt, autosave and controls hint: synthetic frames", test_synthetic_badges}, .expectation = {}}, + {.input = {"advance arrow: synthetic frames", test_synthetic_arrow}, .expectation = {}}, + {.input = {"mission banner: synthetic frames", test_synthetic_mission_banner}, .expectation = {}}, + {.input = {"mission complete card: synthetic frames", test_synthetic_mission_complete}, .expectation = {}}, + {.input = {"the lab's opening frames (PLZA_OPENING_FRAMES)", test_lab_opening_frames}, .expectation = {}}, + {.input = {"the user's opening frames (PLZA_USER_OPENING_FRAMES)", test_user_opening_frames}, .expectation = {}}, + {.input = {"01.01 run 1's arrival frames (PLZA_0101_RUN1_FRAMES)", test_run1_arrival_frames}, .expectation = {}}, + {.input = {"01.01 run 2's arrival frames to the ad (PLZA_0101_RUN2_FRAMES)", test_run2_arrival_frames}, .expectation = {}}, + {.input = {"01.01 run 3's arrival frames to the mission banner (PLZA_0101_RUN3_FRAMES)", test_run3_arrival_frames}, .expectation = {}}, + {.input = {"01.01 run 4's arrival frames to the mission banner (PLZA_0101_RUN4_FRAMES)", test_run4_arrival_frames}, .expectation = {}}, + {.input = {"01.03 run 2's frames: the mission complete card and the MM02 banner (PLZA_0103_RUN2_FRAMES)", test_0103_run2_frames}, .expectation = {}}, +}; + +void add_tests_AutoStoryDetectors(UnitTestDatabase& database){ + for (const OpeningTestCase& item : OPENING_TEST_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h new file mode 100644 index 0000000000..3bae55b920 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h @@ -0,0 +1,28 @@ +/* PokemonLZA AutoStory - Detectors Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryDetectors_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryDetectors_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the tests of the AutoStory detectors (Detectors/): synthetic +// frames always; the opening's frames from the folders in +// PLZA_OPENING_FRAMES and PLZA_USER_OPENING_FRAMES, and the runs' frames +// from PLZA_0101_RUN1_FRAMES and the others, each skipped when unset. +void add_tests_AutoStoryDetectors(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.cpp new file mode 100644 index 0000000000..d855d6fe50 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.cpp @@ -0,0 +1,77 @@ +/* PokemonLZA AutoStory - Main mission banner detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryMainMissionBannerDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Measured on 1920x1080 (console B, 2026-11-10, 01.01 run 3's 0181): the +// bar's yellow fills x 430-820 and x 1100-1500 at y 425-585 (left and +// right of the name), none of it 15 px above or below the bar; the icon's +// hexagon is white at x 700-710 and 724-734, y 337-358, with the "!"'s +// orange stroke at x 716-719 between them. +MainMissionBannerDetector::MainMissionBannerDetector(Color color) + : m_color(color) + , m_bar_left(430.0 / 1920, 425.0 / 1080, 390.0 / 1920, 160.0 / 1080) + , m_bar_right(1100.0 / 1920, 425.0 / 1080, 400.0 / 1920, 160.0 / 1080) + , m_above(430.0 / 1920, 375.0 / 1080, 1070.0 / 1920, 25.0 / 1080) + , m_below(430.0 / 1920, 615.0 / 1080, 1070.0 / 1920, 25.0 / 1080) + , m_icon_left(700.0 / 1920, 337.0 / 1080, 10.0 / 1920, 21.0 / 1080) + , m_icon_right(724.0 / 1920, 337.0 / 1080, 10.0 / 1920, 21.0 / 1080) + , m_icon_stroke(716.0 / 1920, 337.0 / 1080, 3.0 / 1920, 11.0 / 1080) +{} + +void MainMissionBannerDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_bar_left); + items.add(m_color, m_bar_right); + items.add(m_color, m_above); + items.add(m_color, m_below); + items.add(m_color, m_icon_left); + items.add(m_color, m_icon_right); + items.add(m_color, m_icon_stroke); +} + +// Measured on 01.01's runs 1-3, the lab's and the user's opening frames +// and the other PLZA lab captures (746 frames, console B, 2026-11-10): +// the banner's one frame (run 3's 0181) has both bar boxes 100% yellow, +// the strips around it 0-1%, and the icon's three boxes 100% at dx 0. The +// closest others: the bar boxes 8% at most, the icon's weakest box 27% at +// most (run 2's 0032, the flyover). The icon is looked for 60 px either side, as a longer +// or shorter header moves it. +bool MainMissionBannerDetector::detect(const ImageViewRGB32& screen){ + if (banner_yellow_share(screen, m_bar_left) < 0.6 || banner_yellow_share(screen, m_bar_right) < 0.6){ + return false; + } + if (banner_yellow_share(screen, m_above) > 0.3 || banner_yellow_share(screen, m_below) > 0.3){ + return false; + } + const auto bright = [](Color pixel){ + return pixel.red() > 225 && pixel.green() > 225 && pixel.blue() > 225; + }; + const auto orange = [](Color pixel){ + return pixel.red() > 200 && pixel.blue() < 150; + }; + for (double dx = -60; dx <= 60; dx += 2){ + if (share_of(screen, shifted(m_icon_left, dx), bright) >= 0.7 && + share_of(screen, shifted(m_icon_right, dx), bright) >= 0.7 && + share_of(screen, shifted(m_icon_stroke, dx), orange) >= 0.7 + ){ + return true; + } + } + return false; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h new file mode 100644 index 0000000000..17bc5d634c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h @@ -0,0 +1,52 @@ +/* PokemonLZA AutoStory - Main mission banner detector + * + * From: https://github.com/PokemonAutomation/ + * + * The "MAIN MISSION 01" banner across the middle when a main mission + * starts. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryMainMissionBannerDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryMainMissionBannerDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The banner a main mission starts with: a see-through yellow bar at +// x 345-1590, y 410-600 on 1920x1080 with the mission's name in the +// middle, and above it, left of "MAIN MISSION 01", a white hexagon with +// an orange "!" at about x 700-738, y 327-370. The bar is read left and +// right of the name, with no yellow just above or below it, and the icon +// is looked for along the header (the header's text is centred). Text is +// not read, so any language matches. +class MainMissionBannerDetector : public StaticScreenDetector{ +public: + explicit MainMissionBannerDetector(Color color = COLOR_ORANGE); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + ImageFloatBox m_bar_left; + ImageFloatBox m_bar_right; + ImageFloatBox m_above; + ImageFloatBox m_below; + ImageFloatBox m_icon_left; + ImageFloatBox m_icon_right; + ImageFloatBox m_icon_stroke; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.cpp new file mode 100644 index 0000000000..85d58c7d82 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.cpp @@ -0,0 +1,58 @@ +/* PokemonLZA AutoStory - Mission complete detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStoryMissionCompleteDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Measured on 1920x1080 (console B, 2026-11-10, 01.03 run 2's +// mission01-complete-fullres.png): the word's green fills x 615-1300, +// y 271-349, none of it 20 px above or below; the bar's yellow fills +// y 390-585, read left and right of the name as for the banner. +MissionCompleteDetector::MissionCompleteDetector(Color color) + : m_color(color) + , m_word(640.0 / 1920, 285.0 / 1080, 640.0 / 1920, 55.0 / 1080) + , m_above(620.0 / 1920, 245.0 / 1080, 680.0 / 1920, 20.0 / 1080) + , m_below(620.0 / 1920, 358.0 / 1080, 680.0 / 1920, 20.0 / 1080) + , m_bar_left(430.0 / 1920, 440.0 / 1080, 390.0 / 1920, 140.0 / 1080) + , m_bar_right(1100.0 / 1920, 440.0 / 1080, 400.0 / 1920, 140.0 / 1080) +{} + +void MissionCompleteDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_word); + items.add(m_color, m_above); + items.add(m_color, m_below); + items.add(m_color, m_bar_left); + items.add(m_color, m_bar_right); +} + +// Measured on every PLZA lab capture (1109 frames, console B, 2026-11-10): +// the card's three frames (01.03 run 2's 0045, 0046 and the full-res +// one) have the word 70% green, nothing green around it and both bar +// boxes 100% yellow. The closest others: the word 11% green at most +// (plza-platform's boxes.png, no bar), and with the bar, the mission +// banners (01.01 run 3's 0181, run 4's 0182-0189, 01.03 run 2's +// 0133-0139) at 2% at most. +bool MissionCompleteDetector::detect(const ImageViewRGB32& screen){ + if (complete_green_share(screen, m_word) < 0.40){ + return false; + } + if (complete_green_share(screen, m_above) > 0.10 || complete_green_share(screen, m_below) > 0.10){ + return false; + } + return banner_yellow_share(screen, m_bar_left) >= 0.6 && banner_yellow_share(screen, m_bar_right) >= 0.6; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h new file mode 100644 index 0000000000..e337d5ff41 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h @@ -0,0 +1,49 @@ +/* PokemonLZA AutoStory - Mission complete detector + * + * From: https://github.com/PokemonAutomation/ + * + * The "COMPLETE" card when a main mission ends, which waits for A. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryMissionCompleteDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryMissionCompleteDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The card a main mission ends with, which waits for A: a big green +// "COMPLETE" at x 615-1300, y 271-349 on 1920x1080 over the mission's +// yellow bar (x 345-1590, y 390-585, "MAIN MISSION 01" and the mission's +// name), in a yellow hexagon with the mission's item. The word is read +// with nothing green just above or below it, and the bar left and right +// of the name. The word is the same in every language seen (the header +// stays English in Chinese), so its text is not read. +class MissionCompleteDetector : public StaticScreenDetector{ +public: + explicit MissionCompleteDetector(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_word; + ImageFloatBox m_above; + ImageFloatBox m_below; + ImageFloatBox m_bar_left; + ImageFloatBox m_bar_right; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp new file mode 100644 index 0000000000..38d41b598f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp @@ -0,0 +1,61 @@ +/* PokemonLZA AutoStory - Pixel shares + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryPixelShares.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +double cyan_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ + return share_of(screen, box, [](Color pixel){ + return pixel.blue() > pixel.red() + 50 && pixel.green() > pixel.red() + 30 && pixel.blue() > 120; + }); +} + +// The share of `box`'s pixels whose every channel is above 200. +double white_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ + return share_of(screen, box, [](Color pixel){ + return pixel.red() > 200 && pixel.green() > 200 && pixel.blue() > 200; + }); +} + +// The share of `box`'s pixels in the controls hint card's sky blue (about +// 125, 210, 250): blue over 200, green over 160, blue over red by 60. +double sky_blue_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ + return share_of(screen, box, [](Color pixel){ + return pixel.blue() > 200 && pixel.green() > 160 && pixel.blue() > pixel.red() + 60; + }); +} + +// The share of `box`'s pixels in the mission banner's yellow (about 250, +// 210, 40 over a scene): red over 200, green over 140, blue under 130, +// red over blue by 110. +double banner_yellow_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ + return share_of(screen, box, [](Color pixel){ + return pixel.red() > 200 && pixel.green() > 140 && pixel.blue() < 130 && + pixel.red() > pixel.blue() + 110; + }); +} + +// The share of `box`'s pixels in the mission complete card's green (about +// 165, 240, 125): green over 180, over red by 40 and over blue by 70. +double complete_green_share(const ImageViewRGB32& screen, const ImageFloatBox& box){ + return share_of(screen, box, [](Color pixel){ + return pixel.green() > 180 && pixel.green() > pixel.red() + 40 && pixel.green() > pixel.blue() + 70; + }); +} + +ImageFloatBox shifted(ImageFloatBox box, double dx){ + box.x += dx / 1920; + return box; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h new file mode 100644 index 0000000000..d31b670875 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h @@ -0,0 +1,72 @@ +/* PokemonLZA AutoStory - Pixel shares + * + * From: https://github.com/PokemonAutomation/ + * + * How much of a box's pixels are of a color: what the badge detectors + * (Detectors/) read. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryPixelShares_H +#define PokemonAutomation_PokemonLZA_AutoStoryPixelShares_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The share of `box`'s pixels that `matches` (a Color -> bool). +template +double share_of(const ImageViewRGB32& screen, const ImageFloatBox& box, Matches&& matches); + +// The share of `box`'s pixels that glow cyan: blue over red by 50, green +// over red by 30, blue over 120. +double cyan_share(const ImageViewRGB32& screen, const ImageFloatBox& box); + +// The share of `box`'s pixels whose every channel is above 200. +double white_share(const ImageViewRGB32& screen, const ImageFloatBox& box); + +// The share of `box`'s pixels in the controls hint card's sky blue (about +// 125, 210, 250): blue over 200, green over 160, blue over red by 60. +double sky_blue_share(const ImageViewRGB32& screen, const ImageFloatBox& box); + +// The share of `box`'s pixels in the mission banner's yellow (about 250, +// 210, 40 over a scene): red over 200, green over 140, blue under 130, +// red over blue by 110. +double banner_yellow_share(const ImageViewRGB32& screen, const ImageFloatBox& box); + +// The share of `box`'s pixels in the mission complete card's green (about +// 165, 240, 125): green over 180, over red by 40 and over blue by 70. +double complete_green_share(const ImageViewRGB32& screen, const ImageFloatBox& box); + +// `box` moved `dx` pixels (of 1920) right. +ImageFloatBox shifted(ImageFloatBox box, double dx); + + +template +double share_of(const ImageViewRGB32& screen, const ImageFloatBox& box, Matches&& matches){ + const ImageViewRGB32 area = extract_box_reference(screen, box); + const size_t total = area.width() * area.height(); + if (total == 0){ + return 0; + } + size_t count = 0; + for (size_t y = 0; y < area.height(); y++){ + for (size_t x = 0; x < area.width(); x++){ + if (matches(Color(area.pixel(x, y)))){ + count++; + } + } + } + return (double)count / (double)total; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.cpp new file mode 100644 index 0000000000..e89ae9892d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.cpp @@ -0,0 +1,204 @@ +/* PokemonLZA AutoStory - Opening detectors + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonArray.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPlatformArrivalDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// A region of the frame and the cells it is averaged into. On 1920x1080 +// (the user's design, 2026-11-10): the top band y 0-300 across; the left +// side x 0-640 and the right side x 1280-1920, both y 300-1080. The player +// (x 780-1200, y 330-1080) is in none of them. Each cell is 30x30 (top) or +// 40x39 pixels (sides). +struct PlatformRegion{ + std::string_view name; + ImageFloatBox box; + size_t cols; + size_t rows; +}; + +const PlatformRegion PLATFORM_REGIONS[] = { + {"top", {0.0, 0.0, 1.0, 300.0 / 1080}, 64, 10}, + {"left", {0.0, 300.0 / 1080, 640.0 / 1920, 780.0 / 1080}, 16, 20}, + {"right", {1280.0 / 1920, 300.0 / 1080, 640.0 / 1920, 780.0 / 1080}, 16, 20}, +}; + +// The bounds of platform_matches(), from the opening's frames (console B, +// 1920x1080: the platform reference and the 56 cutscene frames before +// it, measured with this code's cell averages): +// - the closest cutscene frame is 0056, the train's interior just before +// the platform: top 112.8, left 82.6, right 71.9; the next are the +// city flyovers 0022-0024 at top 134.7+, left 95.6+; +// - the reference against itself moved 16 px: top 42.2, left 20.8, +// right 21.2; 10% darker: top 24.6, left 19.9, right 16.4. +// - the platform after loading its autosave (camera turned a little, +// 2026-11-10): top 67.9-68.1, left 25.8-41.7, right 16.5-16.9. +// So the bounds sit between the loaded view and 0056: top 90 (23 below +// 0056), left 55 (27 below). The right side holds a walking NPC and the companion, so it only +// has to be roughly the platform (120: a menu or another place is 140+). +constexpr double PLATFORM_TOP_MAX = 90.0; +constexpr double PLATFORM_LEFT_MAX = 55.0; +constexpr double PLATFORM_RIGHT_MAX = 120.0; + +using Cells = std::vector; + +// `region` of `screen`, averaged into its cells, row by row. +Cells region_cells(const ImageViewRGB32& screen, const PlatformRegion& region){ + Cells cells; + cells.reserve(region.cols * region.rows); + const double cell_width = region.box.width / (double)region.cols; + const double cell_height = region.box.height / (double)region.rows; + for (size_t row = 0; row < region.rows; row++){ + for (size_t col = 0; col < region.cols; col++){ + const ImageFloatBox cell( + region.box.x + cell_width * (double)col, region.box.y + cell_height * (double)row, + cell_width, cell_height + ); + cells.push_back(image_stats(extract_box_reference(screen, cell)).average); + } + } + return cells; +} + +// "rrggbb" to its color. +FloatPixel hex_pixel(const std::string& hex, size_t offset){ + const auto channel = [&](size_t index){ + return (double)std::stoi(hex.substr(offset + index * 2, 2), nullptr, 16); + }; + return FloatPixel(channel(0), channel(1), channel(2)); +} + +// The reference's cells of `region` from ReferenceData/plza-platform.json: +// "regions": {: {"cols": n, "rows": ["rrggbb...", ...]}}. +Cells reference_cells(const JsonObject& regions, const PlatformRegion& region){ + const std::string source = "plza-platform.json"; + const JsonObject& entry = regions.get_object_throw(std::string(region.name), source); + const JsonArray& rows = entry.get_array_throw("rows", source); + if ((size_t)entry.get_integer_throw("cols", source) != region.cols || rows.size() != region.rows){ + throw ParseException(std::format("{}: region {} is not {}x{} cells.", source, region.name, region.cols, region.rows)); + } + Cells cells; + for (const JsonValue& row : rows){ + const std::string& hex = row.to_string_throw(source); + if (hex.size() != region.cols * 6){ + throw ParseException(std::format("{}: a row of region {} is not {} colors.", source, region.name, region.cols)); + } + for (size_t col = 0; col < region.cols; col++){ + cells.push_back(hex_pixel(hex, col * 6)); + } + } + return cells; +} + +// The reference's cells, per PLATFORM_REGIONS entry. +const std::vector& platform_reference(){ + static const std::vector reference = []{ + for (const auto& [name, text] : autostory_reference_json()){ + if (name != "plza-platform"){ + continue; + } + const JsonValue json = parse_json(text); + const JsonObject& regions = json.to_object_throw("plza-platform.json").get_object_throw("regions"); + std::vector cells; + for (const PlatformRegion& region : PLATFORM_REGIONS){ + cells.push_back(reference_cells(regions, region)); + } + return cells; + } + throw FileException(nullptr, PA_CURRENT_FUNCTION, "The platform reference is not built in.", "plza-platform.json"); + }(); + return reference; +} + +double cells_rmsd(const Cells& reference, const Cells& cells){ + double sum = 0; + for (size_t index = 0; index < cells.size(); index++){ + const double r = reference[index].r - cells[index].r; + const double g = reference[index].g - cells[index].g; + const double b = reference[index].b - cells[index].b; + sum += r * r + g * g + b * b; + } + return std::sqrt(sum / (double)cells.size()); +} + +} // namespace + + +PlatformDistances platform_distances(const ImageViewRGB32& screen){ + const std::vector& reference = platform_reference(); + double distance[3] = {}; + for (size_t index = 0; index < 3; index++){ + distance[index] = cells_rmsd(reference[index], region_cells(screen, PLATFORM_REGIONS[index])); + } + return PlatformDistances{.top = distance[0], .left = distance[1], .right = distance[2]}; +} + +bool platform_matches(const PlatformDistances& distances){ + return distances.top <= PLATFORM_TOP_MAX + && distances.left <= PLATFORM_LEFT_MAX + && distances.right <= PLATFORM_RIGHT_MAX; +} + +ImageRGB32 platform_reference_image(size_t width, size_t height){ + ImageRGB32 image(width, height); + image.fill(0xff000000); + const std::vector& reference = platform_reference(); + for (size_t index = 0; index < 3; index++){ + const PlatformRegion& region = PLATFORM_REGIONS[index]; + const ImagePixelBox box = floatbox_to_pixelbox(width, height, region.box); + for (size_t y = box.min_y; y < box.max_y; y++){ + for (size_t x = box.min_x; x < box.max_x; x++){ + const size_t col = (x - box.min_x) * region.cols / (box.max_x - box.min_x); + const size_t row = (y - box.min_y) * region.rows / (box.max_y - box.min_y); + const FloatPixel& cell = reference[index][row * region.cols + col]; + image.pixel(x, y) = (uint32_t)Color((uint8_t)std::lround(cell.r), (uint8_t)std::lround(cell.g), (uint8_t)std::lround(cell.b)); + } + } + } + return image; +} + +std::string to_string(const PlatformDistances& distances){ + return std::format("top {:.1f}, left {:.1f}, right {:.1f}", distances.top, distances.left, distances.right); +} + + +PlatformArrivalDetector::PlatformArrivalDetector(Color color) + : m_color(color) +{} + +void PlatformArrivalDetector::make_overlays(VideoOverlaySet& items) const{ + for (const PlatformRegion& region : PLATFORM_REGIONS){ + items.add(m_color, region.box); + } +} + +bool PlatformArrivalDetector::detect(const ImageViewRGB32& screen){ + m_last = platform_distances(screen); + return platform_matches(m_last); +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h new file mode 100644 index 0000000000..d8635ccc5e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h @@ -0,0 +1,83 @@ +/* PokemonLZA AutoStory - Platform arrival detector + * + * From: https://github.com/PokemonAutomation/ + * + * The station platform once the new game's opening cutscene ends and the + * player has control (PlatformArrivalDetector): the frame's top and sides + * against a reference of that first frame, with the player cropped out. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryPlatformArrivalDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryPlatformArrivalDetector_H + +#include +#include +#include +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The checked-in reference files, ReferenceData/*.json, built into the +// program (cmake/EmbedTextFiles.cmake): (name, text), by name. +// plza-platform holds the platform reference's cell colors per region. +const std::vector>& autostory_reference_json(); + + +// How far a frame's regions are from the platform reference: each region +// is averaged into cells, and the distance is the RMSD over its cells of +// the summed squared channel differences (0 = the same, at most 441). +struct PlatformDistances{ + double top; + double left; + double right; +}; + +// The regions of a frame against the platform reference. +PlatformDistances platform_distances(const ImageViewRGB32& screen); + +// Whether `distances` are the platform: top and left within their bounds, +// and the right side within a looser one (the companion and the NPCs there +// move). The bounds and the measurements behind them are in the .cpp. +bool platform_matches(const PlatformDistances& distances); + +// The reference as a `width` x `height` frame: each cell painted its +// color, the player's area black. A frame the detector sees as the +// platform, for tests. +ImageRGB32 platform_reference_image(size_t width, size_t height); + +// "top 12.3, left 4.5, right 30.1", for the log. +std::string to_string(const PlatformDistances& distances); + + +// The station platform with free control, right after the opening +// cutscene, at the default camera. +class PlatformArrivalDetector : public StaticScreenDetector{ +public: + explicit PlatformArrivalDetector(Color color = COLOR_CYAN); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + + // The distances of the last detect(). + const PlatformDistances& last_distances() const{ + return m_last; + } + +private: + Color m_color; + PlatformDistances m_last{.top = 0, .left = 0, .right = 0}; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.cpp new file mode 100644 index 0000000000..ac1ded93af --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.cpp @@ -0,0 +1,53 @@ +/* PokemonLZA AutoStory - Skip prompt detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "PokemonLZA_AutoStoryPixelShares.h" +#include "PokemonLZA_AutoStorySkipPromptDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The badge on 1920x1080 (frame 0050 of the opening): the white (+) icon +// at x 1564-1586, y 128-150; the text x 1630-1875, y 122-158; the strip +// under the text x 1640-1880, y 161-169. +SkipPromptDetector::SkipPromptDetector(Color color) + : m_color(color) + , m_icon(1564.0 / 1920, 128.0 / 1080, 22.0 / 1920, 22.0 / 1080) + , m_text(1630.0 / 1920, 122.0 / 1080, 245.0 / 1920, 36.0 / 1080) + , m_strip(1640.0 / 1920, 161.0 / 1080, 240.0 / 1920, 8.0 / 1080) +{} + +void SkipPromptDetector::make_overlays(VideoOverlaySet& items) const{ + items.add(m_color, m_icon); + items.add(m_color, m_text); + items.add(m_color, m_strip); +} + +// On frame 0050 the icon is 70% white, the text 24%, and the strip is +// dark and even (average 44, deviation 2). No other opening frame has the +// icon over 40% white with a dark strip: the brightest (0044, a white +// flash) has the icon at 38% and the strip at 220. +bool SkipPromptDetector::detect(const ImageViewRGB32& screen){ + if (white_share(screen, m_icon) < 0.40){ + return false; + } + const double text = white_share(screen, m_text); + if (text < 0.10 || text > 0.45){ + return false; + } + const ImageStats strip = image_stats(extract_box_reference(screen, m_strip)); + return strip.average.sum() < 3 * 100.0 && strip.stddev.sum() < 3 * 15.0; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h new file mode 100644 index 0000000000..78079b4a31 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h @@ -0,0 +1,43 @@ +/* PokemonLZA AutoStory - Skip prompt detector + * + * From: https://github.com/PokemonAutomation/ + * + * The opening cutscene's "(+) Hold button to skip" badge. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStorySkipPromptDetector_H +#define PokemonAutomation_PokemonLZA_AutoStorySkipPromptDetector_H + +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonTools/VisualDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The cutscene's "(+) Hold button to skip" badge at the top right: the +// white (+) icon, white text on the badge, and the badge's dark, even +// strip under the text. +class SkipPromptDetector : public StaticScreenDetector{ +public: + explicit SkipPromptDetector(Color color = COLOR_MAGENTA); + + virtual void make_overlays(VideoOverlaySet& items) const override; + virtual bool detect(const ImageViewRGB32& screen) override; + +private: + Color m_color; + ImageFloatBox m_icon; + ImageFloatBox m_text; + ImageFloatBox m_strip; +}; + + + +} // 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 new file mode 100644 index 0000000000..74c72bd708 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -0,0 +1,178 @@ +/* PokemonLZA AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "CommonFramework/Notifications/ProgramNotifications.h" +#include "CommonFramework/VideoPipeline/VideoOverlay.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "Pokemon/AutoStory/Pokemon_AutoStoryStats.h" +#include "Pokemon/AutoStory/Pokemon_AutoStorySelect.h" +#include "Pokemon/AutoStory/Pokemon_StoryLog.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" +#include "Pokemon/Options/Pokemon_GameLanguages.h" +#include "Pokemon/Pokemon_Strings.h" +#include "PokemonLZA_AutoStoryGame.h" +#include "PokemonLZA_AutoStoryStoryFiles.h" +#include "PokemonLZA_AutoStory.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace Pokemon; + + +AutoStory_Descriptor::AutoStory_Descriptor() + : SingleSwitchProgramDescriptor( + "PokemonLZA:AutoStory", + std::format("{} LZA", STRING_POKEMON), "Auto Story", + "Programs/PokemonLZA/AutoStory.html", + "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console.", + PanelQualityStanding::DEVELOPER, + ProgramControllerClass::StandardController_NoRestrictions, + FeedbackType::REQUIRED, + AllowCommandsWhenRunning::DISABLE_COMMANDS + ) +{} + +std::unique_ptr AutoStory_Descriptor::make_stats() const{ + return std::make_unique(); +} + + +namespace{ + +// The start and end dropdowns' entries. The options hold a reference to it. +const StringSelectDatabase& checkpoint_database(){ + static const StringSelectDatabase database = []{ + std::vector labels; + for (const StoryCheckpoint& row : story_checkpoints()){ + labels.push_back(story_checkpoint_label(row)); + } + return story_checkpoint_database(labels); + }(); + return database; +} + +} // namespace + + +AutoStory::AutoStory() + : RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) + , GO_HOME_WHEN_DONE(false) + , NOTIFICATIONS({ + &NOTIFICATION_PROGRAM_FINISH, + &NOTIFICATION_ERROR_RECOVERABLE, + &NOTIFICATION_ERROR_FATAL, + }) +{ + PA_ADD_OPTION(RUN); + PA_ADD_OPTION(BATTLE_AI); + PA_ADD_OPTION(GO_HOME_WHEN_DONE); + PA_ADD_OPTION(NOTIFICATIONS); +} + +namespace{ + +// Checkpoints after the first start from a save (01.01 from the platform +// autosave), so the run loads it first instead of assuming the game is +// already there. +void load_start_save( + ConsoleHandle& console, const StoryGame& game, StoryBackend& backend, + const std::vector& rows, size_t first +){ + if (first == 0){ + return; + } + const Outcome loaded = game.reload(backend); + if (!loaded.succeeded()){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format("AutoStory: could not load the save for {}: {}", rows[first].id, to_string(loaded)) + ); + } + console.log(std::format("AutoStory: loaded the save for {}.", rows[first].id)); +} + +// The story for this run: the built-in checkpoints, with those of +// story_dev_folder() in their place, read now so a run after an edit +// plays the edited walks. Logs each dev file it uses; a bad one fails the +// run. +StoryData load_run_story(ConsoleHandle& console){ + const std::string folder = story_dev_folder(); + try{ + StoryData data = load_story_data(read_story_dev_files(folder)); + for (const auto& [name, path] : data.dev_files){ + console.log(std::format("AutoStory: using dev checkpoint {} from {}", name, path)); + } + return data; + }catch (ParseException& e){ + throw UserSetupError(console, std::format("AutoStory: bad dev checkpoint in {}: {}", folder, e.message())); + } +} + +} // namespace + +void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + const StoryData story_data = load_run_story(env.console); + const std::vector& rows = story_data.checkpoints; + const size_t first = RUN.start_index(); + const size_t last = RUN.end_index(); + if (first > last || last >= rows.size()){ + throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); + } + require_player(env.console, context, BUTTON_L); + + StoryEnv story{.env = env, .context = context, .language = RUN.language(), .battle_ai = BATTLE_AI}; + PlzaConsoleBackend backend(story); + const StoryGame game = make_plza_story_game(story, story_data.autosaves); + StoryEngine engine(game, backend); + RunState state; + load_start_save(env.console, game, backend, rows, first); + + if (const std::optional verify = RUN.VERIFY.policy()){ + const VerifyReport report = engine.verify_checkpoint(rows[first], *verify, state); + if (!report.verified){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format( + "AutoStory verify: {} {}/{} passed, {} needed{}", report.checkpoint, report.passes, report.runs, + verify->passes_needed, report.failure.succeeded() ? std::string() : std::format(": {}", to_string(report.failure)) + ) + ); + } + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + return; + } + const std::span checkpoints(rows.data() + first, last - first + 1); + const SegmentReport report = engine.run_segment("plza", checkpoints, RUN.policy().attempts_per_checkpoint, state); + record_story_counts(report.story_counts(), env.current_stats()); + env.update_stats(); + if (!report.completed){ + throw OperationFailedException( + ErrorReportMode::NO_ERROR_REPORT, + std::format( + "AutoStory stopped at {} {}: {}", report.failed_checkpoint, report.failed_event, to_string(report.failure) + ) + ); + } + env.console.log(std::format("AutoStory: done through {}.", rows[last].id)); + send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); + GO_HOME_WHEN_DONE.run_end_of_program(context); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h new file mode 100644 index 0000000000..c7096ffad5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -0,0 +1,65 @@ +/* PokemonLZA AutoStory + * + * From: https://github.com/PokemonAutomation/ + * + * Plays Pokemon Legends: Z-A's main story: the story table + * (PokemonLZA_AutoStoryTable.h) run by the shared story engine + * (Pokemon/AutoStory), from the start checkpoint to the end one. + * + * For lab tuning: at each start, a checkpoint file in + * /AutoStoryDev/plza/ (story_dev_folder()), e.g. + * plza-02.01.plan.json, replaces the built-in one of the same name, so a + * walk's legs can be retimed without a rebuild. The log names each file + * used; a bad one fails the run. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStory_H +#define PokemonAutomation_PokemonLZA_AutoStory_H + +#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" +#include "Pokemon/Options/Pokemon_StoryRunOptions.h" +#include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Descriptor for the Pokemon Legends: Z-A AutoStory program. +class AutoStory_Descriptor : public SingleSwitchProgramDescriptor{ +public: + AutoStory_Descriptor(); + + virtual std::unique_ptr make_stats() const override; +}; + + +// Runs the story's checkpoints from the start one to the end one on the +// shared story engine. +class AutoStory : public SingleSwitchProgramInstance{ +public: + using Descriptor = AutoStory_Descriptor; + AutoStory(); + + virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; + +private: + // The start and end checkpoints, attempts, checks and language. + Pokemon::StoryRunOptions RUN; + BattleAIOption BATTLE_AI; + + GoHomeWhenDoneOption GO_HOME_WHEN_DONE; + EventNotificationsOption NOTIFICATIONS; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp new file mode 100644 index 0000000000..bbfbedd851 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp @@ -0,0 +1,236 @@ +/* PokemonLZA AutoStory - Story backend + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "CommonFramework/GlobalAutoPaths.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/PrettyPrint.h" +#include "Common/Cpp/Color.h" +#include "CommonFramework/ImageTools/ImageDiff.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h" +#include "PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using Pokemon::Direction; + + +namespace{ + +// Below this pixel RMSD two looks are the same screen. +constexpr double STILL_RMSD = 2.0; + +// `direction` as degrees clockwise of straight on. +double direction_degrees(Direction direction){ + switch (direction){ + case Direction::NORTH: + return 0; + case Direction::EAST: + return 90; + case Direction::SOUTH: + return 180; + case Direction::WEST: + return -90; + } + return 0; +} + +bool same_screen(const VideoSnapshot& a, const VideoSnapshot& b){ + if (!a || !b || a.frame->width() != b.frame->width() || a.frame->height() != b.frame->height()){ + return false; + } + return ImageMatch::pixel_RMSD(*a.frame, *b.frame) < STILL_RMSD; +} + +} // namespace + + +PlzaConsoleBackend::PlzaConsoleBackend(StoryEnv& env) + : m_env(env) +{} + +void PlzaConsoleBackend::press(Button button, Milliseconds hold, Milliseconds release){ + pbf_press_button(m_env.context, button, hold, release); +} + +void PlzaConsoleBackend::tap(Direction direction){ + story_turn(*this, direction_degrees(direction)); +} + +void PlzaConsoleBackend::hold(Direction direction, Milliseconds duration, Pokemon::StoryPace pace){ + stick(direction_degrees(direction), duration, 0ms, pace); +} + +void PlzaConsoleBackend::stick(double degrees, Milliseconds duration, Milliseconds release, Pokemon::StoryPace){ + const double radians = degrees * std::numbers::pi / 180.0; + pbf_move_left_joystick(m_env.context, {std::sin(radians), std::cos(radians)}, duration, release); +} + +void PlzaConsoleBackend::wait(Milliseconds duration){ + m_env.context.wait_for(duration); +} + +Pokemon::Observation PlzaConsoleBackend::observe(){ + m_env.context.wait_for_all_requests(); + VideoSnapshot frame = m_env.env.console.video().snapshot(); + Pokemon::Observation look; + if (frame){ + static_cast(look) = plza_observation(m_observer.read(*frame.frame)); + if (m_platform.detect(*frame.frame)){ + look.readings[std::string(PLATFORM_READING)] = 1; + } + if (m_skip_prompt.detect(*frame.frame)){ + look.readings[std::string(SKIP_PROMPT_READING)] = 1; + } + if (m_autosave.detect(*frame.frame)){ + look.readings[std::string(AUTOSAVE_READING)] = 1; + } + if (m_controls_hint.detect(*frame.frame)){ + look.readings[std::string(CONTROLS_HINT_READING)] = 1; + } + if (m_advance_arrow.detect(*frame.frame)){ + look.readings[std::string(ADVANCE_ARROW_READING)] = 1; + } + if (m_mission_complete.detect(*frame.frame)){ + look.readings[std::string(MISSION_COMPLETE_READING)] = 1; + }else if (m_mission_banner.detect(*frame.frame)){ + look.readings[std::string(MISSION_BANNER_READING)] = 1; + } + if (same_screen(m_previous, frame)){ + look.events.add(PokemonAutomation::ScreenEvent::STILL); + } + } + look.when = current_time(); + m_previous = frame; + look.frame = std::move(frame); + capture(look); + return look; +} + +namespace{ + +std::string events_text(const PokemonAutomation::ScreenEvents& events){ + using EngineEvent = PokemonAutomation::ScreenEvent; + const std::pair names[] = { + {EngineEvent::FADE_BLACK, "fade_black"}, + {EngineEvent::FADE_WHITE, "fade_white"}, + {EngineEvent::TEXT_BOX, "text_box"}, + {EngineEvent::BATTLE, "battle"}, + {EngineEvent::CAN_MOVE, "can_move"}, + {EngineEvent::STILL, "still"}, + {EngineEvent::CHOICE_BOX, "choice_box"}, + {EngineEvent::INTERACT_PROMPT, "interact_prompt"}, + }; + std::string text; + for (const auto& [event, name] : names){ + if (events.has(event)){ + text += text.empty() ? "" : "+"; + text += name; + } + } + return text.empty() ? std::string("nothing") : text; +} + +// The look's events and readings: "fade_black+still", +// "nothing+skip_prompt", "can_move+platform+autosave+controls_hint". +std::string look_text(const ScreenObservation& look){ + std::string text = events_text(look.events); + if (look.readings.contains(PLATFORM_READING)){ + text += "+platform"; + } + if (look.readings.contains(SKIP_PROMPT_READING)){ + text += "+skip_prompt"; + } + if (look.readings.contains(AUTOSAVE_READING)){ + text += "+autosave"; + } + if (look.readings.contains(CONTROLS_HINT_READING)){ + text += "+controls_hint"; + } + if (look.readings.contains(ADVANCE_ARROW_READING)){ + text += "+advance_arrow"; + } + if (look.readings.contains(MISSION_BANNER_READING)){ + text += "+mission_banner"; + } + if (look.readings.contains(MISSION_COMPLETE_READING)){ + text += "+mission_complete"; + } + return text; +} + +constexpr Milliseconds CAPTURE_EVERY(2000); + +} // namespace + +void PlzaConsoleBackend::capture(const Pokemon::Observation& look){ + if (!look.frame || !look.frame->frame){ + return; + } + const std::string text = look_text(look); + const bool changed = m_captured_text != text; + if (!changed && look.when - m_captured_at < CAPTURE_EVERY){ + return; + } + if (m_capture_folder.empty()){ + m_capture_folder = std::format("{}PLZA-capture/{}/", SCREENSHOTS_PATH(), now_to_filestring()); + Filesystem::create_directories(Filesystem::Path(m_capture_folder)); + } + m_captures++; + const std::string path = std::format("{}{:04}-{}.png", m_capture_folder, m_captures, text); + look.frame->frame->save(path); + m_env.env.console.log(std::format("[PLZA capture] {:04} {}{}, platform {}", m_captures, text, + changed ? " (changed)" : "", to_string(m_platform.last_distances()))); + m_captured_text = text; + m_captured_at = look.when; +} + +Pokemon::Outcome PlzaConsoleBackend::battle(const Pokemon::StoryActionArgs&){ + try{ + fight_battle(m_env.env, m_env.env.console, m_env.context, m_env.battle_ai); + }catch (StoryActionNotImplemented&){ + throw; + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("battle_failed", e.message()); + } + return Pokemon::outcome_ok(); +} + +void PlzaConsoleBackend::log(std::string_view line){ + m_env.env.console.log(std::string(line), COLOR_BLUE); +} + +CancellableScope& PlzaConsoleBackend::scope(){ + return m_env.context; +} + +void story_turn(PlzaBackend& backend, double degrees){ + // 150 ms is the tap the story was recorded with (console B, 2026-11-08). + // Short releases: the legs run back to back, as when played by hand. + backend.press(BUTTON_L, 100ms, 150ms); + backend.stick(degrees, 150ms, 100ms, Pokemon::StoryPace::WALK); +} + +PlzaReader heading_reader(StoryEnv& env){ + return [&env](PlzaBackend&, Pokemon::Observation& observation){ + const double heading = get_facing_direction(env.env.console, env.context); + observation.readings[std::string(Pokemon::STORY_HEADING)] = (int)std::lround(heading) % 360; + }; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h new file mode 100644 index 0000000000..9e06505618 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -0,0 +1,129 @@ +/* PokemonLZA AutoStory - Story backend + * + * From: https://github.com/PokemonAutomation/ + * + * PLZA on the console for the engine's backend + * (Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h), and the inputs a game + * with no tiles builds from it. + * + * Directions are the stick relative to the camera: north is straight on, + * east to the right. tap() turns that way (story_turn()); hold() walks. + * Dash is a toggle in this game and the walks assume it is off, so + * StoryPace::RUN walks too. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryBackend_H +#define PokemonAutomation_PokemonLZA_AutoStoryBackend_H + +#include +#include +#include +#include "CommonFramework/Language.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" +#include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.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" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMainMissionBannerDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h" +#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The console a run plays on, for the actions only a console can do +// (menus, OCR, the battle AI). +struct StoryEnv{ + SingleSwitchProgramEnvironment& env; + ProControllerContext& context; + // The new game's name: letters and digits; type_player_name() capitalizes + // the first letter only. The lab's player is Kosmos. + std::string player_name = "Kosmos"; + // The game's language, for the steps that read text. + Language language = Language::English; + BattleAIOption& battle_ai; +}; + + +// The engine's backend for PLZA's pose. +using PlzaBackend = Pokemon::StoryBackend; +// A reader for PLZA's pose (StoryGame::readers). +using PlzaReader = Pokemon::StoryReader; + +// Turns the player `degrees` clockwise of straight on (negative: left), +// as the story was recorded: L recenters the camera behind the player, +// then the stick is tapped that way for 150 ms. The tap also takes a step. +void story_turn(PlzaBackend& backend, double degrees); + +// The STORY_HEADING reading for the console: the minimap's arrow +// (get_facing_direction()), clockwise from north in [0, 360). It waits up +// to 40 s for the minimap and throws without it, so its StoryGameReader +// in make_plza_story_game() is ON_REQUEST and console_only: no +// postcondition check runs it. +PlzaReader heading_reader(StoryEnv& env); + + +// PLZA on the console: the controller and PlzaScreenObserver. +// code-health: allow public_methods -- the engine's backend calls; nothing PLZA adds +class PlzaConsoleBackend : public PlzaBackend{ +public: + explicit PlzaConsoleBackend(StoryEnv& env); + + virtual Pokemon::StoryBackendKind kind() const override{ + return Pokemon::StoryBackendKind::CONSOLE; + } + virtual void press(Button button, Milliseconds hold, Milliseconds release) override; + virtual void tap(Pokemon::Direction direction) override; + virtual void hold(Pokemon::Direction direction, Milliseconds duration, Pokemon::StoryPace pace) override; + virtual void stick(double degrees, Milliseconds duration, Milliseconds release, Pokemon::StoryPace pace) override; + virtual void wait(Milliseconds duration) override; + // Once the inputs are done: PlzaScreenObserver's events on a frame + // (plza_observation()), STILL when it barely differs from the frame + // of the look before, and the readings PLATFORM_READING, + // SKIP_PROMPT_READING, AUTOSAVE_READING, CONTROLS_HINT_READING, + // ADVANCE_ARROW_READING, MISSION_BANNER_READING and + // MISSION_COMPLETE_READING (which wins over the banner: the card has + // the banner's bar). + virtual Pokemon::Observation observe() override; + // fight_battle() with the run's battle AI; a failure is an Outcome. + virtual Pokemon::Outcome battle(const Pokemon::StoryActionArgs& args) override; + virtual void log(std::string_view line) override; + virtual CancellableScope& scope() override; + +private: + StoryEnv& m_env; + PlzaScreenObserver m_observer; + PlatformArrivalDetector m_platform; + SkipPromptDetector m_skip_prompt; + AutosaveDetector m_autosave; + ControlsHintDetector m_controls_hint; + AdvanceArrowDetector m_advance_arrow; + MainMissionBannerDetector m_mission_banner; + MissionCompleteDetector m_mission_complete; + VideoSnapshot m_previous; + // Every look's events, and a frame each time they change (and every + // CAPTURE_EVERY), go to the log and a capture folder: the record of + // what the detectors saw, to find the screens they miss. + void capture(const Pokemon::Observation& look); + std::string m_capture_folder; + std::optional m_captured_text; + WallClock m_captured_at; + size_t m_captures = 0; +}; + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.cpp new file mode 100644 index 0000000000..56d4ada553 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.cpp @@ -0,0 +1,38 @@ +/* PokemonLZA AutoStory - Dev checkpoint files + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include "Common/Cpp/Filesystem/FileIO.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "PokemonLZA_AutoStoryDevFiles.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +std::string story_dev_folder(){ + return std::format("{}AutoStoryDev/plza/", USER_FILE_PATH()); +} + +std::vector read_story_dev_files(std::string_view folder){ + std::vector files; + for (const Filesystem::Path& path : Filesystem::list_directory(Filesystem::Path(std::string(folder)))){ + const std::string name = path.filename().string(); + if (!name.starts_with("plza-") || !name.ends_with(".plan.json") || !Filesystem::is_regular_file(path)){ + continue; + } + files.push_back({.name = name, .path = path.string(), .text = file_to_string(path.string())}); + } + return files; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.h new file mode 100644 index 0000000000..e876449571 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.h @@ -0,0 +1,43 @@ +/* PokemonLZA AutoStory - Dev checkpoint files + * + * From: https://github.com/PokemonAutomation/ + * + * For lab tuning: checkpoint files on disk that a run reads in place of + * the built-in ones of the same name (load_story_data()), so a walk can be + * retimed without a rebuild. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryDevFiles_H +#define PokemonAutomation_PokemonLZA_AutoStoryDevFiles_H + +#include +#include +#include + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A checkpoint file read from disk. +struct StoryDevFile{ + std::string name; // "plza-02.01.plan.json" + std::string path; + std::string text; +}; + +// The folder whose checkpoint files replace the built-in ones: +// /AutoStoryDev/plza/ (USER_FILE_PATH()). +std::string story_dev_folder(); + +// The plza-*.plan.json files in `folder`, by name; none if it does not +// exist. +std::vector read_story_dev_files(std::string_view folder); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp new file mode 100644 index 0000000000..e340f962be --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -0,0 +1,303 @@ +/* PokemonLZA AutoStory - Engine Tests + * + * From: https://github.com/PokemonAutomation/ + * + * 01.00's scene steps, the walks' compass turns, and every checkpoint, through the shared + * story engine on its scripted backend (FakeStoryBackend). + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h" +#include "PokemonLZA_AutoStoryGame.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" +#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryStoryFiles.h" +#include "PokemonLZA_AutoStoryEngine_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using Pokemon::Observation; +using Pokemon::StoryCheckpoint; +using Pokemon::StoryStep; +using Pokemon::ZonePose; +using EngineEvent = PokemonAutomation::ScreenEvent; + + +namespace{ + +using FakeBackend = Pokemon::FakeStoryBackend; + +// A scripted PLZA showing `looks` in order (the last repeats); `kind` +// CONSOLE runs the console_only actions' code. +FakeBackend fake_plza( + std::vector> looks, CancellableScope& scope, + Pokemon::StoryBackendKind kind = Pokemon::StoryBackendKind::SCRIPT +){ + return FakeBackend(Pokemon::FakeStoryScript{.looks = std::move(looks), .battle = Pokemon::outcome_ok(), .kind = kind}, scope); +} + +// A look at `at` after a fixed start showing `events`. +Observation look_at(Milliseconds at, std::initializer_list events = {}){ + static const WallClock START = current_time(); + Observation look; + look.when = START + at; + look.events = ScreenEvents(events); + return look; +} + +// The step `name` of checkpoint `id`, alone in a checkpoint of its own. +StoryCheckpoint step_of(std::string_view id, std::string_view name){ + const auto found = std::find_if(story_checkpoints().begin(), story_checkpoints().end(), [id](const StoryCheckpoint& row){ + return row.id == id; + }); + if (found == story_checkpoints().end()){ + return StoryCheckpoint{}; + } + const StoryCheckpoint& row = *found; + StoryCheckpoint one; + one.id = row.id; + one.title = row.title; + for (const StoryStep& step : row.steps){ + if (step.name == name){ + one.steps.push_back(step); + } + } + return one; +} + +// `checkpoint` on PLZA's engine over `backend`. +Pokemon::StoryEngineReport run_plza(FakeBackend& backend, const StoryCheckpoint& checkpoint){ + const Pokemon::StoryGame game = make_offline_plza_story_game(); + Pokemon::StoryEngine engine(game, backend); + Pokemon::RunState state; + return engine.run_checkpoint(checkpoint, Pokemon::SavePoint::RUN_END, state); +} + +std::string joined(const std::vector& lines){ + std::string text; + for (const std::string& line : lines){ + text += (text.empty() ? "" : ", ") + line; + } + return text; +} + +UnitTestResult expect_inputs(const FakeBackend& backend, const std::vector& expected){ + if (backend.inputs() != expected){ + return std::format("Expected inputs [{}], got [{}].", joined(expected), joined(backend.inputs())); + } + return true; +} + + +// `look` with the reading `name` on screen. +Observation with_reading(Observation look, std::string_view name){ + look.readings[std::string(name)] = 1; + return look; +} + +// The opening (opening_to_platform): no presses through the cutscene and +// its skip prompt; the platform before the autosave does not count; done +// on the second look in a row at the platform after the autosave badge. +UnitTestResult test_opening_waits_for_platform(CancellableScope& scope){ + FakeBackend backend = fake_plza({ + look_at(0ms, {EngineEvent::FADE_BLACK}), + with_reading(look_at(300ms), SKIP_PROMPT_READING), + with_reading(look_at(600ms), PLATFORM_READING), + with_reading(look_at(900ms), PLATFORM_READING), + with_reading(with_reading(look_at(1200ms), PLATFORM_READING), AUTOSAVE_READING), + with_reading(look_at(1500ms), PLATFORM_READING), + with_reading(look_at(1800ms), PLATFORM_READING), + }, scope); + const Pokemon::StoryEngineReport report = run_plza(backend, step_of("01.00", "opening")); + if (report.verdict != Pokemon::CheckpointVerdict::PASSED){ + return std::format("Expected the opening to end at the platform: {}", to_string(report.run.failure)); + } + const auto logged = [&backend](std::string_view text){ + return std::any_of(backend.lines().begin(), backend.lines().end(), [text](const std::string& line){ + return line.find(text) != std::string::npos; + }); + }; + if (!logged("skip prompt") || !logged("autosave")){ + return "Expected the skip prompt and the autosave in the log."; + } + return expect_inputs(backend, std::vector(6, "wait 300ms")); +} + +// A look at `at` facing `heading`, as the minimap reads it. +Observation facing(Milliseconds at, int heading){ + Observation look = look_at(at); + look.readings[std::string(Pokemon::STORY_HEADING)] = heading; + return look; +} + +// face_heading() turns by the difference to the heading a look reads and +// stops once a look reads it within the tolerance; with no heading read it +// fails before any input. +UnitTestResult test_face_heading(CancellableScope& scope){ + FakeBackend backend = fake_plza({facing(0ms, 0), facing(500ms, 88)}, scope); + const Pokemon::Outcome faced = face_heading(backend, PlzaReader(), 90, 10); + if (!faced.succeeded()){ + return std::format("Expected to face 90 degrees: {}", to_string(faced)); + } + const UnitTestResult turned = expect_inputs(backend, {"press L", "stick 90deg 150ms walk, release 100ms"}); + if (turned.result != UnitTestResult::PASSED){ + return turned; + } + FakeBackend blind = fake_plza({look_at(0ms)}, scope); + const Pokemon::Outcome unread = face_heading(blind, PlzaReader(), 90, 10); + if (unread.failure != "heading_unread"){ + return std::format("Expected heading_unread with no heading read, got {}", to_string(unread)); + } + return expect_inputs(blind, {}); +} + +// What PLZA refuses: console actions fail as console_only off a console, +// and tile walks and unknown actions fail the lint. +UnitTestResult test_refused_steps(CancellableScope& scope){ + StoryCheckpoint legs; + legs.id = "probe"; + StoryStep step; + step.kind = Pokemon::StoryStepKind::LEGS; + step.name = "legs"; + step.args["legs"] = std::vector{{.direction = Pokemon::Direction::NORTH, .tiles = 1}}; + legs.steps.push_back(step); + if (plza_story_lint(legs).empty()){ + return "Expected a tile walk to fail the lint."; + } + FakeBackend backend = fake_plza({look_at(0ms)}, scope); + const Pokemon::StoryEngineReport report = run_plza(backend, step_of("01.00", "language")); + if (report.run.failure.failure != "console_only"){ + return std::format("Expected the new game's language to need a console, got {}", to_string(report.run.failure)); + } + const std::vector> unknown{ + {Pokemon::StoryStepKind::MASH, "x"}, + {Pokemon::StoryStepKind::GAME, "no_such_move"}, + {Pokemon::StoryStepKind::GAME, "choose_starter"}, + {Pokemon::StoryStepKind::GAME, "choose_2"}, + }; + for (const auto& [kind, action] : unknown){ + StoryCheckpoint probe; + probe.id = "probe"; + StoryStep bad; + bad.kind = kind; + bad.name = "probe"; + bad.action = action; + probe.steps.push_back(bad); + if (plza_story_lint(probe).empty()){ + return std::format("Expected {} \"{}\" to fail the lint.", Pokemon::story_step_kind_name(kind), action); + } + } + return expect_inputs(backend, {}); +} + +// Every checkpoint through the engine with each action recording itself: +// its steps in order, each by its action, and no save while testing. The +// fake says it is a console, so the console_only actions run too. +UnitTestResult test_every_checkpoint_runs(CancellableScope& scope){ + FakeBackend backend = fake_plza({look_at(0ms)}, scope, Pokemon::StoryBackendKind::CONSOLE); + std::vector trace; + Pokemon::StoryGame game; + game.id = "plza"; + for (const Pokemon::StoryActionSpec& spec : plza_story_action_specs()){ + const std::string label = std::format("{}/{}", Pokemon::story_step_kind_name(spec.kind), spec.name); + game.actions.push_back({.spec = spec, .handler = [&trace, label](Pokemon::StoryBackend&, const Pokemon::StoryActionCall&, Pokemon::RunState&){ + trace.push_back(label); + return Pokemon::outcome_ok(); + }}); + } + size_t saves = 0; + game.save = [&saves](Pokemon::StoryBackend&, const StoryCheckpoint&){ + saves++; + return Pokemon::outcome_ok(); + }; + Pokemon::StoryEngine engine(game, backend); + std::vector expected; + for (const StoryCheckpoint& checkpoint : story_checkpoints()){ + for (const StoryStep& step : checkpoint.steps){ + const Pokemon::StoryActionSpec* spec = Pokemon::find_story_action(plza_story_specs(), step.kind, step.action); + expected.push_back(std::format("{}/{}", Pokemon::story_step_kind_name(step.kind), spec ? spec->name : "?")); + } + Pokemon::RunState state; + const Pokemon::StoryEngineReport report = engine.run_checkpoint(checkpoint, Pokemon::SavePoint::RUN_END, state); + if (report.verdict != Pokemon::CheckpointVerdict::PASSED || report.saved){ + return std::format("{}: expected a pass with no save, got {} ({}).", checkpoint.id, + report.verdict == Pokemon::CheckpointVerdict::PASSED ? "a save" : "a failure", to_string(report.run.failure)); + } + } + if (trace != expected){ + return std::format("Expected {} steps in order, ran {}.", expected.size(), trace.size()); + } + if (saves != 0){ + return std::format("Expected no save from testing checkpoints, saw {}.", saves); + } + return true; +} + + +struct EngineTestInput{ + std::string name; + std::function body; +}; + +struct EngineTestExpectation{ +}; + +struct EngineTestCase{ + EngineTestInput input; + EngineTestExpectation expectation; +}; + +class Test_AutoStoryEngine : public UnitTest{ +public: + explicit Test_AutoStoryEngine(EngineTestCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStoryEngine - {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ + try{ + return m_case.input.body(scope); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + EngineTestCase m_case; +}; + +} // namespace + + +const EngineTestCase ENGINE_TEST_CASES[] = { + {.input = {"01.00 opening: no presses, done on two looks at the platform after the autosave", test_opening_waits_for_platform}, .expectation = {}}, + {.input = {"face_heading: turns by the minimap's heading", test_face_heading}, .expectation = {}}, + {.input = {"refused: console actions off a console, tile walks, unknown actions", test_refused_steps}, .expectation = {}}, + {.input = {"every checkpoint runs in step order, testing never saves", test_every_checkpoint_runs}, .expectation = {}}, +}; + +void add_tests_AutoStoryEngine(UnitTestDatabase& database){ + for (const EngineTestCase& item : ENGINE_TEST_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h new file mode 100644 index 0000000000..9eaefccc32 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Engine Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryEngine_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryEngine_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// PLZA's checkpoints and 01.00's scene steps on the shared story engine, +// with a scripted backend: no console. +void add_tests_AutoStoryEngine(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp new file mode 100644 index 0000000000..8bedc6b145 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -0,0 +1,512 @@ +/* PokemonLZA AutoStory - Story game + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "Pokemon/AutoStory/Pokemon_BuiltinStoryActions.h" +#include "Pokemon/AutoStory/Pokemon_StoryStepExecutor.h" +#include "Pokemon/AutoStory/Engine/Pokemon_StoryActionRegistry.h" +#include "VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h" +#include "VideoGames/PokemonLZA/Resources/PokemonLZA_Locations.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h" +#include "PokemonLZA_AutoStorySceneMachine.h" +#include "PokemonLZA_AutoStoryStepValidator.h" +#include "PokemonLZA_AutoStoryGame.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using Pokemon::Outcome; +using Pokemon::StoryActionArgs; +using Pokemon::StoryActionCall; +using Pokemon::StoryActionSpec; +using Pokemon::StoryArgSpec; +using Pokemon::StoryArgType; +using Pokemon::StoryStepKind; +using Pokemon::ZonePose; +using Handler = Pokemon::StoryActionHandler; + + +const std::map>& story_actions_not_implemented(){ + static const std::map> todos{ + }; + return todos; +} + + +namespace{ + +using IntegerRows = std::vector>; + +// What a console action does with the run's console and the step's args. +using ConsoleBody = std::function; + +// A GAME action that only presses through the game's own screens: one +// call on the console, with no args. +using ConsoleStep = void (*)(StoryEnv& env); + +// The GAME actions that are one ConsoleStep each, by name: console_only. +const std::map>& console_game_actions(){ + static const std::map> actions{ + {"new_game_language", [](StoryEnv& env){ new_game_language(env.env.console, env.context); }}, + {"pick_look", [](StoryEnv& env){ pick_first_look(env.env.console, env.context); }}, + {"type_player_name", [](StoryEnv& env){ type_player_name(env.env.console, env.context, env.player_name); }}, + {"choose_0", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 0); }}, + {"choose_1", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 1); }}, + }; + return actions; +} + +// The built-in action of `kind` named `name`: a replacement keeps its args. +StoryActionSpec builtin_spec(StoryStepKind kind, std::string name){ + const StoryActionSpec* spec = Pokemon::find_story_action(Pokemon::builtin_story_actions(), kind, name); + if (spec != nullptr){ + return *spec; + } + return StoryActionSpec{.kind = kind, .name = std::move(name), .args = {}}; +} + +// `spec`, run only on a console. +StoryActionSpec console_only(StoryActionSpec spec){ + spec.console_only = true; + return spec; +} + +StoryActionSpec game_spec(std::string name, std::vector args = {}){ + return StoryActionSpec{.kind = StoryStepKind::GAME, .name = std::move(name), .args = std::move(args)}; +} + +StoryArgSpec optional_ms(std::string key, int64_t fallback, std::string why){ + return StoryArgSpec{.key = std::move(key), .type = StoryArgType::INTEGER, .required = false, .fallback = fallback, .why = std::move(why)}; +} + +StoryArgSpec legs_arg(std::string key, bool required, std::string why){ + return StoryArgSpec{.key = std::move(key), .type = StoryArgType::INTEGER_ROWS, .required = required, .fallback = std::nullopt, .why = std::move(why)}; +} + +// "walk": its legs, the fade it ends on, the heading it faces first. +StoryActionSpec walk_spec(){ + return game_spec("walk", { + legs_arg("legs", true, "the legs: [turn in degrees, clockwise (negative: left), walk ms] each"), + StoryArgSpec{ + .key = "end", .type = StoryArgType::WORD, .required = false, .fallback = std::nullopt, + .why = "\"fade_white\" or \"fade_black\": the last leg is held until it shows, its ms the bound", + }, + StoryArgSpec{ + .key = "heading", .type = StoryArgType::INTEGER, .required = false, .fallback = std::nullopt, + .why = "the compass heading to face first, clockwise from north", + }, + }); +} + + + +// Builds the handlers. The console actions hold the console; without one +// (a test, a simulation) their specs are console_only and the engine +// refuses them before their handler. +class PlzaHandlers{ +public: + explicit PlzaHandlers(StoryEnv* env) + : m_env(env) + { + if (m_env != nullptr){ + m_heading = heading_reader(*m_env); + } + } + + // `body` on the console. A console step that fails becomes a failed + // Outcome, so the run can reload; an action that is not implemented + // ends the run. + Handler console(std::string name, ConsoleBody body) const{ + if (m_env == nullptr){ + return [name = std::move(name)](Pokemon::StoryBackend&, const StoryActionCall&, Pokemon::RunState&){ + return Pokemon::outcome_failed(std::string(Pokemon::CONSOLE_ONLY), std::format("{} runs only on a console", name)); + }; + } + StoryEnv& env = *m_env; + return [&env, name = std::move(name), body = std::move(body)]( + Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState& + ){ + try{ + body(env, call.args); + }catch (StoryActionNotImplemented&){ + throw; + }catch (OperationFailedException& e){ + backend.log(std::format("[PLZA] {} failed: {}", name, e.message())); + return Pokemon::outcome_failed("operation_failed", e.message()); + } + return Pokemon::outcome_ok(); + }; + } + + // "walk": its args' legs, walked once the screen shows free control, + // until its end event if it has one. + Handler walk() const{ + return [heading = m_heading](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ + return walk_legs(backend, call.step.name, story_walk_move(call.args, "legs"), call.args, heading); + }; + } + + static Handler not_implemented(std::string name, std::string todo){ + return [name = std::move(name), todo = std::move(todo)]( + Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState& + ) -> Outcome{ + const std::string message = std::format("PLZA AutoStory: {} is not implemented yet. TODO: {}", name, todo); + backend.log(message); + throw StoryActionNotImplemented(message); + }; + } + + // "mash_to_move_hints": A through the scenes (a choice takes its top + // row, the advance chevron its text) until the player has control: the + // controls hint or the party bar held a second, or a main mission's + // banner on two looks (01.01's arrival ends on "MAIN MISSION 01"; the + // step returns once it has gone, 10 s at most). 01.01's arrival takes + // ~240 s on the console, hence 360 s. A text-free cutscene + // (01.01's city flyover, ~20 s) is not control: nothing busy for the + // quiet time fails the step. After 5 s with nothing busy and no sign + // of control, A every 2 s, for text the detectors miss (01.01's ad). + // A banner that stays past the 10 s gets A up to 3 times (01.03's + // "MAIN MISSION 02"), so the step ends with control. + static Handler move_hints(){ + return [](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ + SceneMachineConfig config; + config.quiet = Milliseconds(Pokemon::story_arg(call.args, "quiet_ms")); + config.min_length = Milliseconds(Pokemon::story_arg(call.args, "min_length_ms")); + config.blind_press_after = 5s; + return run_scene_machine(backend, "mash_to_move_hints", config, 360s); + }; + } + + // B through the text until the choices show. + static Handler text_to_choice(){ + return [](Pokemon::StoryBackend& backend, const StoryActionCall&, Pokemon::RunState&){ + SceneMachineConfig config; + config.goal = SceneMashGoal::CHOICE; + config.text_button = BUTTON_B; + return run_scene_machine(backend, "text_to_choice", config, 60s); + }; + } + +private: + // `move`, once the screen shows free control; held until the fade of + // `args`' "end", if it names one. + static Outcome walk_legs( + Pokemon::StoryBackend& backend, std::string_view name, const StoryMove& move, + const StoryActionArgs& args, const PlzaReader& heading + ){ + const Outcome free = check_can_walk(backend, name); + if (!free.succeeded()){ + return free; + } + const auto end = args.find("end"); + std::optional fade; + if (end != args.end()){ + const std::optional event = walk_end_event(std::get(end->second)); + fade = event ? engine_fade_event(*event) : std::nullopt; + } + return fade ? walk_until(backend, name, move, heading, *fade) : run_story_move(backend, move, heading); + } + + StoryEnv* m_env; + // The compass for the walks; none without a console, where a look + // carries its own heading. + PlzaReader m_heading; +}; + +// What a platform wait needs before the platform counts. +enum class PlatformWait{ + PLATFORM_ONLY, // "wait_for_platform": a start check + AFTER_AUTOSAVE, // "opening_to_platform": the autosave badge first +}; + +// Looks every PLATFORM_POLL: the autosave badge shows for 1-3 s (console B, +// 2026-11-10), so at least 2 looks a second. +constexpr Milliseconds PLATFORM_POLL(300); +constexpr size_t PLATFORM_LOOKS = 2; + +// One platform wait's progress over its looks. +struct PlatformProgress{ + bool autosave_seen = false; + bool skip_prompt = false; + size_t streak = 0; +}; + +// Takes `look` into `progress`; logs the skip prompt and the autosave +// when they show. True once the platform has held PLATFORM_LOOKS looks. +bool platform_look(Pokemon::StoryBackend& backend, const ScreenObservation& look, PlatformWait wait, PlatformProgress& progress){ + const bool skip_now = look.readings.contains(SKIP_PROMPT_READING); + if (skip_now && !progress.skip_prompt){ + backend.log("[PLZA] platform wait: the skip prompt is on screen"); + } + progress.skip_prompt = skip_now; + if (look.readings.contains(AUTOSAVE_READING)){ + if (!progress.autosave_seen){ + backend.log("[PLZA] platform wait: the autosave badge is on screen"); + } + progress.autosave_seen = true; + progress.streak = 0; + return false; + } + const bool counts = wait == PlatformWait::PLATFORM_ONLY || progress.autosave_seen; + progress.streak = counts && look.readings.contains(PLATFORM_READING) ? progress.streak + 1 : 0; + return progress.streak >= PLATFORM_LOOKS; +} + +// The station platform after the opening cutscene, with no input (A does +// not advance the cutscene): PLATFORM_READING on PLATFORM_LOOKS looks in a +// row; AFTER_AUTOSAVE counts them only once the autosave badge has shown +// and gone. Fails after `timeout`. +Outcome wait_for_platform(Pokemon::StoryBackend& backend, Milliseconds timeout, PlatformWait wait){ + // The looks bound a script whose time stands still. + const size_t max_looks = (size_t)(timeout / PLATFORM_POLL) + 1; + std::optional start; + PlatformProgress progress; + for (size_t looks = 0; looks < max_looks; looks++){ + backend.scope().throw_if_cancelled(); + const Pokemon::Observation look = backend.observe(); + start = start.value_or(look.when); + if (platform_look(backend, look, wait, progress)){ + backend.log(std::format("[PLZA] platform wait: on the platform after {} looks", looks + 1)); + return Pokemon::outcome_ok(); + } + if (look.when - *start >= timeout){ + break; + } + backend.wait(PLATFORM_POLL); + } + return Pokemon::outcome_failed("platform_not_seen", std::format( + "No platform on {} looks in a row within {} ms (autosave {}).", + PLATFORM_LOOKS, timeout.count(), progress.autosave_seen ? "seen" : "not seen" + )); +} + +// The handler of "wait_for_platform" or "opening_to_platform". +Handler platform_handler(PlatformWait wait){ + return [wait](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ + return wait_for_platform(backend, Milliseconds(Pokemon::story_arg(call.args, "timeout_ms")), wait); + }; +} + +// The GAME actions that are not ConsoleSteps, by name: each one's handler +// from the run's handlers. +using HandlerOf = Handler (*)(const PlzaHandlers& handlers); +const std::map>& story_game_actions(){ + static const std::map> actions{ + {"walk", [](const PlzaHandlers& handlers){ return handlers.walk(); }}, + {"mash_to_move_hints", [](const PlzaHandlers&){ return PlzaHandlers::move_hints(); }}, + {"text_to_choice", [](const PlzaHandlers&){ return PlzaHandlers::text_to_choice(); }}, + {"wait_for_platform", [](const PlzaHandlers&){ return platform_handler(PlatformWait::PLATFORM_ONLY); }}, + {"opening_to_platform", [](const PlzaHandlers&){ return platform_handler(PlatformWait::AFTER_AUTOSAVE); }}, + }; + return actions; +} + +// The handler of the GAME action `name`: a todo, a ConsoleStep or one of +// story_game_actions(). +Handler game_handler(const PlzaHandlers& handlers, const std::string& name){ + const auto todo = story_actions_not_implemented().find(name); + if (todo != story_actions_not_implemented().end()){ + return PlzaHandlers::not_implemented(name, todo->second); + } + const auto step = console_game_actions().find(name); + if (step != console_game_actions().end()){ + return handlers.console(name, [step = step->second](StoryEnv& env, const StoryActionArgs&){ + step(env); + }); + } + return story_game_actions().at(name)(handlers); +} + +// The handler of each of plza_story_action_specs(), by kind and name. +Handler plza_handler(const PlzaHandlers& handlers, const StoryActionSpec& spec){ + const std::string& name = spec.name; + switch (spec.kind){ + case StoryStepKind::ROUTE:{ + Handler fly = handlers.console(name, [](StoryEnv& env, const StoryActionArgs& args){ + const Pokemon::GridPose& target = Pokemon::story_arg(args, "target"); + fly_to(env.env.console, env.context, env.language, get_location_item_from_slug(target.map).location); + }); + // Flown: the player is at the target. + return [fly = std::move(fly)](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState& state){ + Outcome outcome = fly(backend, call, state); + if (outcome.succeeded()){ + outcome.pose = Pokemon::pose_of(Pokemon::story_arg(call.args, "target")); + } + return outcome; + }; + } + case StoryStepKind::TALK: + return handlers.console(name, [](StoryEnv& env, const StoryActionArgs&){ + talk_to_facing(env.env.console, env.context); + }); + case StoryStepKind::ANSWER: + return handlers.console(name, [](StoryEnv& env, const StoryActionArgs& args){ + choose_dialog_option(env.env.console, env.context, Pokemon::story_arg(args, "yes") ? 0 : 1); + }); + case StoryStepKind::MASH:{ + // 120 s: a scene can hold a long black screen. + const Button button = name == "a" ? BUTTON_A : BUTTON_B; + return handlers.console(name, [button](StoryEnv& env, const StoryActionArgs&){ + mash_scene(env.env.console, env.context, SceneMashGoal::OVERWORLD, button, 120s); + }); + } + default: + return game_handler(handlers, name); + } +} + +const Pokemon::StoryActionRegistry& spec_registry(){ + static const Pokemon::StoryGame game = []{ + Pokemon::StoryGame specs_only; + specs_only.id = "plza"; + for (StoryActionSpec& spec : plza_story_action_specs()){ + specs_only.actions.push_back({.spec = std::move(spec), .handler = {}}); + } + return specs_only; + }(); + static const Pokemon::StoryActionRegistry registry(game); + return registry; +} + +// PLZA's actions over `env` (none: no console), with no save or reload. +Pokemon::StoryGame plza_game_actions(StoryEnv* env){ + const PlzaHandlers handlers(env); + Pokemon::StoryGame game; + game.id = "plza"; + for (StoryActionSpec& spec : plza_story_action_specs()){ + Handler handler = plza_handler(handlers, spec); + game.actions.push_back({.spec = std::move(spec), .handler = std::move(handler)}); + } + return game; +} + +} // namespace + + +std::vector plza_story_action_specs(){ + std::vector specs{ + console_only(StoryActionSpec{.kind = StoryStepKind::ROUTE, .name = "fly", .args = { + StoryArgSpec{ + .key = "target", .type = StoryArgType::GRID_POSE, .required = true, + .fallback = std::nullopt, .why = "the fast travel place, by slug, as the map", + }, + }}), + console_only(builtin_spec(StoryStepKind::TALK, "talk")), + console_only(builtin_spec(StoryStepKind::ANSWER, "answer")), + console_only(builtin_spec(StoryStepKind::MASH, "mash")), + console_only(StoryActionSpec{.kind = StoryStepKind::MASH, .name = "a", .args = {}}), + game_spec("mash_to_move_hints", { + optional_ms("min_length_ms", 0, "the scene's rough length: no quiet failure before it"), + optional_ms("quiet_ms", 60000, "nothing busy and no control this long fails the step"), + }), + game_spec("text_to_choice"), + game_spec("wait_for_platform", { + optional_ms("timeout_ms", 180000, "no platform this long fails the step"), + }), + game_spec("opening_to_platform", { + optional_ms("timeout_ms", 240000, "no autosave and platform this long fails the step"), + }), + }; + for (const auto& [name, step] : console_game_actions()){ + specs.push_back(console_only(game_spec(name))); + } + specs.push_back(walk_spec()); + for (const auto& [name, todo] : story_actions_not_implemented()){ + specs.push_back(game_spec(name)); + } + return specs; +} + +const std::vector& plza_story_specs(){ + return spec_registry().specs(); +} + +std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpoint){ + std::vector errors = spec_registry().lint(checkpoint); + if (!errors.empty()){ + return errors; + } + for (const Pokemon::StoryStep& step : checkpoint.steps){ + for (std::string& error : plza_step_arg_errors(step)){ + errors.push_back(std::format("{}: {}", checkpoint.id, error)); + } + } + return errors; +} + +StoryMove story_walk_move(const StoryActionArgs& args, std::string_view legs){ + StoryMove move; + const auto heading = args.find("heading"); + if (heading != args.end()){ + move.heading = (double)std::get(heading->second); + } + for (const std::vector& row : Pokemon::story_arg(args, legs)){ + if (row.size() != 2){ + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("A walk leg needs 2 numbers, has {}.", row.size())); + } + move.legs.push_back({.turn = (double)row[0], .walk = Milliseconds(row[1])}); + } + return move; +} + +Pokemon::StoryGame make_plza_story_game( + StoryEnv& env, std::set> autosave_rows +){ + Pokemon::StoryGame game = plza_game_actions(&env); + // Slow, and it throws without the minimap: never after a checkpoint. + game.readers.push_back({ + .name = std::string(Pokemon::STORY_HEADING), .supplies = {std::string(Pokemon::STORY_HEADING)}, + .use = Pokemon::StoryReaderUse::ON_REQUEST, .console_only = true, .read = heading_reader(env), + }); + game.save = [&env, autosave_rows = std::move(autosave_rows)](Pokemon::StoryBackend& backend, const Pokemon::StoryCheckpoint& checkpoint){ + if (autosave_rows.contains(checkpoint.id)){ + backend.log(std::format("[Save] {}: the game autosaved at its end", checkpoint.id)); + return Pokemon::outcome_ok(); + } + try{ + save_story_game(env.env.console, env.context); + }catch (OperationFailedException& e){ + return Pokemon::outcome_failed("save_failed", e.message()); + } + return Pokemon::outcome_ok(); + }; + game.reload = [&env](Pokemon::StoryBackend&){ + go_home(env.env.console, env.context); + if (!reset_game_from_home(env.env, env.env.console, env.context)){ + return Pokemon::outcome_failed("reload_failed", "Failed to reset the game from HOME."); + } + return Pokemon::outcome_ok(); + }; + return game; +} + +Pokemon::StoryGame make_offline_plza_story_game(){ + return plza_game_actions(nullptr); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h new file mode 100644 index 0000000000..1e002aef02 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -0,0 +1,104 @@ +/* PokemonLZA AutoStory - Story game + * + * From: https://github.com/PokemonAutomation/ + * + * PLZA for the shared story engine (Pokemon/AutoStory/Engine/): its + * actions as a StoryGame, and their specs, which a checkpoint's + * JSON is read against. It replaces PLZA's own story executor. + * + * The actions that read or press through the game's own screens (menus, + * the naming keyboard, the battle AI, fast travel) are console_only: the + * engine refuses them elsewhere. The scenes of 01.00 and the walks run on + * any backend. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryGame_H +#define PokemonAutomation_PokemonLZA_AutoStoryGame_H + +#include +#include +#include +#include +#include +#include +#include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" +#include "PokemonLZA_AutoStoryBackend.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The GAME actions whose code does not exist yet, by action, each with the +// code it waits for. They throw StoryActionNotImplemented with that text, +// which ends the run, instead of pressing buttons blind. +const std::map>& story_actions_not_implemented(); + +// PLZA's own actions and its replacements of built-in ones (same kind and +// name), in the order the game registers them: +// +// ROUTE "fly" fly to the target, whose map is a fast travel +// place's slug ("vert-pokemon-center") +// TALK "talk" A at what the player faces +// ANSWER "answer" the first choice for yes, the second for no +// MASH "mash" B through the text until the overworld is back +// MASH "a" A through it +// GAME "walk" (args "legs", [[turn, ms], ...] as story_walk_move() +// reads them; "end", "fade_white" or "fade_black"; "heading"), +// walked once the screen shows free control +// (check_can_walk()), until its end fade if it has one +// (walk_until()); the platform waits "wait_for_platform" and +// "opening_to_platform"; the scene machines +// "mash_to_move_hints" (args min_length_ms, quiet_ms) and +// "text_to_choice" (run_scene_machine()); a console step, one +// call through the game's own screens with no args: the new +// game's "new_game_language", "pick_look", "type_player_name"; +// "choose_0" / "choose_1" (that row of the choices on screen); +// or an action of story_actions_not_implemented() +// +// Every action that works through the game's own screens is console_only. +// BATTLE is the built-in "fight" (the backend's battle), SAVE the +// engine's, and the built-in "route" and "shop" fail by name. Lumiose has +// no tiles: a step naming "legs" or "face" fails the lint. +std::vector plza_story_action_specs(); + +// Every action a PLZA checkpoint may name: the built-ins with +// plza_story_action_specs() on top, as the engine registers them. Its JSON +// is read against these. +const std::vector& plza_story_specs(); + +// What is wrong with `checkpoint` for PLZA's engine +// (StoryActionRegistry::lint), then with its steps' args +// (plza_step_arg_errors(), PokemonLZA_AutoStoryStepValidator.h). +std::vector plza_story_lint(const Pokemon::StoryCheckpoint& checkpoint); + +// The walk of `args`: the legs of its arg `legs` ("legs" for a walk), each [turn in degrees clockwise +// (negative: left), walk ms], and its "heading", if any. The args must +// have passed plza_story_lint(). +StoryMove story_walk_move(const Pokemon::StoryActionArgs& args, std::string_view legs); + +// PLZA as a StoryGame on the console `env`, which must outlive it. +// The walks read the +// compass with heading_reader(). The save waits out the game's autosave at +// the end of the checkpoints of `autosave_rows` (the run's +// StoryData::autosaves) and saves through the menu after the others; the +// reload resets the game from HOME. +Pokemon::StoryGame make_plza_story_game( + StoryEnv& env, std::set> autosave_rows +); + +// The same with no console, for tests and simulations: the console_only +// actions fail as "console_only", the walks read the heading the looks +// carry, and there is no save or reload. +Pokemon::StoryGame make_offline_plza_story_game(); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp new file mode 100644 index 0000000000..aad37c0e4e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp @@ -0,0 +1,57 @@ +/* PokemonLZA AutoStory - Observations + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "PokemonLZA_AutoStoryObservation.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using Pokemon::ScreenEvent; +using Pokemon::ScreenEvents; + + +ScreenObservation plza_observation(const ScreenEvents& events){ + using EngineEvent = PokemonAutomation::ScreenEvent; + ScreenObservation look; + const std::pair same[] = { + {ScreenEvent::FADE_BLACK, EngineEvent::FADE_BLACK}, + {ScreenEvent::FADE_WHITE, EngineEvent::FADE_WHITE}, + {ScreenEvent::DIALOG_BOX, EngineEvent::TEXT_BOX}, + {ScreenEvent::CHOICE_BOX, EngineEvent::TEXT_BOX}, + {ScreenEvent::BATTLE_STARTED, EngineEvent::BATTLE}, + {ScreenEvent::PLAYER_CAN_MOVE, EngineEvent::CAN_MOVE}, + {ScreenEvent::SCREEN_STILL, EngineEvent::STILL}, + {ScreenEvent::CHOICE_BOX, EngineEvent::CHOICE_BOX}, + {ScreenEvent::INTERACT_PROMPT, EngineEvent::INTERACT_PROMPT}, + }; + for (const auto& [event, engine_event] : same){ + if (events.has(event)){ + look.events.add(engine_event); + } + } + return look; +} + +std::optional engine_fade_event(ScreenEvent event){ + switch (event){ + case ScreenEvent::FADE_BLACK: + return PokemonAutomation::ScreenEvent::FADE_BLACK; + case ScreenEvent::FADE_WHITE: + return PokemonAutomation::ScreenEvent::FADE_WHITE; + default: + return std::nullopt; + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h new file mode 100644 index 0000000000..e486fc4b06 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h @@ -0,0 +1,66 @@ +/* PokemonLZA AutoStory - Observations + * + * From: https://github.com/PokemonAutomation/ + * + * PLZA's screen events (PokemonLZA_AutoStoryScreenEvents.h) as the story + * engine's observations, which its backend returns and its scene states + * match on. + * + */ + +// code-health: allow header_symbols -- one reading name per detector; the readings are one concern that every consumer shares +#ifndef PokemonAutomation_PokemonLZA_AutoStoryObservation_H +#define PokemonAutomation_PokemonLZA_AutoStoryObservation_H + +#include +#include +#include "CommonTools/ScreenMachine/ScreenObservation.h" +#include "Pokemon/AutoStory/Pokemon_ScreenEventTypes.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The reading (ScreenObservation::readings) set to 1 when the station +// platform shows with free control after the opening cutscene +// (PlatformArrivalDetector). +constexpr std::string_view PLATFORM_READING = "scene.platform"; +// The reading set to 1 when the cutscene's "Hold button to skip" badge +// shows (SkipPromptDetector). +constexpr std::string_view SKIP_PROMPT_READING = "scene.skip_prompt"; +// The reading set to 1 while the autosave badge (a pencil and "Saving...", +// top right) shows: the game has autosaved (AutosaveDetector). +constexpr std::string_view AUTOSAVE_READING = "scene.autosave"; +// The reading set to 1 while the tutorial's controls hint (a "?" card over +// "(L) Move" and "(R) Control Camera", under the player) shows: the player +// has control (ControlsHintDetector). +constexpr std::string_view CONTROLS_HINT_READING = "scene.controls_hint"; +// The reading set to 1 while the "press A to go on" chevron shows, at a +// dialogue box or at boxless subtitles (AdvanceArrowDetector). +constexpr std::string_view ADVANCE_ARROW_READING = "scene.advance_arrow"; +// The reading set to 1 while a main mission's banner ("MAIN MISSION 01" +// over a yellow bar with the mission's name) shows (MainMissionBannerDetector). +constexpr std::string_view MISSION_BANNER_READING = "scene.mission_banner"; +// The reading set to 1 while the card a main mission ends with ("COMPLETE" +// over the mission's yellow bar) shows; it waits for A +// (MissionCompleteDetector). A look with it has no MISSION_BANNER_READING. +constexpr std::string_view MISSION_COMPLETE_READING = "scene.mission_complete"; + +// PlzaScreenObserver's events as one look for the story engine: +// DIALOG_BOX is TEXT_BOX; CHOICE_BOX adds TEXT_BOX; +// BATTLE_STARTED is BATTLE; PLAYER_CAN_MOVE (the party bar) is CAN_MOVE; +// SCREEN_STILL is STILL; the fades and INTERACT_PROMPT keep their names. +// No time and no frame: the backend adds them. +ScreenObservation plza_observation(const Pokemon::ScreenEvents& events); + +// The engine's event for a fade of the shared events; none for another +// event. +std::optional engine_fade_event(Pokemon::ScreenEvent event); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp new file mode 100644 index 0000000000..8c7c08ce4a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -0,0 +1,533 @@ +/* PokemonLZA AutoStory - Scene machine + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "CommonTools/ScreenMachine/ScreenMachine.h" +#include "PokemonLZA_AutoStorySceneMachine.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using EngineEvent = PokemonAutomation::ScreenEvent; + + +namespace{ + +// A party bar showing this long is the overworld: it also shows between +// lines of a talk. +constexpr Milliseconds PARTY_BAR_HOLD = 1000ms; +// The controls hint showing this long is free control: two looks or more. +constexpr Milliseconds CONTROLS_HINT_HOLD = 1000ms; +// The longest a fade is waited out in one step (02.06 holds a ~25 s black). +constexpr Milliseconds FADE_WAIT = 30000ms; +// The longest a still screen is waited on in one step. +constexpr Milliseconds STILL_WAIT = 10000ms; +// The longest a cutscene may hold one still frame. +constexpr Milliseconds SCENE_STILL_WAIT = 60000ms; +// How often blind_press_after presses A. +constexpr Milliseconds BLIND_PRESS_EVERY = 2000ms; +// How often a wait looks again. +constexpr Milliseconds POLL = 250ms; +// The longest the machine waits for the mission banner to go once it has +// ended the scene (it shows ~3 s). +constexpr Milliseconds BANNER_GONE_WAIT = 10000ms; +// A banner still up after BANNER_GONE_WAIT gets A this many times, this +// far apart, until it goes: 01.03's "MAIN MISSION 02" stayed past 10 s +// (console B, 2026-11-10), where "MAIN MISSION 01" went in ~3 s. +constexpr size_t BANNER_PRESSES = 3; +constexpr Milliseconds BANNER_PRESS_EVERY = 1000ms; + +// Text to press on: a box (or choice), or the advance chevron without one. +bool text_shows(const ScreenObservation& look){ + return look.events.has(EngineEvent::TEXT_BOX) || look.events.has(EngineEvent::CHOICE_BOX) || + look.readings.contains(ADVANCE_ARROW_READING); +} + +// Something holds the player: text, a battle, a fade, the mission +// complete card. +bool busy(const ScreenObservation& look){ + return text_shows(look) || look.events.has(EngineEvent::BATTLE) || + look.events.has(EngineEvent::FADE_BLACK) || look.events.has(EngineEvent::FADE_WHITE) || + look.readings.contains(MISSION_COMPLETE_READING); +} + +// The mission banner, and not the complete card (which has its bar). +bool banner_shows(const ScreenObservation& look){ + return look.readings.contains(MISSION_BANNER_READING) && !look.readings.contains(MISSION_COMPLETE_READING); +} + +// Free control on screen: the controls hint, or an "A: Talk" prompt +// (01.02's battle area shows no controls hint, console B 2026-11-10). +bool control_shows(const ScreenObservation& look){ + return look.readings.contains(CONTROLS_HINT_READING) || look.events.has(EngineEvent::INTERACT_PROMPT); +} + +constexpr SceneScreen ALL_SCREENS[] = { + SceneScreen::GOAL_CHOICE, SceneScreen::GOAL_BATTLE, + SceneScreen::FADE_BLACK, SceneScreen::FADE_WHITE, + SceneScreen::CHOICE, SceneScreen::DIALOG, SceneScreen::MISSION_COMPLETE, + SceneScreen::MISSION_BANNER, SceneScreen::BANNER_SHOWING, + SceneScreen::CAN_MOVE, SceneScreen::PARTY_BAR, + SceneScreen::CONTROLS_HINT, SceneScreen::HINT_SHOWING, SceneScreen::QUIET_END, SceneScreen::BLIND_PRESS, + SceneScreen::SCENE_MOVING, SceneScreen::SCENE_STILL, +}; + +} // namespace + + +std::string_view scene_screen_name(SceneScreen screen){ + switch (screen){ + case SceneScreen::GOAL_CHOICE: + return "goal_choice"; + case SceneScreen::GOAL_BATTLE: + return "goal_battle"; + case SceneScreen::FADE_BLACK: + return "fade_black"; + case SceneScreen::FADE_WHITE: + return "fade_white"; + case SceneScreen::CHOICE: + return "choice"; + case SceneScreen::DIALOG: + return "dialog"; + case SceneScreen::MISSION_COMPLETE: + return "mission_complete"; + case SceneScreen::MISSION_BANNER: + return "mission_banner"; + case SceneScreen::BANNER_SHOWING: + return "banner_showing"; + case SceneScreen::CAN_MOVE: + return "can_move"; + case SceneScreen::PARTY_BAR: + return "party_bar"; + case SceneScreen::CONTROLS_HINT: + return "controls_hint"; + case SceneScreen::HINT_SHOWING: + return "hint_showing"; + case SceneScreen::QUIET_END: + return "quiet_end"; + case SceneScreen::BLIND_PRESS: + return "blind_press"; + case SceneScreen::SCENE_MOVING: + return "scene_moving"; + case SceneScreen::SCENE_STILL: + return "scene_still"; + } + return "unknown"; +} + +bool scene_screen_terminal(SceneScreen screen){ + return screen == SceneScreen::GOAL_CHOICE || screen == SceneScreen::GOAL_BATTLE || + screen == SceneScreen::MISSION_BANNER || screen == SceneScreen::CAN_MOVE || + screen == SceneScreen::CONTROLS_HINT || screen == SceneScreen::QUIET_END; +} + +SceneMashAction scene_screen_action(SceneScreen screen, const SceneMachineConfig& config){ + if (scene_screen_terminal(screen)){ + return SceneMashAction::DONE; + } + switch (screen){ + case SceneScreen::CHOICE: + case SceneScreen::MISSION_COMPLETE: + case SceneScreen::BLIND_PRESS: + return SceneMashAction::PRESS_A; + case SceneScreen::DIALOG: + return SceneMashAction::PRESS_TEXT; + case SceneScreen::SCENE_MOVING: + case SceneScreen::SCENE_STILL: + if (config.goal == SceneMashGoal::BATTLE){ + return SceneMashAction::PRESS_A; + } + return config.text_button == BUTTON_B ? SceneMashAction::PRESS_B : SceneMashAction::WAIT; + default: + return SceneMashAction::WAIT; + } +} + + +SceneTimeline::SceneTimeline(SceneMachineConfig config, WallClock start) + : m_config(std::move(config)) + , m_quiet_from(start + m_config.min_length) + , m_last_busy(start) + , m_last_cue(start) +{} + +std::optional SceneTimeline::quiet_end_due() const{ + if (m_config.goal != SceneMashGoal::OVERWORLD || !m_config.quiet){ + return std::nullopt; + } + return std::max(m_quiet_from, m_last_busy + *m_config.quiet); +} + +bool SceneTimeline::blind_press_due(WallClock now) const{ + if (!m_config.blind_press_after || m_config.goal != SceneMashGoal::OVERWORLD || m_config.text_button != BUTTON_A){ + return false; + } + if (now - m_last_cue < *m_config.blind_press_after){ + return false; + } + return !m_last_blind_press || now - *m_last_blind_press >= BLIND_PRESS_EVERY; +} + +SceneScreen SceneTimeline::classify(const ScreenObservation& look) const{ + const bool choice = look.events.has(EngineEvent::CHOICE_BOX); + if (m_config.goal == SceneMashGoal::CHOICE && choice){ + return SceneScreen::GOAL_CHOICE; + } + if (m_config.goal == SceneMashGoal::BATTLE && look.events.has(EngineEvent::BATTLE)){ + return SceneScreen::GOAL_BATTLE; + } + if (look.events.has(EngineEvent::FADE_BLACK)){ + return SceneScreen::FADE_BLACK; + } + if (look.events.has(EngineEvent::FADE_WHITE)){ + return SceneScreen::FADE_WHITE; + } + if (choice){ + return SceneScreen::CHOICE; + } + if (text_shows(look)){ + return SceneScreen::DIALOG; + } + return classify_open(look); +} + +SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ + if (look.readings.contains(MISSION_COMPLETE_READING)){ + return SceneScreen::MISSION_COMPLETE; + } + if (m_config.goal == SceneMashGoal::OVERWORLD && banner_shows(look)){ + return m_banner_looks >= 1 ? SceneScreen::MISSION_BANNER : SceneScreen::BANNER_SHOWING; + } + if (m_config.goal == SceneMashGoal::OVERWORLD && look.events.has(EngineEvent::CAN_MOVE)){ + if (m_party_bar_since && look.when - *m_party_bar_since >= PARTY_BAR_HOLD){ + return SceneScreen::CAN_MOVE; + } + return SceneScreen::PARTY_BAR; + } + if (m_config.goal == SceneMashGoal::OVERWORLD && control_shows(look)){ + if (m_hint_since && look.when - *m_hint_since >= CONTROLS_HINT_HOLD){ + return SceneScreen::CONTROLS_HINT; + } + return SceneScreen::HINT_SHOWING; + } + const std::optional due = quiet_end_due(); + if (due && look.when >= *due && !busy(look)){ + return SceneScreen::QUIET_END; + } + // Not at an interact prompt: A would talk to whoever it names. + if (blind_press_due(look.when) && !look.events.has(EngineEvent::INTERACT_PROMPT)){ + return SceneScreen::BLIND_PRESS; + } + return look.events.has(EngineEvent::STILL) ? SceneScreen::SCENE_STILL : SceneScreen::SCENE_MOVING; +} + +namespace{ + +// Starts `since` when `shows` starts, clears it when it stops. +void track_since(bool shows, WallClock when, std::optional& since){ + if (!shows){ + since.reset(); + }else if (!since){ + since = when; + } +} + +} // namespace + +void SceneTimeline::record(const ScreenObservation& look){ + if (classify(look) == SceneScreen::BLIND_PRESS){ + m_last_blind_press = look.when; + } + if (busy(look)){ + m_last_busy = look.when; + } + const bool box = look.events.has(EngineEvent::TEXT_BOX) || look.events.has(EngineEvent::CHOICE_BOX); + track_since(look.events.has(EngineEvent::CAN_MOVE) && !box, look.when, m_party_bar_since); + track_since(control_shows(look) && !box, look.when, m_hint_since); + m_banner_looks = banner_shows(look) && !box ? m_banner_looks + 1 : 0; + if (busy(look) || m_party_bar_since || m_hint_since || m_banner_looks > 0){ + m_last_cue = look.when; + } +} + + +namespace{ + +// "text box, choice": a look's events for the log. +std::string describe_look(const ScreenObservation& look){ + const std::pair names[] = { + {EngineEvent::FADE_BLACK, "black fade"}, {EngineEvent::FADE_WHITE, "white fade"}, + {EngineEvent::TEXT_BOX, "text box"}, {EngineEvent::BATTLE, "battle"}, + {EngineEvent::CAN_MOVE, "party bar"}, {EngineEvent::STILL, "still"}, + }; + std::string text; + for (const auto& [event, name] : names){ + if (look.events.has(event)){ + text += std::format("{}{}", text.empty() ? "" : ", ", name); + } + } + if (look.events.has(EngineEvent::CHOICE_BOX)){ + text += text.empty() ? "choice" : ", choice"; + } + if (look.readings.contains(CONTROLS_HINT_READING)){ + text += text.empty() ? "controls hint" : ", controls hint"; + } + if (look.readings.contains(ADVANCE_ARROW_READING)){ + text += text.empty() ? "advance arrow" : ", advance arrow"; + } + if (look.readings.contains(MISSION_BANNER_READING)){ + text += text.empty() ? "mission banner" : ", mission banner"; + } + if (look.readings.contains(MISSION_COMPLETE_READING)){ + text += text.empty() ? "mission complete" : ", mission complete"; + } + return text.empty() ? "nothing" : text; +} + +// What the states share: the backend, the timeline and the look they act on. +class SceneRunner{ +public: + SceneRunner(PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, WallClock start) + : m_backend(backend) + , m_label(label) + , m_timeline(config, start) + {} + + const SceneTimeline& timeline() const{ + return m_timeline; + } + + // The step of `screen`, the state of `look`. + void act(SceneScreen screen, const ScreenObservation& look){ + m_timeline.record(look); + const std::string events = describe_look(look); + if (screen != m_logged_screen || events != m_logged_events){ + m_logged_screen = screen; + m_logged_events = events; + m_backend.log(std::format("[PLZA {}] {}: {}", m_label, scene_screen_name(screen), events)); + } + switch (scene_screen_action(screen, m_timeline.config())){ + case SceneMashAction::DONE: + return; + case SceneMashAction::PRESS_TEXT: + m_backend.press(m_timeline.config().text_button, 160ms, 240ms); + return; + case SceneMashAction::PRESS_A: + m_backend.press(BUTTON_A, 160ms, 240ms); + return; + case SceneMashAction::PRESS_B: + m_backend.press(BUTTON_B, 160ms, 240ms); + return; + case SceneMashAction::WAIT: + wait(screen); + return; + } + } + +private: + void wait(SceneScreen screen){ + switch (screen){ + case SceneScreen::FADE_BLACK: + case SceneScreen::FADE_WHITE: + wait_until(FADE_WAIT, [](const ScreenObservation& look){ + return !look.events.has(EngineEvent::FADE_BLACK) && !look.events.has(EngineEvent::FADE_WHITE); + }); + return; + case SceneScreen::SCENE_STILL: + wait_until(STILL_WAIT, [this](const ScreenObservation& look){ + const std::optional due = m_timeline.quiet_end_due(); + return (due && look.when >= *due) || m_timeline.blind_press_due(look.when) || + !look.events.has(EngineEvent::STILL); + }); + return; + case SceneScreen::PARTY_BAR: + case SceneScreen::HINT_SHOWING: + case SceneScreen::BANNER_SHOWING: + m_backend.wait(POLL); + return; + default: + m_backend.wait(2 * POLL); + return; + } + } + + // Looks every POLL until `done` or `limit`. + template + void wait_until(Milliseconds limit, Done&& done){ + for (Milliseconds waited = 0ms; waited < limit; waited += POLL){ + m_backend.wait(POLL); + if (done(m_backend.observe())){ + return; + } + } + } + + PlzaBackend& m_backend; + std::string m_label; + SceneTimeline m_timeline; + std::optional m_logged_screen; + std::string m_logged_events; +}; + +// How often a state may come up before the machine fails: a box or a +// choice that a press does not get past. +size_t max_visits(SceneScreen screen){ + switch (screen){ + case SceneScreen::DIALOG: + return 400; + case SceneScreen::CHOICE: + case SceneScreen::MISSION_COMPLETE: + return 30; + default: + return SIZE_MAX; + } +} + +// How long a state may see an unchanged screen: the waits (a fade, a +// still cutscene, the party bar held before it counts) for as long as +// they wait. Zero for the rest, whose presses must change the screen. +Milliseconds max_still(SceneScreen screen){ + switch (screen){ + case SceneScreen::FADE_BLACK: + case SceneScreen::FADE_WHITE: + return FADE_WAIT; + case SceneScreen::SCENE_STILL: + case SceneScreen::BLIND_PRESS: + // A blind A press need not change the screen. + return SCENE_STILL_WAIT; + case SceneScreen::PARTY_BAR: + case SceneScreen::HINT_SHOWING: + case SceneScreen::BANNER_SHOWING: + return STILL_WAIT; + default: + return Milliseconds::zero(); + } +} + +} // namespace + + +namespace{ + +// run_screen_machine_on_observations()'s failure as an Outcome. +Pokemon::Outcome scene_failure(std::string_view label, const std::string& failure){ + std::string_view kind = "scene_stuck"; + if (failure.starts_with("Did not finish")){ + kind = "scene_timeout"; + }else if (failure.starts_with("The screen matches none")){ + kind = "scene_unknown"; + } + return Pokemon::outcome_failed(std::string(kind), std::format("{}: {}", label, failure)); +} + +// Whether a new look shows the mission banner. +bool banner_still_shows(PlzaBackend& backend){ + return backend.observe().readings.contains(MISSION_BANNER_READING); +} + +// After the scene ended on the mission banner: looks until it has gone, +// so the next step starts with control, for at most BANNER_GONE_WAIT. +// Whether it went. +bool wait_banner_gone(PlzaBackend& backend, std::string_view label){ + for (Milliseconds waited = 0ms; waited < BANNER_GONE_WAIT; waited += POLL){ + if (!banner_still_shows(backend)){ + backend.log(std::format("[PLZA {}] the mission banner has gone after {} ms.", label, waited.count())); + return true; + } + backend.wait(POLL); + } + return false; +} + +// A banner that stayed past BANNER_GONE_WAIT: A up to BANNER_PRESSES +// times, BANNER_PRESS_EVERY apart, until it goes. +void press_banner_away(PlzaBackend& backend, std::string_view label){ + backend.log(std::format("[PLZA {}] the mission banner still shows after {} ms; pressing A.", label, BANNER_GONE_WAIT.count())); + for (size_t presses = 1; presses <= BANNER_PRESSES; presses++){ + backend.press(BUTTON_A, 160ms, 240ms); + backend.wait(BANNER_PRESS_EVERY); + if (!banner_still_shows(backend)){ + backend.log(std::format("[PLZA {}] the mission banner has gone after {} A presses.", label, presses)); + return; + } + } + backend.log(std::format("[PLZA {}] the mission banner still shows after {} A presses; going on.", label, BANNER_PRESSES)); +} + + +// The step's outcome from where the machine ended. +Pokemon::Outcome scene_outcome( + PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, const ScreenMachineResult& result +){ + if (!result.succeeded()){ + return scene_failure(label, result.failure); + } + if (result.terminal == scene_screen_name(SceneScreen::QUIET_END)){ + // Nothing busy for the quiet time, and no party bar or controls + // hint: a cutscene with no text, or control the detectors miss. + return Pokemon::outcome_failed("scene_quiet", std::format( + "{}: nothing busy for {} ms and no sign of control.", label, config.quiet ? config.quiet->count() : 0 + )); + } + if (result.terminal == scene_screen_name(SceneScreen::MISSION_BANNER) && !wait_banner_gone(backend, label)){ + press_banner_away(backend, label); + } + backend.log(std::format("[PLZA {}] done on {}.", label, result.terminal)); + return Pokemon::outcome_ok(); +} + + +} // namespace + + +Pokemon::Outcome run_scene_machine( + PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, Milliseconds timeout +){ + // The look the states match and act on. + Pokemon::Observation look = backend.observe(); + bool first = true; + SceneRunner runner(backend, label, config, look.when); + std::vector states; + for (const SceneScreen screen : ALL_SCREENS){ + ScreenState state; + state.name = std::string(scene_screen_name(screen)); + state.matches_observation = [&runner, screen](const ScreenObservation& observation){ + return runner.timeline().classify(observation) == screen; + }; + state.act = [&runner, &look, screen]{ + runner.act(screen, look); + }; + state.max_visits = max_visits(screen); + state.max_still = max_still(screen); + state.terminal = scene_screen_terminal(screen); + states.push_back(std::move(state)); + } + const std::function observe = [&backend, &look, &first]() -> ScreenObservation{ + if (!first){ + look = backend.observe(); + } + first = false; + return look; + }; + StepTrace trace(std::format("PLZA {}", label), [&backend](const std::string& line){ + backend.log(line); + }); + const ScreenMachineResult result = run_screen_machine_on_observations(observe, backend.scope(), states, timeout, trace); + return scene_outcome(backend, label, config, result); +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h new file mode 100644 index 0000000000..ccc45f31e3 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -0,0 +1,156 @@ +/* PokemonLZA AutoStory - Scene machine + * + * From: https://github.com/PokemonAutomation/ + * + * 01.00's scenes as ScreenMachine states (CommonTools/ScreenMachine) that + * match on what the backend observed (ScreenState::matches_observation), + * 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 is + * logged with the look's events. The player has control when the party + * bar or, in the tutorial (which has no party bar), the controls hint + * (CONTROLS_HINT_READING) holds a second. A main mission's banner + * (MISSION_BANNER_READING) on two looks in a row ends the scene too: it + * shows as the scene hands over control, and the machine then waits for + * it to go, pressing A if it stays. The card a main mission ends with + * (MISSION_COMPLETE_READING) waits for A: the machine presses A at it, + * and it counts as busy. The advance chevron (ADVANCE_ARROW_READING) is + * text to press on, with or without a box. + * + * The walks between the scenes are Actions/PokemonLZA_AutoStoryWalkScreenChecks.h. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStorySceneMachine_H +#define PokemonAutomation_PokemonLZA_AutoStorySceneMachine_H + +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "CommonTools/ScreenMachine/ScreenObservation.h" +#include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" +#include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryBackend.h" +#include "PokemonLZA_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// What a scene machine is after, and how it presses. +struct SceneMachineConfig{ + SceneMashGoal goal = SceneMashGoal::OVERWORLD; + // Advances the text (A or B). + Button text_button = BUTTON_A; + // OVERWORLD only: fails ("scene_quiet") once nothing busy (box, choice, + // battle, fade) and no sign of control has shown for this long... + std::optional quiet = std::nullopt; + // ...and this long has passed since the start: a cutscene can hold a + // still frame longer than `quiet`. + Milliseconds min_length = Milliseconds(0); + // OVERWORLD with A: presses A every 2 s once nothing + // busy and no sign of control has shown for this long, for text the + // detectors miss (A does not skip a cutscene). + std::optional blind_press_after = std::nullopt; +}; + +// The states a scene machine tells apart, in the order it tries them. +enum class SceneScreen{ + GOAL_CHOICE, // terminal: a choice, when it is the goal + GOAL_BATTLE, // terminal: the battle HUD, when it is the goal + FADE_BLACK, // wait until it lifts + FADE_WHITE, // wait until it lifts + CHOICE, // A: the top choice + DIALOG, // the text button: a box, or the advance chevron + MISSION_COMPLETE, // A: a main mission's "COMPLETE" card + MISSION_BANNER, // terminal: a main mission's banner, on a second look + BANNER_SHOWING, // wait: the banner, on its first look + CAN_MOVE, // terminal: the party bar, held a second + PARTY_BAR, // wait: the party bar, not held a second yet + CONTROLS_HINT, // terminal: the tutorial's controls hint, held a second + HINT_SHOWING, // wait: the controls hint, not held a second yet + QUIET_END, // terminal, failing: nothing busy for the quiet time, past the minimum length + BLIND_PRESS, // A: nothing busy and no sign of control for blind_press_after + SCENE_MOVING, // no box, the screen changing: a cutscene, or the player in control + SCENE_STILL, // no box, the screen still since the read before +}; + +// "fade_black", the state's name in the StepTrace log. +std::string_view scene_screen_name(SceneScreen screen); + +// Whether the machine ends after this state's step. +bool scene_screen_terminal(SceneScreen screen); + +// The press a state takes: DONE for a terminal state; WAIT for a fade, the +// party bar, and a screen with no box in an A mash (A would talk to whoever +// stands in front); PRESS_B there in a B mash (closes the map and Pokedex +// screens), PRESS_A when the goal is a battle (cards, the VS splash). +SceneMashAction scene_screen_action(SceneScreen screen, const SceneMachineConfig& config); + +// The time-dependent part of the machine, apart from the backend so tests +// can feed it looks: when the screen was last busy, since when the party +// bar shows. A look's time is its `when`. +class SceneTimeline{ +public: + SceneTimeline(SceneMachineConfig config, WallClock start); + + // The state for `look` (STILL: the screen barely changed since the + // look before). Does not change the timeline. + SceneScreen classify(const ScreenObservation& look) const; + + // Takes in the look the machine acted on. + void record(const ScreenObservation& look); + + // When the quiet end is due if nothing busy shows before; none + // without a quiet time. + std::optional quiet_end_due() const; + + // Whether a blind A press is due at `now` (blind_press_after). + bool blind_press_due(WallClock now) const; + + const SceneMachineConfig& config() const{ + return m_config; + } + +private: + SceneMachineConfig m_config; + WallClock m_quiet_from; + WallClock m_last_busy; + // The last look busy or with a sign of control (party bar, hint). + WallClock m_last_cue; + std::optional m_last_blind_press; + std::optional m_party_bar_since; + std::optional m_hint_since; + // The looks in a row with the mission banner. + size_t m_banner_looks = 0; + + // classify() past the fades, boxes and the goal. + SceneScreen classify_open(const ScreenObservation& look) const; +}; + + +// Presses through a scene until `config.goal` shows (OVERWORLD: the party +// bar or the controls hint held a second, or the mission banner on two +// looks, then up to 10 s for the banner to go and, if it stays, A up to 3 +// times 1 s apart), on run_screen_machine_on_observations(). +// `label` names its log lines ("[PLZA opening] dialog: text box"). Fails as +// "scene_quiet" on the quiet end, "scene_timeout" when `timeout` passes (by the looks' time), +// "scene_unknown" on a look no state takes and "scene_stuck" on a state +// that comes up too often or a screen that stops changing. +Pokemon::Outcome run_scene_machine( + PlzaBackend& backend, std::string_view label, const SceneMachineConfig& config, Milliseconds timeout +); + +// Registers the scene machine's tests: its states on sequences of events, +// no frames needed. +void add_tests_AutoStorySceneMachine(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp new file mode 100644 index 0000000000..22f2a5cef0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -0,0 +1,420 @@ +/* PokemonLZA AutoStory - Scene machine Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The scene machine's states on sequences of events, as PLZA's backend + * observes them (plza_observation()): no frames needed. + * + */ + +#include +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryGame.h" +#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStorySceneMachine.h" +#include "PokemonLZA_AutoStoryStoryFiles.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; +using Pokemon::ScreenEvent; +using Pokemon::ScreenEvents; + +namespace{ + +// One read of the screen and what the machine should make of it. +struct Read{ + Milliseconds at; + ScreenEvents events; + bool still; + SceneScreen expected; + // The controls hint (CONTROLS_HINT_READING) shows. + bool hint = false; + // The advance chevron (ADVANCE_ARROW_READING) shows. + bool arrow = false; + // The mission banner (MISSION_BANNER_READING) shows. + bool banner = false; + // The mission complete card (MISSION_COMPLETE_READING) shows. + bool complete = false; +}; + +// Feeds `reads` to a timeline as the machine does (classify, then record +// the read it acted on) and checks each state, until a terminal one. +UnitTestResult check_reads(const SceneMachineConfig& config, const std::vector& reads){ + const WallClock start = current_time(); + SceneTimeline timeline(config, start); + for (const Read& read : reads){ + ScreenObservation look = plza_observation(read.events); + look.when = start + read.at; + if (read.still){ + look.events.add(PokemonAutomation::ScreenEvent::STILL); + } + if (read.hint){ + look.readings[std::string(CONTROLS_HINT_READING)] = 1; + } + if (read.arrow){ + look.readings[std::string(ADVANCE_ARROW_READING)] = 1; + } + if (read.banner){ + look.readings[std::string(MISSION_BANNER_READING)] = 1; + } + if (read.complete){ + look.readings[std::string(MISSION_COMPLETE_READING)] = 1; + } + const SceneScreen got = timeline.classify(look); + if (got != read.expected){ + return std::format("at {} ms ({}): expected {}, got {}.", + read.at.count(), Pokemon::describe(read.events), + scene_screen_name(read.expected), scene_screen_name(got)); + } + timeline.record(look); + } + return true; +} + +SceneMachineConfig opening_config(Milliseconds min_length){ + SceneMachineConfig config; + config.quiet = 8000ms; + config.min_length = min_length; + return config; +} + +const ScreenEvents NOTHING{}; +const ScreenEvents DIALOG{ScreenEvent::DIALOG_BOX}; +const ScreenEvents CHOICE{ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX}; +const ScreenEvents PARTY_BAR{ScreenEvent::PLAYER_CAN_MOVE}; +const ScreenEvents WHITE{ScreenEvent::FADE_WHITE}; +const ScreenEvents BLACK{ScreenEvent::FADE_BLACK}; +const ScreenEvents BATTLE{ScreenEvent::BATTLE_STARTED}; +const ScreenEvents PROMPT{ScreenEvent::INTERACT_PROMPT}; + +// mash_to_move_hints' config: a minute quiet, blind A after 5 s. +SceneMachineConfig arrival_config(){ + SceneMachineConfig config; + config.quiet = 60000ms; + config.blind_press_after = 5000ms; + return config; +} + +// The opening: a still frame past the quiet time does not end it before +// the scene's minimum length; then it does. +UnitTestResult test_quiet_waits_for_min_length(Logger&){ + return check_reads(opening_config(60000ms), { + {0ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {5000ms, DIALOG, false, SceneScreen::DIALOG}, + {10000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {30000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {59900ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {60000ms, NOTHING, true, SceneScreen::QUIET_END}, + }); +} + +// A box restarts the quiet time; a fade counts as busy too. +UnitTestResult test_quiet_restarts_on_busy(Logger&){ + return check_reads(opening_config(0ms), { + {0ms, DIALOG, false, SceneScreen::DIALOG}, + {7900ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {7950ms, WHITE, false, SceneScreen::FADE_WHITE}, + {15000ms, WHITE, true, SceneScreen::FADE_WHITE}, + {20000ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {22900ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {23000ms, NOTHING, true, SceneScreen::QUIET_END}, + }); +} + +// The party bar ends the scene once it has held a second; a box between +// lines starts the second again. +UnitTestResult test_party_bar_held(Logger&){ + return check_reads(opening_config(60000ms), { + {0ms, PARTY_BAR, false, SceneScreen::PARTY_BAR}, + {500ms, PARTY_BAR, true, SceneScreen::PARTY_BAR}, + {600ms, DIALOG, false, SceneScreen::DIALOG}, + {800ms, PARTY_BAR, false, SceneScreen::PARTY_BAR}, + {1700ms, PARTY_BAR, true, SceneScreen::PARTY_BAR}, + {1800ms, PARTY_BAR, true, SceneScreen::CAN_MOVE}, + }); +} + +// The controls hint ends the scene once it has held a second, ahead of +// the quiet end; a box over it starts the second again. +UnitTestResult test_controls_hint_held(Logger&){ + return check_reads(opening_config(0ms), { + {0ms, NOTHING, false, SceneScreen::HINT_SHOWING, true}, + {600ms, DIALOG, false, SceneScreen::DIALOG, true}, + {900ms, NOTHING, false, SceneScreen::HINT_SHOWING, true}, + {1800ms, NOTHING, true, SceneScreen::HINT_SHOWING, true}, + {9000ms, NOTHING, true, SceneScreen::CONTROLS_HINT, true}, + }); +} + +// 01.01's ad: subtitles with no box. The advance chevron is text to press +// on; with nothing seen for 5 s, A every 2 s. An interact prompt is free +// control like the controls hint: one look stops the presses, held a +// second it ends the scene (01.02's battle area shows only the prompt). +UnitTestResult test_ad_subtitles(Logger&){ + return check_reads(arrival_config(), { + {0ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {1000ms, NOTHING, false, SceneScreen::DIALOG, false, true}, + {1500ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {3000ms, NOTHING, true, SceneScreen::DIALOG, false, true}, + {7900ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {8000ms, NOTHING, true, SceneScreen::BLIND_PRESS}, + {9000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {10000ms, NOTHING, false, SceneScreen::BLIND_PRESS}, + {12000ms, PROMPT, false, SceneScreen::HINT_SHOWING}, + {12100ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {14200ms, NOTHING, false, SceneScreen::HINT_SHOWING, true}, + {15000ms, NOTHING, true, SceneScreen::HINT_SHOWING, true}, + {15300ms, NOTHING, true, SceneScreen::CONTROLS_HINT, true}, + }); +} + +// 01.01's arrival (run 3, 2026-11-10 13:49): the last box, then "MAIN +// MISSION 01" over the scene. The banner's first look waits, its second +// ends the scene; a box between the two starts the count again. No blind +// A while it shows. +UnitTestResult test_mission_banner_ends(Logger&){ + return check_reads(arrival_config(), { + {0ms, DIALOG, false, SceneScreen::DIALOG}, + {500ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {6000ms, NOTHING, false, SceneScreen::BANNER_SHOWING, false, false, true}, + {6250ms, DIALOG, false, SceneScreen::DIALOG, false, false, true}, + {6500ms, NOTHING, false, SceneScreen::BANNER_SHOWING, false, false, true}, + {12000ms, NOTHING, true, SceneScreen::MISSION_BANNER, false, false, true}, + }); +} + +// 01.03's end (console B, 2026-11-10): the "MAIN MISSION 01 COMPLETE" +// card waits for A. Each look at it presses A, and it is busy: no blind +// press and no quiet end however long it shows, and a look with the +// banner's reading too is the card. Then "MAIN MISSION 02" ends the scene +// on its second look. +UnitTestResult test_mission_complete_presses_a(Logger&){ + SceneMachineConfig config = arrival_config(); + config.quiet = 8000ms; + return check_reads(config, { + {0ms, DIALOG, false, SceneScreen::DIALOG}, + {4000ms, NOTHING, false, SceneScreen::MISSION_COMPLETE, false, false, false, true}, + {9000ms, NOTHING, true, SceneScreen::MISSION_COMPLETE, false, false, false, true}, + {20000ms, NOTHING, true, SceneScreen::MISSION_COMPLETE, false, false, true, true}, + {20500ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {21000ms, NOTHING, false, SceneScreen::BANNER_SHOWING, false, false, true}, + {21250ms, NOTHING, true, SceneScreen::MISSION_BANNER, false, false, true}, + }); +} + +// The banner ends only a scene after the overworld: B to a choice +// presses on past it. +UnitTestResult test_mission_banner_only_overworld(Logger&){ + SceneMachineConfig config; + config.goal = SceneMashGoal::CHOICE; + config.text_button = BUTTON_B; + return check_reads(config, { + {0ms, NOTHING, false, SceneScreen::SCENE_MOVING, false, false, true}, + {500ms, NOTHING, false, SceneScreen::SCENE_MOVING, false, false, true}, + {1000ms, CHOICE, false, SceneScreen::GOAL_CHOICE}, + }); +} + +// Blind presses are not busy: a minute of them still ends quiet; and only +// an A mash after control presses blind. +UnitTestResult test_blind_press_keeps_quiet(Logger& logger){ + const UnitTestResult quiet = check_reads(arrival_config(), { + {0ms, NOTHING, false, SceneScreen::DIALOG, false, true}, + {5000ms, NOTHING, true, SceneScreen::BLIND_PRESS}, + {6000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {59000ms, NOTHING, true, SceneScreen::BLIND_PRESS}, + {60000ms, NOTHING, true, SceneScreen::QUIET_END}, + }); + if (quiet.result != UnitTestResult::PASSED){ + return quiet; + } + SceneMachineConfig to_choice = arrival_config(); + to_choice.goal = SceneMashGoal::CHOICE; + to_choice.text_button = BUTTON_B; + return check_reads(to_choice, { + {0ms, NOTHING, false, SceneScreen::DIALOG, false, true}, + {30000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + }); +} + +// Without a quiet time only the party bar ends an overworld scene: a +// still screen waits until the machine's timeout. +UnitTestResult test_no_quiet_never_ends_still(Logger&){ + SceneMachineConfig config; + return check_reads(config, { + {0ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {300000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {300100ms, BLACK, true, SceneScreen::FADE_BLACK}, + }); +} + +// Pancham cornered: B through the text and the scene, done at the choice. +UnitTestResult test_text_to_choice(Logger&){ + SceneMachineConfig config; + config.goal = SceneMashGoal::CHOICE; + config.text_button = BUTTON_B; + return check_reads(config, { + {0ms, NOTHING, false, SceneScreen::SCENE_MOVING}, + {1000ms, DIALOG, false, SceneScreen::DIALOG}, + {2000ms, PARTY_BAR, false, SceneScreen::SCENE_MOVING}, + {3000ms, CHOICE, false, SceneScreen::GOAL_CHOICE}, + }); +} + +// What each state presses. +UnitTestResult test_state_actions(Logger&){ + SceneMachineConfig a_mash = opening_config(0ms); + SceneMachineConfig b_to_choice; + b_to_choice.goal = SceneMashGoal::CHOICE; + b_to_choice.text_button = BUTTON_B; + SceneMachineConfig to_battle; + to_battle.goal = SceneMashGoal::BATTLE; + struct Case{ + SceneScreen screen; + const SceneMachineConfig& config; + SceneMashAction expected; + }; + const Case cases[] = { + {SceneScreen::DIALOG, a_mash, SceneMashAction::PRESS_TEXT}, + {SceneScreen::CHOICE, a_mash, SceneMashAction::PRESS_A}, + {SceneScreen::FADE_WHITE, a_mash, SceneMashAction::WAIT}, + {SceneScreen::FADE_BLACK, b_to_choice, SceneMashAction::WAIT}, + {SceneScreen::PARTY_BAR, a_mash, SceneMashAction::WAIT}, + {SceneScreen::SCENE_STILL, a_mash, SceneMashAction::WAIT}, + {SceneScreen::SCENE_MOVING, b_to_choice, SceneMashAction::PRESS_B}, + {SceneScreen::SCENE_MOVING, to_battle, SceneMashAction::PRESS_A}, + {SceneScreen::CAN_MOVE, a_mash, SceneMashAction::DONE}, + {SceneScreen::HINT_SHOWING, a_mash, SceneMashAction::WAIT}, + {SceneScreen::CONTROLS_HINT, a_mash, SceneMashAction::DONE}, + {SceneScreen::QUIET_END, a_mash, SceneMashAction::DONE}, + {SceneScreen::BLIND_PRESS, a_mash, SceneMashAction::PRESS_A}, + {SceneScreen::MISSION_COMPLETE, a_mash, SceneMashAction::PRESS_A}, + {SceneScreen::MISSION_COMPLETE, b_to_choice, SceneMashAction::PRESS_A}, + {SceneScreen::GOAL_CHOICE, b_to_choice, SceneMashAction::DONE}, + {SceneScreen::GOAL_BATTLE, to_battle, SceneMashAction::DONE}, + }; + for (const Case& item : cases){ + const SceneMashAction got = scene_screen_action(item.screen, item.config); + if (got != item.expected){ + return std::format("{}: expected action {}, got {}.", + scene_screen_name(item.screen), (int)item.expected, (int)got); + } + } + return true; +} + +// A battle goal presses A through cards and stops at the HUD. +UnitTestResult test_to_battle(Logger&){ + SceneMachineConfig config; + config.goal = SceneMashGoal::BATTLE; + return check_reads(config, { + {0ms, DIALOG, false, SceneScreen::DIALOG}, + {1000ms, NOTHING, true, SceneScreen::SCENE_STILL}, + {2000ms, BATTLE, false, SceneScreen::GOAL_BATTLE}, + }); +} + + +struct SceneMachineInput{ + std::string name; + std::function body; +}; + +struct SceneMachineExpectation{ +}; + +struct SceneMachineCase{ + SceneMachineInput input; + SceneMachineExpectation expectation; +}; + +class Test_AutoStorySceneMachine : public UnitTest{ +public: + explicit Test_AutoStorySceneMachine(SceneMachineCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStorySceneMachine - {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + return m_case.input.body(logger); + } + +private: + SceneMachineCase m_case; +}; + +} // namespace + + +const SceneMachineCase SCENE_MACHINE_CASES[] = { + { + .input = {"quiet end waits for the scene's minimum length", test_quiet_waits_for_min_length}, + .expectation = {}, + }, + { + .input = {"a box or a fade restarts the quiet time", test_quiet_restarts_on_busy}, + .expectation = {}, + }, + { + .input = {"the party bar held a second ends the scene", test_party_bar_held}, + .expectation = {}, + }, + { + .input = {"the controls hint held a second ends the scene", test_controls_hint_held}, + .expectation = {}, + }, + { + .input = {"the ad's subtitles: A at the chevron, blind A, none at the hint", test_ad_subtitles}, + .expectation = {}, + }, + { + .input = {"the mission banner on two looks ends the scene", test_mission_banner_ends}, + .expectation = {}, + }, + { + .input = {"the mission complete card: A, busy, wins over the banner", test_mission_complete_presses_a}, + .expectation = {}, + }, + { + .input = {"the mission banner does not end a mash to a choice", test_mission_banner_only_overworld}, + .expectation = {}, + }, + { + .input = {"blind presses keep the quiet end, and only in an A mash", test_blind_press_keeps_quiet}, + .expectation = {}, + }, + { + .input = {"without a quiet time a still screen never ends it", test_no_quiet_never_ends_still}, + .expectation = {}, + }, + { + .input = {"B through the text to the choice", test_text_to_choice}, + .expectation = {}, + }, + { + .input = {"A through the cards to the battle HUD", test_to_battle}, + .expectation = {}, + }, + { + .input = {"what each state presses", test_state_actions}, + .expectation = {}, + }, +}; + +void add_tests_AutoStorySceneMachine(UnitTestDatabase& database){ + for (const SceneMachineCase& item : SCENE_MACHINE_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp new file mode 100644 index 0000000000..e63a819236 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp @@ -0,0 +1,114 @@ +/* PLZA AutoStory - Screen Events + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" +#include "CommonTools/Images/SolidColorTest.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h" +#include "PokemonLZA_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using Pokemon::ScreenEvent; +using Pokemon::ScreenEvents; + +namespace{ + +// Where an interact prompt shows: over the scene, above the bottom hints +// (the battle HUD's "X A Select Move" is lower). +const ImageFloatBox INTERACT_PROMPT_BOX{0.3, 0.2, 0.4, 0.65}; +// The battle HUD's hints at the bottom centre: the A of "X A: Select Move" +// (za2_hud_s3, za2_atk*: 15 of 15 battle frames, none of 442 others). +const ImageFloatBox BATTLE_HINT_BOX{0.40, 0.84, 0.20, 0.10}; +// A white dialogue box's bottom edge, FlatWhiteDialogDetector's strip. +const ImageFloatBox WHITE_BOX_EDGE{0.265, 0.931, 0.465, 0.020}; + +} // namespace + + +SceneMashAction scene_mash_action(const ScreenEvents& events, SceneMashGoal goal, bool text_button_is_b){ + switch (goal){ + case SceneMashGoal::CHOICE: + if (events.has(ScreenEvent::CHOICE_BOX)){ + return SceneMashAction::DONE; + } + break; + case SceneMashGoal::BATTLE: + if (events.has(ScreenEvent::BATTLE_STARTED)){ + return SceneMashAction::DONE; + } + break; + case SceneMashGoal::OVERWORLD: + if (events.has(ScreenEvent::PLAYER_CAN_MOVE)){ + return SceneMashAction::DONE; + } + break; + } + if (events.has(ScreenEvent::FADE_BLACK) || events.has(ScreenEvent::FADE_WHITE)){ + return SceneMashAction::WAIT; + } + if (events.has(ScreenEvent::CHOICE_BOX)){ + return SceneMashAction::PRESS_A; + } + if (events.has(ScreenEvent::DIALOG_BOX)){ + return SceneMashAction::PRESS_TEXT; + } + if (goal == SceneMashGoal::BATTLE){ + return SceneMashAction::PRESS_A; + } + return text_button_is_b ? SceneMashAction::PRESS_B : SceneMashAction::WAIT; +} + + +PlzaScreenObserver::PlzaScreenObserver() + : m_blue_dialog(COLOR_BLUE) + , m_teal_dialog(COLOR_GREEN) + , 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_party(COLOR_WHITE) +{} + +ScreenEvents PlzaScreenObserver::observe(const VideoSnapshot& frame, WallClock){ + if (!frame){ + return {}; + } + return read(*frame.frame); +} + +ScreenEvents PlzaScreenObserver::read(const ImageViewRGB32& screen){ + ScreenEvents out = Pokemon::fade_events(Pokemon::fade_of_screen(screen)); + if (Pokemon::fade_in(out) != Pokemon::WarpFade::NONE){ + // A uniform screen has no box, prompt or HUD to read. + return out; + } + const bool box = is_white(extract_box_reference(screen, WHITE_BOX_EDGE), 500.0, 20.0) + || m_blue_dialog.detect(screen) || m_teal_dialog.detect(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::PLAYER_CAN_MOVE, !box && m_party.detect(screen)); + return out; +} + +void PlzaScreenObserver::make_overlays(VideoOverlaySet& items) const{ + items.add(COLOR_RED, WHITE_BOX_EDGE); + m_blue_dialog.make_overlays(items); + m_teal_dialog.make_overlays(items); + m_choice_arrow.make_overlays(items); + m_interact.make_overlays(items); + m_battle_hint.make_overlays(items); + m_party.make_overlays(items); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h new file mode 100644 index 0000000000..bd319f3437 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h @@ -0,0 +1,95 @@ +/* PLZA AutoStory - Screen Events + * + * From: https://github.com/PokemonAutomation/ + * + * PLZA's detectors as the shared screen events (Pokemon_ScreenEvents.h), + * so the shared judgements (Pokemon_SceneJudges.h) read PLZA frames too. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryScreenEvents_H +#define PokemonAutomation_PokemonLZA_AutoStoryScreenEvents_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_ButtonDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" +#include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The shared events from PLZA's detectors: +// - DIALOG_BOX: a white dialogue box's bottom edge (FlatWhiteDialogDetector's +// strip, without its advance arrow: the box shows while the text still +// types), or a blue or teal box; +// - CHOICE_BOX: the selection arrow among a dialogue's choices; +// - INTERACT_PROMPT: an A prompt over the scene ("A Talk", "A Take Elevator"); +// - BATTLE_STARTED: the battle HUD's hints at the bottom centre ("ZL: Focus +// on a Pokemon", "X A: Select Move"), read by their A icon. Story battles +// show no Run prompt, so RunFromBattleDetector misses them; +// - PLAYER_CAN_MOVE: the party bar at the bottom left, with no box; +// - FADE_BLACK / FADE_WHITE: fade_of_screen(). +// Follow-up: the party bar is missed in some rooms (Hotel Z's hall, +// za2_m3x). The tutorial's "Move / Control Camera" hint is the story +// backend's CONTROLS_HINT_READING (ControlsHintDetector), not an event here. +class PlzaScreenObserver : public Pokemon::ScreenEventObserver{ +public: + PlzaScreenObserver(); + + virtual Pokemon::ScreenEvents observe(const VideoSnapshot& frame, WallClock now) override; + // observe() for a frame that is not a snapshot (a ScreenState's read). + Pokemon::ScreenEvents read(const ImageViewRGB32& screen); + virtual void make_overlays(VideoOverlaySet& items) const override; + +private: + BlueDialogDetector m_blue_dialog; + TealDialogDetector m_teal_dialog; + SelectionArrowDetector m_choice_arrow; + ButtonDetector m_interact; + ButtonDetector m_battle_hint; + OverworldPartySelectionDetector m_party; +}; + +// What a scene mash is after: the overworld back, a choice on screen +// (pressing nothing that would pick one), or a story battle's HUD. +enum class SceneMashGoal{ + OVERWORLD, + CHOICE, + BATTLE, +}; + +// What a scene mash does on one frame. +enum class SceneMashAction{ + WAIT, // nothing: a fade, or a quiet screen the goal waits out + PRESS_TEXT, // the mash's text button (A or B) at a dialogue box + PRESS_A, // A: the top choice, or a tutorial card / splash (B does not close them) + PRESS_B, // B on a screen with no box: closes the map and Pokedex screens + DONE, // the goal shows +}; + +// How a scene mash reads a frame's events (the console loop is +// mash_scene() in PokemonLZA_AutoStoryActions.h): +// - the goal's event ends it (OVERWORLD: PLAYER_CAN_MOVE; the caller holds +// it a second, since the party bar also shows between lines); +// - a fade waits; +// - a choice takes its top row with A, except when the goal is the choice; +// - a box gets the text button; +// - with no box: BATTLE presses A (cards, the VS splash), a B mash presses +// B (it closes the screens a talk opens), an A mash waits (A would talk +// to whoever stands in front). +SceneMashAction scene_mash_action(const Pokemon::ScreenEvents& events, SceneMashGoal goal, bool text_button_is_b); + +// Registers the adapter's image tests (lab-B frames, 2026-11-08; they live +// in CommandLineTests, PokemonLZA/AutoStoryScreenEvents/). +void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp new file mode 100644 index 0000000000..369b512048 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp @@ -0,0 +1,130 @@ +/* PLZA AutoStory - Screen Events Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The adapter on lab-B frames from 2026-11-08 (1920x1080), kept in + * CommandLineTests under PokemonLZA/AutoStoryScreenEvents/. + * + */ + +#include +#include +#include +#include +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "Tests/ImageUnitTest.h" +#include "PokemonLZA_AutoStoryScreenEvents.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using Pokemon::ScreenEvent; +using Pokemon::ScreenEvents; + +namespace{ + +struct ScreenEventsInput{ + // The frame, under PokemonLZA/AutoStoryScreenEvents/. + std::string frame; +}; + +struct ScreenEventsExpectation{ + ScreenEvents events; +}; + +struct ScreenEventsCase{ + ScreenEventsInput input; + ScreenEventsExpectation expectation; +}; + +class Test_AutoStoryScreenEvents : public ImageUnitTest{ +public: + explicit Test_AutoStoryScreenEvents(ScreenEventsCase test_case) + : ImageUnitTest( + std::format("PokemonLZA::AutoStoryScreenEvents - {}", test_case.input.frame), + {std::format("PokemonLZA/AutoStoryScreenEvents/{}", test_case.input.frame)} + ) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, + const std::vector& images + ) const override{ + PlzaScreenObserver observer; + const ScreenEvents got = observer.observe(VideoSnapshot(images[0].copy(), WallClock()), WallClock()); + if (got != m_case.expectation.events){ + return std::format("expected {}, got {}", describe(m_case.expectation.events), describe(got)); + } + return true; + } + +private: + ScreenEventsCase m_case; +}; + +} // namespace + + +const ScreenEventsCase SCREEN_EVENTS_CASES[] = { + { + .input = {"za2_m3o_s1.png"}, + .expectation = {{ScreenEvent::INTERACT_PROMPT, ScreenEvent::PLAYER_CAN_MOVE}}, + }, + { + .input = {"za2_m3p_s1.png"}, + .expectation = {{ScreenEvent::INTERACT_PROMPT, ScreenEvent::PLAYER_CAN_MOVE}}, + }, + { + .input = {"za2_m3v_s1.png"}, + .expectation = {{ScreenEvent::INTERACT_PROMPT}}, + }, + { + .input = {"za2_m2q_s1.png"}, + .expectation = {{ScreenEvent::PLAYER_CAN_MOVE}}, + }, + { + .input = {"za2_hud_s3.png"}, + .expectation = {{ScreenEvent::BATTLE_STARTED}}, + }, + { + .input = {"za2_m2n_s1.png"}, + .expectation = {{ScreenEvent::BATTLE_STARTED}}, + }, + { + // The battle tutorial's card, before the HUD. + .input = {"za2_hud_s1.png"}, + .expectation = {{}}, + }, + { + // A white box while its text still types: no advance arrow yet. + .input = {"za2_m3s_s1.png"}, + .expectation = {{ScreenEvent::DIALOG_BOX}}, + }, + { + .input = {"za2_fight2_s1.png"}, + .expectation = {{ScreenEvent::DIALOG_BOX}}, + }, + { + .input = {"za2_m3w_s2.png"}, + .expectation = {{ScreenEvent::CHOICE_BOX}}, + }, + { + .input = {"za2_m2m_s1.png"}, + .expectation = {{ScreenEvent::FADE_BLACK}}, + }, +}; + +void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database){ + for (const auto& item : SCREEN_EVENTS_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp new file mode 100644 index 0000000000..f476c912cb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp @@ -0,0 +1,106 @@ +/* PokemonLZA AutoStory - Step validator + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "PokemonLZA_AutoStoryStepValidator.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +using Pokemon::StoryStepKind; + + +namespace{ + +using IntegerRows = std::vector>; + +// What is wrong with the legs `rows` of step `step`: each a [turn, ms] +// pair turning at most half a turn either way and walking no negative +// time, and at least one that walks. +void add_legs_errors(std::string_view step, std::string_view key, const IntegerRows& rows, std::vector& errors){ + if (rows.empty()){ + errors.push_back(std::format("{}: {} has no legs", step, key)); + return; + } + bool goes = false; + for (size_t i = 0; i < rows.size(); i++){ + const std::vector& row = rows[i]; + if (row.size() != 2){ + errors.push_back(std::format("{}: {} leg {} needs 2 numbers [turn, ms], has {}", step, key, i, row.size())); + continue; + } + if (row[0] < -180 || row[0] > 180){ + errors.push_back(std::format("{}: {} leg {} turns {} deg, expected -180 to 180", step, key, i, row[0])); + } + if (row[1] < 0){ + errors.push_back(std::format("{}: {} leg {} walks {} ms, expected 0 or more", step, key, i, row[1])); + } + goes = goes || row[1] > 0; + } + if (!goes){ + errors.push_back(std::format("{}: {} walks nowhere", step, key)); + } +} + +} // namespace + + +// A walk's "end" arg as the event it ends on: a fade. +std::optional walk_end_event(std::string_view end){ + if (end == "fade_white"){ + return Pokemon::ScreenEvent::FADE_WHITE; + } + if (end == "fade_black"){ + return Pokemon::ScreenEvent::FADE_BLACK; + } + return std::nullopt; +} + +// What is wrong with the args of a "walk" step; +// nothing for any other step. +std::vector plza_step_arg_errors(const Pokemon::StoryStep& step){ + std::vector errors; + if (step.kind != StoryStepKind::GAME){ + return errors; + } + if (step.action != "walk"){ + return errors; + } + const auto legs = step.args.find("legs"); + if (legs == step.args.end()){ + return errors; + } + const IntegerRows& rows = std::get(legs->second); + add_legs_errors(step.name, "legs", rows, errors); + const auto end = step.args.find("end"); + if (end != step.args.end()){ + const std::string& name = std::get(end->second); + if (!walk_end_event(name)){ + errors.push_back(std::format("{}: end {} is not \"fade_white\" or \"fade_black\"", step.name, name)); + } + if (rows.empty() || rows.back().size() != 2 || rows.back()[1] <= 0){ + errors.push_back(std::format("{}: the last leg has no walk to hold until the end", step.name)); + } + } + const auto heading = step.args.find("heading"); + if (heading != step.args.end()){ + const int64_t degrees = std::get(heading->second); + if (degrees < 0 || degrees >= 360){ + errors.push_back(std::format("{}: heading {} deg, expected 0 to 359", step.name, degrees)); + } + } + return errors; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h new file mode 100644 index 0000000000..66013a5ec7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h @@ -0,0 +1,42 @@ +/* PokemonLZA AutoStory - Step validator + * + * From: https://github.com/PokemonAutomation/ + * + * PLZA's checks of a story step's args beyond their types, which the + * engine's lint (StoryActionRegistry::lint) checks: a walk's legs, its end + * fade and heading. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryStepValidator_H +#define PokemonAutomation_PokemonLZA_AutoStoryStepValidator_H + +#include +#include +#include +#include +#include "Pokemon/AutoStory/Pokemon_ScreenEventTypes.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" +#include "PokemonLZA_AutoStoryBackend.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A walk's "end" arg as the event it ends on: "fade_white" or +// "fade_black"; nothing for any other name. +std::optional walk_end_event(std::string_view end); + +// What is wrong with the args of a "walk" step: +// each leg a [turn, ms] pair, turning -180 to 180 degrees and walking 0 ms +// or more, some leg walking; an end a fade, after a leg that walks; a +// heading 0 to 359. Nothing for any other step. +std::vector plza_step_arg_errors(const Pokemon::StoryStep& step); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp new file mode 100644 index 0000000000..dfd7ef5d7a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp @@ -0,0 +1,128 @@ +/* PokemonLZA AutoStory - Story files + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/Json/JsonValue.h" +#include "Pokemon/AutoStory/Data/Pokemon_AuthoredCheckpointJson.h" +#include "PokemonLZA_AutoStoryGame.h" +#include "PokemonLZA_AutoStoryStoryFiles.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using Pokemon::StoryCheckpoint; + + +namespace{ + +// A checkpoint file's checkpoint, and whether its execution says the game +// autosaves at its end. `source` names the file in parse errors. +std::pair read_checkpoint_file(std::string_view text, std::string_view source){ + bool autosave = false; + const Pokemon::ExecutionReader read_execution = [&autosave](const JsonObject& execution, std::string_view where){ + Pokemon::validate_json_fields(execution, {"save"}, where); + const std::string& save = execution.get_string_throw("save"); + if (save != "autosave" && save != "menu"){ + throw ParseException(std::format("{}: save must be \"autosave\" or \"menu\", not {}", where, save)); + } + autosave = save == "autosave"; + }; + StoryCheckpoint checkpoint = Pokemon::read_authored_checkpoint( + parse_json(std::string(text)), "plza", source, read_execution, plza_story_specs() + ); + return {std::move(checkpoint), autosave}; +} + +// The dev file of `dev_files` named `name`, if any. +const StoryDevFile* find_dev_file(std::span dev_files, std::string_view name){ + for (const StoryDevFile& file : dev_files){ + if (file.name == name){ + return &file; + } + } + return nullptr; +} + +// `dev`'s checkpoint, which replaces `builtin`'s: it must lint and keep its +// id, so the run's start and end indices still mean the same rows. +std::pair read_dev_checkpoint(const StoryDevFile& dev, std::string_view builtin_text, std::string_view builtin_name){ + std::pair read; + try{ + read = read_checkpoint_file(dev.text, dev.path); + }catch (ParseException& e){ + // Malformed JSON says nothing of where it came from. + if (e.message().find(dev.path) == std::string::npos){ + throw ParseException(std::format("{}: {}", dev.path, e.message())); + } + throw; + } + const std::string builtin_id = read_checkpoint_file(builtin_text, builtin_name).first.id; + if (read.first.id != builtin_id){ + throw ParseException(std::format("{}: checkpoint id {} does not match the built-in {}", dev.path, read.first.id, builtin_id)); + } + const std::vector problems = plza_story_lint(read.first); + if (!problems.empty()){ + throw ParseException(std::format("{}: {}", dev.path, problems.front())); + } + return read; +} + +} // namespace + + +StoryData load_story_data(std::span dev_files){ + for (const StoryDevFile& dev : dev_files){ + bool known = false; + for (const auto& [name, text] : autostory_checkpoint_json()){ + known |= dev.name == std::format("{}.json", name); + } + if (!known){ + throw ParseException(std::format("{}: no built-in checkpoint file is named {}", dev.path, dev.name)); + } + } + StoryData data; + for (const auto& [name, text] : autostory_checkpoint_json()){ + const std::string file_name = std::format("{}.json", name); + const StoryDevFile* dev = find_dev_file(dev_files, file_name); + auto [checkpoint, autosave] = dev == nullptr + ? read_checkpoint_file(text, name) + : read_dev_checkpoint(*dev, text, name); + if (dev != nullptr){ + data.dev_files.emplace_back(file_name, dev->path); + } + if (autosave){ + data.autosaves.insert(checkpoint.id); + } + data.checkpoints.push_back(std::move(checkpoint)); + } + return data; +} + +const StoryData& builtin_story_data(){ + static const StoryData data = load_story_data({}); + return data; +} + +const std::vector& story_checkpoints(){ + return builtin_story_data().checkpoints; +} + +const std::set>& story_autosave_rows(){ + return builtin_story_data().autosaves; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h new file mode 100644 index 0000000000..9b03fe90bc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h @@ -0,0 +1,61 @@ +/* PokemonLZA AutoStory - Story files + * + * From: https://github.com/PokemonAutomation/ + * + * Where the story (PokemonLZA_AutoStoryTable.h) is read from: the + * checked-in checkpoint files, StoryData/plza-.plan.json, built into + * the program, and for lab tuning the files of story_dev_folder() + * (PokemonLZA_AutoStoryDevFiles.h), each in place of the built-in one of + * the same name, so a walk can be retimed without a rebuild. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryStoryFiles_H +#define PokemonAutomation_PokemonLZA_AutoStoryStoryFiles_H + +#include +#include +#include +#include +#include +#include +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" +#include "PokemonLZA_AutoStoryDevFiles.h" +#include "PokemonLZA_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The checked-in checkpoint files, StoryData/plza-.plan.json, built +// into the program (cmake/EmbedTextFiles.cmake): (name, text), by name. +const std::vector>& autostory_checkpoint_json(); + +// The built-in checkpoints, each of `dev_files` in place of the one of the +// same file name. Throws ParseException naming the file when a dev file +// does not parse, fails plza_story_lint(), matches no built-in file or +// changes its checkpoint's id. +StoryData load_story_data(std::span dev_files); + +// The built-in story, load_story_data() with no dev files, read once. +const StoryData& builtin_story_data(); + +// The built-in story (load_story_data() with no dev files), read once: +// what the tests, the lint and the program's dropdowns use: 01.00, a new +// game to the station platform, which starts on the title screen without +// a save. +const std::vector& story_checkpoints(); + +// The built-in rows that end on one of the game's autosaves. Each ends +// where the game autosaved in the recording, so the next row reloads +// there. The menu (X, then R) can save from the start of the story too: +// 01.03 saves through it after Andi (console B, 2026-11-10). +const std::set>& story_autosave_rows(); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp new file mode 100644 index 0000000000..f3b56a684c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -0,0 +1,40 @@ +/* PokemonLZA AutoStory - Story table + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryGame.h" +#include "PokemonLZA_AutoStoryTable.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using Pokemon::StoryCheckpoint; +using Pokemon::StoryStep; +using Pokemon::StoryStepKind; + + +bool story_row_saves(const StoryData& story, const StoryCheckpoint& row){ + return !story.autosaves.contains(row.id); +} + +size_t story_rows_ready(const std::vector& checkpoints){ + size_t ready = 0; + for (const StoryCheckpoint& checkpoint : checkpoints){ + for (const StoryStep& step : checkpoint.steps){ + if (step.kind == StoryStepKind::GAME && story_actions_not_implemented().contains(step.action)){ + return ready; + } + } + ready++; + } + return ready; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h new file mode 100644 index 0000000000..4b0ff85830 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -0,0 +1,62 @@ +/* PokemonLZA AutoStory - Story table + * + * From: https://github.com/PokemonAutomation/ + * + * The story as rows of the shared story steps + * (Pokemon/AutoStory/Types/Pokemon_StoryStep.h), plain data as BDSP's and + * FRLG's tables are, so unit tests can check it without a console. + * + * Lumiose has no tile grid, so a row's poses name a place and nothing more, + * and a walk in the overworld is a GAME "walk" step whose args hold its + * legs: a relative turn and a walk time each (PokemonLZA_AutoStoryGame.h). + * + * Recorded 2026-11-08/09 on console B, played step by step from a new + * game. Every walk was measured walking, not dashing. Steps the game + * has no code for yet are GAME steps of story_actions_not_implemented(). + * + * This is the story as data, with no IO: the checkpoint files it is read + * from, built in or from the dev folder, are PokemonLZA_AutoStoryStoryFiles.h. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryTable_H +#define PokemonAutomation_PokemonLZA_AutoStoryTable_H + +#include +#include +#include +#include +#include +#include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The story a run plays: its checkpoints in order, and the ids of those +// that end on one of the game's autosaves and do not save themselves +// (their JSON "execution": {"save": "autosave"}). +struct StoryData{ + std::vector checkpoints; + std::set> autosaves; + // The dev files that replaced a built-in checkpoint, as (file name, + // path). + std::vector> dev_files; +}; + +// Whether `row` of `story` saves through the menu at its end: every row +// but the autosave rows. The menu (X, then R) can save from the start of +// the story too: 01.03 saves through it after Andi (console B, 2026-11-10). +bool story_row_saves(const StoryData& story, const Pokemon::StoryCheckpoint& row); + +// How many rows of `checkpoints` from the first need no action of +// story_actions_not_implemented(): the part of the story a run can play. +size_t story_rows_ready(const std::vector& checkpoints); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp new file mode 100644 index 0000000000..7dd89b2ed6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -0,0 +1,211 @@ +/* PokemonLZA AutoStory - Story table Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryGame.h" +#include "PokemonLZA_AutoStoryScreenEvents.h" +#include "PokemonLZA_AutoStoryStoryFiles.h" +#include "PokemonLZA_AutoStoryTable_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +using Pokemon::StoryCheckpoint; +using Pokemon::StoryStep; +using Pokemon::StoryStepKind; + +// The table: ids unique and in order, each row but the new game starts +// somewhere, and each lints against PLZA's actions in the engine. +UnitTestResult test_story_table_lints(Logger&){ + std::string previous; + for (const StoryCheckpoint& row : story_checkpoints()){ + if (row.id <= previous){ + return std::format("{}: repeated or out of order after {}.", row.id, previous); + } + previous = row.id; + if (!row.start && row.id != "01.00"){ + return std::format("{}: no start; every row after the new game starts from a save.", row.id); + } + const std::vector problems = plza_story_lint(row); + if (!problems.empty()){ + return problems[0]; + } + } + if (story_checkpoints().empty() || story_checkpoints().front().id != "01.00"){ + return "Expected the table to start at 01.00, the new game."; + } + return true; +} + +// Each action that is not implemented says what it waits for, is no move's +// name, and is in a step. +UnitTestResult test_not_implemented_actions(Logger&){ + std::set used; + for (const StoryCheckpoint& row : story_checkpoints()){ + for (const StoryStep& step : row.steps){ + if (step.kind == StoryStepKind::GAME){ + used.insert(step.action); + } + } + } + for (const auto& [name, todo] : story_actions_not_implemented()){ + if (todo.empty()){ + return std::format("{}: no TODO.", name); + } + if (name == "walk" || name == "approach_starter"){ + return std::format("{}: also a walk's action.", name); + } + if (!used.contains(name)){ + return std::format("{}: in no step.", name); + } + } + return true; +} + +// Every autosave row is in the table, and 01.03 saves through the menu +// (the menu can save from the start of the story). +UnitTestResult test_autosave_rows(Logger&){ + size_t seen = 0; + for (const StoryCheckpoint& row : story_checkpoints()){ + if (row.id == "01.03" && !story_row_saves(builtin_story_data(), row)){ + return "Expected 01.03 to save through the menu."; + } + if (!story_row_saves(builtin_story_data(), row)){ + seen++; + } + } + if (seen != story_autosave_rows().size()){ + return std::format("Expected {} autosave rows in the table, found {}.", story_autosave_rows().size(), seen); + } + return true; +} + +// A run can play every row: none names an action that is not implemented. +UnitTestResult test_every_row_ready(Logger&){ + const size_t ready = story_rows_ready(story_checkpoints()); + if (ready != story_checkpoints().size()){ + return std::format("Expected all {} rows to be ready, {} are.", story_checkpoints().size(), ready); + } + return true; +} + +// scene_mash_action() on each kind of frame. +UnitTestResult test_scene_mash_rule(Logger&){ + using Pokemon::ScreenEvent; + using Pokemon::ScreenEvents; + struct Case{ + std::string_view name; + ScreenEvents events; + SceneMashGoal goal; + bool text_b; + SceneMashAction expected; + }; + const Case cases[] = { + {"box, A mash", {ScreenEvent::DIALOG_BOX}, SceneMashGoal::OVERWORLD, false, SceneMashAction::PRESS_TEXT}, + {"box, B mash", {ScreenEvent::DIALOG_BOX}, SceneMashGoal::OVERWORLD, true, SceneMashAction::PRESS_TEXT}, + {"choice takes the top", {ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX}, SceneMashGoal::OVERWORLD, true, SceneMashAction::PRESS_A}, + {"choice is the goal", {ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX}, SceneMashGoal::CHOICE, true, SceneMashAction::DONE}, + {"party bar", {ScreenEvent::PLAYER_CAN_MOVE}, SceneMashGoal::OVERWORLD, false, SceneMashAction::DONE}, + {"party bar, not the goal", {ScreenEvent::PLAYER_CAN_MOVE}, SceneMashGoal::BATTLE, false, SceneMashAction::PRESS_A}, + {"black fade waits", {ScreenEvent::FADE_BLACK}, SceneMashGoal::BATTLE, false, SceneMashAction::WAIT}, + {"white fade waits", {ScreenEvent::FADE_WHITE}, SceneMashGoal::OVERWORLD, true, SceneMashAction::WAIT}, + {"battle HUD", {ScreenEvent::BATTLE_STARTED}, SceneMashGoal::BATTLE, false, SceneMashAction::DONE}, + {"card before a battle", {}, SceneMashGoal::BATTLE, false, SceneMashAction::PRESS_A}, + {"quiet, A mash", {}, SceneMashGoal::OVERWORLD, false, SceneMashAction::WAIT}, + {"quiet, B mash (map, Pokedex)", {}, SceneMashGoal::OVERWORLD, true, SceneMashAction::PRESS_B}, + {"prompt alone, A mash", {ScreenEvent::INTERACT_PROMPT}, SceneMashGoal::OVERWORLD, false, SceneMashAction::WAIT}, + }; + for (const Case& item : cases){ + const SceneMashAction got = scene_mash_action(item.events, item.goal, item.text_b); + if (got != item.expected){ + return std::format("{}: expected action {}, got {}.", item.name, (int)item.expected, (int)got); + } + } + return true; +} + + +struct AutoStoryTableInput{ + std::string name; + std::function body; +}; + +struct AutoStoryTableExpectation{ +}; + +struct AutoStoryTableCase{ + AutoStoryTableInput input; + AutoStoryTableExpectation expectation; +}; + +class Test_AutoStoryTable : public UnitTest{ +public: + explicit Test_AutoStoryTable(AutoStoryTableCase test_case) + : UnitTest(std::format("PokemonLZA::AutoStory - {}", test_case.input.name)) + , m_case(std::move(test_case)) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + try{ + return m_case.input.body(logger); + }catch (Exception& e){ + return std::format("{}: {}", e.name(), e.message()); + } + } + +private: + AutoStoryTableCase m_case; +}; + +} // namespace + + +const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { + { + .input = {"Story table: rows lint against PLZA's engine actions", test_story_table_lints}, + .expectation = {}, + }, + { + .input = {"Story table: actions not implemented say what they wait for", test_not_implemented_actions}, + .expectation = {}, + }, + { + .input = {"Story table: the autosave rows, and 01.03 saves through the menu", test_autosave_rows}, + .expectation = {}, + }, + { + .input = {"Story table: every row is ready", test_every_row_ready}, + .expectation = {}, + }, + { + .input = {"Scene mash: what each frame presses", test_scene_mash_rule}, + .expectation = {}, + }, +}; + +void add_tests_AutoStory_StoryTable(UnitTestDatabase& database){ + for (const AutoStoryTableCase& item : AUTO_STORY_TABLE_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h new file mode 100644 index 0000000000..fe82988970 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - Story table Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryTable_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryTable_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Tests that need no console: the story table lints against PLZA's engine +// actions, its moves are known, and its autosave rows come first. +void add_tests_AutoStory_StoryTable(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/ReferenceData/plza-platform.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/ReferenceData/plza-platform.json new file mode 100644 index 0000000000..1e673d8cca --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/ReferenceData/plza-platform.json @@ -0,0 +1,70 @@ +{ + "source": "platform_ref.png: console B, the station platform right after the opening cutscene (default camera)", + "regions": { + "top": { + "cols": 64, + "rows": [ + "96dbf56fa2a7364b27577a55a2e8ffa8edffadf1ffb2f4ffb6f6ffb3f7ffb0f6ff9ee2f090d3e6a6edfca8f1ffa6f0ffa3eeff73a7bb234156476f8774afc846698241657d21415a243a4047658321436244668048687e4a6b8248698047687e4869804c6e854b6d8548697f45647a45667c39586c2c4557213a4c26466726475f1f3b554756665e65736d70797679817c7d856c70786e71796d7381777d8f74798773767e6f727963676f6c717c61656d5b606b61646b676a72666a7254585e", + "719ba7374b263245245576645c816a85b6a297cec6c0faffc4fdffc1fcffbdfbffb9faffadeef780b7ca86bfd09cdbe9aff3ff74a8b924455b466a7da7eeff6797ab2b475b25486022384139566e36587441608046677d3c5b6f3753673450632e495b2d485a2d485a2f4a5d355163355164294456243d4e1f3a51315d8b3a65911e3d5554616f6c7078797b8274767e797b826569716b6f79747a8c6e7586767b8b70747e6d707873757d6a6e775e626a5b606955596065697362677152565c", + "2d3849343e4c39474636442f4057323f553396c6b9c8feffc9ffffc9ffffc8ffffc2fafca5dbe37eabb76e97a587bac8afedf67fb3bf25475b486e7fb4f5ff82bbce385e782f546e223843324e63365a7745617f253f54314d6233516838576e33557030516b30526b33516738566b2942562840531f394b2e567e4c79ae5f769121435e54606d73767f75787f6c707a686c756c6f767479875d636d4f58666870816b707a77798183848b737781676a725d626c6669706f727a686b73545961", + "364f742a36482c3848313d4e3743504b5e5dacd7dcccfeffd1ffffd3ffffd3ffffcdfdfdb1dfe391bac3b4e6eaccffffb9edf27daab7224555456876c2fbffc0f9fdb0e9f16596a9223d472945542e516d3a5875213c513350663456723d607c46687f4a6c84496a813e627a2a4a62274255223a4c2546624671a4596d865e70885563735b626e6367706b6f78777f93777d8d676b746e73814a50583f464d4d545e6a6d7773757d84848b787c85676b746569737d7e8371757d60646c555a62", + "7da9f775a6f85b86ca4566943648622f3b4b313e524e5e6d83a0a9bce2e5d6ffffc9f1f350677192b5bbd8ffffdaffffd7ffff96c2c922414e43626ecdfeffd2ffffd1ffffc1f4f629455026404b29496237516326405726455c2e4a5b2f4b5c2c47592b47592c47582d48592e475927455a223b4f39536e4860773e5a72405b736d7179676c756c6f78767a856067766f76886c717c646a7442494e3d434a3c434b70747e7878807a7c837a7d8773757d666a7475777e6e7077696d744f545d", + "9cb8e59ebceba0c0f49bbffb8cb8fb7aa6e75b6281434559313c4b313f505366748da9b1aed1d594b2b6dfffffe1ffffdfffffa1c7cc2543523e5b67b1d9e3bdebf4b3efff97e2fe45768f28485a284b622c455229475f2c475d38576d2d4d6432526934546b3150662d4b61233b4d243f54304d664353626268725f68715c656e6a6f796a6e776e7179717581484e56565d6a757b89565c6341474ea4a7a9c7c9cbd9dadcd9dadcd9dadbdadbddd8d8da6e727b71747b7879806d70774d525d", + "9eb9e19fbae3a2bde6aac5ebacc8eeaecaf39fafd36b56606e5d705f67845470963b4d66323e4f47576494acb2a9c3c8defefea4c9d025414d39566290deff74c3ee70bae478cdf761a3c433556a3d6784243e4a35546a233d5235556c34546b305168315269325168284255254256374b5e546578495764767881787a8275777f6f727b6c70796b6f78676c7841484d4c535e757b8b545a62434950cfd0d2d2d3d6d2d3d7cbced2d5d7dbc6c8ccf7f7f76f737c7f808787878c63676e4f555f", + "9ab5e0a3bee4a6c0e7a2bde6a5c0e7a7c2e8aabfe46b54516c56546d5a5ea6c4f59fc3fa8aaee56483b24b5e783341544661734f7678264550344f5b70b8d876c0e774bee56cadd44c6f863e657966afd72a48562d49582742562b495f355870365a743456702f4e6528455a3f55673a4f5d75777f676b747a7c838281887d7e8674777f72767e676b746167723f4e5c4a5b70696f7c535963464c56d0d1d4c7c9ced7dcdeced1d5dadde0e3e5e6efeff06468707e808786868c64686f4c515c", + "9bb4dd9eb8df9fbbe1a3bce3a9c2e6a4bfe4a9c1e66a53506b54516a53519db6dd7e8a9e79889da6c3f18eb6f18ab5f57595c75a759425424c304952507c6c5ea09e7fd6ff7dd5ff5077903c61727ad1fc487c972b47532643532d4e645490b565aed65a98be47799a364f62495c69626a73787a8070737c7e7e8585848b626e7c707580787b8371747c606672223f5c3e50664e5c6c525762474d59b0b2b7d1d3d5ced3d8dfe0e1d2d5d7dcdddedadbdc575c6462666c696c735f636b494f5c", + "6b81a37088aa758db087a0c3a1b9dd9fb9df9ab2d54c4d5e524d5a584f5793abd28086927e756b9bb8e68cacd980a7df96b3e08397b3233b442b404a6882a84f66834a6e8466aacf4f77903b5e6e69add94a799540687c2946553c647e7fb6ca8ecbdf7ab9d472c2eb4c62726e747c7f80866f737b6f737b7e7f8586858b7d838c6f77846d707b7679815d66715870824c5a6758616c515761454c574147524b515c4a566c585b694c535e6f727b6d70795459626c6f77686c7460656d494f5c" + ] + }, + "left": { + "cols": 16, + "rows": [ + "6c7e92596a7d49618167604c6c685a474c443b413f3c4959808c9a7c92b17b95bc7ea2d38da8d54b5a64263a418caee2", + "6b809a4d5d6b486488645d48655e473841442d353f31384067604e6b7b8553667e799cc9708296314a5c273b41667993", + "768aa24856644a668a605a465f5a44323b402b343a2c353e645f4f5f6c7252667f7496c16f849a3a596c244251576c82", + "7692b5596d834f6e945b564452504329343c28323a353d455151496f776f5469817292b9626d8036536720373d4a5f77", + "6b748351535d506d915651414d4c433638432c313b3038454649465c5b624d63806f8eb16d7f9a4b68741f3d4e5c7a9a", + "58555f50505e4f6c8f524e414d4c42282a3222262e3d3c444b59697188a17594b86a8db780a1cb40576b1d2c30547293", + "5455605a5d6c4863895e666b626c762e37442b34403c3a425a759680a0c87e9fc8678bb77b9dc843647d1e425341596a", + "667e9d6f8aad81a0c683a2c97a9ac02e3a4827333d2a3240708fb57a9ac57698c457759a4c65802d434f1f323634485d", + "84a5ca81a3c880a2c77c9ec57899c15c7a9e486e9f252e396486b1567499455e77485f73475d722d425220313931455f", + "7fa1c87c9fc77a9dc6779ac47395c05f7ca3547cb8456896425b74485e72495f74405670364c6f354c70364c714b5c7a", + "7a9cc5789ac47698c37295c05c7ea6435d7b43596e495f74495f73445a71395071344a6d344a6e344b6f526280828898", + "7497c17094bf5a79a0445d7942586c475d704a6075485e743c526f344a6e344c70344b70344b6f58668284899a838999", + "506e903f5871445a6e4a6075495f73495e72405671354c6e334a6d344c71344b70354c705f6c85828898868b9c838898", + "44596d495f734a6174495f73435970384f70334a6e32496d334b6f344c72364d72647086828797868c9d858b9c70798e", + "465c70465c70455a6f3b516e344b6f344b6f32496c344c71334a6f394f716e778c848998848a9983889778809370798d", + "465c6f3f556e33496b334b6f334b6f32496d32486c31486b3a4d6d747c8e848a988187948186947d83926b74887f8492", + "3247642e43632f456531476a31466930466830476a40526f777d8c8388938489957f84907e8390677083797f8d808593", + "2c405d2b405d2d42612f45663046683046674958747d828f878b95858994858a958387926f7685737a888085907f838e", + "2a3c572a3d592c405e2e42612f45654b5a747f8490858992848890858891848892747986666e7f7e838d7f838d7f848e", + "293b55293b55293b562e415e545f7381858e878a92868a9283868f8488917a7e89626a7a797d8882868e7f838c7d828b" + ] + }, + "right": { + "cols": 16, + "rows": [ + "666c785d636e62666f474d59545963595e68464c573e4450485364494e60636872797a81656a7387868c6e7178505663", + "686e796b6e78676b74464c57555a64585e67454b553c424d4c4e5d4b4048686b74797b8154596271747c6a6e754d535f", + "5352526c6f785f646e464c58555a64565c65464c563b414c5559644e332c4d4a4d70737a5a5f676b6f76656a724b515f", + "5b5e57656a73555c674248565e626c585d664349533f42496d6b6b83623e747367676b73575c646c6e75646871484e5c", + "515b63656a75545d6d404653565d6b4e54603f4651473c3e958b63af98357e7235616671484d5565686e686c74454c59", + "4050694c5769485367383f4c545b694c525d3b434d403a3fb4a25bb0972e9e8a325b626d4b515c595f68585e65424958", + "3f51713f52714051714052724c597240495a3440522c2c3281765081712c836e2e6469714f555f60666e555b66434a59", + "3f52733f52734052744052734153744053744d5d80515c772f333e12192052464860656e5056605b616a505761434a58", + "3e52733e52744053753f52743f5273405374415475435473283344121b264d545f4f56604a515d5259624e545f404855", + "3e52743e52744054773f52744154773f53744154764255772a374c151e293f48543d444b424d5f4b5462474d5a3b4251", + "3e53773d52753e52743f53774054774256793f5375415476303b50171e278a74407e735f474748435678415371415271", + "3d52753f54783f54783e53763f53764054774054765061825e505f6b5a61615e59ad83334747423f4e6845587a425475", + "3e54793c52753c52753e54783e54773e53763e53764055794155784255784f5a6f71644f8b7243445571425577415374", + "3e53783d52763c51753b51753d53763e53773e53763f54763e537641557942567943577a40547643577a425678415475", + "384e713c51753c51743c50733c50723f53773e53773e52753e52753e51744054784154784053764054764052743f5071", + "3a4e6f374c6d394d6f3b4f723c50733b4e703c4f713d50723c50723b4f703c4f703e51734053763e50713c4e6f3e4f6f", + "4f5d76374b6c374a6c374a6c374a6b374a6a394c6c3b4e703a4d6e3a4d6d3a4d6d3b4e6e3d4e6f3c4e6d394b69384966", + "6d75863d4e6c364869374969364767364867374968384a6a384a6a3a4c6c3b4d6d3c4d6d3a4c6a3b4c6b384865374763", + "7b808c576279344563354766354766344665354766394a69354765374967374967394b6938496637486436466135455e", + "7b7f8b707683404f6835466535476635476535466435476533456136476536476435466234445f32425b32425b324158" + ] + } + } +} 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 new file mode 100644 index 0000000000..7cfea81a4e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-01.00.plan.json @@ -0,0 +1,44 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "plza", + "checkpoint": { + "id": "01.00", + "title": "New game to the station platform", + "events": [ + { + "id": "language", + "kind": "game_action", + "why": "step 1: start a new game in English", + "action": "new_game_language" + }, + { + "id": "look", + "kind": "game_action", + "why": "step 2: pick the first look", + "action": "pick_look" + }, + { + "id": "name", + "kind": "game_action", + "why": "steps 3-4: name the player and confirm", + "action": "type_player_name" + }, + { + "id": "opening", + "kind": "game_action", + "why": "step 5: the opening cutscene, no presses (A does not advance it), until the autosave badge has shown and the station platform holds", + "action": "opening_to_platform", + "args": { + "timeout_ms": 240000 + } + } + ], + "metadata": { + "phase": "testing", + "source": "console B recording, 2026-11-08/09: played step by step from a new game" + } + }, + "execution": { + "save": "autosave" + } +} diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b0ff54039b..bedd24378e 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2363,6 +2363,60 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/PokemonLZA_Settings.h Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp Source/VideoGames/PokemonLZA/PokemonLZA_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.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_AutoStoryScenes.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.cpp + 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_AutoStoryControlsHintDetector.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_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 + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPixelShares.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryDevFiles.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.h Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_DonutMaker.cpp Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_DonutMaker.h Source/VideoGames/PokemonLZA/Programs/Farming/PokemonLZA_FriendshipFarmer.cpp From cd4e9a4ce38b66d6144a5ac0b582b377bf407148 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 21:38:05 -0800 Subject: [PATCH 02/33] PokemonLZA: AutoStory: tutorial cards in mash_scene, A for late choices Moved down from plza/story-engine: mash_scene() presses A on a tutorial card (tutorial_card_shows()), and choose_dialog_option() presses A when no choice arrow shows within 3 s (the Research Lab elevator). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryDialogs.cpp | 10 +++++- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 31 ++++++++++++++++++- .../Actions/PokemonLZA_AutoStoryScenes.h | 8 +++++ 3 files changed, 47 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp index 0d6e456191..237d6130e3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp @@ -88,7 +88,15 @@ std::optional wait_for_choice_arrow(ConsoleHandle& console, ProControlle } // namespace void choose_dialog_option(ConsoleHandle& console, ProControllerContext& context, size_t index){ - std::optional row = wait_for_choice_arrow(console, context, 10s); + // Some questions show their choices only after A closes the question's + // text: the Research Lab elevator's "which floor?" (console B, + // 2026-11-10). A press comes only after 3 s without choices, so it + // cannot pick the first choice the moment the choices appear. + std::optional row = wait_for_choice_arrow(console, context, 3s); + for (int press = 0; !row && press < 3; press++){ + pbf_press_button(context, BUTTON_A, 160ms, 240ms); + row = wait_for_choice_arrow(console, context, 3s); + } if (!row){ OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, 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 ac1e57fa70..036bc62998 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 "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" @@ -100,6 +102,27 @@ void log_event_change(ConsoleHandle& console, const Pokemon::ScreenEvents& event } // namespace +// A tutorial card (Map & Missions, Main Missions, Pokedex, ...): a white +// panel in the middle over a dark, blurred, even screen. Only A turns its +// pages (B turns back), so a B mash never closes it. Measured on 5 cards +// and 9 other screens (map, Pokedex, dialogs, overworld, night) on +// console B, 2026-11-10, at full resolution: cards' panel 241-246 bright +// (its text spreads it to 40-48) and edges 61-76 with spread under 7; the +// others' panel at most 185, or edges brighter or busy. +bool tutorial_card_shows(const ImageViewRGB32& frame){ + const ImageStats panel = image_stats(extract_box_reference(frame, ImageFloatBox(0.32, 0.62, 0.36, 0.20))); + if (panel.average.sum() / 3 < 225){ + return false; + } + for (const ImageFloatBox& side : {ImageFloatBox(0.03, 0.30, 0.15, 0.40), ImageFloatBox(0.82, 0.30, 0.15, 0.40)}){ + const ImageStats edge = image_stats(extract_box_reference(frame, side)); + if (edge.average.sum() / 3 > 100 || edge.stddev.sum() / 3 > 12){ + return false; + } + } + return true; +} + void mash_scene( ConsoleHandle& console, ProControllerContext& context, SceneMashGoal goal, Button text_button, Milliseconds timeout, @@ -112,7 +135,13 @@ void mash_scene( while (current_time() - start < timeout){ context.wait_for_all_requests(); const WallClock now = current_time(); - const Pokemon::ScreenEvents events = observer.observe(console.video().snapshot(), now); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && tutorial_card_shows(frame)){ + console.log("mash_scene(): a tutorial card: A."); + pbf_press_button(context, BUTTON_A, 160ms, 840ms); + continue; + } + const Pokemon::ScreenEvents events = observer.observe(frame, now); log_event_change(console, events, last_events); const SceneMashAction action = scene_mash_action(events, goal, text_button == BUTTON_B); if (goal == SceneMashGoal::OVERWORLD){ 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 4e9c905f06..310fd84676 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -14,6 +14,7 @@ #include #include #include "Common/Cpp/Time.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" @@ -32,6 +33,8 @@ namespace PokemonLZA{ // (only the Move / Control Camera hints, which have no detector yet). // A cutscene can hold a still frame longer than `quiet`, so the quiet end // waits for `min_length`, the scene's rough recorded length, to pass. +// A tutorial card gets A whatever `text_button` is: only A turns its pages +// (tutorial_card_shows()). // Throws OperationFailedException if the goal does not show within `timeout`. void mash_scene( ConsoleHandle& console, ProControllerContext& context, @@ -41,6 +44,11 @@ void mash_scene( ); +// A tutorial card on screen (Map & Missions, Main Missions, Pokedex, ...): +// a bright panel in the middle over dark, even edges. +bool tutorial_card_shows(const ImageViewRGB32& frame); + + // The new game's opening, as recorded 2026-11-08 on console B. None of it // reads the screen: each waits a fixed time for its screen. From 36bd9a0ee2bba7ef2be7161c6e891f8986409f2c Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 22:07:42 -0800 Subject: [PATCH 03/33] PokemonLZA: AutoStory: walk legs are TIMED_LEGS, fly takes a place The walk action's legs move from INTEGER_ROWS to the engine's TIMED_LEGS ([turn degrees, ms]), so a leg's shape is checked when the plan loads and the validator only checks the ranges. The fly action's target was a GRID_POSE naming the place as its map; a game with no tiles may not take tile args now, so it takes the place's slug as a WORD "place". Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 28 +++++++++-------- .../AutoStory/PokemonLZA_AutoStoryGame.h | 4 +-- .../PokemonLZA_AutoStoryStepValidator.cpp | 30 ++++++++----------- 3 files changed, 31 insertions(+), 31 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 8bedc6b145..d62ae53c15 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -56,7 +56,7 @@ const std::map>& story_actions_not_impleme namespace{ -using IntegerRows = std::vector>; +using TimedLegs = std::vector; // What a console action does with the run's console and the step's args. using ConsoleBody = std::function; @@ -101,7 +101,7 @@ StoryArgSpec optional_ms(std::string key, int64_t fallback, std::string why){ } StoryArgSpec legs_arg(std::string key, bool required, std::string why){ - return StoryArgSpec{.key = std::move(key), .type = StoryArgType::INTEGER_ROWS, .required = required, .fallback = std::nullopt, .why = std::move(why)}; + return StoryArgSpec{.key = std::move(key), .type = StoryArgType::TIMED_LEGS, .required = required, .fallback = std::nullopt, .why = std::move(why)}; } // "walk": its legs, the fade it ends on, the heading it faces first. @@ -338,20 +338,27 @@ Handler game_handler(const PlzaHandlers& handlers, const std::string& name){ return story_game_actions().at(name)(handlers); } +// Where a fly to `args`' "place" leaves the player: in that place. +Pokemon::Pose flown_to(const StoryActionArgs& args){ + Pokemon::ZoneDeclared place; + place.place = Pokemon::story_arg(args, "place"); + return Pokemon::pose_of(Pokemon::DeclaredPose(std::move(place))); +} + // The handler of each of plza_story_action_specs(), by kind and name. Handler plza_handler(const PlzaHandlers& handlers, const StoryActionSpec& spec){ const std::string& name = spec.name; switch (spec.kind){ case StoryStepKind::ROUTE:{ Handler fly = handlers.console(name, [](StoryEnv& env, const StoryActionArgs& args){ - const Pokemon::GridPose& target = Pokemon::story_arg(args, "target"); - fly_to(env.env.console, env.context, env.language, get_location_item_from_slug(target.map).location); + const std::string& place = Pokemon::story_arg(args, "place"); + fly_to(env.env.console, env.context, env.language, get_location_item_from_slug(place).location); }); // Flown: the player is at the target. return [fly = std::move(fly)](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState& state){ Outcome outcome = fly(backend, call, state); if (outcome.succeeded()){ - outcome.pose = Pokemon::pose_of(Pokemon::story_arg(call.args, "target")); + outcome.pose = flown_to(call.args); } return outcome; }; @@ -408,8 +415,8 @@ std::vector plza_story_action_specs(){ std::vector specs{ console_only(StoryActionSpec{.kind = StoryStepKind::ROUTE, .name = "fly", .args = { StoryArgSpec{ - .key = "target", .type = StoryArgType::GRID_POSE, .required = true, - .fallback = std::nullopt, .why = "the fast travel place, by slug, as the map", + .key = "place", .type = StoryArgType::WORD, .required = true, + .fallback = std::nullopt, .why = "the fast travel place, by slug", }, }}), console_only(builtin_spec(StoryStepKind::TALK, "talk")), @@ -461,11 +468,8 @@ StoryMove story_walk_move(const StoryActionArgs& args, std::string_view legs){ if (heading != args.end()){ move.heading = (double)std::get(heading->second); } - for (const std::vector& row : Pokemon::story_arg(args, legs)){ - if (row.size() != 2){ - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, std::format("A walk leg needs 2 numbers, has {}.", row.size())); - } - move.legs.push_back({.turn = (double)row[0], .walk = Milliseconds(row[1])}); + for (const Pokemon::StoryTimedLeg& row : Pokemon::story_arg(args, legs)){ + move.legs.push_back({.turn = (double)row.turn, .walk = Milliseconds(row.ms)}); } return move; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 1e002aef02..9c9f0276cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -41,8 +41,8 @@ const std::map>& story_actions_not_impleme // PLZA's own actions and its replacements of built-in ones (same kind and // name), in the order the game registers them: // -// ROUTE "fly" fly to the target, whose map is a fast travel -// place's slug ("vert-pokemon-center") +// ROUTE "fly" fly to "place", a fast travel place's slug +// ("vert-pokemon-center") // TALK "talk" A at what the player faces // ANSWER "answer" the first choice for yes, the second for no // MASH "mash" B through the text until the overworld is back diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp index f476c912cb..c652fd13c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.cpp @@ -19,30 +19,26 @@ using Pokemon::StoryStepKind; namespace{ -using IntegerRows = std::vector>; +using TimedLegs = std::vector; -// What is wrong with the legs `rows` of step `step`: each a [turn, ms] -// pair turning at most half a turn either way and walking no negative -// time, and at least one that walks. -void add_legs_errors(std::string_view step, std::string_view key, const IntegerRows& rows, std::vector& errors){ +// What is wrong with the legs `rows` of step `step`: each turning at most +// half a turn either way and walking no negative time, and at least one +// that walks. +void add_legs_errors(std::string_view step, std::string_view key, const TimedLegs& rows, std::vector& errors){ if (rows.empty()){ errors.push_back(std::format("{}: {} has no legs", step, key)); return; } bool goes = false; for (size_t i = 0; i < rows.size(); i++){ - const std::vector& row = rows[i]; - if (row.size() != 2){ - errors.push_back(std::format("{}: {} leg {} needs 2 numbers [turn, ms], has {}", step, key, i, row.size())); - continue; + const Pokemon::StoryTimedLeg& row = rows[i]; + if (row.turn < -180 || row.turn > 180){ + errors.push_back(std::format("{}: {} leg {} turns {} deg, expected -180 to 180", step, key, i, row.turn)); } - if (row[0] < -180 || row[0] > 180){ - errors.push_back(std::format("{}: {} leg {} turns {} deg, expected -180 to 180", step, key, i, row[0])); + if (row.ms < 0){ + errors.push_back(std::format("{}: {} leg {} walks {} ms, expected 0 or more", step, key, i, row.ms)); } - if (row[1] < 0){ - errors.push_back(std::format("{}: {} leg {} walks {} ms, expected 0 or more", step, key, i, row[1])); - } - goes = goes || row[1] > 0; + goes = goes || row.ms > 0; } if (!goes){ errors.push_back(std::format("{}: {} walks nowhere", step, key)); @@ -77,7 +73,7 @@ std::vector plza_step_arg_errors(const Pokemon::StoryStep& step){ if (legs == step.args.end()){ return errors; } - const IntegerRows& rows = std::get(legs->second); + const TimedLegs& rows = std::get(legs->second); add_legs_errors(step.name, "legs", rows, errors); const auto end = step.args.find("end"); if (end != step.args.end()){ @@ -85,7 +81,7 @@ std::vector plza_step_arg_errors(const Pokemon::StoryStep& step){ if (!walk_end_event(name)){ errors.push_back(std::format("{}: end {} is not \"fade_white\" or \"fade_black\"", step.name, name)); } - if (rows.empty() || rows.back().size() != 2 || rows.back()[1] <= 0){ + if (rows.empty() || rows.back().ms <= 0){ errors.push_back(std::format("{}: the last leg has no walk to hold until the end", step.name)); } } From c5c608f241e3f72419829b752b03435f23ba9ebb Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:26:56 -0800 Subject: [PATCH 04/33] PokemonLZA: AutoStory: use shared Pokemon::describe() for scene event logs --- .../AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) 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 036bc62998..a727d31d66 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -89,15 +89,7 @@ void log_event_change(ConsoleHandle& console, const Pokemon::ScreenEvents& event return; } last = shown; - std::string names; - for (size_t i = 0; i < Pokemon::SCREEN_EVENT_COUNT; i++){ - const Pokemon::ScreenEvent event = (Pokemon::ScreenEvent)i; - if (shown.has(event)){ - names += names.empty() ? "" : ", "; - names += Pokemon::screen_event_name(event); - } - } - console.log(std::format("mash_scene(): screen now: {}", names.empty() ? std::string("nothing") : names)); + console.log(std::format("mash_scene(): screen now: {}", Pokemon::describe(shown))); } } // namespace From 01a8725374173b3a88c6f37d8d79a7e602ed0b04 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 22:48:58 -0800 Subject: [PATCH 05/33] PokemonLZA: AutoStory: use shared screen_observation(), describe(), same_screen(), and direction_degrees() --- .../AutoStory/PokemonLZA_AutoStoryBackend.cpp | 61 ++----------------- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 3 +- .../PokemonLZA_AutoStoryObservation.cpp | 57 ----------------- .../PokemonLZA_AutoStoryObservation.h | 15 ----- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 2 +- .../PokemonLZA_AutoStoryStepValidator.cpp | 6 +- .../PokemonLZA_AutoStoryStepValidator.h | 4 +- SerialPrograms/cmake/SourceFiles.cmake | 1 - 8 files changed, 11 insertions(+), 138 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp index bbfbedd851..7fed3e6ce2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp @@ -12,7 +12,6 @@ #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Color.h" -#include "CommonFramework/ImageTools/ImageDiff.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h" @@ -26,36 +25,6 @@ using namespace std::chrono_literals; using Pokemon::Direction; -namespace{ - -// Below this pixel RMSD two looks are the same screen. -constexpr double STILL_RMSD = 2.0; - -// `direction` as degrees clockwise of straight on. -double direction_degrees(Direction direction){ - switch (direction){ - case Direction::NORTH: - return 0; - case Direction::EAST: - return 90; - case Direction::SOUTH: - return 180; - case Direction::WEST: - return -90; - } - return 0; -} - -bool same_screen(const VideoSnapshot& a, const VideoSnapshot& b){ - if (!a || !b || a.frame->width() != b.frame->width() || a.frame->height() != b.frame->height()){ - return false; - } - return ImageMatch::pixel_RMSD(*a.frame, *b.frame) < STILL_RMSD; -} - -} // namespace - - PlzaConsoleBackend::PlzaConsoleBackend(StoryEnv& env) : m_env(env) {} @@ -65,11 +34,11 @@ void PlzaConsoleBackend::press(Button button, Milliseconds hold, Milliseconds re } void PlzaConsoleBackend::tap(Direction direction){ - story_turn(*this, direction_degrees(direction)); + story_turn(*this, Pokemon::direction_degrees(direction)); } void PlzaConsoleBackend::hold(Direction direction, Milliseconds duration, Pokemon::StoryPace pace){ - stick(direction_degrees(direction), duration, 0ms, pace); + stick(Pokemon::direction_degrees(direction), duration, 0ms, pace); } void PlzaConsoleBackend::stick(double degrees, Milliseconds duration, Milliseconds release, Pokemon::StoryPace){ @@ -86,7 +55,7 @@ Pokemon::Observation PlzaConsoleBackend::observe(){ VideoSnapshot frame = m_env.env.console.video().snapshot(); Pokemon::Observation look; if (frame){ - static_cast(look) = plza_observation(m_observer.read(*frame.frame)); + static_cast(look) = Pokemon::screen_observation(m_observer.read(*frame.frame)); if (m_platform.detect(*frame.frame)){ look.readings[std::string(PLATFORM_READING)] = 1; } @@ -120,32 +89,10 @@ Pokemon::Observation PlzaConsoleBackend::observe(){ namespace{ -std::string events_text(const PokemonAutomation::ScreenEvents& events){ - using EngineEvent = PokemonAutomation::ScreenEvent; - const std::pair names[] = { - {EngineEvent::FADE_BLACK, "fade_black"}, - {EngineEvent::FADE_WHITE, "fade_white"}, - {EngineEvent::TEXT_BOX, "text_box"}, - {EngineEvent::BATTLE, "battle"}, - {EngineEvent::CAN_MOVE, "can_move"}, - {EngineEvent::STILL, "still"}, - {EngineEvent::CHOICE_BOX, "choice_box"}, - {EngineEvent::INTERACT_PROMPT, "interact_prompt"}, - }; - std::string text; - for (const auto& [event, name] : names){ - if (events.has(event)){ - text += text.empty() ? "" : "+"; - text += name; - } - } - return text.empty() ? std::string("nothing") : text; -} - // The look's events and readings: "fade_black+still", // "nothing+skip_prompt", "can_move+platform+autosave+controls_hint". std::string look_text(const ScreenObservation& look){ - std::string text = events_text(look.events); + std::string text = describe(look.events, "+"); if (look.readings.contains(PLATFORM_READING)){ text += "+platform"; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index d62ae53c15..1d95606648 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -222,8 +222,7 @@ class PlzaHandlers{ const auto end = args.find("end"); std::optional fade; if (end != args.end()){ - const std::optional event = walk_end_event(std::get(end->second)); - fade = event ? engine_fade_event(*event) : std::nullopt; + fade = walk_end_event(std::get(end->second)); } return fade ? walk_until(backend, name, move, heading, *fade) : run_story_move(backend, move, heading); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp deleted file mode 100644 index aad37c0e4e..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* PokemonLZA AutoStory - Observations - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include "PokemonLZA_AutoStoryObservation.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - -using Pokemon::ScreenEvent; -using Pokemon::ScreenEvents; - - -ScreenObservation plza_observation(const ScreenEvents& events){ - using EngineEvent = PokemonAutomation::ScreenEvent; - ScreenObservation look; - const std::pair same[] = { - {ScreenEvent::FADE_BLACK, EngineEvent::FADE_BLACK}, - {ScreenEvent::FADE_WHITE, EngineEvent::FADE_WHITE}, - {ScreenEvent::DIALOG_BOX, EngineEvent::TEXT_BOX}, - {ScreenEvent::CHOICE_BOX, EngineEvent::TEXT_BOX}, - {ScreenEvent::BATTLE_STARTED, EngineEvent::BATTLE}, - {ScreenEvent::PLAYER_CAN_MOVE, EngineEvent::CAN_MOVE}, - {ScreenEvent::SCREEN_STILL, EngineEvent::STILL}, - {ScreenEvent::CHOICE_BOX, EngineEvent::CHOICE_BOX}, - {ScreenEvent::INTERACT_PROMPT, EngineEvent::INTERACT_PROMPT}, - }; - for (const auto& [event, engine_event] : same){ - if (events.has(event)){ - look.events.add(engine_event); - } - } - return look; -} - -std::optional engine_fade_event(ScreenEvent event){ - switch (event){ - case ScreenEvent::FADE_BLACK: - return PokemonAutomation::ScreenEvent::FADE_BLACK; - case ScreenEvent::FADE_WHITE: - return PokemonAutomation::ScreenEvent::FADE_WHITE; - default: - return std::nullopt; - } -} - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h index e486fc4b06..6ac6753935 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h @@ -8,14 +8,10 @@ * */ -// code-health: allow header_symbols -- one reading name per detector; the readings are one concern that every consumer shares #ifndef PokemonAutomation_PokemonLZA_AutoStoryObservation_H #define PokemonAutomation_PokemonLZA_AutoStoryObservation_H -#include #include -#include "CommonTools/ScreenMachine/ScreenObservation.h" -#include "Pokemon/AutoStory/Pokemon_ScreenEventTypes.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -47,17 +43,6 @@ constexpr std::string_view MISSION_BANNER_READING = "scene.mission_banner"; // (MissionCompleteDetector). A look with it has no MISSION_BANNER_READING. constexpr std::string_view MISSION_COMPLETE_READING = "scene.mission_complete"; -// PlzaScreenObserver's events as one look for the story engine: -// DIALOG_BOX is TEXT_BOX; CHOICE_BOX adds TEXT_BOX; -// BATTLE_STARTED is BATTLE; PLAYER_CAN_MOVE (the party bar) is CAN_MOVE; -// SCREEN_STILL is STILL; the fades and INTERACT_PROMPT keep their names. -// No time and no frame: the backend adds them. -ScreenObservation plza_observation(const Pokemon::ScreenEvents& events); - -// The engine's event for a fade of the shared events; none for another -// event. -std::optional engine_fade_event(Pokemon::ScreenEvent event); - } // namespace PokemonLZA 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 22f2a5cef0..4f3539de3d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -50,7 +50,7 @@ UnitTestResult check_reads(const SceneMachineConfig& config, const std::vector walk_end_event(std::string_view end){ +std::optional walk_end_event(std::string_view end){ if (end == "fade_white"){ - return Pokemon::ScreenEvent::FADE_WHITE; + return PokemonAutomation::ScreenEvent::FADE_WHITE; } if (end == "fade_black"){ - return Pokemon::ScreenEvent::FADE_BLACK; + return PokemonAutomation::ScreenEvent::FADE_BLACK; } return std::nullopt; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h index 66013a5ec7..fb87f619c5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStepValidator.h @@ -15,7 +15,7 @@ #include #include #include -#include "Pokemon/AutoStory/Pokemon_ScreenEventTypes.h" +#include "CommonTools/ScreenMachine/ScreenObservation.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryStep.h" #include "PokemonLZA_AutoStoryBackend.h" @@ -26,7 +26,7 @@ namespace PokemonLZA{ // A walk's "end" arg as the event it ends on: "fade_white" or // "fade_black"; nothing for any other name. -std::optional walk_end_event(std::string_view end); +std::optional walk_end_event(std::string_view end); // What is wrong with the args of a "walk" step: // each leg a [turn, ms] pair, turning -180 to 180 degrees and walking 0 ms diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index b6711ad83d..811f2014bd 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2362,7 +2362,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h - Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h From 8592dde7670ef6feeb976922b2b97ff5c163ba82 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 23:41:04 -0800 Subject: [PATCH 06/33] PokemonLZA AutoStory: rename AutoStoryObservation.h to AutoStoryReadings.h The header now holds only the *_READING names; plza_observation() moved to the shared Pokemon::screen_observation(). Point the stale comments at it and include Pokemon_ScreenObservation.h where it is called. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryWalkScreenChecks.h | 2 +- .../AutoStory/PokemonLZA_AutoStoryBackend.cpp | 1 + .../Programs/AutoStory/PokemonLZA_AutoStoryBackend.h | 4 ++-- .../AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp | 2 +- ...yObservation.h => PokemonLZA_AutoStoryReadings.h} | 12 ++++++------ .../AutoStory/PokemonLZA_AutoStorySceneMachine.h | 2 +- .../PokemonLZA_AutoStorySceneMachine_Tests.cpp | 5 +++-- SerialPrograms/cmake/SourceFiles.cmake | 2 +- 8 files changed, 16 insertions(+), 14 deletions(-) rename SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/{PokemonLZA_AutoStoryObservation.h => PokemonLZA_AutoStoryReadings.h} (83%) 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 4d78d5ad30..b8f8588252 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h @@ -15,7 +15,7 @@ #include #include "CommonTools/ScreenMachine/ScreenObservation.h" #include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" -#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h" #include "PokemonLZA_AutoStoryMoves.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp index 7fed3e6ce2..1889706437 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp @@ -13,6 +13,7 @@ #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Color.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "Pokemon/AutoStory/Engine/Pokemon_ScreenObservation.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h" #include "PokemonLZA_AutoStoryBackend.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h index 9e06505618..8a29077895 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -33,7 +33,7 @@ #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryMissionCompleteDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h" -#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStoryScreenEvents.h" namespace PokemonAutomation{ @@ -88,7 +88,7 @@ class PlzaConsoleBackend : public PlzaBackend{ virtual void stick(double degrees, Milliseconds duration, Milliseconds release, Pokemon::StoryPace pace) override; virtual void wait(Milliseconds duration) override; // Once the inputs are done: PlzaScreenObserver's events on a frame - // (plza_observation()), STILL when it barely differs from the frame + // (Pokemon::screen_observation()), STILL when it barely differs from the frame // of the look before, and the readings PLATFORM_READING, // SKIP_PROMPT_READING, AUTOSAVE_READING, CONTROLS_HINT_READING, // ADVANCE_ARROW_READING, MISSION_BANNER_READING and diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index e340f962be..f30ea11ac4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -22,7 +22,7 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryFakeBackend.h" #include "PokemonLZA_AutoStoryGame.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" -#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStoryEngine_Tests.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h similarity index 83% rename from SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h rename to SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h index 6ac6753935..d1c5757f84 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h @@ -1,15 +1,15 @@ -/* PokemonLZA AutoStory - Observations +/* PokemonLZA AutoStory - Readings * * From: https://github.com/PokemonAutomation/ * - * PLZA's screen events (PokemonLZA_AutoStoryScreenEvents.h) as the story - * engine's observations, which its backend returns and its scene states - * match on. + * The names of the readings (ScreenObservation::readings) PLZA's backend + * sets from its AutoStory detectors, which its scene states and step + * checks match on. * */ -#ifndef PokemonAutomation_PokemonLZA_AutoStoryObservation_H -#define PokemonAutomation_PokemonLZA_AutoStoryObservation_H +#ifndef PokemonAutomation_PokemonLZA_AutoStoryReadings_H +#define PokemonAutomation_PokemonLZA_AutoStoryReadings_H #include diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h index ccc45f31e3..59347f4052 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h @@ -31,7 +31,7 @@ #include "CommonTools/ScreenMachine/ScreenObservation.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" -#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStoryBackend.h" #include "PokemonLZA_AutoStoryScreenEvents.h" 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 4f3539de3d..b42d00f1b5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -3,7 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * The scene machine's states on sequences of events, as PLZA's backend - * observes them (plza_observation()): no frames needed. + * observes them (Pokemon::screen_observation()): no frames needed. * */ @@ -13,8 +13,9 @@ #include #include #include "Common/Cpp/TestRunners/UnitTest.h" +#include "Pokemon/AutoStory/Engine/Pokemon_ScreenObservation.h" #include "PokemonLZA_AutoStoryGame.h" -#include "PokemonLZA_AutoStoryObservation.h" +#include "PokemonLZA_AutoStoryReadings.h" #include "PokemonLZA_AutoStorySceneMachine.h" #include "PokemonLZA_AutoStoryStoryFiles.h" diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 696d7b92b4..f72b3e8c2a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2364,7 +2364,7 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h - Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryObservation.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryReadings.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp From a0143f5c65340d3e645aef441ecb2426705c6371 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 17:45:37 -0800 Subject: [PATCH 07/33] PokemonLZA: AutoStory: new game language, look and name from options (tests first, stubs) The language pick, look picker and name now take the program's options; the presses are pure functions in PokemonLZA_AutoStoryIntro with tests. This commit has the tests and stubs; the next fills them in. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA/PokemonLZA_Tests.cpp | 2 + .../Actions/PokemonLZA_AutoStoryIntro.cpp | 33 +++ .../Actions/PokemonLZA_AutoStoryIntro.h | 97 ++++++++ .../PokemonLZA_AutoStoryIntroScreens.cpp | 29 +++ .../PokemonLZA_AutoStoryIntroScreens.h | 35 +++ .../PokemonLZA_AutoStoryIntro_Tests.cpp | 213 ++++++++++++++++++ .../Actions/PokemonLZA_AutoStoryIntro_Tests.h | 26 +++ .../Actions/PokemonLZA_AutoStoryScenes.cpp | 136 ++++++++--- .../Actions/PokemonLZA_AutoStoryScenes.h | 35 ++- .../AutoStory/PokemonLZA_AutoStory.cpp | 35 ++- .../Programs/AutoStory/PokemonLZA_AutoStory.h | 13 +- .../AutoStory/PokemonLZA_AutoStoryBackend.h | 8 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 8 +- SerialPrograms/cmake/SourceFiles.cmake | 6 + 14 files changed, 629 insertions(+), 47 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index b7861d2bff..ccb666c189 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -20,6 +20,7 @@ #include "Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "Inference/PokemonLZA_SelectionArrowDetector.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h" +#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h" @@ -49,6 +50,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_StoryTable(database); add_tests_AutoStoryScreenEvents(database); add_tests_AutoStoryDetectors(database); + add_tests_AutoStoryIntro(database); add_tests_AutoStorySceneMachine(database); add_tests_AutoStoryEngine(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp new file mode 100644 index 0000000000..9c44f6e22c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp @@ -0,0 +1,33 @@ +/* PokemonLZA AutoStory - New game intro + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryIntro.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +std::optional> language_list_presses(Language){ + return std::nullopt; +} + +std::optional> look_picker_presses(size_t){ + return std::nullopt; +} + +std::optional name_keys(std::string_view, bool){ + return std::nullopt; +} + +std::string new_game_problem(Language, const NewGameChoices&){ + return "TODO"; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h new file mode 100644 index 0000000000..f8dbdb5a4c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h @@ -0,0 +1,97 @@ +/* PokemonLZA AutoStory - New game intro + * + * From: https://github.com/PokemonAutomation/ + * + * The new game's opening screens (language list, look picker, name + * keyboard): the presses each choice takes as pure functions. The screens' + * detectors are in PokemonLZA_AutoStoryIntroScreens.h. + * + * Everything about the screens' layout is a guess from Scarlet/Violet's, + * to be confirmed on a console (see the TODOs): the language list's order, + * the look picker's 2 x 4 grid, and what the name keyboard does with Shift. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntro_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntro_H + +#include +#include +#include +#include +#include "CommonFramework/Language.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// One press on an intro screen. +enum class IntroKey{ + UP, + DOWN, + LEFT, + RIGHT, + A, +}; + + +// The language list's entries, top to bottom, as Scarlet/Violet shows them +// (English, Espanol, Francais, Deutsch, Italiano, Japanese, Korean, +// Chinese Simplified, Chinese Traditional). TODO: confirm LZA's order on a +// console. +// From the top entry: DOWN to the language's entry, then A. Nullopt for a +// language the list lacks. +std::optional> language_list_presses(Language language); + + +// The number of looks on the picker: a grid of 2 rows of 4 faces, as +// Scarlet/Violet's, numbered 1 to LOOK_COUNT left to right along the top +// row, then the bottom row. TODO: confirm the grid and the cursor's moves +// on a console. +constexpr size_t LOOK_COUNT = 8; + +// The highlight starts at random, so: UP and LEFT x3 to the top-left face +// (the edges clamp), then RIGHT and DOWN to look `look` (1 to LOOK_COUNT), +// then A. Nullopt for a look outside the grid. +std::optional> look_picker_presses(size_t look); + + +// What to type for a player name on the keyboard. The keyboard types lower +// case; its Shift (a left stick click) makes the next letter a capital. +struct NameKeys{ + // Upper case letters and digits, the keys to press in order. + std::string keys; + // Click Shift before the first key. + bool shift_first = false; +}; + +// Only the first letter of a name may be a capital: its Shift is the only +// one the typer presses. `first_letter_auto_caps`: the keyboard starts with +// a capital by itself (TODO: confirm on a console), so Shift is for a +// first letter that is lower case. Nullopt for an empty name, a character +// that is not a letter or digit, or a capital after the first letter. +std::optional name_keys(std::string_view name, bool first_letter_auto_caps); + + +// The new game's choices, played by the intro's actions. +struct NewGameChoices{ + // Letters and digits, a capital only as the first letter (name_keys()). + // The lab's player is Kosmos. + std::string name = "Kosmos"; + // 1 to LOOK_COUNT. + size_t look = 1; + // The name keyboard starts with a capital by itself (name_keys()). + bool name_first_letter_auto_caps = false; +}; + + +// Why the new game's choices cannot be played, or an empty string if they +// can. The language is the list's. +std::string new_game_problem(Language language, const NewGameChoices& choices); + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp new file mode 100644 index 0000000000..cdb9381abb --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -0,0 +1,29 @@ +/* PokemonLZA AutoStory - New game intro screens + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryIntroScreens.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +bool is_language_list(const ImageViewRGB32&){ + return false; +} + +bool is_look_picker(const ImageViewRGB32&){ + return false; +} + +bool is_keyboard(const ImageViewRGB32&){ + return false; +} + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h new file mode 100644 index 0000000000..20e742e354 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h @@ -0,0 +1,35 @@ +/* PokemonLZA AutoStory - New game intro screens + * + * From: https://github.com/PokemonAutomation/ + * + * One detector per intro screen, for the actions' fixed waits + * (PokemonLZA_AutoStoryScenes.h) to end early once they are written. TODO: + * each returns false until a detector is built from the frames a run saves + * (DebugDumps/PokemonLZA/AutoStory/Intro). + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The "Which language will you play in?" list. +bool is_language_list(const ImageViewRGB32& frame); + +// The look picker's grid of faces. +bool is_look_picker(const ImageViewRGB32& frame); + +// The Switch keyboard on the name screen. +bool is_keyboard(const ImageViewRGB32& frame); + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp new file mode 100644 index 0000000000..b2abc9b1fc --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -0,0 +1,213 @@ +/* PokemonLZA AutoStory - New game intro Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "PokemonLZA_AutoStoryIntro.h" +#include "PokemonLZA_AutoStoryIntro_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +using Keys = std::vector; + +Keys repeated(IntroKey key, size_t count){ + return Keys(count, key); +} + +Keys joined(std::initializer_list parts){ + Keys all; + for (const Keys& part : parts){ + all.insert(all.end(), part.begin(), part.end()); + } + return all; +} + +UnitTestResult test_language_presses(Logger&){ + struct Row{ + Language language; + size_t downs; + }; + const Row rows[] = { + {Language::English, 0}, + {Language::Spanish, 1}, + {Language::French, 2}, + {Language::German, 3}, + {Language::Italian, 4}, + {Language::Japanese, 5}, + {Language::Korean, 6}, + {Language::ChineseSimplified, 7}, + {Language::ChineseTraditional, 8}, + }; + for (const Row& row : rows){ + const auto presses = language_list_presses(row.language); + const Keys expected = joined({repeated(IntroKey::DOWN, row.downs), {IntroKey::A}}); + if (!presses || *presses != expected){ + return std::format("{}: expected {} DOWN then A.", language_data(row.language).code, row.downs); + } + } + if (language_list_presses(Language::None)){ + return "Language::None has no entry in the list."; + } + return true; +} + +UnitTestResult test_look_presses(Logger&){ + // Look 1 is the top-left face: the clamp, then A. + const Keys clamp = joined({{IntroKey::UP}, repeated(IntroKey::LEFT, 3)}); + const auto first = look_picker_presses(1); + if (!first || *first != joined({clamp, {IntroKey::A}})){ + return "Look 1: expected UP, LEFT x3, A."; + } + // Look 3: two to the right on the top row. + const auto third = look_picker_presses(3); + if (!third || *third != joined({clamp, repeated(IntroKey::RIGHT, 2), {IntroKey::A}})){ + return "Look 3: expected the clamp, RIGHT x2, A."; + } + // Look 5: the bottom row's first face. + const auto fifth = look_picker_presses(5); + if (!fifth || *fifth != joined({clamp, {IntroKey::DOWN, IntroKey::A}})){ + return "Look 5: expected the clamp, DOWN, A."; + } + // Look 8: the bottom-right face. + const auto last = look_picker_presses(8); + if (!last || *last != joined({clamp, repeated(IntroKey::RIGHT, 3), {IntroKey::DOWN, IntroKey::A}})){ + return "Look 8: expected the clamp, RIGHT x3, DOWN, A."; + } + if (look_picker_presses(0) || look_picker_presses(9)){ + return "Looks 0 and 9 are outside the grid."; + } + return true; +} + +UnitTestResult test_name_keys(Logger&){ + // Kosmos: a capital K by Shift, the rest as plain keys. + const auto kosmos = name_keys("Kosmos", false); + if (!kosmos || kosmos->keys != "KOSMOS" || !kosmos->shift_first){ + return "Kosmos: expected keys KOSMOS and Shift first."; + } + // A keyboard that capitalizes by itself needs no Shift for it. + const auto auto_caps = name_keys("Kosmos", true); + if (!auto_caps || auto_caps->keys != "KOSMOS" || auto_caps->shift_first){ + return "Kosmos on a capitalizing keyboard: expected no Shift."; + } + // A lower case name there needs Shift to undo it, and without it none. + const auto lower_auto = name_keys("kosmos", true); + if (!lower_auto || !lower_auto->shift_first){ + return "kosmos on a capitalizing keyboard: expected Shift first."; + } + const auto lower = name_keys("kosmos", false); + if (!lower || lower->shift_first){ + return "kosmos: expected no Shift."; + } + // A digit first takes no Shift. + const auto digit = name_keys("7up", true); + if (!digit || digit->keys != "7UP" || digit->shift_first){ + return "7up: expected keys 7UP and no Shift."; + } + return true; +} + +UnitTestResult test_name_refused(Logger&){ + for (const std::string_view name : {"", "Ko smos", "Kosmos!", "KOsmos", "Kosmo\xC3\x9F"}){ + if (name_keys(name, false)){ + return std::format("\"{}\" is not a name the typer can make.", name); + } + } + return true; +} + +UnitTestResult test_new_game_problem(Logger&){ + NewGameChoices choices; + if (!new_game_problem(Language::English, choices).empty()){ + return "The defaults are a valid new game."; + } + if (new_game_problem(Language::None, choices).empty()){ + return "No language is a problem."; + } + choices.look = 9; + if (new_game_problem(Language::English, choices).empty()){ + return "Look 9 is a problem."; + } + choices.look = 1; + choices.name = "KOsmos"; + if (new_game_problem(Language::English, choices).empty()){ + return "A second capital is a problem."; + } + return true; +} + +struct IntroInput{ + std::string name; + UnitTestResult (*body)(Logger&); +}; + +struct IntroExpectation{ +}; + +struct IntroCase{ + IntroInput input; + IntroExpectation expectation; +}; + +const IntroCase INTRO_CASES[] = { + { + .input = {"Intro: the language list's presses", test_language_presses}, + .expectation = {}, + }, + { + .input = {"Intro: the look picker's presses", test_look_presses}, + .expectation = {}, + }, + { + .input = {"Intro: the name's keys and Shift", test_name_keys}, + .expectation = {}, + }, + { + .input = {"Intro: names the typer refuses", test_name_refused}, + .expectation = {}, + }, + { + .input = {"Intro: the new game's problems", test_new_game_problem}, + .expectation = {}, + }, +}; + +class Test_AutoStoryIntro : public UnitTest{ +public: + explicit Test_AutoStoryIntro(const IntroCase& test_case) + : UnitTest(std::format("PokemonLZA::AutoStory - {}", test_case.input.name)) + , m_case(test_case) + {} + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + return m_case.input.body(logger); + } + +private: + const IntroCase& m_case; +}; + +} // namespace + + +void add_tests_AutoStoryIntro(UnitTestDatabase& database){ + for (const IntroCase& item : INTRO_CASES){ + database.add(item); + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h new file mode 100644 index 0000000000..6ff5822681 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h @@ -0,0 +1,26 @@ +/* PokemonLZA AutoStory - New game intro Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntro_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryIntro_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Tests that need no console: the presses for the new game's language, look +// and name. +void add_tests_AutoStoryIntro(UnitTestDatabase& database); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif 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 a727d31d66..6843c95754 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -5,12 +5,18 @@ */ #include +#include +#include +#include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTools/ImageStats.h" +#include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" +#include "PokemonLZA_AutoStoryIntro.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -153,40 +159,118 @@ void mash_scene( } -void new_game_language(ConsoleHandle&, ProControllerContext& context){ - // TODO: a title screen and a language list detector; the waits are guesses. - pbf_press_button(context, BUTTON_A, 160ms, 5000ms); - pbf_press_button(context, BUTTON_A, 160ms, 5000ms); - context.wait_for_all_requests(); -} +namespace{ -void pick_first_look(ConsoleHandle&, ProControllerContext& context){ - // TODO: the shared MenuCursor (BDSP #305) once it reaches this branch, - // to read the highlight instead of relying on the edges clamping. - pbf_press_dpad(context, DPAD_UP, 160ms, 400ms); - for (int i = 0; i < 3; i++){ - pbf_press_dpad(context, DPAD_LEFT, 160ms, 400ms); +// The intro's screens are waited for by time until their detectors exist +// (PokemonLZA_AutoStoryIntro.h): until `is_screen` says the screen is up or +// `fixed_wait` passes. Either way the screen's frame is saved to +// DebugDumps, so a run records each one for the detectors' captures. +void wait_for_intro_screen( + ConsoleHandle& console, ProControllerContext& context, + std::string_view screen, bool (*is_screen)(const ImageViewRGB32&), Milliseconds fixed_wait +){ + const WallClock deadline = current_time() + fixed_wait; + bool seen = false; + while (current_time() < deadline){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && is_screen(frame)){ + seen = true; + break; + } + context.wait_for(250ms); } - pbf_press_button(context, BUTTON_A, 160ms, 3000ms); context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + console.log(std::format( + "AutoStory intro: {}: {} (waited up to {} ms).", + screen, seen ? "detected" : "not detected; the detector is not written, so the wait is fixed", fixed_wait.count() + )); + if (frame){ + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", std::string(screen), frame); + } } -void type_player_name(ConsoleHandle& console, ProControllerContext& context, const std::string& name){ - // TODO: a keyboard detector instead of the wait. - context.wait_for(3000ms); - // The system keyboard types lowercase. Its Shift (stick click) caps - // the next letter only, so it goes right before the name. Code entry - // takes upper case letters only and presses their keys, so the rest of - // the name comes out lower case. - std::string keys = name; - for (char& ch : keys){ - if ('a' <= ch && ch <= 'z'){ - ch = (char)(ch - 'a' + 'A'); +void press_intro_keys( + ConsoleHandle& console, ProControllerContext& context, + const std::vector& presses, Milliseconds after_last +){ + for (size_t i = 0; i < presses.size(); i++){ + const IntroKey key = presses[i]; + const Milliseconds release = i + 1 == presses.size() ? after_last : 400ms; + switch (key){ + case IntroKey::UP: + console.log("AutoStory intro: UP."); + pbf_press_dpad(context, DPAD_UP, 160ms, release); + break; + case IntroKey::DOWN: + console.log("AutoStory intro: DOWN."); + pbf_press_dpad(context, DPAD_DOWN, 160ms, release); + break; + case IntroKey::LEFT: + console.log("AutoStory intro: LEFT."); + pbf_press_dpad(context, DPAD_LEFT, 160ms, release); + break; + case IntroKey::RIGHT: + console.log("AutoStory intro: RIGHT."); + pbf_press_dpad(context, DPAD_RIGHT, 160ms, release); + break; + case IntroKey::A: + console.log("AutoStory intro: A."); + pbf_press_button(context, BUTTON_A, 160ms, release); + break; } } - pbf_press_button(context, BUTTON_LCLICK, 160ms, 400ms); context.wait_for_all_requests(); - FastCodeEntry::keyboard_enter_code(console, context, true, KeyboardLayout::QWERTY, keys, true); +} + +} // namespace + + +void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language){ + const std::optional> presses = language_list_presses(language); + if (!presses){ + throw UserSetupError(console, "AutoStory: the new game's language list has no such language."); + } + console.log(std::format("AutoStory intro: language {}: {} presses.", language_data(language).code, presses->size())); + // TODO: a title screen detector; the wait is a guess. + pbf_press_button(context, BUTTON_A, 160ms, 500ms); + wait_for_intro_screen(console, context, "language-list", is_language_list, 5000ms); + press_intro_keys(console, context, *presses, 5000ms); +} + +void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ + const std::optional> presses = look_picker_presses(look); + if (!presses){ + throw UserSetupError(console, std::format("AutoStory: the player look must be 1 to {}.", LOOK_COUNT)); + } + console.log(std::format("AutoStory intro: look {} of {}.", look, LOOK_COUNT)); + // The language's A already waited 5 s for this screen. + wait_for_intro_screen(console, context, "look-picker", is_look_picker, 0ms); + press_intro_keys(console, context, *presses, 3000ms); +} + +void type_player_name( + ConsoleHandle& console, ProControllerContext& context, + const std::string& name, bool first_letter_auto_caps +){ + const std::optional plan = name_keys(name, first_letter_auto_caps); + if (!plan){ + throw UserSetupError(console, std::format("AutoStory: the player name \"{}\" cannot be typed.", name)); + } + wait_for_intro_screen(console, context, "keyboard", is_keyboard, 3000ms); + console.log(std::format( + "AutoStory intro: typing \"{}\": keys {}, Shift first {}, keyboard capitalizes the first letter {}.", + name, plan->keys, plan->shift_first, first_letter_auto_caps + )); + // Code entry takes upper case letters and digits only and presses + // their keys. The keyboard types lower case; Shift capitalizes the next + // letter only, so it goes right before the name. + if (plan->shift_first){ + pbf_press_button(context, BUTTON_LCLICK, 160ms, 400ms); + context.wait_for_all_requests(); + } + FastCodeEntry::keyboard_enter_code(console, context, true, KeyboardLayout::QWERTY, plan->keys, true); context.wait_for(1000ms); // PLUS is the keyboard's OK. "Confirm Choices" opens on "Change hair // color"; "Ready!" is two rows down (console B, 2026-11-10). 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 310fd84676..53e18e6297 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -14,6 +14,7 @@ #include #include #include "Common/Cpp/Time.h" +#include "CommonFramework/Language.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" @@ -49,21 +50,31 @@ void mash_scene( bool tutorial_card_shows(const ImageViewRGB32& frame); -// The new game's opening, as recorded 2026-11-08 on console B. None of it -// reads the screen: each waits a fixed time for its screen. +// The new game's opening, as recorded 2026-11-08 on console B, with the +// player's choices (PokemonLZA_AutoStoryIntro.h has each one's presses). +// None of it reads the screen yet: each waits a fixed time for its screen, +// logs every press, and saves the screen's frame (DebugDumps) for the +// detectors to be built from. -// At the title screen with no save: A into the language list, A on its -// first entry (English, the default). -void new_game_language(ConsoleHandle& console, ProControllerContext& context); +// At the title screen with no save: A into the language list, DOWN to +// `language`'s entry (the list's order is Scarlet/Violet's: to be +// confirmed), A. Throws UserSetupError for a language the list lacks. +void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language); -// On the look picker, whose highlight starts at random: UP, then LEFT x3 -// to the first look (the edges clamp), A. -void pick_first_look(ConsoleHandle& console, ProControllerContext& context); +// On the look picker, whose highlight starts at random: UP and LEFT x3 to +// the top-left look (the edges clamp), RIGHT and DOWN to look `look` (1 to 8, +// a 2 x 4 grid, to be confirmed), A. +void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look); -// On the name screen: types `name` on the Switch keyboard (upper case -// letters and digits only, keyboard_enter_code()), + to finish, then -// DOWN x2 and A on "Ready!". -void type_player_name(ConsoleHandle& console, ProControllerContext& context, const std::string& name); +// On the name screen: types `name` on the Switch keyboard (letters and +// digits, a capital only as the first letter; name_keys()), + to finish, +// then DOWN x2 and A on "Ready!". `first_letter_auto_caps`: the keyboard +// starts with a capital by itself, so Shift is for a lower case first +// letter instead (to be confirmed). +void type_player_name( + ConsoleHandle& console, ProControllerContext& context, + const std::string& name, bool first_letter_auto_caps +); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 74c72bd708..718e04664f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -21,6 +21,7 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" +#include "Actions/PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStory.h" @@ -69,6 +70,23 @@ const StringSelectDatabase& checkpoint_database(){ AutoStory::AutoStory() : RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) + , PLAYER_NAME( + false, + "Player Name:
New game only. Letters and digits; a capital only as the first letter.", + LockMode::LOCK_WHILE_RUNNING, + "Kosmos", + "Kosmos" + ) + , PLAYER_LOOK( + "Player Look:
New game only. 1 to 8: left to right along the top row, then the bottom row.", + LockMode::LOCK_WHILE_RUNNING, + 1, 1, (uint8_t)LOOK_COUNT + ) + , NAME_FIRST_LETTER_AUTO_CAPS( + "Keyboard Capitalizes the First Letter:
New game only. Tick if the name comes out in lower case: the name keyboard capitalizes by itself and Shift would undo it.", + LockMode::LOCK_WHILE_RUNNING, + false + ) , GO_HOME_WHEN_DONE(false) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, @@ -78,6 +96,9 @@ AutoStory::AutoStory() { PA_ADD_OPTION(RUN); PA_ADD_OPTION(BATTLE_AI); + PA_ADD_OPTION(PLAYER_NAME); + PA_ADD_OPTION(PLAYER_LOOK); + PA_ADD_OPTION(NAME_FIRST_LETTER_AUTO_CAPS); PA_ADD_OPTION(GO_HOME_WHEN_DONE); PA_ADD_OPTION(NOTIFICATIONS); } @@ -123,6 +144,15 @@ StoryData load_run_story(ConsoleHandle& console){ } // namespace +NewGameChoices AutoStory::new_game_choices(ConsoleHandle& console, bool check) const{ + NewGameChoices choices{.name = PLAYER_NAME, .look = PLAYER_LOOK, .name_first_letter_auto_caps = NAME_FIRST_LETTER_AUTO_CAPS}; + const std::string problem = check ? new_game_problem(RUN.language(), choices) : std::string(); + if (!problem.empty()){ + throw UserSetupError(console, problem); + } + return choices; +} + void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ const StoryData story_data = load_run_story(env.console); const std::vector& rows = story_data.checkpoints; @@ -133,7 +163,10 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex } require_player(env.console, context, BUTTON_L); - StoryEnv story{.env = env, .context = context, .language = RUN.language(), .battle_ai = BATTLE_AI}; + StoryEnv story{ + .env = env, .context = context, .new_game = new_game_choices(env.console, first == 0), + .language = RUN.language(), .battle_ai = BATTLE_AI + }; PlzaConsoleBackend backend(story); const StoryGame game = make_plza_story_game(story, story_data.autosaves); 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 c7096ffad5..7fdfdcaac7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -17,7 +17,9 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStory_H #define PokemonAutomation_PokemonLZA_AutoStory_H -#include "Common/Cpp/Options/EnumDropdownOption.h" +#include "Common/Cpp/Options/BooleanCheckBoxOption.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" @@ -49,9 +51,18 @@ class AutoStory : public SingleSwitchProgramInstance{ virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; private: + // The new game's choices; with `check`, throws UserSetupError for ones the + // intro cannot play. + NewGameChoices new_game_choices(ConsoleHandle& console, bool check) const; + // The start and end checkpoints, attempts, checks and language. Pokemon::StoryRunOptions RUN; BattleAIOption BATTLE_AI; + // The new game's choices (01.00): the language is RUN's. The look and + // the language list's order are guesses from Scarlet/Violet's screens. + StringOption PLAYER_NAME; + SimpleIntegerOption PLAYER_LOOK; + BooleanCheckBoxOption NAME_FIRST_LETTER_AUTO_CAPS; GoHomeWhenDoneOption GO_HOME_WHEN_DONE; EventNotificationsOption NOTIFICATIONS; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h index 8a29077895..cd8a1c5667 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -26,6 +26,7 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" #include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.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" @@ -46,10 +47,9 @@ namespace PokemonLZA{ struct StoryEnv{ SingleSwitchProgramEnvironment& env; ProControllerContext& context; - // The new game's name: letters and digits; type_player_name() capitalizes - // the first letter only. The lab's player is Kosmos. - std::string player_name = "Kosmos"; - // The game's language, for the steps that read text. + // The new game's name and look. + NewGameChoices new_game; + // The game's language: the new game's pick, and the steps that read text. Language language = Language::English; BattleAIOption& battle_ai; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 1d95606648..4002d87c36 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -68,9 +68,11 @@ using ConsoleStep = void (*)(StoryEnv& env); // The GAME actions that are one ConsoleStep each, by name: console_only. const std::map>& console_game_actions(){ static const std::map> actions{ - {"new_game_language", [](StoryEnv& env){ new_game_language(env.env.console, env.context); }}, - {"pick_look", [](StoryEnv& env){ pick_first_look(env.env.console, env.context); }}, - {"type_player_name", [](StoryEnv& env){ type_player_name(env.env.console, env.context, env.player_name); }}, + {"new_game_language", [](StoryEnv& env){ new_game_language(env.env.console, env.context, env.language); }}, + {"pick_look", [](StoryEnv& env){ pick_player_look(env.env.console, env.context, env.new_game.look); }}, + {"type_player_name", [](StoryEnv& env){ + type_player_name(env.env.console, env.context, env.new_game.name, env.new_game.name_first_letter_auto_caps); + }}, {"choose_0", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 0); }}, {"choose_1", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 1); }}, }; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 1bbf69eaa1..d191949ebe 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2335,6 +2335,12 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.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_AutoStoryIntro.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.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 From 756e46344a56e57dfffef4ab9e20e79c42cfeb4e Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 12 Nov 2026 17:45:43 -0800 Subject: [PATCH 08/33] PokemonLZA: AutoStory: new game presses for the language, look and name Fills in the intro's pure functions: the language list's DOWN count, the look picker's moves from the top-left, and the name's keys with Shift for the capital first letter. Options: PLAYER_NAME, PLAYER_LOOK and NAME_FIRST_LETTER_AUTO_CAPS; the language is the run's. Each screen logs every press and saves its frame, with detector hooks to fill in. Co-Authored-By: Claude Sonnet 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryIntro.cpp | 89 +++++++++++++++++-- 1 file changed, 81 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp index 9c44f6e22c..e6aaf00833 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp @@ -4,6 +4,8 @@ * */ +#include +#include #include "PokemonLZA_AutoStoryIntro.h" namespace PokemonAutomation{ @@ -11,20 +13,91 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -std::optional> language_list_presses(Language){ - return std::nullopt; +namespace{ + +constexpr size_t LOOK_COLUMNS = 4; + +std::optional language_list_index(Language language){ + switch (language){ + case Language::English: return 0; + case Language::Spanish: return 1; + case Language::French: return 2; + case Language::German: return 3; + case Language::Italian: return 4; + case Language::Japanese: return 5; + case Language::Korean: return 6; + case Language::ChineseSimplified: return 7; + case Language::ChineseTraditional: return 8; + default: return std::nullopt; + } } -std::optional> look_picker_presses(size_t){ - return std::nullopt; +} // namespace + + +std::optional> language_list_presses(Language language){ + const std::optional index = language_list_index(language); + if (!index){ + return std::nullopt; + } + std::vector presses(*index, IntroKey::DOWN); + presses.push_back(IntroKey::A); + return presses; } -std::optional name_keys(std::string_view, bool){ - return std::nullopt; + +std::optional> look_picker_presses(size_t look){ + if (look < 1 || look > LOOK_COUNT){ + return std::nullopt; + } + const size_t row = (look - 1) / LOOK_COLUMNS; + const size_t column = (look - 1) % LOOK_COLUMNS; + std::vector presses; + presses.push_back(IntroKey::UP); + presses.insert(presses.end(), LOOK_COLUMNS - 1, IntroKey::LEFT); + presses.insert(presses.end(), column, IntroKey::RIGHT); + presses.insert(presses.end(), row, IntroKey::DOWN); + presses.push_back(IntroKey::A); + return presses; } -std::string new_game_problem(Language, const NewGameChoices&){ - return "TODO"; + +std::optional name_keys(std::string_view name, bool first_letter_auto_caps){ + if (name.empty()){ + return std::nullopt; + } + NameKeys result; + for (size_t i = 0; i < name.size(); i++){ + const unsigned char ch = (unsigned char)name[i]; + if (ch > 127 || !std::isalnum(ch)){ + return std::nullopt; + } + if (i > 0 && std::isupper(ch)){ + return std::nullopt; + } + result.keys.push_back((char)std::toupper(ch)); + } + const unsigned char first = (unsigned char)name[0]; + if (std::isalpha(first)){ + result.shift_first = (std::isupper(first) != 0) != first_letter_auto_caps; + } + return result; +} + + +std::string new_game_problem(Language language, const NewGameChoices& choices){ + if (!language_list_presses(language)){ + return "The new game's language list has no such language."; + } + if (!look_picker_presses(choices.look)){ + return std::format("The player look must be 1 to {}.", LOOK_COUNT); + } + if (!name_keys(choices.name, choices.name_first_letter_auto_caps)){ + return std::format( + "The player name \"{}\" must be letters and digits, with a capital only as its first letter.", choices.name + ); + } + return std::string(); } From e0bdeb3b11ba3e34bc9480bfa37696fa1812ceac Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 00:17:57 -0800 Subject: [PATCH 09/33] PokemonLZA: AutoStory: launch from HOME and read the 2x5 language list A new game has no title screen: launch goes straight to the language list, so the old blind A picked English. 01.00 now starts on HOME (closes the game, launches it with start_game_from_home(), which handles the online license check) or on the language list itself, and fails with a setup error otherwise. The list's detector reads which of its 10 boxes is highlighted; the cursor moves one press at a time and is read back before A. Entries map per console B's 2x5 grid (Spanish = Espana). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryIntro.cpp | 29 +--- .../Actions/PokemonLZA_AutoStoryIntro.h | 19 +-- .../PokemonLZA_AutoStoryIntroScreens.cpp | 83 +++++++++- .../PokemonLZA_AutoStoryIntroScreens.h | 18 +- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 156 ++++++++++++++++-- .../Actions/PokemonLZA_AutoStoryIntro_Tests.h | 2 +- .../PokemonLZA_AutoStoryLanguageList.cpp | 55 ++++++ .../PokemonLZA_AutoStoryLanguageList.h | 54 ++++++ .../Actions/PokemonLZA_AutoStoryScenes.cpp | 96 ++++++++++- .../Actions/PokemonLZA_AutoStoryScenes.h | 19 ++- .../AutoStory/PokemonLZA_AutoStory.cpp | 2 +- .../AutoStory/StoryData/plza-01.00.plan.json | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 13 files changed, 459 insertions(+), 78 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp index e6aaf00833..c00c954288 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp @@ -7,6 +7,7 @@ #include #include #include "PokemonLZA_AutoStoryIntro.h" +#include "PokemonLZA_AutoStoryLanguageList.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -17,35 +18,9 @@ namespace{ constexpr size_t LOOK_COLUMNS = 4; -std::optional language_list_index(Language language){ - switch (language){ - case Language::English: return 0; - case Language::Spanish: return 1; - case Language::French: return 2; - case Language::German: return 3; - case Language::Italian: return 4; - case Language::Japanese: return 5; - case Language::Korean: return 6; - case Language::ChineseSimplified: return 7; - case Language::ChineseTraditional: return 8; - default: return std::nullopt; - } -} - } // namespace -std::optional> language_list_presses(Language language){ - const std::optional index = language_list_index(language); - if (!index){ - return std::nullopt; - } - std::vector presses(*index, IntroKey::DOWN); - presses.push_back(IntroKey::A); - return presses; -} - - std::optional> look_picker_presses(size_t look){ if (look < 1 || look > LOOK_COUNT){ return std::nullopt; @@ -86,7 +61,7 @@ std::optional name_keys(std::string_view name, bool first_letter_auto_ std::string new_game_problem(Language language, const NewGameChoices& choices){ - if (!language_list_presses(language)){ + if (!language_list_index(language)){ return "The new game's language list has no such language."; } if (!look_picker_presses(choices.look)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h index f8dbdb5a4c..e24bd107e1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h @@ -3,12 +3,14 @@ * From: https://github.com/PokemonAutomation/ * * The new game's opening screens (language list, look picker, name - * keyboard): the presses each choice takes as pure functions. The screens' + * keyboard): the presses each choice takes as pure functions; the language + * list's are in PokemonLZA_AutoStoryLanguageList.h. The screens' * detectors are in PokemonLZA_AutoStoryIntroScreens.h. * - * Everything about the screens' layout is a guess from Scarlet/Violet's, - * to be confirmed on a console (see the TODOs): the language list's order, - * the look picker's 2 x 4 grid, and what the name keyboard does with Shift. + * The language list is as seen on console B (2026-11-13). The rest is a + * guess from Scarlet/Violet's, to be confirmed on a console (see the + * TODOs): the look picker's 2 x 4 grid, and what the name keyboard does + * with Shift. * */ @@ -36,15 +38,6 @@ enum class IntroKey{ }; -// The language list's entries, top to bottom, as Scarlet/Violet shows them -// (English, Espanol, Francais, Deutsch, Italiano, Japanese, Korean, -// Chinese Simplified, Chinese Traditional). TODO: confirm LZA's order on a -// console. -// From the top entry: DOWN to the language's entry, then A. Nullopt for a -// language the list lacks. -std::optional> language_list_presses(Language language); - - // The number of looks on the picker: a grid of 2 rows of 4 faces, as // Scarlet/Violet's, numbered 1 to LOOK_COUNT left to right along the top // row, then the bottom row. TODO: confirm the grid and the cursor's moves diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp index cdb9381abb..495c7fea47 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -4,6 +4,9 @@ * */ +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "PokemonLZA_AutoStoryLanguageList.h" #include "PokemonLZA_AutoStoryIntroScreens.h" namespace PokemonAutomation{ @@ -11,8 +14,84 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -bool is_language_list(const ImageViewRGB32&){ - return false; +namespace{ + +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); +} + +// Measured on console B (2026-11-13): 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 = image_stats(extract_box_reference(frame, ImageFloatBox(0.4896, 0.331, 0.0208, 0.447))); + return gap.count > 0 && gap.average.sum() / 3 < 70; +} + +} // namespace + + +std::optional read_language_list_cursor(const ImageViewRGB32& frame){ + if (!frame || frame.width() < 160 || frame.height() < 90){ + return std::nullopt; + } + if (!column_gap_dark(frame)){ + return std::nullopt; + } + std::optional highlighted; + for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ + const ImageStats stats = image_stats(extract_box_reference(frame, language_box_strip(index))); + switch (classify_list_box(stats)){ + case ListBox::HIGHLIGHTED: + if (highlighted){ + return std::nullopt; + } + highlighted = index; + break; + case ListBox::PLAIN: + break; + case ListBox::OTHER: + return std::nullopt; + } + } + return highlighted; +} + +bool is_language_list(const ImageViewRGB32& frame){ + return read_language_list_cursor(frame).has_value(); } bool is_look_picker(const ImageViewRGB32&){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h index 20e742e354..c9cd566bbf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h @@ -2,16 +2,18 @@ * * From: https://github.com/PokemonAutomation/ * - * One detector per intro screen, for the actions' fixed waits - * (PokemonLZA_AutoStoryScenes.h) to end early once they are written. TODO: - * each returns false until a detector is built from the frames a run saves - * (DebugDumps/PokemonLZA/AutoStory/Intro). + * One detector per intro screen. The language list's is measured on + * console B (2026-11-13). TODO: the look picker's and the keyboard's return + * false until they are built from the frames a run saves + * (DebugDumps/PokemonLZA/AutoStory/Intro); their actions' + * (PokemonLZA_AutoStoryScenes.h) waits are fixed until then. * */ #ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H #define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H +#include #include "CommonFramework/ImageTypes/ImageViewRGB32.h" namespace PokemonAutomation{ @@ -19,7 +21,13 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -// The "Which language will you play in?" list. +// On the "Which language will you play in?" list, the highlighted entry +// (numbered as language_list_index() numbers them): 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); + +// The language list, with one entry highlighted. bool is_language_list(const ImageViewRGB32& frame); // The look picker's grid of faces. diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index b2abc9b1fc..d7a06f06cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -4,12 +4,18 @@ * */ +#include #include +#include #include #include #include +#include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" #include "PokemonLZA_AutoStoryIntro.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLanguageList.h" #include "PokemonLZA_AutoStoryIntro_Tests.h" namespace PokemonAutomation{ @@ -33,35 +39,139 @@ Keys joined(std::initializer_list parts){ return all; } -UnitTestResult test_language_presses(Logger&){ +UnitTestResult test_language_index(Logger&){ struct Row{ Language language; - size_t downs; + size_t index; }; + // Down the left column, then the right; entry 2 is Latin American + // Spanish, which Language lacks. const Row rows[] = { {Language::English, 0}, {Language::Spanish, 1}, - {Language::French, 2}, - {Language::German, 3}, - {Language::Italian, 4}, - {Language::Japanese, 5}, - {Language::Korean, 6}, - {Language::ChineseSimplified, 7}, - {Language::ChineseTraditional, 8}, + {Language::French, 3}, + {Language::German, 4}, + {Language::Italian, 5}, + {Language::Japanese, 6}, + {Language::Korean, 7}, + {Language::ChineseSimplified, 8}, + {Language::ChineseTraditional, 9}, }; for (const Row& row : rows){ - const auto presses = language_list_presses(row.language); - const Keys expected = joined({repeated(IntroKey::DOWN, row.downs), {IntroKey::A}}); - if (!presses || *presses != expected){ - return std::format("{}: expected {} DOWN then A.", language_data(row.language).code, row.downs); + if (language_list_index(row.language) != row.index){ + return std::format("{}: expected entry {}.", language_data(row.language).code, row.index); } } - if (language_list_presses(Language::None)){ + if (language_list_index(Language::None)){ return "Language::None has no entry in the list."; } return true; } +UnitTestResult test_language_moves(Logger&){ + struct Row{ + size_t from; + size_t to; + Keys expected; + }; + const Row rows[] = { + {0, 0, {}}, + // English to Deutsch: down the left column. + {0, 4, repeated(IntroKey::DOWN, 4)}, + // English to Italiano: across. + {0, 5, {IntroKey::RIGHT}}, + // English to Traditional Chinese: across, then down. + {0, 9, joined({{IntroKey::RIGHT}, repeated(IntroKey::DOWN, 4)})}, + // Korean to Espanol (Espana): across, then up. + {7, 1, joined({{IntroKey::LEFT}, repeated(IntroKey::UP, 1)})}, + // Deutsch to Italiano: no wrap round the bottom edge. + {4, 5, joined({{IntroKey::RIGHT}, repeated(IntroKey::UP, 4)})}, + }; + for (const Row& row : rows){ + const auto moves = language_list_moves(row.from, row.to); + if (!moves || *moves != row.expected){ + return std::format("Entry {} to {}: expected {} presses.", row.from, row.to, row.expected.size()); + } + } + if (language_list_moves(0, LANGUAGE_LIST_SIZE) || language_list_moves(LANGUAGE_LIST_SIZE, 0)){ + return "Entries outside the list have no moves."; + } + return true; +} + +// The language list drawn as console B shows it (1920 x 1080): dark blue, +// 10 slate boxes 576 x 84, the columns at x 347 and 996, the rows from +// y 342, 108 apart, entry `highlighted` (if any) white. +ImageRGB32 language_list_frame(std::optional highlighted){ + ImageRGB32 image(1920, 1080); + image.fill(0xff091838); + for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ + const size_t left = index < LANGUAGE_LIST_ROWS ? 347 : 996; + const size_t top = 342 + 108 * (index % LANGUAGE_LIST_ROWS); + const uint32_t color = highlighted == index ? 0xffffffff : 0xff363c53; + for (size_t y = top; y < top + 84; y++){ + for (size_t x = left; x < left + 576; x++){ + image.pixel(x, y) = color; + } + } + } + return image; +} + +UnitTestResult test_language_list_synthetic(Logger&){ + for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ + if (read_language_list_cursor(language_list_frame(index)) != index){ + return std::format("Expected the highlight read on entry {}.", index); + } + } + if (is_language_list(language_list_frame(std::nullopt))){ + return "Expected no list without a highlight."; + } + ImageRGB32 two = language_list_frame(0); + for (size_t y = 450; y < 534; y++){ + for (size_t x = 347; x < 923; x++){ + two.pixel(x, y) = 0xffffffff; + } + } + if (is_language_list(two)){ + return "Expected no list with two highlights."; + } + for (const uint32_t fill : {0xff000000u, 0xffffffffu, 0xff363c53u}){ + ImageRGB32 flat(1920, 1080); + flat.fill(fill); + if (is_language_list(flat)){ + return std::format("Expected a flat {:08x} frame not to be the list.", fill); + } + } + return true; +} + +UnitTestResult test_language_list_empty(Logger&){ + if (is_language_list(ImageRGB32()) || is_language_list(ImageRGB32(1, 1)) || is_language_list(ImageRGB32(40, 20))){ + return "Expected empty and tiny frames not to be the list."; + } + return true; +} + +// The console's frame, from the folder in PLZA_INTRO_SCREENS +// (~/BDSPLab/intro-screens/plza on the lab Mac): language-list.png, the +// list as a new game opens it, English highlighted. +UnitTestResult test_language_list_capture(Logger&){ + const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); + } + const ImageRGB32 frame(std::format("{}/language-list.png", folder)); + const std::optional cursor = read_language_list_cursor(frame); + if (!cursor){ + return "language-list.png: expected the language list, read none."; + } + if (*cursor != 0){ + return std::format("language-list.png: expected English (entry 0) highlighted, read entry {}.", *cursor); + } + return true; +} + UnitTestResult test_look_presses(Logger&){ // Look 1 is the top-left face: the clamp, then A. const Keys clamp = joined({{IntroKey::UP}, repeated(IntroKey::LEFT, 3)}); @@ -162,7 +272,23 @@ struct IntroCase{ const IntroCase INTRO_CASES[] = { { - .input = {"Intro: the language list's presses", test_language_presses}, + .input = {"Intro: the language list's entries", test_language_index}, + .expectation = {}, + }, + { + .input = {"Intro: the language list's cursor moves", test_language_moves}, + .expectation = {}, + }, + { + .input = {"Intro: the language list's highlight, synthetic frames", test_language_list_synthetic}, + .expectation = {}, + }, + { + .input = {"Intro: empty frames are not the language list", test_language_list_empty}, + .expectation = {}, + }, + { + .input = {"Intro: the language list on console B (PLZA_INTRO_SCREENS)", test_language_list_capture}, .expectation = {}, }, { diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h index 6ff5822681..619100b824 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h @@ -15,7 +15,7 @@ namespace PokemonLZA{ // Tests that need no console: the presses for the new game's language, look -// and name. +// and name, and the language list's detector. void add_tests_AutoStoryIntro(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp new file mode 100644 index 0000000000..38f97ed8ed --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp @@ -0,0 +1,55 @@ +/* PokemonLZA AutoStory - New game language list + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryLanguageList.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +std::optional language_list_index(Language language){ + switch (language){ + case Language::English: return 0; + case Language::Spanish: return 1; + case Language::French: return 3; + case Language::German: return 4; + case Language::Italian: return 5; + case Language::Japanese: return 6; + case Language::Korean: return 7; + case Language::ChineseSimplified: return 8; + case Language::ChineseTraditional: return 9; + default: 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; + } + const size_t from_column = from / LANGUAGE_LIST_ROWS; + const size_t from_row = from % LANGUAGE_LIST_ROWS; + const size_t to_column = to / LANGUAGE_LIST_ROWS; + const size_t to_row = to % LANGUAGE_LIST_ROWS; + std::vector moves; + if (to_column > from_column){ + moves.insert(moves.end(), to_column - from_column, IntroKey::RIGHT); + }else{ + moves.insert(moves.end(), from_column - to_column, IntroKey::LEFT); + } + if (to_row > from_row){ + moves.insert(moves.end(), to_row - from_row, IntroKey::DOWN); + }else{ + moves.insert(moves.end(), from_row - to_row, IntroKey::UP); + } + return moves; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h new file mode 100644 index 0000000000..7a6aa857c9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h @@ -0,0 +1,54 @@ +/* PokemonLZA AutoStory - New game language list + * + * From: https://github.com/PokemonAutomation/ + * + * The new game's language list: where each language is, and the presses + * between two entries, as pure functions. Its detector is in + * PokemonLZA_AutoStoryIntroScreens.h. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLanguageList_H +#define PokemonAutomation_PokemonLZA_AutoStoryLanguageList_H + +#include +#include +#include "CommonFramework/Language.h" +#include "PokemonLZA_AutoStoryIntro.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The language list (console B, 2026-11-13): 2 columns of 5 entries, +// numbered down the left column, then down the right one: +// 0 English 5 Italiano +// 1 Espanol (Espana) 6 Japanese +// 2 Espanol (Latinoamerica) 7 Korean +// 3 Francais 8 Chinese Simplified +// 4 Deutsch 9 Chinese Traditional +// The cursor starts on English. + +// The rows in each column. +constexpr size_t LANGUAGE_LIST_ROWS = 5; + +// The entries: 2 columns of LANGUAGE_LIST_ROWS. +constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; + +// The list's entry for `language`. Language::Spanish is Espanol (Espana): +// Language has no Latin American Spanish. Nullopt for a language the list +// lacks. +std::optional language_list_index(Language language); + +// The presses that move the cursor from entry `from` to entry `to`: LEFT +// or RIGHT to the column, then UP or DOWN to the row, never round an edge. +// Empty when `from` is `to`; nullopt for an entry outside the list. +std::optional> language_list_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_AutoStoryScenes.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp index 6843c95754..2330263d40 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -14,9 +14,12 @@ #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" #include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" #include "PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryLanguageList.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -224,19 +227,98 @@ void press_intro_keys( context.wait_for_all_requests(); } +// After the launch: the license check, the logos, until the language list +// shows. Saves its first frame to DebugDumps. +void wait_for_language_list(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + while (current_time() < deadline){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && is_language_list(frame)){ + console.log("AutoStory intro: language-list: detected."); + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "language-list", frame); + return; + } + context.wait_for(250ms); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: the language list did not show within {} ms of the launch.", timeout.count()), + console + ); +} + +// On the language list: one press at a time towards entry `target`, +// reading the highlight after each, until it is on `target`. A dropped +// press or a frame caught mid-move is read again on the next turn. +void move_language_cursor(ConsoleHandle& console, ProControllerContext& context, size_t target){ + for (size_t attempt = 0; attempt < 20; attempt++){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + const std::optional cursor = frame ? read_language_list_cursor(frame) : std::nullopt; + if (!cursor){ + console.log("AutoStory intro: language-list: no highlight read; reading again."); + context.wait_for(250ms); + continue; + } + if (*cursor == target){ + console.log(std::format("AutoStory intro: language-list: the highlight is on entry {}.", target)); + return; + } + const std::optional> moves = language_list_moves(*cursor, target); + if (!moves || moves->empty()){ + break; + } + console.log(std::format("AutoStory intro: language-list: the highlight is on entry {}.", *cursor)); + press_intro_keys(console, context, {moves->front()}, 400ms); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: the language list's highlight did not reach entry {}.", target), + console + ); +} + +// 01.00's start: the language list already on screen, or the Switch HOME +// screen with the game's tile highlighted (the game open or closed). From +// HOME: closes the game, so the launch is always fresh, starts it +// (start_game_from_home(): the user select and the online license check) +// and waits for the list: a new game has no title screen. Anything else +// on screen is a setup mistake. +void launch_to_language_list(ConsoleHandle& console, ProControllerContext& context){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && is_language_list(frame)){ + console.log("AutoStory intro: start: the language list is on screen; no launch."); + return; + } + HomeMenuDetector home(console, COLOR_RED); + if (!frame || !home.detect_only(frame)){ + throw UserSetupError(console, + "AutoStory 01.00: start on the Switch HOME screen with the game's tile highlighted and no save, " + "or on the game's language list. The screen is neither." + ); + } + console.log("AutoStory intro: start: the HOME screen; closing the game, then launching it."); + close_game_from_home(console, context); + start_game_from_home(console, context, true, 0, 0); + // The launch's logos: the user saw the list come no sooner than this. + context.wait_for(5000ms); + wait_for_language_list(console, context, 90s); +} + } // namespace void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language){ - const std::optional> presses = language_list_presses(language); - if (!presses){ + const std::optional target = language_list_index(language); + if (!target){ throw UserSetupError(console, "AutoStory: the new game's language list has no such language."); } - console.log(std::format("AutoStory intro: language {}: {} presses.", language_data(language).code, presses->size())); - // TODO: a title screen detector; the wait is a guess. - pbf_press_button(context, BUTTON_A, 160ms, 500ms); - wait_for_intro_screen(console, context, "language-list", is_language_list, 5000ms); - press_intro_keys(console, context, *presses, 5000ms); + console.log(std::format("AutoStory intro: language {}: entry {} of the list.", language_data(language).code, *target)); + launch_to_language_list(console, context); + move_language_cursor(console, context, *target); + press_intro_keys(console, context, {IntroKey::A}, 5000ms); } void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ 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 53e18e6297..f3180794b0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -52,13 +52,20 @@ bool tutorial_card_shows(const ImageViewRGB32& frame); // The new game's opening, as recorded 2026-11-08 on console B, with the // player's choices (PokemonLZA_AutoStoryIntro.h has each one's presses). -// None of it reads the screen yet: each waits a fixed time for its screen, -// logs every press, and saves the screen's frame (DebugDumps) for the -// detectors to be built from. +// Each logs every press and saves its screen's frame (DebugDumps) for the +// detectors to be built from. Only the language list's is built: the look +// picker and the keyboard wait a fixed time for their screens. -// At the title screen with no save: A into the language list, DOWN to -// `language`'s entry (the list's order is Scarlet/Violet's: to be -// confirmed), A. Throws UserSetupError for a language the list lacks. +// 01.00's first step. It starts on the Switch HOME screen with the game's +// tile highlighted and no save, the game open or closed: closes the game +// so the launch is fresh, starts it (start_game_from_home(): the user +// select and the online license check), waits 5 s, then up to 90 s for +// the language list (a new game has no title screen). Started on the +// language list itself, it skips the launch. Then moves the list's +// highlight to `language`'s entry, reading it after each press, and +// presses A. Throws UserSetupError for a language the list lacks or any +// other starting screen, OperationFailedException if the list does not +// show or the highlight does not get there. void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language); // On the look picker, whose highlight starts at random: UP and LEFT x3 to diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 718e04664f..47cf687e44 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -38,7 +38,7 @@ AutoStory_Descriptor::AutoStory_Descriptor() "PokemonLZA:AutoStory", std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", - "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console.", + "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. Checkpoint 01.00 (a new game) starts on the Switch HOME screen with the game's tile highlighted and no save: it closes the game if it is open and launches it fresh. It may also start on the game's language list.", PanelQualityStanding::DEVELOPER, ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, 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 7cfea81a4e..bafb2dc650 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 @@ -8,7 +8,7 @@ { "id": "language", "kind": "game_action", - "why": "step 1: start a new game in English", + "why": "step 1: from the HOME screen with the game highlighted, launch it (no save: it opens on the language list) and pick English", "action": "new_game_language" }, { diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index f1ecd70422..8f19603ac7 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2345,6 +2345,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.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 From 91fbcb74705e5e946262be2c843d98058c9e17c3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 00:58:20 -0800 Subject: [PATCH 10/33] PokemonLZA: AutoStory: launch the selected HOME tile; name on the system keyboard 01.00 starts on the HOME screen with PLZA's tile selected. Its first event, launch_from_home, launches the selected tile without moving the cursor (closing it first if it is running: X, then A on the close dialog), then waits for the language list. The old start closed the game through a helper that presses DOWN/UP/HOME, which put the cursor on the first tile and launched FireRed. The launch takes the first screen's detector, so it can move to the shared core for BDSP and FRLG. new_game_language only works the language list. The name screen waits for the Switch system keyboard (#62's detector) and types with type_on_system_keyboard(); the look picker is pressed blind and logged as not checked. Each intro screen, the confirm menu and the frame after "Ready!" are dumped to DebugDumps. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryIntroScreens.cpp | 4 - .../PokemonLZA_AutoStoryIntroScreens.h | 14 +- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 77 ++++++++ .../Actions/PokemonLZA_AutoStoryLaunch.cpp | 145 +++++++++++++++ .../Actions/PokemonLZA_AutoStoryLaunch.h | 72 ++++++++ .../Actions/PokemonLZA_AutoStoryScenes.cpp | 167 +++++++++++------- .../Actions/PokemonLZA_AutoStoryScenes.h | 47 +++-- .../AutoStory/PokemonLZA_AutoStory.cpp | 2 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 1 + .../AutoStory/PokemonLZA_AutoStoryGame.h | 3 +- .../PokemonLZA_AutoStoryStoryFiles.h | 4 +- .../AutoStory/StoryData/plza-01.00.plan.json | 8 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 13 files changed, 452 insertions(+), 94 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp index 495c7fea47..5b5a7f485f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -98,10 +98,6 @@ bool is_look_picker(const ImageViewRGB32&){ return false; } -bool is_keyboard(const ImageViewRGB32&){ - return false; -} - } // namespace PokemonLZA } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h index c9cd566bbf..37adfd92f7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h @@ -3,10 +3,11 @@ * From: https://github.com/PokemonAutomation/ * * One detector per intro screen. The language list's is measured on - * console B (2026-11-13). TODO: the look picker's and the keyboard's return - * false until they are built from the frames a run saves - * (DebugDumps/PokemonLZA/AutoStory/Intro); their actions' - * (PokemonLZA_AutoStoryScenes.h) waits are fixed until then. + * console B (2026-11-13). The name screen is the Switch system keyboard + * (NintendoSwitch_SystemKeyboardDetector.h). TODO: the look picker's + * returns false until it is built from the frames a run saves + * (DebugDumps/PokemonLZA/AutoStory/Intro); its action's + * (PokemonLZA_AutoStoryScenes.h) wait is fixed until then. * */ @@ -30,11 +31,10 @@ std::optional read_language_list_cursor(const ImageViewRGB32& frame); // The language list, with one entry highlighted. bool is_language_list(const ImageViewRGB32& frame); -// The look picker's grid of faces. +// The look picker's 2 x 4 grid of faces. TODO: always false until a +// capture of the screen exists. bool is_look_picker(const ImageViewRGB32& frame); -// The Switch keyboard on the name screen. -bool is_keyboard(const ImageViewRGB32& frame); } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index d7a06f06cf..ecd18a151a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -16,6 +16,7 @@ #include "PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryLanguageList.h" +#include "PokemonLZA_AutoStoryLaunch.h" #include "PokemonLZA_AutoStoryIntro_Tests.h" namespace PokemonAutomation{ @@ -172,6 +173,74 @@ UnitTestResult test_language_list_capture(Logger&){ return true; } +// 01.00's start on frames whose HOME reading is given: only HOME +// launches; the language list and anything else (an empty frame too) are +// refused. +UnitTestResult test_launch_start_synthetic(Logger&){ + const ImageRGB32 list = language_list_frame(0); + ImageRGB32 game(1920, 1080); + game.fill(0xff405060); + const ImageRGB32 empty; + struct Row{ + std::string_view name; + const ImageRGB32* frame; + bool home; + LaunchStart expected; + }; + const Row rows[] = { + {"HOME", &game, true, LaunchStart::HOME_MENU}, + {"a game frame", &game, false, LaunchStart::OTHER}, + {"the language list", &list, false, LaunchStart::FIRST_SCREEN}, + {"the language list, HOME read", &list, true, LaunchStart::FIRST_SCREEN}, + {"an empty frame", &empty, false, LaunchStart::OTHER}, + {"an empty frame, HOME read", &empty, true, LaunchStart::OTHER}, + }; + for (const Row& row : rows){ + if (read_launch_start(*row.frame, row.home, is_language_list) != row.expected){ + return std::format("{}: expected start {}.", row.name, (int)row.expected); + } + } + if (read_launch_start(game, true, ScreenCheck()) != LaunchStart::HOME_MENU){ + return "HOME with no first-screen detector: expected a launch."; + } + return true; +} + +// 01.00's start on console B's frames, from the folder in +// PLZA_INTRO_SCREENS: language-list.png, and if present home.png (the HOME +// menu) and in-game.png (the station). The HOME reading is +// HomeMenuDetector's, which needs a console: here it is given. +UnitTestResult test_launch_start_capture(Logger&){ + const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); + } + struct Row{ + std::string_view file; + bool home; + LaunchStart expected; + }; + const Row rows[] = { + {"language-list.png", false, LaunchStart::FIRST_SCREEN}, + {"home.png", true, LaunchStart::HOME_MENU}, + {"in-game.png", false, LaunchStart::OTHER}, + }; + for (const Row& row : rows){ + const std::string path = std::format("{}/{}", folder, row.file); + if (!Filesystem::exists(Filesystem::Path(path))){ + if (row.expected == LaunchStart::FIRST_SCREEN){ + return std::format("{} is missing.", row.file); + } + continue; + } + const ImageRGB32 frame(path); + if (read_launch_start(frame, row.home, is_language_list) != row.expected){ + return std::format("{}: expected start {}.", row.file, (int)row.expected); + } + } + return true; +} + UnitTestResult test_look_presses(Logger&){ // Look 1 is the top-left face: the clamp, then A. const Keys clamp = joined({{IntroKey::UP}, repeated(IntroKey::LEFT, 3)}); @@ -291,6 +360,14 @@ const IntroCase INTRO_CASES[] = { .input = {"Intro: the language list on console B (PLZA_INTRO_SCREENS)", test_language_list_capture}, .expectation = {}, }, + { + .input = {"Intro: the start screen, synthetic frames", test_launch_start_synthetic}, + .expectation = {}, + }, + { + .input = {"Intro: the start screen on console B (PLZA_INTRO_SCREENS)", test_launch_start_capture}, + .expectation = {}, + }, { .input = {"Intro: the look picker's presses", test_look_presses}, .expectation = {}, 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..60330528c7 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp @@ -0,0 +1,145 @@ +/* PokemonLZA AutoStory - Launch from HOME + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" // NintendoSwitch_CloseGameDetector.h needs it first. +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "NintendoSwitch/Inference/NintendoSwitch_CloseGameDetector.h" +#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" +#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" +#include "PokemonLZA_AutoStoryLaunch.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + +using namespace std::chrono_literals; + + +LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, const ScreenCheck& first_screen){ + if (!frame){ + return LaunchStart::OTHER; + } + if (first_screen && first_screen(frame)){ + return LaunchStart::FIRST_SCREEN; + } + return home_menu_shows ? LaunchStart::HOME_MENU : LaunchStart::OTHER; +} + + +namespace{ + +// Until `check` holds on a frame, or `timeout`. +bool wait_for_screen(ConsoleHandle& console, ProControllerContext& context, const ScreenCheck& check, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + while (true){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && check(frame)){ + return true; + } + if (current_time() >= deadline){ + return false; + } + context.wait_for(250ms); + } +} + +// On HOME with the tile selected: X, and if the close dialog shows the +// game was running, so A to close it and back to HOME. X on a game that is +// not running does nothing. +void close_selected_game_if_running(ConsoleHandle& console, ProControllerContext& context){ + console.log("launch: X on the selected tile (closes it if it is running)."); + pbf_press_button(context, BUTTON_X, 160ms, 0ms); + CloseGameDetector close_dialog(console); + HomeMenuDetector home(console, COLOR_RED); + const ScreenCheck dialog_shows = [&](const ImageViewRGB32& frame){ return close_dialog.detect(frame); }; + if (!wait_for_screen(console, context, dialog_shows, 3000ms)){ + if (!wait_for_screen(console, context, [&](const ImageViewRGB32& frame){ return home.detect_only(frame); }, 2000ms)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "launch: after X on the selected tile, neither the close dialog nor the HOME menu shows.", + console + ); + } + console.log("launch: no close dialog: the selected game is not running."); + return; + } + console.log("launch: the close dialog: the selected game was running; A to close it."); + pbf_press_button(context, BUTTON_A, 160ms, 0ms); + const ScreenCheck home_back = [&](const ImageViewRGB32& frame){ + return home.detect_only(frame) && !close_dialog.detect(frame); + }; + if (!wait_for_screen(console, context, home_back, 15s)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "launch: the HOME menu did not come back within 15 s of closing the selected game.", + console + ); + } + console.log("launch: the selected game is closed."); +} + +} // namespace + + +void launch_selected_game_from_home( + ConsoleHandle& console, ProControllerContext& context, + std::string_view game, std::string_view first_screen_name, + const ScreenCheck& first_screen, Milliseconds timeout, + std::string_view dump_folder +){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + HomeMenuDetector home(console, COLOR_RED); + const bool home_shows = frame && home.detect_only(frame); + switch (read_launch_start(frame, home_shows, first_screen)){ + case LaunchStart::HOME_MENU: + break; + case LaunchStart::FIRST_SCREEN: + throw UserSetupError(console, std::format( + "Start a new game on the HOME screen with {}'s tile selected. The {} is showing: go HOME first.", + game, first_screen_name + )); + case LaunchStart::OTHER: + throw UserSetupError(console, std::format("Start a new game on the HOME screen with {}'s tile selected.", game)); + } + console.log(std::format("launch: the HOME menu; launching the selected tile ({} expected), the cursor not moved.", game)); + close_selected_game_if_running(console, context); + console.log("launch: A on the selected tile, then the user select and the license check."); + start_game_from_home(console, context, true, 0, 0); + // The launch's logos: the first screen comes no sooner than this. + context.wait_for(5000ms); + if (!wait_for_screen(console, context, first_screen, timeout)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format( + "launch: the {} did not show within {} ms: the selected game may not be {}, or it has a save.", + first_screen_name, timeout.count(), game + ), + console + ); + } + console.log(std::format("launch: the {} shows.", first_screen_name)); + context.wait_for_all_requests(); + const VideoSnapshot shown = console.video().snapshot(); + if (shown){ + std::string label(first_screen_name); + std::replace(label.begin(), label.end(), ' ', '-'); + dump_debug_image(console, std::string(dump_folder), label, shown); + } +} + + +} // 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..93447eddd0 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h @@ -0,0 +1,72 @@ +/* PokemonLZA AutoStory - Launch from HOME + * + * From: https://github.com/PokemonAutomation/ + * + * A new game's first step: from the Switch HOME menu, launch the selected + * tile without moving HOME's cursor. Nothing here is PLZA's: the game's + * first screen comes in as a detector, so BDSP and FRLG can share it once + * it moves to the shared AutoStory core. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_H +#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_H + +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A detector for one screen. +using ScreenCheck = std::function; + + +// What the launch step does with the screen it starts on. +enum class LaunchStart{ + // The HOME menu: launch the selected tile. + HOME_MENU, + // The game's first screen already (a launch left there): refused, as + // any other screen. Told apart only for the message. + FIRST_SCREEN, + // Anything else, an empty frame included: refused. + OTHER, +}; + +// Where the launch step starts, from its first frame. `home_menu_shows` is +// the HOME menu detector's reading of `frame` (that detector needs the +// console); `first_screen` is the game's first screen's detector. +LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, const ScreenCheck& first_screen); + + +// From the HOME menu with `game`'s tile selected, a new game (no save): +// launches the selected tile, never moving HOME's cursor (no DOWN, UP or +// HOME presses: from HOME those go to the first tile, the game played +// last). If the selected game is running, X on its tile opens the close +// dialog, which A confirms; on a game that is not running X does nothing. +// Then A on the tile, the user select and the online license check +// (start_game_from_home() with slot 0, which does not move the cursor), +// 5 s, and up to `timeout` for `first_screen` (`first_screen_name` in the +// log), whose frame it saves to DebugDumps under `dump_folder`. +// Throws UserSetupError if HOME is not showing, OperationFailedException +// (with a screenshot) if the close dialog does not close or the first +// screen does not show: then the selected game may not be `game`, or it +// has a save. +void launch_selected_game_from_home( + ConsoleHandle& console, ProControllerContext& context, + std::string_view game, std::string_view first_screen_name, + const ScreenCheck& first_screen, Milliseconds timeout, + std::string_view dump_folder +); + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif 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 2330263d40..d6b5868e71 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -14,12 +15,12 @@ #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" -#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" -#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" -#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_KeyboardCodeEntry.h" +#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" +#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h" #include "PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryLanguageList.h" +#include "PokemonLZA_AutoStoryLaunch.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -164,10 +165,10 @@ void mash_scene( namespace{ -// The intro's screens are waited for by time until their detectors exist -// (PokemonLZA_AutoStoryIntro.h): until `is_screen` says the screen is up or -// `fixed_wait` passes. Either way the screen's frame is saved to -// DebugDumps, so a run records each one for the detectors' captures. +// An intro screen with no detector yet (is_look_picker() is a TODO stub): +// waited for until `is_screen` says it is up or `fixed_wait` passes, then +// pressed blind. Either way its frame is saved to DebugDumps, so a run +// records it for the detector's capture. void wait_for_intro_screen( ConsoleHandle& console, ProControllerContext& context, std::string_view screen, bool (*is_screen)(const ImageViewRGB32&), Milliseconds fixed_wait @@ -185,10 +186,23 @@ void wait_for_intro_screen( } context.wait_for_all_requests(); const VideoSnapshot frame = console.video().snapshot(); - console.log(std::format( - "AutoStory intro: {}: {} (waited up to {} ms).", - screen, seen ? "detected" : "not detected; the detector is not written, so the wait is fixed", fixed_wait.count() - )); + if (seen){ + console.log(std::format("AutoStory intro: {}: detected.", screen)); + }else{ + console.log(std::format( + "AutoStory intro: {}: NOT CHECKED, its detector is a TODO stub; waited a fixed {} ms, pressing blind.", + screen, fixed_wait.count() + )); + } + if (frame){ + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", std::string(screen), frame); + } +} + +// Saves the current frame to DebugDumps as intro screen `screen`. +void dump_intro_frame(ConsoleHandle& console, ProControllerContext& context, std::string_view screen){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); if (frame){ dump_debug_image(console, "PokemonLZA/AutoStory/Intro", std::string(screen), frame); } @@ -227,9 +241,13 @@ void press_intro_keys( context.wait_for_all_requests(); } -// After the launch: the license check, the logos, until the language list -// shows. Saves its first frame to DebugDumps. -void wait_for_language_list(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ +// Until the language list shows, or `timeout`. Saves its first frame to +// DebugDumps. Throws OperationFailedException with `failure` if it does +// not show. +void wait_for_language_list( + ConsoleHandle& console, ProControllerContext& context, + Milliseconds timeout, std::string_view failure +){ const WallClock deadline = current_time() + timeout; while (current_time() < deadline){ context.wait_for_all_requests(); @@ -243,7 +261,7 @@ void wait_for_language_list(ConsoleHandle& console, ProControllerContext& contex } OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, - std::format("AutoStory intro: the language list did not show within {} ms of the launch.", timeout.count()), + std::format("AutoStory intro: {} (waited {} ms)", failure, timeout.count()), console ); } @@ -279,44 +297,75 @@ void move_language_cursor(ConsoleHandle& console, ProControllerContext& context, ); } -// 01.00's start: the language list already on screen, or the Switch HOME -// screen with the game's tile highlighted (the game open or closed). From -// HOME: closes the game, so the launch is always fresh, starts it -// (start_game_from_home(): the user select and the online license check) -// and waits for the list: a new game has no title screen. Anything else -// on screen is a setup mistake. -void launch_to_language_list(ConsoleHandle& console, ProControllerContext& context){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame && is_language_list(frame)){ - console.log("AutoStory intro: start: the language list is on screen; no launch."); - return; +// Until the system keyboard shows (or, `gone`, has closed), or `timeout`. +// Throws OperationFailedException if it does not. +void wait_for_system_keyboard(ConsoleHandle& console, ProControllerContext& context, bool gone, Milliseconds timeout){ + SystemKeyboardDetector keyboard; + const WallClock deadline = current_time() + timeout; + while (current_time() < deadline){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && keyboard.detect(frame) != gone){ + console.log(std::format("AutoStory intro: keyboard: {}.", gone ? "closed" : "detected")); + return; + } + context.wait_for(250ms); } - HomeMenuDetector home(console, COLOR_RED); - if (!frame || !home.detect_only(frame)){ - throw UserSetupError(console, - "AutoStory 01.00: start on the Switch HOME screen with the game's tile highlighted and no save, " - "or on the game's language list. The screen is neither." - ); + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: the name keyboard {} within {} ms.", gone ? "did not close" : "did not show", timeout.count()), + console + ); +} + +// B deletes a character, and closes the keyboard on an empty field, so it +// deletes only while the field holds text (a name left from a retry). +void clear_system_keyboard_field(ConsoleHandle& console, ProControllerContext& context){ + for (size_t c = 0; c < 14; c++){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (!frame || !system_keyboard_field_has_text(frame)){ + return; + } + console.log("AutoStory intro: keyboard: the field holds text; B."); + pbf_press_button(context, BUTTON_B, 60ms, 250ms); } - console.log("AutoStory intro: start: the HOME screen; closing the game, then launching it."); - close_game_from_home(console, context); - start_game_from_home(console, context, true, 0, 0); - // The launch's logos: the user saw the list come no sooner than this. - context.wait_for(5000ms); - wait_for_language_list(console, context, 90s); +} + +// What type_on_system_keyboard() types for `plan`: it clicks Shift before +// each capital, so the keys in lower case, the first a capital when Shift +// goes first. +std::string system_keyboard_text(const NameKeys& plan){ + std::string text; + for (const char key : plan.keys){ + text += (char)std::tolower((unsigned char)key); + } + if (plan.shift_first && !text.empty()){ + text[0] = (char)std::toupper((unsigned char)text[0]); + } + return text; } } // namespace +void launch_game_from_home(ConsoleHandle& console, ProControllerContext& context){ + launch_selected_game_from_home( + console, context, "PLZA", "language list", + [](const ImageViewRGB32& frame){ return is_language_list(frame); }, + 90s, "PokemonLZA/AutoStory/Intro" + ); +} + void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language){ const std::optional target = language_list_index(language); if (!target){ throw UserSetupError(console, "AutoStory: the new game's language list has no such language."); } console.log(std::format("AutoStory intro: language {}: entry {} of the list.", language_data(language).code, *target)); - launch_to_language_list(console, context); + wait_for_language_list(console, context, 5s, + "the language list is not on screen: the launch_game_from_home step brings it up." + ); move_language_cursor(console, context, *target); press_intro_keys(console, context, {IntroKey::A}, 5000ms); } @@ -340,27 +389,27 @@ void type_player_name( if (!plan){ throw UserSetupError(console, std::format("AutoStory: the player name \"{}\" cannot be typed.", name)); } - wait_for_intro_screen(console, context, "keyboard", is_keyboard, 3000ms); + wait_for_system_keyboard(console, context, false, 20s); + dump_intro_frame(console, context, "keyboard"); + // Let the keyboard finish sliding in: inputs during that are dropped. + context.wait_for(800ms); + clear_system_keyboard_field(console, context); + const std::string typed = system_keyboard_text(*plan); console.log(std::format( - "AutoStory intro: typing \"{}\": keys {}, Shift first {}, keyboard capitalizes the first letter {}.", - name, plan->keys, plan->shift_first, first_letter_auto_caps + "AutoStory intro: typing \"{}\" as \"{}\" (keyboard capitalizes the first letter: {}).", + name, typed, first_letter_auto_caps )); - // Code entry takes upper case letters and digits only and presses - // their keys. The keyboard types lower case; Shift capitalizes the next - // letter only, so it goes right before the name. - if (plan->shift_first){ - pbf_press_button(context, BUTTON_LCLICK, 160ms, 400ms); - context.wait_for_all_requests(); - } - FastCodeEntry::keyboard_enter_code(console, context, true, KeyboardLayout::QWERTY, plan->keys, true); - context.wait_for(1000ms); - // PLUS is the keyboard's OK. "Confirm Choices" opens on "Change hair - // color"; "Ready!" is two rows down (console B, 2026-11-10). - pbf_press_button(context, BUTTON_PLUS, 160ms, 2500ms); - pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); - pbf_press_dpad(context, DPAD_DOWN, 160ms, 400ms); - pbf_press_button(context, BUTTON_A, 160ms, 2000ms); - context.wait_for_all_requests(); + FastCodeEntry::type_on_system_keyboard(console, context, typed); + console.log("AutoStory intro: PLUS (the keyboard's OK)."); + pbf_press_button(context, BUTTON_PLUS, 160ms, 0ms); + wait_for_system_keyboard(console, context, true, 5s); + // "Confirm Choices" opens on "Change hair color"; "Ready!" is two rows + // down (console B, 2026-11-10). + context.wait_for(2500ms); + dump_intro_frame(console, context, "confirm-choices"); + console.log("AutoStory intro: Confirm Choices: DOWN x2 to \"Ready!\", then A."); + press_intro_keys(console, context, {IntroKey::DOWN, IntroKey::DOWN, IntroKey::A}, 2000ms); + dump_intro_frame(console, context, "confirm"); } 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 f3180794b0..fc60d7f5d8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -53,31 +53,40 @@ bool tutorial_card_shows(const ImageViewRGB32& frame); // The new game's opening, as recorded 2026-11-08 on console B, with the // player's choices (PokemonLZA_AutoStoryIntro.h has each one's presses). // Each logs every press and saves its screen's frame (DebugDumps) for the -// detectors to be built from. Only the language list's is built: the look -// picker and the keyboard wait a fixed time for their screens. - -// 01.00's first step. It starts on the Switch HOME screen with the game's -// tile highlighted and no save, the game open or closed: closes the game -// so the launch is fresh, starts it (start_game_from_home(): the user -// select and the online license check), waits 5 s, then up to 90 s for -// the language list (a new game has no title screen). Started on the -// language list itself, it skips the launch. Then moves the list's -// highlight to `language`'s entry, reading it after each press, and -// presses A. Throws UserSetupError for a language the list lacks or any -// other starting screen, OperationFailedException if the list does not -// show or the highlight does not get there. +// detectors to be built from. The language list and the name keyboard (the +// Switch system keyboard) are detected; the look picker is not checked and +// waits a fixed time. + +// 01.00's first step. It starts on the Switch HOME menu with PLZA's tile +// selected and no save: launches that tile without moving the cursor, +// closing the game first if it is running, through the user select and +// the license check to the language list (launch_selected_game_from_home(), +// up to 90 s; a new game has no title screen). Throws UserSetupError on +// any other starting screen, OperationFailedException if the list does not +// show (the selected game may not be PLZA, or it has a save). +void launch_game_from_home(ConsoleHandle& console, ProControllerContext& context); + +// On the language list: moves its highlight to `language`'s entry, +// reading it after each press, and presses A. Throws UserSetupError for a +// language the list lacks, OperationFailedException if the list is not on +// screen or the highlight does not get there. void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language); // On the look picker, whose highlight starts at random: UP and LEFT x3 to // the top-left look (the edges clamp), RIGHT and DOWN to look `look` (1 to 8, -// a 2 x 4 grid, to be confirmed), A. +// a 2 x 4 grid), A. The screen is not checked (is_look_picker() is a TODO +// stub): the presses are blind. void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look); -// On the name screen: types `name` on the Switch keyboard (letters and -// digits, a capital only as the first letter; name_keys()), + to finish, -// then DOWN x2 and A on "Ready!". `first_letter_auto_caps`: the keyboard -// starts with a capital by itself, so Shift is for a lower case first -// letter instead (to be confirmed). +// On the name screen, the Switch system keyboard: waits up to 20 s for it, +// deletes any text left in its field, types `name` reading the cursor +// before each key (type_on_system_keyboard(); letters and digits, a +// capital only as the first letter; name_keys()), PLUS to finish and waits +// for the keyboard to close, then on "Confirm Choices" DOWN x2 and A on +// "Ready!". `first_letter_auto_caps`: the keyboard starts with a capital +// by itself, so Shift is for a lower case first letter instead (to be +// confirmed). Throws OperationFailedException if the keyboard does not +// show or close. void type_player_name( ConsoleHandle& console, ProControllerContext& context, const std::string& name, bool first_letter_auto_caps diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 47cf687e44..4511f47858 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -38,7 +38,7 @@ AutoStory_Descriptor::AutoStory_Descriptor() "PokemonLZA:AutoStory", std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", - "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. Checkpoint 01.00 (a new game) starts on the Switch HOME screen with the game's tile highlighted and no save: it closes the game if it is open and launches it fresh. It may also start on the game's language list.", + "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. Checkpoint 01.00 (a new game) starts on the Switch HOME screen with PLZA's tile selected and no save: it launches the selected tile without moving the cursor (closing it first if it is running) and waits for the language list. Go Home When Done leaves HOME with PLZA's tile selected, ready for the next new game.", PanelQualityStanding::DEVELOPER, ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 4002d87c36..4965f234bd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -68,6 +68,7 @@ using ConsoleStep = void (*)(StoryEnv& env); // The GAME actions that are one ConsoleStep each, by name: console_only. const std::map>& console_game_actions(){ static const std::map> actions{ + {"launch_game_from_home", [](StoryEnv& env){ launch_game_from_home(env.env.console, env.context); }}, {"new_game_language", [](StoryEnv& env){ new_game_language(env.env.console, env.context, env.language); }}, {"pick_look", [](StoryEnv& env){ pick_player_look(env.env.console, env.context, env.new_game.look); }}, {"type_player_name", [](StoryEnv& env){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 9c9f0276cc..b2b1d8e629 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -56,7 +56,8 @@ const std::map>& story_actions_not_impleme // "mash_to_move_hints" (args min_length_ms, quiet_ms) and // "text_to_choice" (run_scene_machine()); a console step, one // call through the game's own screens with no args: the new -// game's "new_game_language", "pick_look", "type_player_name"; +// game's "launch_game_from_home", "new_game_language", +// "pick_look", "type_player_name"; // "choose_0" / "choose_1" (that row of the choices on screen); // or an action of story_actions_not_implemented() // diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h index 9b03fe90bc..cf561f3584 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h @@ -43,8 +43,8 @@ const StoryData& builtin_story_data(); // The built-in story (load_story_data() with no dev files), read once: // what the tests, the lint and the program's dropdowns use: 01.00, a new -// game to the station platform, which starts on the title screen without -// a save. +// game to the station platform, which starts without a save on the HOME +// screen with PLZA's tile selected. const std::vector& story_checkpoints(); // The built-in rows that end on one of the game's autosaves. Each ends 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 bafb2dc650..07448dee3c 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 @@ -5,10 +5,16 @@ "id": "01.00", "title": "New game to the station platform", "events": [ + { + "id": "launch_from_home", + "kind": "game_action", + "why": "step 0: on the HOME screen with PLZA's tile selected: close it if it is running (X, A), launch the selected tile without moving the cursor, user select / license check, wait for the language list (no save: a new game opens on it)", + "action": "launch_game_from_home" + }, { "id": "language", "kind": "game_action", - "why": "step 1: from the HOME screen with the game highlighted, launch it (no save: it opens on the language list) and pick English", + "why": "step 1: on the language list, move the highlight to the run's language (English) and press A", "action": "new_game_language" }, { diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index da7014dc2d..1012ba8d5b 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2351,6 +2351,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.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_AutoStoryScenes.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp From 9196de3f1d560347455824d3dbc5002d61953111 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 07:13:03 -0800 Subject: [PATCH 11/33] PokemonLZA: AutoStory: launch presses HOME once when a game is in front Rerunning the new game no longer needs HOME first: if HOME is not showing, the launch step presses HOME once (the game in front stays the selected tile) and reads the screen again; it refuses only with no video or if HOME still does not show. The decision is next_launch_move(), unit tested with synthetic rows and console B's in-game/home captures. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 71 +++++++++++++++++-- .../Actions/PokemonLZA_AutoStoryLaunch.cpp | 67 ++++++++++++----- .../Actions/PokemonLZA_AutoStoryLaunch.h | 54 +++++++++----- .../AutoStory/StoryData/plza-01.00.plan.json | 2 +- 4 files changed, 156 insertions(+), 38 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index ecd18a151a..ef392f72bd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -173,9 +173,8 @@ UnitTestResult test_language_list_capture(Logger&){ return true; } -// 01.00's start on frames whose HOME reading is given: only HOME -// launches; the language list and anything else (an empty frame too) are -// refused. +// 01.00's start on frames whose HOME reading is given: HOME, the +// language list, anything else, and no video. UnitTestResult test_launch_start_synthetic(Logger&){ const ImageRGB32 list = language_list_frame(0); ImageRGB32 game(1920, 1080); @@ -192,8 +191,8 @@ UnitTestResult test_launch_start_synthetic(Logger&){ {"a game frame", &game, false, LaunchStart::OTHER}, {"the language list", &list, false, LaunchStart::FIRST_SCREEN}, {"the language list, HOME read", &list, true, LaunchStart::FIRST_SCREEN}, - {"an empty frame", &empty, false, LaunchStart::OTHER}, - {"an empty frame, HOME read", &empty, true, LaunchStart::OTHER}, + {"an empty frame", &empty, false, LaunchStart::NO_VIDEO}, + {"an empty frame, HOME read", &empty, true, LaunchStart::NO_VIDEO}, }; for (const Row& row : rows){ if (read_launch_start(*row.frame, row.home, is_language_list) != row.expected){ @@ -241,6 +240,60 @@ UnitTestResult test_launch_start_capture(Logger&){ return true; } +// 01.00's moves: HOME launches; a game in front (mid-scene or on its +// first screen) gets one HOME press, then is refused if HOME still does +// not show; no video is refused without a press. +UnitTestResult test_launch_moves(Logger&){ + struct Row{ + LaunchStart start; + bool home_pressed; + LaunchMove expected; + }; + const Row rows[] = { + {LaunchStart::HOME_MENU, false, LaunchMove::LAUNCH}, + {LaunchStart::HOME_MENU, true, LaunchMove::LAUNCH}, + {LaunchStart::OTHER, false, LaunchMove::PRESS_HOME}, + {LaunchStart::OTHER, true, LaunchMove::REFUSE}, + {LaunchStart::FIRST_SCREEN, false, LaunchMove::PRESS_HOME}, + {LaunchStart::FIRST_SCREEN, true, LaunchMove::REFUSE}, + {LaunchStart::NO_VIDEO, false, LaunchMove::REFUSE}, + {LaunchStart::NO_VIDEO, true, LaunchMove::REFUSE}, + }; + for (const Row& row : rows){ + if (next_launch_move(row.start, row.home_pressed) != row.expected){ + return std::format( + "start {}, HOME pressed {}: expected move {}.", + (int)row.start, row.home_pressed, (int)row.expected + ); + } + } + return true; +} + +// The HOME press on console B's frames, from the folder in +// PLZA_INTRO_SCREENS: in-game.png (a game in front) gets the press, and +// home.png, the screen it opens, launches. +UnitTestResult test_launch_moves_capture(Logger&){ + const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); + } + const std::string in_game = std::format("{}/in-game.png", folder); + const std::string home = std::format("{}/home.png", folder); + if (!Filesystem::exists(Filesystem::Path(in_game)) || !Filesystem::exists(Filesystem::Path(home))){ + return UnitTestResult(UnitTestResult::SKIPPED, "in-game.png or home.png is missing."); + } + const LaunchStart before = read_launch_start(ImageRGB32(in_game), false, is_language_list); + if (next_launch_move(before, false) != LaunchMove::PRESS_HOME){ + return "in-game.png: expected a HOME press."; + } + const LaunchStart after = read_launch_start(ImageRGB32(home), true, is_language_list); + if (next_launch_move(after, true) != LaunchMove::LAUNCH){ + return "home.png after the HOME press: expected a launch."; + } + return true; +} + UnitTestResult test_look_presses(Logger&){ // Look 1 is the top-left face: the clamp, then A. const Keys clamp = joined({{IntroKey::UP}, repeated(IntroKey::LEFT, 3)}); @@ -368,6 +421,14 @@ const IntroCase INTRO_CASES[] = { .input = {"Intro: the start screen on console B (PLZA_INTRO_SCREENS)", test_launch_start_capture}, .expectation = {}, }, + { + .input = {"Intro: the launch step's moves", test_launch_moves}, + .expectation = {}, + }, + { + .input = {"Intro: the HOME press on console B (PLZA_INTRO_SCREENS)", test_launch_moves_capture}, + .expectation = {}, + }, { .input = {"Intro: the look picker's presses", test_look_presses}, .expectation = {}, 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 60330528c7..110c95554c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp @@ -27,7 +27,7 @@ using namespace std::chrono_literals; LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, const ScreenCheck& first_screen){ if (!frame){ - return LaunchStart::OTHER; + return LaunchStart::NO_VIDEO; } if (first_screen && first_screen(frame)){ return LaunchStart::FIRST_SCREEN; @@ -35,6 +35,19 @@ LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, return home_menu_shows ? LaunchStart::HOME_MENU : LaunchStart::OTHER; } +LaunchMove next_launch_move(LaunchStart start, bool home_pressed){ + switch (start){ + case LaunchStart::HOME_MENU: + return LaunchMove::LAUNCH; + case LaunchStart::FIRST_SCREEN: + case LaunchStart::OTHER: + return home_pressed ? LaunchMove::REFUSE : LaunchMove::PRESS_HOME; + case LaunchStart::NO_VIDEO: + return LaunchMove::REFUSE; + } + return LaunchMove::REFUSE; +} + namespace{ @@ -89,6 +102,42 @@ void close_selected_game_if_running(ConsoleHandle& console, ProControllerContext console.log("launch: the selected game is closed."); } +// The screen now, read as the launch step's start. +LaunchStart read_screen(ConsoleHandle& console, ProControllerContext& context, const ScreenCheck& first_screen){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + HomeMenuDetector home(console, COLOR_RED); + const bool home_shows = frame && home.detect_only(frame); + return read_launch_start(frame, home_shows, first_screen); +} + +// Until the HOME menu shows, at most HOME once (see next_launch_move()). +// Throws UserSetupError if it does not. +void reach_home_menu(ConsoleHandle& console, ProControllerContext& context, std::string_view game, const ScreenCheck& first_screen){ + LaunchStart start = read_screen(console, context, first_screen); + bool home_pressed = false; + while (true){ + switch (next_launch_move(start, home_pressed)){ + case LaunchMove::LAUNCH: + return; + case LaunchMove::PRESS_HOME:{ + console.log(std::format("launch: not on HOME ({}); HOME once: the game in front stays the selected tile.", (int)start)); + pbf_press_button(context, BUTTON_HOME, 160ms, 0ms); + HomeMenuDetector home(console, COLOR_RED); + wait_for_screen(console, context, [&](const ImageViewRGB32& frame){ return home.detect_only(frame); }, 5000ms); + home_pressed = true; + start = read_screen(console, context, first_screen); + break; + } + case LaunchMove::REFUSE: + throw UserSetupError(console, std::format( + "Start a new game with {} in front, or on the HOME screen with {}'s tile selected. {}", + game, game, start == LaunchStart::NO_VIDEO ? "There is no video." : "HOME did not show after a HOME press." + )); + } + } +} + } // namespace @@ -98,21 +147,7 @@ void launch_selected_game_from_home( const ScreenCheck& first_screen, Milliseconds timeout, std::string_view dump_folder ){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - HomeMenuDetector home(console, COLOR_RED); - const bool home_shows = frame && home.detect_only(frame); - switch (read_launch_start(frame, home_shows, first_screen)){ - case LaunchStart::HOME_MENU: - break; - case LaunchStart::FIRST_SCREEN: - throw UserSetupError(console, std::format( - "Start a new game on the HOME screen with {}'s tile selected. The {} is showing: go HOME first.", - game, first_screen_name - )); - case LaunchStart::OTHER: - throw UserSetupError(console, std::format("Start a new game on the HOME screen with {}'s tile selected.", game)); - } + reach_home_menu(console, context, game, first_screen); console.log(std::format("launch: the HOME menu; launching the selected tile ({} expected), the cursor not moved.", game)); close_selected_game_if_running(console, context); console.log("launch: A on the selected tile, then the user select and the license check."); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h index 93447eddd0..12c8522af9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h @@ -2,10 +2,11 @@ * * From: https://github.com/PokemonAutomation/ * - * A new game's first step: from the Switch HOME menu, launch the selected - * tile without moving HOME's cursor. Nothing here is PLZA's: the game's - * first screen comes in as a detector, so BDSP and FRLG can share it once - * it moves to the shared AutoStory core. + * A new game's first step: from the Switch HOME menu, or with the game in + * front (HOME once), launch the selected tile without moving HOME's + * cursor. Nothing here is PLZA's: the game's first screen comes in as a + * detector, so BDSP and FRLG can share it once it moves to the shared + * AutoStory core. * */ @@ -28,33 +29,54 @@ namespace PokemonLZA{ using ScreenCheck = std::function; -// What the launch step does with the screen it starts on. +// The screen the launch step reads. enum class LaunchStart{ - // The HOME menu: launch the selected tile. + // The HOME menu. HOME_MENU, - // The game's first screen already (a launch left there): refused, as - // any other screen. Told apart only for the message. + // The game's first screen (a launch left there). Told apart from OTHER + // only for the log. FIRST_SCREEN, - // Anything else, an empty frame included: refused. + // Anything else: a game in front, mid-scene or not. OTHER, + // No frame: no video to check HOME against. + NO_VIDEO, }; -// Where the launch step starts, from its first frame. `home_menu_shows` is -// the HOME menu detector's reading of `frame` (that detector needs the +// Where the launch step starts, from a frame. `home_menu_shows` is the +// HOME menu detector's reading of `frame` (that detector needs the // console); `first_screen` is the game's first screen's detector. LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, const ScreenCheck& first_screen); +// What the launch step does next. +enum class LaunchMove{ + // Launch the selected tile. + LAUNCH, + // Press HOME once and read the screen again: with a game in front, HOME + // opens with that game's tile selected. + PRESS_HOME, + // Refuse: UserSetupError. + REFUSE, +}; + +// The launch step's move on `start`; `home_pressed` is whether it has +// pressed HOME already (it presses it once at most). +LaunchMove next_launch_move(LaunchStart start, bool home_pressed); + -// From the HOME menu with `game`'s tile selected, a new game (no save): -// launches the selected tile, never moving HOME's cursor (no DOWN, UP or -// HOME presses: from HOME those go to the first tile, the game played -// last). If the selected game is running, X on its tile opens the close +// From the HOME menu with `game`'s tile selected, or with `game` in front +// (on any screen, mid-scene too), a new game (no save): launches the +// selected tile, never moving HOME's cursor. If HOME is not showing, it +// presses HOME once: with a game in front, HOME opens with that game's +// tile selected. It presses no DOWN or UP, and HOME never on the HOME +// menu: from HOME that goes back to the game in front, and from there +// DOWN and UP select the first tile, the game played last. If the selected game is running, X on its tile opens the close // dialog, which A confirms; on a game that is not running X does nothing. // Then A on the tile, the user select and the online license check // (start_game_from_home() with slot 0, which does not move the cursor), // 5 s, and up to `timeout` for `first_screen` (`first_screen_name` in the // log), whose frame it saves to DebugDumps under `dump_folder`. -// Throws UserSetupError if HOME is not showing, OperationFailedException +// Throws UserSetupError if there is no video or HOME still does not show +// after the HOME press, OperationFailedException // (with a screenshot) if the close dialog does not close or the first // screen does not show: then the selected game may not be `game`, or it // has a save. 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 07448dee3c..601e02a2bb 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 @@ -8,7 +8,7 @@ { "id": "launch_from_home", "kind": "game_action", - "why": "step 0: on the HOME screen with PLZA's tile selected: close it if it is running (X, A), launch the selected tile without moving the cursor, user select / license check, wait for the language list (no save: a new game opens on it)", + "why": "step 0: with PLZA in front (any screen, mid-scene too) or on the HOME screen with its tile selected: HOME once if HOME is not showing (the game in front stays the selected tile), close it if it is running (X, A), launch the selected tile without moving the cursor, user select / license check, wait for the language list (no save: a new game opens on it)", "action": "launch_game_from_home" }, { From 7928e99ae37f112f7b310f70d4e3ac54ea038e6a Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 07:26:28 -0800 Subject: [PATCH 12/33] PokemonLZA: AutoStory: a run from 01.00 checks the black border on HOME The start frame's black border check refused 01.00 when the previous run stopped in a dark scene. A start checkpoint that launches the game skips the start check; the launch runs it once HOME shows. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryLaunch.cpp | 5 ++++ .../AutoStory/PokemonLZA_AutoStory.cpp | 11 ++++++++ .../Programs/AutoStory/PokemonLZA_AutoStory.h | 5 ++++ .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 8 ++++++ .../AutoStory/PokemonLZA_AutoStoryTable.h | 6 +++++ .../PokemonLZA_AutoStoryTable_Tests.cpp | 26 +++++++++++++++++++ 6 files changed, 61 insertions(+) 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 110c95554c..ddfe7bcae8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp @@ -11,6 +11,7 @@ #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "CommonTools/StartupChecks/StartProgramChecks.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" // NintendoSwitch_CloseGameDetector.h needs it first. #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "NintendoSwitch/Inference/NintendoSwitch_CloseGameDetector.h" @@ -148,6 +149,10 @@ void launch_selected_game_from_home( std::string_view dump_folder ){ reach_home_menu(console, context, game, first_screen); + // The program's start skipped this check (the game in front may have + // been dark): HOME fills the screen. + context.wait_for_all_requests(); + StartProgramChecks::check_border(console); console.log(std::format("launch: the HOME menu; launching the selected tile ({} expected), the cursor not moved.", game)); close_selected_game_if_running(console, context); console.log("launch: A on the selected tile, then the user select and the license check."); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 4511f47858..fa3a27d24b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -24,6 +24,7 @@ #include "Actions/PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" +#include "PokemonLZA_AutoStoryTable.h" #include "PokemonLZA_AutoStory.h" namespace PokemonAutomation{ @@ -153,6 +154,16 @@ NewGameChoices AutoStory::new_game_choices(ConsoleHandle& console, bool check) c return choices; } +void AutoStory::start_program_border_check(VideoStream& stream, FeedbackType feedback_type){ + const std::vector& rows = story_checkpoints(); + const size_t first = RUN.start_index(); + if (first < rows.size() && story_row_launches_game(rows[first])){ + stream.log(std::format("AutoStory: {} launches the game; the black border check waits for HOME.", rows[first].id)); + return; + } + SingleSwitchProgramInstance::start_program_border_check(stream, feedback_type); +} + void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ const StoryData story_data = load_run_story(env.console); const std::vector& rows = story_data.checkpoints; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index 7fdfdcaac7..e418fc4ede 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -50,6 +50,11 @@ class AutoStory : public SingleSwitchProgramInstance{ virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; + // The start frame's black border check, except for a start checkpoint + // that launches the game (story_row_launches_game()): the launch checks + // the border on HOME instead. + virtual void start_program_border_check(VideoStream& stream, FeedbackType feedback_type) override; + private: // The new game's choices; with `check`, throws UserSetupError for ones the // intro cannot play. diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index f3b56a684c..1a4adfd832 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -33,6 +33,14 @@ size_t story_rows_ready(const std::vector& checkpoints){ return ready; } +bool story_row_launches_game(const StoryCheckpoint& row){ + if (row.steps.empty()){ + return false; + } + const StoryStep& first = row.steps.front(); + return first.kind == StoryStepKind::GAME && first.action == "launch_game_from_home"; +} + } // 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 4b0ff85830..ec75d10012 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -54,6 +54,12 @@ bool story_row_saves(const StoryData& story, const Pokemon::StoryCheckpoint& row // story_actions_not_implemented(): the part of the story a run can play. size_t story_rows_ready(const std::vector& checkpoints); +// Whether `row` starts by launching the game from HOME (its first step is +// the GAME action "launch_game_from_home"): the game may be in front on any +// screen, a dark scene too, so the frame at the program's start says nothing +// about the screen size and the black border check waits for HOME. +bool story_row_launches_game(const Pokemon::StoryCheckpoint& row); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index 7dd89b2ed6..cc6ba9f1cc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -14,9 +14,12 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "CommonTools/VisualDetectors/BlackBorderDetector.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryScreenEvents.h" #include "PokemonLZA_AutoStoryStoryFiles.h" +#include "PokemonLZA_AutoStoryTable.h" #include "PokemonLZA_AutoStoryTable_Tests.h" namespace PokemonAutomation{ @@ -149,6 +152,25 @@ struct AutoStoryTableInput{ struct AutoStoryTableExpectation{ }; +// A black start frame (the previous run stopped in a dark scene) trips the +// black border check: a run from 01.00, which launches the game, leaves the +// check to HOME; a run from any later row still refuses on it. +UnitTestResult test_black_start_frame(Logger&){ + ImageRGB32 black(1920, 1080); + black.fill(0xff000000); + BlackBorderDetector border; + if (!border.detect(black)){ + return "Expected the black border check to refuse an all-black frame."; + } + for (const StoryCheckpoint& row : story_checkpoints()){ + const bool launches = story_row_launches_game(row); + if (launches != (row.id == "01.00")){ + return std::format("{}: launches the game: {}; only 01.00 should.", row.id, launches); + } + } + return true; +} + struct AutoStoryTableCase{ AutoStoryTableInput input; AutoStoryTableExpectation expectation; @@ -196,6 +218,10 @@ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { .input = {"Scene mash: what each frame presses", test_scene_mash_rule}, .expectation = {}, }, + { + .input = {"Start checks: a black start frame refuses every row but 01.00", test_black_start_frame}, + .expectation = {}, + }, }; void add_tests_AutoStory_StoryTable(UnitTestDatabase& database){ From 187aa095df980b9b57dc4cc47f0bc8353f3b4e16 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 07:49:09 -0800 Subject: [PATCH 13/33] PokemonLZA: AutoStory: read the look picker's highlight; A at the opening's arrival text The look step pressed blind on the APPEARANCE grid and mostly picked look 1 (console B, 2026-11-13). It now waits for the picker, reads the highlighted face, moves the left stick one press at a time towards the target and presses A only on it; no highlight read fails with a screenshot. The opening's platform wait presses A once per text box with the advance arrow ("Your train has arrived in Lumiose City!" waited 100 s for A). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryIntro.cpp | 31 ++-- .../Actions/PokemonLZA_AutoStoryIntro.h | 15 +- .../PokemonLZA_AutoStoryIntroScreens.cpp | 109 ++++++++++- .../PokemonLZA_AutoStoryIntroScreens.h | 19 +- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 169 +++++++++++++++--- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 135 ++++++++++---- .../Actions/PokemonLZA_AutoStoryScenes.h | 9 +- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 31 ++++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 23 ++- 9 files changed, 437 insertions(+), 104 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp index c00c954288..3134d480a0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp @@ -21,19 +21,26 @@ constexpr size_t LOOK_COLUMNS = 4; } // namespace -std::optional> look_picker_presses(size_t look){ - if (look < 1 || look > LOOK_COUNT){ +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; } - const size_t row = (look - 1) / LOOK_COLUMNS; - const size_t column = (look - 1) % LOOK_COLUMNS; - std::vector presses; - presses.push_back(IntroKey::UP); - presses.insert(presses.end(), LOOK_COLUMNS - 1, IntroKey::LEFT); - presses.insert(presses.end(), column, IntroKey::RIGHT); - presses.insert(presses.end(), row, IntroKey::DOWN); - presses.push_back(IntroKey::A); - return presses; + const size_t from_row = (from - 1) / LOOK_COLUMNS; + const size_t from_column = (from - 1) % LOOK_COLUMNS; + const size_t to_row = (to - 1) / LOOK_COLUMNS; + const size_t to_column = (to - 1) % LOOK_COLUMNS; + std::vector moves; + if (to_column > from_column){ + moves.insert(moves.end(), to_column - from_column, IntroKey::RIGHT); + }else{ + moves.insert(moves.end(), from_column - to_column, IntroKey::LEFT); + } + if (to_row > from_row){ + moves.insert(moves.end(), to_row - from_row, IntroKey::DOWN); + }else{ + moves.insert(moves.end(), from_row - to_row, IntroKey::UP); + } + return moves; } @@ -64,7 +71,7 @@ std::string new_game_problem(Language language, const NewGameChoices& choices){ if (!language_list_index(language)){ return "The new game's language list has no such language."; } - if (!look_picker_presses(choices.look)){ + if (choices.look < 1 || choices.look > LOOK_COUNT){ return std::format("The player look must be 1 to {}.", LOOK_COUNT); } if (!name_keys(choices.name, choices.name_first_letter_auto_caps)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h index e24bd107e1..7362fb4f82 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h @@ -38,16 +38,15 @@ enum class IntroKey{ }; -// The number of looks on the picker: a grid of 2 rows of 4 faces, as -// Scarlet/Violet's, numbered 1 to LOOK_COUNT left to right along the top -// row, then the bottom row. TODO: confirm the grid and the cursor's moves -// on a console. +// The number of looks on the picker: a grid of 2 rows of 4 faces, numbered +// 1 to LOOK_COUNT left to right along the top row, then the bottom row +// (console B, 2026-11-13). constexpr size_t LOOK_COUNT = 8; -// The highlight starts at random, so: UP and LEFT x3 to the top-left face -// (the edges clamp), then RIGHT and DOWN to look `look` (1 to LOOK_COUNT), -// then A. Nullopt for a look outside the grid. -std::optional> look_picker_presses(size_t look); +// The presses that move the picker's highlight from look `from` to look +// `to`: LEFT or RIGHT to the column, then UP or DOWN to the row. Empty when +// `from` is `to`; nullopt for a look outside 1 to LOOK_COUNT. +std::optional> look_picker_moves(size_t from, size_t to); // What to type for a player name on the keyboard. The keyboard types lower diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp index 5b5a7f485f..7f9c2a8c13 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -6,6 +6,7 @@ #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTools/ImageStats.h" +#include "PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryLanguageList.h" #include "PokemonLZA_AutoStoryIntroScreens.h" @@ -61,6 +62,101 @@ bool column_gap_dark(const ImageViewRGB32& frame){ return gap.count > 0 && gap.average.sum() / 3 < 70; } +enum class LookTile{ + HIGHLIGHTED, + PLAIN, + OTHER, +}; + +constexpr size_t LOOK_COLUMNS = 4; + +// 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; +} + +// A strip at the left end of look `look`'s tile, left of the face: 24 x 60 +// from 4 right of its edge and 20 down. +ImageFloatBox look_tile_strip(size_t look){ + return ImageFloatBox(look_tile_left(look) + 4.0 / 1920, look_tile_top(look) + 20.0 / 1080, 24.0 / 1920, 60.0 / 1080); +} + +// The dark strip above look `look`'s tile: 160 x 8 from 40 right of its +// edge and 14 above it. +ImageFloatBox look_above_strip(size_t look){ + return ImageFloatBox(look_tile_left(look) + 40.0 / 1920, look_tile_top(look) - 14.0 / 1080, 160.0 / 1920, 8.0 / 1080); +} + +// The dark gap right of look `look`'s tile (not the last column's): 40 x 180 +// from 12 right of the tile and 20 down. +ImageFloatBox look_gap_strip(size_t look){ + return ImageFloatBox(look_tile_left(look) + 252.0 / 1920, look_tile_top(look) + 20.0 / 1080, 40.0 / 1920, 180.0 / 1080); +} + +double brightness(const ImageStats& stats){ + return stats.average.sum() / 3; +} + +// Measured on console B (2026-11-13), the picker as it opens: the tiles' +// strips slate, (31-32, 44-47, 70-77), spread under 6; above them dark +// blue, (9-10, 16-32, 44-67), spread under 3. No frame with a highlight +// exists yet, so HIGHLIGHTED is any tile whose strip or the strip above it +// is much brighter than that: a light tile, or a light frame round it. +LookTile classify_look_tile(const ImageStats& tile, const ImageStats& above){ + if (tile.count == 0 || above.count == 0){ + return LookTile::OTHER; + } + if (brightness(tile) >= 90 || brightness(above) >= 90){ + return LookTile::HIGHLIGHTED; + } + const FloatPixel& average = tile.average; + const bool slate = + average.r >= 20 && average.r <= 45 && + average.g >= 35 && average.g <= 60 && + average.b >= 60 && average.b <= 95 && + average.b >= average.r + 25; + if (slate && tile.stddev.sum() <= 15 && brightness(above) < 50 && above.stddev.sum() <= 10){ + return LookTile::PLAIN; + } + return LookTile::OTHER; +} + +// Whether `frame` is the look picker; if so, `highlighted` is the +// highlighted look, if any. +bool read_look_picker(const ImageViewRGB32& frame, std::optional& highlighted){ + if (!frame || frame.width() < 160 || frame.height() < 90){ + return false; + } + highlighted.reset(); + for (size_t look = 1; look <= LOOK_COUNT; look++){ + if (look % LOOK_COLUMNS != 0){ + const ImageStats gap = image_stats(extract_box_reference(frame, look_gap_strip(look))); + if (gap.count == 0 || brightness(gap) >= 50 || gap.stddev.sum() > 30){ + return false; + } + } + const ImageStats tile = image_stats(extract_box_reference(frame, look_tile_strip(look))); + const ImageStats above = image_stats(extract_box_reference(frame, look_above_strip(look))); + switch (classify_look_tile(tile, above)){ + case LookTile::HIGHLIGHTED: + if (highlighted){ + return false; + } + highlighted = look; + break; + case LookTile::PLAIN: + break; + case LookTile::OTHER: + return false; + } + } + return true; +} + } // namespace @@ -94,8 +190,17 @@ bool is_language_list(const ImageViewRGB32& frame){ return read_language_list_cursor(frame).has_value(); } -bool is_look_picker(const ImageViewRGB32&){ - return false; +std::optional read_look_picker_cursor(const ImageViewRGB32& frame){ + std::optional highlighted; + if (!read_look_picker(frame, highlighted)){ + return std::nullopt; + } + return highlighted; +} + +bool is_look_picker(const ImageViewRGB32& frame){ + std::optional highlighted; + return read_look_picker(frame, highlighted); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h index 37adfd92f7..59d8352aeb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h @@ -2,12 +2,9 @@ * * From: https://github.com/PokemonAutomation/ * - * One detector per intro screen. The language list's is measured on - * console B (2026-11-13). The name screen is the Switch system keyboard - * (NintendoSwitch_SystemKeyboardDetector.h). TODO: the look picker's - * returns false until it is built from the frames a run saves - * (DebugDumps/PokemonLZA/AutoStory/Intro); its action's - * (PokemonLZA_AutoStoryScenes.h) wait is fixed until then. + * One detector per intro screen, measured on console B (2026-11-13). The + * name screen is the Switch system keyboard + * (NintendoSwitch_SystemKeyboardDetector.h). * */ @@ -31,8 +28,14 @@ std::optional read_language_list_cursor(const ImageViewRGB32& frame); // The language list, with one entry highlighted. bool is_language_list(const ImageViewRGB32& frame); -// The look picker's 2 x 4 grid of faces. TODO: always false until a -// capture of the screen exists. +// On the "APPEARANCE" look picker, the look (1 to LOOK_COUNT) whose face is +// highlighted: the one face whose tile or the strip above it is brighter +// than the others' slate tiles. Nullopt while no face is highlighted (the +// screen opens so), and for any other frame. +std::optional read_look_picker_cursor(const ImageViewRGB32& frame); + +// The look picker's 2 x 4 grid of slate face tiles on dark blue, with at +// most one face highlighted. bool is_look_picker(const ImageViewRGB32& frame); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index ef392f72bd..11d6ece300 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -294,34 +294,139 @@ UnitTestResult test_launch_moves_capture(Logger&){ return true; } -UnitTestResult test_look_presses(Logger&){ - // Look 1 is the top-left face: the clamp, then A. - const Keys clamp = joined({{IntroKey::UP}, repeated(IntroKey::LEFT, 3)}); - const auto first = look_picker_presses(1); - if (!first || *first != joined({clamp, {IntroKey::A}})){ - return "Look 1: expected UP, LEFT x3, A."; - } - // Look 3: two to the right on the top row. - const auto third = look_picker_presses(3); - if (!third || *third != joined({clamp, repeated(IntroKey::RIGHT, 2), {IntroKey::A}})){ - return "Look 3: expected the clamp, RIGHT x2, A."; - } - // Look 5: the bottom row's first face. - const auto fifth = look_picker_presses(5); - if (!fifth || *fifth != joined({clamp, {IntroKey::DOWN, IntroKey::A}})){ - return "Look 5: expected the clamp, DOWN, A."; - } - // Look 8: the bottom-right face. - const auto last = look_picker_presses(8); - if (!last || *last != joined({clamp, repeated(IntroKey::RIGHT, 3), {IntroKey::DOWN, IntroKey::A}})){ - return "Look 8: expected the clamp, RIGHT x3, DOWN, A."; - } - if (look_picker_presses(0) || look_picker_presses(9)){ +UnitTestResult test_look_moves(Logger&){ + struct Row{ + size_t from; + size_t to; + Keys expected; + }; + const Row rows[] = { + {1, 1, {}}, + // Along the top row. + {1, 4, repeated(IntroKey::RIGHT, 3)}, + {3, 2, {IntroKey::LEFT}}, + // Down a column. + {1, 5, {IntroKey::DOWN}}, + // Corner to corner: across, then down or up. + {1, 8, joined({repeated(IntroKey::RIGHT, 3), {IntroKey::DOWN}})}, + {8, 1, joined({repeated(IntroKey::LEFT, 3), {IntroKey::UP}})}, + {6, 3, joined({{IntroKey::RIGHT}, {IntroKey::UP}})}, + }; + for (const Row& row : rows){ + const auto moves = look_picker_moves(row.from, row.to); + if (!moves || *moves != row.expected){ + return std::format("Look {} to {}: expected {} presses.", row.from, row.to, row.expected.size()); + } + } + if (look_picker_moves(0, 1) || look_picker_moves(1, 0) || look_picker_moves(1, 9) || look_picker_moves(9, 1)){ return "Looks 0 and 9 are outside the grid."; } return true; } +// How a highlighted face is drawn in look_picker_frame(). +enum class LookHighlight{ + // A white frame round the tile. + FRAME, + // A light tile. + TILE, +}; + +// The look picker drawn as console B shows it (1920 x 1080): dark blue, +// 8 slate tiles 240 x 240, the columns' left edges at x 373, 685, 997 and +// 1309, the rows' tops at y 324 and 609; look `highlighted` (if any) drawn +// as `style`. +ImageRGB32 look_picker_frame(std::optional highlighted, LookHighlight style = LookHighlight::FRAME){ + const size_t lefts[] = {373, 685, 997, 1309}; + const size_t tops[] = {324, 609}; + ImageRGB32 image(1920, 1080); + image.fill(0xff0a1b3e); + for (size_t look = 1; look <= LOOK_COUNT; look++){ + const size_t left = lefts[(look - 1) % 4]; + const size_t top = tops[(look - 1) / 4]; + const bool lit = highlighted == look; + if (lit && style == LookHighlight::FRAME){ + for (size_t y = top - 10; y < top + 250; y++){ + for (size_t x = left - 10; x < left + 250; x++){ + image.pixel(x, y) = 0xffffffff; + } + } + } + const uint32_t tile = lit && style == LookHighlight::TILE ? 0xffc8d2dc : 0xff202f50; + for (size_t y = top; y < top + 240; y++){ + for (size_t x = left; x < left + 240; x++){ + image.pixel(x, y) = tile; + } + } + } + return image; +} + +UnitTestResult test_look_picker_synthetic(Logger&){ + const ImageRGB32 none = look_picker_frame(std::nullopt); + if (!is_look_picker(none) || read_look_picker_cursor(none)){ + return "Expected the picker with no highlight."; + } + for (const LookHighlight style : {LookHighlight::FRAME, LookHighlight::TILE}){ + for (size_t look = 1; look <= LOOK_COUNT; look++){ + const ImageRGB32 frame = look_picker_frame(look, style); + if (!is_look_picker(frame) || read_look_picker_cursor(frame) != look){ + return std::format("Expected the highlight read on look {} (style {}).", look, (int)style); + } + } + } + ImageRGB32 two = look_picker_frame(1, LookHighlight::TILE); + for (size_t y = 609; y < 849; y++){ + for (size_t x = 1309; x < 1549; x++){ + two.pixel(x, y) = 0xffc8d2dc; + } + } + if (is_look_picker(two) || read_look_picker_cursor(two)){ + return "Expected no picker with two highlights."; + } + if (is_look_picker(language_list_frame(0))){ + return "Expected the language list not to be the picker."; + } + for (const uint32_t fill : {0xff000000u, 0xffffffffu, 0xff202f50u, 0xff0a1b3eu}){ + ImageRGB32 flat(1920, 1080); + flat.fill(fill); + if (is_look_picker(flat)){ + return std::format("Expected a flat {:08x} frame not to be the picker.", fill); + } + } + if (is_look_picker(ImageRGB32()) || is_look_picker(ImageRGB32(1, 1)) || read_look_picker_cursor(ImageRGB32(40, 20))){ + return "Expected empty and tiny frames not to be the picker."; + } + return true; +} + +// The console's frames, from the folder in PLZA_INTRO_SCREENS: look-picker.png, +// the picker as it opens (no face highlighted yet), and the screens before +// and after it, which are not the picker. +UnitTestResult test_look_picker_capture(Logger&){ + const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); + } + const ImageRGB32 picker(std::format("{}/look-picker.png", folder)); + if (!is_look_picker(picker)){ + return "look-picker.png: expected the look picker."; + } + if (const std::optional cursor = read_look_picker_cursor(picker)){ + return std::format("look-picker.png: expected no highlight, read look {}.", *cursor); + } + for (const char* name : {"language-list.png", "keyboard.png", "confirm-choices.png"}){ + const std::string path = std::format("{}/{}", folder, name); + if (!Filesystem::exists(Filesystem::Path(path))){ + continue; + } + if (is_look_picker(ImageRGB32(path))){ + return std::format("{}: expected not the look picker.", name); + } + } + return true; +} + UnitTestResult test_name_keys(Logger&){ // Kosmos: a capital K by Shift, the rest as plain keys. const auto kosmos = name_keys("Kosmos", false); @@ -367,9 +472,11 @@ UnitTestResult test_new_game_problem(Logger&){ if (new_game_problem(Language::None, choices).empty()){ return "No language is a problem."; } - choices.look = 9; - if (new_game_problem(Language::English, choices).empty()){ - return "Look 9 is a problem."; + for (const size_t look : {size_t(0), size_t(9)}){ + choices.look = look; + if (new_game_problem(Language::English, choices).empty()){ + return std::format("Look {} is a problem.", look); + } } choices.look = 1; choices.name = "KOsmos"; @@ -430,7 +537,15 @@ const IntroCase INTRO_CASES[] = { .expectation = {}, }, { - .input = {"Intro: the look picker's presses", test_look_presses}, + .input = {"Intro: the look picker's moves", test_look_moves}, + .expectation = {}, + }, + { + .input = {"Intro: the look picker's highlight, synthetic frames", test_look_picker_synthetic}, + .expectation = {}, + }, + { + .input = {"Intro: the look picker on console B (PLZA_INTRO_SCREENS)", test_look_picker_capture}, .expectation = {}, }, { 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 d6b5868e71..d6b4be21f1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -165,40 +165,6 @@ void mash_scene( namespace{ -// An intro screen with no detector yet (is_look_picker() is a TODO stub): -// waited for until `is_screen` says it is up or `fixed_wait` passes, then -// pressed blind. Either way its frame is saved to DebugDumps, so a run -// records it for the detector's capture. -void wait_for_intro_screen( - ConsoleHandle& console, ProControllerContext& context, - std::string_view screen, bool (*is_screen)(const ImageViewRGB32&), Milliseconds fixed_wait -){ - const WallClock deadline = current_time() + fixed_wait; - bool seen = false; - while (current_time() < deadline){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame && is_screen(frame)){ - seen = true; - break; - } - context.wait_for(250ms); - } - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (seen){ - console.log(std::format("AutoStory intro: {}: detected.", screen)); - }else{ - console.log(std::format( - "AutoStory intro: {}: NOT CHECKED, its detector is a TODO stub; waited a fixed {} ms, pressing blind.", - screen, fixed_wait.count() - )); - } - if (frame){ - dump_debug_image(console, "PokemonLZA/AutoStory/Intro", std::string(screen), frame); - } -} - // Saves the current frame to DebugDumps as intro screen `screen`. void dump_intro_frame(ConsoleHandle& console, ProControllerContext& context, std::string_view screen){ context.wait_for_all_requests(); @@ -346,6 +312,97 @@ std::string system_keyboard_text(const NameKeys& plan){ return text; } +// One look picker press: a short tilt of the left stick (the screen says +// "Use the Left Stick"), then a pause for the highlight to move. +void press_look_picker_key(ConsoleHandle& console, ProControllerContext& context, IntroKey key){ + switch (key){ + case IntroKey::UP: + console.log("AutoStory intro: look-picker: stick UP."); + pbf_move_left_joystick(context, {0, +1}, 200ms, 500ms); + break; + case IntroKey::DOWN: + console.log("AutoStory intro: look-picker: stick DOWN."); + pbf_move_left_joystick(context, {0, -1}, 200ms, 500ms); + break; + case IntroKey::LEFT: + console.log("AutoStory intro: look-picker: stick LEFT."); + pbf_move_left_joystick(context, {-1, 0}, 200ms, 500ms); + break; + case IntroKey::RIGHT: + console.log("AutoStory intro: look-picker: stick RIGHT."); + pbf_move_left_joystick(context, {+1, 0}, 200ms, 500ms); + break; + case IntroKey::A: + console.log("AutoStory intro: look-picker: A."); + pbf_press_button(context, BUTTON_A, 160ms, 500ms); + break; + } + context.wait_for_all_requests(); +} + +// Until the look picker shows, or `timeout`. Saves its first frame to +// DebugDumps. Throws OperationFailedException if it does not show. +void wait_for_look_picker(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ + const WallClock deadline = current_time() + timeout; + while (current_time() < deadline){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + if (frame && is_look_picker(frame)){ + console.log("AutoStory intro: look-picker: detected."); + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "look-picker", frame); + return; + } + context.wait_for(250ms); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: the look picker did not show within {} ms.", timeout.count()), + console + ); +} + +// On the look picker: one press at a time towards look `target`, reading +// the highlight after each, until it is on `target`. The picker opens with +// no face highlighted, so while none is, UP (harmless on any face of the +// top row) to bring the highlight up. Each frame read with no highlight is +// saved to DebugDumps. Throws OperationFailedException if the highlight is +// not read or does not reach `target`. +void move_look_cursor(ConsoleHandle& console, ProControllerContext& context, size_t target){ + size_t unread = 0; + for (size_t attempt = 0; attempt < 24; attempt++){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + const std::optional cursor = frame ? read_look_picker_cursor(frame) : std::nullopt; + if (!cursor){ + unread++; + if (frame){ + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "look-picker-unread", frame); + } + if (unread > 6){ + break; + } + console.log("AutoStory intro: look-picker: no highlight read."); + press_look_picker_key(console, context, IntroKey::UP); + continue; + } + unread = 0; + if (*cursor == target){ + return; + } + const std::optional> moves = look_picker_moves(*cursor, target); + if (!moves || moves->empty()){ + break; + } + console.log(std::format("AutoStory intro: look-picker: the highlight is on look {}.", *cursor)); + press_look_picker_key(console, context, moves->front()); + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format("AutoStory intro: the look picker's highlight was not read on look {}.", target), + console + ); +} + } // namespace @@ -371,14 +428,14 @@ void new_game_language(ConsoleHandle& console, ProControllerContext& context, La } void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ - const std::optional> presses = look_picker_presses(look); - if (!presses){ + if (look < 1 || look > LOOK_COUNT){ throw UserSetupError(console, std::format("AutoStory: the player look must be 1 to {}.", LOOK_COUNT)); } console.log(std::format("AutoStory intro: look {} of {}.", look, LOOK_COUNT)); - // The language's A already waited 5 s for this screen. - wait_for_intro_screen(console, context, "look-picker", is_look_picker, 0ms); - press_intro_keys(console, context, *presses, 3000ms); + wait_for_look_picker(console, context, 10s); + move_look_cursor(console, context, look); + console.log(std::format("AutoStory intro: look-picker: the highlight is on look {}; A.", look)); + press_intro_keys(console, context, {IntroKey::A}, 3000ms); } void type_player_name( 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 fc60d7f5d8..94b359f7d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -72,10 +72,11 @@ void launch_game_from_home(ConsoleHandle& console, ProControllerContext& context // screen or the highlight does not get there. void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language); -// On the look picker, whose highlight starts at random: UP and LEFT x3 to -// the top-left look (the edges clamp), RIGHT and DOWN to look `look` (1 to 8, -// a 2 x 4 grid), A. The screen is not checked (is_look_picker() is a TODO -// stub): the presses are blind. +// On the look picker: waits up to 10 s for it, moves its highlight to look +// `look` (1 to 8, a 2 x 4 grid) one left-stick press at a time, reading it +// after each, and presses A only on `look`. Throws UserSetupError for a +// look outside 1 to 8, OperationFailedException if the picker does not +// show or its highlight is not read on `look`. void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look); // On the name screen, the Switch system keyboard: waits up to 20 s for it, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index f30ea11ac4..f8b7a13a2c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -138,6 +138,36 @@ UnitTestResult test_opening_waits_for_platform(CancellableScope& scope){ return expect_inputs(backend, std::vector(6, "wait 300ms")); } +// The opening ends on "Your train has arrived in Lumiose City!", a text box +// with the advance arrow that waits for A (console B, 2026-11-13: the run +// waited 100 s on it and failed platform_not_seen; one A by hand went on to +// the platform). One A per text, none while it is still up, then the platform. +UnitTestResult test_opening_presses_through_arrival_text(CancellableScope& scope){ + const auto arrival = [](Milliseconds at){ + return with_reading(look_at(at, {EngineEvent::TEXT_BOX}), ADVANCE_ARROW_READING); + }; + FakeBackend backend = fake_plza({ + look_at(0ms, {EngineEvent::FADE_BLACK}), + with_reading(look_at(300ms), AUTOSAVE_READING), + arrival(600ms), + arrival(900ms), + with_reading(look_at(1200ms), PLATFORM_READING), + with_reading(look_at(1500ms), PLATFORM_READING), + }, scope); + const Pokemon::StoryEngineReport report = run_plza(backend, step_of("01.00", "opening")); + if (report.verdict != Pokemon::CheckpointVerdict::PASSED){ + return std::format("Expected the opening to end at the platform: {}", to_string(report.run.failure)); + } + std::vector presses; + std::copy_if(backend.inputs().begin(), backend.inputs().end(), std::back_inserter(presses), [](const std::string& input){ + return input.starts_with("press"); + }); + if (presses != std::vector{"press A"}){ + return std::format("Expected one A at the arrival text, got [{}].", joined(backend.inputs())); + } + return true; +} + // A look at `at` facing `heading`, as the minimap reads it. Observation facing(Milliseconds at, int heading){ Observation look = look_at(at); @@ -285,6 +315,7 @@ class Test_AutoStoryEngine : public UnitTest{ const EngineTestCase ENGINE_TEST_CASES[] = { {.input = {"01.00 opening: no presses, done on two looks at the platform after the autosave", test_opening_waits_for_platform}, .expectation = {}}, + {.input = {"01.00 opening: one A at the arrival text with the advance arrow", test_opening_presses_through_arrival_text}, .expectation = {}}, {.input = {"face_heading: turns by the minimap's heading", test_face_heading}, .expectation = {}}, {.input = {"refused: console actions off a console, tile walks, unknown actions", test_refused_steps}, .expectation = {}}, {.input = {"every checkpoint runs in step order, testing never saves", test_every_checkpoint_runs}, .expectation = {}}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 4965f234bd..41006891ee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -252,6 +252,8 @@ struct PlatformProgress{ bool autosave_seen = false; bool skip_prompt = false; size_t streak = 0; + // The text with the advance arrow was on the last look. + bool text_waiting = false; }; // Takes `look` into `progress`; logs the skip prompt and the autosave @@ -275,10 +277,17 @@ bool platform_look(Pokemon::StoryBackend& backend, const ScreenObserva return progress.streak >= PLATFORM_LOOKS; } -// The station platform after the opening cutscene, with no input (A does -// not advance the cutscene): PLATFORM_READING on PLATFORM_LOOKS looks in a -// row; AFTER_AUTOSAVE counts them only once the autosave badge has shown -// and gone. Fails after `timeout`. +// A text box with the advance arrow: the opening's last line ("Your train +// has arrived in Lumiose City!") waits for A (console B, 2026-11-13). +bool text_waiting_for_a(const ScreenObservation& look){ + return look.events.has(PokemonAutomation::ScreenEvent::TEXT_BOX) && look.readings.contains(ADVANCE_ARROW_READING); +} + +// The station platform after the opening cutscene: PLATFORM_READING on +// PLATFORM_LOOKS looks in a row; AFTER_AUTOSAVE counts them only once the +// autosave badge has shown and gone. No input through the cutscene (A does +// not advance it), but one A for each text box with the advance arrow, when +// it shows (not again while the same one is up). Fails after `timeout`. Outcome wait_for_platform(Pokemon::StoryBackend& backend, Milliseconds timeout, PlatformWait wait){ // The looks bound a script whose time stands still. const size_t max_looks = (size_t)(timeout / PLATFORM_POLL) + 1; @@ -295,6 +304,12 @@ Outcome wait_for_platform(Pokemon::StoryBackend& backend, Milliseconds if (look.when - *start >= timeout){ break; } + const bool text_now = text_waiting_for_a(look); + if (text_now && !progress.text_waiting){ + backend.log("[PLZA] platform wait: text waiting for A; A"); + backend.press(BUTTON_A, 160ms, 400ms); + } + progress.text_waiting = text_now; backend.wait(PLATFORM_POLL); } return Pokemon::outcome_failed("platform_not_seen", std::format( From 3f7b01da4206630fd5e79f4cb45e9e98019fb4e9 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 08:44:52 -0800 Subject: [PATCH 14/33] PokemonLZA AutoStory: the new game from HOME is 00.00; 01.00 starts on Confirm Choices The checkpoint that launches from HOME and plays language, look, name and the opening is renumbered 00.00, unchanged. The new 01.00 starts on the new game's Confirm Choices screen after the choices were made by hand: it reads that screen with no press (UserSetupError and no press anywhere else, the controller's connect press included), moves the highlight to Ready! reading it after each DOWN, presses A, and plays the opening to the platform. A run from 00.00 skips 01.00, and neither loads a save. Also fixes the char* loop in the intro tests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryIntroScreens.cpp | 98 ++++++++++++++ .../PokemonLZA_AutoStoryIntroScreens.h | 20 +++ .../PokemonLZA_AutoStoryIntro_Tests.cpp | 128 +++++++++++++++++- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 60 +++++++- .../Actions/PokemonLZA_AutoStoryScenes.h | 15 +- .../AutoStory/PokemonLZA_AutoStory.cpp | 27 ++-- .../Programs/AutoStory/PokemonLZA_AutoStory.h | 2 +- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 4 +- .../PokemonLZA_AutoStoryEngine_Tests.h | 2 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 1 + .../AutoStory/PokemonLZA_AutoStoryGame.h | 5 +- .../PokemonLZA_AutoStoryStoryFiles.h | 7 +- .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 36 ++++- .../AutoStory/PokemonLZA_AutoStoryTable.h | 19 ++- .../PokemonLZA_AutoStoryTable_Tests.cpp | 61 +++++++-- .../AutoStory/StoryData/plza-00.00.plan.json | 50 +++++++ .../AutoStory/StoryData/plza-01.00.plan.json | 30 +--- 17 files changed, 506 insertions(+), 59 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp index 7f9c2a8c13..329fa55f94 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -157,9 +157,72 @@ bool read_look_picker(const ImageViewRGB32& frame, std::optional& highli return true; } +// The right ends of the "Confirm Choices" rows, right of their text: the +// boxes span x 144 to 742 at 1920 x 1080, the two choices from y 578 and +// 662 (68 high), "Ready!" from y 790 (112 high). Each strip is 100 wide +// from x 620. +ImageFloatBox confirm_row_strip(size_t row){ + switch (row){ + case 0: + return ImageFloatBox(620.0 / 1920, 592.0 / 1080, 100.0 / 1920, 40.0 / 1080); + case 1: + return ImageFloatBox(620.0 / 1920, 676.0 / 1080, 100.0 / 1920, 40.0 / 1080); + default: + return ImageFloatBox(620.0 / 1920, 820.0 / 1080, 100.0 / 1920, 60.0 / 1080); + } +} + +// A "Confirm Choices" row's strip: the highlighted row white, flat, as the +// language list's; the others a darker slate than its boxes. +ListBox classify_confirm_row(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 >= 20 && average.r <= 55 && + average.g >= 40 && average.g <= 80 && + average.b >= 65 && average.b <= 115 && + average.b >= average.r + 25; + if (slate && spread <= 20){ + return ListBox::PLAIN; + } + return ListBox::OTHER; +} + +// The dark blue, dotted background round the rows: between the choices and +// "Ready!", and right of all three. +bool confirm_background_dark(const ImageViewRGB32& frame){ + const ImageFloatBox boxes[] = { + ImageFloatBox(620.0 / 1920, 742.0 / 1080, 100.0 / 1920, 40.0 / 1080), + ImageFloatBox(770.0 / 1920, 580.0 / 1080, 30.0 / 1920, 320.0 / 1080), + }; + for (const ImageFloatBox& box : boxes){ + const ImageStats stats = image_stats(extract_box_reference(frame, box)); + if (stats.count == 0 || brightness(stats) >= 50 || stats.stddev.sum() > 35){ + return false; + } + } + return true; +} + } // namespace +std::optional> confirm_choices_moves(size_t cursor){ + if (cursor > CONFIRM_CHOICES_READY_ROW){ + return std::nullopt; + } + std::vector moves(CONFIRM_CHOICES_READY_ROW - cursor, IntroKey::DOWN); + moves.push_back(IntroKey::A); + return moves; +} + + std::optional read_language_list_cursor(const ImageViewRGB32& frame){ if (!frame || frame.width() < 160 || frame.height() < 90){ return std::nullopt; @@ -203,6 +266,41 @@ bool is_look_picker(const ImageViewRGB32& frame){ return read_look_picker(frame, highlighted); } +// Measured on console B (2026-11-13), "Confirm Choices" as it opens: the +// highlighted row 255 white, flat; the others slate, (35-36, 52-61, +// 82-95), spread under 10; the background (10, 29-31, 64-66), spread under +// 25. The language list's boxes and the look picker's tiles fall on the +// background's strips, so neither reads as this screen. +std::optional read_confirm_choices_cursor(const ImageViewRGB32& frame){ + if (!frame || frame.width() < 160 || frame.height() < 90){ + return std::nullopt; + } + if (!confirm_background_dark(frame)){ + return std::nullopt; + } + std::optional highlighted; + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + const ImageStats stats = image_stats(extract_box_reference(frame, confirm_row_strip(row))); + switch (classify_confirm_row(stats)){ + case ListBox::HIGHLIGHTED: + if (highlighted){ + return std::nullopt; + } + highlighted = row; + break; + case ListBox::PLAIN: + break; + case ListBox::OTHER: + return std::nullopt; + } + } + return highlighted; +} + +bool is_confirm_choices(const ImageViewRGB32& frame){ + return read_confirm_choices_cursor(frame).has_value(); +} + } // namespace PokemonLZA } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h index 59d8352aeb..74929cb2ec 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h @@ -12,7 +12,9 @@ #define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H #include +#include #include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "PokemonLZA_AutoStoryIntro.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -38,6 +40,24 @@ std::optional read_look_picker_cursor(const ImageViewRGB32& frame); // most one face highlighted. bool is_look_picker(const ImageViewRGB32& frame); +// "Confirm Choices", the screen after the name keyboard, has three rows: +// "Change hair color" (0, highlighted as it opens), "Change look" and +// "Ready!", the last. +constexpr size_t CONFIRM_CHOICES_READY_ROW = 2; + +// The presses on "Confirm Choices" from the highlighted row `cursor` to +// "Ready!": DOWN to it, then A. Nullopt for a row past "Ready!". +std::optional> confirm_choices_moves(size_t cursor); + +// On "Confirm Choices", the PROFILE screen after the name keyboard (its +// rows "Change hair color", "Change look" and "Ready!"), the highlighted +// row, 0 to CONFIRM_CHOICES_READY_ROW: the one white box of the three, the +// others slate. Nullopt for any other frame, an empty one included. +std::optional read_confirm_choices_cursor(const ImageViewRGB32& frame); + +// "Confirm Choices", with one row highlighted. +bool is_confirm_choices(const ImageViewRGB32& frame); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index 11d6ece300..92f468bb06 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -173,7 +173,7 @@ UnitTestResult test_language_list_capture(Logger&){ return true; } -// 01.00's start on frames whose HOME reading is given: HOME, the +// 00.00's start on frames whose HOME reading is given: HOME, the // language list, anything else, and no video. UnitTestResult test_launch_start_synthetic(Logger&){ const ImageRGB32 list = language_list_frame(0); @@ -205,7 +205,7 @@ UnitTestResult test_launch_start_synthetic(Logger&){ return true; } -// 01.00's start on console B's frames, from the folder in +// 00.00's start on console B's frames, from the folder in // PLZA_INTRO_SCREENS: language-list.png, and if present home.png (the HOME // menu) and in-game.png (the station). The HOME reading is // HomeMenuDetector's, which needs a console: here it is given. @@ -240,7 +240,7 @@ UnitTestResult test_launch_start_capture(Logger&){ return true; } -// 01.00's moves: HOME launches; a game in front (mid-scene or on its +// 00.00's moves: HOME launches; a game in front (mid-scene or on its // first screen) gets one HOME press, then is refused if HOME still does // not show; no video is refused without a press. UnitTestResult test_launch_moves(Logger&){ @@ -415,7 +415,7 @@ UnitTestResult test_look_picker_capture(Logger&){ if (const std::optional cursor = read_look_picker_cursor(picker)){ return std::format("look-picker.png: expected no highlight, read look {}.", *cursor); } - for (const char* name : {"language-list.png", "keyboard.png", "confirm-choices.png"}){ + for (const std::string_view name : {"language-list.png", "keyboard.png", "confirm-choices.png"}){ const std::string path = std::format("{}/{}", folder, name); if (!Filesystem::exists(Filesystem::Path(path))){ continue; @@ -427,6 +427,114 @@ UnitTestResult test_look_picker_capture(Logger&){ return true; } +// "Confirm Choices" drawn as console B shows it (1920 x 1080): dark blue, +// three slate rows x 144 to 742, the two choices from y 578 and 662 (68 +// high) and "Ready!" from y 790 (112 high), row `highlighted` (if any) +// white. +ImageRGB32 confirm_choices_frame(std::optional highlighted){ + ImageRGB32 image(1920, 1080); + image.fill(0xff0a1d40); + const size_t tops[] = {578, 662, 790}; + const size_t heights[] = {68, 68, 112}; + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + const uint32_t color = highlighted == row ? 0xffffffff : 0xff23344f; + for (size_t y = tops[row]; y < tops[row] + heights[row]; y++){ + for (size_t x = 144; x < 742; x++){ + image.pixel(x, y) = color; + } + } + } + return image; +} + +// From each row of "Confirm Choices": DOWN to "Ready!", then A. +UnitTestResult test_confirm_choices_moves(Logger&){ + struct Row{ + size_t cursor; + Keys expected; + }; + const Row rows[] = { + {0, {IntroKey::DOWN, IntroKey::DOWN, IntroKey::A}}, + {1, {IntroKey::DOWN, IntroKey::A}}, + {2, {IntroKey::A}}, + }; + for (const Row& row : rows){ + const auto moves = confirm_choices_moves(row.cursor); + if (!moves || *moves != row.expected){ + return std::format("Row {}: expected {} presses.", row.cursor, row.expected.size()); + } + } + if (confirm_choices_moves(CONFIRM_CHOICES_READY_ROW + 1)){ + return "A row past \"Ready!\" has no moves."; + } + return true; +} + +// 01.00's start check (require_confirm_choices()) on synthetic frames: it +// reads the highlight on each row of "Confirm Choices", and refuses the +// other intro screens, flat and empty frames, and a screen with no row or +// two rows highlighted. +UnitTestResult test_confirm_choices_synthetic(Logger&){ + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + if (read_confirm_choices_cursor(confirm_choices_frame(row)) != row){ + return std::format("Expected the highlight read on row {}.", row); + } + } + if (is_confirm_choices(confirm_choices_frame(std::nullopt))){ + return "Expected no Confirm Choices without a highlight."; + } + ImageRGB32 two = confirm_choices_frame(0); + for (size_t y = 662; y < 730; y++){ + for (size_t x = 144; x < 742; x++){ + two.pixel(x, y) = 0xffffffff; + } + } + if (is_confirm_choices(two)){ + return "Expected no Confirm Choices with two highlights."; + } + for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ + if (is_confirm_choices(language_list_frame(index))){ + return std::format("Expected the language list (entry {} highlighted) not to be Confirm Choices.", index); + } + } + for (const uint32_t fill : {0xff000000u, 0xffffffffu, 0xff0a1d40u, 0xff23344fu}){ + ImageRGB32 flat(1920, 1080); + flat.fill(fill); + if (is_confirm_choices(flat)){ + return std::format("Expected a flat {:08x} frame not to be Confirm Choices.", fill); + } + } + if (is_confirm_choices(ImageRGB32()) || is_confirm_choices(ImageRGB32(1, 1)) || is_confirm_choices(ImageRGB32(40, 20))){ + return "Expected empty and tiny frames not to be Confirm Choices."; + } + return true; +} + +// 01.00's start check on console B's frames, from the folder in +// PLZA_INTRO_SCREENS: it accepts confirm-choices.png, "Change hair +// color" highlighted as the screen opens, and refuses every other intro +// screen there. +UnitTestResult test_confirm_choices_capture(Logger&){ + const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); + } + const std::optional cursor = read_confirm_choices_cursor(ImageRGB32(std::format("{}/confirm-choices.png", folder))); + if (cursor != size_t(0)){ + return "confirm-choices.png: expected Confirm Choices with row 0 highlighted."; + } + for (const std::string_view name : {"home.png", "in-game.png", "language-list.png", "look-picker.png", "keyboard.png"}){ + const std::string path = std::format("{}/{}", folder, name); + if (!Filesystem::exists(Filesystem::Path(path))){ + continue; + } + if (is_confirm_choices(ImageRGB32(path))){ + return std::format("{}: expected 01.00 to refuse it.", name); + } + } + return true; +} + UnitTestResult test_name_keys(Logger&){ // Kosmos: a capital K by Shift, the rest as plain keys. const auto kosmos = name_keys("Kosmos", false); @@ -548,6 +656,18 @@ const IntroCase INTRO_CASES[] = { .input = {"Intro: the look picker on console B (PLZA_INTRO_SCREENS)", test_look_picker_capture}, .expectation = {}, }, + { + .input = {"Intro: Confirm Choices' moves to Ready!", test_confirm_choices_moves}, + .expectation = {}, + }, + { + .input = {"Intro: 01.00's start check on Confirm Choices, synthetic frames", test_confirm_choices_synthetic}, + .expectation = {}, + }, + { + .input = {"Intro: 01.00's start check on console B (PLZA_INTRO_SCREENS)", test_confirm_choices_capture}, + .expectation = {}, + }, { .input = {"Intro: the name's keys and Shift", test_name_keys}, .expectation = {}, 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 d6b4be21f1..46e1666808 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -403,6 +403,45 @@ void move_look_cursor(ConsoleHandle& console, ProControllerContext& context, siz ); } +// The "Confirm Choices" highlight on the screen now, reading a few frames +// over `window` with no press. Nullopt if none of them is the screen. +std::optional read_confirm_choices_now(ConsoleHandle& console, ProControllerContext& context, Milliseconds window){ + const WallClock deadline = current_time() + window; + while (true){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + const std::optional cursor = frame ? read_confirm_choices_cursor(frame) : std::nullopt; + if (cursor || current_time() >= deadline){ + return cursor; + } + context.wait_for(250ms); + } +} + +// On "Confirm Choices": one DOWN at a time to "Ready!", reading the +// highlight after each, then A on it. Throws OperationFailedException if +// the highlight is not read or does not get there. +void press_ready_on_confirm_choices(ConsoleHandle& console, ProControllerContext& context){ + for (size_t attempt = 0; attempt < 6; attempt++){ + const std::optional cursor = read_confirm_choices_now(console, context, 1000ms); + const std::optional> moves = cursor ? confirm_choices_moves(*cursor) : std::nullopt; + if (!moves){ + break; + } + console.log(std::format("AutoStory intro: Confirm Choices: the highlight is on row {}.", *cursor)); + press_intro_keys(console, context, {moves->front()}, 500ms); + if (moves->front() == IntroKey::A){ + dump_intro_frame(console, context, "confirm"); + return; + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "AutoStory intro: the Confirm Choices highlight was not read on \"Ready!\".", + console + ); +} + } // namespace @@ -465,10 +504,29 @@ void type_player_name( context.wait_for(2500ms); dump_intro_frame(console, context, "confirm-choices"); console.log("AutoStory intro: Confirm Choices: DOWN x2 to \"Ready!\", then A."); - press_intro_keys(console, context, {IntroKey::DOWN, IntroKey::DOWN, IntroKey::A}, 2000ms); + press_intro_keys(console, context, *confirm_choices_moves(0), 2000ms); dump_intro_frame(console, context, "confirm"); } +size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context){ + const std::optional cursor = read_confirm_choices_now(console, context, 2000ms); + 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. It is not on screen; nothing was pressed. Start from 00.00 to have the program choose them." + ); + } + console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); + return *cursor; +} + +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ + require_confirm_choices(console, context); + dump_intro_frame(console, context, "confirm-choices"); + press_ready_on_confirm_choices(console, context); +} + } // 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 94b359f7d7..efdf300622 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -57,7 +57,7 @@ bool tutorial_card_shows(const ImageViewRGB32& frame); // Switch system keyboard) are detected; the look picker is not checked and // waits a fixed time. -// 01.00's first step. It starts on the Switch HOME menu with PLZA's tile +// 00.00's first step. It starts on the Switch HOME menu with PLZA's tile // selected and no save: launches that tile without moving the cursor, // closing the game first if it is running, through the user select and // the license check to the language list (launch_selected_game_from_home(), @@ -93,6 +93,19 @@ void type_player_name( const std::string& name, bool first_letter_auto_caps ); +// The highlighted row of "Confirm Choices", read from frames over up to +// 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 +// OperationFailedException if the highlight is lost on the way. +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index fa3a27d24b..8d44a75b5d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -22,6 +22,7 @@ #include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" #include "Actions/PokemonLZA_AutoStoryIntro.h" +#include "Actions/PokemonLZA_AutoStoryScenes.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStoryTable.h" @@ -39,7 +40,7 @@ AutoStory_Descriptor::AutoStory_Descriptor() "PokemonLZA:AutoStory", std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", - "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. Checkpoint 01.00 (a new game) starts on the Switch HOME screen with PLZA's tile selected and no save: it launches the selected tile without moving the cursor (closing it first if it is running) and waits for the language list. Go Home When Done leaves HOME with PLZA's tile selected, ready for the next new game.", + "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. Checkpoint 01.00 (a new game) starts on the new game's Confirm Choices screen, with the language, look and name chosen by hand: it checks that screen, presses nothing anywhere else, and picks Ready!. Checkpoint 00.00 makes those choices too: it starts on the Switch HOME screen with PLZA's tile selected and no save, launches the selected tile without moving the cursor (closing it first if it is running) and plays the new game to the platform; a run from 00.00 skips 01.00. Go Home When Done leaves HOME with PLZA's tile selected, ready for the next new game.", PanelQualityStanding::DEVELOPER, ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, @@ -106,14 +107,14 @@ AutoStory::AutoStory() namespace{ -// Checkpoints after the first start from a save (01.01 from the platform -// autosave), so the run loads it first instead of assuming the game is -// already there. +// Checkpoints after the new game start from a save (01.01 from the +// platform autosave), so the run loads it first instead of assuming the +// game is already there. 00.00 and 01.00 start without one. void load_start_save( ConsoleHandle& console, const StoryGame& game, StoryBackend& backend, const std::vector& rows, size_t first ){ - if (first == 0){ + if (story_row_starts_without_save(rows[first])){ return; } const Outcome loaded = game.reload(backend); @@ -143,6 +144,16 @@ StoryData load_run_story(ConsoleHandle& console){ } } +// 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_confirms_new_game(first_row)){ + require_confirm_choices(console, context); + } + require_player(console, context, BUTTON_L); +} + } // namespace NewGameChoices AutoStory::new_game_choices(ConsoleHandle& console, bool check) const{ @@ -172,10 +183,10 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex if (first > last || last >= rows.size()){ throw UserSetupError(env.console, "The start checkpoint must not come after the end checkpoint."); } - require_player(env.console, context, BUTTON_L); + connect_controller(env.console, context, rows[first]); StoryEnv story{ - .env = env, .context = context, .new_game = new_game_choices(env.console, first == 0), + .env = env, .context = context, .new_game = new_game_choices(env.console, story_row_launches_game(rows[first])), .language = RUN.language(), .battle_ai = BATTLE_AI }; PlzaConsoleBackend backend(story); @@ -198,7 +209,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex send_program_finished_notification(env, NOTIFICATION_PROGRAM_FINISH); return; } - const std::span checkpoints(rows.data() + first, last - first + 1); + const std::vector checkpoints = story_run_rows(rows, first, last); const SegmentReport report = engine.run_segment("plza", checkpoints, RUN.policy().attempts_per_checkpoint, state); record_story_counts(report.story_counts(), env.current_stats()); env.update_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index e418fc4ede..59493e852d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -63,7 +63,7 @@ class AutoStory : public SingleSwitchProgramInstance{ // The start and end checkpoints, attempts, checks and language. Pokemon::StoryRunOptions RUN; BattleAIOption BATTLE_AI; - // The new game's choices (01.00): the language is RUN's. The look and + // The new game's choices (00.00): the language is RUN's. The look and // the language list's order are guesses from Scarlet/Violet's screens. StringOption PLAYER_NAME; SimpleIntegerOption PLAYER_LOOK; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index f8b7a13a2c..f7139efbc3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -2,7 +2,7 @@ * * From: https://github.com/PokemonAutomation/ * - * 01.00's scene steps, the walks' compass turns, and every checkpoint, through the shared + * The new game's scene steps, the walks' compass turns, and every checkpoint, through the shared * story engine on its scripted backend (FakeStoryBackend). * */ @@ -210,7 +210,7 @@ UnitTestResult test_refused_steps(CancellableScope& scope){ return "Expected a tile walk to fail the lint."; } FakeBackend backend = fake_plza({look_at(0ms)}, scope); - const Pokemon::StoryEngineReport report = run_plza(backend, step_of("01.00", "language")); + const Pokemon::StoryEngineReport report = run_plza(backend, step_of("00.00", "language")); if (report.run.failure.failure != "console_only"){ return std::format("Expected the new game's language to need a console, got {}", to_string(report.run.failure)); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h index 9eaefccc32..aeb7bc7e75 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h @@ -14,7 +14,7 @@ namespace NintendoSwitch{ namespace PokemonLZA{ -// PLZA's checkpoints and 01.00's scene steps on the shared story engine, +// PLZA's checkpoints and the new game's scene steps on the shared story engine, // with a scripted backend: no console. void add_tests_AutoStoryEngine(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 41006891ee..4bcfae82a5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -74,6 +74,7 @@ const std::map>& console_game_actions(){ {"type_player_name", [](StoryEnv& env){ type_player_name(env.env.console, env.context, env.new_game.name, env.new_game.name_first_letter_auto_caps); }}, + {"confirm_new_game", [](StoryEnv& env){ confirm_new_game_choices(env.env.console, env.context); }}, {"choose_0", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 0); }}, {"choose_1", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 1); }}, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index b2b1d8e629..68daa81566 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -8,7 +8,7 @@ * * The actions that read or press through the game's own screens (menus, * the naming keyboard, the battle AI, fast travel) are console_only: the - * engine refuses them elsewhere. The scenes of 01.00 and the walks run on + * engine refuses them elsewhere. The new game's scenes and the walks run on * any backend. * */ @@ -57,7 +57,8 @@ const std::map>& story_actions_not_impleme // "text_to_choice" (run_scene_machine()); a console step, one // call through the game's own screens with no args: the new // game's "launch_game_from_home", "new_game_language", -// "pick_look", "type_player_name"; +// "pick_look", "type_player_name" (00.00), and +// "confirm_new_game" (01.00, on "Confirm Choices"); // "choose_0" / "choose_1" (that row of the choices on screen); // or an action of story_actions_not_implemented() // diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h index cf561f3584..09d34e5ff8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h @@ -42,9 +42,10 @@ StoryData load_story_data(std::span dev_files); const StoryData& builtin_story_data(); // The built-in story (load_story_data() with no dev files), read once: -// what the tests, the lint and the program's dropdowns use: 01.00, a new -// game to the station platform, which starts without a save on the HOME -// screen with PLZA's tile selected. +// what the tests, the lint and the program's dropdowns use: 00.00 and +// 01.00, a new game to the station platform, which start without a save: +// 00.00 on the HOME screen with PLZA's tile selected, 01.00 on the new +// game's "Confirm Choices", its choices made by hand. const std::vector& story_checkpoints(); // The built-in rows that end on one of the game's autosaves. Each ends diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index 1a4adfd832..0cc521402a 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 "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryTable.h" @@ -33,12 +34,43 @@ size_t story_rows_ready(const std::vector& checkpoints){ return ready; } -bool story_row_launches_game(const StoryCheckpoint& row){ +namespace{ + +// Whether `row`'s first step is the GAME action `action`. +bool first_game_action_is(const StoryCheckpoint& row, std::string_view action){ if (row.steps.empty()){ return false; } const StoryStep& first = row.steps.front(); - return first.kind == StoryStepKind::GAME && first.action == "launch_game_from_home"; + return first.kind == StoryStepKind::GAME && first.action == action; +} + +} // namespace + +bool story_row_launches_game(const StoryCheckpoint& row){ + return first_game_action_is(row, "launch_game_from_home"); +} + +bool story_row_confirms_new_game(const StoryCheckpoint& row){ + return first_game_action_is(row, "confirm_new_game"); +} + +bool story_row_starts_without_save(const StoryCheckpoint& row){ + return story_row_launches_game(row) || story_row_confirms_new_game(row); +} + +std::vector story_run_rows(const std::vector& checkpoints, size_t first, size_t last){ + std::vector rows; + if (first > last || last >= checkpoints.size()){ + return rows; + } + for (size_t index = first; index <= last; index++){ + if (index > first && story_row_confirms_new_game(checkpoints[index])){ + continue; + } + rows.push_back(checkpoints[index]); + } + return rows; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index ec75d10012..7cedfc5b3e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -55,11 +55,28 @@ bool story_row_saves(const StoryData& story, const Pokemon::StoryCheckpoint& row size_t story_rows_ready(const std::vector& checkpoints); // Whether `row` starts by launching the game from HOME (its first step is -// the GAME action "launch_game_from_home"): the game may be in front on any +// the GAME action "launch_game_from_home"): 00.00. The game may be in front on any // screen, a dark scene too, so the frame at the program's start says nothing // about the screen size and the black border check waits for HOME. bool story_row_launches_game(const Pokemon::StoryCheckpoint& row); +// Whether `row` 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. It plays what 00.00 plays after the name. +bool story_row_confirms_new_game(const Pokemon::StoryCheckpoint& row); + +// Whether `row` starts with no save to load: it launches the game or +// confirms a new game. +bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); + +// The rows a run from `first` to `last` of `checkpoints` plays, in order: +// all of them but a row that confirms a new game after the run's first +// row, which played it already. Empty if `first` comes after `last` or +// `last` is past the end. +std::vector story_run_rows( + const std::vector& checkpoints, size_t first, size_t last +); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index cc6ba9f1cc..0d412571d6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -33,8 +33,9 @@ using Pokemon::StoryCheckpoint; using Pokemon::StoryStep; using Pokemon::StoryStepKind; -// The table: ids unique and in order, each row but the new game starts -// somewhere, and each lints against PLZA's actions in the engine. +// The table: ids unique and in order, each row but the new game's (00.00 +// and 01.00) starts somewhere, and each lints against PLZA's actions in +// the engine. UnitTestResult test_story_table_lints(Logger&){ std::string previous; for (const StoryCheckpoint& row : story_checkpoints()){ @@ -42,7 +43,7 @@ UnitTestResult test_story_table_lints(Logger&){ return std::format("{}: repeated or out of order after {}.", row.id, previous); } previous = row.id; - if (!row.start && row.id != "01.00"){ + if (!row.start && !story_row_starts_without_save(row)){ return std::format("{}: no start; every row after the new game starts from a save.", row.id); } const std::vector problems = plza_story_lint(row); @@ -50,8 +51,8 @@ UnitTestResult test_story_table_lints(Logger&){ return problems[0]; } } - if (story_checkpoints().empty() || story_checkpoints().front().id != "01.00"){ - return "Expected the table to start at 01.00, the new game."; + if (story_checkpoints().size() < 2 || story_checkpoints()[0].id != "00.00" || story_checkpoints()[1].id != "01.00"){ + return "Expected the table to start at 00.00 and 01.00, the new game."; } return true; } @@ -153,7 +154,7 @@ struct AutoStoryTableExpectation{ }; // A black start frame (the previous run stopped in a dark scene) trips the -// black border check: a run from 01.00, which launches the game, leaves the +// black border check: a run from 00.00, which launches the game, leaves the // check to HOME; a run from any later row still refuses on it. UnitTestResult test_black_start_frame(Logger&){ ImageRGB32 black(1920, 1080); @@ -164,13 +165,51 @@ UnitTestResult test_black_start_frame(Logger&){ } for (const StoryCheckpoint& row : story_checkpoints()){ const bool launches = story_row_launches_game(row); - if (launches != (row.id == "01.00")){ - return std::format("{}: launches the game: {}; only 01.00 should.", row.id, launches); + if (launches != (row.id == "00.00")){ + return std::format("{}: launches the game: {}; only 00.00 should.", row.id, launches); } } return true; } +// The new game's two starts: 00.00 launches from HOME and plays every +// choice, 01.00 starts on "Confirm Choices" after the choices made by hand. +// Neither loads a save, every later row does, and a run from 00.00 skips +// 01.00, which it has played. +UnitTestResult test_new_game_rows(Logger&){ + const std::vector& rows = story_checkpoints(); + for (const StoryCheckpoint& row : rows){ + const bool confirms = story_row_confirms_new_game(row); + if (confirms != (row.id == "01.00")){ + return std::format("{}: starts on Confirm Choices: {}; only 01.00 should.", row.id, confirms); + } + const bool no_save = story_row_starts_without_save(row); + if (no_save != (row.id == "00.00" || row.id == "01.00")){ + return std::format("{}: starts without a save: {}; only 00.00 and 01.00 should.", row.id, no_save); + } + } + const size_t last = rows.size() - 1; + const auto ids = [](const std::vector& run){ + std::string text; + for (const StoryCheckpoint& row : run){ + text += (text.empty() ? "" : " ") + row.id; + } + return text; + }; + const std::vector from_setup = story_run_rows(rows, 0, last); + if (from_setup.size() != rows.size() - 1 || from_setup[0].id != "00.00" || (from_setup.size() > 1 && from_setup[1].id == "01.00")){ + return std::format("A run from 00.00: expected every row but 01.00, got {}.", ids(from_setup)); + } + const std::vector from_confirm = story_run_rows(rows, 1, last); + if (from_confirm.size() != rows.size() - 1 || from_confirm[0].id != "01.00"){ + return std::format("A run from 01.00: expected every row from 01.00, got {}.", ids(from_confirm)); + } + if (!story_run_rows(rows, 1, 0).empty() || !story_run_rows(rows, 0, rows.size()).empty()){ + return "Expected no rows for a start after the end or an end past the table."; + } + return true; +} + struct AutoStoryTableCase{ AutoStoryTableInput input; AutoStoryTableExpectation expectation; @@ -219,7 +258,11 @@ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { .expectation = {}, }, { - .input = {"Start checks: a black start frame refuses every row but 01.00", test_black_start_frame}, + .input = {"Start checks: a black start frame refuses every row but 00.00", test_black_start_frame}, + .expectation = {}, + }, + { + .input = {"Start checks: 00.00 and 01.00 start the new game without a save; a run from 00.00 skips 01.00", test_new_game_rows}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json new file mode 100644 index 0000000000..9281202c94 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json @@ -0,0 +1,50 @@ +{ + "format": "pokesim-authored-checkpoint/1", + "game": "plza", + "checkpoint": { + "id": "00.00", + "title": "New game from HOME to the station platform", + "events": [ + { + "id": "launch_from_home", + "kind": "game_action", + "why": "step 0: with PLZA in front (any screen, mid-scene too) or on the HOME screen with its tile selected: HOME once if HOME is not showing (the game in front stays the selected tile), close it if it is running (X, A), launch the selected tile without moving the cursor, user select / license check, wait for the language list (no save: a new game opens on it)", + "action": "launch_game_from_home" + }, + { + "id": "language", + "kind": "game_action", + "why": "step 1: on the language list, move the highlight to the run's language (English) and press A", + "action": "new_game_language" + }, + { + "id": "look", + "kind": "game_action", + "why": "step 2: pick the first look", + "action": "pick_look" + }, + { + "id": "name", + "kind": "game_action", + "why": "steps 3-4: name the player and confirm", + "action": "type_player_name" + }, + { + "id": "opening", + "kind": "game_action", + "why": "step 5: the opening cutscene, no presses (A does not advance it), until the autosave badge has shown and the station platform holds", + "action": "opening_to_platform", + "args": { + "timeout_ms": 240000 + } + } + ], + "metadata": { + "phase": "testing", + "source": "console B recording, 2026-11-08/09: played step by step from a new game" + } + }, + "execution": { + "save": "autosave" + } +} 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 601e02a2bb..d0c807002a 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,36 +3,18 @@ "game": "plza", "checkpoint": { "id": "01.00", - "title": "New game to the station platform", + "title": "New game from Confirm Choices to the station platform", "events": [ { - "id": "launch_from_home", + "id": "confirm", "kind": "game_action", - "why": "step 0: with PLZA in front (any screen, mid-scene too) or on the HOME screen with its tile selected: HOME once if HOME is not showing (the game in front stays the selected tile), close it if it is running (X, A), launch the selected tile without moving the cursor, user select / license check, wait for the language list (no save: a new game opens on it)", - "action": "launch_game_from_home" - }, - { - "id": "language", - "kind": "game_action", - "why": "step 1: on the language list, move the highlight to the run's language (English) and press A", - "action": "new_game_language" - }, - { - "id": "look", - "kind": "game_action", - "why": "step 2: pick the first look", - "action": "pick_look" - }, - { - "id": "name", - "kind": "game_action", - "why": "steps 3-4: name the player and confirm", - "action": "type_player_name" + "why": "step 0: 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", + "action": "confirm_new_game" }, { "id": "opening", "kind": "game_action", - "why": "step 5: the opening cutscene, no presses (A does not advance it), until the autosave badge has shown and the station platform holds", + "why": "step 1: the opening cutscene, no presses (A does not advance it), until the autosave badge has shown and the station platform holds", "action": "opening_to_platform", "args": { "timeout_ms": 240000 @@ -41,7 +23,7 @@ ], "metadata": { "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game" + "source": "00.00's last two steps, console B recording 2026-11-08/09; Confirm Choices from console B, 2026-11-13" } }, "execution": { From 55ea0b0784e9b1cc9ecd57676997cce6f2f4fc46 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 08:51:28 -0800 Subject: [PATCH 15/33] PokemonLZA AutoStory: 01.00's Confirm Choices step in its own file Keeps the scenes header under the code health symbol limit once Main Mission 03 adds its scene helpers. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryConfirmChoices.cpp | 102 ++++++++++++++++++ .../PokemonLZA_AutoStoryConfirmChoices.h | 43 ++++++++ .../Actions/PokemonLZA_AutoStoryScenes.cpp | 58 ---------- .../Actions/PokemonLZA_AutoStoryScenes.h | 13 --- .../AutoStory/PokemonLZA_AutoStory.cpp | 2 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 1 + SerialPrograms/cmake/SourceFiles.cmake | 2 + 7 files changed, 149 insertions(+), 72 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp new file mode 100644 index 0000000000..5ca1d4307a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp @@ -0,0 +1,102 @@ +/* PokemonLZA AutoStory - Confirm Choices + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" +#include "CommonFramework/Tools/DebugDumper.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "PokemonLZA_AutoStoryIntroScreens.h" +#include "PokemonLZA_AutoStoryConfirmChoices.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +// The "Confirm Choices" highlight on the screen now, reading a few frames +// over `window` with no press. Nullopt if none of them is the screen. +// `dump`: save the frame read to DebugDumps under that name. +std::optional read_confirm_choices_now( + ConsoleHandle& console, ProControllerContext& context, Milliseconds window, const std::string& dump +){ + const WallClock deadline = current_time() + window; + while (true){ + context.wait_for_all_requests(); + const VideoSnapshot frame = console.video().snapshot(); + const std::optional cursor = frame ? read_confirm_choices_cursor(frame) : std::nullopt; + if (cursor || current_time() >= deadline){ + if (frame){ + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", dump, frame); + } + return cursor; + } + context.wait_for(250ms); + } +} + +// One press of confirm_choices_moves() on "Confirm Choices". +void press_confirm_key(ConsoleHandle& console, ProControllerContext& context, IntroKey key){ + if (key == IntroKey::A){ + console.log("AutoStory intro: Confirm Choices: A on \"Ready!\"."); + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + }else{ + console.log("AutoStory intro: Confirm Choices: DOWN."); + pbf_press_dpad(context, DPAD_DOWN, 160ms, 500ms); + } + context.wait_for_all_requests(); +} + +} // namespace + + +size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context){ + const std::optional cursor = read_confirm_choices_now(console, context, 2000ms, "confirm-choices"); + 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. It is not on screen; nothing was pressed. Start from 00.00 to have the program choose them." + ); + } + console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); + return *cursor; +} + +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ + std::optional cursor = require_confirm_choices(console, context); + for (size_t press = 0; press < 6 && cursor; press++){ + const std::optional> moves = confirm_choices_moves(*cursor); + if (!moves){ + break; + } + press_confirm_key(console, context, moves->front()); + if (moves->front() == IntroKey::A){ + return; + } + cursor = read_confirm_choices_now(console, context, 1000ms, "confirm-choices-moved"); + if (cursor){ + console.log(std::format("AutoStory intro: Confirm Choices: the highlight is on row {}.", *cursor)); + } + } + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "AutoStory intro: the Confirm Choices highlight was not read on \"Ready!\".", + console + ); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h new file mode 100644 index 0000000000..030fa23ab9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h @@ -0,0 +1,43 @@ +/* PokemonLZA AutoStory - Confirm Choices + * + * 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 detector is in + * PokemonLZA_AutoStoryIntroScreens.h; 00.00's name step + * (type_player_name(), PokemonLZA_AutoStoryScenes.h) presses through the + * same screen with the same moves. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryConfirmChoices_H +#define PokemonAutomation_PokemonLZA_AutoStoryConfirmChoices_H + +#include +#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" +#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// The highlighted row of "Confirm Choices", read from frames over up to +// 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 +// OperationFailedException if the highlight is lost on the way. +void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif 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 46e1666808..0522edbb86 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -403,45 +403,6 @@ void move_look_cursor(ConsoleHandle& console, ProControllerContext& context, siz ); } -// The "Confirm Choices" highlight on the screen now, reading a few frames -// over `window` with no press. Nullopt if none of them is the screen. -std::optional read_confirm_choices_now(ConsoleHandle& console, ProControllerContext& context, Milliseconds window){ - const WallClock deadline = current_time() + window; - while (true){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - const std::optional cursor = frame ? read_confirm_choices_cursor(frame) : std::nullopt; - if (cursor || current_time() >= deadline){ - return cursor; - } - context.wait_for(250ms); - } -} - -// On "Confirm Choices": one DOWN at a time to "Ready!", reading the -// highlight after each, then A on it. Throws OperationFailedException if -// the highlight is not read or does not get there. -void press_ready_on_confirm_choices(ConsoleHandle& console, ProControllerContext& context){ - for (size_t attempt = 0; attempt < 6; attempt++){ - const std::optional cursor = read_confirm_choices_now(console, context, 1000ms); - const std::optional> moves = cursor ? confirm_choices_moves(*cursor) : std::nullopt; - if (!moves){ - break; - } - console.log(std::format("AutoStory intro: Confirm Choices: the highlight is on row {}.", *cursor)); - press_intro_keys(console, context, {moves->front()}, 500ms); - if (moves->front() == IntroKey::A){ - dump_intro_frame(console, context, "confirm"); - return; - } - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "AutoStory intro: the Confirm Choices highlight was not read on \"Ready!\".", - console - ); -} - } // namespace @@ -508,25 +469,6 @@ void type_player_name( dump_intro_frame(console, context, "confirm"); } -size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& context){ - const std::optional cursor = read_confirm_choices_now(console, context, 2000ms); - 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. It is not on screen; nothing was pressed. Start from 00.00 to have the program choose them." - ); - } - console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); - return *cursor; -} - -void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ - require_confirm_choices(console, context); - dump_intro_frame(console, context, "confirm-choices"); - press_ready_on_confirm_choices(console, context); -} - } // 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 efdf300622..7adb477146 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -93,19 +93,6 @@ void type_player_name( const std::string& name, bool first_letter_auto_caps ); -// The highlighted row of "Confirm Choices", read from frames over up to -// 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 -// OperationFailedException if the highlight is lost on the way. -void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context); - } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 8d44a75b5d..2a58f82bbd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -22,7 +22,7 @@ #include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" #include "Actions/PokemonLZA_AutoStoryIntro.h" -#include "Actions/PokemonLZA_AutoStoryScenes.h" +#include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" #include "PokemonLZA_AutoStoryTable.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 4bcfae82a5..a152d8f410 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -23,6 +23,7 @@ #include "VideoGames/PokemonLZA/Programs/PokemonLZA_GameEntry.h" #include "VideoGames/PokemonLZA/Resources/PokemonLZA_Locations.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h" diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e1aba18644..ddc53fb86f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2417,6 +2417,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/PokemonLZA_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryActions.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp From 0a600e562c4e6ea94a499638c0c7b72f9907fd1e Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 11:47:32 -0800 Subject: [PATCH 16/33] PokemonLZA AutoStory: Confirm Choices reads row 1 through the highlight's glow On console B's frames in ten languages, the highlight's blue glow fills the gap under "Change looks" when that row is highlighted, so the dark background check refused the screen on row 1 in eight of them. The background check now takes dark blue with the glow; the slate rows get headroom for the glow too. Tests on the 30 frames (PokemonLZA/AutoStoryConfirmChoices in CommandLineTests): one per highlighted row per language. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryIntroScreens.cpp | 18 +++++++-- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 37 +++++++++++++++++++ 2 files changed, 51 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp index 329fa55f94..5e9a9b49a3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -173,7 +173,9 @@ ImageFloatBox confirm_row_strip(size_t row){ } // A "Confirm Choices" row's strip: the highlighted row white, flat, as the -// language list's; the others a darker slate than its boxes. +// language list's; the others a darker slate than its boxes. The +// highlight's glow pulses over the row next to it: on console B's frames +// in ten languages (2026-11-13) that row's spread went up to 20. ListBox classify_confirm_row(const ImageStats& stats){ if (stats.count == 0){ return ListBox::OTHER; @@ -188,14 +190,19 @@ ListBox classify_confirm_row(const ImageStats& stats){ average.g >= 40 && average.g <= 80 && average.b >= 65 && average.b <= 115 && average.b >= average.r + 25; - if (slate && spread <= 20){ + if (slate && spread <= 30){ return ListBox::PLAIN; } return ListBox::OTHER; } // The dark blue, dotted background round the rows: between the choices and -// "Ready!", and right of all three. +// "Ready!", and right of all three. The highlight's blue glow reaches 40 +// pixels out and fills the gap under "Change looks" when that row is +// highlighted: (12-13, 56-59, 102-106), spread up to 51, against the plain +// background's (10-11, 29-37, 63-75), spread up to 31 (console B, ten +// languages, 2026-11-13). Both are dark and blue with little red; the +// intro's other screens are not. bool confirm_background_dark(const ImageViewRGB32& frame){ const ImageFloatBox boxes[] = { ImageFloatBox(620.0 / 1920, 742.0 / 1080, 100.0 / 1920, 40.0 / 1080), @@ -203,7 +210,10 @@ bool confirm_background_dark(const ImageViewRGB32& frame){ }; for (const ImageFloatBox& box : boxes){ const ImageStats stats = image_stats(extract_box_reference(frame, box)); - if (stats.count == 0 || brightness(stats) >= 50 || stats.stddev.sum() > 35){ + if (stats.count == 0 || brightness(stats) >= 90 || stats.stddev.sum() > 80){ + return false; + } + if (stats.average.r > 30 || stats.average.b < stats.average.r + 40){ return false; } } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index 92f468bb06..f0e069c8ef 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -13,6 +13,7 @@ #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTest.h" #include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Tests/ImageUnitTest.h" #include "PokemonLZA_AutoStoryIntro.h" #include "PokemonLZA_AutoStoryIntroScreens.h" #include "PokemonLZA_AutoStoryLanguageList.h" @@ -682,6 +683,34 @@ const IntroCase INTRO_CASES[] = { }, }; +// "Confirm Choices" on console B in each game language, one frame per +// highlighted row (2026-11-13). The file name ends in that row: +// PokemonLZA/AutoStoryConfirmChoices/_.png. +class Test_ConfirmChoicesFrame : public ImageUnitTest{ +public: + explicit Test_ConfirmChoicesFrame(const std::string& image) + : ImageUnitTest("PokemonLZA::AutoStory - Confirm Choices - " + image, {image}) + {} + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, const std::vector& images + ) const override{ + const std::string& path = image_paths()[0]; + const size_t underscore = path.rfind('_'); + if (underscore == std::string::npos || underscore + 1 >= path.size()){ + return "Error: the file name does not end in _."; + } + const size_t expected = (size_t)(path[underscore + 1] - '0'); + const std::optional cursor = read_confirm_choices_cursor(images[0]); + if (!cursor){ + return std::format("Expected Confirm Choices with row {} highlighted, read no Confirm Choices.", expected); + } + if (*cursor != expected){ + return std::format("Expected row {} highlighted, read row {}.", expected, *cursor); + } + return true; + } +}; + class Test_AutoStoryIntro : public UnitTest{ public: explicit Test_AutoStoryIntro(const IntroCase& test_case) @@ -703,6 +732,14 @@ void add_tests_AutoStoryIntro(UnitTestDatabase& database){ for (const IntroCase& item : INTRO_CASES){ database.add(item); } + for (const std::string_view language : { + "English", "Spanish", "SpanishLatAm", "French", "German", + "Italian", "Japanese", "Korean", "ChineseSimplified", "ChineseTraditional", + }){ + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + database.add(std::format("PokemonLZA/AutoStoryConfirmChoices/{}_{}.png", language, row)); + } + } } From 3d3725fccc899138621ef1e3fa55cd65f1a913ac Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 11:54:55 -0800 Subject: [PATCH 17/33] PokemonLZA AutoStory: read the look picker's highlight by its card's corners On console B the highlighted look is a white card, enlarged past its tile. The old reader, written before any highlighted frame existed, refused every frame with a highlight, so 00.00 never read it (Japanese, 11:46: "not read on look 3" with look 2 highlighted). A tile is now highlighted when its 4 corner patches are white and the other 7 tiles' are slate; the picker itself is 8 tiles with a face and white-or-slate corners. After a press the step takes the look only when two reads in a row agree. Tests on 18 frames in English, German and Japanese (PokemonLZA/AutoStoryLookPicker in CommandLineTests); the 15 with a highlight failed on the old reader. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryIntroScreens.cpp | 133 ++++++++++-------- .../PokemonLZA_AutoStoryIntroScreens.h | 11 +- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 97 ++++++++----- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 37 +++-- 4 files changed, 168 insertions(+), 110 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp index 5e9a9b49a3..a15cd272a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp @@ -62,12 +62,6 @@ bool column_gap_dark(const ImageViewRGB32& frame){ return gap.count > 0 && gap.average.sum() / 3 < 70; } -enum class LookTile{ - HIGHLIGHTED, - PLAIN, - OTHER, -}; - constexpr size_t LOOK_COLUMNS = 4; // The look picker's tiles are 240 x 240 at 1920 x 1080, their left edges @@ -79,80 +73,99 @@ double look_tile_top(size_t look){ return (look <= LOOK_COLUMNS ? 324.0 : 609.0) / 1080; } -// A strip at the left end of look `look`'s tile, left of the face: 24 x 60 -// from 4 right of its edge and 20 down. -ImageFloatBox look_tile_strip(size_t look){ - return ImageFloatBox(look_tile_left(look) + 4.0 / 1920, look_tile_top(look) + 20.0 / 1080, 24.0 / 1920, 60.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 dark strip above look `look`'s tile: 160 x 8 from 40 right of its -// edge and 14 above it. -ImageFloatBox look_above_strip(size_t look){ - return ImageFloatBox(look_tile_left(look) + 40.0 / 1920, look_tile_top(look) - 14.0 / 1080, 160.0 / 1920, 8.0 / 1080); -} - -// The dark gap right of look `look`'s tile (not the last column's): 40 x 180 -// from 12 right of the tile and 20 down. -ImageFloatBox look_gap_strip(size_t look){ - return ImageFloatBox(look_tile_left(look) + 252.0 / 1920, look_tile_top(look) + 20.0 / 1080, 40.0 / 1920, 180.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); } double brightness(const ImageStats& stats){ return stats.average.sum() / 3; } -// Measured on console B (2026-11-13), the picker as it opens: the tiles' -// strips slate, (31-32, 44-47, 70-77), spread under 6; above them dark -// blue, (9-10, 16-32, 44-67), spread under 3. No frame with a highlight -// exists yet, so HIGHLIGHTED is any tile whose strip or the strip above it -// is much brighter than that: a light tile, or a light frame round it. -LookTile classify_look_tile(const ImageStats& tile, const ImageStats& above){ - if (tile.count == 0 || above.count == 0){ - return LookTile::OTHER; +enum class LookCorner{ + WHITE, + DARK, + OTHER, +}; + +// Measured on console B's look pickers (2026-11-13, 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; } - if (brightness(tile) >= 90 || brightness(above) >= 90){ - return LookTile::HIGHLIGHTED; + 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; } - const FloatPixel& average = tile.average; - const bool slate = - average.r >= 20 && average.r <= 45 && - average.g >= 35 && average.g <= 60 && - average.b >= 60 && average.b <= 95 && - average.b >= average.r + 25; - if (slate && tile.stddev.sum() <= 15 && brightness(above) < 50 && above.stddev.sum() <= 10){ - return LookTile::PLAIN; + if (brightness(stats) < 90 && average.r <= 50 && average.b >= average.r + 20 && spread <= 50){ + return LookCorner::DARK; } - return LookTile::OTHER; + return LookCorner::OTHER; } -// Whether `frame` is the look picker; if so, `highlighted` is the -// highlighted look, if any. +// 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 = image_stats(extract_box_reference(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(image_stats(extract_box_reference(frame, look_corner_patch(look, corner))))){ + case LookCorner::WHITE: + white++; + break; + case LookCorner::DARK: + break; + case LookCorner::OTHER: + return std::nullopt; + } + } + return white; +} + +// Whether `frame` is the look picker: all 8 tiles have a face and corners +// that are white or dark. If so, `highlighted` is the one look with 4 +// white corners while the other 7 have none; with any other mix (the card +// moving between looks) no look is highlighted. bool read_look_picker(const ImageViewRGB32& frame, std::optional& highlighted){ + highlighted.reset(); if (!frame || frame.width() < 160 || frame.height() < 90){ return false; } - highlighted.reset(); + std::optional card; + size_t lit_tiles = 0; for (size_t look = 1; look <= LOOK_COUNT; look++){ - if (look % LOOK_COLUMNS != 0){ - const ImageStats gap = image_stats(extract_box_reference(frame, look_gap_strip(look))); - if (gap.count == 0 || brightness(gap) >= 50 || gap.stddev.sum() > 30){ - return false; - } - } - const ImageStats tile = image_stats(extract_box_reference(frame, look_tile_strip(look))); - const ImageStats above = image_stats(extract_box_reference(frame, look_above_strip(look))); - switch (classify_look_tile(tile, above)){ - case LookTile::HIGHLIGHTED: - if (highlighted){ - return false; - } - highlighted = look; - break; - case LookTile::PLAIN: - break; - case LookTile::OTHER: + const std::optional white = look_white_corners(frame, look); + if (!white){ return false; } + if (*white > 0){ + lit_tiles++; + } + if (*white == 4){ + card = look; + } + } + if (lit_tiles == 1 && card){ + highlighted = card; } return true; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h index 74929cb2ec..5353e3adc3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h @@ -31,13 +31,14 @@ std::optional read_language_list_cursor(const ImageViewRGB32& frame); bool is_language_list(const ImageViewRGB32& frame); // On the "APPEARANCE" look picker, the look (1 to LOOK_COUNT) whose face is -// highlighted: the one face whose tile or the strip above it is brighter -// than the others' slate tiles. Nullopt while no face is highlighted (the -// screen opens so), and for any other frame. +// highlighted: the one tile whose 4 corners are on the white card while +// the other 7 tiles' corners are slate. Nullopt while no face is +// highlighted (the screen opens so), while the card moves between looks, +// and for any other frame. std::optional read_look_picker_cursor(const ImageViewRGB32& frame); -// The look picker's 2 x 4 grid of slate face tiles on dark blue, with at -// most one face highlighted. +// The look picker's 2 x 4 grid of face tiles on dark blue, each tile's +// corners white (the highlight's card) or slate. bool is_look_picker(const ImageViewRGB32& frame); // "Confirm Choices", the screen after the name keyboard, has three rows: diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp index f0e069c8ef..115f4d47b9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp @@ -325,19 +325,12 @@ UnitTestResult test_look_moves(Logger&){ return true; } -// How a highlighted face is drawn in look_picker_frame(). -enum class LookHighlight{ - // A white frame round the tile. - FRAME, - // A light tile. - TILE, -}; - // The look picker drawn as console B shows it (1920 x 1080): dark blue, // 8 slate tiles 240 x 240, the columns' left edges at x 373, 685, 997 and -// 1309, the rows' tops at y 324 and 609; look `highlighted` (if any) drawn -// as `style`. -ImageRGB32 look_picker_frame(std::optional highlighted, LookHighlight style = LookHighlight::FRAME){ +// 1309, the rows' tops at y 324 and 609, each with a face (a checkerboard) +// in its middle; looks in `highlighted` drawn on a white card 12 larger on +// every side. +ImageRGB32 look_picker_frame(std::initializer_list highlighted){ const size_t lefts[] = {373, 685, 997, 1309}; const size_t tops[] = {324, 609}; ImageRGB32 image(1920, 1080); @@ -345,18 +338,19 @@ ImageRGB32 look_picker_frame(std::optional highlighted, LookHighlight st for (size_t look = 1; look <= LOOK_COUNT; look++){ const size_t left = lefts[(look - 1) % 4]; const size_t top = tops[(look - 1) / 4]; - const bool lit = highlighted == look; - if (lit && style == LookHighlight::FRAME){ - for (size_t y = top - 10; y < top + 250; y++){ - for (size_t x = left - 10; x < left + 250; x++){ - image.pixel(x, y) = 0xffffffff; - } + bool lit = false; + for (const size_t item : highlighted){ + lit = lit || item == look; + } + const size_t grow = lit ? 12 : 0; + for (size_t y = top - grow; y < top + 240 + grow; y++){ + for (size_t x = left - grow; x < left + 240 + grow; x++){ + image.pixel(x, y) = lit ? 0xffffffff : 0xff202f50; } } - const uint32_t tile = lit && style == LookHighlight::TILE ? 0xffc8d2dc : 0xff202f50; - for (size_t y = top; y < top + 240; y++){ - for (size_t x = left; x < left + 240; x++){ - image.pixel(x, y) = tile; + for (size_t y = top + 80; y < top + 180; y++){ + for (size_t x = left + 70; x < left + 170; x++){ + image.pixel(x, y) = ((x / 10 + y / 10) % 2 == 0) ? 0xffe0b090 : 0xff302020; } } } @@ -364,26 +358,19 @@ ImageRGB32 look_picker_frame(std::optional highlighted, LookHighlight st } UnitTestResult test_look_picker_synthetic(Logger&){ - const ImageRGB32 none = look_picker_frame(std::nullopt); + const ImageRGB32 none = look_picker_frame({}); if (!is_look_picker(none) || read_look_picker_cursor(none)){ return "Expected the picker with no highlight."; } - for (const LookHighlight style : {LookHighlight::FRAME, LookHighlight::TILE}){ - for (size_t look = 1; look <= LOOK_COUNT; look++){ - const ImageRGB32 frame = look_picker_frame(look, style); - if (!is_look_picker(frame) || read_look_picker_cursor(frame) != look){ - return std::format("Expected the highlight read on look {} (style {}).", look, (int)style); - } - } - } - ImageRGB32 two = look_picker_frame(1, LookHighlight::TILE); - for (size_t y = 609; y < 849; y++){ - for (size_t x = 1309; x < 1549; x++){ - two.pixel(x, y) = 0xffc8d2dc; + for (size_t look = 1; look <= LOOK_COUNT; look++){ + const ImageRGB32 frame = look_picker_frame({look}); + if (!is_look_picker(frame) || read_look_picker_cursor(frame) != look){ + return std::format("Expected the highlight read on look {}.", look); } } - if (is_look_picker(two) || read_look_picker_cursor(two)){ - return "Expected no picker with two highlights."; + const ImageRGB32 two = look_picker_frame({1, 8}); + if (!is_look_picker(two) || read_look_picker_cursor(two)){ + return "Expected the picker with no highlight read while two looks have the card."; } if (is_look_picker(language_list_frame(0))){ return "Expected the language list not to be the picker."; @@ -711,6 +698,37 @@ class Test_ConfirmChoicesFrame : public ImageUnitTest{ } }; +// The look picker on console B (2026-11-13), as the 00.00 runs saved it in +// English, German and Japanese. The file name ends in the highlighted +// look, 0 for none: PokemonLZA/AutoStoryLookPicker/__.png. +class Test_LookPickerFrame : public ImageUnitTest{ +public: + explicit Test_LookPickerFrame(const std::string& image) + : ImageUnitTest("PokemonLZA::AutoStory - Look picker - " + image, {image}) + {} + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, const std::vector& images + ) const override{ + const std::string& path = image_paths()[0]; + const size_t underscore = path.rfind('_'); + if (underscore == std::string::npos || underscore + 1 >= path.size()){ + return "Error: the file name does not end in _."; + } + const size_t expected = (size_t)(path[underscore + 1] - '0'); + if (!is_look_picker(images[0])){ + return "Expected the look picker, read another screen."; + } + const std::optional cursor = read_look_picker_cursor(images[0]); + if (expected == 0 && cursor){ + return std::format("Expected no highlight, read look {}.", *cursor); + } + if (expected != 0 && cursor != expected){ + return std::format("Expected look {} highlighted, read {}.", expected, cursor ? std::to_string(*cursor) : "none"); + } + return true; + } +}; + class Test_AutoStoryIntro : public UnitTest{ public: explicit Test_AutoStoryIntro(const IntroCase& test_case) @@ -740,6 +758,13 @@ void add_tests_AutoStoryIntro(UnitTestDatabase& database){ database.add(std::format("PokemonLZA/AutoStoryConfirmChoices/{}_{}.png", language, row)); } } + for (const std::string_view name : { + "English_1_0", "English_2_3", "English_3_7", "English_4_2", "English_5_6", "English_6_1", "English_7_5", + "German_1_0", "German_2_7", "German_3_3", "German_4_2", "German_5_6", + "Japanese_1_0", "Japanese_2_6", "Japanese_3_2", "Japanese_4_2", "Japanese_5_3", "Japanese_6_7", + }){ + database.add(std::format("PokemonLZA/AutoStoryLookPicker/{}.png", name)); + } } 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 0522edbb86..41da498647 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -361,23 +361,42 @@ void wait_for_look_picker(ConsoleHandle& console, ProControllerContext& context, ); } +// The look picker's highlight once it has settled: frames 150 ms apart +// until two reads in a row agree on a look, over at most 2 s. The card +// grows and moves for a moment after a press, so one read can catch it +// between looks. Nullopt (the last frame saved to DebugDumps) if no two +// reads agree. +std::optional read_settled_look(ConsoleHandle& console, ProControllerContext& context){ + std::optional previous; + VideoSnapshot frame; + for (size_t read = 0; read < 14; read++){ + context.wait_for_all_requests(); + frame = console.video().snapshot(); + const std::optional cursor = frame ? read_look_picker_cursor(frame) : std::nullopt; + if (cursor && cursor == previous){ + return cursor; + } + previous = cursor; + context.wait_for(150ms); + } + if (frame){ + dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "look-picker-unread", frame); + } + return std::nullopt; +} + // On the look picker: one press at a time towards look `target`, reading -// the highlight after each, until it is on `target`. The picker opens with +// the settled highlight (read_settled_look()) after each, until it is on +// `target`. The picker opens with // no face highlighted, so while none is, UP (harmless on any face of the -// top row) to bring the highlight up. Each frame read with no highlight is -// saved to DebugDumps. Throws OperationFailedException if the highlight is +// top row) to bring the highlight up. Throws OperationFailedException if the highlight is // not read or does not reach `target`. void move_look_cursor(ConsoleHandle& console, ProControllerContext& context, size_t target){ size_t unread = 0; for (size_t attempt = 0; attempt < 24; attempt++){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - const std::optional cursor = frame ? read_look_picker_cursor(frame) : std::nullopt; + const std::optional cursor = read_settled_look(console, context); if (!cursor){ unread++; - if (frame){ - dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "look-picker-unread", frame); - } if (unread > 6){ break; } From 43279c4f002fbb100453a6e57ac1998539b3d72a Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:10:18 -0800 Subject: [PATCH 18/33] PokemonLZA AutoStory: reload the save at a checkpoint marked reload_when_chained A checkpoint run straight after the one before it can start with the player and camera left differently than after a save load: 01.02's chase went the wrong way after 01.01's scenes (console B, 2026-11-13), while it walks right from its save. A checkpoint file's "execution" can now say "reload_when_chained": true. A run that plays the row before it then ends its segment there, reloads (the game's reload: HOME, close, relaunch, a plain load), logs it as the event reload_at_boundary, and starts a new segment at the row, as if from its save. The reload fails the run if the station platform shows: that is 01.01's start, an older save than the autosave the row starts from. A run that starts at the row loads its save as before, with no extra reload. The field is accepted only as true, on a row with a save, after a row that ends on the game's autosave, so the reload loads that autosave. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonLZA_AutoStory.cpp | 2 +- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 110 ++++++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 84 +++++++++++++ .../AutoStory/PokemonLZA_AutoStoryGame.h | 18 +++ .../PokemonLZA_AutoStoryStoryFiles.cpp | 59 ++++++++-- .../AutoStory/PokemonLZA_AutoStoryTable.h | 5 + .../PokemonLZA_AutoStoryTable_Tests.cpp | 58 +++++++++ 7 files changed, 324 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 2a58f82bbd..426d063a9f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -210,7 +210,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex return; } const std::vector checkpoints = story_run_rows(rows, first, last); - const SegmentReport report = engine.run_segment("plza", checkpoints, RUN.policy().attempts_per_checkpoint, state); + const SegmentReport report = run_plza_segment(game, story_data, checkpoints, RUN.policy().attempts_per_checkpoint, engine, backend, state); record_story_counts(report.story_counts(), env.current_stats()); env.update_stats(); if (!report.completed){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index f7139efbc3..aaf6fe9a81 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -279,6 +280,112 @@ UnitTestResult test_every_checkpoint_runs(CancellableScope& scope){ } +// A row `id` whose one step is the platform start check (wait_for_platform). +StoryCheckpoint platform_row(std::string id){ + StoryCheckpoint row; + row.id = std::move(id); + row.steps.push_back(StoryStep{ + .kind = Pokemon::StoryStepKind::GAME, .name = "on_platform", .why = "test", .action = "wait_for_platform", + .args = {{"timeout_ms", int64_t(1000)}}, + }); + return row; +} + +// How a run of `ids` (platform rows) went, B reloading when chained. +struct BoundaryRun{ + Pokemon::SegmentReport report; + std::vector lines; + size_t reloads = 0; +}; + +// `ids` through run_plza_segment() over looks with the platform on +// `platform` (by look index; the last look repeats); the game's reload +// counts itself. +BoundaryRun run_boundary(std::vector ids, std::vector platform, CancellableScope& scope){ + std::vector> looks; + for (size_t i = 0; i < platform.size(); i++){ + const Observation look = look_at(Milliseconds(300 * (int64_t)i)); + looks.push_back(platform[i] ? with_reading(look, PLATFORM_READING) : look); + } + FakeBackend backend = fake_plza(std::move(looks), scope); + Pokemon::StoryGame game = make_offline_plza_story_game(); + BoundaryRun run; + game.reload = [&run](Pokemon::StoryBackend& backend){ + run.reloads++; + backend.log("[Test] reload"); + return Pokemon::outcome_ok(); + }; + StoryData story; + story.reload_when_chained = {"B"}; + std::vector rows; + for (std::string& id : ids){ + rows.push_back(platform_row(std::move(id))); + } + Pokemon::StoryEngine engine(game, backend); + Pokemon::RunState state; + run.report = run_plza_segment(game, story, rows, 1, engine, backend, state); + run.lines = backend.lines(); + return run; +} + +// The index of the first line of `lines` that holds `text`; the size when +// none does. +size_t line_index(const std::vector& lines, std::string_view text){ + return std::find_if(lines.begin(), lines.end(), [text](const std::string& line){ + return line.find(text) != std::string::npos; + }) - lines.begin(); +} + +// Run straight after A, B starts with the reload, logged as its own event +// between A's pass and B's start; then no platform on the looks after it. +UnitTestResult test_reload_when_chained(CancellableScope& scope){ + const BoundaryRun run = run_boundary({"A", "B"}, {true, true, false, false, false, false, true, true}, scope); + if (!run.report.completed || run.reloads != 1){ + return std::format("Expected A and B with one reload, got {} reloads: {}", run.reloads, joined(run.lines)); + } + const size_t a_passed = line_index(run.lines, "[Checkpoint] A: passed"); + const size_t reload = line_index(run.lines, "[Event] B/0 reload_at_boundary: start"); + const size_t reloaded = line_index(run.lines, "[Test] reload"); + const size_t done = line_index(run.lines, "[Event] B/0 reload_at_boundary: done"); + const size_t b_start = line_index(run.lines, "[Checkpoint] B: start"); + if (!(a_passed < reload && reload < reloaded && reloaded < done && done < b_start && b_start < run.lines.size())){ + return std::format("Expected A, the reload event, then B: {}", joined(run.lines)); + } + if (run.report.runs.size() != 2 || run.report.checkpoints_run != 2){ + return std::format("Expected both rows in one report, got {} runs.", run.report.runs.size()); + } + return true; +} + +// A run that starts at B (from B's save), or a row with no +// reload_when_chained after A, has no reload. +UnitTestResult test_no_reload_unless_chained(CancellableScope& scope){ + for (const std::vector& ids : {std::vector{"B"}, std::vector{"A", "C"}}){ + const BoundaryRun run = run_boundary(ids, {true}, scope); + if (!run.report.completed || run.reloads != 0 || line_index(run.lines, "reload_at_boundary") != run.lines.size()){ + return std::format("Expected no reload for {}: {}", joined(ids), joined(run.lines)); + } + } + return true; +} + +// A reload that lands on the station platform loaded an older save: the +// run fails at the boundary, before any step of B. +UnitTestResult test_reload_lands_on_older_save(CancellableScope& scope){ + const BoundaryRun run = run_boundary({"A", "B"}, {true}, scope); + if (run.report.completed || run.report.failed_checkpoint != "B" || run.report.failed_event != "reload_at_boundary"){ + return std::format("Expected a failure at B's reload: {}", joined(run.lines)); + } + if (to_string(run.report.failure).find("did not land at B's start") == std::string::npos){ + return std::format("Expected the failure to say where it did not land: {}", to_string(run.report.failure)); + } + if (line_index(run.lines, "[Checkpoint] B: start") != run.lines.size()){ + return "Expected no step of B after the failed reload."; + } + return true; +} + + struct EngineTestInput{ std::string name; std::function body; @@ -319,6 +426,9 @@ const EngineTestCase ENGINE_TEST_CASES[] = { {.input = {"face_heading: turns by the minimap's heading", test_face_heading}, .expectation = {}}, {.input = {"refused: console actions off a console, tile walks, unknown actions", test_refused_steps}, .expectation = {}}, {.input = {"every checkpoint runs in step order, testing never saves", test_every_checkpoint_runs}, .expectation = {}}, + {.input = {"reload_when_chained: reload between the rows, as its own event", test_reload_when_chained}, .expectation = {}}, + {.input = {"reload_when_chained: no reload from the row's save or for other rows", test_no_reload_unless_chained}, .expectation = {}}, + {.input = {"reload_when_chained: a reload onto the platform fails", test_reload_lands_on_older_save}, .expectation = {}}, }; void add_tests_AutoStoryEngine(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index a152d8f410..d28e4ae1b7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include #include @@ -529,6 +530,89 @@ Pokemon::StoryGame make_offline_plza_story_game(){ } +namespace{ + +// Looks a reload at a boundary takes, PLATFORM_POLL apart, to tell 01.01's +// start from a later one: right after a load the platform reads on the +// first two (console B, 2026-11-10). +constexpr size_t BOUNDARY_LOOKS = 4; + +// The reload before `row`, which a run reached from the row before it: the +// game's reload, then BOUNDARY_LOOKS looks, which fail if the station +// platform holds PLATFORM_LOOKS of them in a row. A save on the platform is +// 01.01's start: the reload did not bring back the autosave `row` starts +// from, which a reload_when_chained row comes after, but an older one. +Outcome reload_at_boundary(const Pokemon::StoryGame& game, Pokemon::StoryBackend& backend, std::string_view row){ + if (!game.reload){ + return Pokemon::outcome_failed("no_reload", "this game has no reload"); + } + const Outcome reloaded = game.reload(backend); + if (!reloaded.succeeded()){ + return reloaded; + } + size_t streak = 0; + for (size_t looks = 0; looks < BOUNDARY_LOOKS; looks++){ + backend.scope().throw_if_cancelled(); + streak = backend.observe().readings.contains(PLATFORM_READING) ? streak + 1 : 0; + if (streak >= PLATFORM_LOOKS){ + return Pokemon::outcome_failed("older_save", std::format( + "the reload did not land at {}'s start: the station platform shows, so it loaded an older save", row + )); + } + backend.wait(PLATFORM_POLL); + } + return Pokemon::outcome_ok(); +} + +void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& total){ + total.checkpoints_run += part.checkpoints_run; + total.reloads += part.reloads; + total.runs.insert(total.runs.end(), part.runs.begin(), part.runs.end()); + total.failed_checkpoint = part.failed_checkpoint; + total.failed_event = part.failed_event; + total.failure = part.failure; +} + +} // namespace + +Pokemon::SegmentReport run_plza_segment( + const Pokemon::StoryGame& game, const StoryData& story, + std::span rows, size_t attempts_per_checkpoint, + Pokemon::StoryEngine& engine, Pokemon::StoryBackend& backend, Pokemon::RunState& state +){ + Pokemon::SegmentReport total; + size_t begin = 0; + while (begin < rows.size()){ + size_t end = begin + 1; + while (end < rows.size() && !story.reload_when_chained.contains(rows[end].id)){ + end++; + } + if (begin > 0){ + const std::string& id = rows[begin].id; + backend.log(std::format("[Event] {}/0 reload_at_boundary: start", id)); + const Outcome reloaded = reload_at_boundary(game, backend, id); + if (!reloaded.succeeded()){ + backend.log(std::format("[Event] {}/0 reload_at_boundary: failed: {}", id, to_string(reloaded))); + total.failed_checkpoint = id; + total.failed_event = "reload_at_boundary"; + total.failure = reloaded; + return total; + } + backend.log(std::format("[Event] {}/0 reload_at_boundary: done", id)); + state = Pokemon::RunState{}; + } + const Pokemon::SegmentReport part = engine.run_segment("plza", rows.subspan(begin, end - begin), attempts_per_checkpoint, state); + add_segment(part, total); + if (!part.completed){ + return total; + } + begin = end; + } + total.completed = true; + return total; +} + + } // namespace PokemonLZA } // namespace NintendoSwitch diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 68daa81566..0c2c389fa9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -19,13 +19,16 @@ #include #include #include +#include #include #include #include +#include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryActionSpec.h" #include "Pokemon/AutoStory/Types/Pokemon_StoryCheckpoint.h" #include "PokemonLZA_AutoStoryBackend.h" +#include "PokemonLZA_AutoStoryTable.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h" namespace PokemonAutomation{ @@ -98,6 +101,21 @@ Pokemon::StoryGame make_plza_story_game( // carry, and there is no save or reload. Pokemon::StoryGame make_offline_plza_story_game(); +// `rows` in order from the save the game is on, as +// StoryEngine::run_segment() runs them, but a row of `story`'s +// reload_when_chained after the run's first starts as from its save: the +// run's segment stops before it, the event "reload_at_boundary" reloads +// the save (`game`'s reload, the autosave the row before ended on) and +// checks that the station platform does not show (an older save), and a +// new segment starts at it. A failed reload fails the run there. The row +// before such a row ends its segment, so it ends at SavePoint::RUN_END. +Pokemon::SegmentReport run_plza_segment( + const Pokemon::StoryGame& game, const StoryData& story, + std::span rows, size_t attempts_per_checkpoint, + Pokemon::StoryEngine& engine, Pokemon::StoryBackend& backend, + Pokemon::RunState& state +); + } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp index dfd7ef5d7a..adb197b0de 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp @@ -25,22 +25,53 @@ using Pokemon::StoryCheckpoint; namespace{ -// A checkpoint file's checkpoint, and whether its execution says the game -// autosaves at its end. `source` names the file in parse errors. -std::pair read_checkpoint_file(std::string_view text, std::string_view source){ +// What a checkpoint file's "execution" says. +struct CheckpointExecution{ + // "save": "autosave": the game autosaves at the checkpoint's end. bool autosave = false; - const Pokemon::ExecutionReader read_execution = [&autosave](const JsonObject& execution, std::string_view where){ - Pokemon::validate_json_fields(execution, {"save"}, where); + // "reload_when_chained": true (StoryData::reload_when_chained). + bool reload_when_chained = false; +}; + +// A checkpoint file's checkpoint and its execution. `source` names the file +// in parse errors. +std::pair read_checkpoint_file(std::string_view text, std::string_view source){ + CheckpointExecution read; + const Pokemon::ExecutionReader read_execution = [&read](const JsonObject& execution, std::string_view where){ + read.reload_when_chained = execution.get_value("reload_when_chained") != nullptr; + if (read.reload_when_chained){ + Pokemon::validate_json_fields(execution, {"save", "reload_when_chained"}, where); + if (!execution.get_boolean_throw("reload_when_chained", std::string(where))){ + throw ParseException(std::format("{}: reload_when_chained is true or left out", where)); + } + }else{ + Pokemon::validate_json_fields(execution, {"save"}, where); + } const std::string& save = execution.get_string_throw("save"); if (save != "autosave" && save != "menu"){ throw ParseException(std::format("{}: save must be \"autosave\" or \"menu\", not {}", where, save)); } - autosave = save == "autosave"; + read.autosave = save == "autosave"; }; StoryCheckpoint checkpoint = Pokemon::read_authored_checkpoint( parse_json(std::string(text)), "plza", source, read_execution, plza_story_specs() ); - return {std::move(checkpoint), autosave}; + return {std::move(checkpoint), read}; +} + +// Refuses a "reload_when_chained" on `checkpoint` (from `file_name`) unless +// it starts from a save and the row before it in `data` ends on the game's +// autosave: the reload loads the last save, which must be that autosave. +void check_reload_when_chained(const StoryData& data, const StoryCheckpoint& checkpoint, std::string_view file_name){ + if (story_row_starts_without_save(checkpoint)){ + throw ParseException(std::format("{}: reload_when_chained on a checkpoint with no save to reload", file_name)); + } + if (data.checkpoints.empty() || !data.autosaves.contains(data.checkpoints.back().id)){ + throw ParseException(std::format( + "{}: reload_when_chained after a checkpoint that does not end on the game's autosave: the reload would load an older save", + file_name + )); + } } // The dev file of `dev_files` named `name`, if any. @@ -55,8 +86,10 @@ const StoryDevFile* find_dev_file(std::span dev_files, std:: // `dev`'s checkpoint, which replaces `builtin`'s: it must lint and keep its // id, so the run's start and end indices still mean the same rows. -std::pair read_dev_checkpoint(const StoryDevFile& dev, std::string_view builtin_text, std::string_view builtin_name){ - std::pair read; +std::pair read_dev_checkpoint( + const StoryDevFile& dev, std::string_view builtin_text, std::string_view builtin_name +){ + std::pair read; try{ read = read_checkpoint_file(dev.text, dev.path); }catch (ParseException& e){ @@ -94,13 +127,17 @@ StoryData load_story_data(std::span dev_files){ for (const auto& [name, text] : autostory_checkpoint_json()){ const std::string file_name = std::format("{}.json", name); const StoryDevFile* dev = find_dev_file(dev_files, file_name); - auto [checkpoint, autosave] = dev == nullptr + auto [checkpoint, execution] = dev == nullptr ? read_checkpoint_file(text, name) : read_dev_checkpoint(*dev, text, name); if (dev != nullptr){ data.dev_files.emplace_back(file_name, dev->path); } - if (autosave){ + if (execution.reload_when_chained){ + check_reload_when_chained(data, checkpoint, dev == nullptr ? file_name : dev->path); + data.reload_when_chained.insert(checkpoint.id); + } + if (execution.autosave){ data.autosaves.insert(checkpoint.id); } data.checkpoints.push_back(std::move(checkpoint)); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index 7cedfc5b3e..0933a809ed 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -40,6 +40,11 @@ namespace PokemonLZA{ struct StoryData{ std::vector checkpoints; std::set> autosaves; + // The ids of the rows a run reloads the save before when it played the + // row before them too ("execution": {"reload_when_chained": true}), so + // they start as from their save. Each comes after an autosave row, + // whose autosave is its start save. + std::set> reload_when_chained; // The dev files that replaced a built-in checkpoint, as (file name, // path). std::vector> dev_files; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index 0d412571d6..3ff4c4143d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -100,6 +100,60 @@ UnitTestResult test_autosave_rows(Logger&){ return true; } +// The built-in file of checkpoint `id` with its execution's save line +// replaced by `execution` (the fields after "execution": {), as a dev file. +StoryDevFile dev_with_execution(std::string_view id, std::string_view execution){ + for (const auto& [name, text] : autostory_checkpoint_json()){ + if (name != std::format("plza-{}.plan", id)){ + continue; + } + std::string edited = text; + const size_t at = edited.find("\"save\": \"autosave\""); + if (at != std::string::npos){ + edited.replace(at, std::string_view("\"save\": \"autosave\"").size(), execution); + } + return StoryDevFile{.name = std::format("{}.json", name), .path = std::format("dev/{}.json", name), .text = edited}; + } + return StoryDevFile{}; +} + +// The ParseException load_story_data() throws for `dev`; empty when it +// loads. +std::string load_problem(const StoryDevFile& dev){ + try{ + load_story_data(std::vector{dev}); + }catch (ParseException& e){ + return e.message(); + } + return ""; +} + +// "reload_when_chained" in a checkpoint's execution: only true, and only on +// a row with a save to reload after a row that ends on the autosave. +UnitTestResult test_reload_when_chained_field(Logger&){ + struct Case{ + std::string_view execution; + std::string_view problem; + }; + const Case cases[] = { + {R"("save": "autosave", "reload_when_chained": "yes")", "reload_when_chained"}, + {R"("save": "autosave", "reload_when_chained": false)", "true or left out"}, + {R"("save": "autosave", "reload_when_chained": true)", "no save to reload"}, + }; + for (const Case& item : cases){ + const std::string problem = load_problem(dev_with_execution("01.00", item.execution)); + if (problem.find(item.problem) == std::string::npos){ + return std::format("01.00 with {}: expected a problem with \"{}\", got \"{}\".", item.execution, item.problem, problem); + } + } + for (const StoryCheckpoint& row : story_checkpoints()){ + if (story_row_starts_without_save(row) && builtin_story_data().reload_when_chained.contains(row.id)){ + return std::format("{} starts without a save but reloads when chained.", row.id); + } + } + return true; +} + // A run can play every row: none names an action that is not implemented. UnitTestResult test_every_row_ready(Logger&){ const size_t ready = story_rows_ready(story_checkpoints()); @@ -253,6 +307,10 @@ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { .input = {"Story table: every row is ready", test_every_row_ready}, .expectation = {}, }, + { + .input = {"reload_when_chained: only true, only after an autosave row, never on a new game row", test_reload_when_chained_field}, + .expectation = {}, + }, { .input = {"Scene mash: what each frame presses", test_scene_mash_rule}, .expectation = {}, From e79ff9f1c2bc00ac28d2375a2cbf6fe0d3d37f97 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:13:35 -0800 Subject: [PATCH 19/33] PokemonLZA AutoStory: name reload_when_chained when it is not a boolean Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp | 5 +++-- .../Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp | 2 +- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp index adb197b0de..df48f17ab5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.cpp @@ -38,10 +38,11 @@ struct CheckpointExecution{ std::pair read_checkpoint_file(std::string_view text, std::string_view source){ CheckpointExecution read; const Pokemon::ExecutionReader read_execution = [&read](const JsonObject& execution, std::string_view where){ - read.reload_when_chained = execution.get_value("reload_when_chained") != nullptr; + const JsonValue* reload = execution.get_value("reload_when_chained"); + read.reload_when_chained = reload != nullptr; if (read.reload_when_chained){ Pokemon::validate_json_fields(execution, {"save", "reload_when_chained"}, where); - if (!execution.get_boolean_throw("reload_when_chained", std::string(where))){ + if (!reload->is_boolean() || !reload->to_boolean_default()){ throw ParseException(std::format("{}: reload_when_chained is true or left out", where)); } }else{ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index 3ff4c4143d..615b143fa5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -136,7 +136,7 @@ UnitTestResult test_reload_when_chained_field(Logger&){ std::string_view problem; }; const Case cases[] = { - {R"("save": "autosave", "reload_when_chained": "yes")", "reload_when_chained"}, + {R"("save": "autosave", "reload_when_chained": "yes")", "true or left out"}, {R"("save": "autosave", "reload_when_chained": false)", "true or left out"}, {R"("save": "autosave", "reload_when_chained": true)", "no save to reload"}, }; From 8bf006300804cef38f9616779b968d9db84d8bb7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:16:00 -0800 Subject: [PATCH 20/33] PokemonLZA AutoStory: a scene step fails when its scene never starts 02.02 run after the Brigitte battle (console B, 2026-11-13 12:09) walked past the street scene's trigger: its "scene" step saw only a fade and quiet frames, A-mashed for two minutes until something else ended in the overworld, "passed", and the next step failed with "A opened no dialogue". A scene step now needs a box, a choice or a battle within 45 s (SceneStart), and fails there with "the scene never started (player not at its trigger?)". mash_scene()'s other callers are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 46 +++++++++++++++++-- .../Actions/PokemonLZA_AutoStoryScenes.h | 7 +++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 3 +- .../PokemonLZA_AutoStoryScreenEvents.cpp | 5 ++ .../PokemonLZA_AutoStoryScreenEvents.h | 29 ++++++++++++ .../PokemonLZA_AutoStoryTable_Tests.cpp | 31 +++++++++++++ 6 files changed, 115 insertions(+), 6 deletions(-) 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 41da498647..dcc5d28a63 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -125,26 +125,47 @@ bool tutorial_card_shows(const ImageViewRGB32& frame){ return true; } -void mash_scene( +namespace{ + +// When a scene mash ends besides its goal: mash_scene()'s quiet end, and a +// start window (SceneStart). +struct SceneMashLimits{ + std::optional quiet = std::nullopt; + Milliseconds min_length = Milliseconds(0); + std::optional start_window = std::nullopt; +}; + +void mash_scene_until( ConsoleHandle& console, ProControllerContext& context, - SceneMashGoal goal, Button text_button, Milliseconds timeout, - std::optional quiet, Milliseconds min_length + SceneMashGoal goal, Button text_button, Milliseconds timeout, const SceneMashLimits& limits ){ PlzaScreenObserver observer; - OverworldEnd overworld(quiet, min_length); + OverworldEnd overworld(limits.quiet, limits.min_length); Pokemon::ScreenEvents last_events; const WallClock start = current_time(); + SceneStart scene(start, limits.start_window.value_or(timeout)); while (current_time() - start < timeout){ context.wait_for_all_requests(); const WallClock now = current_time(); const VideoSnapshot frame = console.video().snapshot(); if (frame && tutorial_card_shows(frame)){ console.log("mash_scene(): a tutorial card: A."); + scene.see(); pbf_press_button(context, BUTTON_A, 160ms, 840ms); continue; } const Pokemon::ScreenEvents events = observer.observe(frame, now); log_event_change(console, events, last_events); + if (limits.start_window && scene.never_started(events, now)){ + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + std::format( + "mash_scene(): the scene never started (player not at its trigger?): no box, choice or battle in {} ms.", + limits.start_window->count() + ), + console + ); + } const SceneMashAction action = scene_mash_action(events, goal, text_button == BUTTON_B); if (goal == SceneMashGoal::OVERWORLD){ if (overworld.reached(console, events, action, now)){ @@ -162,6 +183,23 @@ void mash_scene( ); } +} // namespace + +void mash_scene( + ConsoleHandle& console, ProControllerContext& context, + SceneMashGoal goal, Button text_button, Milliseconds timeout, + std::optional quiet, Milliseconds min_length +){ + mash_scene_until(console, context, goal, text_button, timeout, SceneMashLimits{.quiet = quiet, .min_length = min_length}); +} + +void mash_story_scene(ConsoleHandle& console, ProControllerContext& context, Button text_button){ + mash_scene_until( + console, context, SceneMashGoal::OVERWORLD, text_button, Milliseconds(120000), + SceneMashLimits{.start_window = SCENE_START_WINDOW} + ); +} + namespace{ 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 7adb477146..986731a22b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -44,6 +44,13 @@ void mash_scene( Milliseconds min_length = Milliseconds(0) ); +// A "scene" step: mash_scene() to the overworld with `text_button`, up to +// 120 s (a scene can hold a ~25 s black screen: 02.06's first evening), +// and the scene must start (SceneStart) within SCENE_START_WINDOW: a run +// not at the scene's trigger fails there, before an A mash talks to +// whoever stands in front. +void mash_story_scene(ConsoleHandle& console, ProControllerContext& context, Button text_button); + // A tutorial card on screen (Map & Missions, Main Missions, Pokedex, ...): // a bright panel in the middle over dark, even edges. diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index d28e4ae1b7..2b1340c62c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -392,10 +392,9 @@ Handler plza_handler(const PlzaHandlers& handlers, const StoryActionSpec& spec){ choose_dialog_option(env.env.console, env.context, Pokemon::story_arg(args, "yes") ? 0 : 1); }); case StoryStepKind::MASH:{ - // 120 s: a scene can hold a long black screen. const Button button = name == "a" ? BUTTON_A : BUTTON_B; return handlers.console(name, [button](StoryEnv& env, const StoryActionArgs&){ - mash_scene(env.env.console, env.context, SceneMashGoal::OVERWORLD, button, 120s); + mash_story_scene(env.env.console, env.context, button); }); } default: diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp index e63a819236..d1dadd902f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp @@ -31,6 +31,11 @@ const ImageFloatBox WHITE_BOX_EDGE{0.265, 0.931, 0.465, 0.020}; } // namespace +bool SceneStart::never_started(const ScreenEvents& events, WallClock now){ + m_seen |= events.any_of({ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX, ScreenEvent::BATTLE_STARTED}); + return !m_seen && now >= m_deadline; +} + SceneMashAction scene_mash_action(const ScreenEvents& events, SceneMashGoal goal, bool text_button_is_b){ switch (goal){ case SceneMashGoal::CHOICE: diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h index bd319f3437..fba8b5bb5f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h @@ -10,6 +10,7 @@ #ifndef PokemonAutomation_PokemonLZA_AutoStoryScreenEvents_H #define PokemonAutomation_PokemonLZA_AutoStoryScreenEvents_H +#include "Common/Cpp/Time.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Pokemon/AutoStory/Pokemon_ScreenEvents.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_ButtonDetector.h" @@ -83,6 +84,34 @@ enum class SceneMashAction{ // to whoever stands in front). SceneMashAction scene_mash_action(const Pokemon::ScreenEvents& events, SceneMashGoal goal, bool text_button_is_b); +// How long a scene step's mash waits for its scene to show. 02.02's street +// scene shows its first box ~10 s in from the save (console B, 2026-11-10); +// 02.06's first evening holds a ~25 s black screen first. +constexpr Milliseconds SCENE_START_WINDOW(45000); + +// Whether a scene mash's scene has started, from its frames: a box, a +// choice or a battle. A fade alone does not count: a walk's way into a new +// area fades too. A run that walked past a scene's trigger (02.02 after +// the Brigitte battle, console B, 2026-11-13) shows none of them, and its +// A mash pressed for 2 minutes before it ended somewhere else. +class SceneStart{ +public: + SceneStart(WallClock start, Milliseconds window) + : m_deadline(start + window) + {} + // Takes the scene as started (a tutorial card). + void see(){ + m_seen = true; + } + // Takes a frame's `events` at `now`; true once the window has passed + // without the scene. + bool never_started(const Pokemon::ScreenEvents& events, WallClock now); + +private: + WallClock m_deadline; + bool m_seen = false; +}; + // Registers the adapter's image tests (lab-B frames, 2026-11-08; they live // in CommandLineTests, PokemonLZA/AutoStoryScreenEvents/). void add_tests_AutoStoryScreenEvents(UnitTestDatabase& database); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index 615b143fa5..63d4ab592e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -164,6 +164,33 @@ UnitTestResult test_every_row_ready(Logger&){ } // scene_mash_action() on each kind of frame. +// A scene step's start window: a box, a choice or a battle within it +// starts the scene; fades and quiet frames alone (02.02's street missed +// after the Brigitte battle, console B, 2026-11-13) fail at its end, not +// before. +UnitTestResult test_scene_start_window(Logger&){ + using Pokemon::ScreenEvent; + using Pokemon::ScreenEvents; + const WallClock start = current_time(); + const auto at = [start](int64_t seconds){ + return start + Milliseconds(seconds * 1000); + }; + SceneStart missed(start, SCENE_START_WINDOW); + if (missed.never_started({ScreenEvent::FADE_BLACK}, at(10)) || missed.never_started({}, at(44))){ + return "Expected no failure inside the window."; + } + if (!missed.never_started({ScreenEvent::PLAYER_CAN_MOVE}, at(45))){ + return "Expected a scene with only a fade and quiet frames to fail at the window's end."; + } + for (const ScreenEvent event : {ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX, ScreenEvent::BATTLE_STARTED}){ + SceneStart started(start, SCENE_START_WINDOW); + if (started.never_started({event}, at(10)) || started.never_started({}, at(100))){ + return "Expected a box, a choice or a battle to start the scene."; + } + } + return true; +} + UnitTestResult test_scene_mash_rule(Logger&){ using Pokemon::ScreenEvent; using Pokemon::ScreenEvents; @@ -311,6 +338,10 @@ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { .input = {"reload_when_chained: only true, only after an autosave row, never on a new game row", test_reload_when_chained_field}, .expectation = {}, }, + { + .input = {"Scene mash: a scene that never starts fails at its start window", test_scene_start_window}, + .expectation = {}, + }, { .input = {"Scene mash: what each frame presses", test_scene_mash_rule}, .expectation = {}, From b6dd087af5e59a14728ab88f26145cfb6d80fb98 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 12:19:33 -0800 Subject: [PATCH 21/33] PokemonLZA AutoStory: walk_to_prompt walks straight on until an A prompt shows For 02.02's gate: the street scene ended at the gate's "A Leave" from the save (console B, 2026-11-10) but at the near end of the street after the Brigitte battle (2026-11-13). walk_to_prompt walks in 250 ms slices until the A prompt (INTERACT_PROMPT) shows, nothing if it shows already, and fails after its timeout (10 s) without one. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 44 +++++++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 30 +++++++++++++ 2 files changed, 74 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index aaf6fe9a81..5a5eb08625 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -386,6 +386,49 @@ UnitTestResult test_reload_lands_on_older_save(CancellableScope& scope){ } +// A walk_to_prompt step alone in a checkpoint. +StoryCheckpoint prompt_walk_row(){ + StoryCheckpoint row; + row.id = "02.02"; + row.steps.push_back(StoryStep{ + .kind = Pokemon::StoryStepKind::GAME, .name = "to_battle_zone_gate", .why = "test", .action = "walk_to_prompt", + .args = {{"timeout_ms", int64_t(1000)}}, + }); + return row; +} + +// walk_to_prompt: no walk when the A prompt shows already; slices of walk +// until it shows; a failure after its timeout without one. +UnitTestResult test_walk_to_prompt(CancellableScope& scope){ + const auto prompt = [](Milliseconds at){ + return look_at(at, {EngineEvent::INTERACT_PROMPT}); + }; + const std::string slice = "hold north 250ms walk"; + { + FakeBackend backend = fake_plza({prompt(0ms)}, scope); + if (run_plza(backend, prompt_walk_row()).verdict != Pokemon::CheckpointVerdict::PASSED || !backend.inputs().empty()){ + return std::format("At the prompt: expected no walk, got [{}].", joined(backend.inputs())); + } + } + { + FakeBackend backend = fake_plza({look_at(0ms), look_at(250ms), prompt(500ms)}, scope); + if (run_plza(backend, prompt_walk_row()).verdict != Pokemon::CheckpointVerdict::PASSED){ + return "Expected a pass once the prompt shows."; + } + UnitTestResult inputs = expect_inputs(backend, {slice, slice}); + if (inputs.result != UnitTestResult::PASSED){ + return inputs; + } + } + FakeBackend backend = fake_plza({look_at(0ms)}, scope); + const Pokemon::StoryEngineReport report = run_plza(backend, prompt_walk_row()); + if (report.verdict == Pokemon::CheckpointVerdict::PASSED || to_string(report.run.failure).find("no A prompt") == std::string::npos){ + return std::format("Expected no_prompt after the timeout: {}", to_string(report.run.failure)); + } + return expect_inputs(backend, std::vector(4, slice)); +} + + struct EngineTestInput{ std::string name; std::function body; @@ -429,6 +472,7 @@ const EngineTestCase ENGINE_TEST_CASES[] = { {.input = {"reload_when_chained: reload between the rows, as its own event", test_reload_when_chained}, .expectation = {}}, {.input = {"reload_when_chained: no reload from the row's save or for other rows", test_no_reload_unless_chained}, .expectation = {}}, {.input = {"reload_when_chained: a reload onto the platform fails", test_reload_lands_on_older_save}, .expectation = {}}, + {.input = {"walk_to_prompt: walks until the A prompt, none when it shows", test_walk_to_prompt}, .expectation = {}}, }; void add_tests_AutoStoryEngine(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 2b1340c62c..bd8c840dfe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -321,6 +321,28 @@ Outcome wait_for_platform(Pokemon::StoryBackend& backend, Milliseconds )); } +// One slice of walk_to_prompt()'s walk between looks. +constexpr Milliseconds PROMPT_WALK_SLICE(250); + +// "walk_to_prompt": straight on until an A prompt shows (INTERACT_PROMPT: +// "A Leave" at the Battle Zone's gate), a slice at a time, nothing if it +// shows already. Fails after `timeout` of walking without one. +Outcome walk_to_prompt(Pokemon::StoryBackend& backend, Milliseconds timeout){ + Milliseconds walked(0); + while (true){ + backend.scope().throw_if_cancelled(); + if (backend.observe().events.has(PokemonAutomation::ScreenEvent::INTERACT_PROMPT)){ + backend.log(std::format("[PLZA] walk_to_prompt: the A prompt shows after {} ms of walking", walked.count())); + return Pokemon::outcome_ok(); + } + if (walked >= timeout){ + return Pokemon::outcome_failed("no_prompt", std::format("walk_to_prompt: no A prompt in {} ms of walking", timeout.count())); + } + backend.hold(Pokemon::Direction::NORTH, PROMPT_WALK_SLICE, Pokemon::StoryPace::WALK); + walked += PROMPT_WALK_SLICE; + } +} + // The handler of "wait_for_platform" or "opening_to_platform". Handler platform_handler(PlatformWait wait){ return [wait](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ @@ -338,6 +360,11 @@ const std::map>& story_game_actions(){ {"text_to_choice", [](const PlzaHandlers&){ return PlzaHandlers::text_to_choice(); }}, {"wait_for_platform", [](const PlzaHandlers&){ return platform_handler(PlatformWait::PLATFORM_ONLY); }}, {"opening_to_platform", [](const PlzaHandlers&){ return platform_handler(PlatformWait::AFTER_AUTOSAVE); }}, + {"walk_to_prompt", [](const PlzaHandlers&){ + return Handler([](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ + return walk_to_prompt(backend, Milliseconds(Pokemon::story_arg(call.args, "timeout_ms"))); + }); + }}, }; return actions; } @@ -450,6 +477,9 @@ std::vector plza_story_action_specs(){ game_spec("wait_for_platform", { optional_ms("timeout_ms", 180000, "no platform this long fails the step"), }), + game_spec("walk_to_prompt", { + optional_ms("timeout_ms", 10000, "walking this long with no A prompt fails the step"), + }), game_spec("opening_to_platform", { optional_ms("timeout_ms", 240000, "no autosave and platform this long fails the step"), }), From 83edab24b692afbbc707c56bfac092dff994c84c Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 13:33:14 -0800 Subject: [PATCH 22/33] PLZA AutoStory: breakpoints before each step and walk leg The program sets StoryGame::breakpoints from the BREAKPOINTS option and pause_point to make_story_pause_hook(); PLZA's own timed walk (run_story_move, walk_until) pauses before each leg in LEGS mode. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryMoves.cpp | 20 ++++++++++-- .../Actions/PokemonLZA_AutoStoryMoves.h | 14 +++++++-- .../PokemonLZA_AutoStoryWalkScreenChecks.cpp | 5 +-- .../PokemonLZA_AutoStoryWalkScreenChecks.h | 4 +-- .../AutoStory/PokemonLZA_AutoStory.cpp | 12 ++++++- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 31 +++++++++++++++++++ .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 12 ++++--- 7 files changed, 84 insertions(+), 14 deletions(-) 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 5e4ab653b9..a021ac17f2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp @@ -51,14 +51,30 @@ Pokemon::Outcome face_heading(PlzaBackend& backend, const PlzaReader& reader, do return Pokemon::outcome_ok(); } -Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move, const PlzaReader& heading){ +std::string story_walk_leg_label(size_t index, size_t count, const StoryWalkLeg& leg){ + std::string label = std::format("leg {}/{} turn {:g}", index + 1, count, leg.turn); + if (leg.walk > Milliseconds(0)){ + label += std::format(" walk {} ms", leg.walk.count()); + } + return label; +} + +Pokemon::Outcome run_story_move( + PlzaBackend& backend, const StoryMove& move, const PlzaReader& heading, + Pokemon::StoryPausePoints* pause +){ if (move.heading){ const Pokemon::Outcome faced = face_heading(backend, heading, *move.heading, 10.0); if (!faced.succeeded()){ return faced; } } - for (const StoryWalkLeg& leg : move.legs){ + for (size_t index = 0; index < move.legs.size(); index++){ + const StoryWalkLeg& leg = move.legs[index]; + if (pause != nullptr){ + pause->before_leg(story_walk_leg_label(index, move.legs.size(), leg)); + backend.scope().throw_if_cancelled(); + } if (leg.turn != 0){ // The walk goes where the camera looks: recenter it after the turn. story_turn(backend, leg.turn); 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 ca2cc313f3..8df5494f5c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.h @@ -12,12 +12,14 @@ #define PokemonAutomation_PokemonLZA_AutoStoryMoves_H #include +#include #include #include "Common/Cpp/Time.h" #include "CommonFramework/Language.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" #include "Pokemon/AutoStory/Pokemon_StoryOutcome.h" +#include "Pokemon/AutoStory/Types/Pokemon_StoryBreakpoints.h" #include "VideoGames/PokemonLZA/Resources/PokemonLZA_Locations.h" #include "VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h" @@ -61,8 +63,16 @@ Pokemon::Outcome face_heading(PlzaBackend& backend, const PlzaReader& reader, do // walk goes where it looks) and walk. Nothing is read on the way: a leg // that is cut short or blocked goes unnoticed, and a step that needs a // prompt after the walk fails there instead. `heading` reads the compass -// (face_heading()). -Pokemon::Outcome run_story_move(PlzaBackend& backend, const StoryMove& move, const PlzaReader& heading); +// (face_heading()). `pause`, if given, is the run's pause points: each leg +// is a breakpoint (StoryPausePoints::before_leg(), story_walk_leg_label()). +Pokemon::Outcome run_story_move( + PlzaBackend& backend, const StoryMove& move, const PlzaReader& heading, + Pokemon::StoryPausePoints* pause = nullptr +); + +// "leg 2/5 turn 90 walk 1200 ms": leg `index` (from 0) of `count`, as a +// breakpoint's label. A leg with no walk leaves it out. +std::string story_walk_leg_label(size_t index, size_t count, const StoryWalkLeg& leg); // From the overworld, opens the map and fast travels to `location` // (open_map_and_fly_to()). Returns in the overworld there; throws 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 c5e617d2f7..85d71666c6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -73,7 +73,8 @@ Pokemon::Outcome check_can_walk(PlzaBackend& backend, std::string_view walk){ } Pokemon::Outcome walk_until( - PlzaBackend& backend, std::string_view walk, const StoryMove& move, const PlzaReader& heading, EngineEvent end + PlzaBackend& backend, std::string_view walk, const StoryMove& move, const PlzaReader& heading, EngineEvent end, + Pokemon::StoryPausePoints* pause ){ StoryMove head = move; Milliseconds hold = 0ms; @@ -81,7 +82,7 @@ Pokemon::Outcome walk_until( hold = head.legs.back().walk; head.legs.back().walk = 0ms; } - const Pokemon::Outcome walked = run_story_move(backend, head, heading); + const Pokemon::Outcome walked = run_story_move(backend, head, heading, pause); if (!walked.succeeded()){ return walked; } 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 b8f8588252..9f70248ae8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.h @@ -32,10 +32,10 @@ Pokemon::Outcome check_can_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), the leg's time as the upper bound. Fails as // "walk_no_end" if `end` does not show within it. `heading` reads the -// compass (face_heading()). +// compass (face_heading()); `pause` is as for run_story_move(). Pokemon::Outcome walk_until( PlzaBackend& backend, std::string_view walk, const StoryMove& move, const PlzaReader& heading, - PokemonAutomation::ScreenEvent end + PokemonAutomation::ScreenEvent end, Pokemon::StoryPausePoints* pause = nullptr ); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 426d063a9f..c1a457010f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -154,6 +154,16 @@ void connect_controller(ConsoleHandle& console, ProControllerContext& context, c require_player(console, context, BUTTON_L); } +// PLZA's game for a run on `story`, pausing at `breakpoints` (the +// BREAKPOINTS option): before each step, or each leg too, where a lab build +// waits for the user (Pokemon_StoryBreakpoints.h). +StoryGame run_game(StoryEnv& story, const StoryData& data, StoryBreakpoints breakpoints, CancellableScope& scope){ + StoryGame game = make_plza_story_game(story, data.autosaves); + game.breakpoints = breakpoints; + game.pause_point = make_story_pause_hook(scope); + return game; +} + } // namespace NewGameChoices AutoStory::new_game_choices(ConsoleHandle& console, bool check) const{ @@ -190,7 +200,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex .language = RUN.language(), .battle_ai = BATTLE_AI }; PlzaConsoleBackend backend(story); - const StoryGame game = make_plza_story_game(story, story_data.autosaves); + const StoryGame game = run_game(story, story_data, RUN.breakpoints(), context); StoryEngine engine(game, backend); RunState state; load_start_save(env.console, game, backend, rows, first); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index 5a5eb08625..8f25a093ba 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -429,6 +429,36 @@ UnitTestResult test_walk_to_prompt(CancellableScope& scope){ } +// Breakpoints on legs: the walk pauses before each of its legs, after the +// step's own pause, each labelled with the leg's turn and walk. +UnitTestResult test_walk_pauses_before_each_leg(CancellableScope& scope){ + std::vector pauses; + Pokemon::StoryGame game = make_offline_plza_story_game(); + game.breakpoints = Pokemon::StoryBreakpoints::LEGS; + game.pause_point = [&pauses](std::string_view label){ + pauses.emplace_back(label); + }; + const std::vector legs{{.turn = 0, .ms = 500}, {.turn = 90, .ms = 0}}; + StoryCheckpoint row; + row.id = "01.01"; + row.steps.push_back(StoryStep{.kind = Pokemon::StoryStepKind::GAME, .name = "chase", .why = "test", .action = "walk"}); + row.steps.back().args["legs"] = legs; + FakeBackend backend = fake_plza({look_at(0ms)}, scope); + Pokemon::StoryEngine engine(game, backend); + Pokemon::RunState state; + if (engine.run_checkpoint(row, Pokemon::SavePoint::RUN_END, state).verdict != Pokemon::CheckpointVerdict::PASSED){ + return std::format("Expected the walk to pass: {}", joined(backend.lines())); + } + const std::vector expected{ + "01.01/1 chase", "01.01/1 chase leg 1/2 turn 0 walk 500 ms", "01.01/1 chase leg 2/2 turn 90", + }; + if (pauses != expected){ + return std::format("Expected pauses [{}], got [{}].", joined(expected), joined(pauses)); + } + return true; +} + + struct EngineTestInput{ std::string name; std::function body; @@ -473,6 +503,7 @@ const EngineTestCase ENGINE_TEST_CASES[] = { {.input = {"reload_when_chained: no reload from the row's save or for other rows", test_no_reload_unless_chained}, .expectation = {}}, {.input = {"reload_when_chained: a reload onto the platform fails", test_reload_lands_on_older_save}, .expectation = {}}, {.input = {"walk_to_prompt: walks until the A prompt, none when it shows", test_walk_to_prompt}, .expectation = {}}, + {.input = {"breakpoints: a walk pauses before each leg", test_walk_pauses_before_each_leg}, .expectation = {}}, }; void add_tests_AutoStoryEngine(UnitTestDatabase& database){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index bd8c840dfe..9baaac2a47 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -169,7 +169,7 @@ class PlzaHandlers{ // until its end event if it has one. Handler walk() const{ return [heading = m_heading](Pokemon::StoryBackend& backend, const StoryActionCall& call, Pokemon::RunState&){ - return walk_legs(backend, call.step.name, story_walk_move(call.args, "legs"), call.args, heading); + return walk_legs(backend, call, story_walk_move(call.args, "legs"), heading); }; } @@ -216,11 +216,13 @@ class PlzaHandlers{ private: // `move`, once the screen shows free control; held until the fade of - // `args`' "end", if it names one. + // `call`'s "end" arg, if it names one. Each leg is a breakpoint. static Outcome walk_legs( - Pokemon::StoryBackend& backend, std::string_view name, const StoryMove& move, - const StoryActionArgs& args, const PlzaReader& heading + Pokemon::StoryBackend& backend, const StoryActionCall& call, const StoryMove& move, + const PlzaReader& heading ){ + const std::string_view name = call.step.name; + const StoryActionArgs& args = call.args; const Outcome free = check_can_walk(backend, name); if (!free.succeeded()){ return free; @@ -230,7 +232,7 @@ class PlzaHandlers{ if (end != args.end()){ fade = walk_end_event(std::get(end->second)); } - return fade ? walk_until(backend, name, move, heading, *fade) : run_story_move(backend, move, heading); + return fade ? walk_until(backend, name, move, heading, *fade, &call.pause) : run_story_move(backend, move, heading, &call.pause); } StoryEnv* m_env; From 8ebd5b09db60916b35a6283b876306b03e6ca6d5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 14:16:24 -0800 Subject: [PATCH 23/33] PLZA AutoStory: Reload at Checkpoint Boundaries option, off by default A chained run reloaded the autosave before every checkpoint whose plan says "reload_when_chained" (about 30 s each, and extra game resets). Now that checkpoints split at the game's autosave points, running straight on is the same state. The new panel option (RELOAD_AT_BOUNDARIES, off) runs straight through; on, the plan flag reloads as before. A failed checkpoint's retry reloads either way. The run logs which mode it uses. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonLZA_AutoStory.cpp | 17 +++++++++++- .../Programs/AutoStory/PokemonLZA_AutoStory.h | 3 +++ .../PokemonLZA_AutoStoryEngine_Tests.cpp | 27 +++++++++++++++---- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 10 +++++-- .../AutoStory/PokemonLZA_AutoStoryGame.h | 14 ++++++++-- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index c1a457010f..720d661bb0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -72,6 +72,12 @@ const StringSelectDatabase& checkpoint_database(){ AutoStory::AutoStory() : RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) + , RELOAD_AT_BOUNDARIES( + "Reload at Checkpoint Boundaries:
Reload the save before a checkpoint whose plan asks for it " + "when the run comes from the checkpoint before. Off: run straight on. A failed checkpoint's retry reloads either way.", + LockMode::LOCK_WHILE_RUNNING, + false + ) , PLAYER_NAME( false, "Player Name:
New game only. Letters and digits; a capital only as the first letter.", @@ -98,6 +104,7 @@ AutoStory::AutoStory() { PA_ADD_OPTION(RUN); PA_ADD_OPTION(BATTLE_AI); + PA_ADD_OPTION(RELOAD_AT_BOUNDARIES); PA_ADD_OPTION(PLAYER_NAME); PA_ADD_OPTION(PLAYER_LOOK); PA_ADD_OPTION(NAME_FIRST_LETTER_AUTO_CAPS); @@ -220,7 +227,15 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex return; } const std::vector checkpoints = story_run_rows(rows, first, last); - const SegmentReport report = run_plza_segment(game, story_data, checkpoints, RUN.policy().attempts_per_checkpoint, engine, backend, state); + const BoundaryReload boundary_reload = RELOAD_AT_BOUNDARIES ? BoundaryReload::AT_PLAN_BOUNDARIES : BoundaryReload::STRAIGHT_THROUGH; + env.console.log( + boundary_reload == BoundaryReload::AT_PLAN_BOUNDARIES + ? "AutoStory: reloads the save at checkpoint boundaries whose plan asks for it." + : "AutoStory: runs straight through checkpoint boundaries, no reload." + ); + const SegmentReport report = run_plza_segment( + game, story_data, checkpoints, RUN.policy().attempts_per_checkpoint, boundary_reload, engine, backend, state + ); record_story_counts(report.story_counts(), env.current_stats()); env.update_stats(); if (!report.completed){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index 59493e852d..625c9dedc6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -63,6 +63,9 @@ class AutoStory : public SingleSwitchProgramInstance{ // The start and end checkpoints, attempts, checks and language. Pokemon::StoryRunOptions RUN; BattleAIOption BATTLE_AI; + // Off: a run of several checkpoints runs straight on at the rows whose + // plans say "reload_when_chained"; on: it reloads the save there. + BooleanCheckBoxOption RELOAD_AT_BOUNDARIES; // The new game's choices (00.00): the language is RUN's. The look and // the language list's order are guesses from Scarlet/Violet's screens. StringOption PLAYER_NAME; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index 8f25a093ba..bf0f3d2b93 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -298,10 +298,13 @@ struct BoundaryRun{ size_t reloads = 0; }; -// `ids` through run_plza_segment() over looks with the platform on -// `platform` (by look index; the last look repeats); the game's reload -// counts itself. -BoundaryRun run_boundary(std::vector ids, std::vector platform, CancellableScope& scope){ +// `ids` through run_plza_segment() with `boundary_reload` over looks with +// the platform on `platform` (by look index; the last look repeats); the +// game's reload counts itself. +BoundaryRun run_boundary( + std::vector ids, std::vector platform, CancellableScope& scope, + BoundaryReload boundary_reload = BoundaryReload::AT_PLAN_BOUNDARIES +){ std::vector> looks; for (size_t i = 0; i < platform.size(); i++){ const Observation look = look_at(Milliseconds(300 * (int64_t)i)); @@ -323,7 +326,7 @@ BoundaryRun run_boundary(std::vector ids, std::vector platfor } Pokemon::StoryEngine engine(game, backend); Pokemon::RunState state; - run.report = run_plza_segment(game, story, rows, 1, engine, backend, state); + run.report = run_plza_segment(game, story, rows, 1, boundary_reload, engine, backend, state); run.lines = backend.lines(); return run; } @@ -369,6 +372,19 @@ UnitTestResult test_no_reload_unless_chained(CancellableScope& scope){ return true; } +// Run straight through, B runs on after A with no reload, though it is in +// reload_when_chained; both rows run in one segment. +UnitTestResult test_straight_through_has_no_reload(CancellableScope& scope){ + const BoundaryRun run = run_boundary({"A", "B", "C"}, {true}, scope, BoundaryReload::STRAIGHT_THROUGH); + if (!run.report.completed || run.reloads != 0 || line_index(run.lines, "reload_at_boundary") != run.lines.size()){ + return std::format("Expected A, B and C with no reload, got {} reloads: {}", run.reloads, joined(run.lines)); + } + if (run.report.runs.size() != 3 || run.report.checkpoints_run != 3){ + return std::format("Expected all three rows in one report, got {} runs.", run.report.runs.size()); + } + return true; +} + // A reload that lands on the station platform loaded an older save: the // run fails at the boundary, before any step of B. UnitTestResult test_reload_lands_on_older_save(CancellableScope& scope){ @@ -502,6 +518,7 @@ const EngineTestCase ENGINE_TEST_CASES[] = { {.input = {"reload_when_chained: reload between the rows, as its own event", test_reload_when_chained}, .expectation = {}}, {.input = {"reload_when_chained: no reload from the row's save or for other rows", test_no_reload_unless_chained}, .expectation = {}}, {.input = {"reload_when_chained: a reload onto the platform fails", test_reload_lands_on_older_save}, .expectation = {}}, + {.input = {"reload_when_chained: straight through, no reload at a boundary", test_straight_through_has_no_reload}, .expectation = {}}, {.input = {"walk_to_prompt: walks until the A prompt, none when it shows", test_walk_to_prompt}, .expectation = {}}, {.input = {"breakpoints: a walk pauses before each leg", test_walk_pauses_before_each_leg}, .expectation = {}}, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 9baaac2a47..85034fb5cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -595,6 +595,12 @@ Outcome reload_at_boundary(const Pokemon::StoryGame& game, Pokemon::St return Pokemon::outcome_ok(); } +// Whether a run reloads the save before `row` when it reaches it from the +// row before. +bool reloads_before(const StoryData& story, BoundaryReload boundary_reload, std::string_view row){ + return boundary_reload == BoundaryReload::AT_PLAN_BOUNDARIES && story.reload_when_chained.contains(row); +} + void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& total){ total.checkpoints_run += part.checkpoints_run; total.reloads += part.reloads; @@ -608,14 +614,14 @@ void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& tot Pokemon::SegmentReport run_plza_segment( const Pokemon::StoryGame& game, const StoryData& story, - std::span rows, size_t attempts_per_checkpoint, + std::span rows, size_t attempts_per_checkpoint, BoundaryReload boundary_reload, Pokemon::StoryEngine& engine, Pokemon::StoryBackend& backend, Pokemon::RunState& state ){ Pokemon::SegmentReport total; size_t begin = 0; while (begin < rows.size()){ size_t end = begin + 1; - while (end < rows.size() && !story.reload_when_chained.contains(rows[end].id)){ + while (end < rows.size() && !reloads_before(story, boundary_reload, rows[end].id)){ end++; } if (begin > 0){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 0c2c389fa9..2f8acea6db 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -101,8 +101,18 @@ Pokemon::StoryGame make_plza_story_game( // carry, and there is no save or reload. Pokemon::StoryGame make_offline_plza_story_game(); +// Whether a run of several checkpoints reloads the save at a row of +// StoryData::reload_when_chained (AT_PLAN_BOUNDARIES) or runs on from the +// state the row before left (STRAIGHT_THROUGH). A failed checkpoint's +// retries reload as usual either way. +enum class BoundaryReload{ + AT_PLAN_BOUNDARIES, + STRAIGHT_THROUGH, +}; + // `rows` in order from the save the game is on, as -// StoryEngine::run_segment() runs them, but a row of `story`'s +// StoryEngine::run_segment() runs them. With +// BoundaryReload::AT_PLAN_BOUNDARIES, a row of `story`'s // reload_when_chained after the run's first starts as from its save: the // run's segment stops before it, the event "reload_at_boundary" reloads // the save (`game`'s reload, the autosave the row before ended on) and @@ -111,7 +121,7 @@ Pokemon::StoryGame make_offline_plza_story_game(); // before such a row ends its segment, so it ends at SavePoint::RUN_END. Pokemon::SegmentReport run_plza_segment( const Pokemon::StoryGame& game, const StoryData& story, - std::span rows, size_t attempts_per_checkpoint, + std::span rows, size_t attempts_per_checkpoint, BoundaryReload boundary_reload, Pokemon::StoryEngine& engine, Pokemon::StoryBackend& backend, Pokemon::RunState& state ); From 368c6190e42a8cf3942e51090bed0c78de9658f0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 14:19:16 -0800 Subject: [PATCH 24/33] PLZA AutoStory: run_plza_segment takes a StoryRunPolicy The attempts per checkpoint and the boundary reload travel together, and program() logs the mode through run_policy(): keeps both under the code health limits. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../AutoStory/PokemonLZA_AutoStory.cpp | 25 ++++++++++++------- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 6 ++--- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 10 ++++---- .../AutoStory/PokemonLZA_AutoStoryGame.h | 15 +++-------- .../AutoStory/PokemonLZA_AutoStoryTable.h | 15 +++++++++++ 5 files changed, 42 insertions(+), 29 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 720d661bb0..cbe126b3c2 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -192,6 +192,21 @@ void AutoStory::start_program_border_check(VideoStream& stream, FeedbackType fee SingleSwitchProgramInstance::start_program_border_check(stream, feedback_type); } +namespace{ + +// `run`'s attempts per checkpoint, and the boundary reload `reload_at_boundaries` +// picks; logs which. +StoryRunPolicy run_policy(const Pokemon::StoryRunOptions& run, const BooleanCheckBoxOption& reload_at_boundaries, Logger& logger){ + if (reload_at_boundaries){ + logger.log("AutoStory: reloads the save at checkpoint boundaries whose plan asks for it."); + return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES}; + } + logger.log("AutoStory: runs straight through checkpoint boundaries, no reload."); + return {.attempts_per_checkpoint = run.policy().attempts_per_checkpoint, .boundary_reload = StoryRunPolicy::BoundaryReload::STRAIGHT_THROUGH}; +} + +} // namespace + void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ const StoryData story_data = load_run_story(env.console); const std::vector& rows = story_data.checkpoints; @@ -227,15 +242,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex return; } const std::vector checkpoints = story_run_rows(rows, first, last); - const BoundaryReload boundary_reload = RELOAD_AT_BOUNDARIES ? BoundaryReload::AT_PLAN_BOUNDARIES : BoundaryReload::STRAIGHT_THROUGH; - env.console.log( - boundary_reload == BoundaryReload::AT_PLAN_BOUNDARIES - ? "AutoStory: reloads the save at checkpoint boundaries whose plan asks for it." - : "AutoStory: runs straight through checkpoint boundaries, no reload." - ); - const SegmentReport report = run_plza_segment( - game, story_data, checkpoints, RUN.policy().attempts_per_checkpoint, boundary_reload, engine, backend, state - ); + const SegmentReport report = run_plza_segment(game, story_data, checkpoints, run_policy(RUN, RELOAD_AT_BOUNDARIES, env.console), engine, backend, state); record_story_counts(report.story_counts(), env.current_stats()); env.update_stats(); if (!report.completed){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index bf0f3d2b93..80ac99cd10 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -303,7 +303,7 @@ struct BoundaryRun{ // game's reload counts itself. BoundaryRun run_boundary( std::vector ids, std::vector platform, CancellableScope& scope, - BoundaryReload boundary_reload = BoundaryReload::AT_PLAN_BOUNDARIES + StoryRunPolicy::BoundaryReload boundary_reload = StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES ){ std::vector> looks; for (size_t i = 0; i < platform.size(); i++){ @@ -326,7 +326,7 @@ BoundaryRun run_boundary( } Pokemon::StoryEngine engine(game, backend); Pokemon::RunState state; - run.report = run_plza_segment(game, story, rows, 1, boundary_reload, engine, backend, state); + run.report = run_plza_segment(game, story, rows, {.boundary_reload = boundary_reload}, engine, backend, state); run.lines = backend.lines(); return run; } @@ -375,7 +375,7 @@ UnitTestResult test_no_reload_unless_chained(CancellableScope& scope){ // Run straight through, B runs on after A with no reload, though it is in // reload_when_chained; both rows run in one segment. UnitTestResult test_straight_through_has_no_reload(CancellableScope& scope){ - const BoundaryRun run = run_boundary({"A", "B", "C"}, {true}, scope, BoundaryReload::STRAIGHT_THROUGH); + const BoundaryRun run = run_boundary({"A", "B", "C"}, {true}, scope, StoryRunPolicy::BoundaryReload::STRAIGHT_THROUGH); if (!run.report.completed || run.reloads != 0 || line_index(run.lines, "reload_at_boundary") != run.lines.size()){ return std::format("Expected A, B and C with no reload, got {} reloads: {}", run.reloads, joined(run.lines)); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 85034fb5cb..5cab90c8d9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -597,8 +597,8 @@ Outcome reload_at_boundary(const Pokemon::StoryGame& game, Pokemon::St // Whether a run reloads the save before `row` when it reaches it from the // row before. -bool reloads_before(const StoryData& story, BoundaryReload boundary_reload, std::string_view row){ - return boundary_reload == BoundaryReload::AT_PLAN_BOUNDARIES && story.reload_when_chained.contains(row); +bool reloads_before(const StoryData& story, StoryRunPolicy::BoundaryReload boundary_reload, std::string_view row){ + return boundary_reload == StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES && story.reload_when_chained.contains(row); } void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& total){ @@ -614,14 +614,14 @@ void add_segment(const Pokemon::SegmentReport& part, Pokemon::SegmentReport& tot Pokemon::SegmentReport run_plza_segment( const Pokemon::StoryGame& game, const StoryData& story, - std::span rows, size_t attempts_per_checkpoint, BoundaryReload boundary_reload, + std::span rows, const StoryRunPolicy& policy, Pokemon::StoryEngine& engine, Pokemon::StoryBackend& backend, Pokemon::RunState& state ){ Pokemon::SegmentReport total; size_t begin = 0; while (begin < rows.size()){ size_t end = begin + 1; - while (end < rows.size() && !reloads_before(story, boundary_reload, rows[end].id)){ + while (end < rows.size() && !reloads_before(story, policy.boundary_reload, rows[end].id)){ end++; } if (begin > 0){ @@ -638,7 +638,7 @@ Pokemon::SegmentReport run_plza_segment( backend.log(std::format("[Event] {}/0 reload_at_boundary: done", id)); state = Pokemon::RunState{}; } - const Pokemon::SegmentReport part = engine.run_segment("plza", rows.subspan(begin, end - begin), attempts_per_checkpoint, state); + const Pokemon::SegmentReport part = engine.run_segment("plza", rows.subspan(begin, end - begin), policy.attempts_per_checkpoint, 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 2f8acea6db..2a8d23fb2c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -101,18 +101,9 @@ Pokemon::StoryGame make_plza_story_game( // carry, and there is no save or reload. Pokemon::StoryGame make_offline_plza_story_game(); -// Whether a run of several checkpoints reloads the save at a row of -// StoryData::reload_when_chained (AT_PLAN_BOUNDARIES) or runs on from the -// state the row before left (STRAIGHT_THROUGH). A failed checkpoint's -// retries reload as usual either way. -enum class BoundaryReload{ - AT_PLAN_BOUNDARIES, - STRAIGHT_THROUGH, -}; - // `rows` in order from the save the game is on, as -// StoryEngine::run_segment() runs them. With -// BoundaryReload::AT_PLAN_BOUNDARIES, a row of `story`'s +// StoryEngine::run_segment() runs them, `policy`'s attempts per checkpoint. +// With StoryRunPolicy::BoundaryReload::AT_PLAN_BOUNDARIES, a row of `story`'s // reload_when_chained after the run's first starts as from its save: the // run's segment stops before it, the event "reload_at_boundary" reloads // the save (`game`'s reload, the autosave the row before ended on) and @@ -121,7 +112,7 @@ enum class BoundaryReload{ // before such a row ends its segment, so it ends at SavePoint::RUN_END. Pokemon::SegmentReport run_plza_segment( const Pokemon::StoryGame& game, const StoryData& story, - std::span rows, size_t attempts_per_checkpoint, BoundaryReload boundary_reload, + std::span rows, const StoryRunPolicy& policy, Pokemon::StoryEngine& engine, Pokemon::StoryBackend& backend, Pokemon::RunState& state ); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index 0933a809ed..72c478529c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -50,6 +50,21 @@ struct StoryData{ std::vector> dev_files; }; +// How a run plays its checkpoints: the attempts each gets, and whether it +// reloads at the plan's boundaries. +struct StoryRunPolicy{ + // Whether a run of several checkpoints reloads the save at a row of + // StoryData::reload_when_chained (AT_PLAN_BOUNDARIES) or runs on from + // the state the row before left (STRAIGHT_THROUGH). A failed + // checkpoint's retries reload as usual either way. + enum class BoundaryReload{ + AT_PLAN_BOUNDARIES, + STRAIGHT_THROUGH, + }; + size_t attempts_per_checkpoint = 1; + BoundaryReload boundary_reload = BoundaryReload::AT_PLAN_BOUNDARIES; +}; + // Whether `row` of `story` saves through the menu at its end: every row // but the autosave rows. The menu (X, then R) can save from the start of // the story too: 01.03 saves through it after Andi (console B, 2026-11-10). From 343a9661ed2070112d2323ffdf2a004b9caefa97 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 14:28:00 -0800 Subject: [PATCH 25/33] PLZA AutoStory: send the story log lines to the video overlay PlzaConsoleBackend::log() wrote only to the console log, so the overlay showed nothing. The engine's [Checkpoint], [Event], [Step] and [Save] lines all go through it, so it now adds each to the overlay too, as FRLG does with its status hook. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp index 1889706437..0d6309cfc6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp @@ -12,6 +12,7 @@ #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/Color.h" +#include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "Pokemon/AutoStory/Engine/Pokemon_ScreenObservation.h" #include "VideoGames/PokemonLZA/Programs/PokemonLZA_BasicNavigation.h" @@ -157,6 +158,9 @@ Pokemon::Outcome PlzaConsoleBackend::battle(const Pokemon::StoryActionArgs&){ void PlzaConsoleBackend::log(std::string_view line){ m_env.env.console.log(std::string(line), COLOR_BLUE); + // The checkpoint, the step under way and the autosaves, for whoever + // watches the stream: the engine's lines all come through here. + m_env.env.console.overlay().add_log(std::string(line)); } CancellableScope& PlzaConsoleBackend::scope(){ From 0706b4b78f0f2ce746735002945a4d5f810111a3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 16:08:29 -0800 Subject: [PATCH 26/33] Use the shared ScreenEvent names after merging autostory/engine PLZA AutoStory: TEXT_BOX -> DIALOG_BOX, BATTLE -> BATTLE_STARTED, CAN_MOVE -> PLAYER_CAN_MOVE, STILL -> SCREEN_STILL, and the observer's Pokemon:: screen event types are now PokemonAutomation's. A capture's file name takes the shared event names with underscores (black_fade+screen_still), from describe(events, "+"). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 20 +++++++++---------- .../PokemonLZA_AutoStoryWalkScreenChecks.cpp | 4 ++-- .../AutoStory/PokemonLZA_AutoStoryBackend.cpp | 9 ++++++--- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 2 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 2 +- .../PokemonLZA_AutoStorySceneMachine.cpp | 20 +++++++++---------- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 6 ++---- .../PokemonLZA_AutoStoryScreenEvents.cpp | 7 +++---- .../PokemonLZA_AutoStoryScreenEvents.h | 12 +++++------ ...PokemonLZA_AutoStoryScreenEvents_Tests.cpp | 2 -- .../PokemonLZA_AutoStoryTable_Tests.cpp | 4 ---- 11 files changed, 41 insertions(+), 47 deletions(-) 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 dcc5d28a63..440cf068f8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -42,11 +42,11 @@ class OverworldEnd{ , m_quiet_from(current_time() + min_length) , m_last_busy(current_time()) {} - bool reached(ConsoleHandle& console, const Pokemon::ScreenEvents& events, SceneMashAction action, WallClock now){ + bool reached(ConsoleHandle& console, const ScreenEvents& events, SceneMashAction action, WallClock now){ if (events.any_of({ - Pokemon::ScreenEvent::DIALOG_BOX, Pokemon::ScreenEvent::CHOICE_BOX, - Pokemon::ScreenEvent::BATTLE_STARTED, Pokemon::ScreenEvent::FADE_BLACK, - Pokemon::ScreenEvent::FADE_WHITE, + ScreenEvent::DIALOG_BOX, ScreenEvent::CHOICE_BOX, + ScreenEvent::BATTLE_STARTED, ScreenEvent::FADE_BLACK, + ScreenEvent::FADE_WHITE, })){ m_last_busy = now; } @@ -92,14 +92,14 @@ void press_for(ProControllerContext& context, SceneMashAction action, Button tex // Logs the frame's events whenever they change (the still-screen flag left // out), so a run's log shows each scene's fades, boxes and party bar. -void log_event_change(ConsoleHandle& console, const Pokemon::ScreenEvents& events, Pokemon::ScreenEvents& last){ - Pokemon::ScreenEvents shown = events; - shown.set(Pokemon::ScreenEvent::SCREEN_STILL, false); +void log_event_change(ConsoleHandle& console, const ScreenEvents& events, ScreenEvents& last){ + ScreenEvents shown = events; + shown.set(ScreenEvent::SCREEN_STILL, false); if (shown == last){ return; } last = shown; - console.log(std::format("mash_scene(): screen now: {}", Pokemon::describe(shown))); + console.log(std::format("mash_scene(): screen now: {}", describe(shown))); } } // namespace @@ -141,7 +141,7 @@ void mash_scene_until( ){ PlzaScreenObserver observer; OverworldEnd overworld(limits.quiet, limits.min_length); - Pokemon::ScreenEvents last_events; + ScreenEvents last_events; const WallClock start = current_time(); SceneStart scene(start, limits.start_window.value_or(timeout)); while (current_time() - start < timeout){ @@ -154,7 +154,7 @@ void mash_scene_until( pbf_press_button(context, BUTTON_A, 160ms, 840ms); continue; } - const Pokemon::ScreenEvents events = observer.observe(frame, now); + const ScreenEvents events = observer.observe(frame, now); log_event_change(console, events, last_events); if (limits.start_window && scene.never_started(events, now)){ OperationFailedExceptionWithScreenshot::fire( 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 85d71666c6..bf02b3c21e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -36,10 +36,10 @@ std::string not_free_control(const ScreenObservation& look){ if (look.events.has(EngineEvent::CHOICE_BOX)){ return "a choice"; } - if (look.events.has(EngineEvent::TEXT_BOX)){ + if (look.events.has(EngineEvent::DIALOG_BOX)){ return "a text box"; } - if (look.events.has(EngineEvent::BATTLE)){ + if (look.events.has(EngineEvent::BATTLE_STARTED)){ return "a battle"; } if (look.events.has(EngineEvent::FADE_BLACK) || look.events.has(EngineEvent::FADE_WHITE)){ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp index 0d6309cfc6..bbcb6d1760 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -79,7 +80,7 @@ Pokemon::Observation PlzaConsoleBackend::observe(){ look.readings[std::string(MISSION_BANNER_READING)] = 1; } if (same_screen(m_previous, frame)){ - look.events.add(PokemonAutomation::ScreenEvent::STILL); + look.events.set(PokemonAutomation::ScreenEvent::SCREEN_STILL, true); } } look.when = current_time(); @@ -91,10 +92,12 @@ Pokemon::Observation PlzaConsoleBackend::observe(){ namespace{ -// The look's events and readings: "fade_black+still", -// "nothing+skip_prompt", "can_move+platform+autosave+controls_hint". +// The look's events and readings, for a capture's file name: +// "black_fade+screen_still", "nothing+skip_prompt", +// "player_can_move+platform+autosave+controls_hint". std::string look_text(const ScreenObservation& look){ std::string text = describe(look.events, "+"); + std::replace(text.begin(), text.end(), ' ', '_'); if (look.readings.contains(PLATFORM_READING)){ text += "+platform"; } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index 80ac99cd10..589f2b8c98 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -145,7 +145,7 @@ UnitTestResult test_opening_waits_for_platform(CancellableScope& scope){ // the platform). One A per text, none while it is still up, then the platform. UnitTestResult test_opening_presses_through_arrival_text(CancellableScope& scope){ const auto arrival = [](Milliseconds at){ - return with_reading(look_at(at, {EngineEvent::TEXT_BOX}), ADVANCE_ARROW_READING); + return with_reading(look_at(at, {EngineEvent::DIALOG_BOX}), ADVANCE_ARROW_READING); }; FakeBackend backend = fake_plza({ look_at(0ms, {EngineEvent::FADE_BLACK}), diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 5cab90c8d9..38fe0ff395 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -285,7 +285,7 @@ bool platform_look(Pokemon::StoryBackend& backend, const ScreenObserva // A text box with the advance arrow: the opening's last line ("Your train // has arrived in Lumiose City!") waits for A (console B, 2026-11-13). bool text_waiting_for_a(const ScreenObservation& look){ - return look.events.has(PokemonAutomation::ScreenEvent::TEXT_BOX) && look.readings.contains(ADVANCE_ARROW_READING); + return look.events.has(PokemonAutomation::ScreenEvent::DIALOG_BOX) && look.readings.contains(ADVANCE_ARROW_READING); } // The station platform after the opening cutscene: PLATFORM_READING on diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp index 8c7c08ce4a..c33c9a6e14 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.cpp @@ -50,14 +50,14 @@ constexpr Milliseconds BANNER_PRESS_EVERY = 1000ms; // Text to press on: a box (or choice), or the advance chevron without one. bool text_shows(const ScreenObservation& look){ - return look.events.has(EngineEvent::TEXT_BOX) || look.events.has(EngineEvent::CHOICE_BOX) || + return look.events.has(EngineEvent::DIALOG_BOX) || look.events.has(EngineEvent::CHOICE_BOX) || look.readings.contains(ADVANCE_ARROW_READING); } // Something holds the player: text, a battle, a fade, the mission // complete card. bool busy(const ScreenObservation& look){ - return text_shows(look) || look.events.has(EngineEvent::BATTLE) || + return text_shows(look) || look.events.has(EngineEvent::BATTLE_STARTED) || look.events.has(EngineEvent::FADE_BLACK) || look.events.has(EngineEvent::FADE_WHITE) || look.readings.contains(MISSION_COMPLETE_READING); } @@ -184,7 +184,7 @@ SceneScreen SceneTimeline::classify(const ScreenObservation& look) const{ if (m_config.goal == SceneMashGoal::CHOICE && choice){ return SceneScreen::GOAL_CHOICE; } - if (m_config.goal == SceneMashGoal::BATTLE && look.events.has(EngineEvent::BATTLE)){ + if (m_config.goal == SceneMashGoal::BATTLE && look.events.has(EngineEvent::BATTLE_STARTED)){ return SceneScreen::GOAL_BATTLE; } if (look.events.has(EngineEvent::FADE_BLACK)){ @@ -209,7 +209,7 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (m_config.goal == SceneMashGoal::OVERWORLD && banner_shows(look)){ return m_banner_looks >= 1 ? SceneScreen::MISSION_BANNER : SceneScreen::BANNER_SHOWING; } - if (m_config.goal == SceneMashGoal::OVERWORLD && look.events.has(EngineEvent::CAN_MOVE)){ + if (m_config.goal == SceneMashGoal::OVERWORLD && look.events.has(EngineEvent::PLAYER_CAN_MOVE)){ if (m_party_bar_since && look.when - *m_party_bar_since >= PARTY_BAR_HOLD){ return SceneScreen::CAN_MOVE; } @@ -229,7 +229,7 @@ SceneScreen SceneTimeline::classify_open(const ScreenObservation& look) const{ if (blind_press_due(look.when) && !look.events.has(EngineEvent::INTERACT_PROMPT)){ return SceneScreen::BLIND_PRESS; } - return look.events.has(EngineEvent::STILL) ? SceneScreen::SCENE_STILL : SceneScreen::SCENE_MOVING; + return look.events.has(EngineEvent::SCREEN_STILL) ? SceneScreen::SCENE_STILL : SceneScreen::SCENE_MOVING; } namespace{ @@ -252,8 +252,8 @@ void SceneTimeline::record(const ScreenObservation& look){ if (busy(look)){ m_last_busy = look.when; } - const bool box = look.events.has(EngineEvent::TEXT_BOX) || look.events.has(EngineEvent::CHOICE_BOX); - track_since(look.events.has(EngineEvent::CAN_MOVE) && !box, look.when, m_party_bar_since); + const bool box = look.events.has(EngineEvent::DIALOG_BOX) || look.events.has(EngineEvent::CHOICE_BOX); + track_since(look.events.has(EngineEvent::PLAYER_CAN_MOVE) && !box, look.when, m_party_bar_since); track_since(control_shows(look) && !box, look.when, m_hint_since); m_banner_looks = banner_shows(look) && !box ? m_banner_looks + 1 : 0; if (busy(look) || m_party_bar_since || m_hint_since || m_banner_looks > 0){ @@ -268,8 +268,8 @@ namespace{ std::string describe_look(const ScreenObservation& look){ const std::pair names[] = { {EngineEvent::FADE_BLACK, "black fade"}, {EngineEvent::FADE_WHITE, "white fade"}, - {EngineEvent::TEXT_BOX, "text box"}, {EngineEvent::BATTLE, "battle"}, - {EngineEvent::CAN_MOVE, "party bar"}, {EngineEvent::STILL, "still"}, + {EngineEvent::DIALOG_BOX, "text box"}, {EngineEvent::BATTLE_STARTED, "battle"}, + {EngineEvent::PLAYER_CAN_MOVE, "party bar"}, {EngineEvent::SCREEN_STILL, "still"}, }; std::string text; for (const auto& [event, name] : names){ @@ -348,7 +348,7 @@ class SceneRunner{ wait_until(STILL_WAIT, [this](const ScreenObservation& look){ const std::optional due = m_timeline.quiet_end_due(); return (due && look.when >= *due) || m_timeline.blind_press_due(look.when) || - !look.events.has(EngineEvent::STILL); + !look.events.has(EngineEvent::SCREEN_STILL); }); return; case SceneScreen::PARTY_BAR: 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 b42d00f1b5..7bc693d1ea 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -24,8 +24,6 @@ namespace NintendoSwitch{ namespace PokemonLZA{ using namespace std::chrono_literals; -using Pokemon::ScreenEvent; -using Pokemon::ScreenEvents; namespace{ @@ -54,7 +52,7 @@ UnitTestResult check_reads(const SceneMachineConfig& config, const std::vector Date: Fri, 13 Nov 2026 22:25:56 -0800 Subject: [PATCH 27/33] PokemonLZA: AutoStory: drop the new game intro picks and 00.00 01.00 starts on Confirm Choices after the user picks the language, look and name by hand, so the program no longer picks them. Removed: the language list, look picker and name typer actions, the launch from HOME, checkpoint 00.00 and the look/name options. They are kept on the fork-only branch plza/dev-new-game-intro for local dev. The Confirm Choices reader that 01.00 needs moves to Detectors/PokemonLZA_AutoStoryConfirmChoicesReader, with its tests. ConfirmChoices presses DOWN to Ready! and A directly instead of through the intro's key list. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA/PokemonLZA_Tests.cpp | 4 +- .../PokemonLZA_AutoStoryConfirmChoices.cpp | 29 +- .../PokemonLZA_AutoStoryConfirmChoices.h | 6 +- .../Actions/PokemonLZA_AutoStoryIntro.cpp | 88 -- .../Actions/PokemonLZA_AutoStoryIntro.h | 89 -- .../PokemonLZA_AutoStoryIntroScreens.cpp | 330 -------- .../PokemonLZA_AutoStoryIntroScreens.h | 67 -- .../PokemonLZA_AutoStoryIntro_Tests.cpp | 774 ------------------ .../Actions/PokemonLZA_AutoStoryIntro_Tests.h | 26 - .../PokemonLZA_AutoStoryLanguageList.cpp | 55 -- .../PokemonLZA_AutoStoryLanguageList.h | 54 -- .../Actions/PokemonLZA_AutoStoryLaunch.cpp | 185 ----- .../Actions/PokemonLZA_AutoStoryLaunch.h | 94 --- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 336 -------- .../Actions/PokemonLZA_AutoStoryScenes.h | 48 +- ...kemonLZA_AutoStoryConfirmChoicesReader.cpp | 133 +++ ...PokemonLZA_AutoStoryConfirmChoicesReader.h | 40 + ...ZA_AutoStoryConfirmChoicesReader_Tests.cpp | 196 +++++ ...nLZA_AutoStoryConfirmChoicesReader_Tests.h | 28 + .../AutoStory/PokemonLZA_AutoStory.cpp | 51 +- .../Programs/AutoStory/PokemonLZA_AutoStory.h | 16 - .../AutoStory/PokemonLZA_AutoStoryBackend.h | 8 +- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 4 +- .../AutoStory/PokemonLZA_AutoStoryGame.cpp | 6 - .../AutoStory/PokemonLZA_AutoStoryGame.h | 4 +- .../PokemonLZA_AutoStoryStoryFiles.h | 7 +- .../AutoStory/PokemonLZA_AutoStoryTable.cpp | 21 +- .../AutoStory/PokemonLZA_AutoStoryTable.h | 22 +- .../PokemonLZA_AutoStoryTable_Tests.cpp | 59 +- .../AutoStory/StoryData/plza-00.00.plan.json | 50 -- .../AutoStory/StoryData/plza-01.00.plan.json | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 14 +- 32 files changed, 447 insertions(+), 2399 deletions(-) delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp index ccb666c189..22f7644f94 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/PokemonLZA_Tests.cpp @@ -20,7 +20,7 @@ #include "Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "Inference/PokemonLZA_SelectionArrowDetector.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.h" -#include "Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h" +#include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h" #include "Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h" #include "Programs/AutoStory/PokemonLZA_AutoStorySceneMachine.h" #include "Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.h" @@ -50,7 +50,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_AutoStory_StoryTable(database); add_tests_AutoStoryScreenEvents(database); add_tests_AutoStoryDetectors(database); - add_tests_AutoStoryIntro(database); + add_tests_AutoStoryConfirmChoicesReader(database); add_tests_AutoStorySceneMachine(database); add_tests_AutoStoryEngine(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 5ca1d4307a..e956410c03 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.cpp @@ -7,13 +7,12 @@ #include #include #include -#include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" -#include "PokemonLZA_AutoStoryIntroScreens.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h" #include "PokemonLZA_AutoStoryConfirmChoices.h" namespace PokemonAutomation{ @@ -44,18 +43,6 @@ std::optional read_confirm_choices_now( } } -// One press of confirm_choices_moves() on "Confirm Choices". -void press_confirm_key(ConsoleHandle& console, ProControllerContext& context, IntroKey key){ - if (key == IntroKey::A){ - console.log("AutoStory intro: Confirm Choices: A on \"Ready!\"."); - pbf_press_button(context, BUTTON_A, 160ms, 2000ms); - }else{ - console.log("AutoStory intro: Confirm Choices: DOWN."); - pbf_press_dpad(context, DPAD_DOWN, 160ms, 500ms); - } - context.wait_for_all_requests(); -} - } // namespace @@ -65,7 +52,7 @@ size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& con throw UserSetupError( console, "AutoStory: 01.00 starts on the new game's \"Confirm Choices\" screen, with the language, look and name " - "already chosen. It is not on screen; nothing was pressed. Start from 00.00 to have the program choose them." + "already chosen by hand. It is not on screen; nothing was pressed." ); } console.log(std::format("AutoStory intro: Confirm Choices on screen, row {} highlighted.", *cursor)); @@ -75,14 +62,14 @@ size_t require_confirm_choices(ConsoleHandle& console, ProControllerContext& con void confirm_new_game_choices(ConsoleHandle& console, ProControllerContext& context){ std::optional cursor = require_confirm_choices(console, context); for (size_t press = 0; press < 6 && cursor; press++){ - const std::optional> moves = confirm_choices_moves(*cursor); - if (!moves){ - break; - } - press_confirm_key(console, context, moves->front()); - if (moves->front() == IntroKey::A){ + if (*cursor == CONFIRM_CHOICES_READY_ROW){ + console.log("AutoStory intro: Confirm Choices: A on \"Ready!\"."); + pbf_press_button(context, BUTTON_A, 160ms, 2000ms); + context.wait_for_all_requests(); return; } + console.log("AutoStory intro: Confirm Choices: DOWN."); + pbf_press_dpad(context, DPAD_DOWN, 160ms, 500ms); cursor = read_confirm_choices_now(console, context, 1000ms, "confirm-choices-moved"); if (cursor){ console.log(std::format("AutoStory intro: Confirm Choices: the highlight is on row {}.", *cursor)); 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 030fa23ab9..e9c40d6812 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryConfirmChoices.h @@ -3,10 +3,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 detector is in - * PokemonLZA_AutoStoryIntroScreens.h; 00.00's name step - * (type_player_name(), PokemonLZA_AutoStoryScenes.h) presses through the - * same screen with the same moves. + * language, look and name were chosen by hand. Its reader is in + * Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h. * */ diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp deleted file mode 100644 index 3134d480a0..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.cpp +++ /dev/null @@ -1,88 +0,0 @@ -/* PokemonLZA AutoStory - New game intro - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include "PokemonLZA_AutoStoryIntro.h" -#include "PokemonLZA_AutoStoryLanguageList.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -namespace{ - -constexpr size_t LOOK_COLUMNS = 4; - -} // namespace - - -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; - } - const size_t from_row = (from - 1) / LOOK_COLUMNS; - const size_t from_column = (from - 1) % LOOK_COLUMNS; - const size_t to_row = (to - 1) / LOOK_COLUMNS; - const size_t to_column = (to - 1) % LOOK_COLUMNS; - std::vector moves; - if (to_column > from_column){ - moves.insert(moves.end(), to_column - from_column, IntroKey::RIGHT); - }else{ - moves.insert(moves.end(), from_column - to_column, IntroKey::LEFT); - } - if (to_row > from_row){ - moves.insert(moves.end(), to_row - from_row, IntroKey::DOWN); - }else{ - moves.insert(moves.end(), from_row - to_row, IntroKey::UP); - } - return moves; -} - - -std::optional name_keys(std::string_view name, bool first_letter_auto_caps){ - if (name.empty()){ - return std::nullopt; - } - NameKeys result; - for (size_t i = 0; i < name.size(); i++){ - const unsigned char ch = (unsigned char)name[i]; - if (ch > 127 || !std::isalnum(ch)){ - return std::nullopt; - } - if (i > 0 && std::isupper(ch)){ - return std::nullopt; - } - result.keys.push_back((char)std::toupper(ch)); - } - const unsigned char first = (unsigned char)name[0]; - if (std::isalpha(first)){ - result.shift_first = (std::isupper(first) != 0) != first_letter_auto_caps; - } - return result; -} - - -std::string new_game_problem(Language language, const NewGameChoices& choices){ - if (!language_list_index(language)){ - return "The new game's language list has no such language."; - } - if (choices.look < 1 || choices.look > LOOK_COUNT){ - return std::format("The player look must be 1 to {}.", LOOK_COUNT); - } - if (!name_keys(choices.name, choices.name_first_letter_auto_caps)){ - return std::format( - "The player name \"{}\" must be letters and digits, with a capital only as its first letter.", choices.name - ); - } - return std::string(); -} - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h deleted file mode 100644 index 7362fb4f82..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h +++ /dev/null @@ -1,89 +0,0 @@ -/* PokemonLZA AutoStory - New game intro - * - * From: https://github.com/PokemonAutomation/ - * - * The new game's opening screens (language list, look picker, name - * keyboard): the presses each choice takes as pure functions; the language - * list's are in PokemonLZA_AutoStoryLanguageList.h. The screens' - * detectors are in PokemonLZA_AutoStoryIntroScreens.h. - * - * The language list is as seen on console B (2026-11-13). The rest is a - * guess from Scarlet/Violet's, to be confirmed on a console (see the - * TODOs): the look picker's 2 x 4 grid, and what the name keyboard does - * with Shift. - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntro_H -#define PokemonAutomation_PokemonLZA_AutoStoryIntro_H - -#include -#include -#include -#include -#include "CommonFramework/Language.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// One press on an intro screen. -enum class IntroKey{ - UP, - DOWN, - LEFT, - RIGHT, - A, -}; - - -// The number of looks on the picker: a grid of 2 rows of 4 faces, numbered -// 1 to LOOK_COUNT left to right along the top row, then the bottom row -// (console B, 2026-11-13). -constexpr size_t LOOK_COUNT = 8; - -// The presses that move the picker's highlight from look `from` to look -// `to`: LEFT or RIGHT to the column, then UP or DOWN to the row. Empty when -// `from` is `to`; nullopt for a look outside 1 to LOOK_COUNT. -std::optional> look_picker_moves(size_t from, size_t to); - - -// What to type for a player name on the keyboard. The keyboard types lower -// case; its Shift (a left stick click) makes the next letter a capital. -struct NameKeys{ - // Upper case letters and digits, the keys to press in order. - std::string keys; - // Click Shift before the first key. - bool shift_first = false; -}; - -// Only the first letter of a name may be a capital: its Shift is the only -// one the typer presses. `first_letter_auto_caps`: the keyboard starts with -// a capital by itself (TODO: confirm on a console), so Shift is for a -// first letter that is lower case. Nullopt for an empty name, a character -// that is not a letter or digit, or a capital after the first letter. -std::optional name_keys(std::string_view name, bool first_letter_auto_caps); - - -// The new game's choices, played by the intro's actions. -struct NewGameChoices{ - // Letters and digits, a capital only as the first letter (name_keys()). - // The lab's player is Kosmos. - std::string name = "Kosmos"; - // 1 to LOOK_COUNT. - size_t look = 1; - // The name keyboard starts with a capital by itself (name_keys()). - bool name_first_letter_auto_caps = false; -}; - - -// Why the new game's choices cannot be played, or an empty string if they -// can. The language is the list's. -std::string new_game_problem(Language language, const NewGameChoices& choices); - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp deleted file mode 100644 index a15cd272a1..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp +++ /dev/null @@ -1,330 +0,0 @@ -/* PokemonLZA AutoStory - New game intro screens - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "CommonFramework/ImageTools/ImageBoxes.h" -#include "CommonFramework/ImageTools/ImageStats.h" -#include "PokemonLZA_AutoStoryIntro.h" -#include "PokemonLZA_AutoStoryLanguageList.h" -#include "PokemonLZA_AutoStoryIntroScreens.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -namespace{ - -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); -} - -// Measured on console B (2026-11-13): 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 = image_stats(extract_box_reference(frame, ImageFloatBox(0.4896, 0.331, 0.0208, 0.447))); - return gap.count > 0 && gap.average.sum() / 3 < 70; -} - -constexpr size_t LOOK_COLUMNS = 4; - -// 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); -} - -double brightness(const ImageStats& stats){ - return stats.average.sum() / 3; -} - -enum class LookCorner{ - WHITE, - DARK, - OTHER, -}; - -// Measured on console B's look pickers (2026-11-13, 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 = image_stats(extract_box_reference(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(image_stats(extract_box_reference(frame, look_corner_patch(look, corner))))){ - case LookCorner::WHITE: - white++; - break; - case LookCorner::DARK: - break; - case LookCorner::OTHER: - return std::nullopt; - } - } - return white; -} - -// Whether `frame` is the look picker: all 8 tiles have a face and corners -// that are white or dark. If so, `highlighted` is the one look with 4 -// white corners while the other 7 have none; with any other mix (the card -// moving between looks) no look is highlighted. -bool read_look_picker(const ImageViewRGB32& frame, std::optional& highlighted){ - highlighted.reset(); - if (!frame || frame.width() < 160 || frame.height() < 90){ - return false; - } - 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 false; - } - if (*white > 0){ - lit_tiles++; - } - if (*white == 4){ - card = look; - } - } - if (lit_tiles == 1 && card){ - highlighted = card; - } - return true; -} - -// The right ends of the "Confirm Choices" rows, right of their text: the -// boxes span x 144 to 742 at 1920 x 1080, the two choices from y 578 and -// 662 (68 high), "Ready!" from y 790 (112 high). Each strip is 100 wide -// from x 620. -ImageFloatBox confirm_row_strip(size_t row){ - switch (row){ - case 0: - return ImageFloatBox(620.0 / 1920, 592.0 / 1080, 100.0 / 1920, 40.0 / 1080); - case 1: - return ImageFloatBox(620.0 / 1920, 676.0 / 1080, 100.0 / 1920, 40.0 / 1080); - default: - return ImageFloatBox(620.0 / 1920, 820.0 / 1080, 100.0 / 1920, 60.0 / 1080); - } -} - -// A "Confirm Choices" row's strip: the highlighted row white, flat, as the -// language list's; the others a darker slate than its boxes. The -// highlight's glow pulses over the row next to it: on console B's frames -// in ten languages (2026-11-13) that row's spread went up to 20. -ListBox classify_confirm_row(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 >= 20 && average.r <= 55 && - average.g >= 40 && average.g <= 80 && - average.b >= 65 && average.b <= 115 && - average.b >= average.r + 25; - if (slate && spread <= 30){ - return ListBox::PLAIN; - } - return ListBox::OTHER; -} - -// The dark blue, dotted background round the rows: between the choices and -// "Ready!", and right of all three. The highlight's blue glow reaches 40 -// pixels out and fills the gap under "Change looks" when that row is -// highlighted: (12-13, 56-59, 102-106), spread up to 51, against the plain -// background's (10-11, 29-37, 63-75), spread up to 31 (console B, ten -// languages, 2026-11-13). Both are dark and blue with little red; the -// intro's other screens are not. -bool confirm_background_dark(const ImageViewRGB32& frame){ - const ImageFloatBox boxes[] = { - ImageFloatBox(620.0 / 1920, 742.0 / 1080, 100.0 / 1920, 40.0 / 1080), - ImageFloatBox(770.0 / 1920, 580.0 / 1080, 30.0 / 1920, 320.0 / 1080), - }; - for (const ImageFloatBox& box : boxes){ - const ImageStats stats = image_stats(extract_box_reference(frame, box)); - if (stats.count == 0 || brightness(stats) >= 90 || stats.stddev.sum() > 80){ - return false; - } - if (stats.average.r > 30 || stats.average.b < stats.average.r + 40){ - return false; - } - } - return true; -} - -} // namespace - - -std::optional> confirm_choices_moves(size_t cursor){ - if (cursor > CONFIRM_CHOICES_READY_ROW){ - return std::nullopt; - } - std::vector moves(CONFIRM_CHOICES_READY_ROW - cursor, IntroKey::DOWN); - moves.push_back(IntroKey::A); - return moves; -} - - -std::optional read_language_list_cursor(const ImageViewRGB32& frame){ - if (!frame || frame.width() < 160 || frame.height() < 90){ - return std::nullopt; - } - if (!column_gap_dark(frame)){ - return std::nullopt; - } - std::optional highlighted; - for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ - const ImageStats stats = image_stats(extract_box_reference(frame, language_box_strip(index))); - switch (classify_list_box(stats)){ - case ListBox::HIGHLIGHTED: - if (highlighted){ - return std::nullopt; - } - highlighted = index; - break; - case ListBox::PLAIN: - break; - case ListBox::OTHER: - return std::nullopt; - } - } - return highlighted; -} - -bool is_language_list(const ImageViewRGB32& frame){ - return read_language_list_cursor(frame).has_value(); -} - -std::optional read_look_picker_cursor(const ImageViewRGB32& frame){ - std::optional highlighted; - if (!read_look_picker(frame, highlighted)){ - return std::nullopt; - } - return highlighted; -} - -bool is_look_picker(const ImageViewRGB32& frame){ - std::optional highlighted; - return read_look_picker(frame, highlighted); -} - -// Measured on console B (2026-11-13), "Confirm Choices" as it opens: the -// highlighted row 255 white, flat; the others slate, (35-36, 52-61, -// 82-95), spread under 10; the background (10, 29-31, 64-66), spread under -// 25. The language list's boxes and the look picker's tiles fall on the -// background's strips, so neither reads as this screen. -std::optional read_confirm_choices_cursor(const ImageViewRGB32& frame){ - if (!frame || frame.width() < 160 || frame.height() < 90){ - return std::nullopt; - } - if (!confirm_background_dark(frame)){ - return std::nullopt; - } - std::optional highlighted; - for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ - const ImageStats stats = image_stats(extract_box_reference(frame, confirm_row_strip(row))); - switch (classify_confirm_row(stats)){ - case ListBox::HIGHLIGHTED: - if (highlighted){ - return std::nullopt; - } - highlighted = row; - break; - case ListBox::PLAIN: - break; - case ListBox::OTHER: - return std::nullopt; - } - } - return highlighted; -} - -bool is_confirm_choices(const ImageViewRGB32& frame){ - return read_confirm_choices_cursor(frame).has_value(); -} - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h deleted file mode 100644 index 5353e3adc3..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h +++ /dev/null @@ -1,67 +0,0 @@ -/* PokemonLZA AutoStory - New game intro screens - * - * From: https://github.com/PokemonAutomation/ - * - * One detector per intro screen, measured on console B (2026-11-13). The - * name screen is the Switch system keyboard - * (NintendoSwitch_SystemKeyboardDetector.h). - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H -#define PokemonAutomation_PokemonLZA_AutoStoryIntroScreens_H - -#include -#include -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" -#include "PokemonLZA_AutoStoryIntro.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// On the "Which language will you play in?" list, the highlighted entry -// (numbered as language_list_index() numbers them): 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); - -// The language list, with one entry highlighted. -bool is_language_list(const ImageViewRGB32& frame); - -// On the "APPEARANCE" look picker, the look (1 to LOOK_COUNT) whose face is -// highlighted: the one tile whose 4 corners are on the white card while -// the other 7 tiles' corners are slate. Nullopt while no face is -// highlighted (the screen opens so), while the card moves between looks, -// and for any other frame. -std::optional read_look_picker_cursor(const ImageViewRGB32& frame); - -// The look picker's 2 x 4 grid of face tiles on dark blue, each tile's -// corners white (the highlight's card) or slate. -bool is_look_picker(const ImageViewRGB32& frame); - -// "Confirm Choices", the screen after the name keyboard, has three rows: -// "Change hair color" (0, highlighted as it opens), "Change look" and -// "Ready!", the last. -constexpr size_t CONFIRM_CHOICES_READY_ROW = 2; - -// The presses on "Confirm Choices" from the highlighted row `cursor` to -// "Ready!": DOWN to it, then A. Nullopt for a row past "Ready!". -std::optional> confirm_choices_moves(size_t cursor); - -// On "Confirm Choices", the PROFILE screen after the name keyboard (its -// rows "Change hair color", "Change look" and "Ready!"), the highlighted -// row, 0 to CONFIRM_CHOICES_READY_ROW: the one white box of the three, the -// others slate. Nullopt for any other frame, an empty one included. -std::optional read_confirm_choices_cursor(const ImageViewRGB32& frame); - -// "Confirm Choices", with one row highlighted. -bool is_confirm_choices(const ImageViewRGB32& frame); - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp deleted file mode 100644 index 115f4d47b9..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp +++ /dev/null @@ -1,774 +0,0 @@ -/* PokemonLZA AutoStory - New game intro Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Filesystem/Filesystem.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "CommonFramework/ImageTypes/ImageRGB32.h" -#include "Tests/ImageUnitTest.h" -#include "PokemonLZA_AutoStoryIntro.h" -#include "PokemonLZA_AutoStoryIntroScreens.h" -#include "PokemonLZA_AutoStoryLanguageList.h" -#include "PokemonLZA_AutoStoryLaunch.h" -#include "PokemonLZA_AutoStoryIntro_Tests.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -namespace{ - -using Keys = std::vector; - -Keys repeated(IntroKey key, size_t count){ - return Keys(count, key); -} - -Keys joined(std::initializer_list parts){ - Keys all; - for (const Keys& part : parts){ - all.insert(all.end(), part.begin(), part.end()); - } - return all; -} - -UnitTestResult test_language_index(Logger&){ - struct Row{ - Language language; - size_t index; - }; - // Down the left column, then the right; entry 2 is Latin American - // Spanish, which Language lacks. - const Row rows[] = { - {Language::English, 0}, - {Language::Spanish, 1}, - {Language::French, 3}, - {Language::German, 4}, - {Language::Italian, 5}, - {Language::Japanese, 6}, - {Language::Korean, 7}, - {Language::ChineseSimplified, 8}, - {Language::ChineseTraditional, 9}, - }; - for (const Row& row : rows){ - if (language_list_index(row.language) != row.index){ - return std::format("{}: expected entry {}.", language_data(row.language).code, row.index); - } - } - if (language_list_index(Language::None)){ - return "Language::None has no entry in the list."; - } - return true; -} - -UnitTestResult test_language_moves(Logger&){ - struct Row{ - size_t from; - size_t to; - Keys expected; - }; - const Row rows[] = { - {0, 0, {}}, - // English to Deutsch: down the left column. - {0, 4, repeated(IntroKey::DOWN, 4)}, - // English to Italiano: across. - {0, 5, {IntroKey::RIGHT}}, - // English to Traditional Chinese: across, then down. - {0, 9, joined({{IntroKey::RIGHT}, repeated(IntroKey::DOWN, 4)})}, - // Korean to Espanol (Espana): across, then up. - {7, 1, joined({{IntroKey::LEFT}, repeated(IntroKey::UP, 1)})}, - // Deutsch to Italiano: no wrap round the bottom edge. - {4, 5, joined({{IntroKey::RIGHT}, repeated(IntroKey::UP, 4)})}, - }; - for (const Row& row : rows){ - const auto moves = language_list_moves(row.from, row.to); - if (!moves || *moves != row.expected){ - return std::format("Entry {} to {}: expected {} presses.", row.from, row.to, row.expected.size()); - } - } - if (language_list_moves(0, LANGUAGE_LIST_SIZE) || language_list_moves(LANGUAGE_LIST_SIZE, 0)){ - return "Entries outside the list have no moves."; - } - return true; -} - -// The language list drawn as console B shows it (1920 x 1080): dark blue, -// 10 slate boxes 576 x 84, the columns at x 347 and 996, the rows from -// y 342, 108 apart, entry `highlighted` (if any) white. -ImageRGB32 language_list_frame(std::optional highlighted){ - ImageRGB32 image(1920, 1080); - image.fill(0xff091838); - for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ - const size_t left = index < LANGUAGE_LIST_ROWS ? 347 : 996; - const size_t top = 342 + 108 * (index % LANGUAGE_LIST_ROWS); - const uint32_t color = highlighted == index ? 0xffffffff : 0xff363c53; - for (size_t y = top; y < top + 84; y++){ - for (size_t x = left; x < left + 576; x++){ - image.pixel(x, y) = color; - } - } - } - return image; -} - -UnitTestResult test_language_list_synthetic(Logger&){ - for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ - if (read_language_list_cursor(language_list_frame(index)) != index){ - return std::format("Expected the highlight read on entry {}.", index); - } - } - if (is_language_list(language_list_frame(std::nullopt))){ - return "Expected no list without a highlight."; - } - ImageRGB32 two = language_list_frame(0); - for (size_t y = 450; y < 534; y++){ - for (size_t x = 347; x < 923; x++){ - two.pixel(x, y) = 0xffffffff; - } - } - if (is_language_list(two)){ - return "Expected no list with two highlights."; - } - for (const uint32_t fill : {0xff000000u, 0xffffffffu, 0xff363c53u}){ - ImageRGB32 flat(1920, 1080); - flat.fill(fill); - if (is_language_list(flat)){ - return std::format("Expected a flat {:08x} frame not to be the list.", fill); - } - } - return true; -} - -UnitTestResult test_language_list_empty(Logger&){ - if (is_language_list(ImageRGB32()) || is_language_list(ImageRGB32(1, 1)) || is_language_list(ImageRGB32(40, 20))){ - return "Expected empty and tiny frames not to be the list."; - } - return true; -} - -// The console's frame, from the folder in PLZA_INTRO_SCREENS -// (~/BDSPLab/intro-screens/plza on the lab Mac): language-list.png, the -// list as a new game opens it, English highlighted. -UnitTestResult test_language_list_capture(Logger&){ - const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); - if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ - return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); - } - const ImageRGB32 frame(std::format("{}/language-list.png", folder)); - const std::optional cursor = read_language_list_cursor(frame); - if (!cursor){ - return "language-list.png: expected the language list, read none."; - } - if (*cursor != 0){ - return std::format("language-list.png: expected English (entry 0) highlighted, read entry {}.", *cursor); - } - return true; -} - -// 00.00's start on frames whose HOME reading is given: HOME, the -// language list, anything else, and no video. -UnitTestResult test_launch_start_synthetic(Logger&){ - const ImageRGB32 list = language_list_frame(0); - ImageRGB32 game(1920, 1080); - game.fill(0xff405060); - const ImageRGB32 empty; - struct Row{ - std::string_view name; - const ImageRGB32* frame; - bool home; - LaunchStart expected; - }; - const Row rows[] = { - {"HOME", &game, true, LaunchStart::HOME_MENU}, - {"a game frame", &game, false, LaunchStart::OTHER}, - {"the language list", &list, false, LaunchStart::FIRST_SCREEN}, - {"the language list, HOME read", &list, true, LaunchStart::FIRST_SCREEN}, - {"an empty frame", &empty, false, LaunchStart::NO_VIDEO}, - {"an empty frame, HOME read", &empty, true, LaunchStart::NO_VIDEO}, - }; - for (const Row& row : rows){ - if (read_launch_start(*row.frame, row.home, is_language_list) != row.expected){ - return std::format("{}: expected start {}.", row.name, (int)row.expected); - } - } - if (read_launch_start(game, true, ScreenCheck()) != LaunchStart::HOME_MENU){ - return "HOME with no first-screen detector: expected a launch."; - } - return true; -} - -// 00.00's start on console B's frames, from the folder in -// PLZA_INTRO_SCREENS: language-list.png, and if present home.png (the HOME -// menu) and in-game.png (the station). The HOME reading is -// HomeMenuDetector's, which needs a console: here it is given. -UnitTestResult test_launch_start_capture(Logger&){ - const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); - if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ - return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); - } - struct Row{ - std::string_view file; - bool home; - LaunchStart expected; - }; - const Row rows[] = { - {"language-list.png", false, LaunchStart::FIRST_SCREEN}, - {"home.png", true, LaunchStart::HOME_MENU}, - {"in-game.png", false, LaunchStart::OTHER}, - }; - for (const Row& row : rows){ - const std::string path = std::format("{}/{}", folder, row.file); - if (!Filesystem::exists(Filesystem::Path(path))){ - if (row.expected == LaunchStart::FIRST_SCREEN){ - return std::format("{} is missing.", row.file); - } - continue; - } - const ImageRGB32 frame(path); - if (read_launch_start(frame, row.home, is_language_list) != row.expected){ - return std::format("{}: expected start {}.", row.file, (int)row.expected); - } - } - return true; -} - -// 00.00's moves: HOME launches; a game in front (mid-scene or on its -// first screen) gets one HOME press, then is refused if HOME still does -// not show; no video is refused without a press. -UnitTestResult test_launch_moves(Logger&){ - struct Row{ - LaunchStart start; - bool home_pressed; - LaunchMove expected; - }; - const Row rows[] = { - {LaunchStart::HOME_MENU, false, LaunchMove::LAUNCH}, - {LaunchStart::HOME_MENU, true, LaunchMove::LAUNCH}, - {LaunchStart::OTHER, false, LaunchMove::PRESS_HOME}, - {LaunchStart::OTHER, true, LaunchMove::REFUSE}, - {LaunchStart::FIRST_SCREEN, false, LaunchMove::PRESS_HOME}, - {LaunchStart::FIRST_SCREEN, true, LaunchMove::REFUSE}, - {LaunchStart::NO_VIDEO, false, LaunchMove::REFUSE}, - {LaunchStart::NO_VIDEO, true, LaunchMove::REFUSE}, - }; - for (const Row& row : rows){ - if (next_launch_move(row.start, row.home_pressed) != row.expected){ - return std::format( - "start {}, HOME pressed {}: expected move {}.", - (int)row.start, row.home_pressed, (int)row.expected - ); - } - } - return true; -} - -// The HOME press on console B's frames, from the folder in -// PLZA_INTRO_SCREENS: in-game.png (a game in front) gets the press, and -// home.png, the screen it opens, launches. -UnitTestResult test_launch_moves_capture(Logger&){ - const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); - if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ - return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); - } - const std::string in_game = std::format("{}/in-game.png", folder); - const std::string home = std::format("{}/home.png", folder); - if (!Filesystem::exists(Filesystem::Path(in_game)) || !Filesystem::exists(Filesystem::Path(home))){ - return UnitTestResult(UnitTestResult::SKIPPED, "in-game.png or home.png is missing."); - } - const LaunchStart before = read_launch_start(ImageRGB32(in_game), false, is_language_list); - if (next_launch_move(before, false) != LaunchMove::PRESS_HOME){ - return "in-game.png: expected a HOME press."; - } - const LaunchStart after = read_launch_start(ImageRGB32(home), true, is_language_list); - if (next_launch_move(after, true) != LaunchMove::LAUNCH){ - return "home.png after the HOME press: expected a launch."; - } - return true; -} - -UnitTestResult test_look_moves(Logger&){ - struct Row{ - size_t from; - size_t to; - Keys expected; - }; - const Row rows[] = { - {1, 1, {}}, - // Along the top row. - {1, 4, repeated(IntroKey::RIGHT, 3)}, - {3, 2, {IntroKey::LEFT}}, - // Down a column. - {1, 5, {IntroKey::DOWN}}, - // Corner to corner: across, then down or up. - {1, 8, joined({repeated(IntroKey::RIGHT, 3), {IntroKey::DOWN}})}, - {8, 1, joined({repeated(IntroKey::LEFT, 3), {IntroKey::UP}})}, - {6, 3, joined({{IntroKey::RIGHT}, {IntroKey::UP}})}, - }; - for (const Row& row : rows){ - const auto moves = look_picker_moves(row.from, row.to); - if (!moves || *moves != row.expected){ - return std::format("Look {} to {}: expected {} presses.", row.from, row.to, row.expected.size()); - } - } - if (look_picker_moves(0, 1) || look_picker_moves(1, 0) || look_picker_moves(1, 9) || look_picker_moves(9, 1)){ - return "Looks 0 and 9 are outside the grid."; - } - return true; -} - -// The look picker drawn as console B shows it (1920 x 1080): dark blue, -// 8 slate tiles 240 x 240, the columns' left edges at x 373, 685, 997 and -// 1309, the rows' tops at y 324 and 609, each with a face (a checkerboard) -// in its middle; looks in `highlighted` drawn on a white card 12 larger on -// every side. -ImageRGB32 look_picker_frame(std::initializer_list highlighted){ - const size_t lefts[] = {373, 685, 997, 1309}; - const size_t tops[] = {324, 609}; - ImageRGB32 image(1920, 1080); - image.fill(0xff0a1b3e); - for (size_t look = 1; look <= LOOK_COUNT; look++){ - const size_t left = lefts[(look - 1) % 4]; - const size_t top = tops[(look - 1) / 4]; - bool lit = false; - for (const size_t item : highlighted){ - lit = lit || item == look; - } - const size_t grow = lit ? 12 : 0; - for (size_t y = top - grow; y < top + 240 + grow; y++){ - for (size_t x = left - grow; x < left + 240 + grow; x++){ - image.pixel(x, y) = lit ? 0xffffffff : 0xff202f50; - } - } - for (size_t y = top + 80; y < top + 180; y++){ - for (size_t x = left + 70; x < left + 170; x++){ - image.pixel(x, y) = ((x / 10 + y / 10) % 2 == 0) ? 0xffe0b090 : 0xff302020; - } - } - } - return image; -} - -UnitTestResult test_look_picker_synthetic(Logger&){ - const ImageRGB32 none = look_picker_frame({}); - if (!is_look_picker(none) || read_look_picker_cursor(none)){ - return "Expected the picker with no highlight."; - } - for (size_t look = 1; look <= LOOK_COUNT; look++){ - const ImageRGB32 frame = look_picker_frame({look}); - if (!is_look_picker(frame) || read_look_picker_cursor(frame) != look){ - return std::format("Expected the highlight read on look {}.", look); - } - } - const ImageRGB32 two = look_picker_frame({1, 8}); - if (!is_look_picker(two) || read_look_picker_cursor(two)){ - return "Expected the picker with no highlight read while two looks have the card."; - } - if (is_look_picker(language_list_frame(0))){ - return "Expected the language list not to be the picker."; - } - for (const uint32_t fill : {0xff000000u, 0xffffffffu, 0xff202f50u, 0xff0a1b3eu}){ - ImageRGB32 flat(1920, 1080); - flat.fill(fill); - if (is_look_picker(flat)){ - return std::format("Expected a flat {:08x} frame not to be the picker.", fill); - } - } - if (is_look_picker(ImageRGB32()) || is_look_picker(ImageRGB32(1, 1)) || read_look_picker_cursor(ImageRGB32(40, 20))){ - return "Expected empty and tiny frames not to be the picker."; - } - return true; -} - -// The console's frames, from the folder in PLZA_INTRO_SCREENS: look-picker.png, -// the picker as it opens (no face highlighted yet), and the screens before -// and after it, which are not the picker. -UnitTestResult test_look_picker_capture(Logger&){ - const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); - if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ - return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); - } - const ImageRGB32 picker(std::format("{}/look-picker.png", folder)); - if (!is_look_picker(picker)){ - return "look-picker.png: expected the look picker."; - } - if (const std::optional cursor = read_look_picker_cursor(picker)){ - return std::format("look-picker.png: expected no highlight, read look {}.", *cursor); - } - for (const std::string_view name : {"language-list.png", "keyboard.png", "confirm-choices.png"}){ - const std::string path = std::format("{}/{}", folder, name); - if (!Filesystem::exists(Filesystem::Path(path))){ - continue; - } - if (is_look_picker(ImageRGB32(path))){ - return std::format("{}: expected not the look picker.", name); - } - } - return true; -} - -// "Confirm Choices" drawn as console B shows it (1920 x 1080): dark blue, -// three slate rows x 144 to 742, the two choices from y 578 and 662 (68 -// high) and "Ready!" from y 790 (112 high), row `highlighted` (if any) -// white. -ImageRGB32 confirm_choices_frame(std::optional highlighted){ - ImageRGB32 image(1920, 1080); - image.fill(0xff0a1d40); - const size_t tops[] = {578, 662, 790}; - const size_t heights[] = {68, 68, 112}; - for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ - const uint32_t color = highlighted == row ? 0xffffffff : 0xff23344f; - for (size_t y = tops[row]; y < tops[row] + heights[row]; y++){ - for (size_t x = 144; x < 742; x++){ - image.pixel(x, y) = color; - } - } - } - return image; -} - -// From each row of "Confirm Choices": DOWN to "Ready!", then A. -UnitTestResult test_confirm_choices_moves(Logger&){ - struct Row{ - size_t cursor; - Keys expected; - }; - const Row rows[] = { - {0, {IntroKey::DOWN, IntroKey::DOWN, IntroKey::A}}, - {1, {IntroKey::DOWN, IntroKey::A}}, - {2, {IntroKey::A}}, - }; - for (const Row& row : rows){ - const auto moves = confirm_choices_moves(row.cursor); - if (!moves || *moves != row.expected){ - return std::format("Row {}: expected {} presses.", row.cursor, row.expected.size()); - } - } - if (confirm_choices_moves(CONFIRM_CHOICES_READY_ROW + 1)){ - return "A row past \"Ready!\" has no moves."; - } - return true; -} - -// 01.00's start check (require_confirm_choices()) on synthetic frames: it -// reads the highlight on each row of "Confirm Choices", and refuses the -// other intro screens, flat and empty frames, and a screen with no row or -// two rows highlighted. -UnitTestResult test_confirm_choices_synthetic(Logger&){ - for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ - if (read_confirm_choices_cursor(confirm_choices_frame(row)) != row){ - return std::format("Expected the highlight read on row {}.", row); - } - } - if (is_confirm_choices(confirm_choices_frame(std::nullopt))){ - return "Expected no Confirm Choices without a highlight."; - } - ImageRGB32 two = confirm_choices_frame(0); - for (size_t y = 662; y < 730; y++){ - for (size_t x = 144; x < 742; x++){ - two.pixel(x, y) = 0xffffffff; - } - } - if (is_confirm_choices(two)){ - return "Expected no Confirm Choices with two highlights."; - } - for (size_t index = 0; index < LANGUAGE_LIST_SIZE; index++){ - if (is_confirm_choices(language_list_frame(index))){ - return std::format("Expected the language list (entry {} highlighted) not to be Confirm Choices.", index); - } - } - for (const uint32_t fill : {0xff000000u, 0xffffffffu, 0xff0a1d40u, 0xff23344fu}){ - ImageRGB32 flat(1920, 1080); - flat.fill(fill); - if (is_confirm_choices(flat)){ - return std::format("Expected a flat {:08x} frame not to be Confirm Choices.", fill); - } - } - if (is_confirm_choices(ImageRGB32()) || is_confirm_choices(ImageRGB32(1, 1)) || is_confirm_choices(ImageRGB32(40, 20))){ - return "Expected empty and tiny frames not to be Confirm Choices."; - } - return true; -} - -// 01.00's start check on console B's frames, from the folder in -// PLZA_INTRO_SCREENS: it accepts confirm-choices.png, "Change hair -// color" highlighted as the screen opens, and refuses every other intro -// screen there. -UnitTestResult test_confirm_choices_capture(Logger&){ - const auto* folder = std::getenv("PLZA_INTRO_SCREENS"); - if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ - return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); - } - const std::optional cursor = read_confirm_choices_cursor(ImageRGB32(std::format("{}/confirm-choices.png", folder))); - if (cursor != size_t(0)){ - return "confirm-choices.png: expected Confirm Choices with row 0 highlighted."; - } - for (const std::string_view name : {"home.png", "in-game.png", "language-list.png", "look-picker.png", "keyboard.png"}){ - const std::string path = std::format("{}/{}", folder, name); - if (!Filesystem::exists(Filesystem::Path(path))){ - continue; - } - if (is_confirm_choices(ImageRGB32(path))){ - return std::format("{}: expected 01.00 to refuse it.", name); - } - } - return true; -} - -UnitTestResult test_name_keys(Logger&){ - // Kosmos: a capital K by Shift, the rest as plain keys. - const auto kosmos = name_keys("Kosmos", false); - if (!kosmos || kosmos->keys != "KOSMOS" || !kosmos->shift_first){ - return "Kosmos: expected keys KOSMOS and Shift first."; - } - // A keyboard that capitalizes by itself needs no Shift for it. - const auto auto_caps = name_keys("Kosmos", true); - if (!auto_caps || auto_caps->keys != "KOSMOS" || auto_caps->shift_first){ - return "Kosmos on a capitalizing keyboard: expected no Shift."; - } - // A lower case name there needs Shift to undo it, and without it none. - const auto lower_auto = name_keys("kosmos", true); - if (!lower_auto || !lower_auto->shift_first){ - return "kosmos on a capitalizing keyboard: expected Shift first."; - } - const auto lower = name_keys("kosmos", false); - if (!lower || lower->shift_first){ - return "kosmos: expected no Shift."; - } - // A digit first takes no Shift. - const auto digit = name_keys("7up", true); - if (!digit || digit->keys != "7UP" || digit->shift_first){ - return "7up: expected keys 7UP and no Shift."; - } - return true; -} - -UnitTestResult test_name_refused(Logger&){ - for (const std::string_view name : {"", "Ko smos", "Kosmos!", "KOsmos", "Kosmo\xC3\x9F"}){ - if (name_keys(name, false)){ - return std::format("\"{}\" is not a name the typer can make.", name); - } - } - return true; -} - -UnitTestResult test_new_game_problem(Logger&){ - NewGameChoices choices; - if (!new_game_problem(Language::English, choices).empty()){ - return "The defaults are a valid new game."; - } - if (new_game_problem(Language::None, choices).empty()){ - return "No language is a problem."; - } - for (const size_t look : {size_t(0), size_t(9)}){ - choices.look = look; - if (new_game_problem(Language::English, choices).empty()){ - return std::format("Look {} is a problem.", look); - } - } - choices.look = 1; - choices.name = "KOsmos"; - if (new_game_problem(Language::English, choices).empty()){ - return "A second capital is a problem."; - } - return true; -} - -struct IntroInput{ - std::string name; - UnitTestResult (*body)(Logger&); -}; - -struct IntroExpectation{ -}; - -struct IntroCase{ - IntroInput input; - IntroExpectation expectation; -}; - -const IntroCase INTRO_CASES[] = { - { - .input = {"Intro: the language list's entries", test_language_index}, - .expectation = {}, - }, - { - .input = {"Intro: the language list's cursor moves", test_language_moves}, - .expectation = {}, - }, - { - .input = {"Intro: the language list's highlight, synthetic frames", test_language_list_synthetic}, - .expectation = {}, - }, - { - .input = {"Intro: empty frames are not the language list", test_language_list_empty}, - .expectation = {}, - }, - { - .input = {"Intro: the language list on console B (PLZA_INTRO_SCREENS)", test_language_list_capture}, - .expectation = {}, - }, - { - .input = {"Intro: the start screen, synthetic frames", test_launch_start_synthetic}, - .expectation = {}, - }, - { - .input = {"Intro: the start screen on console B (PLZA_INTRO_SCREENS)", test_launch_start_capture}, - .expectation = {}, - }, - { - .input = {"Intro: the launch step's moves", test_launch_moves}, - .expectation = {}, - }, - { - .input = {"Intro: the HOME press on console B (PLZA_INTRO_SCREENS)", test_launch_moves_capture}, - .expectation = {}, - }, - { - .input = {"Intro: the look picker's moves", test_look_moves}, - .expectation = {}, - }, - { - .input = {"Intro: the look picker's highlight, synthetic frames", test_look_picker_synthetic}, - .expectation = {}, - }, - { - .input = {"Intro: the look picker on console B (PLZA_INTRO_SCREENS)", test_look_picker_capture}, - .expectation = {}, - }, - { - .input = {"Intro: Confirm Choices' moves to Ready!", test_confirm_choices_moves}, - .expectation = {}, - }, - { - .input = {"Intro: 01.00's start check on Confirm Choices, synthetic frames", test_confirm_choices_synthetic}, - .expectation = {}, - }, - { - .input = {"Intro: 01.00's start check on console B (PLZA_INTRO_SCREENS)", test_confirm_choices_capture}, - .expectation = {}, - }, - { - .input = {"Intro: the name's keys and Shift", test_name_keys}, - .expectation = {}, - }, - { - .input = {"Intro: names the typer refuses", test_name_refused}, - .expectation = {}, - }, - { - .input = {"Intro: the new game's problems", test_new_game_problem}, - .expectation = {}, - }, -}; - -// "Confirm Choices" on console B in each game language, one frame per -// highlighted row (2026-11-13). The file name ends in that row: -// PokemonLZA/AutoStoryConfirmChoices/_.png. -class Test_ConfirmChoicesFrame : public ImageUnitTest{ -public: - explicit Test_ConfirmChoicesFrame(const std::string& image) - : ImageUnitTest("PokemonLZA::AutoStory - Confirm Choices - " + image, {image}) - {} - virtual UnitTestResult run_on_images( - Logger&, CancellableScope&, const std::vector& images - ) const override{ - const std::string& path = image_paths()[0]; - const size_t underscore = path.rfind('_'); - if (underscore == std::string::npos || underscore + 1 >= path.size()){ - return "Error: the file name does not end in _."; - } - const size_t expected = (size_t)(path[underscore + 1] - '0'); - const std::optional cursor = read_confirm_choices_cursor(images[0]); - if (!cursor){ - return std::format("Expected Confirm Choices with row {} highlighted, read no Confirm Choices.", expected); - } - if (*cursor != expected){ - return std::format("Expected row {} highlighted, read row {}.", expected, *cursor); - } - return true; - } -}; - -// The look picker on console B (2026-11-13), as the 00.00 runs saved it in -// English, German and Japanese. The file name ends in the highlighted -// look, 0 for none: PokemonLZA/AutoStoryLookPicker/__.png. -class Test_LookPickerFrame : public ImageUnitTest{ -public: - explicit Test_LookPickerFrame(const std::string& image) - : ImageUnitTest("PokemonLZA::AutoStory - Look picker - " + image, {image}) - {} - virtual UnitTestResult run_on_images( - Logger&, CancellableScope&, const std::vector& images - ) const override{ - const std::string& path = image_paths()[0]; - const size_t underscore = path.rfind('_'); - if (underscore == std::string::npos || underscore + 1 >= path.size()){ - return "Error: the file name does not end in _."; - } - const size_t expected = (size_t)(path[underscore + 1] - '0'); - if (!is_look_picker(images[0])){ - return "Expected the look picker, read another screen."; - } - const std::optional cursor = read_look_picker_cursor(images[0]); - if (expected == 0 && cursor){ - return std::format("Expected no highlight, read look {}.", *cursor); - } - if (expected != 0 && cursor != expected){ - return std::format("Expected look {} highlighted, read {}.", expected, cursor ? std::to_string(*cursor) : "none"); - } - return true; - } -}; - -class Test_AutoStoryIntro : public UnitTest{ -public: - explicit Test_AutoStoryIntro(const IntroCase& test_case) - : UnitTest(std::format("PokemonLZA::AutoStory - {}", test_case.input.name)) - , m_case(test_case) - {} - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - return m_case.input.body(logger); - } - -private: - const IntroCase& m_case; -}; - -} // namespace - - -void add_tests_AutoStoryIntro(UnitTestDatabase& database){ - for (const IntroCase& item : INTRO_CASES){ - database.add(item); - } - for (const std::string_view language : { - "English", "Spanish", "SpanishLatAm", "French", "German", - "Italian", "Japanese", "Korean", "ChineseSimplified", "ChineseTraditional", - }){ - for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ - database.add(std::format("PokemonLZA/AutoStoryConfirmChoices/{}_{}.png", language, row)); - } - } - for (const std::string_view name : { - "English_1_0", "English_2_3", "English_3_7", "English_4_2", "English_5_6", "English_6_1", "English_7_5", - "German_1_0", "German_2_7", "German_3_3", "German_4_2", "German_5_6", - "Japanese_1_0", "Japanese_2_6", "Japanese_3_2", "Japanese_4_2", "Japanese_5_3", "Japanese_6_7", - }){ - database.add(std::format("PokemonLZA/AutoStoryLookPicker/{}.png", name)); - } -} - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h deleted file mode 100644 index 619100b824..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h +++ /dev/null @@ -1,26 +0,0 @@ -/* PokemonLZA AutoStory - New game intro Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryIntro_Tests_H -#define PokemonAutomation_PokemonLZA_AutoStoryIntro_Tests_H - -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// Tests that need no console: the presses for the new game's language, look -// and name, and the language list's detector. -void add_tests_AutoStoryIntro(UnitTestDatabase& database); - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp deleted file mode 100644 index 38f97ed8ed..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp +++ /dev/null @@ -1,55 +0,0 @@ -/* PokemonLZA AutoStory - New game language list - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include "PokemonLZA_AutoStoryLanguageList.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -std::optional language_list_index(Language language){ - switch (language){ - case Language::English: return 0; - case Language::Spanish: return 1; - case Language::French: return 3; - case Language::German: return 4; - case Language::Italian: return 5; - case Language::Japanese: return 6; - case Language::Korean: return 7; - case Language::ChineseSimplified: return 8; - case Language::ChineseTraditional: return 9; - default: 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; - } - const size_t from_column = from / LANGUAGE_LIST_ROWS; - const size_t from_row = from % LANGUAGE_LIST_ROWS; - const size_t to_column = to / LANGUAGE_LIST_ROWS; - const size_t to_row = to % LANGUAGE_LIST_ROWS; - std::vector moves; - if (to_column > from_column){ - moves.insert(moves.end(), to_column - from_column, IntroKey::RIGHT); - }else{ - moves.insert(moves.end(), from_column - to_column, IntroKey::LEFT); - } - if (to_row > from_row){ - moves.insert(moves.end(), to_row - from_row, IntroKey::DOWN); - }else{ - moves.insert(moves.end(), from_row - to_row, IntroKey::UP); - } - return moves; -} - - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h deleted file mode 100644 index 7a6aa857c9..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.h +++ /dev/null @@ -1,54 +0,0 @@ -/* PokemonLZA AutoStory - New game language list - * - * From: https://github.com/PokemonAutomation/ - * - * The new game's language list: where each language is, and the presses - * between two entries, as pure functions. Its detector is in - * PokemonLZA_AutoStoryIntroScreens.h. - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryLanguageList_H -#define PokemonAutomation_PokemonLZA_AutoStoryLanguageList_H - -#include -#include -#include "CommonFramework/Language.h" -#include "PokemonLZA_AutoStoryIntro.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// The language list (console B, 2026-11-13): 2 columns of 5 entries, -// numbered down the left column, then down the right one: -// 0 English 5 Italiano -// 1 Espanol (Espana) 6 Japanese -// 2 Espanol (Latinoamerica) 7 Korean -// 3 Francais 8 Chinese Simplified -// 4 Deutsch 9 Chinese Traditional -// The cursor starts on English. - -// The rows in each column. -constexpr size_t LANGUAGE_LIST_ROWS = 5; - -// The entries: 2 columns of LANGUAGE_LIST_ROWS. -constexpr size_t LANGUAGE_LIST_SIZE = 2 * LANGUAGE_LIST_ROWS; - -// The list's entry for `language`. Language::Spanish is Espanol (Espana): -// Language has no Latin American Spanish. Nullopt for a language the list -// lacks. -std::optional language_list_index(Language language); - -// The presses that move the cursor from entry `from` to entry `to`: LEFT -// or RIGHT to the column, then UP or DOWN to the row, never round an edge. -// Empty when `from` is `to`; nullopt for an entry outside the list. -std::optional> language_list_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_AutoStoryLaunch.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp deleted file mode 100644 index ddfe7bcae8..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.cpp +++ /dev/null @@ -1,185 +0,0 @@ -/* PokemonLZA AutoStory - Launch from HOME - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" -#include "CommonFramework/Tools/DebugDumper.h" -#include "CommonFramework/VideoPipeline/VideoFeed.h" -#include "CommonTools/StartupChecks/StartProgramChecks.h" -#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" // NintendoSwitch_CloseGameDetector.h needs it first. -#include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" -#include "NintendoSwitch/Inference/NintendoSwitch_CloseGameDetector.h" -#include "NintendoSwitch/Inference/NintendoSwitch_HomeMenuDetector.h" -#include "NintendoSwitch/Programs/NintendoSwitch_GameEntry.h" -#include "PokemonLZA_AutoStoryLaunch.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - -using namespace std::chrono_literals; - - -LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, const ScreenCheck& first_screen){ - if (!frame){ - return LaunchStart::NO_VIDEO; - } - if (first_screen && first_screen(frame)){ - return LaunchStart::FIRST_SCREEN; - } - return home_menu_shows ? LaunchStart::HOME_MENU : LaunchStart::OTHER; -} - -LaunchMove next_launch_move(LaunchStart start, bool home_pressed){ - switch (start){ - case LaunchStart::HOME_MENU: - return LaunchMove::LAUNCH; - case LaunchStart::FIRST_SCREEN: - case LaunchStart::OTHER: - return home_pressed ? LaunchMove::REFUSE : LaunchMove::PRESS_HOME; - case LaunchStart::NO_VIDEO: - return LaunchMove::REFUSE; - } - return LaunchMove::REFUSE; -} - - -namespace{ - -// Until `check` holds on a frame, or `timeout`. -bool wait_for_screen(ConsoleHandle& console, ProControllerContext& context, const ScreenCheck& check, Milliseconds timeout){ - const WallClock deadline = current_time() + timeout; - while (true){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame && check(frame)){ - return true; - } - if (current_time() >= deadline){ - return false; - } - context.wait_for(250ms); - } -} - -// On HOME with the tile selected: X, and if the close dialog shows the -// game was running, so A to close it and back to HOME. X on a game that is -// not running does nothing. -void close_selected_game_if_running(ConsoleHandle& console, ProControllerContext& context){ - console.log("launch: X on the selected tile (closes it if it is running)."); - pbf_press_button(context, BUTTON_X, 160ms, 0ms); - CloseGameDetector close_dialog(console); - HomeMenuDetector home(console, COLOR_RED); - const ScreenCheck dialog_shows = [&](const ImageViewRGB32& frame){ return close_dialog.detect(frame); }; - if (!wait_for_screen(console, context, dialog_shows, 3000ms)){ - if (!wait_for_screen(console, context, [&](const ImageViewRGB32& frame){ return home.detect_only(frame); }, 2000ms)){ - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "launch: after X on the selected tile, neither the close dialog nor the HOME menu shows.", - console - ); - } - console.log("launch: no close dialog: the selected game is not running."); - return; - } - console.log("launch: the close dialog: the selected game was running; A to close it."); - pbf_press_button(context, BUTTON_A, 160ms, 0ms); - const ScreenCheck home_back = [&](const ImageViewRGB32& frame){ - return home.detect_only(frame) && !close_dialog.detect(frame); - }; - if (!wait_for_screen(console, context, home_back, 15s)){ - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "launch: the HOME menu did not come back within 15 s of closing the selected game.", - console - ); - } - console.log("launch: the selected game is closed."); -} - -// The screen now, read as the launch step's start. -LaunchStart read_screen(ConsoleHandle& console, ProControllerContext& context, const ScreenCheck& first_screen){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - HomeMenuDetector home(console, COLOR_RED); - const bool home_shows = frame && home.detect_only(frame); - return read_launch_start(frame, home_shows, first_screen); -} - -// Until the HOME menu shows, at most HOME once (see next_launch_move()). -// Throws UserSetupError if it does not. -void reach_home_menu(ConsoleHandle& console, ProControllerContext& context, std::string_view game, const ScreenCheck& first_screen){ - LaunchStart start = read_screen(console, context, first_screen); - bool home_pressed = false; - while (true){ - switch (next_launch_move(start, home_pressed)){ - case LaunchMove::LAUNCH: - return; - case LaunchMove::PRESS_HOME:{ - console.log(std::format("launch: not on HOME ({}); HOME once: the game in front stays the selected tile.", (int)start)); - pbf_press_button(context, BUTTON_HOME, 160ms, 0ms); - HomeMenuDetector home(console, COLOR_RED); - wait_for_screen(console, context, [&](const ImageViewRGB32& frame){ return home.detect_only(frame); }, 5000ms); - home_pressed = true; - start = read_screen(console, context, first_screen); - break; - } - case LaunchMove::REFUSE: - throw UserSetupError(console, std::format( - "Start a new game with {} in front, or on the HOME screen with {}'s tile selected. {}", - game, game, start == LaunchStart::NO_VIDEO ? "There is no video." : "HOME did not show after a HOME press." - )); - } - } -} - -} // namespace - - -void launch_selected_game_from_home( - ConsoleHandle& console, ProControllerContext& context, - std::string_view game, std::string_view first_screen_name, - const ScreenCheck& first_screen, Milliseconds timeout, - std::string_view dump_folder -){ - reach_home_menu(console, context, game, first_screen); - // The program's start skipped this check (the game in front may have - // been dark): HOME fills the screen. - context.wait_for_all_requests(); - StartProgramChecks::check_border(console); - console.log(std::format("launch: the HOME menu; launching the selected tile ({} expected), the cursor not moved.", game)); - close_selected_game_if_running(console, context); - console.log("launch: A on the selected tile, then the user select and the license check."); - start_game_from_home(console, context, true, 0, 0); - // The launch's logos: the first screen comes no sooner than this. - context.wait_for(5000ms); - if (!wait_for_screen(console, context, first_screen, timeout)){ - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - std::format( - "launch: the {} did not show within {} ms: the selected game may not be {}, or it has a save.", - first_screen_name, timeout.count(), game - ), - console - ); - } - console.log(std::format("launch: the {} shows.", first_screen_name)); - context.wait_for_all_requests(); - const VideoSnapshot shown = console.video().snapshot(); - if (shown){ - std::string label(first_screen_name); - std::replace(label.begin(), label.end(), ' ', '-'); - dump_debug_image(console, std::string(dump_folder), label, shown); - } -} - - -} // 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 deleted file mode 100644 index 12c8522af9..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLaunch.h +++ /dev/null @@ -1,94 +0,0 @@ -/* PokemonLZA AutoStory - Launch from HOME - * - * From: https://github.com/PokemonAutomation/ - * - * A new game's first step: from the Switch HOME menu, or with the game in - * front (HOME once), launch the selected tile without moving HOME's - * cursor. Nothing here is PLZA's: the game's first screen comes in as a - * detector, so BDSP and FRLG can share it once it moves to the shared - * AutoStory core. - * - */ - -#ifndef PokemonAutomation_PokemonLZA_AutoStoryLaunch_H -#define PokemonAutomation_PokemonLZA_AutoStoryLaunch_H - -#include -#include -#include "Common/Cpp/Time.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" -#include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" -#include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonLZA{ - - -// A detector for one screen. -using ScreenCheck = std::function; - - -// The screen the launch step reads. -enum class LaunchStart{ - // The HOME menu. - HOME_MENU, - // The game's first screen (a launch left there). Told apart from OTHER - // only for the log. - FIRST_SCREEN, - // Anything else: a game in front, mid-scene or not. - OTHER, - // No frame: no video to check HOME against. - NO_VIDEO, -}; - -// Where the launch step starts, from a frame. `home_menu_shows` is the -// HOME menu detector's reading of `frame` (that detector needs the -// console); `first_screen` is the game's first screen's detector. -LaunchStart read_launch_start(const ImageViewRGB32& frame, bool home_menu_shows, const ScreenCheck& first_screen); - -// What the launch step does next. -enum class LaunchMove{ - // Launch the selected tile. - LAUNCH, - // Press HOME once and read the screen again: with a game in front, HOME - // opens with that game's tile selected. - PRESS_HOME, - // Refuse: UserSetupError. - REFUSE, -}; - -// The launch step's move on `start`; `home_pressed` is whether it has -// pressed HOME already (it presses it once at most). -LaunchMove next_launch_move(LaunchStart start, bool home_pressed); - - -// From the HOME menu with `game`'s tile selected, or with `game` in front -// (on any screen, mid-scene too), a new game (no save): launches the -// selected tile, never moving HOME's cursor. If HOME is not showing, it -// presses HOME once: with a game in front, HOME opens with that game's -// tile selected. It presses no DOWN or UP, and HOME never on the HOME -// menu: from HOME that goes back to the game in front, and from there -// DOWN and UP select the first tile, the game played last. If the selected game is running, X on its tile opens the close -// dialog, which A confirms; on a game that is not running X does nothing. -// Then A on the tile, the user select and the online license check -// (start_game_from_home() with slot 0, which does not move the cursor), -// 5 s, and up to `timeout` for `first_screen` (`first_screen_name` in the -// log), whose frame it saves to DebugDumps under `dump_folder`. -// Throws UserSetupError if there is no video or HOME still does not show -// after the HOME press, OperationFailedException -// (with a screenshot) if the close dialog does not close or the first -// screen does not show: then the selected game may not be `game`, or it -// has a save. -void launch_selected_game_from_home( - ConsoleHandle& console, ProControllerContext& context, - std::string_view game, std::string_view first_screen_name, - const ScreenCheck& first_screen, Milliseconds timeout, - std::string_view dump_folder -); - - -} // namespace PokemonLZA -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif 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 440cf068f8..5802435320 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -4,23 +4,13 @@ * */ -#include #include #include -#include -#include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonFramework/ImageTools/ImageStats.h" -#include "CommonFramework/Tools/DebugDumper.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" -#include "NintendoSwitch/Inference/NintendoSwitch_SystemKeyboardDetector.h" -#include "NintendoSwitch/Programs/FastCodeEntry/NintendoSwitch_SystemKeyboardTyping.h" -#include "PokemonLZA_AutoStoryIntro.h" -#include "PokemonLZA_AutoStoryIntroScreens.h" -#include "PokemonLZA_AutoStoryLanguageList.h" -#include "PokemonLZA_AutoStoryLaunch.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -201,332 +191,6 @@ void mash_story_scene(ConsoleHandle& console, ProControllerContext& context, But } -namespace{ - -// Saves the current frame to DebugDumps as intro screen `screen`. -void dump_intro_frame(ConsoleHandle& console, ProControllerContext& context, std::string_view screen){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame){ - dump_debug_image(console, "PokemonLZA/AutoStory/Intro", std::string(screen), frame); - } -} - -void press_intro_keys( - ConsoleHandle& console, ProControllerContext& context, - const std::vector& presses, Milliseconds after_last -){ - for (size_t i = 0; i < presses.size(); i++){ - const IntroKey key = presses[i]; - const Milliseconds release = i + 1 == presses.size() ? after_last : 400ms; - switch (key){ - case IntroKey::UP: - console.log("AutoStory intro: UP."); - pbf_press_dpad(context, DPAD_UP, 160ms, release); - break; - case IntroKey::DOWN: - console.log("AutoStory intro: DOWN."); - pbf_press_dpad(context, DPAD_DOWN, 160ms, release); - break; - case IntroKey::LEFT: - console.log("AutoStory intro: LEFT."); - pbf_press_dpad(context, DPAD_LEFT, 160ms, release); - break; - case IntroKey::RIGHT: - console.log("AutoStory intro: RIGHT."); - pbf_press_dpad(context, DPAD_RIGHT, 160ms, release); - break; - case IntroKey::A: - console.log("AutoStory intro: A."); - pbf_press_button(context, BUTTON_A, 160ms, release); - break; - } - } - context.wait_for_all_requests(); -} - -// Until the language list shows, or `timeout`. Saves its first frame to -// DebugDumps. Throws OperationFailedException with `failure` if it does -// not show. -void wait_for_language_list( - ConsoleHandle& console, ProControllerContext& context, - Milliseconds timeout, std::string_view failure -){ - const WallClock deadline = current_time() + timeout; - while (current_time() < deadline){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame && is_language_list(frame)){ - console.log("AutoStory intro: language-list: detected."); - dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "language-list", frame); - return; - } - context.wait_for(250ms); - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - std::format("AutoStory intro: {} (waited {} ms)", failure, timeout.count()), - console - ); -} - -// On the language list: one press at a time towards entry `target`, -// reading the highlight after each, until it is on `target`. A dropped -// press or a frame caught mid-move is read again on the next turn. -void move_language_cursor(ConsoleHandle& console, ProControllerContext& context, size_t target){ - for (size_t attempt = 0; attempt < 20; attempt++){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - const std::optional cursor = frame ? read_language_list_cursor(frame) : std::nullopt; - if (!cursor){ - console.log("AutoStory intro: language-list: no highlight read; reading again."); - context.wait_for(250ms); - continue; - } - if (*cursor == target){ - console.log(std::format("AutoStory intro: language-list: the highlight is on entry {}.", target)); - return; - } - const std::optional> moves = language_list_moves(*cursor, target); - if (!moves || moves->empty()){ - break; - } - console.log(std::format("AutoStory intro: language-list: the highlight is on entry {}.", *cursor)); - press_intro_keys(console, context, {moves->front()}, 400ms); - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - std::format("AutoStory intro: the language list's highlight did not reach entry {}.", target), - console - ); -} - -// Until the system keyboard shows (or, `gone`, has closed), or `timeout`. -// Throws OperationFailedException if it does not. -void wait_for_system_keyboard(ConsoleHandle& console, ProControllerContext& context, bool gone, Milliseconds timeout){ - SystemKeyboardDetector keyboard; - const WallClock deadline = current_time() + timeout; - while (current_time() < deadline){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame && keyboard.detect(frame) != gone){ - console.log(std::format("AutoStory intro: keyboard: {}.", gone ? "closed" : "detected")); - return; - } - context.wait_for(250ms); - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - std::format("AutoStory intro: the name keyboard {} within {} ms.", gone ? "did not close" : "did not show", timeout.count()), - console - ); -} - -// B deletes a character, and closes the keyboard on an empty field, so it -// deletes only while the field holds text (a name left from a retry). -void clear_system_keyboard_field(ConsoleHandle& console, ProControllerContext& context){ - for (size_t c = 0; c < 14; c++){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (!frame || !system_keyboard_field_has_text(frame)){ - return; - } - console.log("AutoStory intro: keyboard: the field holds text; B."); - pbf_press_button(context, BUTTON_B, 60ms, 250ms); - } -} - -// What type_on_system_keyboard() types for `plan`: it clicks Shift before -// each capital, so the keys in lower case, the first a capital when Shift -// goes first. -std::string system_keyboard_text(const NameKeys& plan){ - std::string text; - for (const char key : plan.keys){ - text += (char)std::tolower((unsigned char)key); - } - if (plan.shift_first && !text.empty()){ - text[0] = (char)std::toupper((unsigned char)text[0]); - } - return text; -} - -// One look picker press: a short tilt of the left stick (the screen says -// "Use the Left Stick"), then a pause for the highlight to move. -void press_look_picker_key(ConsoleHandle& console, ProControllerContext& context, IntroKey key){ - switch (key){ - case IntroKey::UP: - console.log("AutoStory intro: look-picker: stick UP."); - pbf_move_left_joystick(context, {0, +1}, 200ms, 500ms); - break; - case IntroKey::DOWN: - console.log("AutoStory intro: look-picker: stick DOWN."); - pbf_move_left_joystick(context, {0, -1}, 200ms, 500ms); - break; - case IntroKey::LEFT: - console.log("AutoStory intro: look-picker: stick LEFT."); - pbf_move_left_joystick(context, {-1, 0}, 200ms, 500ms); - break; - case IntroKey::RIGHT: - console.log("AutoStory intro: look-picker: stick RIGHT."); - pbf_move_left_joystick(context, {+1, 0}, 200ms, 500ms); - break; - case IntroKey::A: - console.log("AutoStory intro: look-picker: A."); - pbf_press_button(context, BUTTON_A, 160ms, 500ms); - break; - } - context.wait_for_all_requests(); -} - -// Until the look picker shows, or `timeout`. Saves its first frame to -// DebugDumps. Throws OperationFailedException if it does not show. -void wait_for_look_picker(ConsoleHandle& console, ProControllerContext& context, Milliseconds timeout){ - const WallClock deadline = current_time() + timeout; - while (current_time() < deadline){ - context.wait_for_all_requests(); - const VideoSnapshot frame = console.video().snapshot(); - if (frame && is_look_picker(frame)){ - console.log("AutoStory intro: look-picker: detected."); - dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "look-picker", frame); - return; - } - context.wait_for(250ms); - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - std::format("AutoStory intro: the look picker did not show within {} ms.", timeout.count()), - console - ); -} - -// The look picker's highlight once it has settled: frames 150 ms apart -// until two reads in a row agree on a look, over at most 2 s. The card -// grows and moves for a moment after a press, so one read can catch it -// between looks. Nullopt (the last frame saved to DebugDumps) if no two -// reads agree. -std::optional read_settled_look(ConsoleHandle& console, ProControllerContext& context){ - std::optional previous; - VideoSnapshot frame; - for (size_t read = 0; read < 14; read++){ - context.wait_for_all_requests(); - frame = console.video().snapshot(); - const std::optional cursor = frame ? read_look_picker_cursor(frame) : std::nullopt; - if (cursor && cursor == previous){ - return cursor; - } - previous = cursor; - context.wait_for(150ms); - } - if (frame){ - dump_debug_image(console, "PokemonLZA/AutoStory/Intro", "look-picker-unread", frame); - } - return std::nullopt; -} - -// On the look picker: one press at a time towards look `target`, reading -// the settled highlight (read_settled_look()) after each, until it is on -// `target`. The picker opens with -// no face highlighted, so while none is, UP (harmless on any face of the -// top row) to bring the highlight up. Throws OperationFailedException if the highlight is -// not read or does not reach `target`. -void move_look_cursor(ConsoleHandle& console, ProControllerContext& context, size_t target){ - size_t unread = 0; - for (size_t attempt = 0; attempt < 24; attempt++){ - const std::optional cursor = read_settled_look(console, context); - if (!cursor){ - unread++; - if (unread > 6){ - break; - } - console.log("AutoStory intro: look-picker: no highlight read."); - press_look_picker_key(console, context, IntroKey::UP); - continue; - } - unread = 0; - if (*cursor == target){ - return; - } - const std::optional> moves = look_picker_moves(*cursor, target); - if (!moves || moves->empty()){ - break; - } - console.log(std::format("AutoStory intro: look-picker: the highlight is on look {}.", *cursor)); - press_look_picker_key(console, context, moves->front()); - } - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - std::format("AutoStory intro: the look picker's highlight was not read on look {}.", target), - console - ); -} - -} // namespace - - -void launch_game_from_home(ConsoleHandle& console, ProControllerContext& context){ - launch_selected_game_from_home( - console, context, "PLZA", "language list", - [](const ImageViewRGB32& frame){ return is_language_list(frame); }, - 90s, "PokemonLZA/AutoStory/Intro" - ); -} - -void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language){ - const std::optional target = language_list_index(language); - if (!target){ - throw UserSetupError(console, "AutoStory: the new game's language list has no such language."); - } - console.log(std::format("AutoStory intro: language {}: entry {} of the list.", language_data(language).code, *target)); - wait_for_language_list(console, context, 5s, - "the language list is not on screen: the launch_game_from_home step brings it up." - ); - move_language_cursor(console, context, *target); - press_intro_keys(console, context, {IntroKey::A}, 5000ms); -} - -void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look){ - if (look < 1 || look > LOOK_COUNT){ - throw UserSetupError(console, std::format("AutoStory: the player look must be 1 to {}.", LOOK_COUNT)); - } - console.log(std::format("AutoStory intro: look {} of {}.", look, LOOK_COUNT)); - wait_for_look_picker(console, context, 10s); - move_look_cursor(console, context, look); - console.log(std::format("AutoStory intro: look-picker: the highlight is on look {}; A.", look)); - press_intro_keys(console, context, {IntroKey::A}, 3000ms); -} - -void type_player_name( - ConsoleHandle& console, ProControllerContext& context, - const std::string& name, bool first_letter_auto_caps -){ - const std::optional plan = name_keys(name, first_letter_auto_caps); - if (!plan){ - throw UserSetupError(console, std::format("AutoStory: the player name \"{}\" cannot be typed.", name)); - } - wait_for_system_keyboard(console, context, false, 20s); - dump_intro_frame(console, context, "keyboard"); - // Let the keyboard finish sliding in: inputs during that are dropped. - context.wait_for(800ms); - clear_system_keyboard_field(console, context); - const std::string typed = system_keyboard_text(*plan); - console.log(std::format( - "AutoStory intro: typing \"{}\" as \"{}\" (keyboard capitalizes the first letter: {}).", - name, typed, first_letter_auto_caps - )); - FastCodeEntry::type_on_system_keyboard(console, context, typed); - console.log("AutoStory intro: PLUS (the keyboard's OK)."); - pbf_press_button(context, BUTTON_PLUS, 160ms, 0ms); - wait_for_system_keyboard(console, context, true, 5s); - // "Confirm Choices" opens on "Change hair color"; "Ready!" is two rows - // down (console B, 2026-11-10). - context.wait_for(2500ms); - dump_intro_frame(console, context, "confirm-choices"); - console.log("AutoStory intro: Confirm Choices: DOWN x2 to \"Ready!\", then A."); - press_intro_keys(console, context, *confirm_choices_moves(0), 2000ms); - dump_intro_frame(console, context, "confirm"); -} - - } // namespace PokemonLZA } // namespace NintendoSwitch 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 986731a22b..4f008b09ee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -3,8 +3,7 @@ * From: https://github.com/PokemonAutomation/ * * The story actions that press through scenes rather than walk: the scene - * mash over PlzaScreenObserver's events, and the new game's opening, - * which is timed presses as recorded on console B (2026-11-08). None has run on a console as a story step yet. + * mash over PlzaScreenObserver's events. * */ @@ -12,9 +11,7 @@ #define PokemonAutomation_PokemonLZA_AutoStoryScenes_H #include -#include #include "Common/Cpp/Time.h" -#include "CommonFramework/Language.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" @@ -57,49 +54,6 @@ void mash_story_scene(ConsoleHandle& console, ProControllerContext& context, But bool tutorial_card_shows(const ImageViewRGB32& frame); -// The new game's opening, as recorded 2026-11-08 on console B, with the -// player's choices (PokemonLZA_AutoStoryIntro.h has each one's presses). -// Each logs every press and saves its screen's frame (DebugDumps) for the -// detectors to be built from. The language list and the name keyboard (the -// Switch system keyboard) are detected; the look picker is not checked and -// waits a fixed time. - -// 00.00's first step. It starts on the Switch HOME menu with PLZA's tile -// selected and no save: launches that tile without moving the cursor, -// closing the game first if it is running, through the user select and -// the license check to the language list (launch_selected_game_from_home(), -// up to 90 s; a new game has no title screen). Throws UserSetupError on -// any other starting screen, OperationFailedException if the list does not -// show (the selected game may not be PLZA, or it has a save). -void launch_game_from_home(ConsoleHandle& console, ProControllerContext& context); - -// On the language list: moves its highlight to `language`'s entry, -// reading it after each press, and presses A. Throws UserSetupError for a -// language the list lacks, OperationFailedException if the list is not on -// screen or the highlight does not get there. -void new_game_language(ConsoleHandle& console, ProControllerContext& context, Language language); - -// On the look picker: waits up to 10 s for it, moves its highlight to look -// `look` (1 to 8, a 2 x 4 grid) one left-stick press at a time, reading it -// after each, and presses A only on `look`. Throws UserSetupError for a -// look outside 1 to 8, OperationFailedException if the picker does not -// show or its highlight is not read on `look`. -void pick_player_look(ConsoleHandle& console, ProControllerContext& context, size_t look); - -// On the name screen, the Switch system keyboard: waits up to 20 s for it, -// deletes any text left in its field, types `name` reading the cursor -// before each key (type_on_system_keyboard(); letters and digits, a -// capital only as the first letter; name_keys()), PLUS to finish and waits -// for the keyboard to close, then on "Confirm Choices" DOWN x2 and A on -// "Ready!". `first_letter_auto_caps`: the keyboard starts with a capital -// by itself, so Shift is for a lower case first letter instead (to be -// confirmed). Throws OperationFailedException if the keyboard does not -// show or close. -void type_player_name( - ConsoleHandle& console, ProControllerContext& context, - const std::string& name, bool first_letter_auto_caps -); - } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.cpp new file mode 100644 index 0000000000..0337c5caca --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.cpp @@ -0,0 +1,133 @@ +/* PokemonLZA AutoStory - Confirm Choices reader + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "PokemonLZA_AutoStoryConfirmChoicesReader.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +enum class RowBox{ + HIGHLIGHTED, + PLAIN, + OTHER, +}; + +double brightness(const ImageStats& stats){ + return stats.average.sum() / 3; +} + +// The right ends of the "Confirm Choices" rows, right of their text: the +// boxes span x 144 to 742 at 1920 x 1080, the two choices from y 578 and +// 662 (68 high), "Ready!" from y 790 (112 high). Each strip is 100 wide +// from x 620. +ImageFloatBox confirm_row_strip(size_t row){ + switch (row){ + case 0: + return ImageFloatBox(620.0 / 1920, 592.0 / 1080, 100.0 / 1920, 40.0 / 1080); + case 1: + return ImageFloatBox(620.0 / 1920, 676.0 / 1080, 100.0 / 1920, 40.0 / 1080); + default: + return ImageFloatBox(620.0 / 1920, 820.0 / 1080, 100.0 / 1920, 60.0 / 1080); + } +} + +// A "Confirm Choices" row's strip: the highlighted row white, flat; the +// others slate. The highlight's glow pulses over the row next to it: on +// console B's frames in ten languages (2026-11-13) that row's spread went +// up to 20. +RowBox classify_confirm_row(const ImageStats& stats){ + if (stats.count == 0){ + return RowBox::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 RowBox::HIGHLIGHTED; + } + const bool slate = + average.r >= 20 && average.r <= 55 && + average.g >= 40 && average.g <= 80 && + average.b >= 65 && average.b <= 115 && + average.b >= average.r + 25; + if (slate && spread <= 30){ + return RowBox::PLAIN; + } + return RowBox::OTHER; +} + +// The dark blue, dotted background round the rows: between the choices and +// "Ready!", and right of all three. The highlight's blue glow reaches 40 +// pixels out and fills the gap under "Change looks" when that row is +// highlighted: (12-13, 56-59, 102-106), spread up to 51, against the plain +// background's (10-11, 29-37, 63-75), spread up to 31 (console B, ten +// languages, 2026-11-13). Both are dark and blue with little red; the +// intro's other screens are not. +bool confirm_background_dark(const ImageViewRGB32& frame){ + const ImageFloatBox boxes[] = { + ImageFloatBox(620.0 / 1920, 742.0 / 1080, 100.0 / 1920, 40.0 / 1080), + ImageFloatBox(770.0 / 1920, 580.0 / 1080, 30.0 / 1920, 320.0 / 1080), + }; + for (const ImageFloatBox& box : boxes){ + const ImageStats stats = image_stats(extract_box_reference(frame, box)); + if (stats.count == 0 || brightness(stats) >= 90 || stats.stddev.sum() > 80){ + return false; + } + if (stats.average.r > 30 || stats.average.b < stats.average.r + 40){ + return false; + } + } + return true; +} + +} // namespace + + +// Measured on console B (2026-11-13), "Confirm Choices" as it opens: the +// highlighted row 255 white, flat; the others slate, (35-36, 52-61, +// 82-95), spread under 10; the background (10, 29-31, 64-66), spread under +// 25. The intro's language list and look picker fall on the background's +// strips, so neither reads as this screen. +std::optional read_confirm_choices_cursor(const ImageViewRGB32& frame){ + if (!frame || frame.width() < 160 || frame.height() < 90){ + return std::nullopt; + } + if (!confirm_background_dark(frame)){ + return std::nullopt; + } + std::optional highlighted; + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + const ImageStats stats = image_stats(extract_box_reference(frame, confirm_row_strip(row))); + switch (classify_confirm_row(stats)){ + case RowBox::HIGHLIGHTED: + if (highlighted){ + return std::nullopt; + } + highlighted = row; + break; + case RowBox::PLAIN: + break; + case RowBox::OTHER: + return std::nullopt; + } + } + return highlighted; +} + +bool is_confirm_choices(const ImageViewRGB32& frame){ + return read_confirm_choices_cursor(frame).has_value(); +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h new file mode 100644 index 0000000000..f675df1f58 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h @@ -0,0 +1,40 @@ +/* PokemonLZA AutoStory - Confirm Choices reader + * + * From: https://github.com/PokemonAutomation/ + * + * The new game's "Confirm Choices" screen, where checkpoint 01.00 starts: + * the PROFILE screen after the name keyboard, with its rows "Change hair + * color", "Change look" and "Ready!". + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryConfirmChoicesReader_H +#define PokemonAutomation_PokemonLZA_AutoStoryConfirmChoicesReader_H + +#include +#include +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// "Confirm Choices" has three rows: "Change hair color" (0, highlighted as +// it opens), "Change look" and "Ready!", the last. +constexpr size_t CONFIRM_CHOICES_READY_ROW = 2; + +// On "Confirm Choices", the highlighted row, 0 to +// CONFIRM_CHOICES_READY_ROW: the one white box of the three, the others +// slate. Nullopt for any other frame, an empty one included. +std::optional read_confirm_choices_cursor(const ImageViewRGB32& frame); + +// "Confirm Choices", with one row highlighted. +bool is_confirm_choices(const ImageViewRGB32& frame); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp new file mode 100644 index 0000000000..ff020183f5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp @@ -0,0 +1,196 @@ +/* PokemonLZA AutoStory - Confirm Choices reader Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include +#include +#include +#include +#include +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "CommonFramework/ImageTypes/ImageRGB32.h" +#include "Tests/ImageUnitTest.h" +#include "PokemonLZA_AutoStoryConfirmChoicesReader.h" +#include "PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +namespace{ + +constexpr uint32_t BACKGROUND = 0xff0a1d40; +constexpr uint32_t SLATE = 0xff23344f; +constexpr uint32_t WHITE = 0xffffffff; + +// "Confirm Choices" drawn as console B shows it (1920 x 1080): dark blue, +// three slate rows x 144 to 742, the two choices from y 578 and 662 (68 +// high) and "Ready!" from y 790 (112 high), the rows in `highlighted` +// white. +ImageRGB32 confirm_choices_frame(std::initializer_list highlighted){ + ImageRGB32 image(1920, 1080); + image.fill(BACKGROUND); + const size_t tops[] = {578, 662, 790}; + const size_t heights[] = {68, 68, 112}; + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + bool lit = false; + for (const size_t pick : highlighted){ + lit = lit || pick == row; + } + for (size_t y = tops[row]; y < tops[row] + heights[row]; y++){ + for (size_t x = 144; x < 742; x++){ + image.pixel(x, y) = lit ? WHITE : SLATE; + } + } + } + return image; +} + +ImageRGB32 flat_frame(uint32_t color){ + ImageRGB32 image(1920, 1080); + image.fill(color); + return image; +} + +struct SyntheticInput{ + std::function frame; +}; + +struct SyntheticExpectation{ + // The row read; nullopt: not Confirm Choices. + std::optional cursor; +}; + +struct SyntheticCase{ + std::string name; + SyntheticInput input; + SyntheticExpectation expectation; +}; + +const SyntheticCase SYNTHETIC_CASES[] = { + {"row 0 highlighted", {[]{ return confirm_choices_frame({0}); }}, {0}}, + {"row 1 highlighted", {[]{ return confirm_choices_frame({1}); }}, {1}}, + {"Ready! highlighted", {[]{ return confirm_choices_frame({CONFIRM_CHOICES_READY_ROW}); }}, {CONFIRM_CHOICES_READY_ROW}}, + {"no row highlighted", {[]{ return confirm_choices_frame({}); }}, {std::nullopt}}, + {"two rows highlighted", {[]{ return confirm_choices_frame({0, 1}); }}, {std::nullopt}}, + {"flat black", {[]{ return flat_frame(0xff000000); }}, {std::nullopt}}, + {"flat white", {[]{ return flat_frame(WHITE); }}, {std::nullopt}}, + {"flat background", {[]{ return flat_frame(BACKGROUND); }}, {std::nullopt}}, + {"flat slate", {[]{ return flat_frame(SLATE); }}, {std::nullopt}}, + {"empty frame", {[]{ return ImageRGB32(); }}, {std::nullopt}}, + {"1 x 1 frame", {[]{ return ImageRGB32(1, 1); }}, {std::nullopt}}, + {"40 x 20 frame", {[]{ return ImageRGB32(40, 20); }}, {std::nullopt}}, +}; + +std::string describe_cursor(std::optional cursor){ + return cursor ? std::format("row {}", *cursor) : std::string("no Confirm Choices"); +} + +class Test_ConfirmChoicesSynthetic : public UnitTest{ +public: + explicit Test_ConfirmChoicesSynthetic(const SyntheticCase& test_case) + : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {}", test_case.name)) + , m_case(test_case) + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const std::optional cursor = read_confirm_choices_cursor(m_case.input.frame()); + if (cursor != m_case.expectation.cursor){ + return std::format( + "Expected {}, read {}.", describe_cursor(m_case.expectation.cursor), describe_cursor(cursor) + ); + } + return true; + } + +private: + const SyntheticCase& m_case; +}; + +// 01.00's start check on console B's frames, from the folder in +// PLZA_INTRO_SCREENS: it accepts confirm-choices.png, "Change hair +// color" highlighted as the screen opens, and refuses every other intro +// screen there. +class Test_ConfirmChoicesCapture : public UnitTest{ +public: + Test_ConfirmChoicesCapture() + : UnitTest("PokemonLZA::AutoStory - Confirm Choices reader: console B's intro screens (PLZA_INTRO_SCREENS)") + {} + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const char* folder = std::getenv("PLZA_INTRO_SCREENS"); + if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); + } + const std::optional cursor = read_confirm_choices_cursor(ImageRGB32(std::format("{}/confirm-choices.png", folder))); + if (cursor != size_t(0)){ + return "confirm-choices.png: expected Confirm Choices with row 0 highlighted."; + } + for (const std::string_view name : {"home.png", "in-game.png", "language-list.png", "look-picker.png", "keyboard.png"}){ + const std::string path = std::format("{}/{}", folder, name); + if (!Filesystem::exists(Filesystem::Path(path))){ + continue; + } + if (is_confirm_choices(ImageRGB32(path))){ + return std::format("{}: expected 01.00 to refuse it.", name); + } + } + return true; + } +}; + +// "Confirm Choices" on console B in each game language, one frame per +// highlighted row (2026-11-13). The file name ends in that row: +// PokemonLZA/AutoStoryConfirmChoices/_.png. +class Test_ConfirmChoicesFrame : public ImageUnitTest{ +public: + explicit Test_ConfirmChoicesFrame(const std::string& image) + : ImageUnitTest("PokemonLZA::AutoStory - Confirm Choices - " + image, {image}) + {} + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, const std::vector& images + ) const override{ + const std::string& path = image_paths()[0]; + const size_t underscore = path.rfind('_'); + if (underscore == std::string::npos || underscore + 1 >= path.size()){ + return "Error: the file name does not end in _."; + } + const size_t expected = (size_t)(path[underscore + 1] - '0'); + const std::optional cursor = read_confirm_choices_cursor(images[0]); + if (!cursor){ + return std::format("Expected Confirm Choices with row {} highlighted, read no Confirm Choices.", expected); + } + if (*cursor != expected){ + return std::format("Expected row {} highlighted, read row {}.", expected, *cursor); + } + return true; + } +}; + +} // namespace + + +void add_tests_AutoStoryConfirmChoicesReader(UnitTestDatabase& database){ + for (const SyntheticCase& item : SYNTHETIC_CASES){ + database.add(item); + } + database.add(); + for (const std::string_view language : { + "English", "Spanish", "SpanishLatAm", "French", "German", + "Italian", "Japanese", "Korean", "ChineseSimplified", "ChineseTraditional", + }){ + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + database.add(std::format("PokemonLZA/AutoStoryConfirmChoices/{}_{}.png", language, row)); + } + } +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h new file mode 100644 index 0000000000..67a4d291fa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h @@ -0,0 +1,28 @@ +/* PokemonLZA AutoStory - Confirm Choices reader Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryConfirmChoicesReader_Tests_H +#define PokemonAutomation_PokemonLZA_AutoStoryConfirmChoicesReader_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Registers the Confirm Choices reader's tests: synthetic frames always; +// console B's frames in each language from the test images +// (PokemonLZA/AutoStoryConfirmChoices/), and the other intro screens from +// the folder in PLZA_INTRO_SCREENS, skipped when unset. +void add_tests_AutoStoryConfirmChoicesReader(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 cbe126b3c2..4790fea105 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -21,7 +21,6 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" -#include "Actions/PokemonLZA_AutoStoryIntro.h" #include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" @@ -78,23 +77,6 @@ AutoStory::AutoStory() LockMode::LOCK_WHILE_RUNNING, false ) - , PLAYER_NAME( - false, - "Player Name:
New game only. Letters and digits; a capital only as the first letter.", - LockMode::LOCK_WHILE_RUNNING, - "Kosmos", - "Kosmos" - ) - , PLAYER_LOOK( - "Player Look:
New game only. 1 to 8: left to right along the top row, then the bottom row.", - LockMode::LOCK_WHILE_RUNNING, - 1, 1, (uint8_t)LOOK_COUNT - ) - , NAME_FIRST_LETTER_AUTO_CAPS( - "Keyboard Capitalizes the First Letter:
New game only. Tick if the name comes out in lower case: the name keyboard capitalizes by itself and Shift would undo it.", - LockMode::LOCK_WHILE_RUNNING, - false - ) , GO_HOME_WHEN_DONE(false) , NOTIFICATIONS({ &NOTIFICATION_PROGRAM_FINISH, @@ -105,9 +87,6 @@ AutoStory::AutoStory() PA_ADD_OPTION(RUN); PA_ADD_OPTION(BATTLE_AI); PA_ADD_OPTION(RELOAD_AT_BOUNDARIES); - PA_ADD_OPTION(PLAYER_NAME); - PA_ADD_OPTION(PLAYER_LOOK); - PA_ADD_OPTION(NAME_FIRST_LETTER_AUTO_CAPS); PA_ADD_OPTION(GO_HOME_WHEN_DONE); PA_ADD_OPTION(NOTIFICATIONS); } @@ -116,7 +95,7 @@ namespace{ // Checkpoints after the new game start from a save (01.01 from the // platform autosave), so the run loads it first instead of assuming the -// game is already there. 00.00 and 01.00 start without one. +// game is already there. 01.00 starts without one. void load_start_save( ConsoleHandle& console, const StoryGame& game, StoryBackend& backend, const std::vector& rows, size_t first @@ -155,7 +134,7 @@ StoryData load_run_story(ConsoleHandle& console){ // 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_confirms_new_game(first_row)){ + if (story_row_starts_without_save(first_row)){ require_confirm_choices(console, context); } require_player(console, context, BUTTON_L); @@ -171,29 +150,6 @@ StoryGame run_game(StoryEnv& story, const StoryData& data, StoryBreakp return game; } -} // namespace - -NewGameChoices AutoStory::new_game_choices(ConsoleHandle& console, bool check) const{ - NewGameChoices choices{.name = PLAYER_NAME, .look = PLAYER_LOOK, .name_first_letter_auto_caps = NAME_FIRST_LETTER_AUTO_CAPS}; - const std::string problem = check ? new_game_problem(RUN.language(), choices) : std::string(); - if (!problem.empty()){ - throw UserSetupError(console, problem); - } - return choices; -} - -void AutoStory::start_program_border_check(VideoStream& stream, FeedbackType feedback_type){ - const std::vector& rows = story_checkpoints(); - const size_t first = RUN.start_index(); - if (first < rows.size() && story_row_launches_game(rows[first])){ - stream.log(std::format("AutoStory: {} launches the game; the black border check waits for HOME.", rows[first].id)); - return; - } - SingleSwitchProgramInstance::start_program_border_check(stream, feedback_type); -} - -namespace{ - // `run`'s attempts per checkpoint, and the boundary reload `reload_at_boundaries` // picks; logs which. StoryRunPolicy run_policy(const Pokemon::StoryRunOptions& run, const BooleanCheckBoxOption& reload_at_boundaries, Logger& logger){ @@ -218,8 +174,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex connect_controller(env.console, context, rows[first]); StoryEnv story{ - .env = env, .context = context, .new_game = new_game_choices(env.console, story_row_launches_game(rows[first])), - .language = RUN.language(), .battle_ai = BATTLE_AI + .env = env, .context = context, .language = RUN.language(), .battle_ai = BATTLE_AI }; PlzaConsoleBackend backend(story); const StoryGame game = run_game(story, story_data, RUN.breakpoints(), context); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index 625c9dedc6..a452bc8882 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -18,8 +18,6 @@ #define PokemonAutomation_PokemonLZA_AutoStory_H #include "Common/Cpp/Options/BooleanCheckBoxOption.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" @@ -50,27 +48,13 @@ class AutoStory : public SingleSwitchProgramInstance{ virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; - // The start frame's black border check, except for a start checkpoint - // that launches the game (story_row_launches_game()): the launch checks - // the border on HOME instead. - virtual void start_program_border_check(VideoStream& stream, FeedbackType feedback_type) override; - private: - // The new game's choices; with `check`, throws UserSetupError for ones the - // intro cannot play. - NewGameChoices new_game_choices(ConsoleHandle& console, bool check) const; - // The start and end checkpoints, attempts, checks and language. Pokemon::StoryRunOptions RUN; BattleAIOption BATTLE_AI; // Off: a run of several checkpoints runs straight on at the rows whose // plans say "reload_when_chained"; on: it reloads the save there. BooleanCheckBoxOption RELOAD_AT_BOUNDARIES; - // The new game's choices (00.00): the language is RUN's. The look and - // the language list's order are guesses from Scarlet/Violet's screens. - StringOption PLAYER_NAME; - SimpleIntegerOption PLAYER_LOOK; - BooleanCheckBoxOption NAME_FIRST_LETTER_AUTO_CAPS; GoHomeWhenDoneOption GO_HOME_WHEN_DONE; EventNotificationsOption NOTIFICATIONS; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h index cd8a1c5667..9989979198 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.h @@ -26,7 +26,6 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryBackend.h" #include "Pokemon/AutoStory/Engine/Pokemon_StoryGame.h" #include "VideoGames/PokemonLZA/Options/PokemonLZA_BattleAIOption.h" -#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.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" @@ -47,10 +46,9 @@ namespace PokemonLZA{ struct StoryEnv{ SingleSwitchProgramEnvironment& env; ProControllerContext& context; - // The new game's name and look. - NewGameChoices new_game; - // The game's language: the new game's pick, and the steps that read text. - Language language = Language::English; + // The language the game is set to, for the steps that read text (the + // fast travel menu's place names). + Language language = Language::None; BattleAIOption& battle_ai; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index 589f2b8c98..c2f1a4ae81 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -211,9 +211,9 @@ UnitTestResult test_refused_steps(CancellableScope& scope){ return "Expected a tile walk to fail the lint."; } FakeBackend backend = fake_plza({look_at(0ms)}, scope); - const Pokemon::StoryEngineReport report = run_plza(backend, step_of("00.00", "language")); + const Pokemon::StoryEngineReport report = run_plza(backend, step_of("01.00", "confirm")); if (report.run.failure.failure != "console_only"){ - return std::format("Expected the new game's language to need a console, got {}", to_string(report.run.failure)); + return std::format("Expected Confirm Choices to need a console, got {}", to_string(report.run.failure)); } const std::vector> unknown{ {Pokemon::StoryStepKind::MASH, "x"}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp index 38fe0ff395..3eb56af153 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.cpp @@ -70,12 +70,6 @@ using ConsoleStep = void (*)(StoryEnv& env); // The GAME actions that are one ConsoleStep each, by name: console_only. const std::map>& console_game_actions(){ static const std::map> actions{ - {"launch_game_from_home", [](StoryEnv& env){ launch_game_from_home(env.env.console, env.context); }}, - {"new_game_language", [](StoryEnv& env){ new_game_language(env.env.console, env.context, env.language); }}, - {"pick_look", [](StoryEnv& env){ pick_player_look(env.env.console, env.context, env.new_game.look); }}, - {"type_player_name", [](StoryEnv& env){ - type_player_name(env.env.console, env.context, env.new_game.name, env.new_game.name_first_letter_auto_caps); - }}, {"confirm_new_game", [](StoryEnv& env){ confirm_new_game_choices(env.env.console, env.context); }}, {"choose_0", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 0); }}, {"choose_1", [](StoryEnv& env){ choose_dialog_option(env.env.console, env.context, 1); }}, diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h index 2a8d23fb2c..94216e4eee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryGame.h @@ -58,9 +58,7 @@ const std::map>& story_actions_not_impleme // "opening_to_platform"; the scene machines // "mash_to_move_hints" (args min_length_ms, quiet_ms) and // "text_to_choice" (run_scene_machine()); a console step, one -// call through the game's own screens with no args: the new -// game's "launch_game_from_home", "new_game_language", -// "pick_look", "type_player_name" (00.00), and +// call through the game's own screens with no args: // "confirm_new_game" (01.00, on "Confirm Choices"); // "choose_0" / "choose_1" (that row of the choices on screen); // or an action of story_actions_not_implemented() diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h index 09d34e5ff8..c4f7d917df 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryStoryFiles.h @@ -42,10 +42,9 @@ StoryData load_story_data(std::span dev_files); const StoryData& builtin_story_data(); // The built-in story (load_story_data() with no dev files), read once: -// what the tests, the lint and the program's dropdowns use: 00.00 and -// 01.00, a new game to the station platform, which start without a save: -// 00.00 on the HOME screen with PLZA's tile selected, 01.00 on the new -// game's "Confirm Choices", its choices made by hand. +// what the tests, the lint and the program's dropdowns use. The first, +// 01.00, plays a new game to the station platform without a save, from +// the new game's "Confirm Choices", its choices made by hand. const std::vector& story_checkpoints(); // The built-in rows that end on one of the game's autosaves. Each ends diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp index 0cc521402a..ea30e96a57 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.cpp @@ -47,30 +47,15 @@ bool first_game_action_is(const StoryCheckpoint& row, std::string_view action){ } // namespace -bool story_row_launches_game(const StoryCheckpoint& row){ - return first_game_action_is(row, "launch_game_from_home"); -} - -bool story_row_confirms_new_game(const StoryCheckpoint& row){ - return first_game_action_is(row, "confirm_new_game"); -} - bool story_row_starts_without_save(const StoryCheckpoint& row){ - return story_row_launches_game(row) || story_row_confirms_new_game(row); + return first_game_action_is(row, "confirm_new_game"); } std::vector story_run_rows(const std::vector& checkpoints, size_t first, size_t last){ - std::vector rows; if (first > last || last >= checkpoints.size()){ - return rows; - } - for (size_t index = first; index <= last; index++){ - if (index > first && story_row_confirms_new_game(checkpoints[index])){ - continue; - } - rows.push_back(checkpoints[index]); + return {}; } - return rows; + return std::vector(checkpoints.begin() + first, checkpoints.begin() + last + 1); } diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h index 72c478529c..5037fb1188 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable.h @@ -74,25 +74,13 @@ bool story_row_saves(const StoryData& story, const Pokemon::StoryCheckpoint& row // story_actions_not_implemented(): the part of the story a run can play. size_t story_rows_ready(const std::vector& checkpoints); -// Whether `row` starts by launching the game from HOME (its first step is -// the GAME action "launch_game_from_home"): 00.00. The game may be in front on any -// screen, a dark scene too, so the frame at the program's start says nothing -// about the screen size and the black border check waits for HOME. -bool story_row_launches_game(const Pokemon::StoryCheckpoint& row); - -// Whether `row` 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. It plays what 00.00 plays after the name. -bool story_row_confirms_new_game(const Pokemon::StoryCheckpoint& row); - -// Whether `row` starts with no save to load: it launches the game or -// confirms a new game. +// 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. bool story_row_starts_without_save(const Pokemon::StoryCheckpoint& row); -// The rows a run from `first` to `last` of `checkpoints` plays, in order: -// all of them but a row that confirms a new game after the run's first -// row, which played it already. Empty if `first` comes after `last` or -// `last` is past the end. +// The rows a run from `first` to `last` of `checkpoints` plays, in order. +// Empty if `first` comes after `last` or `last` is past the end. std::vector story_run_rows( const std::vector& checkpoints, size_t first, size_t last ); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index aae253abf8..72c0590bd1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -14,8 +14,6 @@ #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" -#include "CommonFramework/ImageTypes/ImageRGB32.h" -#include "CommonTools/VisualDetectors/BlackBorderDetector.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryScreenEvents.h" #include "PokemonLZA_AutoStoryStoryFiles.h" @@ -33,9 +31,8 @@ using Pokemon::StoryCheckpoint; using Pokemon::StoryStep; using Pokemon::StoryStepKind; -// The table: ids unique and in order, each row but the new game's (00.00 -// and 01.00) starts somewhere, and each lints against PLZA's actions in -// the engine. +// The table: ids unique and in order, each row but the new game's (01.00) +// starts somewhere, and each lints against PLZA's actions in the engine. UnitTestResult test_story_table_lints(Logger&){ std::string previous; for (const StoryCheckpoint& row : story_checkpoints()){ @@ -51,8 +48,8 @@ UnitTestResult test_story_table_lints(Logger&){ return problems[0]; } } - if (story_checkpoints().size() < 2 || story_checkpoints()[0].id != "00.00" || story_checkpoints()[1].id != "01.00"){ - return "Expected the table to start at 00.00 and 01.00, the new game."; + if (story_checkpoints().empty() || story_checkpoints()[0].id != "01.00"){ + return "Expected the table to start at 01.00, the new game."; } return true; } @@ -230,39 +227,15 @@ struct AutoStoryTableInput{ struct AutoStoryTableExpectation{ }; -// A black start frame (the previous run stopped in a dark scene) trips the -// black border check: a run from 00.00, which launches the game, leaves the -// check to HOME; a run from any later row still refuses on it. -UnitTestResult test_black_start_frame(Logger&){ - ImageRGB32 black(1920, 1080); - black.fill(0xff000000); - BlackBorderDetector border; - if (!border.detect(black)){ - return "Expected the black border check to refuse an all-black frame."; - } - for (const StoryCheckpoint& row : story_checkpoints()){ - const bool launches = story_row_launches_game(row); - if (launches != (row.id == "00.00")){ - return std::format("{}: launches the game: {}; only 00.00 should.", row.id, launches); - } - } - return true; -} - -// The new game's two starts: 00.00 launches from HOME and plays every -// choice, 01.00 starts on "Confirm Choices" after the choices made by hand. -// Neither loads a save, every later row does, and a run from 00.00 skips -// 01.00, which it has played. +// The new game's start: 01.00 starts on "Confirm Choices" after the +// choices made by hand, without a save; every later row loads one. A run +// plays every row from its start to its end. UnitTestResult test_new_game_rows(Logger&){ const std::vector& rows = story_checkpoints(); for (const StoryCheckpoint& row : rows){ - const bool confirms = story_row_confirms_new_game(row); - if (confirms != (row.id == "01.00")){ - return std::format("{}: starts on Confirm Choices: {}; only 01.00 should.", row.id, confirms); - } const bool no_save = story_row_starts_without_save(row); - if (no_save != (row.id == "00.00" || row.id == "01.00")){ - return std::format("{}: starts without a save: {}; only 00.00 and 01.00 should.", row.id, no_save); + if (no_save != (row.id == "01.00")){ + return std::format("{}: starts without a save: {}; only 01.00 should.", row.id, no_save); } } const size_t last = rows.size() - 1; @@ -273,12 +246,8 @@ UnitTestResult test_new_game_rows(Logger&){ } return text; }; - const std::vector from_setup = story_run_rows(rows, 0, last); - if (from_setup.size() != rows.size() - 1 || from_setup[0].id != "00.00" || (from_setup.size() > 1 && from_setup[1].id == "01.00")){ - return std::format("A run from 00.00: expected every row but 01.00, got {}.", ids(from_setup)); - } - const std::vector from_confirm = story_run_rows(rows, 1, last); - if (from_confirm.size() != rows.size() - 1 || from_confirm[0].id != "01.00"){ + const std::vector from_confirm = story_run_rows(rows, 0, last); + if (from_confirm.size() != rows.size() || from_confirm[0].id != "01.00"){ return std::format("A run from 01.00: expected every row from 01.00, got {}.", ids(from_confirm)); } if (!story_run_rows(rows, 1, 0).empty() || !story_run_rows(rows, 0, rows.size()).empty()){ @@ -343,11 +312,7 @@ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { .expectation = {}, }, { - .input = {"Start checks: a black start frame refuses every row but 00.00", test_black_start_frame}, - .expectation = {}, - }, - { - .input = {"Start checks: 00.00 and 01.00 start the new game without a save; a run from 00.00 skips 01.00", test_new_game_rows}, + .input = {"Start checks: 01.00 starts the new game without a save; a run plays every row", test_new_game_rows}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json deleted file mode 100644 index 9281202c94..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/StoryData/plza-00.00.plan.json +++ /dev/null @@ -1,50 +0,0 @@ -{ - "format": "pokesim-authored-checkpoint/1", - "game": "plza", - "checkpoint": { - "id": "00.00", - "title": "New game from HOME to the station platform", - "events": [ - { - "id": "launch_from_home", - "kind": "game_action", - "why": "step 0: with PLZA in front (any screen, mid-scene too) or on the HOME screen with its tile selected: HOME once if HOME is not showing (the game in front stays the selected tile), close it if it is running (X, A), launch the selected tile without moving the cursor, user select / license check, wait for the language list (no save: a new game opens on it)", - "action": "launch_game_from_home" - }, - { - "id": "language", - "kind": "game_action", - "why": "step 1: on the language list, move the highlight to the run's language (English) and press A", - "action": "new_game_language" - }, - { - "id": "look", - "kind": "game_action", - "why": "step 2: pick the first look", - "action": "pick_look" - }, - { - "id": "name", - "kind": "game_action", - "why": "steps 3-4: name the player and confirm", - "action": "type_player_name" - }, - { - "id": "opening", - "kind": "game_action", - "why": "step 5: the opening cutscene, no presses (A does not advance it), until the autosave badge has shown and the station platform holds", - "action": "opening_to_platform", - "args": { - "timeout_ms": 240000 - } - } - ], - "metadata": { - "phase": "testing", - "source": "console B recording, 2026-11-08/09: played step by step from a new game" - } - }, - "execution": { - "save": "autosave" - } -} 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 d0c807002a..6d69611e20 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 @@ -23,7 +23,7 @@ ], "metadata": { "phase": "testing", - "source": "00.00's last two steps, console B recording 2026-11-08/09; Confirm Choices from console B, 2026-11-13" + "source": "console B recording 2026-11-08/09; Confirm Choices from console B, 2026-11-13" } }, "execution": { diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index bf0c65e3e2..f2285f7249 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2432,16 +2432,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.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_AutoStoryIntro.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro.h - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntroScreens.h - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryIntro_Tests.h - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.cpp - Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryLanguageList.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_AutoStoryScenes.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryWalkScreenChecks.cpp @@ -2450,6 +2440,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAdvanceArrowDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryAutosaveDetector.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp From 9af276bd246ca86d8d9c1dd255cc3fd4146055c5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 22:26:54 -0800 Subject: [PATCH 28/33] PokemonLZA: AutoStory: screen readers live in Detectors/ Detectors/ reads pixels and presses nothing; Actions/ presses. Moved unchanged: tutorial_card_shows() from Actions/Scenes to Detectors/PokemonLZA_AutoStoryTutorialCardDetector, and dialog_choice_box() from Actions/Dialogs to Detectors/PokemonLZA_AutoStoryDialogChoiceBox, so the screen events no longer include an action header. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryDialogs.cpp | 8 +--- .../Actions/PokemonLZA_AutoStoryDialogs.h | 13 ++----- .../Actions/PokemonLZA_AutoStoryScenes.cpp | 24 +----------- .../Actions/PokemonLZA_AutoStoryScenes.h | 8 +--- .../PokemonLZA_AutoStoryDialogChoiceBox.cpp | 23 +++++++++++ .../PokemonLZA_AutoStoryDialogChoiceBox.h | 30 ++++++++++++++ ...kemonLZA_AutoStoryTutorialCardDetector.cpp | 39 +++++++++++++++++++ ...PokemonLZA_AutoStoryTutorialCardDetector.h | 30 ++++++++++++++ .../PokemonLZA_AutoStoryScreenEvents.cpp | 2 +- SerialPrograms/cmake/SourceFiles.cmake | 4 ++ 10 files changed, 134 insertions(+), 47 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp index 237d6130e3..a1b3bd0416 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.cpp @@ -8,13 +8,13 @@ #include #include "Common/Cpp/Color.h" #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "CommonTools/Async/InferenceRoutines.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_DialogDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_OverworldPartySelectionDetector.h" #include "VideoGames/PokemonLZA/Inference/PokemonLZA_SelectionArrowDetector.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h" #include "PokemonLZA_AutoStoryDialogs.h" namespace PokemonAutomation{ @@ -66,12 +66,6 @@ void talk_to_facing(ConsoleHandle& console, ProControllerContext& context){ } } - -const ImageFloatBox& dialog_choice_box(){ - static const ImageFloatBox box{0.654308, 0.481553, 0.295529, 0.312621}; - return box; -} - namespace{ // The selection arrow's top among the choices, once it has held still; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h index 424c47c4a3..d317c032ab 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h @@ -12,7 +12,6 @@ #include #include "Common/Cpp/Time.h" -#include "CommonFramework/ImageTools/ImageBoxes.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" @@ -31,15 +30,11 @@ void mash_to_overworld(ConsoleHandle& console, ProControllerContext& context, Bu // dialogue box shows; throws OperationFailedException if none does. void talk_to_facing(ConsoleHandle& console, ProControllerContext& context); -// Where a dialogue's choices are drawn, and choose_dialog_option() looks -// for the selection arrow: the restaurant receptionist's (RestaurantFarmer). -// Other dialogues' choices are assumed to sit there. -const ImageFloatBox& dialog_choice_box(); - // With a dialogue's choices on screen, picks choice `index` (0 is the top): -// waits for the selection arrow, presses down until it has moved `index` -// rows, then A. Throws OperationFailedException if the arrow never shows or -// does not move. +// waits for the selection arrow in dialog_choice_box() +// (Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h), presses down until it +// has moved `index` rows, then A. Throws OperationFailedException if the +// arrow never shows or does not move. void choose_dialog_option(ConsoleHandle& console, ProControllerContext& context, size_t index); 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 5802435320..aaf366452a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.cpp @@ -7,10 +7,9 @@ #include #include #include "CommonFramework/Exceptions/OperationFailedExceptionWithScreenshot.h" -#include "CommonFramework/ImageTools/ImageBoxes.h" -#include "CommonFramework/ImageTools/ImageStats.h" #include "CommonFramework/VideoPipeline/VideoFeed.h" #include "NintendoSwitch/Commands/NintendoSwitch_Commands_PushButtons.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h" #include "PokemonLZA_AutoStoryScenes.h" namespace PokemonAutomation{ @@ -94,27 +93,6 @@ void log_event_change(ConsoleHandle& console, const ScreenEvents& events, Screen } // namespace -// A tutorial card (Map & Missions, Main Missions, Pokedex, ...): a white -// panel in the middle over a dark, blurred, even screen. Only A turns its -// pages (B turns back), so a B mash never closes it. Measured on 5 cards -// and 9 other screens (map, Pokedex, dialogs, overworld, night) on -// console B, 2026-11-10, at full resolution: cards' panel 241-246 bright -// (its text spreads it to 40-48) and edges 61-76 with spread under 7; the -// others' panel at most 185, or edges brighter or busy. -bool tutorial_card_shows(const ImageViewRGB32& frame){ - const ImageStats panel = image_stats(extract_box_reference(frame, ImageFloatBox(0.32, 0.62, 0.36, 0.20))); - if (panel.average.sum() / 3 < 225){ - return false; - } - for (const ImageFloatBox& side : {ImageFloatBox(0.03, 0.30, 0.15, 0.40), ImageFloatBox(0.82, 0.30, 0.15, 0.40)}){ - const ImageStats edge = image_stats(extract_box_reference(frame, side)); - if (edge.average.sum() / 3 > 100 || edge.stddev.sum() / 3 > 12){ - return false; - } - } - return true; -} - namespace{ // When a scene mash ends besides its goal: mash_scene()'s quiet end, and a 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 4f008b09ee..d2aadbd035 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryScenes.h @@ -12,7 +12,6 @@ #include #include "Common/Cpp/Time.h" -#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "NintendoSwitch/Controllers/NintendoSwitch_ControllerButtons.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" @@ -32,7 +31,7 @@ namespace PokemonLZA{ // A cutscene can hold a still frame longer than `quiet`, so the quiet end // waits for `min_length`, the scene's rough recorded length, to pass. // A tutorial card gets A whatever `text_button` is: only A turns its pages -// (tutorial_card_shows()). +// (tutorial_card_shows(), Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h). // Throws OperationFailedException if the goal does not show within `timeout`. void mash_scene( ConsoleHandle& console, ProControllerContext& context, @@ -49,11 +48,6 @@ void mash_scene( void mash_story_scene(ConsoleHandle& console, ProControllerContext& context, Button text_button); -// A tutorial card on screen (Map & Missions, Main Missions, Pokedex, ...): -// a bright panel in the middle over dark, even edges. -bool tutorial_card_shows(const ImageViewRGB32& frame); - - } // namespace PokemonLZA diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp new file mode 100644 index 0000000000..f9f3c0cd7e --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp @@ -0,0 +1,23 @@ +/* PokemonLZA AutoStory - Dialog choice box + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonLZA_AutoStoryDialogChoiceBox.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +const ImageFloatBox& dialog_choice_box(){ + static const ImageFloatBox box{0.654308, 0.481553, 0.295529, 0.312621}; + return box; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h new file mode 100644 index 0000000000..8dbd035c54 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h @@ -0,0 +1,30 @@ +/* PokemonLZA AutoStory - Dialog choice box + * + * From: https://github.com/PokemonAutomation/ + * + * Where a dialogue's choices are drawn, for the selection arrow's + * detector: the screen events' choice box and choose_dialog_option() + * (Actions/PokemonLZA_AutoStoryDialogs.h) both read it. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryDialogChoiceBox_H +#define PokemonAutomation_PokemonLZA_AutoStoryDialogChoiceBox_H + +#include "CommonFramework/ImageTools/ImageBoxes.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// Where a dialogue's choices are drawn: the restaurant receptionist's +// (RestaurantFarmer). Other dialogues' choices are assumed to sit there. +const ImageFloatBox& dialog_choice_box(); + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.cpp new file mode 100644 index 0000000000..caeaf61408 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.cpp @@ -0,0 +1,39 @@ +/* PokemonLZA AutoStory - Tutorial card detector + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "CommonFramework/ImageTools/ImageBoxes.h" +#include "CommonFramework/ImageTools/ImageStats.h" +#include "PokemonLZA_AutoStoryTutorialCardDetector.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A white panel in the middle over a dark, blurred, even screen. Measured +// on 5 cards and 9 other screens (map, Pokedex, dialogs, overworld, night) +// on console B, 2026-11-10, at full resolution: cards' panel 241-246 +// bright (its text spreads it to 40-48) and edges 61-76 with spread under +// 7; the others' panel at most 185, or edges brighter or busy. +bool tutorial_card_shows(const ImageViewRGB32& frame){ + const ImageStats panel = image_stats(extract_box_reference(frame, ImageFloatBox(0.32, 0.62, 0.36, 0.20))); + if (panel.average.sum() / 3 < 225){ + return false; + } + for (const ImageFloatBox& side : {ImageFloatBox(0.03, 0.30, 0.15, 0.40), ImageFloatBox(0.82, 0.30, 0.15, 0.40)}){ + const ImageStats edge = image_stats(extract_box_reference(frame, side)); + if (edge.average.sum() / 3 > 100 || edge.stddev.sum() / 3 > 12){ + return false; + } + } + return true; +} + + + +} // namespace PokemonLZA +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h new file mode 100644 index 0000000000..fcea31caf5 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryTutorialCardDetector.h @@ -0,0 +1,30 @@ +/* PokemonLZA AutoStory - Tutorial card detector + * + * From: https://github.com/PokemonAutomation/ + * + * The tutorial cards the story opens (Map & Missions, Main Missions, + * Pokedex, ...). Only A turns their pages (B turns back), so a scene mash + * checks for one before it presses its text button. + * + */ + +#ifndef PokemonAutomation_PokemonLZA_AutoStoryTutorialCardDetector_H +#define PokemonAutomation_PokemonLZA_AutoStoryTutorialCardDetector_H + +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonLZA{ + + +// A tutorial card on screen: a bright panel in the middle over dark, even +// edges. +bool tutorial_card_shows(const ImageViewRGB32& frame); + + + +} // 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 fb29e1bbd1..3104b27187 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryScreenEvents.cpp @@ -8,7 +8,7 @@ #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" #include "CommonTools/Images/SolidColorTest.h" #include "CommonTools/ScreenEvents/ScreenFades.h" -#include "VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryDialogs.h" +#include "VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.h" #include "PokemonLZA_AutoStoryScreenEvents.h" namespace PokemonAutomation{ diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index f2285f7249..09eff91ac8 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2448,6 +2448,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryControlsHintDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDetectors_Tests.h + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.cpp + Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryDialogChoiceBox.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 @@ -2458,6 +2460,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryPlatformArrivalDetector.h Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.cpp Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStorySkipPromptDetector.h + 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_AutoStory.h Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryBackend.cpp From fa94e5687d21faff3cefb8f06d0b03c425bf70f3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 22:27:34 -0800 Subject: [PATCH 29/33] PokemonLZA: AutoStory: required Game Language option, as SV AutoStory's The language is now PLZA's own required option (no default), like PokemonSV AutoStory's: the language the game is set to, used to read the fast travel menu's place names. The shared run options' language dropdown is hidden for PLZA. Nothing checks that the game matches; a failed fly_to() names the language it read in and points at the option. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Actions/PokemonLZA_AutoStoryMoves.cpp | 5 +++-- .../Programs/AutoStory/PokemonLZA_AutoStory.cpp | 14 ++++++++++++-- .../Programs/AutoStory/PokemonLZA_AutoStory.h | 8 +++++++- 3 files changed, 22 insertions(+), 5 deletions(-) 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 a021ac17f2..453054bd60 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Actions/PokemonLZA_AutoStoryMoves.cpp @@ -94,8 +94,9 @@ void fly_to(ConsoleHandle& console, ProControllerContext& context, Language lang OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, std::format( - "fly_to(): could not fly to {} (state {}).", - get_location_item_from_enum(location).slug, static_cast(state) + "fly_to(): could not fly to {} (state {}). The fast travel menu is read in {}: " + "check that the Game Language option matches the game.", + get_location_item_from_enum(location).slug, static_cast(state), language_data(language).name ), console ); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 4790fea105..2707979acf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -21,6 +21,7 @@ #include "Pokemon/AutoStory/Engine/Pokemon_StoryEngine.h" #include "Pokemon/Options/Pokemon_GameLanguages.h" #include "Pokemon/Pokemon_Strings.h" +#include "VideoGames/PokemonLZA/Inference/Map/PokemonLZA_LocationNameReader.h" #include "Actions/PokemonLZA_AutoStoryConfirmChoices.h" #include "PokemonLZA_AutoStoryGame.h" #include "PokemonLZA_AutoStoryStoryFiles.h" @@ -70,7 +71,14 @@ const StringSelectDatabase& checkpoint_database(){ AutoStory::AutoStory() - : RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) + : LANGUAGE( + "Game Language:
The language the game is set to. The program reads text in it " + "(the place names in the fast travel menu) and does not check that the game matches.", + LocationNameOCR::instance().languages(), + LockMode::LOCK_WHILE_RUNNING, + true + ) + , RUN(checkpoint_database(), Gen8ToGen9Languages_Database()) , RELOAD_AT_BOUNDARIES( "Reload at Checkpoint Boundaries:
Reload the save before a checkpoint whose plan asks for it " "when the run comes from the checkpoint before. Off: run straight on. A failed checkpoint's retry reloads either way.", @@ -84,6 +92,8 @@ AutoStory::AutoStory() &NOTIFICATION_ERROR_FATAL, }) { + PA_ADD_OPTION(LANGUAGE); + RUN.LANGUAGE.set_visibility(ConfigOptionState::HIDDEN); PA_ADD_OPTION(RUN); PA_ADD_OPTION(BATTLE_AI); PA_ADD_OPTION(RELOAD_AT_BOUNDARIES); @@ -174,7 +184,7 @@ void AutoStory::program(SingleSwitchProgramEnvironment& env, ProControllerContex connect_controller(env.console, context, rows[first]); StoryEnv story{ - .env = env, .context = context, .language = RUN.language(), .battle_ai = BATTLE_AI + .env = env, .context = context, .language = LANGUAGE, .battle_ai = BATTLE_AI }; PlzaConsoleBackend backend(story); const StoryGame game = run_game(story, story_data, RUN.breakpoints(), context); diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h index a452bc8882..5d1c144629 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.h @@ -19,6 +19,7 @@ #include "Common/Cpp/Options/BooleanCheckBoxOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" +#include "CommonTools/Options/LanguageOCROption.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Options/Pokemon_StoryRunOptions.h" @@ -49,7 +50,12 @@ class AutoStory : public SingleSwitchProgramInstance{ virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext& context) override; private: - // The start and end checkpoints, attempts, checks and language. + // The language the game is set to, required: the steps that read text + // (the fast travel menu's place names) read it in this language. The + // program does not check that the game matches. + OCR::LanguageOCROption LANGUAGE; + // The start and end checkpoints, attempts and checks. Its own language + // dropdown is hidden: LANGUAGE above is PLZA's. Pokemon::StoryRunOptions RUN; BattleAIOption BATTLE_AI; // Off: a run of several checkpoints runs straight on at the rows whose From b03ad1dd42af5c85375b27b4df54878bbb31b783 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 22:27:34 -0800 Subject: [PATCH 30/33] PokemonLZA: AutoStory: describe the hand-picked new game start Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp index 2707979acf..4d51218b0e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStory.cpp @@ -40,7 +40,10 @@ AutoStory_Descriptor::AutoStory_Descriptor() "PokemonLZA:AutoStory", std::format("{} LZA", STRING_POKEMON), "Auto Story", "Programs/PokemonLZA/AutoStory.html", - "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. Checkpoint 01.00 (a new game) starts on the new game's Confirm Choices screen, with the language, look and name chosen by hand: it checks that screen, presses nothing anywhere else, and picks Ready!. Checkpoint 00.00 makes those choices too: it starts on the Switch HOME screen with PLZA's tile selected and no save, launches the selected tile without moving the cursor (closing it first if it is running) and plays the new game to the platform; a run from 00.00 skips 01.00. Go Home When Done leaves HOME with PLZA's tile selected, ready for the next new game.", + "Play the main story of Pokemon Legends: Z-A. Prototype: plays a new game to the station platform, as recorded on a console. " + "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 their save first. " + "Set Game Language to the language the game is set to: the program reads place names in it.", PanelQualityStanding::DEVELOPER, ProgramControllerClass::StandardController_NoRestrictions, FeedbackType::REQUIRED, From afb8b3ccec8644f85f4404dbe47cc5072678202f Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 22:33:22 -0800 Subject: [PATCH 31/33] PokemonLZA: AutoStory: Confirm Choices reader tests as case tables Each test is built from one case (input, expectation) of a named table, as the code-health test-case rule asks. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...ZA_AutoStoryConfirmChoicesReader_Tests.cpp | 216 ++++++++++++------ 1 file changed, 142 insertions(+), 74 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp index ff020183f5..ce10f9a0aa 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp @@ -58,114 +58,185 @@ ImageRGB32 flat_frame(uint32_t color){ return image; } +std::string describe_cursor(std::optional cursor){ + return cursor ? std::format("row {}", *cursor) : std::string("no Confirm Choices"); +} + + struct SyntheticInput{ + std::string name; std::function frame; }; struct SyntheticExpectation{ - // The row read; nullopt: not Confirm Choices. - std::optional cursor; + std::optional cursor; // The row read; none: not Confirm Choices. }; struct SyntheticCase{ - std::string name; SyntheticInput input; SyntheticExpectation expectation; }; const SyntheticCase SYNTHETIC_CASES[] = { - {"row 0 highlighted", {[]{ return confirm_choices_frame({0}); }}, {0}}, - {"row 1 highlighted", {[]{ return confirm_choices_frame({1}); }}, {1}}, - {"Ready! highlighted", {[]{ return confirm_choices_frame({CONFIRM_CHOICES_READY_ROW}); }}, {CONFIRM_CHOICES_READY_ROW}}, - {"no row highlighted", {[]{ return confirm_choices_frame({}); }}, {std::nullopt}}, - {"two rows highlighted", {[]{ return confirm_choices_frame({0, 1}); }}, {std::nullopt}}, - {"flat black", {[]{ return flat_frame(0xff000000); }}, {std::nullopt}}, - {"flat white", {[]{ return flat_frame(WHITE); }}, {std::nullopt}}, - {"flat background", {[]{ return flat_frame(BACKGROUND); }}, {std::nullopt}}, - {"flat slate", {[]{ return flat_frame(SLATE); }}, {std::nullopt}}, - {"empty frame", {[]{ return ImageRGB32(); }}, {std::nullopt}}, - {"1 x 1 frame", {[]{ return ImageRGB32(1, 1); }}, {std::nullopt}}, - {"40 x 20 frame", {[]{ return ImageRGB32(40, 20); }}, {std::nullopt}}, + {.input = {.name = "row 0 highlighted", .frame = []{ return confirm_choices_frame({0}); }}, .expectation = {.cursor = 0}}, + {.input = {.name = "row 1 highlighted", .frame = []{ return confirm_choices_frame({1}); }}, .expectation = {.cursor = 1}}, + { + .input = {.name = "Ready! highlighted", .frame = []{ return confirm_choices_frame({CONFIRM_CHOICES_READY_ROW}); }}, + .expectation = {.cursor = CONFIRM_CHOICES_READY_ROW}, + }, + {.input = {.name = "no row highlighted", .frame = []{ return confirm_choices_frame({}); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "two rows highlighted", .frame = []{ return confirm_choices_frame({0, 1}); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "flat black", .frame = []{ return flat_frame(0xff000000); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "flat white", .frame = []{ return flat_frame(WHITE); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "flat background", .frame = []{ return flat_frame(BACKGROUND); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "flat slate", .frame = []{ return flat_frame(SLATE); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "an empty frame", .frame = []{ return ImageRGB32(); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "a 1 x 1 frame", .frame = []{ return ImageRGB32(1, 1); }}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "a 40 x 20 frame", .frame = []{ return ImageRGB32(40, 20); }}, .expectation = {.cursor = std::nullopt}}, }; -std::string describe_cursor(std::optional cursor){ - return cursor ? std::format("row {}", *cursor) : std::string("no Confirm Choices"); -} - class Test_ConfirmChoicesSynthetic : public UnitTest{ public: - explicit Test_ConfirmChoicesSynthetic(const SyntheticCase& test_case) - : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {}", test_case.name)) - , m_case(test_case) + explicit Test_ConfirmChoicesSynthetic(const SyntheticCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {}", test.input.name)) + , m_test(test) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const std::optional cursor = read_confirm_choices_cursor(m_case.input.frame()); - if (cursor != m_case.expectation.cursor){ - return std::format( - "Expected {}, read {}.", describe_cursor(m_case.expectation.cursor), describe_cursor(cursor) - ); + const std::optional cursor = read_confirm_choices_cursor(m_test.input.frame()); + if (cursor != m_test.expectation.cursor){ + return std::format("Expected {}, read {}.", describe_cursor(m_test.expectation.cursor), describe_cursor(cursor)); } return true; } private: - const SyntheticCase& m_case; + const SyntheticCase& m_test; +}; + + +// The folder named by the environment variable `variable`; none if it is +// unset or not a folder. +std::optional env_folder(std::string_view variable){ + const auto* value = std::getenv(std::string(variable).c_str()); + if (value == nullptr){ + return std::nullopt; + } + std::string folder(value); + if (!Filesystem::is_directory(Filesystem::Path(folder))){ + return std::nullopt; + } + return folder; +} + +// 01.00's start check on console B's intro screens, from the folder in +// PLZA_INTRO_SCREENS: it accepts Confirm Choices as it opens, and refuses +// every other intro screen. A file the folder lacks is skipped. +struct CaptureInput{ + std::string name; + std::string_view file; +}; + +struct CaptureExpectation{ + std::optional cursor; +}; + +struct CaptureCase{ + CaptureInput input; + CaptureExpectation expectation; +}; + +const CaptureCase CAPTURE_CASES[] = { + {.input = {.name = "Confirm Choices as it opens", .file = "confirm-choices.png"}, .expectation = {.cursor = 0}}, + {.input = {.name = "HOME", .file = "home.png"}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "a game in front", .file = "in-game.png"}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "the language list", .file = "language-list.png"}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "the look picker", .file = "look-picker.png"}, .expectation = {.cursor = std::nullopt}}, + {.input = {.name = "the name keyboard", .file = "keyboard.png"}, .expectation = {.cursor = std::nullopt}}, }; -// 01.00's start check on console B's frames, from the folder in -// PLZA_INTRO_SCREENS: it accepts confirm-choices.png, "Change hair -// color" highlighted as the screen opens, and refuses every other intro -// screen there. class Test_ConfirmChoicesCapture : public UnitTest{ public: - Test_ConfirmChoicesCapture() - : UnitTest("PokemonLZA::AutoStory - Confirm Choices reader: console B's intro screens (PLZA_INTRO_SCREENS)") + explicit Test_ConfirmChoicesCapture(const CaptureCase& test) + : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {} (PLZA_INTRO_SCREENS)", test.input.name)) + , m_test(test) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const char* folder = std::getenv("PLZA_INTRO_SCREENS"); - if (folder == nullptr || !Filesystem::is_directory(Filesystem::Path(folder))){ + const std::optional folder = env_folder("PLZA_INTRO_SCREENS"); + if (!folder){ return UnitTestResult(UnitTestResult::SKIPPED, "PLZA_INTRO_SCREENS is not a folder."); } - const std::optional cursor = read_confirm_choices_cursor(ImageRGB32(std::format("{}/confirm-choices.png", folder))); - if (cursor != size_t(0)){ - return "confirm-choices.png: expected Confirm Choices with row 0 highlighted."; + const std::string path = std::format("{}/{}", *folder, m_test.input.file); + if (!Filesystem::exists(Filesystem::Path(path))){ + return UnitTestResult(UnitTestResult::SKIPPED, std::format("{} is not in the folder.", m_test.input.file)); } - for (const std::string_view name : {"home.png", "in-game.png", "language-list.png", "look-picker.png", "keyboard.png"}){ - const std::string path = std::format("{}/{}", folder, name); - if (!Filesystem::exists(Filesystem::Path(path))){ - continue; - } - if (is_confirm_choices(ImageRGB32(path))){ - return std::format("{}: expected 01.00 to refuse it.", name); - } + const std::optional cursor = read_confirm_choices_cursor(ImageRGB32(path)); + if (cursor != m_test.expectation.cursor){ + return std::format( + "{}: expected {}, read {}.", m_test.input.file, describe_cursor(m_test.expectation.cursor), describe_cursor(cursor) + ); } return true; } + +private: + const CaptureCase& m_test; }; + // "Confirm Choices" on console B in each game language, one frame per -// highlighted row (2026-11-13). The file name ends in that row: -// PokemonLZA/AutoStoryConfirmChoices/_.png. -class Test_ConfirmChoicesFrame : public ImageUnitTest{ +// highlighted row (2026-11-13): PokemonLZA/AutoStoryConfirmChoices/ +// _.png, row 0 to CONFIRM_CHOICES_READY_ROW. Each frame +// reads as its row. +struct LanguageFramesInput{ + std::string name; + std::string_view language; +}; + +struct LanguageFramesExpectation{ +}; + +struct LanguageFramesCase{ + LanguageFramesInput input; + LanguageFramesExpectation expectation; +}; + +const LanguageFramesCase LANGUAGE_FRAMES_CASES[] = { + {.input = {.name = "English", .language = "English"}, .expectation = {}}, + {.input = {.name = "Spanish", .language = "Spanish"}, .expectation = {}}, + {.input = {.name = "Latin American Spanish", .language = "SpanishLatAm"}, .expectation = {}}, + {.input = {.name = "French", .language = "French"}, .expectation = {}}, + {.input = {.name = "German", .language = "German"}, .expectation = {}}, + {.input = {.name = "Italian", .language = "Italian"}, .expectation = {}}, + {.input = {.name = "Japanese", .language = "Japanese"}, .expectation = {}}, + {.input = {.name = "Korean", .language = "Korean"}, .expectation = {}}, + {.input = {.name = "Simplified Chinese", .language = "ChineseSimplified"}, .expectation = {}}, + {.input = {.name = "Traditional Chinese", .language = "ChineseTraditional"}, .expectation = {}}, +}; + +std::vector language_frame_paths(std::string_view language){ + std::vector paths; + for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ + paths.push_back(std::format("PokemonLZA/AutoStoryConfirmChoices/{}_{}.png", language, row)); + } + return paths; +} + +class Test_ConfirmChoicesFrames : public ImageUnitTest{ public: - explicit Test_ConfirmChoicesFrame(const std::string& image) - : ImageUnitTest("PokemonLZA::AutoStory - Confirm Choices - " + image, {image}) + explicit Test_ConfirmChoicesFrames(const LanguageFramesCase& test) + : ImageUnitTest( + std::format("PokemonLZA::AutoStory - Confirm Choices - {}", test.input.name), + language_frame_paths(test.input.language) + ) {} virtual UnitTestResult run_on_images( Logger&, CancellableScope&, const std::vector& images ) const override{ - const std::string& path = image_paths()[0]; - const size_t underscore = path.rfind('_'); - if (underscore == std::string::npos || underscore + 1 >= path.size()){ - return "Error: the file name does not end in _."; - } - const size_t expected = (size_t)(path[underscore + 1] - '0'); - const std::optional cursor = read_confirm_choices_cursor(images[0]); - if (!cursor){ - return std::format("Expected Confirm Choices with row {} highlighted, read no Confirm Choices.", expected); - } - if (*cursor != expected){ - return std::format("Expected row {} highlighted, read row {}.", expected, *cursor); + for (size_t row = 0; row < images.size(); row++){ + const std::optional cursor = read_confirm_choices_cursor(images[row]); + if (cursor != row){ + return std::format("{}: expected row {}, read {}.", image_paths()[row], row, describe_cursor(cursor)); + } } return true; } @@ -175,17 +246,14 @@ class Test_ConfirmChoicesFrame : public ImageUnitTest{ void add_tests_AutoStoryConfirmChoicesReader(UnitTestDatabase& database){ - for (const SyntheticCase& item : SYNTHETIC_CASES){ - database.add(item); + for (const SyntheticCase& test : SYNTHETIC_CASES){ + database.add(test); } - database.add(); - for (const std::string_view language : { - "English", "Spanish", "SpanishLatAm", "French", "German", - "Italian", "Japanese", "Korean", "ChineseSimplified", "ChineseTraditional", - }){ - for (size_t row = 0; row <= CONFIRM_CHOICES_READY_ROW; row++){ - database.add(std::format("PokemonLZA/AutoStoryConfirmChoices/{}_{}.png", language, row)); - } + for (const CaptureCase& test : CAPTURE_CASES){ + database.add(test); + } + for (const LanguageFramesCase& test : LANGUAGE_FRAMES_CASES){ + database.add(test); } } From 8ba4d8706fdd782c923bf66f7230a1b7dc513a5f Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 22:34:46 -0800 Subject: [PATCH 32/33] PokemonLZA: AutoStory: test cases keep the name outside the input The code-health test-case rule now wants each case as a name, an Input struct and an Expectation struct. Converts the Confirm Choices reader, engine, scene machine and story table tables; the cases are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...ZA_AutoStoryConfirmChoicesReader_Tests.cpp | 121 +++++++++--------- .../PokemonLZA_AutoStoryEngine_Tests.cpp | 42 +++--- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 46 ++++--- .../PokemonLZA_AutoStoryTable_Tests.cpp | 36 +++--- 4 files changed, 117 insertions(+), 128 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp index ce10f9a0aa..1226c359ac 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/Detectors/PokemonLZA_AutoStoryConfirmChoicesReader_Tests.cpp @@ -63,42 +63,41 @@ std::string describe_cursor(std::optional cursor){ } -struct SyntheticInput{ - std::string name; - std::function frame; -}; - -struct SyntheticExpectation{ - std::optional cursor; // The row read; none: not Confirm Choices. -}; - struct SyntheticCase{ - SyntheticInput input; - SyntheticExpectation expectation; + std::string name; + struct Input{ + std::function frame; + }; + Input input; + struct Expectation{ + std::optional cursor; // The row read; none: not Confirm Choices. + }; + Expectation expectation; }; const SyntheticCase SYNTHETIC_CASES[] = { - {.input = {.name = "row 0 highlighted", .frame = []{ return confirm_choices_frame({0}); }}, .expectation = {.cursor = 0}}, - {.input = {.name = "row 1 highlighted", .frame = []{ return confirm_choices_frame({1}); }}, .expectation = {.cursor = 1}}, + {.name = "row 0 highlighted", .input = {.frame = []{ return confirm_choices_frame({0}); }}, .expectation = {.cursor = 0}}, + {.name = "row 1 highlighted", .input = {.frame = []{ return confirm_choices_frame({1}); }}, .expectation = {.cursor = 1}}, { - .input = {.name = "Ready! highlighted", .frame = []{ return confirm_choices_frame({CONFIRM_CHOICES_READY_ROW}); }}, + .name = "Ready! highlighted", + .input = {.frame = []{ return confirm_choices_frame({CONFIRM_CHOICES_READY_ROW}); }}, .expectation = {.cursor = CONFIRM_CHOICES_READY_ROW}, }, - {.input = {.name = "no row highlighted", .frame = []{ return confirm_choices_frame({}); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "two rows highlighted", .frame = []{ return confirm_choices_frame({0, 1}); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "flat black", .frame = []{ return flat_frame(0xff000000); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "flat white", .frame = []{ return flat_frame(WHITE); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "flat background", .frame = []{ return flat_frame(BACKGROUND); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "flat slate", .frame = []{ return flat_frame(SLATE); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "an empty frame", .frame = []{ return ImageRGB32(); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "a 1 x 1 frame", .frame = []{ return ImageRGB32(1, 1); }}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "a 40 x 20 frame", .frame = []{ return ImageRGB32(40, 20); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "no row highlighted", .input = {.frame = []{ return confirm_choices_frame({}); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "two rows highlighted", .input = {.frame = []{ return confirm_choices_frame({0, 1}); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "flat black", .input = {.frame = []{ return flat_frame(0xff000000); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "flat white", .input = {.frame = []{ return flat_frame(WHITE); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "flat background", .input = {.frame = []{ return flat_frame(BACKGROUND); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "flat slate", .input = {.frame = []{ return flat_frame(SLATE); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "an empty frame", .input = {.frame = []{ return ImageRGB32(); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "a 1 x 1 frame", .input = {.frame = []{ return ImageRGB32(1, 1); }}, .expectation = {.cursor = std::nullopt}}, + {.name = "a 40 x 20 frame", .input = {.frame = []{ return ImageRGB32(40, 20); }}, .expectation = {.cursor = std::nullopt}}, }; class Test_ConfirmChoicesSynthetic : public UnitTest{ public: explicit Test_ConfirmChoicesSynthetic(const SyntheticCase& test) - : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {}", test.input.name)) + : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {}", test.name)) , m_test(test) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -131,33 +130,31 @@ std::optional env_folder(std::string_view variable){ // 01.00's start check on console B's intro screens, from the folder in // PLZA_INTRO_SCREENS: it accepts Confirm Choices as it opens, and refuses // every other intro screen. A file the folder lacks is skipped. -struct CaptureInput{ - std::string name; - std::string_view file; -}; - -struct CaptureExpectation{ - std::optional cursor; -}; - struct CaptureCase{ - CaptureInput input; - CaptureExpectation expectation; + std::string name; + struct Input{ + std::string_view file; + }; + Input input; + struct Expectation{ + std::optional cursor; + }; + Expectation expectation; }; const CaptureCase CAPTURE_CASES[] = { - {.input = {.name = "Confirm Choices as it opens", .file = "confirm-choices.png"}, .expectation = {.cursor = 0}}, - {.input = {.name = "HOME", .file = "home.png"}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "a game in front", .file = "in-game.png"}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "the language list", .file = "language-list.png"}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "the look picker", .file = "look-picker.png"}, .expectation = {.cursor = std::nullopt}}, - {.input = {.name = "the name keyboard", .file = "keyboard.png"}, .expectation = {.cursor = std::nullopt}}, + {.name = "Confirm Choices as it opens", .input = {.file = "confirm-choices.png"}, .expectation = {.cursor = 0}}, + {.name = "HOME", .input = {.file = "home.png"}, .expectation = {.cursor = std::nullopt}}, + {.name = "a game in front", .input = {.file = "in-game.png"}, .expectation = {.cursor = std::nullopt}}, + {.name = "the language list", .input = {.file = "language-list.png"}, .expectation = {.cursor = std::nullopt}}, + {.name = "the look picker", .input = {.file = "look-picker.png"}, .expectation = {.cursor = std::nullopt}}, + {.name = "the name keyboard", .input = {.file = "keyboard.png"}, .expectation = {.cursor = std::nullopt}}, }; class Test_ConfirmChoicesCapture : public UnitTest{ public: explicit Test_ConfirmChoicesCapture(const CaptureCase& test) - : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {} (PLZA_INTRO_SCREENS)", test.input.name)) + : UnitTest(std::format("PokemonLZA::AutoStory - Confirm Choices reader: {} (PLZA_INTRO_SCREENS)", test.name)) , m_test(test) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ @@ -187,30 +184,28 @@ class Test_ConfirmChoicesCapture : public UnitTest{ // highlighted row (2026-11-13): PokemonLZA/AutoStoryConfirmChoices/ // _.png, row 0 to CONFIRM_CHOICES_READY_ROW. Each frame // reads as its row. -struct LanguageFramesInput{ - std::string name; - std::string_view language; -}; - -struct LanguageFramesExpectation{ -}; - struct LanguageFramesCase{ - LanguageFramesInput input; - LanguageFramesExpectation expectation; + std::string name; + struct Input{ + std::string_view language; + }; + Input input; + struct Expectation{ + }; + Expectation expectation; }; const LanguageFramesCase LANGUAGE_FRAMES_CASES[] = { - {.input = {.name = "English", .language = "English"}, .expectation = {}}, - {.input = {.name = "Spanish", .language = "Spanish"}, .expectation = {}}, - {.input = {.name = "Latin American Spanish", .language = "SpanishLatAm"}, .expectation = {}}, - {.input = {.name = "French", .language = "French"}, .expectation = {}}, - {.input = {.name = "German", .language = "German"}, .expectation = {}}, - {.input = {.name = "Italian", .language = "Italian"}, .expectation = {}}, - {.input = {.name = "Japanese", .language = "Japanese"}, .expectation = {}}, - {.input = {.name = "Korean", .language = "Korean"}, .expectation = {}}, - {.input = {.name = "Simplified Chinese", .language = "ChineseSimplified"}, .expectation = {}}, - {.input = {.name = "Traditional Chinese", .language = "ChineseTraditional"}, .expectation = {}}, + {.name = "English", .input = {.language = "English"}, .expectation = {}}, + {.name = "Spanish", .input = {.language = "Spanish"}, .expectation = {}}, + {.name = "Latin American Spanish", .input = {.language = "SpanishLatAm"}, .expectation = {}}, + {.name = "French", .input = {.language = "French"}, .expectation = {}}, + {.name = "German", .input = {.language = "German"}, .expectation = {}}, + {.name = "Italian", .input = {.language = "Italian"}, .expectation = {}}, + {.name = "Japanese", .input = {.language = "Japanese"}, .expectation = {}}, + {.name = "Korean", .input = {.language = "Korean"}, .expectation = {}}, + {.name = "Simplified Chinese", .input = {.language = "ChineseSimplified"}, .expectation = {}}, + {.name = "Traditional Chinese", .input = {.language = "ChineseTraditional"}, .expectation = {}}, }; std::vector language_frame_paths(std::string_view language){ @@ -225,7 +220,7 @@ class Test_ConfirmChoicesFrames : public ImageUnitTest{ public: explicit Test_ConfirmChoicesFrames(const LanguageFramesCase& test) : ImageUnitTest( - std::format("PokemonLZA::AutoStory - Confirm Choices - {}", test.input.name), + std::format("PokemonLZA::AutoStory - Confirm Choices - {}", test.name), language_frame_paths(test.input.language) ) {} diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp index c2f1a4ae81..b4af8fe9b1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryEngine_Tests.cpp @@ -475,23 +475,21 @@ UnitTestResult test_walk_pauses_before_each_leg(CancellableScope& scope){ } -struct EngineTestInput{ - std::string name; - std::function body; -}; - -struct EngineTestExpectation{ -}; - struct EngineTestCase{ - EngineTestInput input; - EngineTestExpectation expectation; + std::string name; + struct Input{ + std::function body; + }; + Input input; + struct Expectation{ + }; + Expectation expectation; }; class Test_AutoStoryEngine : public UnitTest{ public: explicit Test_AutoStoryEngine(EngineTestCase test_case) - : UnitTest(std::format("PokemonLZA::AutoStoryEngine - {}", test_case.input.name)) + : UnitTest(std::format("PokemonLZA::AutoStoryEngine - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger&, CancellableScope& scope) const override{ @@ -510,17 +508,17 @@ class Test_AutoStoryEngine : public UnitTest{ const EngineTestCase ENGINE_TEST_CASES[] = { - {.input = {"01.00 opening: no presses, done on two looks at the platform after the autosave", test_opening_waits_for_platform}, .expectation = {}}, - {.input = {"01.00 opening: one A at the arrival text with the advance arrow", test_opening_presses_through_arrival_text}, .expectation = {}}, - {.input = {"face_heading: turns by the minimap's heading", test_face_heading}, .expectation = {}}, - {.input = {"refused: console actions off a console, tile walks, unknown actions", test_refused_steps}, .expectation = {}}, - {.input = {"every checkpoint runs in step order, testing never saves", test_every_checkpoint_runs}, .expectation = {}}, - {.input = {"reload_when_chained: reload between the rows, as its own event", test_reload_when_chained}, .expectation = {}}, - {.input = {"reload_when_chained: no reload from the row's save or for other rows", test_no_reload_unless_chained}, .expectation = {}}, - {.input = {"reload_when_chained: a reload onto the platform fails", test_reload_lands_on_older_save}, .expectation = {}}, - {.input = {"reload_when_chained: straight through, no reload at a boundary", test_straight_through_has_no_reload}, .expectation = {}}, - {.input = {"walk_to_prompt: walks until the A prompt, none when it shows", test_walk_to_prompt}, .expectation = {}}, - {.input = {"breakpoints: a walk pauses before each leg", test_walk_pauses_before_each_leg}, .expectation = {}}, + {.name = "01.00 opening: no presses, done on two looks at the platform after the autosave", .input = {.body = test_opening_waits_for_platform}, .expectation = {}}, + {.name = "01.00 opening: one A at the arrival text with the advance arrow", .input = {.body = test_opening_presses_through_arrival_text}, .expectation = {}}, + {.name = "face_heading: turns by the minimap's heading", .input = {.body = test_face_heading}, .expectation = {}}, + {.name = "refused: console actions off a console, tile walks, unknown actions", .input = {.body = test_refused_steps}, .expectation = {}}, + {.name = "every checkpoint runs in step order, testing never saves", .input = {.body = test_every_checkpoint_runs}, .expectation = {}}, + {.name = "reload_when_chained: reload between the rows, as its own event", .input = {.body = test_reload_when_chained}, .expectation = {}}, + {.name = "reload_when_chained: no reload from the row's save or for other rows", .input = {.body = test_no_reload_unless_chained}, .expectation = {}}, + {.name = "reload_when_chained: a reload onto the platform fails", .input = {.body = test_reload_lands_on_older_save}, .expectation = {}}, + {.name = "reload_when_chained: straight through, no reload at a boundary", .input = {.body = test_straight_through_has_no_reload}, .expectation = {}}, + {.name = "walk_to_prompt: walks until the A prompt, none when it shows", .input = {.body = test_walk_to_prompt}, .expectation = {}}, + {.name = "breakpoints: a walk pauses before each leg", .input = {.body = test_walk_pauses_before_each_leg}, .expectation = {}}, }; void add_tests_AutoStoryEngine(UnitTestDatabase& database){ 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 7bc693d1ea..59cc14af9e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -321,23 +321,21 @@ UnitTestResult test_to_battle(Logger&){ } -struct SceneMachineInput{ - std::string name; - std::function body; -}; - -struct SceneMachineExpectation{ -}; - struct SceneMachineCase{ - SceneMachineInput input; - SceneMachineExpectation expectation; + std::string name; + struct Input{ + std::function body; + }; + Input input; + struct Expectation{ + }; + Expectation expectation; }; class Test_AutoStorySceneMachine : public UnitTest{ public: explicit Test_AutoStorySceneMachine(SceneMachineCase test_case) - : UnitTest(std::format("PokemonLZA::AutoStorySceneMachine - {}", test_case.input.name)) + : UnitTest(std::format("PokemonLZA::AutoStorySceneMachine - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ @@ -353,55 +351,55 @@ class Test_AutoStorySceneMachine : public UnitTest{ const SceneMachineCase SCENE_MACHINE_CASES[] = { { - .input = {"quiet end waits for the scene's minimum length", test_quiet_waits_for_min_length}, + .name = "quiet end waits for the scene's minimum length", .input = {.body = test_quiet_waits_for_min_length}, .expectation = {}, }, { - .input = {"a box or a fade restarts the quiet time", test_quiet_restarts_on_busy}, + .name = "a box or a fade restarts the quiet time", .input = {.body = test_quiet_restarts_on_busy}, .expectation = {}, }, { - .input = {"the party bar held a second ends the scene", test_party_bar_held}, + .name = "the party bar held a second ends the scene", .input = {.body = test_party_bar_held}, .expectation = {}, }, { - .input = {"the controls hint held a second ends the scene", test_controls_hint_held}, + .name = "the controls hint held a second ends the scene", .input = {.body = test_controls_hint_held}, .expectation = {}, }, { - .input = {"the ad's subtitles: A at the chevron, blind A, none at the hint", test_ad_subtitles}, + .name = "the ad's subtitles: A at the chevron, blind A, none at the hint", .input = {.body = test_ad_subtitles}, .expectation = {}, }, { - .input = {"the mission banner on two looks ends the scene", test_mission_banner_ends}, + .name = "the mission banner on two looks ends the scene", .input = {.body = test_mission_banner_ends}, .expectation = {}, }, { - .input = {"the mission complete card: A, busy, wins over the banner", test_mission_complete_presses_a}, + .name = "the mission complete card: A, busy, wins over the banner", .input = {.body = test_mission_complete_presses_a}, .expectation = {}, }, { - .input = {"the mission banner does not end a mash to a choice", test_mission_banner_only_overworld}, + .name = "the mission banner does not end a mash to a choice", .input = {.body = test_mission_banner_only_overworld}, .expectation = {}, }, { - .input = {"blind presses keep the quiet end, and only in an A mash", test_blind_press_keeps_quiet}, + .name = "blind presses keep the quiet end, and only in an A mash", .input = {.body = test_blind_press_keeps_quiet}, .expectation = {}, }, { - .input = {"without a quiet time a still screen never ends it", test_no_quiet_never_ends_still}, + .name = "without a quiet time a still screen never ends it", .input = {.body = test_no_quiet_never_ends_still}, .expectation = {}, }, { - .input = {"B through the text to the choice", test_text_to_choice}, + .name = "B through the text to the choice", .input = {.body = test_text_to_choice}, .expectation = {}, }, { - .input = {"A through the cards to the battle HUD", test_to_battle}, + .name = "A through the cards to the battle HUD", .input = {.body = test_to_battle}, .expectation = {}, }, { - .input = {"what each state presses", test_state_actions}, + .name = "what each state presses", .input = {.body = test_state_actions}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index 72c0590bd1..e372523b3f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -219,14 +219,6 @@ UnitTestResult test_scene_mash_rule(Logger&){ } -struct AutoStoryTableInput{ - std::string name; - std::function body; -}; - -struct AutoStoryTableExpectation{ -}; - // The new game's start: 01.00 starts on "Confirm Choices" after the // choices made by hand, without a save; every later row loads one. A run // plays every row from its start to its end. @@ -257,14 +249,20 @@ UnitTestResult test_new_game_rows(Logger&){ } struct AutoStoryTableCase{ - AutoStoryTableInput input; - AutoStoryTableExpectation expectation; + std::string name; + struct Input{ + std::function body; + }; + Input input; + struct Expectation{ + }; + Expectation expectation; }; class Test_AutoStoryTable : public UnitTest{ public: explicit Test_AutoStoryTable(AutoStoryTableCase test_case) - : UnitTest(std::format("PokemonLZA::AutoStory - {}", test_case.input.name)) + : UnitTest(std::format("PokemonLZA::AutoStory - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ @@ -284,35 +282,35 @@ class Test_AutoStoryTable : public UnitTest{ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { { - .input = {"Story table: rows lint against PLZA's engine actions", test_story_table_lints}, + .name = "Story table: rows lint against PLZA's engine actions", .input = {.body = test_story_table_lints}, .expectation = {}, }, { - .input = {"Story table: actions not implemented say what they wait for", test_not_implemented_actions}, + .name = "Story table: actions not implemented say what they wait for", .input = {.body = test_not_implemented_actions}, .expectation = {}, }, { - .input = {"Story table: the autosave rows, and 01.03 saves through the menu", test_autosave_rows}, + .name = "Story table: the autosave rows, and 01.03 saves through the menu", .input = {.body = test_autosave_rows}, .expectation = {}, }, { - .input = {"Story table: every row is ready", test_every_row_ready}, + .name = "Story table: every row is ready", .input = {.body = test_every_row_ready}, .expectation = {}, }, { - .input = {"reload_when_chained: only true, only after an autosave row, never on a new game row", test_reload_when_chained_field}, + .name = "reload_when_chained: only true, only after an autosave row, never on a new game row", .input = {.body = test_reload_when_chained_field}, .expectation = {}, }, { - .input = {"Scene mash: a scene that never starts fails at its start window", test_scene_start_window}, + .name = "Scene mash: a scene that never starts fails at its start window", .input = {.body = test_scene_start_window}, .expectation = {}, }, { - .input = {"Scene mash: what each frame presses", test_scene_mash_rule}, + .name = "Scene mash: what each frame presses", .input = {.body = test_scene_mash_rule}, .expectation = {}, }, { - .input = {"Start checks: 01.00 starts the new game without a save; a run plays every row", test_new_game_rows}, + .name = "Start checks: 01.00 starts the new game without a save; a run plays every row", .input = {.body = test_new_game_rows}, .expectation = {}, }, }; From 8545388fb33573c7d9f4559d99d440dee059f574 Mon Sep 17 00:00:00 2001 From: dayfine Date: Fri, 13 Nov 2026 22:37:38 -0800 Subject: [PATCH 33/33] PokemonLZA: AutoStory: one field per line in the multi-line test cases Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- ...PokemonLZA_AutoStorySceneMachine_Tests.cpp | 39 ++++++++++++------- .../PokemonLZA_AutoStoryTable_Tests.cpp | 24 ++++++++---- 2 files changed, 42 insertions(+), 21 deletions(-) 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 59cc14af9e..524be158e1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStorySceneMachine_Tests.cpp @@ -351,55 +351,68 @@ class Test_AutoStorySceneMachine : public UnitTest{ const SceneMachineCase SCENE_MACHINE_CASES[] = { { - .name = "quiet end waits for the scene's minimum length", .input = {.body = test_quiet_waits_for_min_length}, + .name = "quiet end waits for the scene's minimum length", + .input = {.body = test_quiet_waits_for_min_length}, .expectation = {}, }, { - .name = "a box or a fade restarts the quiet time", .input = {.body = test_quiet_restarts_on_busy}, + .name = "a box or a fade restarts the quiet time", + .input = {.body = test_quiet_restarts_on_busy}, .expectation = {}, }, { - .name = "the party bar held a second ends the scene", .input = {.body = test_party_bar_held}, + .name = "the party bar held a second ends the scene", + .input = {.body = test_party_bar_held}, .expectation = {}, }, { - .name = "the controls hint held a second ends the scene", .input = {.body = test_controls_hint_held}, + .name = "the controls hint held a second ends the scene", + .input = {.body = test_controls_hint_held}, .expectation = {}, }, { - .name = "the ad's subtitles: A at the chevron, blind A, none at the hint", .input = {.body = test_ad_subtitles}, + .name = "the ad's subtitles: A at the chevron, blind A, none at the hint", + .input = {.body = test_ad_subtitles}, .expectation = {}, }, { - .name = "the mission banner on two looks ends the scene", .input = {.body = test_mission_banner_ends}, + .name = "the mission banner on two looks ends the scene", + .input = {.body = test_mission_banner_ends}, .expectation = {}, }, { - .name = "the mission complete card: A, busy, wins over the banner", .input = {.body = test_mission_complete_presses_a}, + .name = "the mission complete card: A, busy, wins over the banner", + .input = {.body = test_mission_complete_presses_a}, .expectation = {}, }, { - .name = "the mission banner does not end a mash to a choice", .input = {.body = test_mission_banner_only_overworld}, + .name = "the mission banner does not end a mash to a choice", + .input = {.body = test_mission_banner_only_overworld}, .expectation = {}, }, { - .name = "blind presses keep the quiet end, and only in an A mash", .input = {.body = test_blind_press_keeps_quiet}, + .name = "blind presses keep the quiet end, and only in an A mash", + .input = {.body = test_blind_press_keeps_quiet}, .expectation = {}, }, { - .name = "without a quiet time a still screen never ends it", .input = {.body = test_no_quiet_never_ends_still}, + .name = "without a quiet time a still screen never ends it", + .input = {.body = test_no_quiet_never_ends_still}, .expectation = {}, }, { - .name = "B through the text to the choice", .input = {.body = test_text_to_choice}, + .name = "B through the text to the choice", + .input = {.body = test_text_to_choice}, .expectation = {}, }, { - .name = "A through the cards to the battle HUD", .input = {.body = test_to_battle}, + .name = "A through the cards to the battle HUD", + .input = {.body = test_to_battle}, .expectation = {}, }, { - .name = "what each state presses", .input = {.body = test_state_actions}, + .name = "what each state presses", + .input = {.body = test_state_actions}, .expectation = {}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp index e372523b3f..7584f5fdbd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonLZA/Programs/AutoStory/PokemonLZA_AutoStoryTable_Tests.cpp @@ -282,35 +282,43 @@ class Test_AutoStoryTable : public UnitTest{ const AutoStoryTableCase AUTO_STORY_TABLE_CASES[] = { { - .name = "Story table: rows lint against PLZA's engine actions", .input = {.body = test_story_table_lints}, + .name = "Story table: rows lint against PLZA's engine actions", + .input = {.body = test_story_table_lints}, .expectation = {}, }, { - .name = "Story table: actions not implemented say what they wait for", .input = {.body = test_not_implemented_actions}, + .name = "Story table: actions not implemented say what they wait for", + .input = {.body = test_not_implemented_actions}, .expectation = {}, }, { - .name = "Story table: the autosave rows, and 01.03 saves through the menu", .input = {.body = test_autosave_rows}, + .name = "Story table: the autosave rows, and 01.03 saves through the menu", + .input = {.body = test_autosave_rows}, .expectation = {}, }, { - .name = "Story table: every row is ready", .input = {.body = test_every_row_ready}, + .name = "Story table: every row is ready", + .input = {.body = test_every_row_ready}, .expectation = {}, }, { - .name = "reload_when_chained: only true, only after an autosave row, never on a new game row", .input = {.body = test_reload_when_chained_field}, + .name = "reload_when_chained: only true, only after an autosave row, never on a new game row", + .input = {.body = test_reload_when_chained_field}, .expectation = {}, }, { - .name = "Scene mash: a scene that never starts fails at its start window", .input = {.body = test_scene_start_window}, + .name = "Scene mash: a scene that never starts fails at its start window", + .input = {.body = test_scene_start_window}, .expectation = {}, }, { - .name = "Scene mash: what each frame presses", .input = {.body = test_scene_mash_rule}, + .name = "Scene mash: what each frame presses", + .input = {.body = test_scene_mash_rule}, .expectation = {}, }, { - .name = "Start checks: 01.00 starts the new game without a save; a run plays every row", .input = {.body = test_new_game_rows}, + .name = "Start checks: 01.00 starts the new game without a save; a run plays every row", + .input = {.body = test_new_game_rows}, .expectation = {}, }, };