From 9d6d1a8d448675b28216c5e2fdcef04c57259a48 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 19:36:40 -0800 Subject: [PATCH 01/13] [FRLG RNG] Check free party slots in applicable RNG programs The RNG programs' documentation lists how many free party slots each one needs. Check that at program startup through a new pre-startup hook, start_program_game_checks(), instead of failing after a catch or gift goes to the box. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../NintendoSwitch_SingleSwitchProgram.cpp | 1 + .../NintendoSwitch_SingleSwitchProgram.h | 9 + .../PokemonFRLG/PokemonFRLG_Navigation.cpp | 15 +- .../PokemonFRLG/PokemonFRLG_Navigation.h | 3 + .../PokemonFRLG/PokemonFRLG_Tests.cpp | 291 ++++++++++++++++++ .../RngManipulation/PokemonFRLG_EggRng.h | 7 +- .../RngManipulation/PokemonFRLG_GiftRng.h | 6 +- .../RngManipulation/PokemonFRLG_RngHelper.h | 7 +- .../PokemonFRLG_RngProgram.cpp | 95 ++++++ .../RngManipulation/PokemonFRLG_RngProgram.h | 79 +++++ .../PokemonFRLG_RoamingLegendaryRng.h | 6 +- .../RngManipulation/PokemonFRLG_StarterRng.h | 7 +- .../RngManipulation/PokemonFRLG_StaticRng.h | 6 +- .../RngManipulation/PokemonFRLG_WildRng.h | 9 +- SerialPrograms/cmake/SourceFiles.cmake | 2 + 15 files changed, 520 insertions(+), 23 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp index 8f4e94ab65..cbb210b0b7 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp @@ -86,6 +86,7 @@ void SingleSwitchProgramInstance::program(SingleSwitchProgramEnvironment& env, C }; try{ + start_program_game_checks(env, context); program(env, context); }catch (FatalProgramException&){ record_debug_video(); diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h index 9c464ca3a7..b44bb655a1 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h @@ -86,6 +86,15 @@ class SingleSwitchProgramInstance : public GameConsole::ConsoleProgramInstance{ FeedbackType feedback_type ); + // Called with the controller ready, just before program(env, context). + // Override to check that the game is set up the way the program needs + // (e.g. a free party slot) and throw UserSetupError if not, so a setup + // mistake stops the program before it starts its work. + virtual void start_program_game_checks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context + ){} + private: virtual void program(GameConsole::ConsoleProgramEnvironment& env, CancellableScope& scope) override; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp index 970080ca26..8de1341438 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp @@ -839,18 +839,15 @@ void open_party_menu_from_overworld(ConsoleHandle& console, ProControllerContext } PartySlot detect_last_occupied_party_slot(ConsoleHandle& console){ - const auto snapshot = console.video().snapshot(); - constexpr std::array slots{ - PartySlot::SIX, - PartySlot::FIVE, - PartySlot::FOUR, - PartySlot::THREE, - PartySlot::TWO, - }; + return detect_last_occupied_party_slot(console.video().snapshot()); +} + +PartySlot detect_last_occupied_party_slot(const ImageViewRGB32& screen){ + constexpr std::array slots{PartySlot::SIX, PartySlot::FIVE, PartySlot::FOUR, PartySlot::THREE, PartySlot::TWO}; for (PartySlot slot : slots){ PartyEmptySlotDetector empty_slot_detector(COLOR_RED, slot); - if (!empty_slot_detector.detect(snapshot)){ + if (!empty_slot_detector.detect(screen)){ return slot; } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h index e802a4be6d..b19ead8d00 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h @@ -10,6 +10,7 @@ #define PokemonAutomation_PokemonFRLG_Navigation_H #include "Common/Cpp/Logging/AbstractLogger.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Language.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" @@ -136,6 +137,8 @@ void open_party_menu_from_overworld(ConsoleHandle& console, ProControllerContext // Starting from the party menu, detect the last occupied party slot PartySlot detect_last_occupied_party_slot(ConsoleHandle& console); +// Detect the last occupied party slot on a screenshot of the party menu +PartySlot detect_last_occupied_party_slot(const ImageViewRGB32& screen); // Starting from the start menu, a sub-screen of the start menu, or the overworld, navigate to the bag void open_bag_from_overworld(ConsoleHandle& console, ProControllerContext& context, StartMenuContext menu_context = StartMenuContext::STANDARD); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 49d9b56265..f8bcb64246 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -4,8 +4,16 @@ * */ +#include #include +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Filesystem/Filesystem.h" +#include "Common/Cpp/Json/JsonObject.h" +#include "Common/Cpp/Json/JsonValue.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/StaticGlobals.h" #include "Inference/Box/PokemonFRLG_BoxCellOccupiedDetector.h" @@ -28,7 +36,16 @@ #include "Inference/PokemonFRLG_TrainerIdReader.h" #include "Inference/PokemonFRLG_WildEncounterReader.h" #include "Programs/BoxOrganization/PokemonFRLG_BoxSorter_Tests.h" +#include "Programs/RngManipulation/PokemonFRLG_EggRng.h" +#include "Programs/RngManipulation/PokemonFRLG_GiftRng.h" +#include "Programs/RngManipulation/PokemonFRLG_RngHelper.h" +#include "Programs/RngManipulation/PokemonFRLG_RngProgram.h" +#include "Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h" +#include "Programs/RngManipulation/PokemonFRLG_StarterRng.h" +#include "Programs/RngManipulation/PokemonFRLG_StaticRng.h" +#include "Programs/RngManipulation/PokemonFRLG_WildRng.h" #include "PokemonFRLG_Navigation.h" +#include "Tests/ImageUnitTest.h" #include "Tests/TestUtils.h" #include "PokemonFRLG_Tests.h" @@ -261,6 +278,277 @@ void add_tests_ExitWildBattle(UnitTestDatabase& database){ } } + +std::string slot_name(PartySlot slot){ + return std::to_string(static_cast(slot) + 1); +} + +// Reads the last occupied slot from a party menu screenshot, as the RNG programs' party check does. +class Test_LastOccupiedPartySlot : public ImageUnitTest{ +public: + Test_LastOccupiedPartySlot(std::string_view image, PartySlot expected) + : ImageUnitTest("PokemonFRLG::LastOccupiedPartySlot - " + std::string(image), {std::string(image)}) + , m_expected(expected) + {} + + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, + const std::vector& images + ) const override{ + const PartySlot slot = detect_last_occupied_party_slot(images[0]); + if (slot != m_expected){ + return std::format("Expected last occupied slot {}, got {}", slot_name(m_expected), slot_name(slot)); + } + return true; + } + +private: + const PartySlot m_expected; +}; + +void add_tests_LastOccupiedPartySlot(UnitTestDatabase& database){ + for (unsigned occupied = 1; occupied <= 6; occupied++){ + database.add( + "PokemonFRLG/Party/Party_" + std::to_string(occupied) + ".png", + static_cast(occupied - 1) + ); + } + database.add("PokemonFRLG/Party/Party_6_With_Held_Items.png", PartySlot::SIX); + database.add("PokemonFRLG/Party/JPN_HeldItem.png", PartySlot::SIX); + database.add("PokemonFRLG/Party/JPN_Party.png", PartySlot::FOUR); + database.add("PokemonFRLG/Party/SPA_HeldItem.png", PartySlot::SIX); +} + +// Steps that return scripted reads, and record what check_party_free_slots() asked for. +class ScriptedPartyCheck : public PartyCheckActions{ +public: + bool menu_opens = true; + PartySlot last_occupied = PartySlot::ONE; + std::string steps; + + virtual bool open_party_menu() override{ + steps += steps.empty() ? "open" : " open"; + return menu_opens; + } + virtual PartySlot read_last_occupied_slot() override{ + steps += steps.empty() ? "read" : " read"; + return last_occupied; + } +}; + +struct PartyCheckInput{ + std::string name; + size_t free_slots_needed = 1; + bool menu_opens = true; + PartySlot last_occupied = PartySlot::ONE; +}; + +struct PartyCheckExpectation{ + std::string steps = ""; + // Start of the UserSetupError message; empty if the check passes. + std::string error = ""; +}; + +struct PartyCheckCase{ + PartyCheckInput input; + PartyCheckExpectation expectation; +}; + +class Test_PartyCheck : public UnitTest{ +public: + Test_PartyCheck(PartyCheckCase test_case) + : UnitTest("PokemonFRLG::RngPartyCheck - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const PartyCheckInput& input = m_case.input; + const PartyCheckExpectation& expected = m_case.expectation; + ScriptedPartyCheck actions; + actions.menu_opens = input.menu_opens; + actions.last_occupied = input.last_occupied; + + NullLogger logger; + std::string error; + try{ + check_party_free_slots(logger, input.free_slots_needed, actions); + }catch (UserSetupError& e){ + error = e.message(); + } + const bool error_matches = expected.error.empty() + ? error.empty() + : error.rfind(expected.error, 0) == 0; + if (!error_matches){ + return std::format("Expected error: \"{}\"\nActual error: \"{}\"", expected.error, error); + } + if (actions.steps != expected.steps){ + return std::format("Expected steps: {}\nActual steps: {}", expected.steps, actions.steps); + } + return true; + } + +private: + const PartyCheckCase m_case; +}; + +void add_tests_PartyCheck(UnitTestDatabase& database){ + const PartyCheckCase cases[] = { + { + // Programs that don't add a Pokemon to the party don't open the menu. + .input = {.name = "no free slot needed, full party", .free_slots_needed = 0, .last_occupied = PartySlot::SIX}, + .expectation = {}, + }, + { + .input = {.name = "one free slot needed, one Pokemon"}, + .expectation = {.steps = "open read"}, + }, + { + .input = {.name = "one free slot needed, five Pokemon", .last_occupied = PartySlot::FIVE}, + .expectation = {.steps = "open read"}, + }, + { + .input = {.name = "one free slot needed, full party", .last_occupied = PartySlot::SIX}, + .expectation = {.steps = "open read", .error = "Your party is full. Leave a party slot free"}, + }, + { + .input = {.name = "three free slots needed, three Pokemon", .free_slots_needed = 3, .last_occupied = PartySlot::THREE}, + .expectation = {.steps = "open read"}, + }, + { + .input = {.name = "three free slots needed, four Pokemon", .free_slots_needed = 3, .last_occupied = PartySlot::FOUR}, + .expectation = {.steps = "open read", .error = "Your party has 4 "}, + }, + { + // A menu that can't be opened skips the check rather than stopping the program. + .input = {.name = "party menu not opened", .menu_opens = false, .last_occupied = PartySlot::SIX}, + .expectation = {.steps = "open"}, + }, + }; + for (const PartyCheckCase& test_case : cases){ + database.add(test_case); + } +} + + +std::string menu_context_name(StartMenuContext context){ + switch (context){ + case StartMenuContext::STANDARD: return "STANDARD"; + case StartMenuContext::SAFARI_ZONE: return "SAFARI_ZONE"; + case StartMenuContext::NO_DEX: return "NO_DEX"; + } + return "?"; +} + +template +std::unique_ptr make_rng_program(){ + return std::make_unique(); +} + +struct RngProgramPartyInput{ + std::string name; + std::function()> make_program; + // Program settings by option name, as in the saved settings JSON. + std::map settings = {}; +}; + +struct RngProgramPartyExpectation{ + size_t free_slots; + StartMenuContext menu_context = StartMenuContext::STANDARD; +}; + +struct RngProgramPartyCase{ + RngProgramPartyInput input; + RngProgramPartyExpectation expectation; +}; + +// Builds the program with the given settings and checks what its start check asks for. The +// check itself runs for every RNG program: RngProgramInstance's start hook is final. +class Test_RngProgramPartyRequirement : public UnitTest{ +public: + Test_RngProgramPartyRequirement(RngProgramPartyCase test_case) + : UnitTest("PokemonFRLG::RngProgramPartyRequirement - " + test_case.input.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const RngProgramPartyInput& input = m_case.input; + const RngProgramPartyExpectation& expected = m_case.expectation; + std::unique_ptr program = input.make_program(); + JsonObject settings; + for (const auto& [option, value] : input.settings){ + settings[option] = value; + } + program->load_json(JsonValue(std::move(settings))); + + const size_t free_slots = program->free_party_slots_needed(); + if (free_slots != expected.free_slots){ + return std::format("Expected {} free party slots needed, got {}", expected.free_slots, free_slots); + } + const StartMenuContext menu_context = program->start_menu_context(); + if (menu_context != expected.menu_context){ + return std::format( + "Expected start menu {}, got {}", menu_context_name(expected.menu_context), menu_context_name(menu_context) + ); + } + return true; + } + +private: + const RngProgramPartyCase m_case; +}; + +const RngProgramPartyCase RNG_PROGRAM_PARTY_CASES[] = { + { + .input = {.name = "StarterRng", .make_program = make_rng_program}, + .expectation = {.free_slots = 0}, + }, + { + // The egg and the two wild Pokemon caught to confirm the seed. + .input = {.name = "EggRng", .make_program = make_rng_program}, + .expectation = {.free_slots = 3}, + }, + { + .input = {.name = "GiftRng", .make_program = make_rng_program}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "StaticRng", .make_program = make_rng_program}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "RoamingLegendaryRng", .make_program = make_rng_program}, + .expectation = {.free_slots = 1}, + }, + { + .input = { + .name = "WildRng on Route 1", + .make_program = make_rng_program, + .settings = {{"GAME_LOCATION", "route_1"}}, + }, + .expectation = {.free_slots = 1}, + }, + { + // The Safari Zone start menu has no POKEMON entry in the usual place. + .input = { + .name = "WildRng in the Safari Zone", + .make_program = make_rng_program, + .settings = {{"GAME_LOCATION", "safari_zone_entrance"}}, + }, + .expectation = {.free_slots = 1, .menu_context = StartMenuContext::SAFARI_ZONE}, + }, + // RngHelper is the manual tool: whatever the target, it trusts the user's party. + { + .input = {.name = "RngHelper lapras", .make_program = make_rng_program, .settings = {{"TARGET", "lapras"}}}, + .expectation = {.free_slots = 0}, + }, +}; + +void add_tests_RngProgramPartyRequirement(UnitTestDatabase& database){ + for (const RngProgramPartyCase& test_case : RNG_PROGRAM_PARTY_CASES){ + database.add(test_case); + } +} + } @@ -279,12 +567,15 @@ void add_tests(UnitTestDatabase& database){ add_tests_EliteFourRoomDetector(database); add_tests_ExitWildBattle(database); add_tests_HallOfFameSavingDetector(database); + add_tests_LastOccupiedPartySlot(database); + add_tests_PartyCheck(database); add_tests_PartyEmptySlotDetector(database); add_tests_PartyHeldItemDetector(database); add_tests_PartyLevelUpReader(database); add_tests_PartyMenuDetector(database); add_tests_PrizeSelectDetector(database); add_tests_PartySlotDetector(database); + add_tests_RngProgramPartyRequirement(database); add_tests_StatsReader(database); add_tests_SelectionDialogDetector(database); add_tests_ShinySymbolDetector(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index 5462ee2eac..6adb83effc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h @@ -14,12 +14,12 @@ #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonFramework/Options/LabelCellOption.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Options/Pokemon_NameSelectOption.h" #include "Pokemon/Pokemon_AdvRng.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngCalibration.h" +#include "PokemonFRLG_RngProgram.h" #include "PokemonFRLG_RngStatsDatabase.h" #include "PokemonFRLG_RngDisplays.h" #include "PokemonFRLG_RngLoopRoutines.h" @@ -56,9 +56,12 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener{ +// Calibrates timings to hit an RNG target for a daycare egg. +class EggRng : public RngProgramInstance, public ConfigOption::Listener{ public: using Descriptor = EggRng_Descriptor; + // The egg and the two wild Pokemon caught to confirm the seed. + virtual size_t free_party_slots_needed() const override{ return 3; } ~EggRng(); EggRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h index 3df8e600ac..fc18d1b111 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h @@ -12,10 +12,10 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngDisplays.h" +#include "PokemonFRLG_RngProgram.h" #include "PokemonFRLG_SeedsDatabase.h" namespace PokemonAutomation{ @@ -29,9 +29,11 @@ class GiftRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class GiftRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +// Calibrates timings to hit an RNG target for a gift Pokemon. +class GiftRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = GiftRng_Descriptor; + virtual size_t free_party_slots_needed() const override{ return 1; } ~GiftRng(); GiftRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h index 3f4e694065..cbecd81a9e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h @@ -13,9 +13,9 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" +#include "PokemonFRLG_RngProgram.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -28,9 +28,12 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class RngHelper : public SingleSwitchProgramInstance{ +// Soft resets with given timings to hit a target seed and frame. +class RngHelper : public RngProgramInstance{ public: using Descriptor = RngHelper_Descriptor; + // The manual tool: the user sets the target and the party, so no check. + virtual size_t free_party_slots_needed() const override{ return 0; } RngHelper(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; virtual void start_program_border_check( diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp new file mode 100644 index 0000000000..573e991687 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -0,0 +1,95 @@ +/* RNG Program + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Pokemon/Pokemon_Strings.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" +#include "PokemonFRLG_RngProgram.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +namespace{ + +class ConsolePartyCheckActions : public PartyCheckActions{ +public: + ConsolePartyCheckActions(ConsoleHandle& console, ProControllerContext& context, StartMenuContext menu_context) + : m_console(console), m_context(context), m_menu_context(menu_context) + {} + + virtual bool open_party_menu() override{ + try{ + open_party_menu_from_overworld(m_console, m_context, m_menu_context); + }catch (OperationFailedException&){ + return false; + } + m_context.wait_for_all_requests(); + return true; + } + virtual PartySlot read_last_occupied_slot() override{ + return detect_last_occupied_party_slot(m_console); + } + +private: + ConsoleHandle& m_console; + ProControllerContext& m_context; + StartMenuContext m_menu_context; +}; + +std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ + if (free_slots_needed == 1){ + return std::format( + "Your party is full. Leave a party slot free so the program can check the {} it catches or receives.", + Pokemon::STRING_POKEMON + ); + } + return std::format( + "Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.", + party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON + ); +} + +} // namespace + + +void check_party_free_slots( + Logger& logger, + size_t free_slots_needed, + PartyCheckActions& actions +){ + if (free_slots_needed == 0){ + return; + } + logger.log("Checking for " + std::to_string(free_slots_needed) + " free party slot(s)..."); + if (!actions.open_party_menu()){ + logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); + return; + } + constexpr size_t MAX_PARTY_SIZE = 6; + const size_t party_size = static_cast(actions.read_last_occupied_slot()) + 1; + if (MAX_PARTY_SIZE - party_size < free_slots_needed){ + throw UserSetupError(logger, not_enough_free_slots_message(party_size, free_slots_needed)); + } + logger.log("Party has enough free slots."); +} + + +void RngProgramInstance::start_program_game_checks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context +){ + ConsolePartyCheckActions actions(env.console, context, start_menu_context()); + check_party_free_slots(env.console.logger(), free_party_slots_needed(), actions); +} + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h new file mode 100644 index 0000000000..8ec4935ef9 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -0,0 +1,79 @@ +/* RNG Program + * + * From: https://github.com/PokemonAutomation/ + * + * Base class for the FRLG RNG programs. Each program states what the game + * must look like when it starts, and the base class checks it before the + * program runs, so a setup mistake stops the run at once instead of failing + * in a misleading way many resets later. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_RngProgram_H +#define PokemonAutomation_PokemonFRLG_RngProgram_H + +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// The game steps that check_party_free_slots() takes. They are injected so +// that its decisions run in tests without a Switch. +class PartyCheckActions{ +public: + virtual ~PartyCheckActions() = default; + + // Open the party menu from the overworld. Returns false if it can't. + virtual bool open_party_menu() = 0; + + // Read the last occupied slot on the open party menu. + virtual PartySlot read_last_occupied_slot() = 0; +}; + +// Checks that the party has at least `free_slots_needed` free slots, +// starting from the overworld. Throws UserSetupError if it doesn't. If the +// party menu can't be opened, logs that and returns. May leave the party +// menu open. +void check_party_free_slots( + Logger& logger, + size_t free_slots_needed, + PartyCheckActions& actions +); + + +// Base class of the RNG programs. Before program() runs, it checks that the +// party has the free slots the program needs. +class RngProgramInstance : public SingleSwitchProgramInstance{ +public: + using SingleSwitchProgramInstance::SingleSwitchProgramInstance; + + // How many free party slots the program needs: one for each Pokemon it + // catches or receives and then reads from the end of the party. In a full + // party that Pokemon would go to the PC instead. + virtual size_t free_party_slots_needed() const = 0; + + // The start menu the player sees where the program starts. + virtual StartMenuContext start_menu_context() const{ + return StartMenuContext::STANDARD; + } + + // Runs with the game on the overworld where the player saved. May leave a + // menu open: the program's first reset closes the game. Final so that + // every RNG program runs the check free_party_slots_needed() asks for. + virtual void start_program_game_checks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context + ) override final; +}; + + +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h index f53f60a6ce..2b331ac54d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h @@ -12,10 +12,10 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngDisplays.h" +#include "PokemonFRLG_RngProgram.h" #include "PokemonFRLG_SeedsDatabase.h" namespace PokemonAutomation{ @@ -29,9 +29,11 @@ class RoamingLegendaryRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class RoamingLegendaryRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +// Calibrates timings to hit an RNG target for a roaming legendary. +class RoamingLegendaryRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = RoamingLegendaryRng_Descriptor; + virtual size_t free_party_slots_needed() const override{ return 1; } ~RoamingLegendaryRng(); RoamingLegendaryRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h index 4e99f55bda..ea5fa11c06 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h @@ -12,11 +12,11 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Pokemon_StatsCalculation.h" #include "Pokemon/Pokemon_AdvRng.h" #include "PokemonFRLG_RngDisplays.h" +#include "PokemonFRLG_RngProgram.h" #include "PokemonFRLG_SeedsDatabase.h" namespace PokemonAutomation{ @@ -30,9 +30,12 @@ class StarterRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class StarterRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +// Calibrates timings to hit an RNG target for a starter. +class StarterRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StarterRng_Descriptor; + // The party is empty before the starter, so there is nothing to check. + virtual size_t free_party_slots_needed() const override{ return 0; } ~StarterRng(); StarterRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h index 29e117f7fa..3a274e79e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h @@ -14,13 +14,13 @@ #include "Common/Cpp/Options/TextEditOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Pokemon_StatsCalculation.h" #include "Pokemon/Pokemon_AdvRng.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngCalibration.h" #include "PokemonFRLG_RngDisplays.h" +#include "PokemonFRLG_RngProgram.h" #include "PokemonFRLG_SeedsDatabase.h" namespace PokemonAutomation{ @@ -34,9 +34,11 @@ class StaticRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class StaticRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +// Calibrates timings to hit an RNG target for a static encounter. +class StaticRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StaticRng_Descriptor; + virtual size_t free_party_slots_needed() const override{ return 1; } ~StaticRng(); StaticRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h index 1fa342063a..968f68119a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h @@ -13,11 +13,11 @@ #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" #include "CommonTools/Options/StringSelectOption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Pokemon_AdvRng.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngDisplays.h" +#include "PokemonFRLG_RngProgram.h" #include "PokemonFRLG_SeedsDatabase.h" namespace PokemonAutomation{ @@ -31,9 +31,14 @@ class WildRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class WildRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +// Calibrates timings to hit an RNG target for a random wild encounter. +class WildRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = WildRng_Descriptor; + virtual size_t free_party_slots_needed() const override{ return 1; } + virtual StartMenuContext start_menu_context() const override{ + return in_safari_zone() ? StartMenuContext::SAFARI_ZONE : StartMenuContext::STANDARD; + } ~WildRng(); WildRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 8ce94da419..cd41727485 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1818,6 +1818,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngLoopRoutines.h Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.cpp Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h + Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp + Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.cpp Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngStatsDatabase.h Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp From 34a59ded4c9879061d3fb7634dd2b0282d35bd65 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 17:28:52 -0800 Subject: [PATCH 02/13] FRLG party check: image-backed tests; keep the original slots formatting Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Navigation.cpp | 8 +- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 74 +++++++++++++++++-- 2 files changed, 73 insertions(+), 9 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp index 8de1341438..49d239d45f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp @@ -843,7 +843,13 @@ PartySlot detect_last_occupied_party_slot(ConsoleHandle& console){ } PartySlot detect_last_occupied_party_slot(const ImageViewRGB32& screen){ - constexpr std::array slots{PartySlot::SIX, PartySlot::FIVE, PartySlot::FOUR, PartySlot::THREE, PartySlot::TWO}; + constexpr std::array slots{ + PartySlot::SIX, + PartySlot::FIVE, + PartySlot::FOUR, + PartySlot::THREE, + PartySlot::TWO, + }; for (PartySlot slot : slots){ PartyEmptySlotDetector empty_slot_detector(COLOR_RED, slot); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index f8bcb64246..9cd1d0d2fd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -406,18 +406,10 @@ void add_tests_PartyCheck(UnitTestDatabase& database){ .input = {.name = "one free slot needed, five Pokemon", .last_occupied = PartySlot::FIVE}, .expectation = {.steps = "open read"}, }, - { - .input = {.name = "one free slot needed, full party", .last_occupied = PartySlot::SIX}, - .expectation = {.steps = "open read", .error = "Your party is full. Leave a party slot free"}, - }, { .input = {.name = "three free slots needed, three Pokemon", .free_slots_needed = 3, .last_occupied = PartySlot::THREE}, .expectation = {.steps = "open read"}, }, - { - .input = {.name = "three free slots needed, four Pokemon", .free_slots_needed = 3, .last_occupied = PartySlot::FOUR}, - .expectation = {.steps = "open read", .error = "Your party has 4 "}, - }, { // A menu that can't be opened skips the check rather than stopping the program. .input = {.name = "party menu not opened", .menu_opens = false, .last_occupied = PartySlot::SIX}, @@ -429,6 +421,71 @@ void add_tests_PartyCheck(UnitTestDatabase& database){ } } +// Party menu steps for a menu that is already open on the given screenshot. +class ImagePartyCheck : public PartyCheckActions{ +public: + explicit ImagePartyCheck(const ImageViewRGB32& screen) + : m_screen(screen) + {} + + virtual bool open_party_menu() override{ + return true; + } + virtual PartySlot read_last_occupied_slot() override{ + return detect_last_occupied_party_slot(m_screen); + } + +private: + const ImageViewRGB32& m_screen; +}; + +// Runs check_party_free_slots() on a party menu screenshot. +class Test_PartyCheckOnImage : public ImageUnitTest{ +public: + // expected_error: start of the UserSetupError message; empty if the check passes. + Test_PartyCheckOnImage(std::string_view image, size_t free_slots_needed, std::string_view expected_error) + : ImageUnitTest( + std::format("PokemonFRLG::RngPartyCheck - {} free slots needed, {}", free_slots_needed, image), + {std::string(image)} + ) + , m_free_slots_needed(free_slots_needed) + , m_expected_error(expected_error) + {} + + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, + const std::vector& images + ) const override{ + ImagePartyCheck actions(images[0]); + NullLogger logger; + std::string error; + try{ + check_party_free_slots(logger, m_free_slots_needed, actions); + }catch (UserSetupError& e){ + error = e.message(); + } + const bool error_matches = m_expected_error.empty() + ? error.empty() + : error.rfind(m_expected_error, 0) == 0; + if (!error_matches){ + return std::format("Expected error: \"{}\"\nActual error: \"{}\"", m_expected_error, error); + } + return true; + } + +private: + const size_t m_free_slots_needed; + const std::string m_expected_error; +}; + +void add_tests_PartyCheckOnImage(UnitTestDatabase& database){ + database.add( + "PokemonFRLG/Party/Party_6_With_Held_Items.png", 1, "Your party is full. Leave a party slot free" + ); + database.add("PokemonFRLG/Party/JPN_Party.png", 3, "Your party has 4 "); + database.add("PokemonFRLG/Party/JPN_Party.png", 1, ""); +} + std::string menu_context_name(StartMenuContext context){ switch (context){ @@ -569,6 +626,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_HallOfFameSavingDetector(database); add_tests_LastOccupiedPartySlot(database); add_tests_PartyCheck(database); + add_tests_PartyCheckOnImage(database); add_tests_PartyEmptySlotDetector(database); add_tests_PartyHeldItemDetector(database); add_tests_PartyLevelUpReader(database); From 827430978c252126138982dbbf8d307fa0afa631 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 17:39:57 -0800 Subject: [PATCH 03/13] FRLG party check: one image-backed test for the slot reader and the check Each case runs check_party_free_slots() with the real slot detector on a party menu screenshot, replacing the scripted PartyCheck cases and the separate LastOccupiedPartySlot test. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 216 +++++------------- 1 file changed, 54 insertions(+), 162 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 9cd1d0d2fd..c2229c22ee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -279,110 +279,76 @@ void add_tests_ExitWildBattle(UnitTestDatabase& database){ } -std::string slot_name(PartySlot slot){ - return std::to_string(static_cast(slot) + 1); -} - -// Reads the last occupied slot from a party menu screenshot, as the RNG programs' party check does. -class Test_LastOccupiedPartySlot : public ImageUnitTest{ +// Party menu steps on a screenshot of the open menu: the real slot detector reads it, +// and the steps check_party_free_slots() asked for are recorded. +class ImagePartyCheck : public PartyCheckActions{ public: - Test_LastOccupiedPartySlot(std::string_view image, PartySlot expected) - : ImageUnitTest("PokemonFRLG::LastOccupiedPartySlot - " + std::string(image), {std::string(image)}) - , m_expected(expected) + ImagePartyCheck(const ImageViewRGB32& screen, bool menu_opens) + : m_screen(screen) + , m_menu_opens(menu_opens) {} - virtual UnitTestResult run_on_images( - Logger&, CancellableScope&, - const std::vector& images - ) const override{ - const PartySlot slot = detect_last_occupied_party_slot(images[0]); - if (slot != m_expected){ - return std::format("Expected last occupied slot {}, got {}", slot_name(m_expected), slot_name(slot)); - } - return true; - } - -private: - const PartySlot m_expected; -}; - -void add_tests_LastOccupiedPartySlot(UnitTestDatabase& database){ - for (unsigned occupied = 1; occupied <= 6; occupied++){ - database.add( - "PokemonFRLG/Party/Party_" + std::to_string(occupied) + ".png", - static_cast(occupied - 1) - ); - } - database.add("PokemonFRLG/Party/Party_6_With_Held_Items.png", PartySlot::SIX); - database.add("PokemonFRLG/Party/JPN_HeldItem.png", PartySlot::SIX); - database.add("PokemonFRLG/Party/JPN_Party.png", PartySlot::FOUR); - database.add("PokemonFRLG/Party/SPA_HeldItem.png", PartySlot::SIX); -} - -// Steps that return scripted reads, and record what check_party_free_slots() asked for. -class ScriptedPartyCheck : public PartyCheckActions{ -public: - bool menu_opens = true; - PartySlot last_occupied = PartySlot::ONE; - std::string steps; - virtual bool open_party_menu() override{ steps += steps.empty() ? "open" : " open"; - return menu_opens; + return m_menu_opens; } virtual PartySlot read_last_occupied_slot() override{ steps += steps.empty() ? "read" : " read"; - return last_occupied; + return detect_last_occupied_party_slot(m_screen); } + + std::string steps; + +private: + const ImageViewRGB32& m_screen; + const bool m_menu_opens; }; -struct PartyCheckInput{ - std::string name; +struct PartyCheckCase{ + std::string image; size_t free_slots_needed = 1; bool menu_opens = true; - PartySlot last_occupied = PartySlot::ONE; -}; - -struct PartyCheckExpectation{ - std::string steps = ""; + std::string steps = "open read"; // Start of the UserSetupError message; empty if the check passes. std::string error = ""; }; -struct PartyCheckCase{ - PartyCheckInput input; - PartyCheckExpectation expectation; -}; - -class Test_PartyCheck : public UnitTest{ +// Runs check_party_free_slots() on a party menu screenshot. +class Test_PartyCheck : public ImageUnitTest{ public: Test_PartyCheck(PartyCheckCase test_case) - : UnitTest("PokemonFRLG::RngPartyCheck - " + test_case.input.name) + : ImageUnitTest( + std::format( + "PokemonFRLG::RngPartyCheck - {} free slots needed{}, {}", + test_case.free_slots_needed, + test_case.menu_opens ? "" : ", menu not opened", + test_case.image + ), + {test_case.image} + ) , m_case(std::move(test_case)) {} - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const PartyCheckInput& input = m_case.input; - const PartyCheckExpectation& expected = m_case.expectation; - ScriptedPartyCheck actions; - actions.menu_opens = input.menu_opens; - actions.last_occupied = input.last_occupied; - + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, + const std::vector& images + ) const override{ + ImagePartyCheck actions(images[0], m_case.menu_opens); NullLogger logger; std::string error; try{ - check_party_free_slots(logger, input.free_slots_needed, actions); + check_party_free_slots(logger, m_case.free_slots_needed, actions); }catch (UserSetupError& e){ error = e.message(); } - const bool error_matches = expected.error.empty() + const bool error_matches = m_case.error.empty() ? error.empty() - : error.rfind(expected.error, 0) == 0; + : error.rfind(m_case.error, 0) == 0; if (!error_matches){ - return std::format("Expected error: \"{}\"\nActual error: \"{}\"", expected.error, error); + return std::format("Expected error: \"{}\"\nActual error: \"{}\"", m_case.error, error); } - if (actions.steps != expected.steps){ - return std::format("Expected steps: {}\nActual steps: {}", expected.steps, actions.steps); + if (actions.steps != m_case.steps){ + return std::format("Expected steps: {}\nActual steps: {}", m_case.steps, actions.steps); } return true; } @@ -392,100 +358,28 @@ class Test_PartyCheck : public UnitTest{ }; void add_tests_PartyCheck(UnitTestDatabase& database){ + const std::string FULL = "Your party is full. Leave a party slot free"; + for (unsigned occupied = 1; occupied <= 5; occupied++){ + database.add(PartyCheckCase{.image = "PokemonFRLG/Party/Party_" + std::to_string(occupied) + ".png"}); + } const PartyCheckCase cases[] = { - { - // Programs that don't add a Pokemon to the party don't open the menu. - .input = {.name = "no free slot needed, full party", .free_slots_needed = 0, .last_occupied = PartySlot::SIX}, - .expectation = {}, - }, - { - .input = {.name = "one free slot needed, one Pokemon"}, - .expectation = {.steps = "open read"}, - }, - { - .input = {.name = "one free slot needed, five Pokemon", .last_occupied = PartySlot::FIVE}, - .expectation = {.steps = "open read"}, - }, - { - .input = {.name = "three free slots needed, three Pokemon", .free_slots_needed = 3, .last_occupied = PartySlot::THREE}, - .expectation = {.steps = "open read"}, - }, - { - // A menu that can't be opened skips the check rather than stopping the program. - .input = {.name = "party menu not opened", .menu_opens = false, .last_occupied = PartySlot::SIX}, - .expectation = {.steps = "open"}, - }, + {.image = "PokemonFRLG/Party/Party_6.png", .error = FULL}, + {.image = "PokemonFRLG/Party/Party_6_With_Held_Items.png", .error = FULL}, + {.image = "PokemonFRLG/Party/JPN_HeldItem.png", .error = FULL}, + {.image = "PokemonFRLG/Party/SPA_HeldItem.png", .error = FULL}, + {.image = "PokemonFRLG/Party/JPN_Party.png"}, + {.image = "PokemonFRLG/Party/Party_3.png", .free_slots_needed = 3}, + {.image = "PokemonFRLG/Party/JPN_Party.png", .free_slots_needed = 3, .error = "Your party has 4 "}, + // Programs that don't add a Pokemon to the party don't open the menu. + {.image = "PokemonFRLG/Party/Party_6.png", .free_slots_needed = 0, .steps = ""}, + // A menu that can't be opened skips the check rather than stopping the program. + {.image = "PokemonFRLG/Party/Party_6.png", .menu_opens = false, .steps = "open"}, }; for (const PartyCheckCase& test_case : cases){ database.add(test_case); } } -// Party menu steps for a menu that is already open on the given screenshot. -class ImagePartyCheck : public PartyCheckActions{ -public: - explicit ImagePartyCheck(const ImageViewRGB32& screen) - : m_screen(screen) - {} - - virtual bool open_party_menu() override{ - return true; - } - virtual PartySlot read_last_occupied_slot() override{ - return detect_last_occupied_party_slot(m_screen); - } - -private: - const ImageViewRGB32& m_screen; -}; - -// Runs check_party_free_slots() on a party menu screenshot. -class Test_PartyCheckOnImage : public ImageUnitTest{ -public: - // expected_error: start of the UserSetupError message; empty if the check passes. - Test_PartyCheckOnImage(std::string_view image, size_t free_slots_needed, std::string_view expected_error) - : ImageUnitTest( - std::format("PokemonFRLG::RngPartyCheck - {} free slots needed, {}", free_slots_needed, image), - {std::string(image)} - ) - , m_free_slots_needed(free_slots_needed) - , m_expected_error(expected_error) - {} - - virtual UnitTestResult run_on_images( - Logger&, CancellableScope&, - const std::vector& images - ) const override{ - ImagePartyCheck actions(images[0]); - NullLogger logger; - std::string error; - try{ - check_party_free_slots(logger, m_free_slots_needed, actions); - }catch (UserSetupError& e){ - error = e.message(); - } - const bool error_matches = m_expected_error.empty() - ? error.empty() - : error.rfind(m_expected_error, 0) == 0; - if (!error_matches){ - return std::format("Expected error: \"{}\"\nActual error: \"{}\"", m_expected_error, error); - } - return true; - } - -private: - const size_t m_free_slots_needed; - const std::string m_expected_error; -}; - -void add_tests_PartyCheckOnImage(UnitTestDatabase& database){ - database.add( - "PokemonFRLG/Party/Party_6_With_Held_Items.png", 1, "Your party is full. Leave a party slot free" - ); - database.add("PokemonFRLG/Party/JPN_Party.png", 3, "Your party has 4 "); - database.add("PokemonFRLG/Party/JPN_Party.png", 1, ""); -} - std::string menu_context_name(StartMenuContext context){ switch (context){ @@ -624,9 +518,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_EliteFourRoomDetector(database); add_tests_ExitWildBattle(database); add_tests_HallOfFameSavingDetector(database); - add_tests_LastOccupiedPartySlot(database); add_tests_PartyCheck(database); - add_tests_PartyCheckOnImage(database); add_tests_PartyEmptySlotDetector(database); add_tests_PartyHeldItemDetector(database); add_tests_PartyLevelUpReader(database); From 055c5a40f70f001b7c51cb09284c4889ffbe5a4a Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 18:29:41 -0800 Subject: [PATCH 04/13] FRLG RNG: run the party check from RngProgramInstance, not a SingleSwitchProgram hook Drop the start_program_game_checks() hook from SingleSwitchProgramInstance. Each RNG program calls check_free_party_slots() first in program(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../NintendoSwitch_SingleSwitchProgram.cpp | 1 - .../NintendoSwitch_SingleSwitchProgram.h | 9 -------- .../RngManipulation/PokemonFRLG_EggRng.cpp | 1 + .../RngManipulation/PokemonFRLG_GiftRng.cpp | 1 + .../RngManipulation/PokemonFRLG_RngHelper.cpp | 1 + .../PokemonFRLG_RngProgram.cpp | 2 +- .../RngManipulation/PokemonFRLG_RngProgram.h | 21 ++++++++++--------- .../PokemonFRLG_RoamingLegendaryRng.cpp | 1 + .../PokemonFRLG_StarterRng.cpp | 1 + .../RngManipulation/PokemonFRLG_StaticRng.cpp | 1 + .../RngManipulation/PokemonFRLG_WildRng.cpp | 1 + 11 files changed, 19 insertions(+), 21 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp index cbb210b0b7..8f4e94ab65 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.cpp @@ -86,7 +86,6 @@ void SingleSwitchProgramInstance::program(SingleSwitchProgramEnvironment& env, C }; try{ - start_program_game_checks(env, context); program(env, context); }catch (FatalProgramException&){ record_debug_video(); diff --git a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h index b44bb655a1..9c464ca3a7 100644 --- a/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h +++ b/SerialPrograms/Source/NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h @@ -86,15 +86,6 @@ class SingleSwitchProgramInstance : public GameConsole::ConsoleProgramInstance{ FeedbackType feedback_type ); - // Called with the controller ready, just before program(env, context). - // Override to check that the game is set up the way the program needs - // (e.g. a free party slot) and throw UserSetupError if not, so a setup - // mistake stops the program before it starts its work. - virtual void start_program_game_checks( - SingleSwitchProgramEnvironment& env, - ProControllerContext& context - ){} - private: virtual void program(GameConsole::ConsoleProgramEnvironment& env, CancellableScope& scope) override; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp index a05d693683..c5ade3c53e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp @@ -722,6 +722,7 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); EggRng_Descriptor::Stats& stats = env.current_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp index 3341d8cef2..c1dd785904 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp @@ -231,6 +231,7 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); GiftRng_Descriptor::Stats& stats = env.current_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp index 16065cbda0..240d872593 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp @@ -242,6 +242,7 @@ void RngHelper::program(SingleSwitchProgramEnvironment& env, ProControllerContex /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); RngHelper_Descriptor::Stats& stats = env.current_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 7e80dc64f0..034d713973 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -35,7 +35,7 @@ std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_n } // namespace -void RngProgramInstance::start_program_game_checks( +void RngProgramInstance::check_free_party_slots( SingleSwitchProgramEnvironment& env, ProControllerContext& context ){ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 69a0dd8e03..78dc1ebbf1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -3,9 +3,9 @@ * From: https://github.com/PokemonAutomation/ * * Base class for the FRLG RNG programs. Each program states what the game - * must look like when it starts, and the base class checks it before the - * program runs, so a setup mistake stops the run at once instead of failing - * in a misleading way many resets later. + * must look like when it starts, and checks it first thing, so a setup + * mistake stops the run at once instead of failing in a misleading way many + * resets later. * */ @@ -21,8 +21,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// Base class of the RNG programs. Before program() runs, it checks that the -// party has the free slots the program needs. +// Base class of the RNG programs. class RngProgramInstance : public SingleSwitchProgramInstance{ public: using SingleSwitchProgramInstance::SingleSwitchProgramInstance; @@ -37,13 +36,15 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ return StartMenuContext::STANDARD; } - // Runs with the game on the overworld where the player saved. May leave a - // menu open: the program's first reset closes the game. Final so that - // every RNG program runs the check free_party_slots_needed() asks for. - virtual void start_program_game_checks( +protected: + // Checks that the party has the free slots free_party_slots_needed() + // asks for; throws UserSetupError if not. Call it first in program(), + // with the game on the overworld where the player saved. May leave the + // party menu open: the program's first reset closes the game. + void check_free_party_slots( SingleSwitchProgramEnvironment& env, ProControllerContext& context - ) override final; + ); }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp index fe284e8a2c..abdc185711 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp @@ -226,6 +226,7 @@ void RoamingLegendaryRng::program(SingleSwitchProgramEnvironment& env, ProContro /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); RoamingLegendaryRng_Descriptor::Stats& stats = env.current_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp index 5b22bee42f..3de06022f8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp @@ -558,6 +558,7 @@ void StarterRng::program(SingleSwitchProgramEnvironment& env, ProControllerConte /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); StarterRng_Descriptor::Stats& stats = env.current_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp index 30bdaaea7a..e865610de4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp @@ -232,6 +232,7 @@ void StaticRng::program(SingleSwitchProgramEnvironment& env, ProControllerContex /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); StaticRng_Descriptor::Stats& stats = env.current_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp index 9aeb97fb45..370e1cb260 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp @@ -277,6 +277,7 @@ void WildRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& /* * Settings: Text Speed fast */ + check_free_party_slots(env, context); WildRng_Descriptor::Stats& stats = env.current_stats(); From f33000c9fe3cb3ec535062042747e1a8439c7944 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 18:32:56 -0800 Subject: [PATCH 05/13] FRLG RNG: run_precheck() runs the party check and the black border check Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../RngManipulation/PokemonFRLG_EggRng.cpp | 4 +--- .../RngManipulation/PokemonFRLG_GiftRng.cpp | 4 +--- .../RngManipulation/PokemonFRLG_RngHelper.cpp | 4 +--- .../RngManipulation/PokemonFRLG_RngProgram.cpp | 8 ++++++++ .../RngManipulation/PokemonFRLG_RngProgram.h | 14 ++++++++++---- .../PokemonFRLG_RoamingLegendaryRng.cpp | 4 +--- .../RngManipulation/PokemonFRLG_StarterRng.cpp | 4 +--- .../RngManipulation/PokemonFRLG_StaticRng.cpp | 4 +--- .../RngManipulation/PokemonFRLG_WildRng.cpp | 4 +--- 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp index c5ade3c53e..3144110055 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.cpp @@ -722,12 +722,10 @@ void EggRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); EggRng_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - // prepare database of base stats and gender thresholds RngStatsDatabase STATS_DATA("PokemonFRLG/BaseStats.json"); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp index c1dd785904..c81241ddbe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.cpp @@ -231,12 +231,10 @@ void GiftRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); GiftRng_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - RNG_FILTERS.reset(); RNG_CALIBRATION.reset_hits(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp index 240d872593..961217cacd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp @@ -242,12 +242,10 @@ void RngHelper::program(SingleSwitchProgramEnvironment& env, ProControllerContex /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); RngHelper_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - bool shiny_found = false; static const int64_t FIXED_SEED_OFFSET = -845; // milliseconds, approximate diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 034d713973..12a9a4f151 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -60,6 +60,14 @@ void RngProgramInstance::check_free_party_slots( logger.log("Party has enough free slots."); } +void RngProgramInstance::run_precheck( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context +){ + check_free_party_slots(env, context); + home_black_border_check(env.console, context); +} + } // namespace PokemonFRLG } // namespace NintendoSwitch } // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 78dc1ebbf1..b35ef4c14f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -37,10 +37,16 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ } protected: - // Checks that the party has the free slots free_party_slots_needed() - // asks for; throws UserSetupError if not. Call it first in program(), - // with the game on the overworld where the player saved. May leave the - // party menu open: the program's first reset closes the game. + // Call first in program(), with the game on the overworld where the + // player saved: checks the party has the free slots + // free_party_slots_needed() asks for, then goes Home for the black + // border check. Throws UserSetupError if a check fails. + void run_precheck( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context + ); + +private: void check_free_party_slots( SingleSwitchProgramEnvironment& env, ProControllerContext& context diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp index abdc185711..ca6ea548e6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.cpp @@ -226,12 +226,10 @@ void RoamingLegendaryRng::program(SingleSwitchProgramEnvironment& env, ProContro /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); RoamingLegendaryRng_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - RNG_FILTERS.reset(); RNG_CALIBRATION.reset_hits(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp index 3de06022f8..7e8413e136 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.cpp @@ -558,12 +558,10 @@ void StarterRng::program(SingleSwitchProgramEnvironment& env, ProControllerConte /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); StarterRng_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - RNG_FILTERS.reset(); RNG_CALIBRATION.reset_hits(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp index e865610de4..d4cde6017c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.cpp @@ -232,12 +232,10 @@ void StaticRng::program(SingleSwitchProgramEnvironment& env, ProControllerContex /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); StaticRng_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - RNG_FILTERS.reset(); RNG_CALIBRATION.reset_hits(); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp index 370e1cb260..96a98f5084 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.cpp @@ -277,12 +277,10 @@ void WildRng::program(SingleSwitchProgramEnvironment& env, ProControllerContext& /* * Settings: Text Speed fast */ - check_free_party_slots(env, context); + run_precheck(env, context); WildRng_Descriptor::Stats& stats = env.current_stats(); - home_black_border_check(env.console, context); - RNG_FILTERS.reset(); RNG_CALIBRATION.reset_hits(); From 986e7fd0bf882374071c4f2d5e78d4111167f5e3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 20:25:25 -0800 Subject: [PATCH 06/13] FRLG RNG: run the black border check before the free party slots check --- .../Programs/RngManipulation/PokemonFRLG_RngProgram.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 12a9a4f151..3bc49ecb46 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -64,8 +64,8 @@ void RngProgramInstance::run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context ){ - check_free_party_slots(env, context); home_black_border_check(env.console, context); + check_free_party_slots(env, context); } } // namespace PokemonFRLG From 5d1fc804c9e5e6fd724204af20e40a671dfe9fd8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 21:10:57 -0800 Subject: [PATCH 07/13] FRLG EggRng: free party slots check depends on STARTING_POINT --- .../Programs/RngManipulation/PokemonFRLG_EggRng.h | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index 6adb83effc..921d9b862a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h @@ -60,8 +60,12 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{ class EggRng : public RngProgramInstance, public ConfigOption::Listener{ public: using Descriptor = EggRng_Descriptor; - // The egg and the two wild Pokemon caught to confirm the seed. - virtual size_t free_party_slots_needed() const override{ return 3; } + virtual size_t free_party_slots_needed() const override{ + if (STARTING_POINT == EggProgramState::pickup_calibration){ + return 2; + } + return 3; + } ~EggRng(); EggRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; From c09beca6d7747bbfe12efbd8da85abe24cac1ba6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 11 Nov 2026 21:32:05 -0800 Subject: [PATCH 08/13] FRLG RNG: remove start_menu_context; all save locations use standard menu --- .../Programs/RngManipulation/PokemonFRLG_RngProgram.cpp | 3 ++- .../Programs/RngManipulation/PokemonFRLG_RngProgram.h | 6 ------ .../Programs/RngManipulation/PokemonFRLG_WildRng.h | 3 --- 3 files changed, 2 insertions(+), 10 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 3bc49ecb46..a1014876d1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -10,6 +10,7 @@ #include "CommonFramework/Exceptions/OperationFailedException.h" #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "PokemonFRLG_RngProgram.h" namespace PokemonAutomation{ @@ -46,7 +47,7 @@ void RngProgramInstance::check_free_party_slots( Logger& logger = env.console.logger(); logger.log("Checking for " + std::to_string(free_slots_needed) + " free party slot(s)..."); try{ - open_party_menu_from_overworld(env.console, context, start_menu_context()); + open_party_menu_from_overworld(env.console, context); }catch (OperationFailedException&){ logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); return; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index b35ef4c14f..727ba9b099 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -14,7 +14,6 @@ #include #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" -#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -31,11 +30,6 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ // party that Pokemon would go to the PC instead. virtual size_t free_party_slots_needed() const = 0; - // The start menu the player sees where the program starts. - virtual StartMenuContext start_menu_context() const{ - return StartMenuContext::STANDARD; - } - protected: // Call first in program(), with the game on the overworld where the // player saved: checks the party has the free slots diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h index 968f68119a..25daee4b08 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h @@ -36,9 +36,6 @@ class WildRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = WildRng_Descriptor; virtual size_t free_party_slots_needed() const override{ return 1; } - virtual StartMenuContext start_menu_context() const override{ - return in_safari_zone() ? StartMenuContext::SAFARI_ZONE : StartMenuContext::STANDARD; - } ~WildRng(); WildRng(); virtual void program(SingleSwitchProgramEnvironment& env, ProControllerContext &context) override; From eb27dfc4f14231c9457e100f3ee5ab35db6186aa Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 12:54:36 -0800 Subject: [PATCH 09/13] FRLG RNG: setting to skip the free party slots check "Run Start Checks" in the FRLG Game Settings, in a new RNG Settings section with the license check. Off skips the party check; the black border check always runs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp | 9 +++++++++ .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h | 3 +++ .../Programs/RngManipulation/PokemonFRLG_RngProgram.cpp | 5 +++++ 3 files changed, 17 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp index 6a08282535..30537d3cd0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp @@ -65,6 +65,7 @@ GameSettings::GameSettings() LockMode::LOCK_WHILE_RUNNING, "3000 ms" ) + , m_rng_settings("RNG Settings:") , HANDLE_ONLINE_LICENSE_CHECK( "Handle Online License Check:
" "Turn this on if your console checks the game's license online when it starts the game: " @@ -73,6 +74,12 @@ GameSettings::GameSettings() LockMode::LOCK_WHILE_RUNNING, false // default ) + , RUN_RNG_START_CHECKS( + "Run Start Checks:
" + "Run pre-program validation checks, e.g. that your party has enough free slots.", + LockMode::LOCK_WHILE_RUNNING, + true // default + ) , m_shiny_audio_settings("Shiny Audio Settings:") , SHINY_SOUND_THRESHOLD( "Shiny Sound Threshold:
Maximum error coefficient to trigger a shiny detection.", @@ -98,7 +105,9 @@ GameSettings::GameSettings() PA_ADD_OPTION(SELECT_BUTTON_MASH0); PA_ADD_OPTION(ENTER_GAME_WAIT0); PA_ADD_OPTION(ENTER_GAME_MASH0); + PA_ADD_STATIC(m_rng_settings); PA_ADD_OPTION(HANDLE_ONLINE_LICENSE_CHECK); + PA_ADD_OPTION(RUN_RNG_START_CHECKS); PA_ADD_STATIC(m_shiny_audio_settings); PA_ADD_OPTION(SHINY_SOUND_THRESHOLD); PA_ADD_OPTION(SHINY_SOUND_LOW_FREQUENCY); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h index 83583b1afb..c8015bbef4 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h @@ -41,7 +41,10 @@ class GameSettings : public BatchOption, private ConfigOption::Listener{ MillisecondsOption SELECT_BUTTON_MASH0; MillisecondsOption ENTER_GAME_WAIT0; MillisecondsOption ENTER_GAME_MASH0; + + SectionDividerOption m_rng_settings; BooleanCheckBoxOption HANDLE_ONLINE_LICENSE_CHECK; + BooleanCheckBoxOption RUN_RNG_START_CHECKS; SectionDividerOption m_shiny_audio_settings; FloatingPointOption SHINY_SOUND_THRESHOLD; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index a1014876d1..d4257d7f37 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -11,6 +11,7 @@ #include "Pokemon/Pokemon_Strings.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_RngProgram.h" namespace PokemonAutomation{ @@ -66,6 +67,10 @@ void RngProgramInstance::run_precheck( ProControllerContext& context ){ home_black_border_check(env.console, context); + if (!GameSettings::instance().RUN_RNG_START_CHECKS){ + env.console.log("Start checks are off in the FRLG Game Settings. Skipping them."); + return; + } check_free_party_slots(env, context); } From 439cedd294255c47b402a4997df9586695a561f3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:35:48 -0800 Subject: [PATCH 10/13] Prechecks: a program's start checks as a named list; FRLG RNG first A Precheck has a stable name, a one-line "needs" and a policy (REQUIRED or OPTIONAL). run_prechecks() runs a list in order, leaves out the OPTIONAL ones when asked, returns one result per check (name, passed/failed/skipped, message) and throws UserSetupError with the check's message at the first failure. FRLG RNG's run_precheck() now runs rng_prechecks(n): black_border (REQUIRED), then free_party_slots(n) (OPTIONAL, only when n > 0). The "Run Start Checks" box in the FRLG Game Settings skips the OPTIONAL checks, as it skipped the party check before. Messages are unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../ComputerPrograms_UnitTestRunner.cpp | 2 + .../Programs/NintendoSwitch_Prechecks.cpp | 63 +++++++ .../Programs/NintendoSwitch_Prechecks.h | 104 ++++++++++++ .../NintendoSwitch_Prechecks_Tests.cpp | 155 +++++++++++++++++ .../Programs/NintendoSwitch_Prechecks_Tests.h | 21 +++ .../PokemonFRLG/PokemonFRLG_Prechecks.cpp | 100 +++++++++++ .../PokemonFRLG/PokemonFRLG_Prechecks.h | 36 ++++ .../PokemonFRLG_Prechecks_Tests.cpp | 158 ++++++++++++++++++ .../PokemonFRLG/PokemonFRLG_Prechecks_Tests.h | 23 +++ .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 + .../PokemonFRLG_RngProgram.cpp | 64 ++----- .../RngManipulation/PokemonFRLG_RngProgram.h | 21 ++- SerialPrograms/cmake/SourceFiles.cmake | 8 + 13 files changed, 697 insertions(+), 60 deletions(-) create mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp create mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h create mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp create mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 9b48682bc1..ade4631c3c 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -28,6 +28,7 @@ #include "NintendoSwitch/Inference/NintendoSwitch_CheckOnlineDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_FailedToConnectDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h" +#include "NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h" #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" @@ -73,6 +74,7 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); + NintendoSwitch::add_tests_Prechecks(ret); NintendoSwitch::Typewriter::add_tests_TypewriterTextMapping(ret); NintendoSwitch::PokemonBDSP::add_tests_DialogDetector(ret); NintendoSwitch::PokemonBDSP::add_tests_MenuDetector(ret); diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp new file mode 100644 index 0000000000..f77d70ede8 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp @@ -0,0 +1,63 @@ +/* Prechecks + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/Exceptions.h" +#include "NintendoSwitch_Prechecks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +Precheck::Precheck(std::string name, std::string needs, PrecheckPolicy policy) + : m_name(std::move(name)) + , m_needs(std::move(needs)) + , m_policy(policy) +{} + + +std::vector run_prechecks( + Logger& logger, + const PrecheckList& checks, + OptionalPrechecks optional, + const std::function& run_check +){ + std::vector results; + for (const std::unique_ptr& check : checks){ + if (check->policy() == PrecheckPolicy::OPTIONAL && optional == OptionalPrechecks::SKIP){ + logger.log("Precheck " + check->name() + ": skipped, optional prechecks are off."); + results.emplace_back(PrecheckResult{check->name(), {PrecheckStatus::SKIPPED, "Optional prechecks are off."}}); + continue; + } + logger.log("Precheck " + check->name() + ": " + check->needs()); + PrecheckOutcome outcome = run_check(*check); + if (outcome.status == PrecheckStatus::FAILED){ + throw UserSetupError(logger, std::move(outcome.message)); + } + if (outcome.status == PrecheckStatus::SKIPPED){ + logger.log("Precheck " + check->name() + ": skipped. " + outcome.message, COLOR_RED); + } + results.emplace_back(PrecheckResult{check->name(), std::move(outcome)}); + } + return results; +} + +std::vector run_prechecks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context, + const PrecheckList& checks, + OptionalPrechecks optional +){ + return run_prechecks( + env.console.logger(), checks, optional, + [&](const Precheck& check){ + return check.run(env, context); + } + ); +} + + +} +} diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h new file mode 100644 index 0000000000..5e11ba9a0d --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h @@ -0,0 +1,104 @@ +/* Prechecks + * + * From: https://github.com/PokemonAutomation/ + * + * What the console and the game must look like before a program starts. + * A program lists its prechecks in order and runs them first thing, so a + * setup mistake stops the run before it resets or saves, with a message that + * says what to fix. + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_Prechecks_H +#define PokemonAutomation_NintendoSwitch_Prechecks_H + +#include +#include +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" +#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +enum class PrecheckStatus{ + PASSED, + FAILED, + SKIPPED, +}; + +// Whether a precheck can be turned off. +enum class PrecheckPolicy{ + REQUIRED, // Always runs. + OPTIONAL, // Runs unless the program turns its optional checks off. +}; + +// Whether run_prechecks() runs the OPTIONAL checks. +enum class OptionalPrechecks{ + RUN, + SKIP, +}; + +// What one precheck found. On FAILED, the message tells the user what to fix. +struct PrecheckOutcome{ + PrecheckStatus status; + std::string message; +}; + +// One precheck of a run, as run_prechecks() reports it. +struct PrecheckResult{ + std::string name; + PrecheckOutcome outcome; +}; + + +// One thing a program needs before it starts. +class Precheck{ +public: + Precheck(std::string name, std::string needs, PrecheckPolicy policy); + virtual ~Precheck() = default; + + // Stable id, e.g. "free_party_slots". + const std::string& name() const{ return m_name; } + // One line for the user: what the program needs. + const std::string& needs() const{ return m_needs; } + PrecheckPolicy policy() const{ return m_policy; } + + // Reads the console. Never resets, saves or changes options. + virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const = 0; + +private: + std::string m_name; + std::string m_needs; + PrecheckPolicy m_policy; +}; + +// A program's prechecks, in the order they run. Building the list never +// touches the console. +using PrecheckList = std::vector>; + + +// Runs the checks in order, each through run_check, leaving out the OPTIONAL +// ones when optional is SKIP. Throws UserSetupError with the check's message +// at the first FAILED one. Returns one result per check. +std::vector run_prechecks( + Logger& logger, + const PrecheckList& checks, + OptionalPrechecks optional, + const std::function& run_check +); + +// Runs the checks on the console. Call first in program(). +std::vector run_prechecks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context, + const PrecheckList& checks, + OptionalPrechecks optional +); + + +} +} +#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp new file mode 100644 index 0000000000..4f404043d6 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp @@ -0,0 +1,155 @@ +/* Prechecks - Tests + * + * From: https://github.com/PokemonAutomation/ + * + * run_prechecks() with fake checks: no console, no GUI. + */ + +#include +#include +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "NintendoSwitch_Prechecks.h" +#include "NintendoSwitch_Prechecks_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + +namespace{ + + +// A check that only has a name and a policy. The tests run it through +// run_check, never through run(). +class FakePrecheck : public Precheck{ +public: + using Precheck::Precheck; + virtual PrecheckOutcome run(SingleSwitchProgramEnvironment&, ProControllerContext&) const override{ + return {PrecheckStatus::FAILED, "A fake check must not touch the console."}; + } +}; + +struct FakeCheck{ + std::string name; + PrecheckPolicy policy; + PrecheckOutcome outcome; +}; + +struct RunPrechecksCase{ + struct Input{ + std::vector checks; + OptionalPrechecks optional; + }; + struct Expectation{ + // Names of the checks run_prechecks() ran, in order. + std::vector ran; + // Set when run_prechecks() throws UserSetupError: its message. + std::optional error; + // Statuses run_prechecks() returned, in order, when it did not throw. + std::vector statuses; + }; + std::string name; + Input input; + Expectation expectation; +}; + +const PrecheckOutcome PASS{PrecheckStatus::PASSED, ""}; + + +class Test_RunPrechecks : public UnitTest{ +public: + explicit Test_RunPrechecks(RunPrechecksCase test_case) + : UnitTest("NintendoSwitch::Prechecks::RunPrechecks - " + test_case.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ + PrecheckList checks; + std::map outcomes; + for (const FakeCheck& check : m_case.input.checks){ + checks.emplace_back(std::make_unique(check.name, "Fake needs.", check.policy)); + outcomes.emplace(check.name, check.outcome); + } + std::vector ran; + auto run_check = [&](const Precheck& check){ + ran.emplace_back(check.name()); + return outcomes.at(check.name()); + }; + + const RunPrechecksCase::Expectation& expected = m_case.expectation; + std::optional error; + std::vector statuses; + try{ + for (const PrecheckResult& result : run_prechecks(logger, checks, m_case.input.optional, run_check)){ + statuses.emplace_back(result.outcome.status); + } + }catch (UserSetupError& e){ + error = e.message(); + } + + if (ran != expected.ran){ + return "run_prechecks() ran the wrong checks or in the wrong order."; + } + if (error != expected.error){ + return "run_prechecks() threw the wrong error: \"" + error.value_or("(none)") + "\""; + } + if (statuses != expected.statuses){ + return "run_prechecks() returned the wrong statuses."; + } + return true; + } + +private: + RunPrechecksCase m_case; +}; + + +std::vector run_prechecks_cases(){ + using enum PrecheckPolicy; + using enum PrecheckStatus; + const PrecheckOutcome no_room{FAILED, "Your party is full."}; + const PrecheckOutcome no_menu{SKIPPED, "Unable to open the party menu."}; + return { + { + "AllPassInOrder", + {{{"first", REQUIRED, PASS}, {"second", OPTIONAL, PASS}}, OptionalPrechecks::RUN}, + {{"first", "second"}, std::nullopt, {PASSED, PASSED}}, + }, + { + "SkipLeavesOutOptionalChecks", + {{{"first", OPTIONAL, PASS}, {"second", REQUIRED, PASS}}, OptionalPrechecks::SKIP}, + {{"second"}, std::nullopt, {SKIPPED, PASSED}}, + }, + { + "FirstFailureStopsWithItsMessage", + {{{"first", REQUIRED, no_room}, {"second", REQUIRED, PASS}}, OptionalPrechecks::RUN}, + {{"first"}, "Your party is full.", {}}, + }, + { + "SkippedCheckDoesNotStopTheRun", + {{{"first", OPTIONAL, no_menu}, {"second", REQUIRED, PASS}}, OptionalPrechecks::RUN}, + {{"first", "second"}, std::nullopt, {SKIPPED, PASSED}}, + }, + { + "EmptyListRunsNothing", + {{}, OptionalPrechecks::RUN}, + {{}, std::nullopt, {}}, + }, + }; +} + + +} // namespace + + +void add_tests_Prechecks(UnitTestDatabase& database){ + for (RunPrechecksCase& test_case : run_prechecks_cases()){ + database.add(std::move(test_case)); + } +} + + +} +} diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h new file mode 100644 index 0000000000..ea7d53be29 --- /dev/null +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h @@ -0,0 +1,21 @@ +/* Prechecks - Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_NintendoSwitch_Prechecks_Tests_H +#define PokemonAutomation_NintendoSwitch_Prechecks_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ + + +void add_tests_Prechecks(UnitTestDatabase& database); + + +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp new file mode 100644 index 0000000000..eb820e08b6 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp @@ -0,0 +1,100 @@ +/* FRLG Prechecks + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Pokemon/Pokemon_Strings.h" +#include "PokemonFRLG_Navigation.h" +#include "PokemonFRLG_Prechecks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +namespace{ + +constexpr size_t MAX_PARTY_SIZE = 6; + + +std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ + if (free_slots_needed == 1){ + return std::format( + "Your party is full. Leave a party slot free so the program can check the {} it catches or receives.", + Pokemon::STRING_POKEMON + ); + } + return std::format( + "Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.", + party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON + ); +} + + +class BlackBorderPrecheck : public Precheck{ +public: + BlackBorderPrecheck() + : Precheck( + "black_border", + "Screen size at 100% with no black border, and the controller connected.", + PrecheckPolicy::REQUIRED + ) + {} + virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const override{ + home_black_border_check(env.console, context); + return {PrecheckStatus::PASSED, ""}; + } +}; + + +class FreePartySlotsPrecheck : public Precheck{ +public: + explicit FreePartySlotsPrecheck(size_t free_slots_needed) + : Precheck( + "free_party_slots", + std::format("At least {} free party slot(s), on the overworld where the game was saved.", free_slots_needed), + PrecheckPolicy::OPTIONAL + ) + , m_free_slots_needed(free_slots_needed) + {} + virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const override{ + try{ + open_party_menu_from_overworld(env.console, context); + }catch (OperationFailedException&){ + return {PrecheckStatus::SKIPPED, "Unable to open the party menu."}; + } + context.wait_for_all_requests(); + const size_t party_size = static_cast(detect_last_occupied_party_slot(env.console)) + 1; + return free_party_slots_outcome(party_size, m_free_slots_needed); + } + +private: + size_t m_free_slots_needed; +}; + + +} // namespace + + +std::unique_ptr make_black_border_precheck(){ + return std::make_unique(); +} + +std::unique_ptr make_free_party_slots_precheck(size_t free_slots_needed){ + return std::make_unique(free_slots_needed); +} + +PrecheckOutcome free_party_slots_outcome(size_t party_size, size_t free_slots_needed){ + if (party_size + free_slots_needed > MAX_PARTY_SIZE){ + return {PrecheckStatus::FAILED, not_enough_free_slots_message(party_size, free_slots_needed)}; + } + return {PrecheckStatus::PASSED, "Party has enough free slots."}; +} + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h new file mode 100644 index 0000000000..e3790cad0c --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h @@ -0,0 +1,36 @@ +/* FRLG Prechecks + * + * From: https://github.com/PokemonAutomation/ + * + * The prechecks FRLG programs share. See NintendoSwitch_Prechecks.h. + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_Prechecks_H +#define PokemonAutomation_PokemonFRLG_Prechecks_H + +#include +#include +#include "NintendoSwitch/Programs/NintendoSwitch_Prechecks.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +// "black_border": goes Home to check the screen size and the controller, +// then resumes the game. Always runs. +std::unique_ptr make_black_border_precheck(); + +// "free_party_slots": opens the party menu from the overworld and checks +// that at least free_slots_needed slots are free. Optional. +std::unique_ptr make_free_party_slots_precheck(size_t free_slots_needed); + +// The free_party_slots verdict for a party of party_size Pokemon. +PrecheckOutcome free_party_slots_outcome(size_t party_size, size_t free_slots_needed); + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp new file mode 100644 index 0000000000..c2bb6ca756 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp @@ -0,0 +1,158 @@ +/* FRLG Prechecks - Tests + * + * From: https://github.com/PokemonAutomation/ + * + * The FRLG precheck lists and verdicts: no console, no GUI. + */ + +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Programs/RngManipulation/PokemonFRLG_RngProgram.h" +#include "PokemonFRLG_Prechecks.h" +#include "PokemonFRLG_Prechecks_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + +namespace{ + + +struct ListedPrecheck{ + std::string name; + PrecheckPolicy policy; + + bool operator==(const ListedPrecheck&) const = default; +}; + +struct RngPrechecksCase{ + struct Input{ + size_t free_party_slots_needed; + }; + struct Expectation{ + std::vector checks; + }; + std::string name; + Input input; + Expectation expectation; +}; + +class Test_RngPrechecks : public UnitTest{ +public: + explicit Test_RngPrechecks(RngPrechecksCase test_case) + : UnitTest("PokemonFRLG::Prechecks::RngPrechecks - " + test_case.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::vector listed; + for (const std::unique_ptr& check : rng_prechecks(m_case.input.free_party_slots_needed)){ + if (check->needs().empty()){ + return "Precheck " + check->name() + " must say what it needs."; + } + listed.emplace_back(ListedPrecheck{check->name(), check->policy()}); + } + if (listed != m_case.expectation.checks){ + return "The RNG precheck list has the wrong checks, order or policies."; + } + return true; + } + +private: + RngPrechecksCase m_case; +}; + + +struct FreePartySlotsCase{ + struct Input{ + size_t party_size; + size_t free_slots_needed; + }; + struct Expectation{ + PrecheckStatus status; + // Checked only on FAILED: the message the user sees. + std::string message; + }; + std::string name; + Input input; + Expectation expectation; +}; + +class Test_FreePartySlotsOutcome : public UnitTest{ +public: + explicit Test_FreePartySlotsOutcome(FreePartySlotsCase test_case) + : UnitTest("PokemonFRLG::Prechecks::FreePartySlotsOutcome - " + test_case.name) + , m_case(std::move(test_case)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const PrecheckOutcome outcome = free_party_slots_outcome( + m_case.input.party_size, m_case.input.free_slots_needed + ); + if (outcome.status != m_case.expectation.status){ + return "Wrong verdict: \"" + outcome.message + "\""; + } + if (outcome.status == PrecheckStatus::FAILED && outcome.message != m_case.expectation.message){ + return "Wrong message: \"" + outcome.message + "\""; + } + return true; + } + +private: + FreePartySlotsCase m_case; +}; + + +std::vector rng_prechecks_cases(){ + const ListedPrecheck black_border{"black_border", PrecheckPolicy::REQUIRED}; + const ListedPrecheck free_party_slots{"free_party_slots", PrecheckPolicy::OPTIONAL}; + return { + {"NeedsNoSlots", {0}, {{black_border}}}, + {"NeedsOneSlot", {1}, {{black_border, free_party_slots}}}, + {"NeedsTwoSlots", {2}, {{black_border, free_party_slots}}}, + }; +} + +std::vector free_party_slots_cases(){ + using enum PrecheckStatus; + return { + {"FiveOfSixNeedsOne", {5, 1}, {PASSED, ""}}, + { + "FullPartyNeedsOne", {6, 1}, + { + FAILED, + "Your party is full. Leave a party slot free so the program can check the " + "Pokémon it catches or receives.", + }, + }, + {"FourOfSixNeedsTwo", {4, 2}, {PASSED, ""}}, + { + "FiveOfSixNeedsTwo", {5, 2}, + { + FAILED, + "Your party has 5 Pokémon. Leave at least 2 party slots free for the " + "Pokémon the program catches or receives.", + }, + }, + }; +} + + +} // namespace + + +void add_tests_Prechecks(UnitTestDatabase& database){ + for (RngPrechecksCase& test_case : rng_prechecks_cases()){ + database.add(std::move(test_case)); + } + for (FreePartySlotsCase& test_case : free_party_slots_cases()){ + database.add(std::move(test_case)); + } +} + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h new file mode 100644 index 0000000000..b0f0af3f26 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h @@ -0,0 +1,23 @@ +/* FRLG Prechecks - Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonFRLG_Prechecks_Tests_H +#define PokemonAutomation_PokemonFRLG_Prechecks_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +void add_tests_Prechecks(UnitTestDatabase& database); + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 94dc41dd85..0dd809965a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -30,6 +30,7 @@ #include "Programs/BoxOrganization/PokemonFRLG_BoxSorter_Tests.h" #include "Tests/TestUtils.h" +#include "PokemonFRLG_Prechecks_Tests.h" #include "PokemonFRLG_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -54,6 +55,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_PartyHeldItemDetector(database); add_tests_PartyLevelUpReader(database); add_tests_PartyMenuDetector(database); + add_tests_Prechecks(database); add_tests_PrizeSelectDetector(database); add_tests_PartySlotDetector(database); add_tests_StatsReader(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index d4257d7f37..a32c0e7c78 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -4,13 +4,7 @@ * */ -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "CommonFramework/Exceptions/OperationFailedException.h" -#include "Pokemon/Pokemon_Strings.h" -#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" -#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_RngProgram.h" @@ -19,59 +13,27 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -namespace{ - -std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ - if (free_slots_needed == 1){ - return std::format( - "Your party is full. Leave a party slot free so the program can check the {} it catches or receives.", - Pokemon::STRING_POKEMON - ); +PrecheckList rng_prechecks(size_t free_party_slots_needed){ + PrecheckList checks; + checks.emplace_back(make_black_border_precheck()); + if (free_party_slots_needed > 0){ + checks.emplace_back(make_free_party_slots_precheck(free_party_slots_needed)); } - return std::format( - "Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.", - party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON - ); + return checks; } -} // namespace - - -void RngProgramInstance::check_free_party_slots( - SingleSwitchProgramEnvironment& env, - ProControllerContext& context -){ - const size_t free_slots_needed = free_party_slots_needed(); - if (free_slots_needed == 0){ - return; - } - Logger& logger = env.console.logger(); - logger.log("Checking for " + std::to_string(free_slots_needed) + " free party slot(s)..."); - try{ - open_party_menu_from_overworld(env.console, context); - }catch (OperationFailedException&){ - logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); - return; - } - context.wait_for_all_requests(); - constexpr size_t MAX_PARTY_SIZE = 6; - const size_t party_size = static_cast(detect_last_occupied_party_slot(env.console)) + 1; - if (MAX_PARTY_SIZE - party_size < free_slots_needed){ - throw UserSetupError(logger, not_enough_free_slots_message(party_size, free_slots_needed)); - } - logger.log("Party has enough free slots."); +PrecheckList RngProgramInstance::prechecks() const{ + return rng_prechecks(free_party_slots_needed()); } void RngProgramInstance::run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context ){ - home_black_border_check(env.console, context); - if (!GameSettings::instance().RUN_RNG_START_CHECKS){ - env.console.log("Start checks are off in the FRLG Game Settings. Skipping them."); - return; - } - check_free_party_slots(env, context); + const OptionalPrechecks optional = GameSettings::instance().RUN_RNG_START_CHECKS + ? OptionalPrechecks::RUN + : OptionalPrechecks::SKIP; + run_prechecks(env, context, prechecks(), optional); } } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 727ba9b099..6d0a0e4154 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -14,12 +14,18 @@ #include #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "NintendoSwitch/Programs/NintendoSwitch_Prechecks.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ +// The prechecks of an RNG program that needs free_party_slots_needed free +// party slots: black_border, then free_party_slots when it needs any. +PrecheckList rng_prechecks(size_t free_party_slots_needed); + + // Base class of the RNG programs. class RngProgramInstance : public SingleSwitchProgramInstance{ public: @@ -30,21 +36,18 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ // party that Pokemon would go to the PC instead. virtual size_t free_party_slots_needed() const = 0; + // What the program needs before it starts, in the order run_precheck() + // checks it. Does not touch the console. + PrecheckList prechecks() const; + protected: // Call first in program(), with the game on the overworld where the - // player saved: checks the party has the free slots - // free_party_slots_needed() asks for, then goes Home for the black - // border check. Throws UserSetupError if a check fails. + // player saved: runs prechecks(). "Run Start Checks" off in the FRLG Game + // Settings skips the optional ones. Throws UserSetupError if a check fails. void run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context ); - -private: - void check_free_party_slots( - SingleSwitchProgramEnvironment& env, - ProControllerContext& context - ); }; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 5bde7d3e75..e85cd7987f 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1417,6 +1417,10 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.h Source/NintendoSwitch/Programs/NintendoSwitch_MenuStabilityTester.cpp Source/NintendoSwitch/Programs/NintendoSwitch_MenuStabilityTester.h + Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp + Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h + Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp + Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h Source/NintendoSwitch/Programs/NintendoSwitch_PreventSleep.cpp Source/NintendoSwitch/Programs/NintendoSwitch_PreventSleep.h Source/NintendoSwitch/Programs/NintendoSwitch_PushJoySticks.cpp @@ -1767,6 +1771,10 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.h + Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp + Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h + Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp + Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp From 25763445fae4a1584e01a23cb950e902bfd9b140 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 13:37:52 -0800 Subject: [PATCH 11/13] Prechecks: table-driven tests, SKIPPABLE/ALWAYS_RUNS policy names, code health OPTIONAL is a macro in the Windows headers, so the policy values are ALWAYS_RUNS and SKIPPABLE. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Programs/NintendoSwitch_Prechecks.cpp | 21 +-- .../Programs/NintendoSwitch_Prechecks.h | 21 +-- .../NintendoSwitch_Prechecks_Tests.cpp | 165 +++++++++--------- .../Programs/NintendoSwitch_Prechecks_Tests.h | 5 +- .../PokemonFRLG/PokemonFRLG_Prechecks.cpp | 10 +- .../PokemonFRLG/PokemonFRLG_Prechecks.h | 10 +- .../PokemonFRLG_Prechecks_Tests.cpp | 127 +++++++------- .../PokemonFRLG/PokemonFRLG_Prechecks_Tests.h | 7 +- .../PokemonFRLG_RngProgram.cpp | 8 +- .../RngManipulation/PokemonFRLG_RngProgram.h | 2 +- 10 files changed, 195 insertions(+), 181 deletions(-) diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp index f77d70ede8..42f0ceaa8d 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp @@ -4,6 +4,7 @@ * */ +#include #include "Common/Cpp/Exceptions.h" #include "NintendoSwitch_Prechecks.h" @@ -21,23 +22,23 @@ Precheck::Precheck(std::string name, std::string needs, PrecheckPolicy policy) std::vector run_prechecks( Logger& logger, const PrecheckList& checks, - OptionalPrechecks optional, + SkippablePrechecks skippable, const std::function& run_check ){ std::vector results; for (const std::unique_ptr& check : checks){ - if (check->policy() == PrecheckPolicy::OPTIONAL && optional == OptionalPrechecks::SKIP){ - logger.log("Precheck " + check->name() + ": skipped, optional prechecks are off."); - results.emplace_back(PrecheckResult{check->name(), {PrecheckStatus::SKIPPED, "Optional prechecks are off."}}); + if (check->policy() == PrecheckPolicy::SKIPPABLE && skippable == SkippablePrechecks::SKIP){ + logger.log(std::format("Precheck {}: skipped, skippable prechecks are off.", check->name())); + results.emplace_back(PrecheckResult{check->name(), {PrecheckStatus::SKIPPED, "Skippable prechecks are off."}}); continue; } - logger.log("Precheck " + check->name() + ": " + check->needs()); + logger.log(std::format("Precheck {}: {}", check->name(), check->needs())); PrecheckOutcome outcome = run_check(*check); if (outcome.status == PrecheckStatus::FAILED){ throw UserSetupError(logger, std::move(outcome.message)); } if (outcome.status == PrecheckStatus::SKIPPED){ - logger.log("Precheck " + check->name() + ": skipped. " + outcome.message, COLOR_RED); + logger.log(std::format("Precheck {}: skipped. {}", check->name(), outcome.message), COLOR_RED); } results.emplace_back(PrecheckResult{check->name(), std::move(outcome)}); } @@ -48,10 +49,10 @@ std::vector run_prechecks( SingleSwitchProgramEnvironment& env, ProControllerContext& context, const PrecheckList& checks, - OptionalPrechecks optional + SkippablePrechecks skippable ){ return run_prechecks( - env.console.logger(), checks, optional, + env.console.logger(), checks, skippable, [&](const Precheck& check){ return check.run(env, context); } @@ -59,5 +60,5 @@ std::vector run_prechecks( } -} -} +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h index 5e11ba9a0d..992c6b5683 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h @@ -23,6 +23,7 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ +// How one precheck ended. enum class PrecheckStatus{ PASSED, FAILED, @@ -31,12 +32,12 @@ enum class PrecheckStatus{ // Whether a precheck can be turned off. enum class PrecheckPolicy{ - REQUIRED, // Always runs. - OPTIONAL, // Runs unless the program turns its optional checks off. + ALWAYS_RUNS, + SKIPPABLE, // Left out when the program turns its skippable checks off. }; -// Whether run_prechecks() runs the OPTIONAL checks. -enum class OptionalPrechecks{ +// Whether run_prechecks() runs the SKIPPABLE checks. +enum class SkippablePrechecks{ RUN, SKIP, }; @@ -80,13 +81,13 @@ class Precheck{ using PrecheckList = std::vector>; -// Runs the checks in order, each through run_check, leaving out the OPTIONAL -// ones when optional is SKIP. Throws UserSetupError with the check's message +// Runs the checks in order, each through run_check, leaving out the SKIPPABLE +// ones when skippable is SKIP. Throws UserSetupError with the check's message // at the first FAILED one. Returns one result per check. std::vector run_prechecks( Logger& logger, const PrecheckList& checks, - OptionalPrechecks optional, + SkippablePrechecks skippable, const std::function& run_check ); @@ -95,10 +96,10 @@ std::vector run_prechecks( SingleSwitchProgramEnvironment& env, ProControllerContext& context, const PrecheckList& checks, - OptionalPrechecks optional + SkippablePrechecks skippable ); -} -} +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp index 4f404043d6..89315f6f41 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp @@ -5,6 +5,7 @@ * run_prechecks() with fake checks: no console, no GUI. */ +#include #include #include #include @@ -37,65 +38,68 @@ struct FakeCheck{ PrecheckOutcome outcome; }; +struct RunPrechecksInput{ + std::vector checks; + SkippablePrechecks skippable; +}; + +struct RunPrechecksExpectation{ + // Names of the checks run_prechecks() ran, in order. + std::vector ran; + // Set when run_prechecks() throws UserSetupError: its message. + std::optional error; + // Statuses run_prechecks() returned, in order, when it did not throw. + std::vector statuses; +}; + struct RunPrechecksCase{ - struct Input{ - std::vector checks; - OptionalPrechecks optional; - }; - struct Expectation{ - // Names of the checks run_prechecks() ran, in order. - std::vector ran; - // Set when run_prechecks() throws UserSetupError: its message. - std::optional error; - // Statuses run_prechecks() returned, in order, when it did not throw. - std::vector statuses; - }; std::string name; - Input input; - Expectation expectation; + RunPrechecksInput input; + RunPrechecksExpectation expectation; }; -const PrecheckOutcome PASS{PrecheckStatus::PASSED, ""}; + +// Runs the case's fake checks; returns what run_prechecks() did. +RunPrechecksExpectation run_fake_prechecks(Logger& logger, const RunPrechecksInput& input){ + PrecheckList checks; + std::map outcomes; + for (const FakeCheck& check : input.checks){ + checks.emplace_back(std::make_unique(check.name, "Fake needs.", check.policy)); + outcomes.emplace(check.name, check.outcome); + } + RunPrechecksExpectation actual; + auto run_check = [&](const Precheck& check){ + actual.ran.emplace_back(check.name()); + return outcomes.at(check.name()); + }; + try{ + for (const PrecheckResult& result : run_prechecks(logger, checks, input.skippable, run_check)){ + actual.statuses.emplace_back(result.outcome.status); + } + }catch (UserSetupError& e){ + actual.error = e.message(); + } + return actual; +} class Test_RunPrechecks : public UnitTest{ public: explicit Test_RunPrechecks(RunPrechecksCase test_case) - : UnitTest("NintendoSwitch::Prechecks::RunPrechecks - " + test_case.name) + : UnitTest(std::format("NintendoSwitch::Prechecks::RunPrechecks - {}", test_case.name)) , m_case(std::move(test_case)) {} virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - PrecheckList checks; - std::map outcomes; - for (const FakeCheck& check : m_case.input.checks){ - checks.emplace_back(std::make_unique(check.name, "Fake needs.", check.policy)); - outcomes.emplace(check.name, check.outcome); - } - std::vector ran; - auto run_check = [&](const Precheck& check){ - ran.emplace_back(check.name()); - return outcomes.at(check.name()); - }; - - const RunPrechecksCase::Expectation& expected = m_case.expectation; - std::optional error; - std::vector statuses; - try{ - for (const PrecheckResult& result : run_prechecks(logger, checks, m_case.input.optional, run_check)){ - statuses.emplace_back(result.outcome.status); - } - }catch (UserSetupError& e){ - error = e.message(); - } - - if (ran != expected.ran){ + const RunPrechecksExpectation actual = run_fake_prechecks(logger, m_case.input); + const RunPrechecksExpectation& expected = m_case.expectation; + if (actual.ran != expected.ran){ return "run_prechecks() ran the wrong checks or in the wrong order."; } - if (error != expected.error){ - return "run_prechecks() threw the wrong error: \"" + error.value_or("(none)") + "\""; + if (actual.error != expected.error){ + return std::format("run_prechecks() threw the wrong error: \"{}\"", actual.error.value_or("(none)")); } - if (statuses != expected.statuses){ + if (actual.statuses != expected.statuses){ return "run_prechecks() returned the wrong statuses."; } return true; @@ -106,50 +110,51 @@ class Test_RunPrechecks : public UnitTest{ }; -std::vector run_prechecks_cases(){ - using enum PrecheckPolicy; - using enum PrecheckStatus; - const PrecheckOutcome no_room{FAILED, "Your party is full."}; - const PrecheckOutcome no_menu{SKIPPED, "Unable to open the party menu."}; - return { - { - "AllPassInOrder", - {{{"first", REQUIRED, PASS}, {"second", OPTIONAL, PASS}}, OptionalPrechecks::RUN}, - {{"first", "second"}, std::nullopt, {PASSED, PASSED}}, - }, - { - "SkipLeavesOutOptionalChecks", - {{{"first", OPTIONAL, PASS}, {"second", REQUIRED, PASS}}, OptionalPrechecks::SKIP}, - {{"second"}, std::nullopt, {SKIPPED, PASSED}}, - }, - { - "FirstFailureStopsWithItsMessage", - {{{"first", REQUIRED, no_room}, {"second", REQUIRED, PASS}}, OptionalPrechecks::RUN}, - {{"first"}, "Your party is full.", {}}, - }, - { - "SkippedCheckDoesNotStopTheRun", - {{{"first", OPTIONAL, no_menu}, {"second", REQUIRED, PASS}}, OptionalPrechecks::RUN}, - {{"first", "second"}, std::nullopt, {SKIPPED, PASSED}}, - }, - { - "EmptyListRunsNothing", - {{}, OptionalPrechecks::RUN}, - {{}, std::nullopt, {}}, - }, - }; -} +using enum PrecheckPolicy; +using enum PrecheckStatus; + +const PrecheckOutcome PASS{PASSED, ""}; +const PrecheckOutcome PARTY_FULL{FAILED, "Your party is full."}; +const PrecheckOutcome NO_PARTY_MENU{SKIPPED, "Unable to open the party menu."}; + +const std::vector RUN_PRECHECKS_CASES{ + { + .name = "AllPassInOrder", + .input = {{{"first", ALWAYS_RUNS, PASS}, {"second", SKIPPABLE, PASS}}, SkippablePrechecks::RUN}, + .expectation = {{"first", "second"}, std::nullopt, {PASSED, PASSED}}, + }, + { + .name = "SkipLeavesOutSkippableChecks", + .input = {{{"first", SKIPPABLE, PASS}, {"second", ALWAYS_RUNS, PASS}}, SkippablePrechecks::SKIP}, + .expectation = {{"second"}, std::nullopt, {SKIPPED, PASSED}}, + }, + { + .name = "FirstFailureStopsWithItsMessage", + .input = {{{"first", ALWAYS_RUNS, PARTY_FULL}, {"second", ALWAYS_RUNS, PASS}}, SkippablePrechecks::RUN}, + .expectation = {{"first"}, "Your party is full.", {}}, + }, + { + .name = "SkippedCheckDoesNotStopTheRun", + .input = {{{"first", SKIPPABLE, NO_PARTY_MENU}, {"second", ALWAYS_RUNS, PASS}}, SkippablePrechecks::RUN}, + .expectation = {{"first", "second"}, std::nullopt, {SKIPPED, PASSED}}, + }, + { + .name = "EmptyListRunsNothing", + .input = {{}, SkippablePrechecks::RUN}, + .expectation = {{}, std::nullopt, {}}, + }, +}; } // namespace void add_tests_Prechecks(UnitTestDatabase& database){ - for (RunPrechecksCase& test_case : run_prechecks_cases()){ - database.add(std::move(test_case)); + for (const RunPrechecksCase& test_case : RUN_PRECHECKS_CASES){ + database.add(test_case); } } -} -} +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h index ea7d53be29..d9bd4a511c 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h @@ -13,9 +13,10 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ +// Registers the precheck unit tests. void add_tests_Prechecks(UnitTestDatabase& database); -} -} +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp index eb820e08b6..a4cde21233 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp @@ -40,7 +40,7 @@ class BlackBorderPrecheck : public Precheck{ : Precheck( "black_border", "Screen size at 100% with no black border, and the controller connected.", - PrecheckPolicy::REQUIRED + PrecheckPolicy::ALWAYS_RUNS ) {} virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const override{ @@ -56,7 +56,7 @@ class FreePartySlotsPrecheck : public Precheck{ : Precheck( "free_party_slots", std::format("At least {} free party slot(s), on the overworld where the game was saved.", free_slots_needed), - PrecheckPolicy::OPTIONAL + PrecheckPolicy::SKIPPABLE ) , m_free_slots_needed(free_slots_needed) {} @@ -95,6 +95,6 @@ PrecheckOutcome free_party_slots_outcome(size_t party_size, size_t free_slots_ne } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h index e3790cad0c..6e8d30cd4d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h @@ -19,18 +19,18 @@ namespace PokemonFRLG{ // "black_border": goes Home to check the screen size and the controller, -// then resumes the game. Always runs. +// then resumes the game. ALWAYS_RUNS. std::unique_ptr make_black_border_precheck(); // "free_party_slots": opens the party menu from the overworld and checks -// that at least free_slots_needed slots are free. Optional. +// that at least free_slots_needed slots are free. SKIPPABLE. std::unique_ptr make_free_party_slots_precheck(size_t free_slots_needed); // The free_party_slots verdict for a party of party_size Pokemon. PrecheckOutcome free_party_slots_outcome(size_t party_size, size_t free_slots_needed); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp index c2bb6ca756..44b8b888c0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp @@ -5,6 +5,7 @@ * The FRLG precheck lists and verdicts: no console, no GUI. */ +#include #include #include #include "Common/Cpp/TestRunners/UnitTest.h" @@ -27,22 +28,24 @@ struct ListedPrecheck{ bool operator==(const ListedPrecheck&) const = default; }; +struct RngPrechecksInput{ + size_t free_party_slots_needed; +}; + +struct RngPrechecksExpectation{ + std::vector checks; +}; + struct RngPrechecksCase{ - struct Input{ - size_t free_party_slots_needed; - }; - struct Expectation{ - std::vector checks; - }; std::string name; - Input input; - Expectation expectation; + RngPrechecksInput input; + RngPrechecksExpectation expectation; }; class Test_RngPrechecks : public UnitTest{ public: explicit Test_RngPrechecks(RngPrechecksCase test_case) - : UnitTest("PokemonFRLG::Prechecks::RngPrechecks - " + test_case.name) + : UnitTest(std::format("PokemonFRLG::Prechecks::RngPrechecks - {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -50,7 +53,7 @@ class Test_RngPrechecks : public UnitTest{ std::vector listed; for (const std::unique_ptr& check : rng_prechecks(m_case.input.free_party_slots_needed)){ if (check->needs().empty()){ - return "Precheck " + check->name() + " must say what it needs."; + return std::format("Precheck {} must say what it needs.", check->name()); } listed.emplace_back(ListedPrecheck{check->name(), check->policy()}); } @@ -65,25 +68,27 @@ class Test_RngPrechecks : public UnitTest{ }; +struct FreePartySlotsInput{ + size_t party_size; + size_t free_slots_needed; +}; + +struct FreePartySlotsExpectation{ + PrecheckStatus status; + // Checked only on FAILED: the message the user sees. + std::string message; +}; + struct FreePartySlotsCase{ - struct Input{ - size_t party_size; - size_t free_slots_needed; - }; - struct Expectation{ - PrecheckStatus status; - // Checked only on FAILED: the message the user sees. - std::string message; - }; std::string name; - Input input; - Expectation expectation; + FreePartySlotsInput input; + FreePartySlotsExpectation expectation; }; class Test_FreePartySlotsOutcome : public UnitTest{ public: explicit Test_FreePartySlotsOutcome(FreePartySlotsCase test_case) - : UnitTest("PokemonFRLG::Prechecks::FreePartySlotsOutcome - " + test_case.name) + : UnitTest(std::format("PokemonFRLG::Prechecks::FreePartySlotsOutcome - {}", test_case.name)) , m_case(std::move(test_case)) {} @@ -92,10 +97,10 @@ class Test_FreePartySlotsOutcome : public UnitTest{ m_case.input.party_size, m_case.input.free_slots_needed ); if (outcome.status != m_case.expectation.status){ - return "Wrong verdict: \"" + outcome.message + "\""; + return std::format("Wrong verdict: \"{}\"", outcome.message); } if (outcome.status == PrecheckStatus::FAILED && outcome.message != m_case.expectation.message){ - return "Wrong message: \"" + outcome.message + "\""; + return std::format("Wrong message: \"{}\"", outcome.message); } return true; } @@ -105,54 +110,54 @@ class Test_FreePartySlotsOutcome : public UnitTest{ }; -std::vector rng_prechecks_cases(){ - const ListedPrecheck black_border{"black_border", PrecheckPolicy::REQUIRED}; - const ListedPrecheck free_party_slots{"free_party_slots", PrecheckPolicy::OPTIONAL}; - return { - {"NeedsNoSlots", {0}, {{black_border}}}, - {"NeedsOneSlot", {1}, {{black_border, free_party_slots}}}, - {"NeedsTwoSlots", {2}, {{black_border, free_party_slots}}}, - }; -} +const ListedPrecheck BLACK_BORDER{"black_border", PrecheckPolicy::ALWAYS_RUNS}; +const ListedPrecheck FREE_PARTY_SLOTS{"free_party_slots", PrecheckPolicy::SKIPPABLE}; + +const std::vector RNG_PRECHECKS_CASES{ + {.name = "NeedsNoSlots", .input = {0}, .expectation = {{BLACK_BORDER}}}, + {.name = "NeedsOneSlot", .input = {1}, .expectation = {{BLACK_BORDER, FREE_PARTY_SLOTS}}}, + {.name = "NeedsTwoSlots", .input = {2}, .expectation = {{BLACK_BORDER, FREE_PARTY_SLOTS}}}, +}; -std::vector free_party_slots_cases(){ - using enum PrecheckStatus; - return { - {"FiveOfSixNeedsOne", {5, 1}, {PASSED, ""}}, - { - "FullPartyNeedsOne", {6, 1}, - { - FAILED, - "Your party is full. Leave a party slot free so the program can check the " - "Pokémon it catches or receives.", - }, +// The messages are the ones the party check showed before it moved onto the +// precheck list. +const std::vector FREE_PARTY_SLOTS_CASES{ + {.name = "FiveOfSixNeedsOne", .input = {5, 1}, .expectation = {PrecheckStatus::PASSED, ""}}, + { + .name = "FullPartyNeedsOne", + .input = {6, 1}, + .expectation = { + PrecheckStatus::FAILED, + "Your party is full. Leave a party slot free so the program can check the " + "Pokémon it catches or receives.", }, - {"FourOfSixNeedsTwo", {4, 2}, {PASSED, ""}}, - { - "FiveOfSixNeedsTwo", {5, 2}, - { - FAILED, - "Your party has 5 Pokémon. Leave at least 2 party slots free for the " - "Pokémon the program catches or receives.", - }, + }, + {.name = "FourOfSixNeedsTwo", .input = {4, 2}, .expectation = {PrecheckStatus::PASSED, ""}}, + { + .name = "FiveOfSixNeedsTwo", + .input = {5, 2}, + .expectation = { + PrecheckStatus::FAILED, + "Your party has 5 Pokémon. Leave at least 2 party slots free for the " + "Pokémon the program catches or receives.", }, - }; -} + }, +}; } // namespace void add_tests_Prechecks(UnitTestDatabase& database){ - for (RngPrechecksCase& test_case : rng_prechecks_cases()){ - database.add(std::move(test_case)); + for (const RngPrechecksCase& test_case : RNG_PRECHECKS_CASES){ + database.add(test_case); } - for (FreePartySlotsCase& test_case : free_party_slots_cases()){ - database.add(std::move(test_case)); + for (const FreePartySlotsCase& test_case : FREE_PARTY_SLOTS_CASES){ + database.add(test_case); } } -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h index b0f0af3f26..29d6a11284 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h @@ -14,10 +14,11 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +// Registers the precheck unit tests. void add_tests_Prechecks(UnitTestDatabase& database); -} -} -} +} // namespace PokemonFRLG +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index a32c0e7c78..3b95ab5762 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -30,10 +30,10 @@ void RngProgramInstance::run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context ){ - const OptionalPrechecks optional = GameSettings::instance().RUN_RNG_START_CHECKS - ? OptionalPrechecks::RUN - : OptionalPrechecks::SKIP; - run_prechecks(env, context, prechecks(), optional); + const SkippablePrechecks skippable = GameSettings::instance().RUN_RNG_START_CHECKS + ? SkippablePrechecks::RUN + : SkippablePrechecks::SKIP; + run_prechecks(env, context, prechecks(), skippable); } } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 6d0a0e4154..8e8cc64055 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -43,7 +43,7 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ protected: // Call first in program(), with the game on the overworld where the // player saved: runs prechecks(). "Run Start Checks" off in the FRLG Game - // Settings skips the optional ones. Throws UserSetupError if a check fails. + // Settings skips the SKIPPABLE ones. Throws UserSetupError if a check fails. void run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context From 9236b46c13f7b0da3a6ea51640151a75b7381620 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 14 Nov 2026 15:54:41 -0800 Subject: [PATCH 12/13] Prechecks: log passed outcomes, explicit includes, accurate run() contract --- .../NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp | 4 ++++ .../Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h | 3 ++- .../Programs/NintendoSwitch_Prechecks_Tests.cpp | 1 + .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp | 2 ++ 4 files changed, 9 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp index 42f0ceaa8d..dc4d5986a5 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "Common/Cpp/Exceptions.h" #include "NintendoSwitch_Prechecks.h" @@ -37,6 +38,9 @@ std::vector run_prechecks( if (outcome.status == PrecheckStatus::FAILED){ throw UserSetupError(logger, std::move(outcome.message)); } + if (outcome.status == PrecheckStatus::PASSED && !outcome.message.empty()){ + logger.log(std::format("Precheck {}: passed. {}", check->name(), outcome.message)); + } if (outcome.status == PrecheckStatus::SKIPPED){ logger.log(std::format("Precheck {}: skipped. {}", check->name(), outcome.message), COLOR_RED); } diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h index 992c6b5683..4c360fa34c 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h @@ -67,7 +67,8 @@ class Precheck{ const std::string& needs() const{ return m_needs; } PrecheckPolicy policy() const{ return m_policy; } - // Reads the console. Never resets, saves or changes options. + // May navigate (open a menu, go Home) but must return to the screen it started on. + // Never resets, saves or changes options. virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const = 0; private: diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp index 89315f6f41..fcf4ba3bd7 100644 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp +++ b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp @@ -9,6 +9,7 @@ #include #include #include +#include #include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/TestRunners/UnitTest.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp index a4cde21233..10f830f46f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp @@ -5,10 +5,12 @@ */ #include +#include #include #include "CommonFramework/Exceptions/OperationFailedException.h" #include "Pokemon/Pokemon_Strings.h" #include "PokemonFRLG_Navigation.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" #include "PokemonFRLG_Prechecks.h" namespace PokemonAutomation{ From 002d62f905a4977cc6235657c3b5bbd0d24129ec Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 15 Nov 2026 11:24:39 -0800 Subject: [PATCH 13/13] Revert "Merge pull request #485 from dayfine/lab/slice4-prechecks" This reverts commit a7e19eaf6452e69b213f7ec0da71efd1e0ad1622, reversing changes made to eb27dfc4f14231c9457e100f3ee5ab35db6186aa. --- .../ComputerPrograms_UnitTestRunner.cpp | 2 - .../Programs/NintendoSwitch_Prechecks.cpp | 68 -------- .../Programs/NintendoSwitch_Prechecks.h | 106 ------------ .../NintendoSwitch_Prechecks_Tests.cpp | 161 ----------------- .../Programs/NintendoSwitch_Prechecks_Tests.h | 22 --- .../PokemonFRLG/PokemonFRLG_Prechecks.cpp | 102 ----------- .../PokemonFRLG/PokemonFRLG_Prechecks.h | 36 ---- .../PokemonFRLG_Prechecks_Tests.cpp | 163 ------------------ .../PokemonFRLG/PokemonFRLG_Prechecks_Tests.h | 24 --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 2 - .../PokemonFRLG_RngProgram.cpp | 64 +++++-- .../RngManipulation/PokemonFRLG_RngProgram.h | 21 +-- SerialPrograms/cmake/SourceFiles.cmake | 8 - 13 files changed, 60 insertions(+), 719 deletions(-) delete mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp delete mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h delete mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp delete mode 100644 SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp delete mode 100644 SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index ade4631c3c..9b48682bc1 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -28,7 +28,6 @@ #include "NintendoSwitch/Inference/NintendoSwitch_CheckOnlineDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_FailedToConnectDetector.h" #include "NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h" -#include "NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h" #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" #include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" @@ -74,7 +73,6 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ NintendoSwitch::add_tests_CheckOnlineDetector(ret); NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); - NintendoSwitch::add_tests_Prechecks(ret); NintendoSwitch::Typewriter::add_tests_TypewriterTextMapping(ret); NintendoSwitch::PokemonBDSP::add_tests_DialogDetector(ret); NintendoSwitch::PokemonBDSP::add_tests_MenuDetector(ret); diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp deleted file mode 100644 index dc4d5986a5..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp +++ /dev/null @@ -1,68 +0,0 @@ -/* Prechecks - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "NintendoSwitch_Prechecks.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - -Precheck::Precheck(std::string name, std::string needs, PrecheckPolicy policy) - : m_name(std::move(name)) - , m_needs(std::move(needs)) - , m_policy(policy) -{} - - -std::vector run_prechecks( - Logger& logger, - const PrecheckList& checks, - SkippablePrechecks skippable, - const std::function& run_check -){ - std::vector results; - for (const std::unique_ptr& check : checks){ - if (check->policy() == PrecheckPolicy::SKIPPABLE && skippable == SkippablePrechecks::SKIP){ - logger.log(std::format("Precheck {}: skipped, skippable prechecks are off.", check->name())); - results.emplace_back(PrecheckResult{check->name(), {PrecheckStatus::SKIPPED, "Skippable prechecks are off."}}); - continue; - } - logger.log(std::format("Precheck {}: {}", check->name(), check->needs())); - PrecheckOutcome outcome = run_check(*check); - if (outcome.status == PrecheckStatus::FAILED){ - throw UserSetupError(logger, std::move(outcome.message)); - } - if (outcome.status == PrecheckStatus::PASSED && !outcome.message.empty()){ - logger.log(std::format("Precheck {}: passed. {}", check->name(), outcome.message)); - } - if (outcome.status == PrecheckStatus::SKIPPED){ - logger.log(std::format("Precheck {}: skipped. {}", check->name(), outcome.message), COLOR_RED); - } - results.emplace_back(PrecheckResult{check->name(), std::move(outcome)}); - } - return results; -} - -std::vector run_prechecks( - SingleSwitchProgramEnvironment& env, - ProControllerContext& context, - const PrecheckList& checks, - SkippablePrechecks skippable -){ - return run_prechecks( - env.console.logger(), checks, skippable, - [&](const Precheck& check){ - return check.run(env, context); - } - ); -} - - -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h deleted file mode 100644 index 4c360fa34c..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h +++ /dev/null @@ -1,106 +0,0 @@ -/* Prechecks - * - * From: https://github.com/PokemonAutomation/ - * - * What the console and the game must look like before a program starts. - * A program lists its prechecks in order and runs them first thing, so a - * setup mistake stops the run before it resets or saves, with a message that - * says what to fix. - * - */ - -#ifndef PokemonAutomation_NintendoSwitch_Prechecks_H -#define PokemonAutomation_NintendoSwitch_Prechecks_H - -#include -#include -#include -#include -#include "Common/Cpp/Logging/AbstractLogger.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - -// How one precheck ended. -enum class PrecheckStatus{ - PASSED, - FAILED, - SKIPPED, -}; - -// Whether a precheck can be turned off. -enum class PrecheckPolicy{ - ALWAYS_RUNS, - SKIPPABLE, // Left out when the program turns its skippable checks off. -}; - -// Whether run_prechecks() runs the SKIPPABLE checks. -enum class SkippablePrechecks{ - RUN, - SKIP, -}; - -// What one precheck found. On FAILED, the message tells the user what to fix. -struct PrecheckOutcome{ - PrecheckStatus status; - std::string message; -}; - -// One precheck of a run, as run_prechecks() reports it. -struct PrecheckResult{ - std::string name; - PrecheckOutcome outcome; -}; - - -// One thing a program needs before it starts. -class Precheck{ -public: - Precheck(std::string name, std::string needs, PrecheckPolicy policy); - virtual ~Precheck() = default; - - // Stable id, e.g. "free_party_slots". - const std::string& name() const{ return m_name; } - // One line for the user: what the program needs. - const std::string& needs() const{ return m_needs; } - PrecheckPolicy policy() const{ return m_policy; } - - // May navigate (open a menu, go Home) but must return to the screen it started on. - // Never resets, saves or changes options. - virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const = 0; - -private: - std::string m_name; - std::string m_needs; - PrecheckPolicy m_policy; -}; - -// A program's prechecks, in the order they run. Building the list never -// touches the console. -using PrecheckList = std::vector>; - - -// Runs the checks in order, each through run_check, leaving out the SKIPPABLE -// ones when skippable is SKIP. Throws UserSetupError with the check's message -// at the first FAILED one. Returns one result per check. -std::vector run_prechecks( - Logger& logger, - const PrecheckList& checks, - SkippablePrechecks skippable, - const std::function& run_check -); - -// Runs the checks on the console. Call first in program(). -std::vector run_prechecks( - SingleSwitchProgramEnvironment& env, - ProControllerContext& context, - const PrecheckList& checks, - SkippablePrechecks skippable -); - - -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp deleted file mode 100644 index fcf4ba3bd7..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp +++ /dev/null @@ -1,161 +0,0 @@ -/* Prechecks - Tests - * - * From: https://github.com/PokemonAutomation/ - * - * run_prechecks() with fake checks: no console, no GUI. - */ - -#include -#include -#include -#include -#include -#include -#include "Common/Cpp/Exceptions.h" -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "NintendoSwitch_Prechecks.h" -#include "NintendoSwitch_Prechecks_Tests.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - -namespace{ - - -// A check that only has a name and a policy. The tests run it through -// run_check, never through run(). -class FakePrecheck : public Precheck{ -public: - using Precheck::Precheck; - virtual PrecheckOutcome run(SingleSwitchProgramEnvironment&, ProControllerContext&) const override{ - return {PrecheckStatus::FAILED, "A fake check must not touch the console."}; - } -}; - -struct FakeCheck{ - std::string name; - PrecheckPolicy policy; - PrecheckOutcome outcome; -}; - -struct RunPrechecksInput{ - std::vector checks; - SkippablePrechecks skippable; -}; - -struct RunPrechecksExpectation{ - // Names of the checks run_prechecks() ran, in order. - std::vector ran; - // Set when run_prechecks() throws UserSetupError: its message. - std::optional error; - // Statuses run_prechecks() returned, in order, when it did not throw. - std::vector statuses; -}; - -struct RunPrechecksCase{ - std::string name; - RunPrechecksInput input; - RunPrechecksExpectation expectation; -}; - - -// Runs the case's fake checks; returns what run_prechecks() did. -RunPrechecksExpectation run_fake_prechecks(Logger& logger, const RunPrechecksInput& input){ - PrecheckList checks; - std::map outcomes; - for (const FakeCheck& check : input.checks){ - checks.emplace_back(std::make_unique(check.name, "Fake needs.", check.policy)); - outcomes.emplace(check.name, check.outcome); - } - RunPrechecksExpectation actual; - auto run_check = [&](const Precheck& check){ - actual.ran.emplace_back(check.name()); - return outcomes.at(check.name()); - }; - try{ - for (const PrecheckResult& result : run_prechecks(logger, checks, input.skippable, run_check)){ - actual.statuses.emplace_back(result.outcome.status); - } - }catch (UserSetupError& e){ - actual.error = e.message(); - } - return actual; -} - - -class Test_RunPrechecks : public UnitTest{ -public: - explicit Test_RunPrechecks(RunPrechecksCase test_case) - : UnitTest(std::format("NintendoSwitch::Prechecks::RunPrechecks - {}", test_case.name)) - , m_case(std::move(test_case)) - {} - - virtual UnitTestResult run(Logger& logger, CancellableScope&) const override{ - const RunPrechecksExpectation actual = run_fake_prechecks(logger, m_case.input); - const RunPrechecksExpectation& expected = m_case.expectation; - if (actual.ran != expected.ran){ - return "run_prechecks() ran the wrong checks or in the wrong order."; - } - if (actual.error != expected.error){ - return std::format("run_prechecks() threw the wrong error: \"{}\"", actual.error.value_or("(none)")); - } - if (actual.statuses != expected.statuses){ - return "run_prechecks() returned the wrong statuses."; - } - return true; - } - -private: - RunPrechecksCase m_case; -}; - - -using enum PrecheckPolicy; -using enum PrecheckStatus; - -const PrecheckOutcome PASS{PASSED, ""}; -const PrecheckOutcome PARTY_FULL{FAILED, "Your party is full."}; -const PrecheckOutcome NO_PARTY_MENU{SKIPPED, "Unable to open the party menu."}; - -const std::vector RUN_PRECHECKS_CASES{ - { - .name = "AllPassInOrder", - .input = {{{"first", ALWAYS_RUNS, PASS}, {"second", SKIPPABLE, PASS}}, SkippablePrechecks::RUN}, - .expectation = {{"first", "second"}, std::nullopt, {PASSED, PASSED}}, - }, - { - .name = "SkipLeavesOutSkippableChecks", - .input = {{{"first", SKIPPABLE, PASS}, {"second", ALWAYS_RUNS, PASS}}, SkippablePrechecks::SKIP}, - .expectation = {{"second"}, std::nullopt, {SKIPPED, PASSED}}, - }, - { - .name = "FirstFailureStopsWithItsMessage", - .input = {{{"first", ALWAYS_RUNS, PARTY_FULL}, {"second", ALWAYS_RUNS, PASS}}, SkippablePrechecks::RUN}, - .expectation = {{"first"}, "Your party is full.", {}}, - }, - { - .name = "SkippedCheckDoesNotStopTheRun", - .input = {{{"first", SKIPPABLE, NO_PARTY_MENU}, {"second", ALWAYS_RUNS, PASS}}, SkippablePrechecks::RUN}, - .expectation = {{"first", "second"}, std::nullopt, {SKIPPED, PASSED}}, - }, - { - .name = "EmptyListRunsNothing", - .input = {{}, SkippablePrechecks::RUN}, - .expectation = {{}, std::nullopt, {}}, - }, -}; - - -} // namespace - - -void add_tests_Prechecks(UnitTestDatabase& database){ - for (const RunPrechecksCase& test_case : RUN_PRECHECKS_CASES){ - database.add(test_case); - } -} - - -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h b/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h deleted file mode 100644 index d9bd4a511c..0000000000 --- a/SerialPrograms/Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h +++ /dev/null @@ -1,22 +0,0 @@ -/* Prechecks - Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_NintendoSwitch_Prechecks_Tests_H -#define PokemonAutomation_NintendoSwitch_Prechecks_Tests_H - -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ - - -// Registers the precheck unit tests. -void add_tests_Prechecks(UnitTestDatabase& database); - - -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp deleted file mode 100644 index 10f830f46f..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp +++ /dev/null @@ -1,102 +0,0 @@ -/* FRLG Prechecks - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#include -#include -#include -#include "CommonFramework/Exceptions/OperationFailedException.h" -#include "Pokemon/Pokemon_Strings.h" -#include "PokemonFRLG_Navigation.h" -#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" -#include "PokemonFRLG_Prechecks.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - -namespace{ - -constexpr size_t MAX_PARTY_SIZE = 6; - - -std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ - if (free_slots_needed == 1){ - return std::format( - "Your party is full. Leave a party slot free so the program can check the {} it catches or receives.", - Pokemon::STRING_POKEMON - ); - } - return std::format( - "Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.", - party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON - ); -} - - -class BlackBorderPrecheck : public Precheck{ -public: - BlackBorderPrecheck() - : Precheck( - "black_border", - "Screen size at 100% with no black border, and the controller connected.", - PrecheckPolicy::ALWAYS_RUNS - ) - {} - virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const override{ - home_black_border_check(env.console, context); - return {PrecheckStatus::PASSED, ""}; - } -}; - - -class FreePartySlotsPrecheck : public Precheck{ -public: - explicit FreePartySlotsPrecheck(size_t free_slots_needed) - : Precheck( - "free_party_slots", - std::format("At least {} free party slot(s), on the overworld where the game was saved.", free_slots_needed), - PrecheckPolicy::SKIPPABLE - ) - , m_free_slots_needed(free_slots_needed) - {} - virtual PrecheckOutcome run(SingleSwitchProgramEnvironment& env, ProControllerContext& context) const override{ - try{ - open_party_menu_from_overworld(env.console, context); - }catch (OperationFailedException&){ - return {PrecheckStatus::SKIPPED, "Unable to open the party menu."}; - } - context.wait_for_all_requests(); - const size_t party_size = static_cast(detect_last_occupied_party_slot(env.console)) + 1; - return free_party_slots_outcome(party_size, m_free_slots_needed); - } - -private: - size_t m_free_slots_needed; -}; - - -} // namespace - - -std::unique_ptr make_black_border_precheck(){ - return std::make_unique(); -} - -std::unique_ptr make_free_party_slots_precheck(size_t free_slots_needed){ - return std::make_unique(free_slots_needed); -} - -PrecheckOutcome free_party_slots_outcome(size_t party_size, size_t free_slots_needed){ - if (party_size + free_slots_needed > MAX_PARTY_SIZE){ - return {PrecheckStatus::FAILED, not_enough_free_slots_message(party_size, free_slots_needed)}; - } - return {PrecheckStatus::PASSED, "Party has enough free slots."}; -} - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h deleted file mode 100644 index 6e8d30cd4d..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h +++ /dev/null @@ -1,36 +0,0 @@ -/* FRLG Prechecks - * - * From: https://github.com/PokemonAutomation/ - * - * The prechecks FRLG programs share. See NintendoSwitch_Prechecks.h. - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_Prechecks_H -#define PokemonAutomation_PokemonFRLG_Prechecks_H - -#include -#include -#include "NintendoSwitch/Programs/NintendoSwitch_Prechecks.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// "black_border": goes Home to check the screen size and the controller, -// then resumes the game. ALWAYS_RUNS. -std::unique_ptr make_black_border_precheck(); - -// "free_party_slots": opens the party menu from the overworld and checks -// that at least free_slots_needed slots are free. SKIPPABLE. -std::unique_ptr make_free_party_slots_precheck(size_t free_slots_needed); - -// The free_party_slots verdict for a party of party_size Pokemon. -PrecheckOutcome free_party_slots_outcome(size_t party_size, size_t free_slots_needed); - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp deleted file mode 100644 index 44b8b888c0..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp +++ /dev/null @@ -1,163 +0,0 @@ -/* FRLG Prechecks - Tests - * - * From: https://github.com/PokemonAutomation/ - * - * The FRLG precheck lists and verdicts: no console, no GUI. - */ - -#include -#include -#include -#include "Common/Cpp/TestRunners/UnitTest.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "Programs/RngManipulation/PokemonFRLG_RngProgram.h" -#include "PokemonFRLG_Prechecks.h" -#include "PokemonFRLG_Prechecks_Tests.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - -namespace{ - - -struct ListedPrecheck{ - std::string name; - PrecheckPolicy policy; - - bool operator==(const ListedPrecheck&) const = default; -}; - -struct RngPrechecksInput{ - size_t free_party_slots_needed; -}; - -struct RngPrechecksExpectation{ - std::vector checks; -}; - -struct RngPrechecksCase{ - std::string name; - RngPrechecksInput input; - RngPrechecksExpectation expectation; -}; - -class Test_RngPrechecks : public UnitTest{ -public: - explicit Test_RngPrechecks(RngPrechecksCase test_case) - : UnitTest(std::format("PokemonFRLG::Prechecks::RngPrechecks - {}", test_case.name)) - , m_case(std::move(test_case)) - {} - - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - std::vector listed; - for (const std::unique_ptr& check : rng_prechecks(m_case.input.free_party_slots_needed)){ - if (check->needs().empty()){ - return std::format("Precheck {} must say what it needs.", check->name()); - } - listed.emplace_back(ListedPrecheck{check->name(), check->policy()}); - } - if (listed != m_case.expectation.checks){ - return "The RNG precheck list has the wrong checks, order or policies."; - } - return true; - } - -private: - RngPrechecksCase m_case; -}; - - -struct FreePartySlotsInput{ - size_t party_size; - size_t free_slots_needed; -}; - -struct FreePartySlotsExpectation{ - PrecheckStatus status; - // Checked only on FAILED: the message the user sees. - std::string message; -}; - -struct FreePartySlotsCase{ - std::string name; - FreePartySlotsInput input; - FreePartySlotsExpectation expectation; -}; - -class Test_FreePartySlotsOutcome : public UnitTest{ -public: - explicit Test_FreePartySlotsOutcome(FreePartySlotsCase test_case) - : UnitTest(std::format("PokemonFRLG::Prechecks::FreePartySlotsOutcome - {}", test_case.name)) - , m_case(std::move(test_case)) - {} - - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const PrecheckOutcome outcome = free_party_slots_outcome( - m_case.input.party_size, m_case.input.free_slots_needed - ); - if (outcome.status != m_case.expectation.status){ - return std::format("Wrong verdict: \"{}\"", outcome.message); - } - if (outcome.status == PrecheckStatus::FAILED && outcome.message != m_case.expectation.message){ - return std::format("Wrong message: \"{}\"", outcome.message); - } - return true; - } - -private: - FreePartySlotsCase m_case; -}; - - -const ListedPrecheck BLACK_BORDER{"black_border", PrecheckPolicy::ALWAYS_RUNS}; -const ListedPrecheck FREE_PARTY_SLOTS{"free_party_slots", PrecheckPolicy::SKIPPABLE}; - -const std::vector RNG_PRECHECKS_CASES{ - {.name = "NeedsNoSlots", .input = {0}, .expectation = {{BLACK_BORDER}}}, - {.name = "NeedsOneSlot", .input = {1}, .expectation = {{BLACK_BORDER, FREE_PARTY_SLOTS}}}, - {.name = "NeedsTwoSlots", .input = {2}, .expectation = {{BLACK_BORDER, FREE_PARTY_SLOTS}}}, -}; - -// The messages are the ones the party check showed before it moved onto the -// precheck list. -const std::vector FREE_PARTY_SLOTS_CASES{ - {.name = "FiveOfSixNeedsOne", .input = {5, 1}, .expectation = {PrecheckStatus::PASSED, ""}}, - { - .name = "FullPartyNeedsOne", - .input = {6, 1}, - .expectation = { - PrecheckStatus::FAILED, - "Your party is full. Leave a party slot free so the program can check the " - "Pokémon it catches or receives.", - }, - }, - {.name = "FourOfSixNeedsTwo", .input = {4, 2}, .expectation = {PrecheckStatus::PASSED, ""}}, - { - .name = "FiveOfSixNeedsTwo", - .input = {5, 2}, - .expectation = { - PrecheckStatus::FAILED, - "Your party has 5 Pokémon. Leave at least 2 party slots free for the " - "Pokémon the program catches or receives.", - }, - }, -}; - - -} // namespace - - -void add_tests_Prechecks(UnitTestDatabase& database){ - for (const RngPrechecksCase& test_case : RNG_PRECHECKS_CASES){ - database.add(test_case); - } - for (const FreePartySlotsCase& test_case : FREE_PARTY_SLOTS_CASES){ - database.add(test_case); - } -} - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h deleted file mode 100644 index 29d6a11284..0000000000 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h +++ /dev/null @@ -1,24 +0,0 @@ -/* FRLG Prechecks - Tests - * - * From: https://github.com/PokemonAutomation/ - * - */ - -#ifndef PokemonAutomation_PokemonFRLG_Prechecks_Tests_H -#define PokemonAutomation_PokemonFRLG_Prechecks_Tests_H - -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" - -namespace PokemonAutomation{ -namespace NintendoSwitch{ -namespace PokemonFRLG{ - - -// Registers the precheck unit tests. -void add_tests_Prechecks(UnitTestDatabase& database); - - -} // namespace PokemonFRLG -} // namespace NintendoSwitch -} // namespace PokemonAutomation -#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 0dd809965a..94dc41dd85 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -30,7 +30,6 @@ #include "Programs/BoxOrganization/PokemonFRLG_BoxSorter_Tests.h" #include "Tests/TestUtils.h" -#include "PokemonFRLG_Prechecks_Tests.h" #include "PokemonFRLG_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -55,7 +54,6 @@ void add_tests(UnitTestDatabase& database){ add_tests_PartyHeldItemDetector(database); add_tests_PartyLevelUpReader(database); add_tests_PartyMenuDetector(database); - add_tests_Prechecks(database); add_tests_PrizeSelectDetector(database); add_tests_PartySlotDetector(database); add_tests_StatsReader(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 3b95ab5762..d4257d7f37 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -4,7 +4,13 @@ * */ -#include "VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h" +#include +#include +#include "Common/Cpp/Exceptions.h" +#include "CommonFramework/Exceptions/OperationFailedException.h" +#include "Pokemon/Pokemon_Strings.h" +#include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" #include "VideoGames/PokemonFRLG/PokemonFRLG_Settings.h" #include "PokemonFRLG_RngProgram.h" @@ -13,27 +19,59 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -PrecheckList rng_prechecks(size_t free_party_slots_needed){ - PrecheckList checks; - checks.emplace_back(make_black_border_precheck()); - if (free_party_slots_needed > 0){ - checks.emplace_back(make_free_party_slots_precheck(free_party_slots_needed)); +namespace{ + +std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ + if (free_slots_needed == 1){ + return std::format( + "Your party is full. Leave a party slot free so the program can check the {} it catches or receives.", + Pokemon::STRING_POKEMON + ); } - return checks; + return std::format( + "Your party has {} {}. Leave at least {} party slots free for the {} the program catches or receives.", + party_size, Pokemon::STRING_POKEMON, free_slots_needed, Pokemon::STRING_POKEMON + ); } -PrecheckList RngProgramInstance::prechecks() const{ - return rng_prechecks(free_party_slots_needed()); +} // namespace + + +void RngProgramInstance::check_free_party_slots( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context +){ + const size_t free_slots_needed = free_party_slots_needed(); + if (free_slots_needed == 0){ + return; + } + Logger& logger = env.console.logger(); + logger.log("Checking for " + std::to_string(free_slots_needed) + " free party slot(s)..."); + try{ + open_party_menu_from_overworld(env.console, context); + }catch (OperationFailedException&){ + logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); + return; + } + context.wait_for_all_requests(); + constexpr size_t MAX_PARTY_SIZE = 6; + const size_t party_size = static_cast(detect_last_occupied_party_slot(env.console)) + 1; + if (MAX_PARTY_SIZE - party_size < free_slots_needed){ + throw UserSetupError(logger, not_enough_free_slots_message(party_size, free_slots_needed)); + } + logger.log("Party has enough free slots."); } void RngProgramInstance::run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context ){ - const SkippablePrechecks skippable = GameSettings::instance().RUN_RNG_START_CHECKS - ? SkippablePrechecks::RUN - : SkippablePrechecks::SKIP; - run_prechecks(env, context, prechecks(), skippable); + home_black_border_check(env.console, context); + if (!GameSettings::instance().RUN_RNG_START_CHECKS){ + env.console.log("Start checks are off in the FRLG Game Settings. Skipping them."); + return; + } + check_free_party_slots(env, context); } } // namespace PokemonFRLG diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 8e8cc64055..727ba9b099 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -14,18 +14,12 @@ #include #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" -#include "NintendoSwitch/Programs/NintendoSwitch_Prechecks.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonFRLG{ -// The prechecks of an RNG program that needs free_party_slots_needed free -// party slots: black_border, then free_party_slots when it needs any. -PrecheckList rng_prechecks(size_t free_party_slots_needed); - - // Base class of the RNG programs. class RngProgramInstance : public SingleSwitchProgramInstance{ public: @@ -36,18 +30,21 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ // party that Pokemon would go to the PC instead. virtual size_t free_party_slots_needed() const = 0; - // What the program needs before it starts, in the order run_precheck() - // checks it. Does not touch the console. - PrecheckList prechecks() const; - protected: // Call first in program(), with the game on the overworld where the - // player saved: runs prechecks(). "Run Start Checks" off in the FRLG Game - // Settings skips the SKIPPABLE ones. Throws UserSetupError if a check fails. + // player saved: checks the party has the free slots + // free_party_slots_needed() asks for, then goes Home for the black + // border check. Throws UserSetupError if a check fails. void run_precheck( SingleSwitchProgramEnvironment& env, ProControllerContext& context ); + +private: + void check_free_party_slots( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context + ); }; diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index e85cd7987f..5bde7d3e75 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1417,10 +1417,6 @@ file(GLOB LIBRARY_SOURCES Source/NintendoSwitch/Programs/NintendoSwitch_GameEntry.h Source/NintendoSwitch/Programs/NintendoSwitch_MenuStabilityTester.cpp Source/NintendoSwitch/Programs/NintendoSwitch_MenuStabilityTester.h - Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.cpp - Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks.h - Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.cpp - Source/NintendoSwitch/Programs/NintendoSwitch_Prechecks_Tests.h Source/NintendoSwitch/Programs/NintendoSwitch_PreventSleep.cpp Source/NintendoSwitch/Programs/NintendoSwitch_PreventSleep.h Source/NintendoSwitch/Programs/NintendoSwitch_PushJoySticks.cpp @@ -1771,10 +1767,6 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Panels.h - Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.cpp - Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks.h - Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.cpp - Source/VideoGames/PokemonFRLG/PokemonFRLG_Prechecks_Tests.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.cpp Source/VideoGames/PokemonFRLG/PokemonFRLG_Settings.h Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp