From 5d89d08d15fae7001102689b687ddc2fec1f54ec Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 12:22:02 -0800 Subject: [PATCH 1/2] PokemonBDSP: MenuDetector sees past NEW tags; ShortDialogDetector accepts a long first line ShortDialogDetector missed dialogue whose long first line covers the white box it checks at the right end (Rowan's "Now, go on, and leap into the world of Pokemon!"). It keeps the old check and also accepts the box's right end below the first line, so every screen it accepted before is still accepted. MenuDetector's columns start a little further right (0.160 to 0.166), in the gap after each icon: with a NEW tag on TOWN MAP the second column took the edge of the tag and the menu went unseen. Adds image tests for both, read from PokemonBDSP/DialogDetector and PokemonBDSP/MenuDetector in CommandLineTests. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../ComputerPrograms_UnitTestRunner.cpp | 4 ++ .../Inference/PokemonBDSP_DialogDetector.cpp | 40 ++++++++++- .../Inference/PokemonBDSP_DialogDetector.h | 6 ++ .../Inference/PokemonBDSP_MenuDetector.cpp | 72 ++++++++++++++++++- .../Inference/PokemonBDSP_MenuDetector.h | 4 ++ 5 files changed, 124 insertions(+), 2 deletions(-) diff --git a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp index 1eaae86b3a..ff95bd98d2 100644 --- a/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp +++ b/SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp @@ -29,6 +29,8 @@ #include "NintendoSwitch/Inference/NintendoSwitch_UpdatePopupDetector.h" #include "NintendoSwitch/Programs/Typewriter/NintendoSwitch_Typewriter_Tests.h" #include "NintendoSwitch/Controllers/SysbotBase/SysbotBase_Connection.h" +#include "PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h" +#include "PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h" #include "VideoGames/PokemonHome/PokemonHome_Tests.h" #include "VideoGames/PokemonSwSh/PokemonSwSh_Tests.h" @@ -69,6 +71,8 @@ UnitTestDatabase make_UNIT_TESTS_ALL(){ NintendoSwitch::add_tests_FailedToConnectDetector(ret); NintendoSwitch::add_tests_UpdatePopupDetector(ret); NintendoSwitch::Typewriter::add_tests_TypewriterTextMapping(ret); + NintendoSwitch::PokemonBDSP::add_tests_DialogDetector(ret); + NintendoSwitch::PokemonBDSP::add_tests_MenuDetector(ret); NintendoSwitch::PokemonFRLG::add_tests(ret); NintendoSwitch::PokemonRSE::add_tests(ret); NintendoSwitch::PokemonHome::add_tests(ret); diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp index c8636d99cb..17194476f8 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp @@ -6,6 +6,8 @@ #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "CommonTools/Images/SolidColorTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Tests/ImageUnitTest.h" #include "PokemonBDSP_DialogDetector.h" //#include @@ -23,6 +25,7 @@ ShortDialogDetector::ShortDialogDetector(Color color) , m_left_white(0.21, 0.835, 0.008, 0.12) , m_left(0.18, 0.835, 0.02, 0.12) , m_right_white(0.785, 0.835, 0.008, 0.12) + , m_right_white_low(0.785, 0.915, 0.008, 0.04) , m_right(0.822, 0.835, 0.02, 0.12) {} void ShortDialogDetector::make_overlays(VideoOverlaySet& items) const{ @@ -40,7 +43,9 @@ bool ShortDialogDetector::detect(const ImageViewRGB32& screen){ } ImageStats right_white = image_stats(extract_box_reference(screen, m_right_white)); // cout << right_white.average << right_white.stddev << endl; - if (!is_white(right_white)){ + // A long first line runs into m_right_white (Rowan's "Now, go on, and + // leap into the world of Pokemon!"): then the box's right end below it. + if (!is_white(right_white) && !is_white(image_stats(extract_box_reference(screen, m_right_white_low)))){ return false; } // ImageStats bottom = image_stats(extract_box_reference(screen, m_bottom)); @@ -125,6 +130,39 @@ bool ShortDialogPromptDetector::process_frame(const ImageViewRGB32& screen, Wall + + +class Test_ShortDialogDetector : public ImageUnitTest{ +public: + Test_ShortDialogDetector(const std::string& image, bool expected) + : ImageUnitTest("PokemonBDSP::ShortDialogDetector - " + image, {image}) + , m_expected(expected) + {} + + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, + const std::vector& images + ) const override{ + return ShortDialogDetector().detect(images[0]) == m_expected; + } + +private: + bool m_expected; +}; + +void add_tests_DialogDetector(UnitTestDatabase& database){ + database.add("PokemonBDSP/DialogDetector/IntroRowanNameTab_True.png", true); + database.add("PokemonBDSP/DialogDetector/IntroRowanNoArrow_True.png", true); + // A short line: the box's right end is white where the old check looks. + database.add("PokemonBDSP/DialogDetector/IntroRowanShortLine_True.png", true); + // A "???" name tab, in Jubilife's yellow plaza after the tag battle. + database.add("PokemonBDSP/DialogDetector/JubilifeUnknownNameTab_True.png", true); + // One line, no name tab, over Floaroma's flowers. + database.add("PokemonBDSP/DialogDetector/FloaromaOldManOneLine_True.png", true); + database.add("PokemonBDSP/DialogDetector/FloaromaCloudShadows_False.png", false); +} + + } } } diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h index fe7c90cbb0..f1f98bcc3a 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h @@ -7,6 +7,7 @@ #ifndef PokemonAutomation_PokemonBDSP_BattleDialogDetector_H #define PokemonAutomation_PokemonBDSP_BattleDialogDetector_H +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h" #include "CommonTools/VisualDetector.h" #include "PokemonBDSP_SelectionArrow.h" @@ -31,6 +32,7 @@ class ShortDialogDetector : public StaticScreenDetector{ ImageFloatBox m_left_white; ImageFloatBox m_left; ImageFloatBox m_right_white; + ImageFloatBox m_right_white_low; ImageFloatBox m_right; }; class ShortDialogWatcher : public DetectorToFinder{ @@ -79,6 +81,10 @@ class ShortDialogPromptDetector : public VisualInferenceCallback{ + +// The screenshot tests in CommandLineTests/PokemonBDSP/DialogDetector/. +void add_tests_DialogDetector(UnitTestDatabase& database); + } } } diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp index 12da43966e..ef90664b86 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp @@ -7,6 +7,8 @@ #include "CommonFramework/ImageTools/ImageStats.h" #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" #include "CommonTools/Images/SolidColorTest.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "Tests/ImageUnitTest.h" #include "PokemonBDSP_MenuDetector.h" namespace PokemonAutomation{ @@ -18,9 +20,14 @@ const double STRIPE_TOP = 0.110; const double STRIPE_TOP_BELOW_BANNER = 0.170; const double STRIPE_BOTTOM = 0.598; +// Each column sits in the gap right of an icon, clear of the "NEW" tag on +// its top right corner: from 0.160 the column took the edge of the tag on +// TOWN MAP and the menu went unseen (r65, Jubilife). +const double STRIPE_LEFT = 0.166; + static ImageFloatBox menu_stripe(size_t index, bool skip_new_banner){ double top = skip_new_banner ? STRIPE_TOP_BELOW_BANNER : STRIPE_TOP; - return ImageFloatBox(0.160 + 0.166 * (double)index, top, 0.015, STRIPE_BOTTOM - top); + return ImageFloatBox(STRIPE_LEFT + 0.166 * (double)index, top, 0.015, STRIPE_BOTTOM - top); } MenuDetector::MenuDetector(Color color, bool skip_new_banner) @@ -84,6 +91,69 @@ bool MenuWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp +namespace{ + +// Which columns the detector checks: the default ones from the top, or the +// ones below the "NEW" tags (a new game's menu, skip_new_banner = true). +enum class Columns{ + FromTop, + BelowNewTags, +}; + +class Test_MenuDetector : public ImageUnitTest{ +public: + Test_MenuDetector(const std::string& image, Columns columns, bool expected) + : ImageUnitTest( + "PokemonBDSP::MenuDetector" + std::string(columns == Columns::BelowNewTags ? "(skip_new_banner)" : "") + " - " + image, + {image} + ) + , m_columns(columns) + , m_expected(expected) + {} + + virtual UnitTestResult run_on_images( + Logger&, CancellableScope&, + const std::vector& images + ) const override{ + MenuDetector detector(COLOR_RED, m_columns == Columns::BelowNewTags); + return detector.detect(images[0]) == m_expected; + } + +private: + Columns m_columns; + bool m_expected; +}; + +} + +void add_tests_MenuDetector(UnitTestDatabase& database){ + // The new game's menu: a "NEW" tag above OPTIONS. Jubilife after the + // Town Map: one on TOWN MAP, and the quest's text below. + for (const char* image : { + "PokemonBDSP/MenuDetector/NewGameBagOptions_True.png", + "PokemonBDSP/MenuDetector/JubilifeTownMapNew_True.png", + // Three NEW tags (Trainer Card, Town Map, Ball Capsules), cursor on Bag. + "PokemonBDSP/MenuDetector/FloaromaMenuThreeNew_True.png", + }){ + database.add(image, Columns::FromTop, true); + database.add(image, Columns::BelowNewTags, true); + } + for (const char* image : { + "PokemonBDSP/MenuDetector/Home_False.png", + "PokemonBDSP/MenuDetector/OverworldSandgemMart_False.png", + "PokemonBDSP/MenuDetector/OverworldOreburghMine_False.png", + "PokemonBDSP/MenuDetector/IntroDialog_False.png", + "PokemonBDSP/MenuDetector/IntroBarry_False.png", + "PokemonBDSP/MenuDetector/FloaromaOldManDialog_False.png", + // Cloud shadows over Floaroma's flower field. + "PokemonBDSP/MenuDetector/FloaromaCloudShadows_False.png", + }){ + database.add(image, Columns::FromTop, false); + database.add(image, Columns::BelowNewTags, false); + } +} + + } } } diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h index f7e5a0517f..b605bfd3cf 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h @@ -11,6 +11,7 @@ #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h" #include "CommonTools/VisualDetector.h" +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -46,6 +47,9 @@ class MenuWatcher : public MenuDetector, public VisualInferenceCallback{ +// The screenshot tests in CommandLineTests/PokemonBDSP/MenuDetector/. +void add_tests_MenuDetector(UnitTestDatabase& database); + } } } From fc2d984b7dad11a9e6aa7f32674569b3605deb01 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 7 Nov 2026 11:50:20 -0800 Subject: [PATCH 2/2] BDSP detectors: align image tests with current C++ conventions --- .../Inference/PokemonBDSP_DialogDetector.cpp | 68 ++++++--- .../Inference/PokemonBDSP_DialogDetector.h | 6 +- .../Inference/PokemonBDSP_MenuDetector.cpp | 139 ++++++++++++------ .../Inference/PokemonBDSP_MenuDetector.h | 8 +- 4 files changed, 147 insertions(+), 74 deletions(-) diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp index 17194476f8..d3cbe175b1 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.cpp @@ -4,9 +4,12 @@ * */ +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/VideoPipeline/VideoOverlay.h" #include "CommonTools/Images/SolidColorTest.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Tests/ImageUnitTest.h" #include "PokemonBDSP_DialogDetector.h" @@ -33,6 +36,7 @@ void ShortDialogDetector::make_overlays(VideoOverlaySet& items) const{ items.add(m_color, m_left_white); items.add(m_color, m_left); items.add(m_color, m_right_white); + items.add(m_color, m_right_white_low); items.add(m_color, m_right); } bool ShortDialogDetector::detect(const ImageViewRGB32& screen){ @@ -44,7 +48,7 @@ bool ShortDialogDetector::detect(const ImageViewRGB32& screen){ ImageStats right_white = image_stats(extract_box_reference(screen, m_right_white)); // cout << right_white.average << right_white.stddev << endl; // A long first line runs into m_right_white (Rowan's "Now, go on, and - // leap into the world of Pokemon!"): then the box's right end below it. + // leap into the world of Pokemon!"). Check below that line as well. if (!is_white(right_white) && !is_white(image_stats(extract_box_reference(screen, m_right_white_low)))){ return false; } @@ -132,37 +136,61 @@ bool ShortDialogPromptDetector::process_frame(const ImageViewRGB32& screen, Wall +namespace{ + +// The captured screen supplied to the short-dialog detector. +struct DialogInput{ + std::string_view image; +}; +// Whether a short dialog should be visible in that screen. +struct DialogExpectation{ + bool detected = false; +}; +// One image and its independently specified expected result. +struct DialogCase{ + DialogInput input; + DialogExpectation expectation; +}; + +// Runs the detector on the original image and the image-test color distortions. class Test_ShortDialogDetector : public ImageUnitTest{ public: - Test_ShortDialogDetector(const std::string& image, bool expected) - : ImageUnitTest("PokemonBDSP::ShortDialogDetector - " + image, {image}) - , m_expected(expected) + explicit Test_ShortDialogDetector(const DialogCase& test) + : ImageUnitTest(std::format("PokemonBDSP::ShortDialogDetector - {}", test.input.image), {std::string(test.input.image)}) + , m_expectation(test.expectation) {} virtual UnitTestResult run_on_images( Logger&, CancellableScope&, const std::vector& images ) const override{ - return ShortDialogDetector().detect(images[0]) == m_expected; + const bool detected = ShortDialogDetector().detect(images[0]); + if (detected != m_expectation.detected){ + return std::format("Expected short dialog detected={}, read {}.", m_expectation.detected, detected); + } + return true; } private: - bool m_expected; + DialogExpectation m_expectation; }; +} // namespace + void add_tests_DialogDetector(UnitTestDatabase& database){ - database.add("PokemonBDSP/DialogDetector/IntroRowanNameTab_True.png", true); - database.add("PokemonBDSP/DialogDetector/IntroRowanNoArrow_True.png", true); - // A short line: the box's right end is white where the old check looks. - database.add("PokemonBDSP/DialogDetector/IntroRowanShortLine_True.png", true); - // A "???" name tab, in Jubilife's yellow plaza after the tag battle. - database.add("PokemonBDSP/DialogDetector/JubilifeUnknownNameTab_True.png", true); - // One line, no name tab, over Floaroma's flowers. - database.add("PokemonBDSP/DialogDetector/FloaromaOldManOneLine_True.png", true); - database.add("PokemonBDSP/DialogDetector/FloaromaCloudShadows_False.png", false); + static constexpr std::array CASES{{ + {.input = {.image = "PokemonBDSP/DialogDetector/IntroRowanNameTab_True.png"}, .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/DialogDetector/IntroRowanNoArrow_True.png"}, .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/DialogDetector/IntroRowanShortLine_True.png"}, .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/DialogDetector/JubilifeUnknownNameTab_True.png"}, .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/DialogDetector/FloaromaOldManOneLine_True.png"}, .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/DialogDetector/FloaromaCloudShadows_False.png"}, .expectation = {.detected = false}}, + }}; + for (const DialogCase& test : CASES){ + database.add(test); + } } - -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h index f1f98bcc3a..00d4b4eb1f 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_DialogDetector.h @@ -85,7 +85,7 @@ class ShortDialogPromptDetector : public VisualInferenceCallback{ // The screenshot tests in CommandLineTests/PokemonBDSP/DialogDetector/. void add_tests_DialogDetector(UnitTestDatabase& database); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp index ef90664b86..6d23f8fb83 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.cpp @@ -4,10 +4,13 @@ * */ +#include +#include +#include +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "CommonFramework/ImageTools/ImageStats.h" #include "CommonFramework/VideoPipeline/VideoOverlayScopes.h" #include "CommonTools/Images/SolidColorTest.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Tests/ImageUnitTest.h" #include "PokemonBDSP_MenuDetector.h" @@ -16,20 +19,23 @@ namespace NintendoSwitch{ namespace PokemonBDSP{ -const double STRIPE_TOP = 0.110; -const double STRIPE_TOP_BELOW_BANNER = 0.170; -const double STRIPE_BOTTOM = 0.598; +namespace{ + +constexpr double STRIPE_TOP = 0.110; +constexpr double STRIPE_TOP_BELOW_BANNER = 0.170; +constexpr double STRIPE_BOTTOM = 0.598; // Each column sits in the gap right of an icon, clear of the "NEW" tag on -// its top right corner: from 0.160 the column took the edge of the tag on -// TOWN MAP and the menu went unseen (r65, Jubilife). -const double STRIPE_LEFT = 0.166; +// its top right corner. The tag on TOWN MAP extends into a column at 0.160. +constexpr double STRIPE_LEFT = 0.166; -static ImageFloatBox menu_stripe(size_t index, bool skip_new_banner){ +ImageFloatBox menu_stripe(size_t index, bool skip_new_banner){ double top = skip_new_banner ? STRIPE_TOP_BELOW_BANNER : STRIPE_TOP; return ImageFloatBox(STRIPE_LEFT + 0.166 * (double)index, top, 0.015, STRIPE_BOTTOM - top); } +} // namespace + MenuDetector::MenuDetector(Color color, bool skip_new_banner) : m_color(color) , m_line0(menu_stripe(0, skip_new_banner)) @@ -93,67 +99,106 @@ bool MenuWatcher::process_frame(const ImageViewRGB32& frame, WallClock timestamp namespace{ -// Which columns the detector checks: the default ones from the top, or the -// ones below the "NEW" tags (a new game's menu, skip_new_banner = true). +// Selects full-height columns or columns starting below the NEW tags. enum class Columns{ FromTop, BelowNewTags, }; +// A screen and the existing detector mode used to inspect it. +struct MenuInput{ + std::string_view image; + Columns columns = Columns::FromTop; +}; +// Whether the screen should be recognized as the X menu. +struct MenuExpectation{ + bool detected = false; +}; +// One screen/mode pair and its independently specified expected result. +struct MenuCase{ + MenuInput input; + MenuExpectation expectation; +}; +// Verifies both detector modes, including the image-test color distortions. class Test_MenuDetector : public ImageUnitTest{ public: - Test_MenuDetector(const std::string& image, Columns columns, bool expected) + explicit Test_MenuDetector(const MenuCase& test) : ImageUnitTest( - "PokemonBDSP::MenuDetector" + std::string(columns == Columns::BelowNewTags ? "(skip_new_banner)" : "") + " - " + image, - {image} + std::format("PokemonBDSP::MenuDetector{} - {}", + test.input.columns == Columns::BelowNewTags ? "(skip_new_banner)" : "", test.input.image), + {std::string(test.input.image)} ) - , m_columns(columns) - , m_expected(expected) + , m_columns(test.input.columns) + , m_expectation(test.expectation) {} virtual UnitTestResult run_on_images( Logger&, CancellableScope&, const std::vector& images ) const override{ - MenuDetector detector(COLOR_RED, m_columns == Columns::BelowNewTags); - return detector.detect(images[0]) == m_expected; + MenuDetector detector(COLOR_RED, /*skip_new_banner=*/m_columns == Columns::BelowNewTags); + const bool detected = detector.detect(images[0]); + if (detected != m_expectation.detected){ + return std::format("Expected menu detected={}, read {}.", m_expectation.detected, detected); + } + return true; } private: - Columns m_columns; - bool m_expected; + Columns m_columns = Columns::FromTop; + MenuExpectation m_expectation; }; -} +} // namespace void add_tests_MenuDetector(UnitTestDatabase& database){ - // The new game's menu: a "NEW" tag above OPTIONS. Jubilife after the - // Town Map: one on TOWN MAP, and the quest's text below. - for (const char* image : { - "PokemonBDSP/MenuDetector/NewGameBagOptions_True.png", - "PokemonBDSP/MenuDetector/JubilifeTownMapNew_True.png", - // Three NEW tags (Trainer Card, Town Map, Ball Capsules), cursor on Bag. - "PokemonBDSP/MenuDetector/FloaromaMenuThreeNew_True.png", - }){ - database.add(image, Columns::FromTop, true); - database.add(image, Columns::BelowNewTags, true); - } - for (const char* image : { - "PokemonBDSP/MenuDetector/Home_False.png", - "PokemonBDSP/MenuDetector/OverworldSandgemMart_False.png", - "PokemonBDSP/MenuDetector/OverworldOreburghMine_False.png", - "PokemonBDSP/MenuDetector/IntroDialog_False.png", - "PokemonBDSP/MenuDetector/IntroBarry_False.png", - "PokemonBDSP/MenuDetector/FloaromaOldManDialog_False.png", - // Cloud shadows over Floaroma's flower field. - "PokemonBDSP/MenuDetector/FloaromaCloudShadows_False.png", - }){ - database.add(image, Columns::FromTop, false); - database.add(image, Columns::BelowNewTags, false); + static constexpr std::array CASES{{ + {.input = {.image = "PokemonBDSP/MenuDetector/NewGameBagOptions_True.png", .columns = Columns::FromTop}, + .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/MenuDetector/NewGameBagOptions_True.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/MenuDetector/JubilifeTownMapNew_True.png", .columns = Columns::FromTop}, + .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/MenuDetector/JubilifeTownMapNew_True.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/MenuDetector/FloaromaMenuThreeNew_True.png", .columns = Columns::FromTop}, + .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/MenuDetector/FloaromaMenuThreeNew_True.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = true}}, + {.input = {.image = "PokemonBDSP/MenuDetector/Home_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/Home_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/OverworldSandgemMart_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/OverworldSandgemMart_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/OverworldOreburghMine_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/OverworldOreburghMine_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/IntroDialog_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/IntroDialog_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/IntroBarry_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/IntroBarry_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/FloaromaOldManDialog_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/FloaromaOldManDialog_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/FloaromaCloudShadows_False.png", .columns = Columns::FromTop}, + .expectation = {.detected = false}}, + {.input = {.image = "PokemonBDSP/MenuDetector/FloaromaCloudShadows_False.png", .columns = Columns::BelowNewTags}, + .expectation = {.detected = false}}, + }}; + for (const MenuCase& test : CASES){ + database.add(test); } } - -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation diff --git a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h index b605bfd3cf..e084f66d3e 100644 --- a/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h +++ b/SerialPrograms/Source/PokemonBDSP/Inference/PokemonBDSP_MenuDetector.h @@ -7,11 +7,11 @@ #ifndef PokemonAutomation_PokemonBDSP_MenuDetector_H #define PokemonAutomation_PokemonBDSP_MenuDetector_H +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" #include "Common/Cpp/Color.h" #include "CommonFramework/ImageTools/ImageBoxes.h" #include "CommonTools/InferenceCallbacks/VisualInferenceCallback.h" #include "CommonTools/VisualDetector.h" -#include "Common/Cpp/TestRunners/UnitTestDatabase.h" namespace PokemonAutomation{ namespace NintendoSwitch{ @@ -50,7 +50,7 @@ class MenuWatcher : public MenuDetector, public VisualInferenceCallback{ // The screenshot tests in CommandLineTests/PokemonBDSP/MenuDetector/. void add_tests_MenuDetector(UnitTestDatabase& database); -} -} -} +} // namespace PokemonBDSP +} // namespace NintendoSwitch +} // namespace PokemonAutomation #endif