From a536fda46864a9adf51ef77a14cae15352adab4d Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 27 Oct 2026 23:47:15 -0700 Subject: [PATCH] BBQ: give up an Auto Battle quest after 3 empty passes or a time limit run_auto_battle() had no bound: if kills stopped registering (wrong lead, no spawns, no audio) it never returned, and the farmer's retry handling could not step in. It now stops after 3 passes in a row with no kill, or after the pass that ends past the time limit (35 minutes for Auto Battle 10, 60 for Auto Battle 30, about 3x the slowest attempts seen). It returns to Central Plaza without healing, logs which limit ended it, and leaves the outcome to the board check. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Programs/Farming/PokemonSV_BBQTests.cpp | 73 +++++++++++++++---- .../Farming/PokemonSV_BlueberryQuests.cpp | 11 +++ .../Farming/PokemonSV_BlueberryQuests.h | 8 ++ 3 files changed, 78 insertions(+), 14 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 197bd57cb6..3cb0254e9b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -154,11 +154,21 @@ std::string passes(int count){ return join(ret, " "); } +std::string auto_battle_result_to_string(BBQAutoBattleResult result){ + switch (result){ + case BBQAutoBattleResult::TargetReached: return "TargetReached"; + case BBQAutoBattleResult::NoKills: return "NoKills"; + case BBQAutoBattleResult::TimeLimit: return "TimeLimit"; + } + return "?"; +} + struct BBQAutoBattleScenario{ std::string name; uint64_t kill_target = 10; + int time_limit_minutes = 35; std::vector kills_per_clear; - bool expected_endless = false; // Runs past the script without stopping. + BBQAutoBattleResult expected_result = BBQAutoBattleResult::TargetReached; std::string expected_steps; int expected_seconds = 0; std::vector expected_log = {}; // Checked when not empty. @@ -178,16 +188,16 @@ class Test_BBQAutoBattle : public UnitTest{ RecordingLogger logger; BBQAutoBattlePolicy policy; policy.kill_target = m_scenario.kill_target; - bool endless = false; + policy.time_limit = std::chrono::minutes(m_scenario.time_limit_minutes); + BBQAutoBattleResult result; try{ - run_auto_battle(logger, actions, policy); + result = run_auto_battle(logger, actions, policy); }catch (const std::runtime_error&){ - endless = true; + return "Expected the loop to stop, but it cleared more often than scripted."; } - if (endless != m_scenario.expected_endless){ - return endless - ? "Expected the loop to stop, but it cleared more often than scripted." - : "Expected the loop to run past the script, but it stopped."; + if (result != m_scenario.expected_result){ + return "Expected " + auto_battle_result_to_string(m_scenario.expected_result) + + ", got " + auto_battle_result_to_string(result); } const std::string steps = join(actions.steps, " "); if (steps != m_scenario.expected_steps){ @@ -250,12 +260,47 @@ static void add_tests_BBQAutoBattle(UnitTestDatabase& database){ .expected_seconds = 5 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS, }, { - // Nothing bounds the loop: with no kills it never ends. - .name = "no kills never stops", - .kills_per_clear = {0, 0, 0, 0, 0, 0}, - .expected_endless = true, - .expected_steps = passes(6) + " fly", - .expected_seconds = 6 * PASS_SECONDS + ScriptedAutoBattle::FLY_SECONDS, + .name = "gives up after 3 passes with no kill", + .kills_per_clear = {0, 0, 0}, + .expected_result = BBQAutoBattleResult::NoKills, + .expected_steps = passes(2) + " " + LAST_PASS, + .expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS, + .expected_log = { + "Auto Battle pass 1: 0 kills, 0/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.", + "Auto Battle pass 2: 0 kills, 0/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.", + "Auto Battle pass 3: 0 kills, 0/10 in total, HP ?, 250 s elapsed. No kill in 3 passes in a row: return and give up.", + }, + }, + { + // Only passes in a row count. + .name = "a kill resets the empty passes", + .kills_per_clear = {0, 0, 1, 0, 0, 0}, + .expected_result = BBQAutoBattleResult::NoKills, + .expected_steps = passes(5) + " " + LAST_PASS, + .expected_seconds = 6 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS, + }, + { + // The pass that ends past the limit is the last. + .name = "gives up at the time limit", + .time_limit_minutes = 5, + .kills_per_clear = {1, 1, 1, 1}, + .expected_result = BBQAutoBattleResult::TimeLimit, + .expected_steps = passes(3) + " " + LAST_PASS, + .expected_seconds = 4 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS, + .expected_log = { + "Auto Battle pass 1: 1 kills, 1/10 in total, HP ?, 46 s elapsed. Below the target: return, heal and go again.", + "Auto Battle pass 2: 1 kills, 2/10 in total, HP ?, 148 s elapsed. Below the target: return, heal and go again.", + "Auto Battle pass 3: 1 kills, 3/10 in total, HP ?, 250 s elapsed. Below the target: return, heal and go again.", + "Auto Battle pass 4: 1 kills, 4/10 in total, HP ?, 352 s elapsed. Time limit of 5 min reached: return and give up.", + }, + }, + { + // Reaching the target counts as reached, even past the time limit. + .name = "target reached past the time limit", + .time_limit_minutes = 5, + .kills_per_clear = {3, 3, 3, 3}, + .expected_steps = passes(3) + " " + LAST_PASS, + .expected_seconds = 4 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS, }, }; for (const BBQAutoBattleScenario& scenario : scenarios){ diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 62d0fd2de5..42d7f27044 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -1258,6 +1258,7 @@ BBQAutoBattleResult run_auto_battle( ){ const WallClock start = actions.now(); uint64_t pass = 0; + uint64_t empty_passes = 0; while (actions.kills() < policy.kill_target){ pass++; const uint64_t kills_before = actions.kills(); @@ -1266,6 +1267,7 @@ BBQAutoBattleResult run_auto_battle( const std::optional hp = actions.clear(policy.kill_target); const uint64_t kills = actions.kills(); + empty_passes = kills == kills_before ? empty_passes + 1 : 0; const auto elapsed = std::chrono::duration_cast(actions.now() - start); const std::string hp_text = hp ? std::to_string((int)std::floor(*hp * 100)) + "%" : "?"; @@ -1274,6 +1276,12 @@ BBQAutoBattleResult run_auto_battle( if (kills >= policy.kill_target){ end = BBQAutoBattleResult::TargetReached; next = "Target reached: return without healing."; + }else if (empty_passes >= policy.max_empty_passes){ + end = BBQAutoBattleResult::NoKills; + next = "No kill in " + std::to_string(empty_passes) + " passes in a row: return and give up."; + }else if (elapsed >= policy.time_limit){ + end = BBQAutoBattleResult::TimeLimit; + next = "Time limit of " + std::to_string(policy.time_limit.count()) + " min reached: return and give up."; } logger.log( "Auto Battle pass " + std::to_string(pass) + ": " @@ -1406,11 +1414,14 @@ void quest_auto_battle( sensors.lets_go_kill ); + //The time limits are about 3x the slowest attempts seen with a correct lead. BBQAutoBattlePolicy policy; policy.kill_target = 10; + policy.time_limit = std::chrono::minutes(35); if (current_quest == BBQuests::auto_30){ policy.kill_target = 30; + policy.time_limit = std::chrono::minutes(60); } ConsoleBBQAutoBattleActions actions(env, stream, context, stats, tracker, sensors.lets_go_hp); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h index d643fa3ce3..6cad2bd92b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.h @@ -192,16 +192,24 @@ class BBQAutoBattleActions{ struct BBQAutoBattlePolicy{ uint64_t kill_target = 10; + //Give up after this many passes in a row with no kill. + uint64_t max_empty_passes = 3; + //Give up after the pass that ends past this time. + std::chrono::minutes time_limit = std::chrono::minutes(35); }; //Why run_auto_battle() returned. enum class BBQAutoBattleResult{ TargetReached, + NoKills, //max_empty_passes passes in a row had no kill. + TimeLimit, }; //Clear Chargestone Cavern, one pass at a time, until the kills reach the target, and return why //it stopped. It ends at Central Plaza, where the next quest starts. Logs one line per pass: its //kills, the total, the lead's HP, the time spent, and what happens next. +//It gives up early when a limit in `policy` is reached; the board check then decides the quest +//failed. BBQAutoBattleResult run_auto_battle( Logger& logger, BBQAutoBattleActions& actions,