From 6e412fc1c3ac11d06223ca1c38ed0df41d1521ee Mon Sep 17 00:00:00 2001 From: dayfine Date: Wed, 21 Oct 2026 10:51:21 -0700 Subject: [PATCH] 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 --- .../Farming/PokemonSV_BBQSoloFarmer.cpp | 45 ++++++++++- .../Farming/PokemonSV_BBQSoloFarmer.h | 3 +- .../Programs/Farming/PokemonSV_BBQTests.cpp | 75 +++++++++++++------ 3 files changed, 96 insertions(+), 27 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index e71f27ac80..891221b0d3 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); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 03433af297..9adeb555f5 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -97,6 +97,13 @@ class SimulatedBBQGameActions : public BBQGameActions{ std::set never_completes = {}; bool out_of_bp = false; size_t max_reads = 1000; + // 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; @@ -153,16 +160,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; } @@ -196,6 +196,7 @@ struct BBQRoundsScenario{ std::set never_completes = {}; bool out_of_bp = false; size_t max_reads = 1000; + std::vector new_quests = {}; uint64_t expected_completed = 0; std::string expected; }; @@ -223,6 +224,9 @@ class Test_BBQFarmerRounds : public UnitTest{ game.never_completes = m_scenario.never_completes; game.out_of_bp = m_scenario.out_of_bp; game.max_reads = m_scenario.max_reads; + if (!m_scenario.new_quests.empty()){ + game.new_quests = m_scenario.new_quests; + } NullLogger logger; try{ @@ -304,29 +308,23 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ // "today:" state the current behavior, so that each fix shows up as a // change to one of them. { - // Today: sneak-up never completes and is attempted again in every - // round it stays on the panel. - .name = "today: a failed quest is attempted every round", + // 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 read do end", + "read process read do completed read do completed end", }, { - // Today: the only doable quest never completes, so the farmer - // attempts it every round and never finishes. - .name = "today: a panel of failed quests is retried forever", + .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}, - .max_reads = 6, .expected_completed = 0, - .expected = - "read process read do end " - "read process read do end " - "read process read do end read stuck", + .expected = "read process read do end read process", }, { // Today: rerolls change nothing (out of BP), so the farmer reads @@ -350,15 +348,44 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ }, { // Today: round 1 completes nothing, but 0 is a multiple of 2, so - // it saves anyway. + // it saves anyway. Every quest failed, so the farmer then stops. .name = "today: a round without completions saves", .num_quests = 3, .save_num_quests = 2, .outcomes = {false, false, false}, - .expected_completed = 3, + .expected_completed = 0, + .expected = "read process read do read do read do end(save) 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 read do end(save) " - + round_of_3 + " end", + "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){