From 50787d3463112a7ac069b92f0cb60e9cb85722f2 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 22 Oct 2026 17:33:51 -0700 Subject: [PATCH 1/2] Run the doable BBQ quests cheapest first The round loop ran doable quests in panel order. R3 07:54 ran Make TM, then Catch any (failed), with Travel 500 m last; R3b 10:14 chose Auto Battle 10 with Travel 500 m on the board. order_quests_by_cost() sorts the quests to do by expected seconds per completion, from lab runs R3-R5: make-tm 79, travel-500 89, photo-swim 63/0.71, typed catch 137/0.75, hatch 190, sandwich 200, tera-self 153/0.59, auto-10 280. Quests without a measurement keep their places; ties keep panel order. run_bbq_rounds() orders each batch before running it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 42 ++++++++++++- .../Farming/PokemonSV_BBQSoloFarmer.cpp | 4 ++ .../Farming/PokemonSV_BlueberryQuests.cpp | 63 +++++++++++++++++++ .../Farming/PokemonSV_BlueberryQuests.h | 7 +++ 4 files changed, 115 insertions(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index 5996984886..5fcdc0a102 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -426,6 +426,8 @@ class SimulatedBBQGameActions : public BBQGameActions{ }; std::vector events; + // The quests do_quest() was called with, in order. + std::vector attempted; virtual std::vector read_quests() override{ events.push_back("read"); @@ -453,6 +455,7 @@ class SimulatedBBQGameActions : public BBQGameActions{ } virtual bool do_quest(BBQuests quest, uint8_t&) override{ events.push_back("do"); + attempted.push_back(quest); const bool success = !never_completes.contains(quest) && (m_next_outcome < outcomes.size() ? outcomes[m_next_outcome++] : true); if (success){ @@ -525,6 +528,8 @@ struct BBQRoundsScenario{ BBQOption::OutOfRetries out_of_retries = BBQOption::OutOfRetries::Skip; uint64_t expected_completed = 0; std::string expected; + // Checked when not empty. + std::vector expected_attempted; }; class Test_BBQFarmerRounds : public UnitTest{ @@ -564,6 +569,10 @@ class Test_BBQFarmerRounds : public UnitTest{ if (actual != m_scenario.expected){ return "Expected: " + m_scenario.expected + "\nActual: " + actual; } + if (!m_scenario.expected_attempted.empty() && game.attempted != m_scenario.expected_attempted){ + return "Expected attempts: " + quests_to_string(m_scenario.expected_attempted) + + "got: " + quests_to_string(game.attempted); + } return true; } @@ -586,12 +595,43 @@ void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ { // Doing photo_swim also completes travel_500, so travel_500 is // gone when the loop reads the panel before attempting it. + // make_tm runs first, as the cheapest. .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", + .expected = "read process read do completed read do completed read completed end", + .expected_attempted = {BBQuests::make_tm, BBQuests::photo_swim}, + }, + { + // Expected seconds per completion: make-tm 79, travel-500 89, + // auto-10 280. + .name = "doable quests run cheapest first", + .num_quests = 3, + .panel = {BBQuests::auto_10, BBQuests::travel_500, BBQuests::make_tm}, + .expected_completed = 3, + .expected = round_of_3 + " end", + .expected_attempted = {BBQuests::make_tm, BBQuests::travel_500, BBQuests::auto_10}, + }, + { + // photo-swim 63 s at 71% (89 s), typed catch 137 s at 75% + // (183 s), tera-self 153 s at 59% (259 s). + .name = "success rate counts in the order", + .num_quests = 3, + .panel = {BBQuests::tera_self_defeat, BBQuests::catch_fire, BBQuests::photo_swim}, + .expected_completed = 3, + .expected = round_of_3 + " end", + .expected_attempted = {BBQuests::photo_swim, BBQuests::catch_fire, BBQuests::tera_self_defeat}, + }, + { + // sneak_up has no measurement, so it stays in slot 2. + .name = "unmeasured quests keep their place", + .num_quests = 3, + .panel = {BBQuests::auto_10, BBQuests::sneak_up, BBQuests::make_tm}, + .expected_completed = 3, + .expected = round_of_3 + " end", + .expected_attempted = {BBQuests::make_tm, BBQuests::sneak_up, BBQuests::auto_10}, }, { // The first attempt fails: 3 attempts, 2 completions. diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index d67906f0ff..f593e5c8fe 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp @@ -135,6 +135,10 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga quest_list.clear(); } + //Cheap, reliable quests first: a quest done early can also finish a later one (e.g. + //travel-500 while flying to a photo target), and a failure costs less of the round. + order_quests_by_cost(logger, quests_to_do); + 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_panel(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 2f5514dbc6..e9ef48443d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -45,6 +45,7 @@ #include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h" #include "PokemonSV_BlueberryQuests.h" +#include #include namespace PokemonAutomation{ @@ -460,6 +461,68 @@ void reroll_quest_slot( } } +std::optional expected_seconds_per_success(BBQuests quest){ + switch (quest){ + case BBQuests::make_tm: return 79; + case BBQuests::travel_500: return 89; + case BBQuests::photo_swim: return 63 / 0.71; + case BBQuests::hatch_egg: return 190; + case BBQuests::tera_self_defeat: return 153 / 0.59; + case BBQuests::auto_10: return 280; + case BBQuests::sandwich_three: + case BBQuests::bitter_sandwich: + case BBQuests::sweet_sandwich: + case BBQuests::salty_sandwich: + case BBQuests::sour_sandwich: + case BBQuests::spicy_sandwich: + return 200; + case BBQuests::catch_normal: + case BBQuests::catch_fighting: + case BBQuests::catch_flying: + case BBQuests::catch_poison: + case BBQuests::catch_ground: + case BBQuests::catch_rock: + case BBQuests::catch_bug: + case BBQuests::catch_ghost: + case BBQuests::catch_steel: + case BBQuests::catch_fire: + case BBQuests::catch_water: + case BBQuests::catch_grass: + case BBQuests::catch_electric: + case BBQuests::catch_psychic: + case BBQuests::catch_ice: + case BBQuests::catch_dragon: + case BBQuests::catch_dark: + case BBQuests::catch_fairy: + return 137 / 0.75; + default: + return std::nullopt; + } +} + +void order_quests_by_cost(Logger& logger, std::vector& quests){ + //Only the measured quests move, among the places they hold. + std::vector places; + std::vector measured; + for (size_t i = 0; i < quests.size(); i++){ + if (expected_seconds_per_success(quests[i])){ + places.push_back(i); + measured.push_back(quests[i]); + } + } + std::stable_sort(measured.begin(), measured.end(), [](BBQuests a, BBQuests b){ + return *expected_seconds_per_success(a) < *expected_seconds_per_success(b); + }); + bool changed = false; + for (size_t i = 0; i < places.size(); i++){ + changed |= quests[places[i]] != measured[i]; + quests[places[i]] = measured[i]; + } + if (changed){ + logger.log("Running the quests with the lowest expected time per completion first."); + } +} + BBQuestPlan plan_quests( Logger& logger, const BBQOption& BBQ_OPTIONS, diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index a7044e73fe..cbf8d62247 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -83,6 +83,13 @@ BBQuestPlan plan_quests( uint8_t eggs_hatched ); +//Expected seconds per completed quest (time per attempt / success rate), measured in lab +//runs R3-R5, or nothing for a quest that was not measured. +std::optional expected_seconds_per_success(BBQuests quest); +//Reorder quests so the cheapest by expected_seconds_per_success() run first. Quests that +//were not measured keep their places; ties keep their order. +void order_quests_by_cost(Logger& logger, std::vector& quests); + //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{ From 1ee923bdfef527560b664aea12538f915a183cd5 Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 22 Oct 2026 21:24:35 -0700 Subject: [PATCH 2/2] BBQ tests: default-initialize scenario fields Give BBQRoundsScenario's `expected_attempted` a default member initializer (= {}), so test cases that leave them out of a designated initializer compile on the Windows Clang CI job. That job builds with clang-cl /W4 /WX, which turns on -Wmissing-designated-field-initializers: a designated initializer that omits a field without a default member initializer is an error. Apple clang's -Wextra does not enable that warning, so macOS builds miss it. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index 5fcdc0a102..2fd79ddb74 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -529,7 +529,7 @@ struct BBQRoundsScenario{ uint64_t expected_completed = 0; std::string expected; // Checked when not empty. - std::vector expected_attempted; + std::vector expected_attempted = {}; }; class Test_BBQFarmerRounds : public UnitTest{