From 2addd8f1e1d2be64b3e3b144df2cb90c560e9a80 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 29 Oct 2026 12:11:00 -0700 Subject: [PATCH 01/12] FRLG RNG: check the party before the program starts Static, Wild, Gift and Roaming RNG read the Pokemon they catch or receive from the end of the party. With a full party it goes to the PC instead, every attempt reads the wrong Pokemon, and after a few resets the program stops with "The target Seed is missing from the list of nearby seeds", which points at the wrong setting. SingleSwitchProgramInstance gets start_program_game_checks(), a no-op hook called with the controller ready just before program(), for checking that the game is set up the way a program needs. The FRLG RNG programs now derive from RngProgramInstance, which implements it from a required party_requirement() (and start_menu_context() for the Safari Zone): with FREE_SLOT it opens the party and stops with a setup error naming the real problem, or skips the check if the party menu can't be opened. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../NintendoSwitch_SingleSwitchProgram.cpp | 1 + .../NintendoSwitch_SingleSwitchProgram.h | 9 +++ .../RngManipulation/PokemonFRLG_EggRng.h | 5 +- .../RngManipulation/PokemonFRLG_GiftRng.h | 5 +- .../RngManipulation/PokemonFRLG_RngHelper.h | 5 +- .../PokemonFRLG_RngNavigation.h | 11 ++++ .../PokemonFRLG_RngProgram.cpp | 31 +++++++++++ .../RngManipulation/PokemonFRLG_RngProgram.h | 55 +++++++++++++++++++ .../PokemonFRLG_RoamingLegendaryRng.h | 5 +- .../RngManipulation/PokemonFRLG_StarterRng.h | 5 +- .../RngManipulation/PokemonFRLG_StaticRng.h | 5 +- .../RngManipulation/PokemonFRLG_WildRng.h | 8 ++- SerialPrograms/cmake/SourceFiles.cmake | 2 + 13 files changed, 133 insertions(+), 14 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/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index 5462ee2eac..1b09f20fd5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h @@ -14,7 +14,7 @@ #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonFramework/Options/LabelCellOption.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Options/Pokemon_NameSelectOption.h" #include "Pokemon/Pokemon_AdvRng.h" @@ -56,9 +56,10 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class EggRng : public SingleSwitchProgramInstance, public ConfigOption::Listener{ +class EggRng : public RngProgramInstance, public ConfigOption::Listener{ public: using Descriptor = EggRng_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::NONE; } ~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..4afdbeb822 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h @@ -12,7 +12,7 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngDisplays.h" @@ -29,9 +29,10 @@ class GiftRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class GiftRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +class GiftRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = GiftRng_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } ~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..046bb7a493 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h @@ -13,7 +13,7 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" @@ -28,9 +28,10 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class RngHelper : public SingleSwitchProgramInstance{ +class RngHelper : public RngProgramInstance{ public: using Descriptor = RngHelper_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::NONE; } 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_RngNavigation.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h index 6179ca74cf..4410462e7a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h @@ -26,6 +26,17 @@ static const std::set ROAMER_ROUTE1_SUBSET = { "raikou", "suicune", "entei", "rattata", "pidgey" }; +// Starting from the overworld, check that the party has a free slot for the +// Pokemon the program will catch or receive; without one it goes to the PC +// and the program reads the wrong Pokemon. Throws UserSetupError if the party +// is full. If the party menu can't be opened, logs that and returns. +// Leaves the party menu open. +void check_party_has_free_slot( + ConsoleHandle& console, + ProControllerContext& context, + StartMenuContext menu_context = StartMenuContext::STANDARD +); + void go_to_summary( ConsoleHandle& console, ProControllerContext& context, 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..2742242391 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -0,0 +1,31 @@ +/* RNG Program + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "PokemonFRLG_RngNavigation.h" +#include "PokemonFRLG_RngProgram.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +void RngProgramInstance::start_program_game_checks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context +){ + switch (party_requirement()){ + case PartyRequirement::NONE: + break; + case PartyRequirement::FREE_SLOT: + check_party_has_free_slot(env.console, context, start_menu_context()); + break; + } +} + + +} +} +} 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..555883253f --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -0,0 +1,55 @@ +/* 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 "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonFRLG{ + + +enum class PartyRequirement{ + NONE, + // The program catches or receives a Pokemon and reads it from the end of + // the party. In a full party it would go to the PC instead. + FREE_SLOT, +}; + + +class RngProgramInstance : public SingleSwitchProgramInstance{ +public: + using SingleSwitchProgramInstance::SingleSwitchProgramInstance; + + // What the program needs from the party. + virtual PartyRequirement party_requirement() 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. + virtual void start_program_game_checks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context + ) override; +}; + + +} +} +} +#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..714604e08c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h @@ -12,7 +12,7 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" #include "PokemonFRLG_RngDisplays.h" @@ -29,9 +29,10 @@ class RoamingLegendaryRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class RoamingLegendaryRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +class RoamingLegendaryRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = RoamingLegendaryRng_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } ~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..78274f7733 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h @@ -12,7 +12,7 @@ #include "Common/Cpp/Options/StaticTextOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Pokemon_StatsCalculation.h" #include "Pokemon/Pokemon_AdvRng.h" @@ -30,9 +30,10 @@ class StarterRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class StarterRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +class StarterRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StarterRng_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::NONE; } ~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..cd39f725b3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h @@ -14,7 +14,7 @@ #include "Common/Cpp/Options/TextEditOption.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Pokemon_StatsCalculation.h" #include "Pokemon/Pokemon_AdvRng.h" @@ -34,9 +34,10 @@ class StaticRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class StaticRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +class StaticRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StaticRng_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } ~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..3c442d52a7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h @@ -13,7 +13,7 @@ #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "CommonTools/Options/LanguageOCROption.h" #include "CommonTools/Options/StringSelectOption.h" -#include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" +#include "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "Pokemon/Pokemon_AdvRng.h" #include "PokemonFRLG_BlindNavigation.h" @@ -31,9 +31,13 @@ class WildRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; -class WildRng : public SingleSwitchProgramInstance, private ConfigOption::Listener{ +class WildRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = WildRng_Descriptor; + virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } + 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 9e4e0895bb..bb241a622a 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -1766,6 +1766,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 9f36e0db2cf418b3ed3507ab6789fc8b852e12c5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 29 Oct 2026 19:30:27 -0700 Subject: [PATCH 02/12] FRLG RNG: keep the party check with the RNG program base; sort its include The free-slot check is only used by RngProgramInstance, so it lives in PokemonFRLG_RngProgram.cpp instead of RngNavigation. The base class's header joins the other same-folder includes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../RngManipulation/PokemonFRLG_EggRng.h | 2 +- .../RngManipulation/PokemonFRLG_GiftRng.h | 2 +- .../RngManipulation/PokemonFRLG_RngHelper.h | 2 +- .../PokemonFRLG_RngNavigation.h | 11 ------- .../PokemonFRLG_RngProgram.cpp | 33 ++++++++++++++++++- .../PokemonFRLG_RoamingLegendaryRng.h | 2 +- .../RngManipulation/PokemonFRLG_StarterRng.h | 2 +- .../RngManipulation/PokemonFRLG_StaticRng.h | 2 +- .../RngManipulation/PokemonFRLG_WildRng.h | 2 +- 9 files changed, 39 insertions(+), 19 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index 1b09f20fd5..03cbbbb706 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 "PokemonFRLG_RngProgram.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" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h index 4afdbeb822..03eb0cbe66 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 "PokemonFRLG_RngProgram.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{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h index 046bb7a493..a262d8a1df 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 "PokemonFRLG_RngProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" #include "PokemonFRLG_BlindNavigation.h" +#include "PokemonFRLG_RngProgram.h" namespace PokemonAutomation{ namespace NintendoSwitch{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h index 4410462e7a..6179ca74cf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngNavigation.h @@ -26,17 +26,6 @@ static const std::set ROAMER_ROUTE1_SUBSET = { "raikou", "suicune", "entei", "rattata", "pidgey" }; -// Starting from the overworld, check that the party has a free slot for the -// Pokemon the program will catch or receive; without one it goes to the PC -// and the program reads the wrong Pokemon. Throws UserSetupError if the party -// is full. If the party menu can't be opened, logs that and returns. -// Leaves the party menu open. -void check_party_has_free_slot( - ConsoleHandle& console, - ProControllerContext& context, - StartMenuContext menu_context = StartMenuContext::STANDARD -); - void go_to_summary( ConsoleHandle& console, ProControllerContext& context, diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 2742242391..bd26c24a47 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -4,7 +4,10 @@ * */ -#include "PokemonFRLG_RngNavigation.h" +#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{ @@ -12,6 +15,34 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ +namespace{ + +// Starting from the overworld, checks that the party has a free slot for the +// Pokemon the program will catch or receive; without one it goes to the PC +// and the program reads the wrong Pokemon. Throws UserSetupError if the party +// is full. If the party menu can't be opened, logs that and returns. Leaves +// the party menu open. +void check_party_has_free_slot(ConsoleHandle& console, ProControllerContext& context, StartMenuContext menu_context){ + console.log("Checking for a free party slot..."); + try{ + open_party_menu_from_overworld(console, context, menu_context); + }catch (OperationFailedException&){ + console.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); + return; + } + context.wait_for_all_requests(); + if (detect_last_occupied_party_slot(console) == PartySlot::SIX){ + throw UserSetupError( + console, + "Your party is full. Leave a party slot free so the program can check the " + Pokemon::STRING_POKEMON + " it catches." + ); + } + console.log("Party has a free slot."); +} + +} + + void RngProgramInstance::start_program_game_checks( SingleSwitchProgramEnvironment& env, ProControllerContext& context diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h index 714604e08c..a25fe3da63 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 "PokemonFRLG_RngProgram.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{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h index 78274f7733..72ed61bf62 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 "PokemonFRLG_RngProgram.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{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h index cd39f725b3..0bc3269983 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 "PokemonFRLG_RngProgram.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{ diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h index 3c442d52a7..4226a4b813 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 "PokemonFRLG_RngProgram.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{ From bdbeb41d4894efacc685cb6645b49358c9cc107e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 10:06:35 -0700 Subject: [PATCH 03/12] FRLG RNG: unit test the party check Take the party check's game steps through a small PartyCheckActions interface, so check_party_requirement() runs against scripted steps in tests, and read the last occupied party slot from an image, so it runs on the party menu screenshots already in CommandLineTests. Behavior is unchanged. Tests: PokemonFRLG::RngPartyCheck (no requirement, free slot, full party, menu not opened) and PokemonFRLG::LastOccupiedPartySlot (Party_1..6 and the held-item/JPN/SPA party screenshots). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Navigation.cpp | 7 +- .../PokemonFRLG/PokemonFRLG_Navigation.h | 2 + .../PokemonFRLG/PokemonFRLG_Tests.cpp | 144 ++++++++++++++++++ .../PokemonFRLG_RngProgram.cpp | 68 ++++++--- .../RngManipulation/PokemonFRLG_RngProgram.h | 25 +++ 5 files changed, 224 insertions(+), 22 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp index 970080ca26..49d239d45f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp @@ -839,7 +839,10 @@ void open_party_menu_from_overworld(ConsoleHandle& console, ProControllerContext } PartySlot detect_last_occupied_party_slot(ConsoleHandle& console){ - const auto snapshot = console.video().snapshot(); + 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, @@ -850,7 +853,7 @@ PartySlot detect_last_occupied_party_slot(ConsoleHandle& console){ 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..b5105b6e0a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h @@ -11,6 +11,7 @@ #include "Common/Cpp/Logging/AbstractLogger.h" #include "CommonFramework/Language.h" +#include "CommonFramework/ImageTypes/ImageViewRGB32.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" @@ -136,6 +137,7 @@ 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); +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 d51e585590..de7812963c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -5,9 +5,11 @@ */ #include +#include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/StaticGlobals.h" +#include "Tests/ImageUnitTest.h" #include "Tests/TestUtils.h" #include "Inference/Dialogs/PokemonFRLG_BattleDialogs.h" #include "Inference/Dialogs/PokemonFRLG_DialogDetector.h" @@ -23,6 +25,7 @@ #include "Inference/PokemonFRLG_StatsReader.h" #include "Inference/PokemonFRLG_TrainerIdReader.h" #include "Inference/PokemonFRLG_WildEncounterReader.h" +#include "Programs/RngManipulation/PokemonFRLG_RngProgram.h" #include "PokemonFRLG_Navigation.h" #include "PokemonFRLG_Tests.h" @@ -255,6 +258,145 @@ 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(const std::string& image, PartySlot expected) + : ImageUnitTest("PokemonFRLG::LastOccupiedPartySlot - " + image, {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 "Expected last occupied slot " + slot_name(m_expected) + ", got " + 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::THREE); + database.add("PokemonFRLG/Party/SPA_HeldItem.png", PartySlot::SIX); +} + +// Steps that return scripted reads, and record what check_party_requirement() 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 PartyCheckScenario{ + std::string name; + PartyRequirement requirement = PartyRequirement::FREE_SLOT; + bool menu_opens = true; + PartySlot last_occupied = PartySlot::ONE; + std::string expected_steps = ""; + // Start of the UserSetupError message; empty if the check passes. + std::string expected_error = ""; +}; + +class Test_PartyCheck : public UnitTest{ +public: + Test_PartyCheck(PartyCheckScenario scenario) + : UnitTest("PokemonFRLG::RngPartyCheck - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + ScriptedPartyCheck actions; + actions.menu_opens = m_scenario.menu_opens; + actions.last_occupied = m_scenario.last_occupied; + + NullLogger logger; + std::string error; + try{ + check_party_requirement(logger, m_scenario.requirement, actions); + }catch (UserSetupError& e){ + error = e.message(); + } + const bool error_matches = m_scenario.expected_error.empty() + ? error.empty() + : error.rfind(m_scenario.expected_error, 0) == 0; + if (!error_matches){ + return "Expected error: \"" + m_scenario.expected_error + "\"\nActual error: \"" + error + "\""; + } + if (actions.steps != m_scenario.expected_steps){ + return "Expected steps: " + m_scenario.expected_steps + "\nActual steps: " + actions.steps; + } + return true; + } + +private: + const PartyCheckScenario m_scenario; +}; + +void add_tests_PartyCheck(UnitTestDatabase& database){ + const PartyCheckScenario scenarios[] = { + { + // Programs that don't add a Pokemon to the party don't open the menu. + .name = "no requirement, full party", + .requirement = PartyRequirement::NONE, + .last_occupied = PartySlot::SIX, + }, + { + .name = "one Pokemon", + .expected_steps = "open read", + }, + { + .name = "five Pokemon", + .last_occupied = PartySlot::FIVE, + .expected_steps = "open read", + }, + { + .name = "full party", + .last_occupied = PartySlot::SIX, + .expected_steps = "open read", + .expected_error = "Your party is full. Leave a party slot free", + }, + { + // A menu that can't be opened skips the check rather than stopping the program. + .name = "party menu not opened", + .menu_opens = false, + .last_occupied = PartySlot::SIX, + .expected_steps = "open", + }, + }; + for (const PartyCheckScenario& scenario : scenarios){ + database.add(scenario); + } +} + } @@ -278,6 +420,8 @@ void add_tests(UnitTestDatabase& database){ add_tests_HallOfFameSavingDetector(database); add_tests_BattleMoveSelectionArrow(database); add_tests_ExitWildBattle(database); + add_tests_LastOccupiedPartySlot(database); + add_tests_PartyCheck(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index bd26c24a47..e9079bf77b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -17,46 +17,74 @@ namespace PokemonFRLG{ namespace{ -// Starting from the overworld, checks that the party has a free slot for the -// Pokemon the program will catch or receive; without one it goes to the PC -// and the program reads the wrong Pokemon. Throws UserSetupError if the party -// is full. If the party menu can't be opened, logs that and returns. Leaves -// the party menu open. -void check_party_has_free_slot(ConsoleHandle& console, ProControllerContext& context, StartMenuContext menu_context){ - console.log("Checking for a free party slot..."); - try{ - open_party_menu_from_overworld(console, context, menu_context); - }catch (OperationFailedException&){ - console.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); +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; +}; + +// Without a free slot, the Pokemon the program catches or receives goes to +// the PC and the program reads the wrong Pokemon. +void check_party_has_free_slot(Logger& logger, PartyCheckActions& actions){ + logger.log("Checking for a free party slot..."); + if (!actions.open_party_menu()){ + logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); return; } - context.wait_for_all_requests(); - if (detect_last_occupied_party_slot(console) == PartySlot::SIX){ + if (actions.read_last_occupied_slot() == PartySlot::SIX){ throw UserSetupError( - console, + logger, "Your party is full. Leave a party slot free so the program can check the " + Pokemon::STRING_POKEMON + " it catches." ); } - console.log("Party has a free slot."); + logger.log("Party has a free slot."); } } -void RngProgramInstance::start_program_game_checks( - SingleSwitchProgramEnvironment& env, - ProControllerContext& context +void check_party_requirement( + Logger& logger, + PartyRequirement requirement, + PartyCheckActions& actions ){ - switch (party_requirement()){ + switch (requirement){ case PartyRequirement::NONE: break; case PartyRequirement::FREE_SLOT: - check_party_has_free_slot(env.console, context, start_menu_context()); + check_party_has_free_slot(logger, actions); break; } } +void RngProgramInstance::start_program_game_checks( + SingleSwitchProgramEnvironment& env, + ProControllerContext& context +){ + ConsolePartyCheckActions actions(env.console, context, start_menu_context()); + check_party_requirement(env.console.logger(), party_requirement(), actions); +} + } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 555883253f..e0544a615a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -12,7 +12,9 @@ #ifndef PokemonAutomation_PokemonFRLG_RngProgram_H #define PokemonAutomation_PokemonFRLG_RngProgram_H +#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{ @@ -28,6 +30,29 @@ enum class PartyRequirement{ }; +// The game steps that check_party_requirement() 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 meets `requirement`, 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_requirement( + Logger& logger, + PartyRequirement requirement, + PartyCheckActions& actions +); + + class RngProgramInstance : public SingleSwitchProgramInstance{ public: using SingleSwitchProgramInstance::SingleSwitchProgramInstance; From fda0033f180389a113d22c5a9d8b96a42cd7fbd3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 10:16:37 -0700 Subject: [PATCH 04/12] FRLG RNG: test each program's party requirement from its settings Build each FRLG RNG program, load its settings from JSON, and check the party requirement and start menu its start check uses (WildRng on Route 1 and in the Safari Zone). Make RngProgramInstance's start hook final, so no RNG program can skip the check by overriding it. Behavior is unchanged. Tests: PokemonFRLG::RngProgramPartyRequirement. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 111 ++++++++++++++++++ .../RngManipulation/PokemonFRLG_RngProgram.h | 5 +- 2 files changed, 114 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index de7812963c..54e2f734ad 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -5,8 +5,13 @@ */ #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 "Tests/ImageUnitTest.h" @@ -25,7 +30,14 @@ #include "Inference/PokemonFRLG_StatsReader.h" #include "Inference/PokemonFRLG_TrainerIdReader.h" #include "Inference/PokemonFRLG_WildEncounterReader.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 "PokemonFRLG_Tests.h" @@ -397,6 +409,104 @@ void add_tests_PartyCheck(UnitTestDatabase& database){ } } + +std::string requirement_name(PartyRequirement requirement){ + switch (requirement){ + case PartyRequirement::NONE: return "NONE"; + case PartyRequirement::FREE_SLOT: return "FREE_SLOT"; + } + return "?"; +} +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 "?"; +} + +struct RngProgramPartyScenario{ + std::string name; + std::function()> make_program; + // Program settings by option name, as in the saved settings JSON. + std::map settings = {}; + PartyRequirement expected_requirement; + StartMenuContext expected_menu_context = StartMenuContext::STANDARD; +}; + +// 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(RngProgramPartyScenario scenario) + : UnitTest("PokemonFRLG::RngProgramPartyRequirement - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + std::unique_ptr program = m_scenario.make_program(); + JsonObject settings; + for (const auto& [option, value] : m_scenario.settings){ + settings[option] = value; + } + program->load_json(JsonValue(std::move(settings))); + + const PartyRequirement requirement = program->party_requirement(); + if (requirement != m_scenario.expected_requirement){ + return "Expected party requirement " + requirement_name(m_scenario.expected_requirement) + + ", got " + requirement_name(requirement); + } + const StartMenuContext menu_context = program->start_menu_context(); + if (menu_context != m_scenario.expected_menu_context){ + return "Expected start menu " + menu_context_name(m_scenario.expected_menu_context) + + ", got " + menu_context_name(menu_context); + } + return true; + } + +private: + const RngProgramPartyScenario m_scenario; +}; + +template +std::unique_ptr make_rng_program(){ + return std::make_unique(); +} + +void add_tests_RngProgramPartyRequirement(UnitTestDatabase& database){ + using enum PartyRequirement; + const RngProgramPartyScenario scenarios[] = { + {.name = "RngHelper", .make_program = make_rng_program, .expected_requirement = NONE}, + {.name = "StarterRng", .make_program = make_rng_program, .expected_requirement = NONE}, + {.name = "EggRng", .make_program = make_rng_program, .expected_requirement = NONE}, + {.name = "GiftRng", .make_program = make_rng_program, .expected_requirement = FREE_SLOT}, + {.name = "StaticRng", .make_program = make_rng_program, .expected_requirement = FREE_SLOT}, + { + .name = "RoamingLegendaryRng", + .make_program = make_rng_program, + .expected_requirement = FREE_SLOT, + }, + { + .name = "WildRng on Route 1", + .make_program = make_rng_program, + .settings = {{"GAME_LOCATION", "route_1"}}, + .expected_requirement = FREE_SLOT, + }, + { + // The Safari Zone start menu has no POKEMON entry in the usual place. + .name = "WildRng in the Safari Zone", + .make_program = make_rng_program, + .settings = {{"GAME_LOCATION", "safari_zone_entrance"}}, + .expected_requirement = FREE_SLOT, + .expected_menu_context = StartMenuContext::SAFARI_ZONE, + }, + }; + for (const RngProgramPartyScenario& scenario : scenarios){ + database.add(scenario); + } +} + } @@ -422,6 +532,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_ExitWildBattle(database); add_tests_LastOccupiedPartySlot(database); add_tests_PartyCheck(database); + add_tests_RngProgramPartyRequirement(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index e0544a615a..0ebcd4d99f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -66,11 +66,12 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ } // Runs with the game on the overworld where the player saved. May leave a - // menu open: the program's first reset closes the game. + // menu open: the program's first reset closes the game. Final so that + // every RNG program runs the check its party_requirement() asks for. virtual void start_program_game_checks( SingleSwitchProgramEnvironment& env, ProControllerContext& context - ) override; + ) override final; }; From 85c066ea337b3237587454e7972aa50aa6030767 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 10:18:06 -0700 Subject: [PATCH 05/12] FRLG RNG: JPN_Party.png has four Pokemon The party screenshot test expected three; the existing empty-slot tests for the same image mark slots 5 and 6 empty. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 54e2f734ad..92b4ee2843 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -307,7 +307,7 @@ void add_tests_LastOccupiedPartySlot(UnitTestDatabase& database){ } 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::THREE); + database.add("PokemonFRLG/Party/JPN_Party.png", PartySlot::FOUR); database.add("PokemonFRLG/Party/SPA_HeldItem.png", PartySlot::SIX); } From 24113fb5f7056b30a0831395b6c7fa39112a4918 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 31 Oct 2026 10:37:22 -0700 Subject: [PATCH 06/12] FRLG RNG: check the number of free party slots each program needs EggRng needs three free slots (the egg and the two wild Pokemon it catches to confirm the seed), and what RngHelper needs depends on its target: gifts, prizes, Togepi and the daycare egg pickup read the received Pokemon from the party, while encounters are only watched. So programs now say how many free slots they need instead of whether they need one, and RngHelper derives it from its Target setting. Tests: PokemonFRLG::RngPartyCheck adds three-slot cases; PokemonFRLG::RngProgramPartyRequirement covers EggRng and RngHelper targets. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 80 ++++++++++--------- .../RngManipulation/PokemonFRLG_EggRng.h | 3 +- .../RngManipulation/PokemonFRLG_GiftRng.h | 2 +- .../RngManipulation/PokemonFRLG_RngHelper.cpp | 31 +++++++ .../RngManipulation/PokemonFRLG_RngHelper.h | 2 +- .../PokemonFRLG_RngProgram.cpp | 46 +++++------ .../RngManipulation/PokemonFRLG_RngProgram.h | 28 +++---- .../PokemonFRLG_RoamingLegendaryRng.h | 2 +- .../RngManipulation/PokemonFRLG_StarterRng.h | 2 +- .../RngManipulation/PokemonFRLG_StaticRng.h | 2 +- .../RngManipulation/PokemonFRLG_WildRng.h | 2 +- 11 files changed, 118 insertions(+), 82 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 92b4ee2843..217f2c6c33 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -311,7 +311,7 @@ void add_tests_LastOccupiedPartySlot(UnitTestDatabase& database){ database.add("PokemonFRLG/Party/SPA_HeldItem.png", PartySlot::SIX); } -// Steps that return scripted reads, and record what check_party_requirement() asked for. +// Steps that return scripted reads, and record what check_party_free_slots() asked for. class ScriptedPartyCheck : public PartyCheckActions{ public: bool menu_opens = true; @@ -330,7 +330,7 @@ class ScriptedPartyCheck : public PartyCheckActions{ struct PartyCheckScenario{ std::string name; - PartyRequirement requirement = PartyRequirement::FREE_SLOT; + size_t free_slots_needed = 1; bool menu_opens = true; PartySlot last_occupied = PartySlot::ONE; std::string expected_steps = ""; @@ -353,7 +353,7 @@ class Test_PartyCheck : public UnitTest{ NullLogger logger; std::string error; try{ - check_party_requirement(logger, m_scenario.requirement, actions); + check_party_free_slots(logger, m_scenario.free_slots_needed, actions); }catch (UserSetupError& e){ error = e.message(); } @@ -377,24 +377,30 @@ void add_tests_PartyCheck(UnitTestDatabase& database){ const PartyCheckScenario scenarios[] = { { // Programs that don't add a Pokemon to the party don't open the menu. - .name = "no requirement, full party", - .requirement = PartyRequirement::NONE, + .name = "no free slot needed, full party", + .free_slots_needed = 0, .last_occupied = PartySlot::SIX, }, + {.name = "one free slot needed, one Pokemon", .expected_steps = "open read"}, + {.name = "one free slot needed, five Pokemon", .last_occupied = PartySlot::FIVE, .expected_steps = "open read"}, { - .name = "one Pokemon", + .name = "one free slot needed, full party", + .last_occupied = PartySlot::SIX, .expected_steps = "open read", + .expected_error = "Your party is full. Leave a party slot free", }, { - .name = "five Pokemon", - .last_occupied = PartySlot::FIVE, + .name = "three free slots needed, three Pokemon", + .free_slots_needed = 3, + .last_occupied = PartySlot::THREE, .expected_steps = "open read", }, { - .name = "full party", - .last_occupied = PartySlot::SIX, + .name = "three free slots needed, four Pokemon", + .free_slots_needed = 3, + .last_occupied = PartySlot::FOUR, .expected_steps = "open read", - .expected_error = "Your party is full. Leave a party slot free", + .expected_error = "Your party has 4 ", }, { // A menu that can't be opened skips the check rather than stopping the program. @@ -410,13 +416,6 @@ void add_tests_PartyCheck(UnitTestDatabase& database){ } -std::string requirement_name(PartyRequirement requirement){ - switch (requirement){ - case PartyRequirement::NONE: return "NONE"; - case PartyRequirement::FREE_SLOT: return "FREE_SLOT"; - } - return "?"; -} std::string menu_context_name(StartMenuContext context){ switch (context){ case StartMenuContext::STANDARD: return "STANDARD"; @@ -431,7 +430,7 @@ struct RngProgramPartyScenario{ std::function()> make_program; // Program settings by option name, as in the saved settings JSON. std::map settings = {}; - PartyRequirement expected_requirement; + size_t expected_free_slots; StartMenuContext expected_menu_context = StartMenuContext::STANDARD; }; @@ -452,10 +451,10 @@ class Test_RngProgramPartyRequirement : public UnitTest{ } program->load_json(JsonValue(std::move(settings))); - const PartyRequirement requirement = program->party_requirement(); - if (requirement != m_scenario.expected_requirement){ - return "Expected party requirement " + requirement_name(m_scenario.expected_requirement) - + ", got " + requirement_name(requirement); + const size_t free_slots = program->free_party_slots_needed(); + if (free_slots != m_scenario.expected_free_slots){ + return "Expected " + std::to_string(m_scenario.expected_free_slots) + " free party slots needed, got " + + std::to_string(free_slots); } const StartMenuContext menu_context = program->start_menu_context(); if (menu_context != m_scenario.expected_menu_context){ @@ -475,36 +474,45 @@ std::unique_ptr make_rng_program(){ } void add_tests_RngProgramPartyRequirement(UnitTestDatabase& database){ - using enum PartyRequirement; const RngProgramPartyScenario scenarios[] = { - {.name = "RngHelper", .make_program = make_rng_program, .expected_requirement = NONE}, - {.name = "StarterRng", .make_program = make_rng_program, .expected_requirement = NONE}, - {.name = "EggRng", .make_program = make_rng_program, .expected_requirement = NONE}, - {.name = "GiftRng", .make_program = make_rng_program, .expected_requirement = FREE_SLOT}, - {.name = "StaticRng", .make_program = make_rng_program, .expected_requirement = FREE_SLOT}, - { - .name = "RoamingLegendaryRng", - .make_program = make_rng_program, - .expected_requirement = FREE_SLOT, - }, + {.name = "StarterRng", .make_program = make_rng_program, .expected_free_slots = 0}, + // The egg and the two wild Pokemon caught to confirm the seed. + {.name = "EggRng", .make_program = make_rng_program, .expected_free_slots = 3}, + {.name = "GiftRng", .make_program = make_rng_program, .expected_free_slots = 1}, + {.name = "StaticRng", .make_program = make_rng_program, .expected_free_slots = 1}, + {.name = "RoamingLegendaryRng", .make_program = make_rng_program, .expected_free_slots = 1}, { .name = "WildRng on Route 1", .make_program = make_rng_program, .settings = {{"GAME_LOCATION", "route_1"}}, - .expected_requirement = FREE_SLOT, + .expected_free_slots = 1, }, { // The Safari Zone start menu has no POKEMON entry in the usual place. .name = "WildRng in the Safari Zone", .make_program = make_rng_program, .settings = {{"GAME_LOCATION", "safari_zone_entrance"}}, - .expected_requirement = FREE_SLOT, + .expected_free_slots = 1, .expected_menu_context = StartMenuContext::SAFARI_ZONE, }, }; for (const RngProgramPartyScenario& scenario : scenarios){ database.add(scenario); } + // RngHelper reads a Pokemon it receives from the party, but only watches encounters, so what + // it needs depends on the target. + const std::pair rng_helper_targets[] = { + {"starters", 0}, {"lapras", 1}, {"fossils", 1}, {"gamecornerporygon", 1}, {"togepi", 1}, + {"eggheld", 0}, {"eggpickup", 1}, {"snorlax", 0}, {"sweetscent", 0}, {"safarizonesurf", 0}, {"roaming", 0}, + }; + for (const auto& [target, free_slots] : rng_helper_targets){ + database.add(RngProgramPartyScenario{ + .name = std::string("RngHelper ") + target, + .make_program = make_rng_program, + .settings = {{"TARGET", target}}, + .expected_free_slots = free_slots, + }); + } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index 03cbbbb706..b31f90dd97 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h @@ -59,7 +59,8 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{ class EggRng : public RngProgramInstance, public ConfigOption::Listener{ public: using Descriptor = EggRng_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::NONE; } + // 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 03eb0cbe66..6f62a1565e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h @@ -32,7 +32,7 @@ class GiftRng_Descriptor : public SingleSwitchProgramDescriptor{ class GiftRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = GiftRng_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } + 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.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp index 16065cbda0..64e0918468 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp @@ -238,6 +238,37 @@ RngHelper::RngHelper() PA_ADD_OPTION(NOTIFICATIONS); } +size_t RngHelper::free_party_slots_needed() const{ + // The targets whose shiny check reads the Pokemon received from the end of + // the party (see check_for_shiny()) need a free slot for it. The others + // only watch the encounter, and before the starter the party is empty. + switch (TARGET){ + case PokemonFRLG_RngTarget::magikarp: + case PokemonFRLG_RngTarget::hitmon: + case PokemonFRLG_RngTarget::hitmonchan: + case PokemonFRLG_RngTarget::hitmonlee: + case PokemonFRLG_RngTarget::eevee: + case PokemonFRLG_RngTarget::lapras: + case PokemonFRLG_RngTarget::fossils: + case PokemonFRLG_RngTarget::omanyte: + case PokemonFRLG_RngTarget::kabuto: + case PokemonFRLG_RngTarget::aerodactyl: + case PokemonFRLG_RngTarget::gamecornerabra: + case PokemonFRLG_RngTarget::gamecornerclefairy: + case PokemonFRLG_RngTarget::gamecornerdratinifr: + case PokemonFRLG_RngTarget::gamecornerdratinilg: + case PokemonFRLG_RngTarget::gamecornerscyther: + case PokemonFRLG_RngTarget::gamecornerpinsir: + case PokemonFRLG_RngTarget::gamecornerporygon: + case PokemonFRLG_RngTarget::togepi: + case PokemonFRLG_RngTarget::togepifast: + case PokemonFRLG_RngTarget::eggpickup: + return 1; + default: + return 0; + } +} + void RngHelper::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ /* * Settings: Text Speed fast diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h index a262d8a1df..85fef9f465 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h @@ -31,7 +31,7 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{ class RngHelper : public RngProgramInstance{ public: using Descriptor = RngHelper_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::NONE; } + virtual size_t free_party_slots_needed() const override; 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 index e9079bf77b..6e05d83ee3 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -4,6 +4,7 @@ * */ +#include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" #include "Pokemon/Pokemon_Strings.h" @@ -42,38 +43,37 @@ class ConsolePartyCheckActions : public PartyCheckActions{ StartMenuContext m_menu_context; }; -// Without a free slot, the Pokemon the program catches or receives goes to -// the PC and the program reads the wrong Pokemon. -void check_party_has_free_slot(Logger& logger, PartyCheckActions& actions){ - logger.log("Checking for a free party slot..."); - if (!actions.open_party_menu()){ - logger.log("Unable to open the party menu. Skipping the free party slot check.", COLOR_RED); - return; +std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ + if (free_slots_needed == 1){ + return "Your party is full. Leave a party slot free so the program can check the " + + Pokemon::STRING_POKEMON + " it catches."; } - if (actions.read_last_occupied_slot() == PartySlot::SIX){ - throw UserSetupError( - logger, - "Your party is full. Leave a party slot free so the program can check the " + Pokemon::STRING_POKEMON + " it catches." - ); - } - logger.log("Party has a free slot."); + return "Your party has " + std::to_string(party_size) + " " + Pokemon::STRING_POKEMON + + ". Leave at least " + std::to_string(free_slots_needed) + + " party slots free for the " + Pokemon::STRING_POKEMON + " the program catches or receives."; } } -void check_party_requirement( +void check_party_free_slots( Logger& logger, - PartyRequirement requirement, + size_t free_slots_needed, PartyCheckActions& actions ){ - switch (requirement){ - case PartyRequirement::NONE: - break; - case PartyRequirement::FREE_SLOT: - check_party_has_free_slot(logger, actions); - break; + 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; + } + const size_t party_size = static_cast(actions.read_last_occupied_slot()) + 1; + if (6 - 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."); } @@ -82,7 +82,7 @@ void RngProgramInstance::start_program_game_checks( ProControllerContext& context ){ ConsolePartyCheckActions actions(env.console, context, start_menu_context()); - check_party_requirement(env.console.logger(), party_requirement(), actions); + check_party_free_slots(env.console.logger(), free_party_slots_needed(), actions); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 0ebcd4d99f..3a3cee6d6e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -12,6 +12,7 @@ #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" @@ -22,14 +23,6 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -enum class PartyRequirement{ - NONE, - // The program catches or receives a Pokemon and reads it from the end of - // the party. In a full party it would go to the PC instead. - FREE_SLOT, -}; - - // The game steps that check_party_requirement() takes. They are injected so // that its decisions run in tests without a Switch. class PartyCheckActions{ @@ -43,12 +36,13 @@ class PartyCheckActions{ virtual PartySlot read_last_occupied_slot() = 0; }; -// Checks that the party meets `requirement`, 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_requirement( +// 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, - PartyRequirement requirement, + size_t free_slots_needed, PartyCheckActions& actions ); @@ -57,8 +51,10 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ public: using SingleSwitchProgramInstance::SingleSwitchProgramInstance; - // What the program needs from the party. - virtual PartyRequirement party_requirement() const = 0; + // 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{ @@ -67,7 +63,7 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ // 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 its party_requirement() asks for. + // every RNG program runs the check free_party_slots_needed() asks for. virtual void start_program_game_checks( SingleSwitchProgramEnvironment& env, ProControllerContext& context diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h index a25fe3da63..a3cb727f9c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h @@ -32,7 +32,7 @@ class RoamingLegendaryRng_Descriptor : public SingleSwitchProgramDescriptor{ class RoamingLegendaryRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = RoamingLegendaryRng_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } + 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 72ed61bf62..b2b49fbf35 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h @@ -33,7 +33,7 @@ class StarterRng_Descriptor : public SingleSwitchProgramDescriptor{ class StarterRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StarterRng_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::NONE; } + 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 0bc3269983..5b7856e443 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h @@ -37,7 +37,7 @@ class StaticRng_Descriptor : public SingleSwitchProgramDescriptor{ class StaticRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StaticRng_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } + 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 4226a4b813..8bb9e2d562 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h @@ -34,7 +34,7 @@ class WildRng_Descriptor : public SingleSwitchProgramDescriptor{ class WildRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = WildRng_Descriptor; - virtual PartyRequirement party_requirement() const override{ return PartyRequirement::FREE_SLOT; } + 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; } From a5e50d152b943d5315fe3fa633300e22f6cf33b6 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 13:03:15 -0800 Subject: [PATCH 07/12] FRLG: list the party slots on one line to keep PokemonFRLG_Navigation.cpp at its size origin/main grew the file to its code-health allowance (1656 lines over the 1000-line limit); the image overload this PR adds needs three lines. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp index 49d239d45f..8de1341438 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.cpp @@ -843,13 +843,7 @@ 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); From 53d57187c710e537061de5b844a820384ba3b9fa Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 18:00:47 -0800 Subject: [PATCH 08/12] FRLG RNG party check: review fixes Fix the stale function name in the PartyCheckActions comment, name the party size, word the one-slot message for gifts too, sort the new Navigation.h include, and take the test image path as string_view. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h | 2 +- .../Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 5 +++-- .../Programs/RngManipulation/PokemonFRLG_RngProgram.cpp | 5 +++-- .../Programs/RngManipulation/PokemonFRLG_RngProgram.h | 2 +- 4 files changed, 8 insertions(+), 6 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h index b5105b6e0a..da3fc4b016 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h @@ -10,8 +10,8 @@ #define PokemonAutomation_PokemonFRLG_Navigation_H #include "Common/Cpp/Logging/AbstractLogger.h" -#include "CommonFramework/Language.h" #include "CommonFramework/ImageTypes/ImageViewRGB32.h" +#include "CommonFramework/Language.h" #include "CommonFramework/Tools/VideoStream.h" #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "VideoGames/PokemonFRLG/Inference/Menus/PokemonFRLG_PartySlot.h" diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index db45e717bd..308db4c071 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -8,6 +8,7 @@ #include #include #include +#include #include "Common/Cpp/Exceptions.h" #include "Common/Cpp/Filesystem/Filesystem.h" #include "Common/Cpp/Json/JsonObject.h" @@ -284,8 +285,8 @@ std::string slot_name(PartySlot slot){ // 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(const std::string& image, PartySlot expected) - : ImageUnitTest("PokemonFRLG::LastOccupiedPartySlot - " + image, {image}) + Test_LastOccupiedPartySlot(std::string_view image, PartySlot expected) + : ImageUnitTest("PokemonFRLG::LastOccupiedPartySlot - " + std::string(image), {std::string(image)}) , m_expected(expected) {} diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index 6e05d83ee3..ea08213a72 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -46,7 +46,7 @@ class ConsolePartyCheckActions : public PartyCheckActions{ std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ if (free_slots_needed == 1){ return "Your party is full. Leave a party slot free so the program can check the " - + Pokemon::STRING_POKEMON + " it catches."; + + Pokemon::STRING_POKEMON + " it catches or receives."; } return "Your party has " + std::to_string(party_size) + " " + Pokemon::STRING_POKEMON + ". Leave at least " + std::to_string(free_slots_needed) @@ -69,8 +69,9 @@ void check_party_free_slots( 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 (6 - party_size < free_slots_needed){ + 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."); diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h index 3a3cee6d6e..33540e0cc5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -23,7 +23,7 @@ namespace NintendoSwitch{ namespace PokemonFRLG{ -// The game steps that check_party_requirement() takes. They are injected so +// 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: From 5e3f8b3fec9bcd8623ce90719346fc5f3303282a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 18:04:35 -0800 Subject: [PATCH 09/12] FRLG RNG party check: meet the code-health gate Table-driven input/expectation cases for the party check tests, a comment on each RNG program class and the new overload, and closing namespace comments in the new files. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Navigation.h | 1 + .../PokemonFRLG/PokemonFRLG_Tests.cpp | 243 +++++++++++------- .../RngManipulation/PokemonFRLG_EggRng.h | 1 + .../RngManipulation/PokemonFRLG_GiftRng.h | 1 + .../RngManipulation/PokemonFRLG_RngHelper.h | 1 + .../PokemonFRLG_RngProgram.cpp | 8 +- .../RngManipulation/PokemonFRLG_RngProgram.h | 8 +- .../PokemonFRLG_RoamingLegendaryRng.h | 1 + .../RngManipulation/PokemonFRLG_StarterRng.h | 1 + .../RngManipulation/PokemonFRLG_StaticRng.h | 1 + .../RngManipulation/PokemonFRLG_WildRng.h | 1 + 11 files changed, 172 insertions(+), 95 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h index da3fc4b016..b19ead8d00 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Navigation.h @@ -137,6 +137,7 @@ 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 308db4c071..21c1cfcdc7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -335,90 +335,96 @@ class ScriptedPartyCheck : public PartyCheckActions{ } }; -struct PartyCheckScenario{ +struct PartyCheckInput{ std::string name; size_t free_slots_needed = 1; bool menu_opens = true; PartySlot last_occupied = PartySlot::ONE; - std::string expected_steps = ""; +}; + +struct PartyCheckExpectation{ + std::string steps = ""; // Start of the UserSetupError message; empty if the check passes. - std::string expected_error = ""; + std::string error = ""; +}; + +struct PartyCheckCase{ + PartyCheckInput input; + PartyCheckExpectation expectation; }; class Test_PartyCheck : public UnitTest{ public: - Test_PartyCheck(PartyCheckScenario scenario) - : UnitTest("PokemonFRLG::RngPartyCheck - " + scenario.name) - , m_scenario(std::move(scenario)) + 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 = m_scenario.menu_opens; - actions.last_occupied = m_scenario.last_occupied; + actions.menu_opens = input.menu_opens; + actions.last_occupied = input.last_occupied; NullLogger logger; std::string error; try{ - check_party_free_slots(logger, m_scenario.free_slots_needed, actions); + check_party_free_slots(logger, input.free_slots_needed, actions); }catch (UserSetupError& e){ error = e.message(); } - const bool error_matches = m_scenario.expected_error.empty() + const bool error_matches = expected.error.empty() ? error.empty() - : error.rfind(m_scenario.expected_error, 0) == 0; + : error.rfind(expected.error, 0) == 0; if (!error_matches){ - return "Expected error: \"" + m_scenario.expected_error + "\"\nActual error: \"" + error + "\""; + return "Expected error: \"" + expected.error + "\"\nActual error: \"" + error + "\""; } - if (actions.steps != m_scenario.expected_steps){ - return "Expected steps: " + m_scenario.expected_steps + "\nActual steps: " + actions.steps; + if (actions.steps != expected.steps){ + return "Expected steps: " + expected.steps + "\nActual steps: " + actions.steps; } return true; } private: - const PartyCheckScenario m_scenario; + const PartyCheckCase m_case; }; void add_tests_PartyCheck(UnitTestDatabase& database){ - const PartyCheckScenario scenarios[] = { + const PartyCheckCase cases[] = { { // Programs that don't add a Pokemon to the party don't open the menu. - .name = "no free slot needed, full party", - .free_slots_needed = 0, - .last_occupied = PartySlot::SIX, + .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"}, }, - {.name = "one free slot needed, one Pokemon", .expected_steps = "open read"}, - {.name = "one free slot needed, five Pokemon", .last_occupied = PartySlot::FIVE, .expected_steps = "open read"}, { - .name = "one free slot needed, full party", - .last_occupied = PartySlot::SIX, - .expected_steps = "open read", - .expected_error = "Your party is full. Leave a party slot free", + .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"}, }, { - .name = "three free slots needed, three Pokemon", - .free_slots_needed = 3, - .last_occupied = PartySlot::THREE, - .expected_steps = "open read", + .input = {.name = "three free slots needed, three Pokemon", .free_slots_needed = 3, .last_occupied = PartySlot::THREE}, + .expectation = {.steps = "open read"}, }, { - .name = "three free slots needed, four Pokemon", - .free_slots_needed = 3, - .last_occupied = PartySlot::FOUR, - .expected_steps = "open read", - .expected_error = "Your party has 4 ", + .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. - .name = "party menu not opened", - .menu_opens = false, - .last_occupied = PartySlot::SIX, - .expected_steps = "open", + .input = {.name = "party menu not opened", .menu_opens = false, .last_occupied = PartySlot::SIX}, + .expectation = {.steps = "open"}, }, }; - for (const PartyCheckScenario& scenario : scenarios){ - database.add(scenario); + for (const PartyCheckCase& test_case : cases){ + database.add(test_case); } } @@ -432,93 +438,154 @@ std::string menu_context_name(StartMenuContext context){ return "?"; } -struct RngProgramPartyScenario{ +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 = {}; - size_t expected_free_slots; - StartMenuContext expected_menu_context = StartMenuContext::STANDARD; +}; + +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(RngProgramPartyScenario scenario) - : UnitTest("PokemonFRLG::RngProgramPartyRequirement - " + scenario.name) - , m_scenario(std::move(scenario)) + 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{ - std::unique_ptr program = m_scenario.make_program(); + 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] : m_scenario.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 != m_scenario.expected_free_slots){ - return "Expected " + std::to_string(m_scenario.expected_free_slots) + " free party slots needed, got " + if (free_slots != expected.free_slots){ + return "Expected " + std::to_string(expected.free_slots) + " free party slots needed, got " + std::to_string(free_slots); } const StartMenuContext menu_context = program->start_menu_context(); - if (menu_context != m_scenario.expected_menu_context){ - return "Expected start menu " + menu_context_name(m_scenario.expected_menu_context) + if (menu_context != expected.menu_context){ + return "Expected start menu " + menu_context_name(expected.menu_context) + ", got " + menu_context_name(menu_context); } return true; } private: - const RngProgramPartyScenario m_scenario; + const RngProgramPartyCase m_case; }; -template -std::unique_ptr make_rng_program(){ - return std::make_unique(); -} - -void add_tests_RngProgramPartyRequirement(UnitTestDatabase& database){ - const RngProgramPartyScenario scenarios[] = { - {.name = "StarterRng", .make_program = make_rng_program, .expected_free_slots = 0}, +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. - {.name = "EggRng", .make_program = make_rng_program, .expected_free_slots = 3}, - {.name = "GiftRng", .make_program = make_rng_program, .expected_free_slots = 1}, - {.name = "StaticRng", .make_program = make_rng_program, .expected_free_slots = 1}, - {.name = "RoamingLegendaryRng", .make_program = make_rng_program, .expected_free_slots = 1}, - { + .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"}}, - .expected_free_slots = 1, }, - { - // The Safari Zone start menu has no POKEMON entry in the usual place. + .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"}}, - .expected_free_slots = 1, - .expected_menu_context = StartMenuContext::SAFARI_ZONE, }, - }; - for (const RngProgramPartyScenario& scenario : scenarios){ - database.add(scenario); - } - // RngHelper reads a Pokemon it receives from the party, but only watches encounters, so what - // it needs depends on the target. - const std::pair rng_helper_targets[] = { - {"starters", 0}, {"lapras", 1}, {"fossils", 1}, {"gamecornerporygon", 1}, {"togepi", 1}, - {"eggheld", 0}, {"eggpickup", 1}, {"snorlax", 0}, {"sweetscent", 0}, {"safarizonesurf", 0}, {"roaming", 0}, - }; - for (const auto& [target, free_slots] : rng_helper_targets){ - database.add(RngProgramPartyScenario{ - .name = std::string("RngHelper ") + target, - .make_program = make_rng_program, - .settings = {{"TARGET", target}}, - .expected_free_slots = free_slots, - }); + .expectation = {.free_slots = 1, .menu_context = StartMenuContext::SAFARI_ZONE}, + }, + // RngHelper reads a Pokemon it receives from the party, but only watches encounters, so + // what it needs depends on the target. + { + .input = {.name = "RngHelper starters", .make_program = make_rng_program, .settings = {{"TARGET", "starters"}}}, + .expectation = {.free_slots = 0}, + }, + { + .input = {.name = "RngHelper lapras", .make_program = make_rng_program, .settings = {{"TARGET", "lapras"}}}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "RngHelper fossils", .make_program = make_rng_program, .settings = {{"TARGET", "fossils"}}}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "RngHelper gamecornerporygon", .make_program = make_rng_program, .settings = {{"TARGET", "gamecornerporygon"}}}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "RngHelper togepi", .make_program = make_rng_program, .settings = {{"TARGET", "togepi"}}}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "RngHelper eggheld", .make_program = make_rng_program, .settings = {{"TARGET", "eggheld"}}}, + .expectation = {.free_slots = 0}, + }, + { + .input = {.name = "RngHelper eggpickup", .make_program = make_rng_program, .settings = {{"TARGET", "eggpickup"}}}, + .expectation = {.free_slots = 1}, + }, + { + .input = {.name = "RngHelper snorlax", .make_program = make_rng_program, .settings = {{"TARGET", "snorlax"}}}, + .expectation = {.free_slots = 0}, + }, + { + .input = {.name = "RngHelper sweetscent", .make_program = make_rng_program, .settings = {{"TARGET", "sweetscent"}}}, + .expectation = {.free_slots = 0}, + }, + { + .input = {.name = "RngHelper safarizonesurf", .make_program = make_rng_program, .settings = {{"TARGET", "safarizonesurf"}}}, + .expectation = {.free_slots = 0}, + }, + { + .input = {.name = "RngHelper roaming", .make_program = make_rng_program, .settings = {{"TARGET", "roaming"}}}, + .expectation = {.free_slots = 0}, + }, +}; + +void add_tests_RngProgramPartyRequirement(UnitTestDatabase& database){ + for (const RngProgramPartyCase& test_case : RNG_PROGRAM_PARTY_CASES){ + database.add(test_case); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h index b31f90dd97..6adb83effc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_EggRng.h @@ -56,6 +56,7 @@ class EggRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Calibrates timings to hit an RNG target for a daycare egg. class EggRng : public RngProgramInstance, public ConfigOption::Listener{ public: using Descriptor = EggRng_Descriptor; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h index 6f62a1565e..fc18d1b111 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_GiftRng.h @@ -29,6 +29,7 @@ class GiftRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Calibrates timings to hit an RNG target for a gift Pokemon. class GiftRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = GiftRng_Descriptor; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h index 85fef9f465..ce13de9168 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h @@ -28,6 +28,7 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Soft resets with given timings to hit a target seed and frame. class RngHelper : public RngProgramInstance{ public: using Descriptor = RngHelper_Descriptor; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index ea08213a72..bacb9deff7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -53,7 +53,7 @@ std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_n + " party slots free for the " + Pokemon::STRING_POKEMON + " the program catches or receives."; } -} +} // namespace void check_party_free_slots( @@ -86,6 +86,6 @@ void RngProgramInstance::start_program_game_checks( 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 index 33540e0cc5..8ec4935ef9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.h @@ -47,6 +47,8 @@ void check_party_free_slots( ); +// 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; @@ -71,7 +73,7 @@ class RngProgramInstance : public SingleSwitchProgramInstance{ }; -} -} -} +} // 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 a3cb727f9c..2b331ac54d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RoamingLegendaryRng.h @@ -29,6 +29,7 @@ class RoamingLegendaryRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Calibrates timings to hit an RNG target for a roaming legendary. class RoamingLegendaryRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = RoamingLegendaryRng_Descriptor; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h index b2b49fbf35..d3140574f0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h @@ -30,6 +30,7 @@ class StarterRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Calibrates timings to hit an RNG target for a starter. class StarterRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StarterRng_Descriptor; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h index 5b7856e443..3a274e79e8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StaticRng.h @@ -34,6 +34,7 @@ class StaticRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Calibrates timings to hit an RNG target for a static encounter. class StaticRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = StaticRng_Descriptor; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h index 8bb9e2d562..968f68119a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_WildRng.h @@ -31,6 +31,7 @@ class WildRng_Descriptor : public SingleSwitchProgramDescriptor{ virtual std::unique_ptr make_stats() const override; }; +// Calibrates timings to hit an RNG target for a random wild encounter. class WildRng : public RngProgramInstance, private ConfigOption::Listener{ public: using Descriptor = WildRng_Descriptor; From 8490e0caa0531cc2880a6fb5e7918307cc506179 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 19:19:13 -0800 Subject: [PATCH 10/12] FRLG RNG party check: std::format for the message; note why StarterRng needs no slot Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../RngManipulation/PokemonFRLG_RngProgram.cpp | 14 +++++++++----- .../RngManipulation/PokemonFRLG_StarterRng.h | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp index bacb9deff7..573e991687 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngProgram.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Exceptions/OperationFailedException.h" @@ -45,12 +46,15 @@ class ConsolePartyCheckActions : public PartyCheckActions{ std::string not_enough_free_slots_message(size_t party_size, size_t free_slots_needed){ if (free_slots_needed == 1){ - return "Your party is full. Leave a party slot free so the program can check the " - + Pokemon::STRING_POKEMON + " it catches or receives."; + 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 "Your party has " + std::to_string(party_size) + " " + Pokemon::STRING_POKEMON - + ". Leave at least " + std::to_string(free_slots_needed) - + " party slots free for the " + Pokemon::STRING_POKEMON + " the program catches or receives."; + 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 diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h index d3140574f0..ea5fa11c06 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_StarterRng.h @@ -34,6 +34,7 @@ class StarterRng_Descriptor : public SingleSwitchProgramDescriptor{ 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(); From a48b54d38de531ffa8949c9e49efa999cbe3d750 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 19:21:51 -0800 Subject: [PATCH 11/12] FRLG RNG party check: no check in RngHelper, the manual tool Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonFRLG/PokemonFRLG_Tests.cpp | 43 +------------------ .../RngManipulation/PokemonFRLG_RngHelper.cpp | 31 ------------- .../RngManipulation/PokemonFRLG_RngHelper.h | 3 +- 3 files changed, 3 insertions(+), 74 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 21c1cfcdc7..712a1fc6e1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -535,50 +535,9 @@ const RngProgramPartyCase RNG_PROGRAM_PARTY_CASES[] = { }, .expectation = {.free_slots = 1, .menu_context = StartMenuContext::SAFARI_ZONE}, }, - // RngHelper reads a Pokemon it receives from the party, but only watches encounters, so - // what it needs depends on the target. - { - .input = {.name = "RngHelper starters", .make_program = make_rng_program, .settings = {{"TARGET", "starters"}}}, - .expectation = {.free_slots = 0}, - }, + // 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 = 1}, - }, - { - .input = {.name = "RngHelper fossils", .make_program = make_rng_program, .settings = {{"TARGET", "fossils"}}}, - .expectation = {.free_slots = 1}, - }, - { - .input = {.name = "RngHelper gamecornerporygon", .make_program = make_rng_program, .settings = {{"TARGET", "gamecornerporygon"}}}, - .expectation = {.free_slots = 1}, - }, - { - .input = {.name = "RngHelper togepi", .make_program = make_rng_program, .settings = {{"TARGET", "togepi"}}}, - .expectation = {.free_slots = 1}, - }, - { - .input = {.name = "RngHelper eggheld", .make_program = make_rng_program, .settings = {{"TARGET", "eggheld"}}}, - .expectation = {.free_slots = 0}, - }, - { - .input = {.name = "RngHelper eggpickup", .make_program = make_rng_program, .settings = {{"TARGET", "eggpickup"}}}, - .expectation = {.free_slots = 1}, - }, - { - .input = {.name = "RngHelper snorlax", .make_program = make_rng_program, .settings = {{"TARGET", "snorlax"}}}, - .expectation = {.free_slots = 0}, - }, - { - .input = {.name = "RngHelper sweetscent", .make_program = make_rng_program, .settings = {{"TARGET", "sweetscent"}}}, - .expectation = {.free_slots = 0}, - }, - { - .input = {.name = "RngHelper safarizonesurf", .make_program = make_rng_program, .settings = {{"TARGET", "safarizonesurf"}}}, - .expectation = {.free_slots = 0}, - }, - { - .input = {.name = "RngHelper roaming", .make_program = make_rng_program, .settings = {{"TARGET", "roaming"}}}, .expectation = {.free_slots = 0}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp index 64e0918468..16065cbda0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.cpp @@ -238,37 +238,6 @@ RngHelper::RngHelper() PA_ADD_OPTION(NOTIFICATIONS); } -size_t RngHelper::free_party_slots_needed() const{ - // The targets whose shiny check reads the Pokemon received from the end of - // the party (see check_for_shiny()) need a free slot for it. The others - // only watch the encounter, and before the starter the party is empty. - switch (TARGET){ - case PokemonFRLG_RngTarget::magikarp: - case PokemonFRLG_RngTarget::hitmon: - case PokemonFRLG_RngTarget::hitmonchan: - case PokemonFRLG_RngTarget::hitmonlee: - case PokemonFRLG_RngTarget::eevee: - case PokemonFRLG_RngTarget::lapras: - case PokemonFRLG_RngTarget::fossils: - case PokemonFRLG_RngTarget::omanyte: - case PokemonFRLG_RngTarget::kabuto: - case PokemonFRLG_RngTarget::aerodactyl: - case PokemonFRLG_RngTarget::gamecornerabra: - case PokemonFRLG_RngTarget::gamecornerclefairy: - case PokemonFRLG_RngTarget::gamecornerdratinifr: - case PokemonFRLG_RngTarget::gamecornerdratinilg: - case PokemonFRLG_RngTarget::gamecornerscyther: - case PokemonFRLG_RngTarget::gamecornerpinsir: - case PokemonFRLG_RngTarget::gamecornerporygon: - case PokemonFRLG_RngTarget::togepi: - case PokemonFRLG_RngTarget::togepifast: - case PokemonFRLG_RngTarget::eggpickup: - return 1; - default: - return 0; - } -} - void RngHelper::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ /* * Settings: Text Speed fast diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h index ce13de9168..cbecd81a9e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/Programs/RngManipulation/PokemonFRLG_RngHelper.h @@ -32,7 +32,8 @@ class RngHelper_Descriptor : public SingleSwitchProgramDescriptor{ class RngHelper : public RngProgramInstance{ public: using Descriptor = RngHelper_Descriptor; - virtual size_t free_party_slots_needed() const override; + // 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( From fa6ff207d3fc0a6c1c89161672d84f19c3890e0d Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 19:32:53 -0800 Subject: [PATCH 12/12] FRLG RNG party check tests: std::format for the failure messages Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp index 712a1fc6e1..f8bcb64246 100644 --- a/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonFRLG/PokemonFRLG_Tests.cpp @@ -4,6 +4,7 @@ * */ +#include #include #include #include @@ -296,7 +297,7 @@ class Test_LastOccupiedPartySlot : public ImageUnitTest{ ) const override{ const PartySlot slot = detect_last_occupied_party_slot(images[0]); if (slot != m_expected){ - return "Expected last occupied slot " + slot_name(m_expected) + ", got " + slot_name(slot); + return std::format("Expected last occupied slot {}, got {}", slot_name(m_expected), slot_name(slot)); } return true; } @@ -378,10 +379,10 @@ class Test_PartyCheck : public UnitTest{ ? error.empty() : error.rfind(expected.error, 0) == 0; if (!error_matches){ - return "Expected error: \"" + expected.error + "\"\nActual error: \"" + error + "\""; + return std::format("Expected error: \"{}\"\nActual error: \"{}\"", expected.error, error); } if (actions.steps != expected.steps){ - return "Expected steps: " + expected.steps + "\nActual steps: " + actions.steps; + return std::format("Expected steps: {}\nActual steps: {}", expected.steps, actions.steps); } return true; } @@ -481,13 +482,13 @@ class Test_RngProgramPartyRequirement : public UnitTest{ const size_t free_slots = program->free_party_slots_needed(); if (free_slots != expected.free_slots){ - return "Expected " + std::to_string(expected.free_slots) + " free party slots needed, got " - + std::to_string(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 "Expected start menu " + menu_context_name(expected.menu_context) - + ", got " + menu_context_name(menu_context); + return std::format( + "Expected start menu {}, got {}", menu_context_name(expected.menu_context), menu_context_name(menu_context) + ); } return true; }