From ea359ba3d021daf9d2e472c06f6db929c03ca35a Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 20 Oct 2026 21:08:30 -0700 Subject: [PATCH 1/6] Run the BBQ farmer's rounds against an injectable BBQGameActions BBQSoloFarmer::program() runs its quest rounds inline against the console, so the round logic (which quests count, when to stop, when to save) can only be exercised by running the farmer on a Switch. Move the round loop into run_bbq_rounds(), which takes the game actions it depends on as a BBQGameActions interface: read the quests, process them, do a quest, report a completed quest, and end the round (saving if due). BBQSoloFarmer implements these with the calls they replace, in the same order; the date fix, save/reset, stats and notification move together into end_round(). Startup, flying to the plaza and end-of-program handling stay in program(). The commented-out single-quest debug block declares its own egg counter now that the loop locals have moved. process_quest_list() only reads its quest list and egg count, so take them as const& and by value. Add PokemonSV::BBQFarmerRounds, a table of scenarios run against a simulated singleplayer quest panel: 3 blue quests, completed quests are replaced, impossible quests are skipped, and a panel with nothing doable is rerolled. Each scenario checks the number of completed quests and the exact action sequence: finishing the round that reaches the goal, a quest already gone, a failed quest, a panel with nothing doable, saving at exact multiples, and stopping when out of eggs. No behavior change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 222 ++++++++++++++++++ .../Farming/PokemonSV_BBQSoloFarmer.cpp | 166 ++++++++----- .../Farming/PokemonSV_BBQSoloFarmer.h | 42 ++++ .../Farming/PokemonSV_BlueberryQuests.cpp | 4 +- .../Farming/PokemonSV_BlueberryQuests.h | 4 +- 5 files changed, 375 insertions(+), 63 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index d966bfe133..f894861d68 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -4,6 +4,7 @@ * */ +#include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Inference/PokemonSV_WhiteButtonDetector.h" #include "Inference/Boxes/PokemonSV_BoxDetection.h" @@ -25,15 +26,236 @@ #include "Inference/Overworld/PokemonSV_LetsGoKillDetector.h" #include "Inference/Picnics/PokemonSV_SandwichRecipeDetector.h" #include "Inference/Picnics/PokemonSV_SandwichHandDetector.h" +#include "Programs/Farming/PokemonSV_BlueberryQuests.h" +#include "Programs/Farming/PokemonSV_BBQSoloFarmer.h" #include "PokemonSV_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonSV{ +namespace{ +class NullLogger : public Logger{ +public: + virtual void log(const std::string&, Color) override{} +}; + +// A singleplayer quest panel that behaves like the game's: 3 blue quests, +// and a completed quest is replaced by a new one. process_quest_list() +// follows the two rules of the real one that the round loop depends on: +// quests in not_possible_quests are skipped, and if nothing is doable all +// quests are rerolled and nothing is returned. Red quests and the +// exclusions table are not modeled. Records the game actions taken. +class SimulatedBBQGameActions : public BBQGameActions{ +public: + std::vector panel; + // Each attempt returns the next outcome; once exhausted, attempts succeed. + std::vector outcomes; + // Completing the first quest also completes the second, e.g. walking + // 500 meters while navigating to a photo target. + std::vector> also_completes; + + std::vector events; + + virtual std::vector read_quests() override{ + events.push_back("read"); + if (++m_reads > 1000){ + throw std::runtime_error("Too many quest panel reads."); + } + return panel; + } + virtual std::vector process_quest_list( + const std::vector& quests, uint8_t + ) override{ + events.push_back("process"); + std::vector doable; + for (BBQuests quest : quests){ + if (!not_possible_quests.contains(quest)){ + doable.push_back(quest); + } + } + if (doable.empty()){ + for (BBQuests& slot : panel){ + slot = next_new_quest(); + } + } + return doable; + } + virtual bool do_quest(BBQuests quest, uint8_t&) override{ + events.push_back("do"); + const bool success = m_next_outcome < outcomes.size() ? outcomes[m_next_outcome++] : true; + if (success){ + complete(quest); + for (const auto& [done, extra] : also_completes){ + if (done == quest){ + complete(extra); + } + } + } + return success; + } + virtual void quest_completed() override{ + events.push_back("completed"); + } + virtual void end_round(bool save) override{ + events.push_back(save ? "end(save)" : "end"); + } + +private: + void complete(BBQuests quest){ + auto iter = std::find(panel.begin(), panel.end(), quest); + if (iter != panel.end()){ + *iter = next_new_quest(); + } + } + + // New quests come from a fixed rotation of doable blue quests, skipping + // any that are already on the panel. + BBQuests next_new_quest(){ + static const BBQuests ROTATION[] = { + BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar, + BBQuests::photo_savanna, BBQuests::catch_any, BBQuests::catch_normal, + BBQuests::catch_fire, BBQuests::catch_water, BBQuests::catch_grass, + }; + while (true){ + BBQuests quest = ROTATION[m_next_new_quest++ % std::size(ROTATION)]; + if (std::find(panel.begin(), panel.end(), quest) == panel.end()){ + return quest; + } + } + } + + size_t m_reads = 0; + size_t m_next_outcome = 0; + size_t m_next_new_quest = 0; +}; + +std::string join_events(const std::vector& events){ + std::string ret; + for (const std::string& event : events){ + if (!ret.empty()) ret += ' '; + ret += event; + } + return ret; +} + +// One simulated farmer run: option values, the panel it starts with and how +// quests turn out, and the game actions it must take. +struct BBQRoundsScenario{ + std::string name; + uint64_t num_quests; + uint64_t save_num_quests = 0; + bool stop_when_out_of_eggs = false; + std::vector panel = {BBQuests::make_tm, BBQuests::auto_10, BBQuests::sneak_up}; + std::vector outcomes; + std::vector> also_completes; + uint64_t expected_completed = 0; + std::string expected; +}; + +class Test_BBQFarmerRounds : public UnitTest{ +public: + Test_BBQFarmerRounds(BBQRoundsScenario scenario) + : UnitTest("PokemonSV::BBQFarmerRounds - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + BBQOption options; + options.NUM_QUESTS.set(m_scenario.num_quests); + options.SAVE_NUM_QUESTS.set(m_scenario.save_num_quests); + if (m_scenario.stop_when_out_of_eggs){ + options.NUM_EGGS.set(0); + options.OUT_OF_EGGS.set(BBQOption::OOEggs::Stop); + } + + SimulatedBBQGameActions game; + game.panel = m_scenario.panel; + game.outcomes = m_scenario.outcomes; + game.also_completes = m_scenario.also_completes; + + NullLogger logger; + run_bbq_rounds(logger, options, game); + const uint64_t completed = (uint64_t)std::count(game.events.begin(), game.events.end(), "completed"); + if (completed != m_scenario.expected_completed){ + return "Expected " + std::to_string(m_scenario.expected_completed) + + " completed quests, counted " + std::to_string(completed); + } + const std::string actual = join_events(game.events); + if (actual != m_scenario.expected){ + return "Expected: " + m_scenario.expected + "\nActual: " + actual; + } + return true; + } + +private: + const BBQRoundsScenario m_scenario; +}; + +void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ + const std::string round_of_3 = "read process read do completed read do completed read do completed"; + const BBQRoundsScenario scenarios[] = { + { + // The goal (4) is reached in the middle of round 2. The loop only + // checks the goal between rounds, so round 2 finishes and 6 quests + // complete. + .name = "finishes the round that reaches the quest goal", + .num_quests = 4, + .expected_completed = 6, + .expected = round_of_3 + " end " + round_of_3 + " end", + }, + { + // Doing photo_swim also completes travel_500, so travel_500 is + // gone when the loop reads the panel before attempting it. + .name = "quest already gone counts as completed", + .num_quests = 3, + .panel = {BBQuests::photo_swim, BBQuests::travel_500, BBQuests::make_tm}, + .also_completes = {{BBQuests::photo_swim, BBQuests::travel_500}}, + .expected_completed = 3, + .expected = "read process read do completed read completed read do completed end", + }, + { + // The first attempt fails: 3 attempts, 2 completions. + .name = "failed quest does not count", + .num_quests = 2, + .outcomes = {false}, + .expected_completed = 2, + .expected = "read process read do read do completed read do completed end", + }, + { + // Nothing on the panel is doable, so process_quest_list() rerolls + // all of it and returns nothing; the loop reads the panel again. + .name = "panel with nothing doable is rerolled", + .num_quests = 3, + .panel = {BBQuests::pickup_10, BBQuests::catch_flying, BBQuests::UnableToDetect}, + .expected_completed = 3, + .expected = "read process " + round_of_3 + " end", + }, + { + .name = "saves at exact multiples", + .num_quests = 6, + .save_num_quests = 3, + .expected_completed = 6, + .expected = round_of_3 + " end(save) " + round_of_3 + " end(save)", + }, + { + .name = "stops when out of eggs", + .num_quests = 5, + .stop_when_out_of_eggs = true, + .expected_completed = 0, + .expected = "", + }, + }; + for (const BBQRoundsScenario& scenario : scenarios){ + database.add(scenario); + } +} + +} void add_tests(UnitTestDatabase& database){ + add_tests_BBQFarmerRounds(database); add_tests_WhiteButtonDetector(database); add_tests_BoxInfoDetector(database); add_tests_BoxEggDetector(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index 1c874e32a1..c6deaccca9 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp @@ -74,48 +74,22 @@ BBQSoloFarmer::BBQSoloFarmer() PA_ADD_OPTION(NOTIFICATIONS); } -void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ - StartProgramChecks::check_performance_class_wired_or_wireless(context); - assert_16_9_720p_min(env.logger(), env.console); - - BBQSoloFarmer_Descriptor::Stats& stats = env.current_stats(); - - //Make sure console type is set - if (env.console.state().console_type() == ConsoleType::Unknown){ - throw UserSetupError(env.console, "Console Type (Switch 1 or 2) must be specified."); - } - - // Connect the controller. - require_player(env.console, context, BUTTON_LCLICK); - - //Fly to plaza - open_map_from_overworld(env.program_info(), env.console, context); - fly_to_overworld_from_map(env.program_info(), env.console, context); - +void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game){ std::vector quest_list; //all quests std::vector quests_to_do; //do-able quests uint8_t eggs_hatched = 0; //Track eggs uint64_t num_completed_quests = 0; - //Test a specific quest - /* - BBQuests test_quest = BBQuests::catch_water; - bool questTest = process_and_do_quest(env, env.console, context, BBQ_OPTIONS, test_quest, eggs_hatched); - if (questTest){ - env.log("Finished quest."); - } - */ - - while (num_completed_quests < BBQ_OPTIONS.NUM_QUESTS){ - if (BBQ_OPTIONS.OUT_OF_EGGS == BBQOption::OOEggs::Stop && eggs_hatched >= BBQ_OPTIONS.NUM_EGGS){ - env.log("Stop when out of eggs selected. Stopping program."); + while (num_completed_quests < options.NUM_QUESTS){ + if (options.OUT_OF_EGGS == BBQOption::OOEggs::Stop && eggs_hatched >= options.NUM_EGGS){ + logger.log("Stop when out of eggs selected. Stopping program."); break; } //Get and reroll quests until we can at least one while (quests_to_do.size() < 1){ - quest_list = read_quests(env.program_info(), env.console, context, BBQ_OPTIONS); - quests_to_do = process_quest_list(env.program_info(), env.console, context, BBQ_OPTIONS, quest_list, eggs_hatched); + quest_list = game.read_quests(); + quests_to_do = game.process_quest_list(quest_list, eggs_hatched); //Clear out the regular quest list. quest_list.clear(); @@ -123,23 +97,21 @@ void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerCo for (auto current_quest : quests_to_do){ //Check if quest was already completed (ex. 500 meters completed while navigating to take a photo) - quest_list = read_quests(env.program_info(), env.console, context, BBQ_OPTIONS); + quest_list = game.read_quests(); if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ - env.log("Current quest exists on list. Doing quest."); - bool questSuccess = process_and_do_quest(env, env.console, context, BBQ_OPTIONS, current_quest, eggs_hatched); + logger.log("Current quest exists on list. Doing quest."); + bool questSuccess = game.do_quest(current_quest, eggs_hatched); if (questSuccess){ - env.log("Quest completed successfully."); - stats.questsCompleted++; - env.update_stats(); + logger.log("Quest completed successfully."); + game.quest_completed(); num_completed_quests++; }else{ - env.log("Quest did not complete successfully."); + logger.log("Quest did not complete successfully."); } }else{ //Note: This doesn't account for case such as "sneak up" being added and then completed alongside the next quest - env.log("Current quest does not exist on list. Quest completed at some point."); - stats.questsCompleted++; - env.update_stats(); + logger.log("Current quest does not exist on list. Quest completed at some point."); + game.quest_completed(); num_completed_quests++; } quest_list.clear(); @@ -147,27 +119,103 @@ void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerCo //Clear out the todo list quests_to_do.clear(); - //Fix the time to prevent running out of years - pbf_wait(context, 2000ms); - context.wait_for_all_requests(); - go_home(env.console, context); - home_to_date_time(env.console, context, false); - pbf_press_button(context, BUTTON_A, 160ms, 840ms); - pbf_press_button(context, BUTTON_A, 160ms, 840ms); - pbf_press_button(context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); - resume_game_from_home(env.console, context); + uint64_t temp_save_num_option = options.SAVE_NUM_QUESTS; + game.end_round(temp_save_num_option != 0 && num_completed_quests % temp_save_num_option == 0); + } +} + - uint64_t temp_save_num_option = BBQ_OPTIONS.SAVE_NUM_QUESTS; - if (temp_save_num_option != 0 && num_completed_quests % temp_save_num_option == 0){ - env.log("Saving and resetting."); - save_game_from_overworld(env.program_info(), env.console, context); - reset_game(env.program_info(), env.console, context); - stats.saves++; +namespace{ + +class BBQSoloFarmerGameActions : public BBQGameActions{ +public: + BBQSoloFarmerGameActions( + SingleSwitchProgramEnvironment& env, ProControllerContext& context, + BBQOption& options, BBQSoloFarmer_Descriptor::Stats& stats, + EventNotificationOption& status_update + ) + : m_env(env), m_context(context) + , m_options(options), m_stats(stats) + , m_status_update(status_update) + {} + + virtual std::vector read_quests() override{ + return PokemonSV::read_quests(m_env.program_info(), m_env.console, m_context, m_options); + } + virtual std::vector process_quest_list( + const std::vector& quests, uint8_t eggs_hatched + ) override{ + return PokemonSV::process_quest_list(m_env.program_info(), m_env.console, m_context, m_options, quests, eggs_hatched); + } + virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) override{ + return process_and_do_quest(m_env, m_env.console, m_context, m_options, quest, eggs_hatched); + } + virtual void quest_completed() override{ + m_stats.questsCompleted++; + m_env.update_stats(); + } + virtual void end_round(bool save) override{ + //Fix the time to prevent running out of years + pbf_wait(m_context, 2000ms); + m_context.wait_for_all_requests(); + go_home(m_env.console, m_context); + home_to_date_time(m_env.console, m_context, false); + pbf_press_button(m_context, BUTTON_A, 160ms, 840ms); + pbf_press_button(m_context, BUTTON_A, 160ms, 840ms); + pbf_press_button(m_context, BUTTON_HOME, 160ms, ConsoleSettings::instance().SETTINGS_TO_HOME_DELAY0); + resume_game_from_home(m_env.console, m_context); + + if (save){ + m_env.log("Saving and resetting."); + save_game_from_overworld(m_env.program_info(), m_env.console, m_context); + reset_game(m_env.program_info(), m_env.console, m_context); + m_stats.saves++; } - env.update_stats(); - send_program_status_notification(env, NOTIFICATION_STATUS_UPDATE); + m_env.update_stats(); + send_program_status_notification(m_env, m_status_update); + } + +private: + SingleSwitchProgramEnvironment& m_env; + ProControllerContext& m_context; + BBQOption& m_options; + BBQSoloFarmer_Descriptor::Stats& m_stats; + EventNotificationOption& m_status_update; +}; + +} + +void BBQSoloFarmer::program(SingleSwitchProgramEnvironment& env, ProControllerContext& context){ + StartProgramChecks::check_performance_class_wired_or_wireless(context); + assert_16_9_720p_min(env.logger(), env.console); + + BBQSoloFarmer_Descriptor::Stats& stats = env.current_stats(); + + //Make sure console type is set + if (env.console.state().console_type() == ConsoleType::Unknown){ + throw UserSetupError(env.console, "Console Type (Switch 1 or 2) must be specified."); + } + + // Connect the controller. + require_player(env.console, context, BUTTON_LCLICK); + + //Fly to plaza + open_map_from_overworld(env.program_info(), env.console, context); + fly_to_overworld_from_map(env.program_info(), env.console, context); + + //Test a specific quest + /* + uint8_t eggs_hatched = 0; + BBQuests test_quest = BBQuests::catch_water; + bool questTest = process_and_do_quest(env, env.console, context, BBQ_OPTIONS, test_quest, eggs_hatched); + if (questTest){ + env.log("Finished quest."); } + */ + + BBQSoloFarmerGameActions game(env, context, BBQ_OPTIONS, stats, NOTIFICATION_STATUS_UPDATE); + run_bbq_rounds(env.logger(), BBQ_OPTIONS, game); env.update_stats(); if (BBQ_OPTIONS.FIX_TIME_WHEN_DONE){ diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h index 9917606334..1ac8535caf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h @@ -7,6 +7,9 @@ #ifndef PokemonAutomation_PokemonSV_BBQSoloFarmer_H #define PokemonAutomation_PokemonSV_BBQSoloFarmer_H +#include +#include +#include "Common/Cpp/Logging/AbstractLogger.h" #include "CommonFramework/Notifications/EventNotificationsTable.h" #include "NintendoSwitch/NintendoSwitch_SingleSwitchProgram.h" #include "NintendoSwitch/Options/NintendoSwitch_GoHomeWhenDoneOption.h" @@ -16,6 +19,45 @@ namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonSV{ + +// The game actions that run_bbq_rounds() depends on. They are injected so +// that the round loop (which quests to attempt, which ones count, when to +// stop, when to save) runs in tests without a Switch: BBQSoloFarmer performs +// them on the console, and tests replace them with scripted results. +class BBQGameActions{ +public: + virtual ~BBQGameActions() = default; + + // Open the quest panel and read the quests on it. + virtual std::vector read_quests() = 0; + + // Decide which of the quests just read are worth attempting this round. + // May reroll quests in game, so the returned list can be empty even when + // `quests` is not; the loop then reads the panel again. + virtual std::vector process_quest_list( + const std::vector& quests, uint8_t eggs_hatched + ) = 0; + + // Attempt one quest that is on the panel, after process_quest_list() + // chose it. Returns true if it is no longer on the panel afterwards. + // Increments `eggs_hatched` when the quest hatches eggs. + virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) = 0; + + // Progress reporting only: a quest was counted as completed. Lets stats + // update after every quest instead of once per round. + virtual void quest_completed() = 0; + + // A round has ended. The loop decides whether a save is due, because + // that depends on how many quests it has counted; how to fix the date, + // save and reset, and report the round is up to the game side. + virtual void end_round(bool save) = 0; +}; + +// Run rounds of quests until NUM_QUESTS have been completed, or until +// eggs run out when OUT_OF_EGGS is Stop. +void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game); + + class BBQSoloFarmer_Descriptor : public SingleSwitchProgramDescriptor{ public: BBQSoloFarmer_Descriptor(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 43740d2c1c..fda3441a39 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -225,8 +225,8 @@ std::vector process_quest_list( const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, const BBQOption& BBQ_OPTIONS, - std::vector& quest_list, - uint8_t& eggs_hatched + const std::vector& quest_list, + uint8_t eggs_hatched ){ std::vector quests_to_do; bool rerolled = false; diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 957a3c50e9..8ab92394f1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -71,8 +71,8 @@ std::vector process_quest_list( const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, const BBQOption& BBQ_OPTIONS, - std::vector& quest_list, - uint8_t& eggs_hatched + const std::vector& quest_list, + uint8_t eggs_hatched ); //Take the current quest and calls the function to do it, then checks the quest was successful. Returns true if so. From 102957f131d20d503526da3ceaa108b8670549f8 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 20 Oct 2026 22:39:54 -0700 Subject: [PATCH 2/6] Separate the BBQ quest plan from the controller actions that carry it out process_quest_list() decided what to do with each quest and pressed the buttons for it in the same loop, so the decisions could only be checked on a Switch. plan_quests() now makes the decisions from the options alone: which quests to do, which panel slots to reroll, and whether to reroll all. process_quest_list() carries out the plan, and opening the panel is a shared helper instead of three copies. All rerolls now move the cursor to the quest's slot. The out-of-eggs reroll used to reroll the top slot; the egg quest is a red quest and red quests are listed at the top, so this is the same in practice. OOEggs::Stop reaching the planner is now an InternalProgramError, since the farmer stops before that can happen. Unit tests cover the plan for exclusions, duplicate rows, quests that are not possible, and eggs. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 150 +++++++++++ .../Farming/PokemonSV_BlueberryQuests.cpp | 255 ++++++++---------- .../Farming/PokemonSV_BlueberryQuests.h | 17 ++ 3 files changed, 279 insertions(+), 143 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index d966bfe133..8c9563ff9a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -25,15 +25,165 @@ #include "Inference/Overworld/PokemonSV_LetsGoKillDetector.h" #include "Inference/Picnics/PokemonSV_SandwichRecipeDetector.h" #include "Inference/Picnics/PokemonSV_SandwichHandDetector.h" +#include "Programs/Farming/PokemonSV_BlueberryQuests.h" #include "PokemonSV_Tests.h" namespace PokemonAutomation{ namespace NintendoSwitch{ namespace PokemonSV{ +namespace{ + +class NullLogger : public Logger{ +public: + virtual void log(const std::string&, Color) override{} +}; + +// The quests read from the panel, the options that matter, and the plan +// plan_quests() must make. The default exclusions table has one row: +// auto-10, skip. +struct BBQuestPlanScenario{ + std::string name; + std::vector quests; + std::vector> extra_exclusions; + uint8_t num_eggs = 1; + uint8_t eggs_hatched = 0; + BBQOption::OOEggs out_of_eggs = BBQOption::OOEggs::Reroll; + std::vector expected_to_do; + std::vector expected_reroll_slots; + bool expected_reroll_all = false; +}; + +std::string quests_to_string(const std::vector& quests){ + std::string ret; + for (BBQuests quest : quests){ + ret += std::to_string((int)quest) + " "; + } + return ret; +} +std::string slots_to_string(const std::vector& slots){ + std::string ret; + for (size_t slot : slots){ + ret += std::to_string(slot) + " "; + } + return ret; +} + +class Test_BBQuestPlan : public UnitTest{ +public: + Test_BBQuestPlan(BBQuestPlanScenario scenario) + : UnitTest("PokemonSV::BBQuestPlan - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + BBQOption options; + options.NUM_EGGS.set(m_scenario.num_eggs); + options.OUT_OF_EGGS.set(m_scenario.out_of_eggs); + for (const auto& [quest, action] : m_scenario.extra_exclusions){ + auto row = std::make_unique(options.QUEST_EXCLUSIONS); + row->quest.set(quest); + row->action.set(action); + options.QUEST_EXCLUSIONS.append_row(std::move(row)); + } + + NullLogger logger; + const BBQuestPlan plan = plan_quests(logger, options, m_scenario.quests, m_scenario.eggs_hatched); + if (plan.to_do != m_scenario.expected_to_do){ + return "Expected quests to do: " + quests_to_string(m_scenario.expected_to_do) + + "got: " + quests_to_string(plan.to_do); + } + if (plan.reroll_slots != m_scenario.expected_reroll_slots){ + return "Expected reroll slots: " + slots_to_string(m_scenario.expected_reroll_slots) + + "got: " + slots_to_string(plan.reroll_slots); + } + if (plan.reroll_all != m_scenario.expected_reroll_all){ + return std::string("Expected reroll_all = ") + (m_scenario.expected_reroll_all ? "true" : "false"); + } + return true; + } + +private: + const BBQuestPlanScenario m_scenario; +}; + +} + +void add_tests_BBQuestPlan(UnitTestDatabase& database){ + using enum BBQuests; + const BBQuestPlanScenario scenarios[] = { + { + .name = "default table skips auto-10", + .quests = {make_tm, auto_10, sneak_up}, + .expected_to_do = {make_tm, sneak_up}, + }, + { + .name = "quests not possible are left out", + .quests = {pickup_10, make_tm, UnableToDetect}, + .expected_to_do = {make_tm}, + }, + { + .name = "nothing doable rerolls all", + .quests = {pickup_10, auto_10, catch_flying}, + .expected_reroll_all = true, + }, + { + // The reroll replaces a quest, so the next read has something new. + .name = "a reroll row rerolls that slot", + .quests = {make_tm, sneak_up, travel_500}, + .extra_exclusions = {{travel_500, BBQAction::reroll}}, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {2}, + }, + { + // A reroll is already a change, so nothing more is rerolled. + .name = "a rerolled slot with nothing doable does not reroll all", + .quests = {pickup_10, sneak_up, auto_10}, + .extra_exclusions = {{sneak_up, BBQAction::reroll}}, + .expected_reroll_slots = {1}, + }, + { + // Each row for a quest applies, in table order. + .name = "every table row for a quest applies", + .quests = {travel_500, auto_10}, + .extra_exclusions = { + {travel_500, BBQAction::run}, + {auto_10, BBQAction::run}, + {travel_500, BBQAction::run}, + }, + .expected_to_do = {travel_500, travel_500, auto_10}, + }, + { + .name = "egg quest is done while eggs remain", + .quests = {make_tm, hatch_egg, sneak_up}, + .expected_to_do = {make_tm, hatch_egg, sneak_up}, + }, + { + // The egg quest is rerolled where it is on the panel, not always + // in the top slot. + .name = "out of eggs rerolls the egg quest slot", + .quests = {make_tm, hatch_egg, sneak_up}, + .eggs_hatched = 1, + .expected_to_do = {make_tm, sneak_up}, + .expected_reroll_slots = {1}, + }, + { + .name = "out of eggs with keep going leaves the egg quest", + .quests = {make_tm, hatch_egg, sneak_up}, + .eggs_hatched = 1, + .out_of_eggs = BBQOption::OOEggs::KeepGoing, + .expected_to_do = {make_tm, sneak_up}, + }, + }; + for (const BBQuestPlanScenario& scenario : scenarios){ + database.add(scenario); + } +} + void add_tests(UnitTestDatabase& database){ + add_tests_BBQuestPlan(database); add_tests_WhiteButtonDetector(database); add_tests_BoxInfoDetector(database); add_tests_BoxEggDetector(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 43740d2c1c..dab292b71a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -221,6 +221,97 @@ std::vector read_quests( return quest_list; } +BBQuestPlan plan_quests( + Logger& logger, + const BBQOption& BBQ_OPTIONS, + const std::vector& quest_list, + uint8_t eggs_hatched +){ + BBQuestPlan plan; + std::vector> exclusions_table = BBQ_OPTIONS.QUEST_EXCLUSIONS.copy_snapshot(); + + logger.log("Processing quests."); + for (size_t slot = 0; slot < quest_list.size(); slot++){ + const BBQuests n = quest_list[slot]; + if (not_possible_quests.contains(n)){ + logger.log("Quest not possible"); + continue; + } + //Check eggs remaining. + if (n == BBQuests::hatch_egg && eggs_hatched >= BBQ_OPTIONS.NUM_EGGS){ + logger.log("Out of eggs! Quest not possible."); + switch (BBQ_OPTIONS.OUT_OF_EGGS){ + case BBQOption::OOEggs::Reroll: + logger.log("Reroll selected. Rerolling Egg quest. New quest will be run in the next batch of quests."); + //logger.log("Warning: This does not handle/check being out of BP!", COLOR_RED); + plan.reroll_slots.push_back(slot); + break; + case BBQOption::OOEggs::KeepGoing: + logger.log("Keep Going selected. Ignoring quest."); + break; + default: + //This case is handled in BBQSoloFarmer. + throw InternalProgramError(&logger, PA_CURRENT_FUNCTION, "OOEggs is Stop in process_quest_list()."); + } + continue; + } + bool quest_in_table = false; + for (const std::unique_ptr& row : exclusions_table){ + if (n != row->quest){ + continue; + } + logger.log("Quest found in inclusions/exclusions table."); + quest_in_table = true; + switch (row->action){ + case BBQAction::run: + logger.log("Run selected. Adding quest to list."); + plan.to_do.push_back(n); + break; + case BBQAction::reroll: + logger.log("Reroll selected. Rerolling quest. New quest will be run in the next batch of quests."); + plan.reroll_slots.push_back(slot); + break; + case BBQAction::skip: + logger.log("Skip selected. Skipping quest."); + break; + } + } + if (!quest_in_table){ + logger.log("Quest not in inclusion/exclusions table. Adding to list."); + plan.to_do.push_back(n); + } + } + + //Check that quests_to_do is not empty (after completing all quests on the list, be sure to erase it. + //Lag might be a problem in multi - look into making slots like menu-left navigation + plan.reroll_all = plan.reroll_slots.empty() && plan.to_do.empty(); + return plan; +} + +namespace{ + +//Open the quest panel from the overworld, with the cursor on the top quest. +void open_quest_panel(VideoStream& stream, ProControllerContext& context){ + WhiteButtonWatcher panel(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); + int result = run_until( + stream, context, + [&](ProControllerContext& context){ + for (int i = 0; i < 6; i++){ + pbf_press_dpad(context, DPAD_RIGHT, 400ms, 160ms); + pbf_wait(context, 1600ms); + context.wait_for_all_requests(); + } + }, + {{ panel }} + ); + if (result == 0){ + stream.log("Found quest panel."); + } + context.wait_for_all_requests(); +} + +} + std::vector process_quest_list( const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, @@ -228,155 +319,33 @@ std::vector process_quest_list( std::vector& quest_list, uint8_t& eggs_hatched ){ - std::vector quests_to_do; - bool rerolled = false; - std::vector> exclusions_table = BBQ_OPTIONS.QUEST_EXCLUSIONS.copy_snapshot(); - int questpos = 0; - - stream.log("Processing quests."); - //Put all do-able quests into a different list - for (auto n : quest_list){ - if (not_possible_quests.contains(n)){ - stream.log("Quest not possible"); - }else{ - //Check eggs remaining. - if (n == BBQuests::hatch_egg && eggs_hatched >= BBQ_OPTIONS.NUM_EGGS){ - stream.log("Out of eggs! Quest not possible."); - - switch (BBQ_OPTIONS.OUT_OF_EGGS){ - case BBQOption::OOEggs::Reroll: - { - stream.log("Reroll selected. Rerolling Egg quest. New quest will be run in the next batch of quests."); - //stream.log("Warning: This does not handle/check being out of BP!", COLOR_RED); - - WhiteButtonWatcher right_panel(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); - int result = run_until( - stream, context, - [&](ProControllerContext& context){ - for (int i = 0; i < 6; i++){ - pbf_press_dpad(context, DPAD_RIGHT, 400ms, 160ms); - pbf_wait(context, 1600ms); - context.wait_for_all_requests(); - } - }, - {{ right_panel }} - ); - if (result == 0){ - stream.log("Found quest panel."); - } - context.wait_for_all_requests(); - - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); + BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched); - rerolled = true; - press_Bs_to_back_to_overworld(info, stream, context); + for (size_t slot : plan.reroll_slots){ + open_quest_panel(stream, context); - break; - } - case BBQOption::OOEggs::KeepGoing: - stream.log("Keep Going selected. Ignoring quest."); - break; - default: - //This case is handled in BBQSoloFarmer. - stream.log("OOEggs is Stop in process_quest_list()."); - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "OOEggs is Stop in process_quest_list().", - stream - ); - break; - } - }else{ - bool quest_in_table = false; - for (const std::unique_ptr& row : exclusions_table){ - if(n == row->quest){ - stream.log("Quest found in inclusions/exclusions table."); - quest_in_table = true; - - WhiteButtonWatcher rp2(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); - int result2; - switch (row->action){ - case BBQAction::run: - stream.log("Run selected. Adding quest to list."); - quests_to_do.push_back(n); - break; - case BBQAction::reroll: - stream.log("Reroll selected. Rerolling quest. New quest will be run in the next batch of quests."); - result2 = run_until( - stream, context, - [&](ProControllerContext& context){ - for (int i = 0; i < 6; i++){ - pbf_press_dpad(context, DPAD_RIGHT, 400ms, 160ms); - pbf_wait(context, 1600ms); - context.wait_for_all_requests(); - } - }, - {{ rp2 }} - ); - if (result2 == 0){ - stream.log("Found quest panel."); - } - context.wait_for_all_requests(); - - //Move cursor down to quest - for (int i = 0; i < questpos; i++){ - pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - } - - //Reroll - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - - //Prevent error/rerolling again at the end (allows program to read the rerolled quests) - rerolled = true; - - press_Bs_to_back_to_overworld(info, stream, context); - break; - case BBQAction::skip: - stream.log("Skip selected. Skipping quest."); - break; - } - } - } - if(!quest_in_table){ - stream.log("Quest not in inclusion/exclusions table. Adding to list."); - quests_to_do.push_back(n); - } - } + //Move cursor down to quest + for (size_t i = 0; i < slot; i++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); + pbf_wait(context, 800ms); + context.wait_for_all_requests(); } - questpos++; + + //Reroll + pbf_press_button(context, BUTTON_A, 160ms, 400ms); + pbf_press_button(context, BUTTON_A, 160ms, 400ms); + pbf_wait(context, 800ms); + context.wait_for_all_requests(); + + press_Bs_to_back_to_overworld(info, stream, context); } - - //Check that quests_to_do is not empty (after completing all quests on the list, be sure to erase it. - //Lag might be a problem in multi - look into making slots like menu-left navigation - if (!rerolled && quests_to_do.size() == 0){ + + if (plan.reroll_all){ stream.log("No possible quests! Rerolling all quests."); //Open quest panel and reroll all quests. //This does not handle out of BP. - WhiteButtonWatcher panel(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); - int result = run_until( - stream, context, - [&](ProControllerContext& context){ - for (int i = 0; i < 6; i++){ - pbf_press_dpad(context, DPAD_RIGHT, 400ms, 160ms); - pbf_wait(context, 1600ms); - context.wait_for_all_requests(); - } - }, - {{ panel }} - ); - if (result == 0){ - stream.log("Found quest panel."); - } - context.wait_for_all_requests(); + open_quest_panel(stream, context); for (string::size_type i = 0; i < quest_list.size(); i++){ pbf_press_button(context, BUTTON_A, 160ms, 400ms); @@ -391,7 +360,7 @@ std::vector process_quest_list( press_Bs_to_back_to_overworld(info, stream, context); } /* - if (!rerolled && quests_to_do.size() == 0){ + if (plan.reroll_all){ OperationFailedExceptionWithScreenshot::fire( ErrorReportMode::SEND_ERROR_REPORT, "No possible quests! Check language selection.", @@ -399,7 +368,7 @@ std::vector process_quest_list( ); } */ - return quests_to_do; + return plan.to_do; } bool process_and_do_quest( diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 957a3c50e9..92270cf374 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -65,6 +65,23 @@ std::vector read_quests( const BBQOption& BBQ_OPTIONS ); +//What to do with the quests read from the panel. Slot 0 is the top quest on the panel. +struct BBQuestPlan{ + std::vector to_do; //Quests to attempt, in panel order. + std::vector reroll_slots; //Slots to reroll, in panel order. + bool reroll_all = false; //Nothing to do and nothing rerolled: reroll every slot. +}; +//Decide what to do with each quest from the options alone, without touching the game, so +//the decision can be tested. Quests not possible are left out. Out-of-egg hatch quests and +//quests set to reroll in the exclusions table are rerolled. A quest with several table rows +//gets the action of each row, in table order. +BBQuestPlan plan_quests( + Logger& logger, + const BBQOption& BBQ_OPTIONS, + const std::vector& quest_list, + uint8_t eggs_hatched +); + //Determine which quests are possible and which quests are not. (ex. no eggs, reroll egg hatcher.) //Quests not possible are removed from the list. If the list is empty, then reroll all items. std::vector process_quest_list( From 053e59b375ab3bdcf06c5ed167820e5d844ab070 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 21 Oct 2026 10:51:21 -0700 Subject: [PATCH 3/6] Do not retry a failed BBQ quest every round while it stays on the panel process_and_do_quest() gives up on a quest after NUM_RETRIES retries, but the quest stays on the panel, so the next round attempts it again with a fresh set of retries. A quest that cannot be done, such as a sneak-up whose target does not spawn, is retried forever. run_bbq_rounds() now remembers quests that failed all their attempts and leaves them out of later rounds. A quest is forgotten once a read of 4 known quests shows it gone, so it gets its attempts again if it comes back. If only failed quests are doable, the farmer stops instead of spending BP to reroll them. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 78 ++++++++++++++++--- .../Farming/PokemonSV_BBQSoloFarmer.cpp | 45 ++++++++++- .../Farming/PokemonSV_BBQSoloFarmer.h | 3 +- 3 files changed, 114 insertions(+), 12 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index f894861d68..f98872d0ba 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Inference/PokemonSV_WhiteButtonDetector.h" #include "Inference/Boxes/PokemonSV_BoxDetection.h" @@ -55,6 +56,15 @@ class SimulatedBBQGameActions : public BBQGameActions{ // Completing the first quest also completes the second, e.g. walking // 500 meters while navigating to a photo target. std::vector> also_completes; + // Attempts at these always fail, e.g. a target that never spawns. + std::set never_completes; + // New quests are drawn from this list in turn, skipping any that are + // already on the panel. + std::vector new_quests = { + BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar, + BBQuests::photo_savanna, BBQuests::catch_any, BBQuests::catch_normal, + BBQuests::catch_fire, BBQuests::catch_water, BBQuests::catch_grass, + }; std::vector events; @@ -84,7 +94,8 @@ class SimulatedBBQGameActions : public BBQGameActions{ } virtual bool do_quest(BBQuests quest, uint8_t&) override{ events.push_back("do"); - const bool success = m_next_outcome < outcomes.size() ? outcomes[m_next_outcome++] : true; + const bool success = !never_completes.contains(quest) + && (m_next_outcome < outcomes.size() ? outcomes[m_next_outcome++] : true); if (success){ complete(quest); for (const auto& [done, extra] : also_completes){ @@ -110,16 +121,9 @@ class SimulatedBBQGameActions : public BBQGameActions{ } } - // New quests come from a fixed rotation of doable blue quests, skipping - // any that are already on the panel. BBQuests next_new_quest(){ - static const BBQuests ROTATION[] = { - BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar, - BBQuests::photo_savanna, BBQuests::catch_any, BBQuests::catch_normal, - BBQuests::catch_fire, BBQuests::catch_water, BBQuests::catch_grass, - }; while (true){ - BBQuests quest = ROTATION[m_next_new_quest++ % std::size(ROTATION)]; + BBQuests quest = new_quests[m_next_new_quest++ % new_quests.size()]; if (std::find(panel.begin(), panel.end(), quest) == panel.end()){ return quest; } @@ -150,6 +154,8 @@ struct BBQRoundsScenario{ std::vector panel = {BBQuests::make_tm, BBQuests::auto_10, BBQuests::sneak_up}; std::vector outcomes; std::vector> also_completes; + std::set never_completes; + std::vector new_quests; uint64_t expected_completed = 0; std::string expected; }; @@ -174,6 +180,10 @@ class Test_BBQFarmerRounds : public UnitTest{ game.panel = m_scenario.panel; game.outcomes = m_scenario.outcomes; game.also_completes = m_scenario.also_completes; + game.never_completes = m_scenario.never_completes; + if (!m_scenario.new_quests.empty()){ + game.new_quests = m_scenario.new_quests; + } NullLogger logger; run_bbq_rounds(logger, options, game); @@ -246,6 +256,56 @@ void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ .expected_completed = 0, .expected = "", }, + { + // sneak-up fails in round 1 and is still on the panel in round 2, + // where only the two new quests are attempted. + .name = "failed quest is not attempted again", + .num_quests = 4, + .never_completes = {BBQuests::sneak_up}, + .expected_completed = 4, + .expected = + "read process read do completed read do completed read do end " + "read process read do completed read do completed end", + }, + { + .name = "stops when only failed quests are doable", + .num_quests = 3, + .panel = {BBQuests::sneak_up, BBQuests::pickup_10, BBQuests::catch_flying}, + .never_completes = {BBQuests::sneak_up}, + .expected_completed = 0, + .expected = "read process read do end read process", + }, + { + // sneak-up fails, then leaves the panel along with make-tm. Round 2 + // reads a full panel without it, and its replacement for + // photo-canyon brings it back. Round 3 attempts it again. + .name = "failed quest that leaves a full panel is attempted again", + .num_quests = 5, + .panel = {BBQuests::sneak_up, BBQuests::make_tm, BBQuests::pickup_10, BBQuests::catch_flying}, + .outcomes = {false}, + .also_completes = {{BBQuests::make_tm, BBQuests::sneak_up}}, + .new_quests = {BBQuests::auto_10, BBQuests::photo_canyon, BBQuests::sneak_up}, + .expected_completed = 5, + .expected = + "read process read do read do completed end " + "read process read do completed read do completed end " + "read process read do completed read do completed end", + }, + { + // As above with 3 slots. A 4th quest could have been missed by + // OCR, so the read does not prove sneak-up left: it stays failed. + .name = "failed quest missing from a 3-slot panel stays failed", + .num_quests = 4, + .panel = {BBQuests::sneak_up, BBQuests::make_tm, BBQuests::pickup_10}, + .outcomes = {false}, + .also_completes = {{BBQuests::make_tm, BBQuests::sneak_up}}, + .new_quests = {BBQuests::auto_10, BBQuests::photo_canyon, BBQuests::sneak_up}, + .expected_completed = 4, + .expected = + "read process read do read do completed end " + "read process read do completed read do completed end " + "read process read do completed end", + }, }; for (const BBQRoundsScenario& scenario : scenarios){ database.add(scenario); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index c6deaccca9..ee63a9b792 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp @@ -4,6 +4,7 @@ * */ +#include #include "Common/Cpp/Exceptions.h" #include "CommonFramework/Notifications/ProgramNotifications.h" #include "CommonFramework/ProgramStats/StatsTracking.h" @@ -74,12 +75,40 @@ BBQSoloFarmer::BBQSoloFarmer() PA_ADD_OPTION(NOTIFICATIONS); } +namespace{ + +// Forget the failed quests that are gone from the panel, so a quest that +// comes back later gets its attempts again. The first 3 slots are always +// read, as UnableToDetect when OCR fails, but a 4th slot is only there when +// OCR reads it. So only a read of 4 known quests proves a quest is gone; a +// missed read must not give a failing quest new attempts. +void forget_quests_gone_from_panel(std::set& failed_quests, const std::vector& panel){ + if (panel.size() < 4 || std::find(panel.begin(), panel.end(), BBQuests::UnableToDetect) != panel.end()){ + return; + } + std::erase_if(failed_quests, [&](BBQuests quest){ + return std::find(panel.begin(), panel.end(), quest) == panel.end(); + }); +} + +} + void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game){ std::vector quest_list; //all quests std::vector quests_to_do; //do-able quests uint8_t eggs_hatched = 0; //Track eggs uint64_t num_completed_quests = 0; + // Quests that failed every attempt do_quest() made. A failed quest stays + // on the panel, so without this it gets NUM_RETRIES more attempts every + // round, forever, e.g. a sneak-up whose target does not spawn. + std::set failed_quests; + auto read_panel = [&](){ + std::vector panel = game.read_quests(); + forget_quests_gone_from_panel(failed_quests, panel); + return panel; + }; + while (num_completed_quests < options.NUM_QUESTS){ if (options.OUT_OF_EGGS == BBQOption::OOEggs::Stop && eggs_hatched >= options.NUM_EGGS){ logger.log("Stop when out of eggs selected. Stopping program."); @@ -88,16 +117,27 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga //Get and reroll quests until we can at least one while (quests_to_do.size() < 1){ - quest_list = game.read_quests(); + quest_list = read_panel(); quests_to_do = game.process_quest_list(quest_list, eggs_hatched); + // Rerolling costs BP and the failed quests may be doable another + // time, so stop instead of spending BP to replace them. + const bool found_doable = !quests_to_do.empty(); + std::erase_if(quests_to_do, [&](BBQuests quest){ + return failed_quests.contains(quest); + }); + if (found_doable && quests_to_do.empty()){ + logger.log("Every doable quest on the panel failed all its attempts. Stopping program.", COLOR_RED); + return; + } + //Clear out the regular quest list. quest_list.clear(); } for (auto current_quest : quests_to_do){ //Check if quest was already completed (ex. 500 meters completed while navigating to take a photo) - quest_list = game.read_quests(); + quest_list = read_panel(); if (std::find(quest_list.begin(), quest_list.end(), current_quest) != quest_list.end()){ logger.log("Current quest exists on list. Doing quest."); bool questSuccess = game.do_quest(current_quest, eggs_hatched); @@ -107,6 +147,7 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga num_completed_quests++; }else{ logger.log("Quest did not complete successfully."); + failed_quests.insert(current_quest); } }else{ //Note: This doesn't account for case such as "sneak up" being added and then completed alongside the next quest diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h index 1ac8535caf..1afa74e6dc 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h @@ -54,7 +54,8 @@ class BBQGameActions{ }; // Run rounds of quests until NUM_QUESTS have been completed, or until -// eggs run out when OUT_OF_EGGS is Stop. +// eggs run out when OUT_OF_EGGS is Stop, or until every doable quest on the +// panel is one that already failed all its attempts. void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game); From fe5055a40c7de35885fb4d248123ee7347111ea1 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 21 Oct 2026 10:59:00 -0700 Subject: [PATCH 4/6] Break the BBQ quest planner and its controller steps into helpers Move the out-of-eggs choice, the exclusions table rows, a single-slot reroll and the reroll of every slot into file-local helpers, so plan_quests() and process_quest_list() read as one level of steps. Explain why the language-selection error is commented out. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Farming/PokemonSV_BlueberryQuests.cpp | 217 ++++++++++-------- 1 file changed, 125 insertions(+), 92 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index dab292b71a..f960282969 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -221,6 +221,122 @@ std::vector read_quests( return quest_list; } +namespace{ + +//Out of eggs, the egg quest cannot be done. OUT_OF_EGGS decides what happens to it. +void plan_out_of_eggs(Logger& logger, const BBQOption& BBQ_OPTIONS, size_t slot, BBQuestPlan& plan){ + switch (BBQ_OPTIONS.OUT_OF_EGGS){ + case BBQOption::OOEggs::Reroll: + logger.log("Reroll selected. Rerolling Egg quest. New quest will be run in the next batch of quests."); + //logger.log("Warning: This does not handle/check being out of BP!", COLOR_RED); + plan.reroll_slots.push_back(slot); + break; + case BBQOption::OOEggs::KeepGoing: + logger.log("Keep Going selected. Ignoring quest."); + break; + default: + //This case is handled in BBQSoloFarmer. + throw InternalProgramError(&logger, PA_CURRENT_FUNCTION, "OOEggs is Stop in process_quest_list()."); + } +} + +//Apply each exclusions table row for the quest, in table order. Returns false if no row is for it. +bool plan_from_exclusions( + Logger& logger, + const std::vector>& exclusions_table, + BBQuests quest, size_t slot, + BBQuestPlan& plan +){ + bool quest_in_table = false; + for (const std::unique_ptr& row : exclusions_table){ + if (quest != row->quest){ + continue; + } + logger.log("Quest found in inclusions/exclusions table."); + quest_in_table = true; + switch (row->action){ + case BBQAction::run: + logger.log("Run selected. Adding quest to list."); + plan.to_do.push_back(quest); + break; + case BBQAction::reroll: + logger.log("Reroll selected. Rerolling quest. New quest will be run in the next batch of quests."); + plan.reroll_slots.push_back(slot); + break; + case BBQAction::skip: + logger.log("Skip selected. Skipping quest."); + break; + } + } + return quest_in_table; +} + +//Open the quest panel from the overworld, with the cursor on the top quest. +void open_quest_panel(VideoStream& stream, ProControllerContext& context){ + WhiteButtonWatcher panel(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); + int result = run_until( + stream, context, + [&](ProControllerContext& context){ + for (int i = 0; i < 6; i++){ + pbf_press_dpad(context, DPAD_RIGHT, 400ms, 160ms); + pbf_wait(context, 1600ms); + context.wait_for_all_requests(); + } + }, + {{ panel }} + ); + if (result == 0){ + stream.log("Found quest panel."); + } + context.wait_for_all_requests(); +} + +void reroll_slot( + const ProgramInfo& info, + VideoStream& stream, ProControllerContext& context, + size_t slot +){ + open_quest_panel(stream, context); + + //Move cursor down to quest + for (size_t i = 0; i < slot; i++){ + pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); + pbf_wait(context, 800ms); + context.wait_for_all_requests(); + } + + //Reroll + pbf_press_button(context, BUTTON_A, 160ms, 400ms); + pbf_press_button(context, BUTTON_A, 160ms, 400ms); + pbf_wait(context, 800ms); + context.wait_for_all_requests(); + + press_Bs_to_back_to_overworld(info, stream, context); +} + +//This does not handle out of BP. +void reroll_all_slots( + const ProgramInfo& info, + VideoStream& stream, ProControllerContext& context, + size_t slots +){ + open_quest_panel(stream, context); + + for (size_t i = 0; i < slots; i++){ + pbf_press_button(context, BUTTON_A, 160ms, 400ms); + pbf_press_button(context, BUTTON_A, 160ms, 400ms); //Yes. + pbf_wait(context, 800ms); + context.wait_for_all_requests(); + pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); + pbf_wait(context, 800ms); + context.wait_for_all_requests(); + } + //Close quest panel - mash b + press_Bs_to_back_to_overworld(info, stream, context); +} + +} + BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, @@ -240,43 +356,10 @@ BBQuestPlan plan_quests( //Check eggs remaining. if (n == BBQuests::hatch_egg && eggs_hatched >= BBQ_OPTIONS.NUM_EGGS){ logger.log("Out of eggs! Quest not possible."); - switch (BBQ_OPTIONS.OUT_OF_EGGS){ - case BBQOption::OOEggs::Reroll: - logger.log("Reroll selected. Rerolling Egg quest. New quest will be run in the next batch of quests."); - //logger.log("Warning: This does not handle/check being out of BP!", COLOR_RED); - plan.reroll_slots.push_back(slot); - break; - case BBQOption::OOEggs::KeepGoing: - logger.log("Keep Going selected. Ignoring quest."); - break; - default: - //This case is handled in BBQSoloFarmer. - throw InternalProgramError(&logger, PA_CURRENT_FUNCTION, "OOEggs is Stop in process_quest_list()."); - } + plan_out_of_eggs(logger, BBQ_OPTIONS, slot, plan); continue; } - bool quest_in_table = false; - for (const std::unique_ptr& row : exclusions_table){ - if (n != row->quest){ - continue; - } - logger.log("Quest found in inclusions/exclusions table."); - quest_in_table = true; - switch (row->action){ - case BBQAction::run: - logger.log("Run selected. Adding quest to list."); - plan.to_do.push_back(n); - break; - case BBQAction::reroll: - logger.log("Reroll selected. Rerolling quest. New quest will be run in the next batch of quests."); - plan.reroll_slots.push_back(slot); - break; - case BBQAction::skip: - logger.log("Skip selected. Skipping quest."); - break; - } - } - if (!quest_in_table){ + if (!plan_from_exclusions(logger, exclusions_table, n, slot, plan)){ logger.log("Quest not in inclusion/exclusions table. Adding to list."); plan.to_do.push_back(n); } @@ -288,30 +371,6 @@ BBQuestPlan plan_quests( return plan; } -namespace{ - -//Open the quest panel from the overworld, with the cursor on the top quest. -void open_quest_panel(VideoStream& stream, ProControllerContext& context){ - WhiteButtonWatcher panel(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); - int result = run_until( - stream, context, - [&](ProControllerContext& context){ - for (int i = 0; i < 6; i++){ - pbf_press_dpad(context, DPAD_RIGHT, 400ms, 160ms); - pbf_wait(context, 1600ms); - context.wait_for_all_requests(); - } - }, - {{ panel }} - ); - if (result == 0){ - stream.log("Found quest panel."); - } - context.wait_for_all_requests(); -} - -} - std::vector process_quest_list( const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, @@ -322,43 +381,17 @@ std::vector process_quest_list( BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched); for (size_t slot : plan.reroll_slots){ - open_quest_panel(stream, context); - - //Move cursor down to quest - for (size_t i = 0; i < slot; i++){ - pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - } - - //Reroll - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - - press_Bs_to_back_to_overworld(info, stream, context); + reroll_slot(info, stream, context, slot); } - if (plan.reroll_all){ stream.log("No possible quests! Rerolling all quests."); - - //Open quest panel and reroll all quests. - //This does not handle out of BP. - open_quest_panel(stream, context); - - for (string::size_type i = 0; i < quest_list.size(); i++){ - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_press_button(context, BUTTON_A, 160ms, 400ms); //Yes. - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - } - //Close quest panel - mash b - press_Bs_to_back_to_overworld(info, stream, context); + reroll_all_slots(info, stream, context, quest_list.size()); } + + //Disabled since 2025-05, when the exclusions table gained its reroll action. Before that, + //nothing doable stopped the program here, because it usually meant the game language + //option did not match the game and no quest could be read. Now all quests are rerolled + //above instead, which also covers a panel of only excluded quests. /* if (plan.reroll_all){ OperationFailedExceptionWithScreenshot::fire( From 5b86beecb19588dadffddbdaffc40035b9937dde Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 21 Oct 2026 13:05:54 -0700 Subject: [PATCH 5/6] Check which quest a BBQ reroll pays for, and that it was replaced reroll_slot() opened the quest panel, pressed DOWN once per slot from where it assumed the cursor was, and pressed A twice. The panel does not always open with the cursor on the top quest: on a Switch it opened where the cursor was left, so the reroll paid for a different quest than planned. Nothing checked the menu opened or the quest changed, so running out of BP went unnoticed and the same quest was rerolled every round. reroll_quest() now does a reroll through injectable BBQRerollActions: open the reroll menu wherever the cursor is, see which quest the menu opened next to from its arrow, move to the planned quest, and only then confirm. Afterwards it reads the panel (up to 3 times, as OCR can miss a read) to check the quest was replaced. Panel or menu not found stops before spending BP; a quest not replaced stops without an error report, as it usually means out of BP. The arrow boxes for the top three slots were checked on a Switch; the fourth uses the same spacing. Reroll-all is unchanged. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 216 ++++++++++++++++++ .../Farming/PokemonSV_BlueberryQuests.cpp | 158 +++++++++++-- .../Farming/PokemonSV_BlueberryQuests.h | 47 ++++ 3 files changed, 403 insertions(+), 18 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index 8c9563ff9a..610a5bb935 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -107,6 +107,128 @@ class Test_BBQuestPlan : public UnitTest{ const BBQuestPlanScenario m_scenario; }; + +// A quest panel with a cursor. A reroll replaces the quest under the cursor +// with the next of `replacements`, unless out of BP. +class SimulatedQuestPanel : public BBQRerollActions{ +public: + std::vector quests; + std::vector replacements; + size_t cursor = 0; + bool panel_opens = true; + bool menu_seen = true; + bool out_of_bp = false; + int missed_reads = 0; // Reads that fail OCR on every slot. + + bool panel_open = false; + bool menu_open = false; + std::vector rerolled_slots; + + virtual bool open_panel() override{ + panel_open = panel_opens; + return panel_open; + } + virtual std::optional open_reroll_menu() override{ + menu_open = true; + if (!menu_seen){ + return std::nullopt; + } + return cursor; + } + virtual void close_reroll_menu() override{ + menu_open = false; + } + virtual void move_cursor(int slots) override{ + cursor = (size_t)((int)cursor + slots); + } + virtual void confirm_reroll() override{ + menu_open = false; + if (out_of_bp){ + return; + } + rerolled_slots.push_back(cursor); + quests[cursor] = replacements[rerolled_slots.size() - 1]; + } + virtual void close_panel() override{ + panel_open = false; + menu_open = false; + } + virtual std::vector read_quests() override{ + if (missed_reads > 0){ + missed_reads--; + return std::vector(quests.size(), BBQuests::UnableToDetect); + } + return quests; + } +}; + +struct BBQRerollScenario{ + std::string name; + std::vector quests; + std::vector replacements; + size_t slot; + size_t cursor = 0; + bool panel_opens = true; + bool menu_seen = true; + bool out_of_bp = false; + int missed_reads = 0; + BBQRerollResult expected; + std::vector expected_rerolled_slots; + std::vector expected_quests; +}; + +std::string reroll_result_to_string(BBQRerollResult result){ + switch (result){ + case BBQRerollResult::Rerolled: return "Rerolled"; + case BBQRerollResult::PanelNotOpened: return "PanelNotOpened"; + case BBQRerollResult::MenuNotFound: return "MenuNotFound"; + case BBQRerollResult::NotReplaced: return "NotReplaced"; + } + return "?"; +} + +class Test_BBQReroll : public UnitTest{ +public: + Test_BBQReroll(BBQRerollScenario scenario) + : UnitTest("PokemonSV::BBQReroll - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + SimulatedQuestPanel panel; + panel.quests = m_scenario.quests; + panel.replacements = m_scenario.replacements; + panel.cursor = m_scenario.cursor; + panel.panel_opens = m_scenario.panel_opens; + panel.menu_seen = m_scenario.menu_seen; + panel.out_of_bp = m_scenario.out_of_bp; + panel.missed_reads = m_scenario.missed_reads; + + NullLogger logger; + std::vector quests = m_scenario.quests; + const BBQRerollResult result = reroll_quest(logger, panel, quests, m_scenario.slot); + if (result != m_scenario.expected){ + return "Expected " + reroll_result_to_string(m_scenario.expected) + + ", got " + reroll_result_to_string(result); + } + if (panel.rerolled_slots != m_scenario.expected_rerolled_slots){ + return "Expected rerolled slots: " + slots_to_string(m_scenario.expected_rerolled_slots) + + "got: " + slots_to_string(panel.rerolled_slots); + } + if (quests != m_scenario.expected_quests){ + return "Expected quests: " + quests_to_string(m_scenario.expected_quests) + + "got: " + quests_to_string(quests); + } + if (panel.panel_open || panel.menu_open){ + return "Panel left open."; + } + return true; + } + +private: + const BBQRerollScenario m_scenario; +}; + } void add_tests_BBQuestPlan(UnitTestDatabase& database){ @@ -180,10 +302,104 @@ void add_tests_BBQuestPlan(UnitTestDatabase& database){ } } +void add_tests_BBQReroll(UnitTestDatabase& database){ + using enum BBQuests; + const BBQRerollScenario scenarios[] = { + { + .name = "cursor on the top quest", + .quests = {make_tm, sneak_up, travel_500}, + .replacements = {catch_any}, + .slot = 2, + .expected = BBQRerollResult::Rerolled, + .expected_rerolled_slots = {2}, + .expected_quests = {make_tm, sneak_up, catch_any}, + }, + { + // Seen on a Switch: the panel can open with the cursor where it + // was left, so moving down from the top rerolls the wrong quest. + .name = "cursor left below the quest moves up", + .quests = {make_tm, travel_500, sneak_up, hatch_egg}, + .replacements = {catch_any}, + .slot = 1, + .cursor = 3, + .expected = BBQRerollResult::Rerolled, + .expected_rerolled_slots = {1}, + .expected_quests = {make_tm, catch_any, sneak_up, hatch_egg}, + }, + { + .name = "fourth quest", + .quests = {make_tm, travel_500, sneak_up, hatch_egg}, + .replacements = {catch_any}, + .slot = 3, + .expected = BBQRerollResult::Rerolled, + .expected_rerolled_slots = {3}, + .expected_quests = {make_tm, travel_500, sneak_up, catch_any}, + }, + { + .name = "panel not opened spends nothing", + .quests = {make_tm, sneak_up, travel_500}, + .slot = 2, + .panel_opens = false, + .expected = BBQRerollResult::PanelNotOpened, + .expected_quests = {make_tm, sneak_up, travel_500}, + }, + { + .name = "menu not seen spends nothing", + .quests = {make_tm, sneak_up, travel_500}, + .slot = 2, + .menu_seen = false, + .expected = BBQRerollResult::MenuNotFound, + .expected_quests = {make_tm, sneak_up, travel_500}, + }, + { + .name = "out of BP is not replaced", + .quests = {make_tm, sneak_up, travel_500}, + .slot = 2, + .out_of_bp = true, + .expected = BBQRerollResult::NotReplaced, + .expected_quests = {make_tm, sneak_up, travel_500}, + }, + { + .name = "a missed read is read again", + .quests = {make_tm, sneak_up, travel_500}, + .replacements = {catch_any}, + .slot = 2, + .missed_reads = 2, + .expected = BBQRerollResult::Rerolled, + .expected_rerolled_slots = {2}, + .expected_quests = {make_tm, sneak_up, catch_any}, + }, + { + .name = "three missed reads give up", + .quests = {make_tm, sneak_up, travel_500}, + .replacements = {catch_any}, + .slot = 2, + .missed_reads = 3, + .expected = BBQRerollResult::NotReplaced, + .expected_rerolled_slots = {2}, + .expected_quests = {make_tm, sneak_up, travel_500}, + }, + { + // Cannot be told apart from out of BP. + .name = "replaced by the same quest is not replaced", + .quests = {make_tm, sneak_up, travel_500}, + .replacements = {travel_500}, + .slot = 2, + .expected = BBQRerollResult::NotReplaced, + .expected_rerolled_slots = {2}, + .expected_quests = {make_tm, sneak_up, travel_500}, + }, + }; + for (const BBQRerollScenario& scenario : scenarios){ + database.add(scenario); + } +} + void add_tests(UnitTestDatabase& database){ add_tests_BBQuestPlan(database); + add_tests_BBQReroll(database); add_tests_WhiteButtonDetector(database); add_tests_BoxInfoDetector(database); add_tests_BoxEggDetector(database); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index f960282969..28e5481912 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -22,6 +22,7 @@ #include "VideoGames/PokemonSV/PokemonSV_Settings.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_GameEntry.h" #include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_DialogDetector.h" +#include "VideoGames/PokemonSV/Inference/Dialogs/PokemonSV_GradientArrowDetector.h" #include "VideoGames/PokemonSV/Inference/Battles/PokemonSV_NormalBattleMenus.h" #include "VideoGames/PokemonSV/Inference/Battles/PokemonSV_EncounterWatcher.h" #include "VideoGames/PokemonSV/Inference/PokemonSV_MainMenuDetector.h" @@ -271,8 +272,8 @@ bool plan_from_exclusions( return quest_in_table; } -//Open the quest panel from the overworld, with the cursor on the top quest. -void open_quest_panel(VideoStream& stream, ProControllerContext& context){ +//Open the quest panel from the overworld. Returns false if it did not open. +bool open_quest_panel(VideoStream& stream, ProControllerContext& context){ WhiteButtonWatcher panel(COLOR_BLUE, WhiteButton::ButtonB, {0.484, 0.117, 0.022, 0.037}); int result = run_until( stream, context, @@ -289,29 +290,102 @@ void open_quest_panel(VideoStream& stream, ProControllerContext& context){ stream.log("Found quest panel."); } context.wait_for_all_requests(); + return result == 0; } +class ConsoleBBQRerollActions : public BBQRerollActions{ +public: + ConsoleBBQRerollActions( + const ProgramInfo& info, + VideoStream& stream, ProControllerContext& context, + const BBQOption& BBQ_OPTIONS + ) + : m_info(info), m_stream(stream), m_context(context), m_options(BBQ_OPTIONS) + {} + + virtual bool open_panel() override{ + return open_quest_panel(m_stream, m_context); + } + virtual std::optional open_reroll_menu() override{ + //The menu opens next to the quest, with an arrow on its top choice. Slots are 0.177 + //apart; the boxes for the top 3 slots were checked on a Switch, the 4th is spaced + //the same way. + GradientArrowWatcher slot0(COLOR_RED, GradientArrowType::RIGHT, {0.475, 0.218, 0.070, 0.095}); + GradientArrowWatcher slot1(COLOR_RED, GradientArrowType::RIGHT, {0.475, 0.395, 0.070, 0.095}); + GradientArrowWatcher slot2(COLOR_RED, GradientArrowType::RIGHT, {0.475, 0.572, 0.070, 0.095}); + GradientArrowWatcher slot3(COLOR_RED, GradientArrowType::RIGHT, {0.475, 0.749, 0.070, 0.095}); + pbf_press_button(m_context, BUTTON_A, 160ms, 400ms); + m_context.wait_for_all_requests(); + int ret = wait_until( + m_stream, m_context, std::chrono::seconds(3), + {slot0, slot1, slot2, slot3} + ); + if (ret < 0){ + return std::nullopt; + } + return (size_t)ret; + } + virtual void close_reroll_menu() override{ + pbf_press_button(m_context, BUTTON_B, 160ms, 400ms); + m_context.wait_for_all_requests(); + } + virtual void move_cursor(int slots) override{ + for (int i = 0; i < std::abs(slots); i++){ + pbf_press_dpad(m_context, slots > 0 ? DPAD_DOWN : DPAD_UP, 160ms, 160ms); + pbf_wait(m_context, 800ms); + } + m_context.wait_for_all_requests(); + } + virtual void confirm_reroll() override{ + pbf_press_button(m_context, BUTTON_A, 160ms, 400ms); + pbf_wait(m_context, 800ms); + m_context.wait_for_all_requests(); + } + virtual void close_panel() override{ + press_Bs_to_back_to_overworld(m_info, m_stream, m_context); + } + virtual std::vector read_quests() override{ + return PokemonSV::read_quests(m_info, m_stream, m_context, m_options); + } + +private: + const ProgramInfo& m_info; + VideoStream& m_stream; + ProControllerContext& m_context; + const BBQOption& m_options; +}; + void reroll_slot( const ProgramInfo& info, VideoStream& stream, ProControllerContext& context, + const BBQOption& BBQ_OPTIONS, + std::vector& quest_list, size_t slot ){ - open_quest_panel(stream, context); - - //Move cursor down to quest - for (size_t i = 0; i < slot; i++){ - pbf_press_dpad(context, DPAD_DOWN, 160ms, 160ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); + ConsoleBBQRerollActions actions(info, stream, context, BBQ_OPTIONS); + switch (reroll_quest(stream.logger(), actions, quest_list, slot)){ + case BBQRerollResult::Rerolled: + return; + case BBQRerollResult::PanelNotOpened: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "Unable to open the quest panel to reroll a quest.", + stream + ); + case BBQRerollResult::MenuNotFound: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "Unable to open the reroll menu for quest " + std::to_string(slot + 1) + ". No BP was spent.", + stream + ); + case BBQRerollResult::NotReplaced: + //Most likely out of BP, which is not a program error. + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, + "Quest " + std::to_string(slot + 1) + " was not replaced after rerolling it. Check that there is enough BP.", + stream + ); } - - //Reroll - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_press_button(context, BUTTON_A, 160ms, 400ms); - pbf_wait(context, 800ms); - context.wait_for_all_requests(); - - press_Bs_to_back_to_overworld(info, stream, context); } //This does not handle out of BP. @@ -337,6 +411,54 @@ void reroll_all_slots( } +BBQRerollResult reroll_quest( + Logger& logger, + BBQRerollActions& actions, + std::vector& quests, + size_t slot +){ + if (!actions.open_panel()){ + return BBQRerollResult::PanelNotOpened; + } + + //The cursor is not always on the top quest when the panel opens; it can be left where it + //was. So open the menu wherever the cursor is, see which quest it opened next to, and move + //from there. Moving can drop a press, so this is tried a few times. + bool menu_on_slot = false; + for (int attempt = 0; attempt < 3 && !menu_on_slot; attempt++){ + std::optional menu_slot = actions.open_reroll_menu(); + if (!menu_slot){ + //Without a menu, B would close the panel instead, so stop here. + break; + } + if (*menu_slot == slot){ + menu_on_slot = true; + break; + } + logger.log("Reroll menu opened on quest " + std::to_string(*menu_slot + 1) + ". Moving to quest " + std::to_string(slot + 1) + "."); + actions.close_reroll_menu(); + actions.move_cursor((int)slot - (int)*menu_slot); + } + if (!menu_on_slot){ + actions.close_panel(); + return BBQRerollResult::MenuNotFound; + } + actions.confirm_reroll(); + actions.close_panel(); + + //A read can miss the quest in the slot, so read up to 3 times before deciding it is + //still the old quest. + for (int read = 0; read < 3; read++){ + std::vector after = actions.read_quests(); + if (slot < after.size() && after[slot] != quests[slot] && after[slot] != BBQuests::UnableToDetect){ + logger.log("Quest " + std::to_string(slot + 1) + " rerolled."); + quests[slot] = after[slot]; + return BBQRerollResult::Rerolled; + } + } + return BBQRerollResult::NotReplaced; +} + BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, @@ -381,7 +503,7 @@ std::vector process_quest_list( BBQuestPlan plan = plan_quests(stream.logger(), BBQ_OPTIONS, quest_list, eggs_hatched); for (size_t slot : plan.reroll_slots){ - reroll_slot(info, stream, context, slot); + reroll_slot(info, stream, context, BBQ_OPTIONS, quest_list, slot); } if (plan.reroll_all){ stream.log("No possible quests! Rerolling all quests."); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 92270cf374..25a847c154 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -7,6 +7,7 @@ #ifndef PokemonAutomation_PokemonSV_BlueberryQuests_H #define PokemonAutomation_PokemonSV_BlueberryQuests_H +#include #include #include "NintendoSwitch/Controllers/Procon/NintendoSwitch_ProController.h" #include "NintendoSwitch/NintendoSwitch_ConsoleHandle.h" @@ -82,6 +83,52 @@ BBQuestPlan plan_quests( uint8_t eggs_hatched ); +//The steps of rerolling one quest on the quest panel. They are injected so that the reroll +//(which quest it pays for, when it gives up) runs in tests without a Switch. +class BBQRerollActions{ +public: + virtual ~BBQRerollActions() = default; + + //Open the quest panel from the overworld. Returns false if it did not open. + virtual bool open_panel() = 0; + + //Press A on the quest under the cursor, which opens its reroll menu. Returns the slot of + //the quest the menu opened next to, or nothing if no menu was seen. + virtual std::optional open_reroll_menu() = 0; + + //Close the reroll menu without rerolling. + virtual void close_reroll_menu() = 0; + + //Move the cursor down this many slots, or up if negative. + virtual void move_cursor(int slots) = 0; + + //Choose to reroll in the open menu. This spends BP. + virtual void confirm_reroll() = 0; + + //Close the quest panel and return to the overworld. + virtual void close_panel() = 0; + + //Open the quest panel and read the quests on it, as read_quests() does. + virtual std::vector read_quests() = 0; +}; + +enum class BBQRerollResult{ + Rerolled, //The quest in the slot was replaced. + PanelNotOpened, //Nothing was spent. + MenuNotFound, //Nothing was spent. + NotReplaced, //The reroll was confirmed, but the slot still shows the same quest. +}; + +//Reroll the quest in `slot` of `quests`, the quests last read from the panel. Only pays once +//the reroll menu is open next to that slot, then reads the panel again to check the quest was +//replaced. On Rerolled, `quests[slot]` is updated to the new quest. +BBQRerollResult reroll_quest( + Logger& logger, + BBQRerollActions& actions, + std::vector& quests, + size_t slot +); + //Determine which quests are possible and which quests are not. (ex. no eggs, reroll egg hatcher.) //Quests not possible are removed from the list. If the list is empty, then reroll all items. std::vector process_quest_list( From a1b685f9e255bd8de34eed566a998322900da271 Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 21 Oct 2026 13:10:16 -0700 Subject: [PATCH 6/6] Let the BBQ farmer reroll or stop on a quest that fails all its retries A quest that fails all its retries is skipped while it stays on the panel. That keeps the farmer going, but the quest blocks its slot, and if every doable quest is one that failed the farmer stops. OUT_OF_RETRIES now chooses what happens: - Skip (default): as before. - Reroll: reroll the failed quest, so its slot gets a new quest. Uses reroll_quest_slot(), which checks which quest it pays for and that it was replaced. - Stop: end the program there, through the normal end of program. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonSV/Options/PokemonSV_BBQOption.cpp | 11 +++ .../PokemonSV/Options/PokemonSV_BBQOption.h | 7 ++ .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 27 ++++++++ .../Farming/PokemonSV_BBQSoloFarmer.cpp | 22 +++++- .../Farming/PokemonSV_BBQSoloFarmer.h | 7 +- .../Farming/PokemonSV_BlueberryQuests.cpp | 67 ++++++++++--------- .../Farming/PokemonSV_BlueberryQuests.h | 10 +++ 7 files changed, 116 insertions(+), 35 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp index 4067d75fa3..a15034162b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp @@ -192,6 +192,16 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option) "Number of Retries:
Reattempt a quest this many times if it fails.", LockMode::UNLOCK_WHILE_RUNNING, 1, 0, 5 ) + , OUT_OF_RETRIES( + "Out of Retries:
When a quest fails all its retries, do the selected option.", + { + {OutOfRetries::Skip, "skip", "Skip Quest - Not attempted again while it stays on the panel"}, + {OutOfRetries::Reroll, "reroll", "Reroll Quest - Costs BP"}, + {OutOfRetries::Stop, "stop", "Stop Program"}, + }, + LockMode::UNLOCK_WHILE_RUNNING, + OutOfRetries::Skip + ) , FIX_TIME_WHEN_DONE( "Fix Time when Done:
Fix the time after the program finishes.", LockMode::UNLOCK_WHILE_RUNNING, false @@ -212,6 +222,7 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option) PA_ADD_OPTION(BATTLE_AI); PA_ADD_OPTION(CATCH_ON_WIN); PA_ADD_OPTION(NUM_RETRIES); + PA_ADD_OPTION(OUT_OF_RETRIES); PA_ADD_OPTION(FIX_TIME_WHEN_DONE); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h index 48db02d5f9..c93cb83a21 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h @@ -85,6 +85,12 @@ class BBQOption : public GroupOption{ KeepGoing, }; + enum class OutOfRetries{ + Skip, + Reroll, + Stop, + }; + OCR::LanguageOCROption& LANGUAGE; SimpleIntegerOption NUM_QUESTS; @@ -109,6 +115,7 @@ class BBQOption : public GroupOption{ TeraFarmerCatchOnWin CATCH_ON_WIN; SimpleIntegerOption NUM_RETRIES; + EnumDropdownOption OUT_OF_RETRIES; BooleanCheckBoxOption FIX_TIME_WHEN_DONE; diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index 0e25fd09c3..2325d9b069 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -465,6 +465,13 @@ class SimulatedBBQGameActions : public BBQGameActions{ } return success; } + virtual void reroll_quest(BBQuests quest) override{ + events.push_back("reroll"); + auto iter = std::find(panel.begin(), panel.end(), quest); + if (iter != panel.end()){ + *iter = next_new_quest(); + } + } virtual void quest_completed() override{ events.push_back("completed"); } @@ -515,6 +522,7 @@ struct BBQRoundsScenario{ std::vector> also_completes; std::set never_completes; std::vector new_quests; + BBQOption::OutOfRetries out_of_retries = BBQOption::OutOfRetries::Skip; uint64_t expected_completed = 0; std::string expected; }; @@ -534,6 +542,7 @@ class Test_BBQFarmerRounds : public UnitTest{ options.NUM_EGGS.set(0); options.OUT_OF_EGGS.set(BBQOption::OOEggs::Stop); } + options.OUT_OF_RETRIES.set(m_scenario.out_of_retries); SimulatedBBQGameActions game; game.panel = m_scenario.panel; @@ -665,6 +674,24 @@ void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ "read process read do completed read do completed end " "read process read do completed end", }, + { + // sneak-up is rerolled to photo-polar, which round 2 attempts. + .name = "out of retries with reroll replaces the failed quest", + .num_quests = 3, + .never_completes = {BBQuests::sneak_up}, + .out_of_retries = BBQOption::OutOfRetries::Reroll, + .expected_completed = 5, + .expected = "read process read do completed read do completed read do reroll end " + round_of_3 + " end", + }, + { + .name = "out of retries with stop stops at once", + .num_quests = 3, + .panel = {BBQuests::sneak_up, BBQuests::make_tm, BBQuests::auto_10}, + .never_completes = {BBQuests::sneak_up}, + .out_of_retries = BBQOption::OutOfRetries::Stop, + .expected_completed = 0, + .expected = "read process read do", + }, }; for (const BBQRoundsScenario& scenario : scenarios){ database.add(scenario); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index ee63a9b792..d67906f0ff 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp @@ -147,7 +147,18 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga num_completed_quests++; }else{ logger.log("Quest did not complete successfully."); - failed_quests.insert(current_quest); + switch (options.OUT_OF_RETRIES){ + case BBQOption::OutOfRetries::Skip: + failed_quests.insert(current_quest); + break; + case BBQOption::OutOfRetries::Reroll: + logger.log("Reroll selected. Rerolling the failed quest."); + game.reroll_quest(current_quest); + break; + case BBQOption::OutOfRetries::Stop: + logger.log("Stop selected. Stopping program.", COLOR_RED); + return; + } } }else{ //Note: This doesn't account for case such as "sneak up" being added and then completed alongside the next quest @@ -191,6 +202,15 @@ class BBQSoloFarmerGameActions : public BBQGameActions{ virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) override{ return process_and_do_quest(m_env, m_env.console, m_context, m_options, quest, eggs_hatched); } + virtual void reroll_quest(BBQuests quest) override{ + std::vector quests = PokemonSV::read_quests(m_env.program_info(), m_env.console, m_context, m_options); + auto iter = std::find(quests.begin(), quests.end(), quest); + if (iter == quests.end()){ + m_env.log("Failed quest is no longer on the panel. Not rerolling."); + return; + } + reroll_quest_slot(m_env.program_info(), m_env.console, m_context, m_options, quests, iter - quests.begin()); + } virtual void quest_completed() override{ m_stats.questsCompleted++; m_env.update_stats(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h index 1afa74e6dc..c9c32d591c 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h @@ -43,6 +43,10 @@ class BBQGameActions{ // Increments `eggs_hatched` when the quest hatches eggs. virtual bool do_quest(BBQuests quest, uint8_t& eggs_hatched) = 0; + // Reroll a quest that failed all its attempts, if it is still on the + // panel. Spends BP. + virtual void reroll_quest(BBQuests quest) = 0; + // Progress reporting only: a quest was counted as completed. Lets stats // update after every quest instead of once per round. virtual void quest_completed() = 0; @@ -55,7 +59,8 @@ class BBQGameActions{ // Run rounds of quests until NUM_QUESTS have been completed, or until // eggs run out when OUT_OF_EGGS is Stop, or until every doable quest on the -// panel is one that already failed all its attempts. +// panel is one that already failed all its attempts, or until a quest fails +// all its attempts when OUT_OF_RETRIES is Stop. void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& game); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 59d5656a8a..2f5514dbc6 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -355,38 +355,6 @@ class ConsoleBBQRerollActions : public BBQRerollActions{ const BBQOption& m_options; }; -void reroll_slot( - const ProgramInfo& info, - VideoStream& stream, ProControllerContext& context, - const BBQOption& BBQ_OPTIONS, - std::vector& quest_list, - size_t slot -){ - ConsoleBBQRerollActions actions(info, stream, context, BBQ_OPTIONS); - switch (reroll_quest(stream.logger(), actions, quest_list, slot)){ - case BBQRerollResult::Rerolled: - return; - case BBQRerollResult::PanelNotOpened: - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "Unable to open the quest panel to reroll a quest.", - stream - ); - case BBQRerollResult::MenuNotFound: - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::SEND_ERROR_REPORT, - "Unable to open the reroll menu for quest " + std::to_string(slot + 1) + ". No BP was spent.", - stream - ); - case BBQRerollResult::NotReplaced: - //Most likely out of BP, which is not a program error. - OperationFailedExceptionWithScreenshot::fire( - ErrorReportMode::NO_ERROR_REPORT, - "Quest " + std::to_string(slot + 1) + " was not replaced after rerolling it. Check that there is enough BP.", - stream - ); - } -} //This does not handle out of BP. void reroll_all_slots( @@ -459,6 +427,39 @@ BBQRerollResult reroll_quest( return BBQRerollResult::NotReplaced; } +void reroll_quest_slot( + const ProgramInfo& info, + VideoStream& stream, ProControllerContext& context, + const BBQOption& BBQ_OPTIONS, + std::vector& quest_list, + size_t slot +){ + ConsoleBBQRerollActions actions(info, stream, context, BBQ_OPTIONS); + switch (reroll_quest(stream.logger(), actions, quest_list, slot)){ + case BBQRerollResult::Rerolled: + return; + case BBQRerollResult::PanelNotOpened: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "Unable to open the quest panel to reroll a quest.", + stream + ); + case BBQRerollResult::MenuNotFound: + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::SEND_ERROR_REPORT, + "Unable to open the reroll menu for quest " + std::to_string(slot + 1) + ". No BP was spent.", + stream + ); + case BBQRerollResult::NotReplaced: + //Most likely out of BP, which is not a program error. + OperationFailedExceptionWithScreenshot::fire( + ErrorReportMode::NO_ERROR_REPORT, + "Quest " + std::to_string(slot + 1) + " was not replaced after rerolling it. Check that there is enough BP.", + stream + ); + } +} + BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, @@ -505,7 +506,7 @@ std::vector process_quest_list( //Each reroll updates the panel the next one checks against. std::vector panel = quest_list; for (size_t slot : plan.reroll_slots){ - reroll_slot(info, stream, context, BBQ_OPTIONS, panel, slot); + reroll_quest_slot(info, stream, context, BBQ_OPTIONS, panel, slot); } if (plan.reroll_all){ stream.log("No possible quests! Rerolling all quests."); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index 5939c326e6..a7044e73fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -129,6 +129,16 @@ BBQRerollResult reroll_quest( size_t slot ); +//Reroll the quest in `slot` of `quests` on the console, with reroll_quest(). Stops the program +//if the reroll fails. +void reroll_quest_slot( + const ProgramInfo& info, + VideoStream& stream, ProControllerContext& context, + const BBQOption& BBQ_OPTIONS, + std::vector& quests, + size_t slot +); + //Determine which quests are possible and which quests are not. (ex. no eggs, reroll egg hatcher.) //Quests not possible are removed from the list. If the list is empty, then reroll all items. std::vector process_quest_list(