From 037549e0079f345fa6a8497b826c94c41b46dbf7 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 27 Oct 2026 12:09:24 -0700 Subject: [PATCH] Pin the ways the BBQ farmer's round loop gets stuck today The round loop has several ways to stop making progress or lose time, and the PRs that fix them each change its behavior. Without a test of the current behavior, a reviewer has to infer from the code what each fix changes. Add BBQFarmerRounds scenarios that state what the loop does today: a failed quest is attempted again every round; a panel whose only doable quest keeps failing is retried forever; rerolls that change nothing (out of BP) repeat forever; a round that skips past a save milestone does not save; and a round with no completions saves because 0 is a multiple of the interval. Each fix then shows up as a change to one of these expectations. The simulated panel gains quests that never complete, an out-of-BP mode where rerolls do nothing, and a read limit per scenario; a run that exceeds it is recorded as "stuck". Test-only; no behavior change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/Farming/PokemonSV_BBQTests.cpp | 88 ++++++++++++++++++- 1 file changed, 84 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 68798b9a7a..716bc8a158 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "PokemonSV_BlueberryQuests.h" #include "PokemonSV_BBQSoloFarmer.h" @@ -81,6 +82,9 @@ class NullLogger : public Logger{ // 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. +// With out_of_bp, rerolls do nothing, as in the game when BP runs out. +// A run that reads the panel more than max_reads times is stuck: the read +// throws, and the test records "stuck". class SimulatedBBQGameActions : public BBQGameActions{ public: std::vector panel; @@ -89,12 +93,16 @@ 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 = {}; + bool out_of_bp = false; + size_t max_reads = 1000; std::vector events; virtual std::vector read_quests() override{ events.push_back("read"); - if (++m_reads > 1000){ + if (++m_reads > max_reads){ throw std::runtime_error("Too many quest panel reads."); } return panel; @@ -109,7 +117,7 @@ class SimulatedBBQGameActions : public BBQGameActions{ doable.push_back(quest); } } - if (doable.empty()){ + if (doable.empty() && !out_of_bp){ for (BBQuests& slot : panel){ slot = next_new_quest(); } @@ -118,7 +126,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){ @@ -184,6 +193,9 @@ 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 = {}; + bool out_of_bp = false; + size_t max_reads = 1000; uint64_t expected_completed = 0; std::string expected; }; @@ -208,9 +220,16 @@ 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; + game.out_of_bp = m_scenario.out_of_bp; + game.max_reads = m_scenario.max_reads; NullLogger logger; - run_bbq_rounds(logger, options, game); + try{ + run_bbq_rounds(logger, options, game); + }catch (std::runtime_error&){ + game.events.push_back("stuck"); + } 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) @@ -280,6 +299,67 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ .expected_completed = 0, .expected = "", }, + + // The ways the loop gets stuck or loses time. Scenarios named + // "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", + .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", + }, + { + // 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", + .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", + }, + { + // Today: rerolls change nothing (out of BP), so the farmer reads + // and rerolls the panel forever. + .name = "today: rerolls that do not help repeat forever", + .num_quests = 3, + .panel = {BBQuests::pickup_10, BBQuests::catch_flying, BBQuests::UnableToDetect}, + .out_of_bp = true, + .max_reads = 4, + .expected_completed = 0, + .expected = "read process read process read process read process read stuck", + }, + { + // Today: the save check only looks for exact multiples, so going + // from 0 to 3 skips the milestone at 2 without saving. + .name = "today: a round that skips past a milestone does not save", + .num_quests = 6, + .save_num_quests = 2, + .expected_completed = 6, + .expected = round_of_3 + " end " + round_of_3 + " end(save)", + }, + { + // Today: round 1 completes nothing, but 0 is a multiple of 2, so + // it saves anyway. + .name = "today: a round without completions saves", + .num_quests = 3, + .save_num_quests = 2, + .outcomes = {false, false, false}, + .expected_completed = 3, + .expected = + "read process read do read do read do end(save) " + + round_of_3 + " end", + }, }; for (const BBQRoundsScenario& scenario : scenarios){ database.add(scenario);