diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp index 46d2d349d4..715dee88a7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp @@ -205,6 +205,7 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga //Never carry an observation across quest actions or the round's date/reset work. observed_panel.reset(); const uint64_t completed_before_round = num_completed_quests; + bool replan_after_reroll = false; for (auto current_quest : quests_to_do){ //Check if quest was already completed (ex. 500 meters completed while navigating to take a photo) if (dispatch_panel){ @@ -231,6 +232,8 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga case BBQOption::OutOfRetries::Reroll: logger.log("Reroll selected. Rerolling the failed quest."); game.reroll_quest(current_quest); + logger.log("Reroll finished. Discarding the remaining batch before scheduling."); + replan_after_reroll = true; break; case BBQOption::OutOfRetries::Stop: logger.log("Stop selected. Stopping program.", COLOR_RED); @@ -244,6 +247,11 @@ void run_bbq_rounds(Logger& logger, const BBQOption& options, BBQGameActions& ga num_completed_quests++; } quest_list.clear(); + if (replan_after_reroll){ + //A replacement belongs in the next plan, before more old queued + //work. Finish normal round actions so save milestones are kept. + break; + } } //Clear out the todo list quests_to_do.clear(); diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 8e2f258bbe..f510f1300f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -164,6 +164,7 @@ class SimulatedBBQGameActions : public BBQGameActions{ bool reuse_rerolled_panel = false; std::vector events; + std::vector attempted_quests; virtual std::vector read_quests() override{ events.push_back("read"); @@ -192,6 +193,7 @@ class SimulatedBBQGameActions : public BBQGameActions{ } virtual bool do_quest(BBQuests quest, uint8_t&) override{ events.push_back("do"); + attempted_quests.push_back(quest); const bool success = !never_completes.contains(quest) && (m_next_outcome < outcomes.size() ? outcomes[m_next_outcome++] : true); if (success){ @@ -267,6 +269,7 @@ struct BBQRoundsScenario{ BBQOption::OutOfRetries out_of_retries = BBQOption::OutOfRetries::Skip; bool reuse_rerolled_panel = false; uint64_t expected_completed = 0; + std::vector expected_attempted = {}; std::string expected; }; @@ -318,6 +321,18 @@ class Test_BBQFarmerRounds : public UnitTest{ return "Expected " + std::to_string(m_scenario.expected_completed) + " completed quests, counted " + std::to_string(completed); } + if (!m_scenario.expected_attempted.empty() && game.attempted_quests != m_scenario.expected_attempted){ + std::vector expected_quests; + std::vector actual_quests; + for (BBQuests quest : m_scenario.expected_attempted){ + expected_quests.push_back(std::to_string((int)quest)); + } + for (BBQuests quest : game.attempted_quests){ + actual_quests.push_back(std::to_string((int)quest)); + } + return "Expected quest order: " + join_events(expected_quests) + + "\nActual quest order: " + join_events(actual_quests); + } const std::string actual = join_events(game.events); if (actual != m_scenario.expected){ return "Expected: " + m_scenario.expected + "\nActual: " + actual; @@ -349,6 +364,41 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ std::vector> all_skipped_but_make_tm = every_doable_blue_quest(BBQAction::skip); all_skipped_but_make_tm.emplace_back(BBQuests::make_tm, BBQAction::run); const BBQRoundsScenario scenarios[] = { + { + .name = "failed reroll replans before queued photo and TM", + .num_quests = 1, + .panel = {BBQuests::catch_grass, BBQuests::photo_savanna, BBQuests::make_tm}, + .outcomes = {false}, + .new_quests = {BBQuests::travel_500, BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar}, + .out_of_retries = BBQOption::OutOfRetries::Reroll, + .expected_completed = 3, + .expected_attempted = {BBQuests::catch_grass, BBQuests::travel_500, BBQuests::photo_savanna, BBQuests::make_tm}, + .expected = "read process read do reroll end " + round_of_3 + " end", + }, + { + .name = "failed reroll on full board reads fresh after round actions", + .num_quests = 1, + .panel = {BBQuests::catch_grass, BBQuests::photo_savanna, BBQuests::make_tm, BBQuests::wash_pokemon}, + .outcomes = {false}, + .new_quests = {BBQuests::travel_500, BBQuests::photo_canyon, BBQuests::photo_coastal, BBQuests::photo_polar}, + .out_of_retries = BBQOption::OutOfRetries::Reroll, + .reuse_rerolled_panel = true, + .expected_completed = 4, + .expected_attempted = {BBQuests::catch_grass, BBQuests::travel_500, BBQuests::photo_savanna, BBQuests::make_tm, BBQuests::wash_pokemon}, + .expected = "read process read do reroll end " + round_of_3 + " read do completed end", + }, + { + .name = "replanning after failure preserves a crossed save milestone", + .num_quests = 2, + .save_num_quests = 1, + .panel = {BBQuests::make_tm, BBQuests::catch_grass, BBQuests::photo_savanna}, + .outcomes = {true, false}, + .new_quests = {BBQuests::photo_canyon, BBQuests::travel_500, BBQuests::photo_coastal, BBQuests::photo_polar}, + .out_of_retries = BBQOption::OutOfRetries::Reroll, + .expected_completed = 4, + .expected_attempted = {BBQuests::make_tm, BBQuests::catch_grass, BBQuests::photo_canyon, BBQuests::travel_500, BBQuests::photo_savanna}, + .expected = "read process read do completed read do reroll end(save) " + round_of_3 + " end(save)", + }, { .name = "reuses reroll observation for selection and first dispatch only", .num_quests = 1, @@ -454,17 +504,17 @@ static void add_tests_BBQFarmerRounds(UnitTestDatabase& database){ .expected = round_of_3 + " end(save) " + round_of_3 + " end(save)", }, { - // Round 1 completes nothing. It must not save, even though the - // count (0) is a multiple of the interval. - // Every quest fails and is rerolled, so round 1 completes - // nothing and doesn't save; round 2 reaches the milestone. + // Three partial rounds each fail and reroll their first quest. + // None may save while the completed count is still zero. .name = "round without completions does not save", .num_quests = 3, .save_num_quests = 2, .outcomes = {false, false, false}, .out_of_retries = BBQOption::OutOfRetries::Reroll, .expected_completed = 3, - .expected = "read process read do reroll read do reroll read do reroll end " + round_of_3 + " end(save)", + .expected = + "read process read do reroll end read process read do reroll end " + "read process read do reroll end " + round_of_3 + " end(save)", }, { // sneak-up fails, then leaves the panel along with make-tm. Round 2