diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 0ddc6e731d..83bd64f7da 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -162,6 +162,9 @@ class ScriptedAutoBattle : public BBQAutoBattleActions{ std::vector kills_per_clear; // The lead's HP read in each clear, in turn. Past the end, it is unknown. std::vector> hp_per_clear; + // Kills heard on each flight back, in turn: the lead finishing a kill + // after the clear ends. Past the end, none. + std::vector kills_per_return; std::vector steps; int seconds = 0; @@ -192,6 +195,10 @@ class ScriptedAutoBattle : public BBQAutoBattleActions{ virtual void return_to_plaza() override{ steps.push_back("return"); seconds += RETURN_SECONDS; + if (m_returns < kills_per_return.size()){ + m_kills += kills_per_return[m_returns]; + } + m_returns++; } virtual void heal() override{ steps.push_back("heal"); @@ -201,6 +208,7 @@ class ScriptedAutoBattle : public BBQAutoBattleActions{ private: uint64_t m_kills = 0; size_t m_clears = 0; + size_t m_returns = 0; }; // One pass as it shows in the expected steps. @@ -228,6 +236,7 @@ struct BBQAutoBattleScenario{ int time_limit_minutes = 35; std::vector kills_per_clear; std::vector> hp_per_clear = {}; // Unknown when not given. + std::vector kills_per_return = {}; // None when not given. int heal_below_hp_percent = 50; BBQAutoBattleResult expected_result = BBQAutoBattleResult::TargetReached; std::string expected_steps; @@ -246,6 +255,7 @@ class Test_BBQAutoBattle : public UnitTest{ ScriptedAutoBattle actions; actions.kills_per_clear = m_scenario.kills_per_clear; actions.hp_per_clear = m_scenario.hp_per_clear; + actions.kills_per_return = m_scenario.kills_per_return; RecordingLogger logger; BBQAutoBattlePolicy policy; @@ -450,6 +460,43 @@ static void add_tests_BBQAutoBattle(UnitTestDatabase& database){ .expected_steps = passes(3, LAST_PASS), .expected_seconds = 3 * (PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS), }, + { + // R3b: "pass 2: 1 kills, 4/10 in total" after "2/10". A kill heard after a pass's + // line counts in the next one, so the passes add up to the total. + .name = "a kill heard on the way back counts in the next pass", + .kills_per_clear = {2, 1, 3, 4}, + .kills_per_return = {1}, + .expected_steps = passes(3) + " " + LAST_PASS, + .expected_seconds = 4 * PASS_SECONDS - LAST_PASS_SAVED_SECONDS, + .expected_log = { + "Auto Battle pass 1: 2 kills, 2/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.", + "Auto Battle pass 2: 2 kills, 4/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.", + "Auto Battle pass 3: 3 kills, 7/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.", + "Auto Battle pass 4: 4 kills, 11/10 in total, HP ?, 346 s elapsed. Target reached: return without healing.", + }, + }, + { + // A pass whose only kill was heard on the previous flight back is not empty. + .name = "a kill heard on the way back resets the empty passes", + .kills_per_clear = {0, 0, 0, 0, 0, 0}, + .kills_per_return = {0, 1}, + .expected_result = BBQAutoBattleResult::NoKills, + .expected_steps = passes(5) + " " + LAST_PASS, + .expected_seconds = 6 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS, + }, + { + .name = "a kill heard on the way back that reaches the target skips the heal", + .kills_per_clear = {3, 3, 3}, + .kills_per_return = {0, 0, 1}, + .expected_steps = passes(2) + " " + LAST_PASS, + .expected_seconds = 3 * PASS_SECONDS - ScriptedAutoBattle::HEAL_SECONDS, + .expected_log = { + "Auto Battle pass 1: 3 kills, 3/10 in total, HP ?, 46 s elapsed. Below the target and HP unknown: return, heal and go again.", + "Auto Battle pass 2: 3 kills, 6/10 in total, HP ?, 148 s elapsed. Below the target and HP unknown: return, heal and go again.", + "Auto Battle pass 3: 3 kills, 9/10 in total, HP ?, 250 s elapsed. Below the target and HP unknown: return, heal and go again.", + "Auto Battle: kills heard on the way back reached the target, 10/10. Stop without healing.", + }, + }, }; for (const BBQAutoBattleScenario& scenario : scenarios){ database.add(scenario); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 6fc50a5687..84fb0ad327 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -1255,9 +1255,12 @@ BBQAutoBattleResult run_auto_battle( const WallClock start = actions.now(); uint64_t pass = 0; uint64_t empty_passes = 0; + //The kill sound is heard in every step, not only while clearing: the lead can finish a kill + //after the clear ends, as the flight back starts. Each pass counts the kills since the last + //pass log, so a kill heard after it goes to the next pass and the passes add up to the total. + uint64_t kills_before = actions.kills(); while (actions.kills() < policy.kill_target){ pass++; - const uint64_t kills_before = actions.kills(); actions.fly_to_battle_area(); const std::optional hp = actions.clear(policy.kill_target); @@ -1299,12 +1302,21 @@ BBQAutoBattleResult run_auto_battle( + std::to_string(elapsed.count()) + " s elapsed. " + next ); + kills_before = kills; //The next quest starts from Central Plaza, so return even when done. actions.return_to_plaza(); if (end){ return *end; } + if (actions.kills() >= policy.kill_target){ + logger.log( + "Auto Battle: kills heard on the way back reached the target, " + + std::to_string(actions.kills()) + "/" + std::to_string(policy.kill_target) + + ". Stop without healing." + ); + return BBQAutoBattleResult::TargetReached; + } //Skipping the heal also skips its re-fly: return_to_plaza() already lands on the Central //Plaza fly point, which is where the flight to Chargestone starts from. if (heal){