From 2779423d94539cf2674b7aafe0a4ed733e4201cd Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 26 Oct 2026 22:51:24 -0700 Subject: [PATCH 1/2] PokemonSV: move the BBQ farmer's tests into their own file PokemonSV_Tests.cpp registers every SV test, and each BBQ change adds its controller tests there, so parallel BBQ changes all conflict in it. Move the Tera encounter tests unchanged into Programs/Farming/PokemonSV_BBQTests.cpp, registered through one add_tests_BBQ() call, following the add_tests_() pattern the detectors use. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSV/PokemonSV_Tests.cpp | 56 +------------- .../Programs/Farming/PokemonSV_BBQTests.cpp | 77 +++++++++++++++++++ .../Programs/Farming/PokemonSV_BBQTests.h | 26 +++++++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 4 files changed, 107 insertions(+), 54 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp index 7788036545..eeb891a1cb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/PokemonSV_Tests.cpp @@ -26,7 +26,7 @@ #include "Inference/Picnics/PokemonSV_SandwichRecipeDetector.h" #include "Inference/Picnics/PokemonSV_SandwichHandDetector.h" #include "Options/PokemonSV_BBQuests.h" -#include "Programs/Farming/PokemonSV_BlueberryQuests.h" +#include "Programs/Farming/PokemonSV_BBQTests.h" #include "PokemonSV_Tests.h" namespace PokemonAutomation{ @@ -35,58 +35,6 @@ namespace PokemonSV{ namespace{ -struct TeraEncounterScenario{ - std::string name; - bool shiny = false; - int encounter_watcher_result; // 0: battle menu, 1: audio, -1: route finished first - bool battle_menu_detected = false; // The route's own wait saw the battle menu. - TeraEncounterAction expected; -}; - -class Test_TeraEncounterAction : public UnitTest{ -public: - Test_TeraEncounterAction(TeraEncounterScenario scenario) - : UnitTest("PokemonSV::TeraEncounterAction - " + scenario.name) - , m_scenario(std::move(scenario)) - {} - - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const TeraEncounterAction actual = tera_encounter_action( - m_scenario.shiny, m_scenario.encounter_watcher_result, m_scenario.battle_menu_detected - ); - if (actual != m_scenario.expected){ - return "Expected action " + std::to_string((int)m_scenario.expected) - + ", got " + std::to_string((int)actual) + "."; - } - return true; - } - -private: - const TeraEncounterScenario m_scenario; -}; - -} - -void add_tests_TeraEncounterAction(UnitTestDatabase& database){ - using enum TeraEncounterAction; - const std::vector scenarios{ - {.name = "timeout recovers without battle", .encounter_watcher_result = -1, .expected = Recover}, - {.name = "audio alone is not entry", .encounter_watcher_result = 1, .expected = Recover}, - {.name = "unknown callback is not entry", .encounter_watcher_result = 2, .expected = Recover}, - {.name = "encounter watcher menu battles", .encounter_watcher_result = 0, .expected = Battle}, - {.name = "route wait menu battles", .encounter_watcher_result = -1, .battle_menu_detected = true, .expected = Battle}, - {.name = "audio then route wait menu battles", .encounter_watcher_result = 1, .battle_menu_detected = true, .expected = Battle}, - {.name = "both menus battle", .encounter_watcher_result = 0, .battle_menu_detected = true, .expected = Battle}, - {.name = "shiny stops without entry", .shiny = true, .encounter_watcher_result = -1, .expected = StopForShiny}, - {.name = "shiny stops before battle", .shiny = true, .encounter_watcher_result = 0, .battle_menu_detected = true, .expected = StopForShiny}, - }; - for (const TeraEncounterScenario& scenario : scenarios){ - database.add(scenario); - } -} - -namespace{ - class Test_BBQuestsSlugs : public UnitTest{ public: Test_BBQuestsSlugs() @@ -138,7 +86,7 @@ void add_tests(UnitTestDatabase& database){ add_tests_TeraTypeReader(database); add_tests_NormalBattleMenus(database); add_tests_LetsGoKillDetector(database); - add_tests_TeraEncounterAction(database); + add_tests_BBQ(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp new file mode 100644 index 0000000000..999661c313 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp @@ -0,0 +1,77 @@ +/* Pokemon SV BBQ Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonSV_BlueberryQuests.h" +#include "PokemonSV_BBQTests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + +namespace{ + +struct TeraEncounterScenario{ + std::string name; + bool shiny = false; + int encounter_watcher_result; // 0: battle menu, 1: audio, -1: route finished first + bool battle_menu_detected = false; // The route's own wait saw the battle menu. + TeraEncounterAction expected; +}; + +class Test_TeraEncounterAction : public UnitTest{ +public: + Test_TeraEncounterAction(TeraEncounterScenario scenario) + : UnitTest("PokemonSV::TeraEncounterAction - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const TeraEncounterAction actual = tera_encounter_action( + m_scenario.shiny, m_scenario.encounter_watcher_result, m_scenario.battle_menu_detected + ); + if (actual != m_scenario.expected){ + return "Expected action " + std::to_string((int)m_scenario.expected) + + ", got " + std::to_string((int)actual) + "."; + } + return true; + } + +private: + const TeraEncounterScenario m_scenario; +}; + +} + +static void add_tests_TeraEncounterAction(UnitTestDatabase& database){ + using enum TeraEncounterAction; + const std::vector scenarios{ + {.name = "timeout recovers without battle", .encounter_watcher_result = -1, .expected = Recover}, + {.name = "audio alone is not entry", .encounter_watcher_result = 1, .expected = Recover}, + {.name = "unknown callback is not entry", .encounter_watcher_result = 2, .expected = Recover}, + {.name = "encounter watcher menu battles", .encounter_watcher_result = 0, .expected = Battle}, + {.name = "route wait menu battles", .encounter_watcher_result = -1, .battle_menu_detected = true, .expected = Battle}, + {.name = "audio then route wait menu battles", .encounter_watcher_result = 1, .battle_menu_detected = true, .expected = Battle}, + {.name = "both menus battle", .encounter_watcher_result = 0, .battle_menu_detected = true, .expected = Battle}, + {.name = "shiny stops without entry", .shiny = true, .encounter_watcher_result = -1, .expected = StopForShiny}, + {.name = "shiny stops before battle", .shiny = true, .encounter_watcher_result = 0, .battle_menu_detected = true, .expected = StopForShiny}, + }; + for (const TeraEncounterScenario& scenario : scenarios){ + database.add(scenario); + } +} + + +void add_tests_BBQ(UnitTestDatabase& database){ + add_tests_TeraEncounterAction(database); +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.h new file mode 100644 index 0000000000..64317f45aa --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.h @@ -0,0 +1,26 @@ +/* Pokemon SV BBQ Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonSV_BBQTests_H +#define PokemonAutomation_PokemonSV_BBQTests_H + +#include "Common/Cpp/TestRunners/UnitTest.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + + +// Blueberry Quest farmer tests: controller decisions run against scripted inputs. +void add_tests_BBQ(UnitTestDatabase& database); + + + +} +} +} +#endif diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 39c48d531e..ce54742834 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2597,6 +2597,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp From 6d374677147be3072a0121a61ec20e7546590e0a Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 22 Oct 2026 03:01:08 -0700 Subject: [PATCH 2/2] BBQ: log and capture each attempt to reach a catch, Sneak Up or photo target Catch Any and Sneak Up spent 48% of an hour failing to find a target, and the log only says "Did not enter battle. Did target spawn?". Record each attempt so a run can tell a missing target from a missed arrival or a missed detection: - log a checkpoint after lock-on / before the shutter, and on a timeout, then the attempt's outcome from what the detectors reported; - with the new "Save Target Diagnostics" option (off by default), save the checkpoint frames, and the stream history on a possible miss, under DebugDumps/BBQ/targets/, after the attempt ends. No controller command, wait or decision changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../PokemonSV/Options/PokemonSV_BBQOption.cpp | 7 + .../PokemonSV/Options/PokemonSV_BBQOption.h | 2 + .../PokemonSV_BBQTargetDiagnostics.cpp | 160 ++++++++++++++++++ .../Farming/PokemonSV_BBQTargetDiagnostics.h | 99 +++++++++++ .../Programs/Farming/PokemonSV_BBQTests.cpp | 131 ++++++++++++++ .../Farming/PokemonSV_BlueberryCatchPhoto.cpp | 21 +++ .../Farming/PokemonSV_BlueberryQuests.cpp | 11 ++ SerialPrograms/cmake/SourceFiles.cmake | 2 + 8 files changed, 433 insertions(+) create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.h diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp index 57986e80d2..5720fac758 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.cpp @@ -194,6 +194,12 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option) "Fix Time when Done:
Fix the time after the program finishes.", LockMode::UNLOCK_WHILE_RUNNING, false ) + , SAVE_TARGET_DIAGNOSTICS( + "Save Target Diagnostics:
For catch, Sneak Up and photo quests, save a frame at each step of reaching the target to DebugDumps/BBQ/targets/. " + "When the target may not have been reached, also save the stream history there, if it is enabled in the global settings. " + "For finding out why these quests fail. The log records each attempt either way.", + LockMode::UNLOCK_WHILE_RUNNING, false + ) { if (m_language_owner){ PA_ADD_OPTION(LANGUAGE); @@ -211,6 +217,7 @@ BBQOption::BBQOption(OCR::LanguageOCROption* language_option) PA_ADD_OPTION(CATCH_ON_WIN); PA_ADD_OPTION(NUM_RETRIES); PA_ADD_OPTION(FIX_TIME_WHEN_DONE); + PA_ADD_OPTION(SAVE_TARGET_DIAGNOSTICS); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h index f5715a10c7..c1eaabb1bb 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h @@ -101,6 +101,8 @@ class BBQOption : public GroupOption{ BooleanCheckBoxOption FIX_TIME_WHEN_DONE; + BooleanCheckBoxOption SAVE_TARGET_DIAGNOSTICS; + private: BBQOption(OCR::LanguageOCROption* language_option); }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.cpp new file mode 100644 index 0000000000..4f65662b8d --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.cpp @@ -0,0 +1,160 @@ +/* BBQ Target Diagnostics + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/PrettyPrint.h" +#include "Common/Cpp/Filesystem/Filesystem.h" +#include "CommonFramework/GlobalAutoPaths.h" +#include "PokemonSV_BBQTargetDiagnostics.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + +namespace{ + +std::string quest_slug(BBQuests quest){ + const EnumEntry* entry = BBQuests_database().find(quest); + return entry == nullptr ? "unknown" : entry->slug; +} + +std::string seconds_to_string(std::chrono::milliseconds elapsed){ + std::ostringstream out; + out << std::fixed << std::setprecision(1) << elapsed.count() / 1000.0 << "s"; + return out.str(); +} + +std::string target_diagnostics_directory(){ + return DEBUG_PATH() + "BBQ/targets/"; +} + +} + + +TargetAttemptOutcome classify_target_attempt(const TargetAttemptSignals& signals){ + switch (signals.kind){ + case TargetAttemptKind::battle: + if (signals.encounter_detected){ + return TargetAttemptOutcome::battle_entered; + } + return signals.battle_menu_seen + ? TargetAttemptOutcome::battle_menu_without_encounter + : TargetAttemptOutcome::no_battle; + case TargetAttemptKind::photo: + if (signals.encounter_detected){ + return TargetAttemptOutcome::battle_during_photo; + } + return signals.photo_prompt_seen + ? TargetAttemptOutcome::photo_prompt_seen + : TargetAttemptOutcome::photo_prompt_timeout; + } + return TargetAttemptOutcome::no_battle; +} + +const char* target_attempt_outcome_to_string(TargetAttemptOutcome outcome){ + switch (outcome){ + case TargetAttemptOutcome::battle_entered: return "battle-entered"; + case TargetAttemptOutcome::no_battle: return "no-battle"; + case TargetAttemptOutcome::battle_menu_without_encounter: return "battle-menu-without-encounter"; + case TargetAttemptOutcome::photo_prompt_seen: return "photo-prompt-seen"; + case TargetAttemptOutcome::photo_prompt_timeout: return "photo-prompt-timeout"; + case TargetAttemptOutcome::battle_during_photo: return "battle-during-photo"; + } + return "unknown"; +} + +bool target_attempt_needs_history(TargetAttemptOutcome outcome){ + switch (outcome){ + case TargetAttemptOutcome::battle_entered: + case TargetAttemptOutcome::photo_prompt_seen: + return false; + case TargetAttemptOutcome::no_battle: + case TargetAttemptOutcome::battle_menu_without_encounter: + case TargetAttemptOutcome::photo_prompt_timeout: + case TargetAttemptOutcome::battle_during_photo: + return true; + } + return true; +} + +std::string target_attempt_summary( + BBQuests quest, + const TargetAttemptSignals& signals, + std::chrono::milliseconds elapsed +){ + std::ostringstream out; + out << "BBQ event=target-attempt quest=" << quest_slug(quest) + << " outcome=" << target_attempt_outcome_to_string(classify_target_attempt(signals)) + << " encounter=" << signals.encounter_detected; + switch (signals.kind){ + case TargetAttemptKind::battle: + out << " battle_menu=" << signals.battle_menu_seen; + break; + case TargetAttemptKind::photo: + out << " photo_prompt=" << signals.photo_prompt_seen; + break; + } + out << " elapsed=" << seconds_to_string(elapsed); + return out.str(); +} + + +TargetAttemptRecorder::TargetAttemptRecorder(VideoStream& stream, BBQuests quest, bool save_files) + : m_stream(stream) + , m_quest(quest) + , m_save_files(save_files) + , m_start(current_time()) + , m_file_prefix(target_diagnostics_directory() + now_to_filestring() + "-" + quest_slug(quest)) +{} + +void TargetAttemptRecorder::checkpoint(const std::string& name){ + const auto elapsed = std::chrono::duration_cast(current_time() - m_start); + m_stream.log( + "BBQ event=target-checkpoint quest=" + quest_slug(m_quest) + + " checkpoint=" + name + " elapsed=" + seconds_to_string(elapsed) + ); + if (m_save_files){ + m_frames.emplace_back(name, m_stream.video().snapshot()); + } +} + +TargetAttemptOutcome TargetAttemptRecorder::finish(const TargetAttemptSignals& signals){ + const auto elapsed = std::chrono::duration_cast(current_time() - m_start); + m_stream.log(target_attempt_summary(m_quest, signals, elapsed)); + + const TargetAttemptOutcome outcome = classify_target_attempt(signals); + if (!m_save_files){ + return outcome; + } + + try{ + Filesystem::create_directories(Filesystem::Path(target_diagnostics_directory())); + }catch (...){} + + for (const auto& [name, frame] : m_frames){ + const std::string path = m_file_prefix + "-" + name + ".png"; + const bool saved = frame && frame->save(path); + m_stream.log("BBQ event=target-file saved=" + std::to_string(saved) + " path=" + path); + } + m_frames.clear(); + + // The stream history covers the approach that led here, if the user has + // turned it on in the global settings. + if (target_attempt_needs_history(outcome)){ + const std::string path = m_file_prefix + "-approach.mp4"; + const bool saved = m_stream.save_stream_history(path); + m_stream.log("BBQ event=target-file saved=" + std::to_string(saved) + " path=" + path); + } + return outcome; +} + + + +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.h b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.h new file mode 100644 index 0000000000..90b29ae19b --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.h @@ -0,0 +1,99 @@ +/* BBQ Target Diagnostics + * + * From: https://github.com/PokemonAutomation/ + * + * Records how each attempt to reach a catch, Sneak Up or photo target went, + * to find out why so many attempts never find their target. It only observes: + * it sends no controller commands and changes no decision. + * + */ + +#ifndef PokemonAutomation_PokemonSV_BBQTargetDiagnostics_H +#define PokemonAutomation_PokemonSV_BBQTargetDiagnostics_H + +#include +#include +#include +#include +#include "Common/Cpp/Time.h" +#include "CommonFramework/Tools/VideoStream.h" +#include "CommonFramework/VideoPipeline/VideoFeed.h" +#include "VideoGames/PokemonSV/Options/PokemonSV_BBQOption.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSV{ + + +enum class TargetAttemptKind{ + battle, // Catch and Sneak Up: lock on to the target to start a battle. + photo, // Photo: frame the target and take a picture. +}; + +enum class TargetAttemptOutcome{ + battle_entered, + no_battle, + // The battle menu showed up, but the encounter watcher did not fire, so + // the route treats the attempt as if no battle started. + battle_menu_without_encounter, + photo_prompt_seen, + // Not proof the photo failed: some photo quests still complete. + photo_prompt_timeout, + battle_during_photo, +}; + +// What the route's detectors reported for one attempt. +struct TargetAttemptSignals{ + TargetAttemptKind kind = TargetAttemptKind::battle; + bool encounter_detected = false; + bool battle_menu_seen = false; // Battle routes only. + bool photo_prompt_seen = false; // Photo routes only. +}; + +TargetAttemptOutcome classify_target_attempt(const TargetAttemptSignals& signals); +const char* target_attempt_outcome_to_string(TargetAttemptOutcome outcome); + +// Whether the stream history before this outcome is worth keeping: it is, +// whenever the target may not have been reached. +bool target_attempt_needs_history(TargetAttemptOutcome outcome); + +// The log line for an attempt, in the same "BBQ event=..." form as the other +// BBQ logs so run audits can grep for it. +std::string target_attempt_summary( + BBQuests quest, + const TargetAttemptSignals& signals, + std::chrono::milliseconds elapsed +); + + +// Records one attempt: logs each checkpoint and the outcome. With +// "save_files", it also saves the frame at each checkpoint, and the stream +// history when the target may not have been reached, under +// DebugDumps/BBQ/targets/. Files are written in finish(), after the attempt, +// so saving them never delays a controller command during the approach. +class TargetAttemptRecorder{ +public: + TargetAttemptRecorder(VideoStream& stream, BBQuests quest, bool save_files); + + // Logs a checkpoint and keeps the current frame. Call it only where the + // route already waits for its commands to finish, so the frame shows the + // result of the commands sent so far. + void checkpoint(const std::string& name); + + TargetAttemptOutcome finish(const TargetAttemptSignals& signals); + +private: + VideoStream& m_stream; + const BBQuests m_quest; + const bool m_save_files; + const WallClock m_start; + const std::string m_file_prefix; + std::vector> m_frames; +}; + + + +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp index 999661c313..4d353588a9 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 "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "PokemonSV_BBQTargetDiagnostics.h" #include "PokemonSV_BlueberryQuests.h" #include "PokemonSV_BBQTests.h" @@ -66,8 +67,138 @@ static void add_tests_TeraEncounterAction(UnitTestDatabase& database){ } +namespace{ + +struct BBQTargetAttemptScenario{ + std::string name; + BBQuests quest = BBQuests::catch_any; + TargetAttemptSignals signals; + TargetAttemptOutcome expected_outcome = TargetAttemptOutcome::no_battle; + bool expected_needs_history = false; + std::string expected_summary; +}; + +class Test_BBQTargetAttempt : public UnitTest{ +public: + Test_BBQTargetAttempt(BBQTargetAttemptScenario scenario) + : UnitTest("PokemonSV::BBQTargetAttempt - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const TargetAttemptOutcome outcome = classify_target_attempt(m_scenario.signals); + if (outcome != m_scenario.expected_outcome){ + return std::string("Expected outcome ") + target_attempt_outcome_to_string(m_scenario.expected_outcome) + + ", got " + target_attempt_outcome_to_string(outcome); + } + const bool needs_history = target_attempt_needs_history(outcome); + if (needs_history != m_scenario.expected_needs_history){ + return std::string("Expected needs_history=") + (m_scenario.expected_needs_history ? "true" : "false") + + ", got " + (needs_history ? "true" : "false"); + } + const std::string summary = target_attempt_summary( + m_scenario.quest, m_scenario.signals, std::chrono::milliseconds(41300) + ); + if (summary != m_scenario.expected_summary){ + return "Expected summary: " + m_scenario.expected_summary + "\nActual summary: " + summary; + } + return true; + } + +private: + const BBQTargetAttemptScenario m_scenario; +}; + +} + +static void add_tests_BBQTargetAttempt(UnitTestDatabase& database){ + const BBQTargetAttemptScenario scenarios[] = { + { + .name = "catch enters battle", + .signals = { + .kind = TargetAttemptKind::battle, + .encounter_detected = true, + }, + .expected_outcome = TargetAttemptOutcome::battle_entered, + .expected_needs_history = false, + .expected_summary = "BBQ event=target-attempt quest=catch-any outcome=battle-entered encounter=1 battle_menu=0 elapsed=41.3s", + }, + { + // The failure behind "Did not enter battle. Did target spawn?". + .name = "catch finds no battle", + .signals = { + .kind = TargetAttemptKind::battle, + }, + .expected_outcome = TargetAttemptOutcome::no_battle, + .expected_needs_history = true, + .expected_summary = "BBQ event=target-attempt quest=catch-any outcome=no-battle encounter=0 battle_menu=0 elapsed=41.3s", + }, + { + .name = "sneak up finds no battle", + .quest = BBQuests::sneak_up, + .signals = { + .kind = TargetAttemptKind::battle, + }, + .expected_outcome = TargetAttemptOutcome::no_battle, + .expected_needs_history = true, + .expected_summary = "BBQ event=target-attempt quest=sneak-up outcome=no-battle encounter=0 battle_menu=0 elapsed=41.3s", + }, + { + // The route only acts on the encounter watcher, so it treats this + // as no battle: a detector disagreement, not a missing target. + .name = "battle menu without the encounter watcher", + .quest = BBQuests::catch_normal, + .signals = { + .kind = TargetAttemptKind::battle, + .battle_menu_seen = true, + }, + .expected_outcome = TargetAttemptOutcome::battle_menu_without_encounter, + .expected_needs_history = true, + .expected_summary = "BBQ event=target-attempt quest=catch-normal outcome=battle-menu-without-encounter encounter=0 battle_menu=1 elapsed=41.3s", + }, + { + .name = "photo prompt seen", + .quest = BBQuests::photo_savanna, + .signals = { + .kind = TargetAttemptKind::photo, + .photo_prompt_seen = true, + }, + .expected_outcome = TargetAttemptOutcome::photo_prompt_seen, + .expected_needs_history = false, + .expected_summary = "BBQ event=target-attempt quest=photo-savanna outcome=photo-prompt-seen encounter=0 photo_prompt=1 elapsed=41.3s", + }, + { + .name = "photo prompt timeout", + .quest = BBQuests::photo_savanna, + .signals = { + .kind = TargetAttemptKind::photo, + }, + .expected_outcome = TargetAttemptOutcome::photo_prompt_timeout, + .expected_needs_history = true, + .expected_summary = "BBQ event=target-attempt quest=photo-savanna outcome=photo-prompt-timeout encounter=0 photo_prompt=0 elapsed=41.3s", + }, + { + // A wild battle cuts the photo route short; the route retries. + .name = "battle during photo", + .quest = BBQuests::photo_coastal, + .signals = { + .kind = TargetAttemptKind::photo, + .encounter_detected = true, + }, + .expected_outcome = TargetAttemptOutcome::battle_during_photo, + .expected_needs_history = true, + .expected_summary = "BBQ event=target-attempt quest=photo-coastal outcome=battle-during-photo encounter=1 photo_prompt=0 elapsed=41.3s", + }, + }; + for (const BBQTargetAttemptScenario& scenario : scenarios){ + database.add(scenario); + } +} + + void add_tests_BBQ(UnitTestDatabase& database){ add_tests_TeraEncounterAction(database); + add_tests_BBQTargetAttempt(database); } diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp index 3a24e1d187..a43f05c306 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp @@ -26,6 +26,7 @@ #include "VideoGames/PokemonSV/Programs/PokemonSV_WorldNavigation.h" #include "VideoGames/PokemonSV/Programs/Battles/PokemonSV_BasicCatcher.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h" +#include "PokemonSV_BBQTargetDiagnostics.h" #include "PokemonSV_BlueberryCatchPhoto.h" namespace PokemonAutomation{ @@ -289,6 +290,8 @@ void quest_photo( CameraAngle move_camera = CameraAngle::none; while(!took_photo){ + TargetAttemptRecorder recorder(console, current_quest, BBQ_OPTIONS.SAVE_TARGET_DIAGNOSTICS); + bool photo_prompt_seen = false; EncounterWatcher encounter_watcher(console, COLOR_RED); int ret = run_until( console, context, @@ -311,6 +314,7 @@ void quest_photo( pbf_move_right_joystick(context, {0, -1}, 400ms, 160ms); } context.wait_for_all_requests(); + recorder.checkpoint("before-shutter"); pbf_press_button(context, BUTTON_A, 160ms, 400ms); @@ -319,9 +323,11 @@ void quest_photo( std::chrono::seconds(10), { photo_prompt } ); + photo_prompt_seen = ret == 0; if (ret != 0){ console.log("Photo not taken."); } + recorder.checkpoint(photo_prompt_seen ? "photo-prompt" : "photo-prompt-timeout"); //Mash B until overworld int exit = run_until( @@ -342,6 +348,11 @@ void quest_photo( static_cast(encounter_watcher), } ); + recorder.finish({ + .kind = TargetAttemptKind::photo, + .encounter_detected = ret >= 0, + .photo_prompt_seen = photo_prompt_seen, + }); encounter_watcher.throw_if_no_sound(); if (ret >= 0){ @@ -899,6 +910,8 @@ void quest_catch( const BBQOption& BBQ_OPTIONS, BBQuests current_quest ){ + TargetAttemptRecorder recorder(console, current_quest, BBQ_OPTIONS.SAVE_TARGET_DIAGNOSTICS); + bool battle_menu_seen = false; EncounterWatcher encounter_watcher(console, COLOR_RED); //Navigate to target and start battle @@ -908,6 +921,7 @@ void quest_catch( quest_catch_navi(info, console, context, BBQ_OPTIONS, current_quest); context.wait_for_all_requests(); + recorder.checkpoint("after-lock-on"); NormalBattleMenuWatcher battle_menu(COLOR_YELLOW); int ret2 = wait_until( @@ -915,8 +929,10 @@ void quest_catch( std::chrono::seconds(25), { battle_menu } ); + battle_menu_seen = ret2 == 0; if (ret2 != 0){ console.log("Did not enter battle. Did target spawn?"); + recorder.checkpoint("battle-entry-timeout"); } }, { @@ -924,6 +940,11 @@ void quest_catch( static_cast(encounter_watcher), } ); + recorder.finish({ + .kind = TargetAttemptKind::battle, + .encounter_detected = ret >= 0, + .battle_menu_seen = battle_menu_seen, + }); encounter_watcher.throw_if_no_sound(); if (ret >= 0){ diff --git a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp index 8bec917a63..bd95b26f86 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryQuests.cpp @@ -41,6 +41,7 @@ #include "VideoGames/PokemonSV/Programs/TeraRaids/PokemonSV_TeraBattler.h" #include "VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.h" #include "VideoGames/PokemonSV/Programs/PokemonSV_Terarium.h" +#include "PokemonSV_BBQTargetDiagnostics.h" #include "PokemonSV_BlueberryQuests.h" @@ -665,6 +666,8 @@ void quest_sneak_up( ConsoleHandle& console, ProControllerContext& context, const BBQOption& BBQ_OPTIONS ){ + TargetAttemptRecorder recorder(console, BBQuests::sneak_up, BBQ_OPTIONS.SAVE_TARGET_DIAGNOSTICS); + bool battle_menu_seen = false; EncounterWatcher encounter_watcher(console, COLOR_RED); console.log("Quest: Sneak up."); //Navigate to target and start battle @@ -697,6 +700,7 @@ void quest_sneak_up( pbf_wait(context, 2400ms); context.wait_for_all_requests(); + recorder.checkpoint("after-lock-on"); NormalBattleMenuWatcher battle_menu(COLOR_YELLOW); int ret2 = wait_until( @@ -704,8 +708,10 @@ void quest_sneak_up( std::chrono::seconds(15), { battle_menu } ); + battle_menu_seen = ret2 == 0; if (ret2 != 0){ console.log("Did not enter battle. Did target spawn?"); + recorder.checkpoint("battle-entry-timeout"); } }, { @@ -713,6 +719,11 @@ void quest_sneak_up( static_cast(encounter_watcher), } ); + recorder.finish({ + .kind = TargetAttemptKind::battle, + .encounter_detected = ret >= 0, + .battle_menu_seen = battle_menu_seen, + }); encounter_watcher.throw_if_no_sound(); if (ret >= 0){ diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index ce54742834..e293fe9daa 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2597,6 +2597,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_AuctionFarmer.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.h + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.cpp + Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTargetDiagnostics.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.cpp Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQTests.h Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BlueberryCatchPhoto.cpp