From 3dec3ca93d1a29e41cce746edbe0aa9cfc2a769f Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 20:51:05 -0800 Subject: [PATCH 1/5] Max Lair: test the summary read on a single-type Normal opponent Runs BattleMenuReader::read_opponent_in_summary() on a 4K summary screenshot of Persian and expects {"persian"}. The image goes in the CommandLineTests repo at PokemonSwSh/MaxLair_SummaryOpponentReader/English_Persian.jpg. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_Detect_BattleMenu.cpp | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp index 5f53191aab..a1fcfcd319 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp @@ -14,6 +14,7 @@ #include "CommonTools/Images/SolidColorTest.h" #include "CommonTools/Images/ColorClustering.h" #include "Tests/ImageUnitTest.h" +#include "Tests/TestUtils.h" #include "Pokemon/Inference/Pokemon_ReadHpBar.h" #include "Pokemon/Inference/Pokemon_TypeReader.h" #include "VideoGames/PokemonSwSh/Resources/PokemonSwSh_MaxLairDatabase.h" @@ -573,12 +574,59 @@ class Test_MaxLairBattleMenuDetector : public ImageUnitTest{ +class Test_MaxLairSummaryOpponentReader : public ImageUnitTest{ +public: + Test_MaxLairSummaryOpponentReader( + const std::string& image, + Language language, + std::set expected + ) + : ImageUnitTest("PokemonSwSh::MaxLairSummaryOpponentReader - " + image, {image}) + , m_language(language) + , m_expected(std::move(expected)) + {} + + virtual UnitTestResult run_on_images( + Logger& logger, CancellableScope& scope, + const std::vector& images + ) const override{ + DummyVideoOverlay overlay; + OcrFailureWatchdog ocr_watchdog(logger, m_language); + BattleMenuReader reader(overlay, m_language, ocr_watchdog); + std::set result = reader.read_opponent_in_summary(logger, images[0]); + if (result == m_expected){ + return true; + } + std::string message = "Read:"; + for (const std::string& slug : result){ + message += " " + slug; + } + if (result.empty()){ + message += " (nothing)"; + } + return UnitTestResult(UnitTestResult::FAILED, std::move(message)); + }; + +private: + Language m_language; + std::set m_expected; +}; + + + void add_tests_MaxLairBattleMenuDetector(UnitTestDatabase& database){ database.add("PokemonSwSh/MaxLair_BattleMenuDetector/MyPin_Q6g_BattleMenuDA_True.jpg", true); + + // A single-type Normal Pokemon: the "O" of the "NORMAL" badge label also + // matches the Normal icon. + database.add( + "PokemonSwSh/MaxLair_SummaryOpponentReader/English_Persian.jpg", + Language::English, std::set{"persian"} + ); } From 04c99bb8dc42260ec7c281ecb01c3402bb625b4e Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 20:51:05 -0800 Subject: [PATCH 2/5] Max Lair: a type read twice is one type in the summary read The summary's type box holds the type badge, e.g. "(O) NORMAL". The letter "O" of the "NORMAL" label is a separate white ring that matches the Normal icon (Persian: 0.368, next to 0.076 for the real icon), and find_type_symbols() drops only overlapping matches. A single-type Normal Pokemon was read as Normal/Normal, matched nothing, and the summary read returned empty. No Pokemon has the same type twice, so treat a repeated type as one type. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_Detect_BattleMenu.cpp | 45 +++++++++++++------ 1 file changed, 32 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp index a1fcfcd319..767d269f1e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp @@ -5,6 +5,7 @@ */ #include +#include #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/CancellableScope.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" @@ -261,6 +262,36 @@ std::set BattleMenuReader::read_opponent( // dump_image(logger, MODULE_NAME, "MaxLair-read_opponent", screen); return result; } +namespace{ + +// The opponent's types from the type matches in its summary's type box, best +// match first. PokemonType::NONE where there is no match. +std::pair summary_types( + const std::multimap>& candidates +){ + PokemonType type0 = PokemonType::NONE; + PokemonType type1 = PokemonType::NONE; + auto iter = candidates.begin(); + if (iter != candidates.end()){ + type0 = iter->second.first; + ++iter; + } + if (iter != candidates.end()){ + type1 = iter->second.first; + } + // The type box holds the type badge, e.g. "(O) NORMAL". The letter "O" + // of the "NORMAL" label is a white ring of its own that also matches the + // Normal icon (Persian: 0.368, next to 0.076 for the real icon). + // find_type_symbols() drops only overlapping matches, so a single-type + // Normal Pokemon was read as Normal/Normal and matched nothing. No + // Pokemon has the same type twice, so a repeated type is one type. + if (type1 == type0){ + type1 = PokemonType::NONE; + } + return {type0, type1}; +} + +} // namespace std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, const ImageViewRGB32& screen) const{ // Start by reading the types. PokemonType type0, type1; @@ -279,19 +310,7 @@ std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, } logger.log(type_str); - type0 = PokemonType::NONE; - type1 = PokemonType::NONE; - { - auto iter = candidates.begin(); - if (iter != candidates.end()){ - type0 = iter->second.first; - ++iter; - } - if (iter != candidates.end()){ - type1 = iter->second.first; - ++iter; - } - } + std::tie(type0, type1) = summary_types(candidates); } // Compile a list of all possible mons that match the type. From 8057ade5ec30b241174b55b4da46359b78be0d82 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 20:16:22 -0800 Subject: [PATCH 3/5] Max Lair: skip a repeated type where the second type is read Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_Detect_BattleMenu.cpp | 50 +++++++------------ 1 file changed, 18 insertions(+), 32 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp index 767d269f1e..3bd7e78f9f 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp @@ -5,7 +5,6 @@ */ #include -#include #include "Common/Cpp/PrettyPrint.h" #include "Common/Cpp/CancellableScope.h" #include "Common/Cpp/TestRunners/UnitTestDatabase.h" @@ -262,36 +261,6 @@ std::set BattleMenuReader::read_opponent( // dump_image(logger, MODULE_NAME, "MaxLair-read_opponent", screen); return result; } -namespace{ - -// The opponent's types from the type matches in its summary's type box, best -// match first. PokemonType::NONE where there is no match. -std::pair summary_types( - const std::multimap>& candidates -){ - PokemonType type0 = PokemonType::NONE; - PokemonType type1 = PokemonType::NONE; - auto iter = candidates.begin(); - if (iter != candidates.end()){ - type0 = iter->second.first; - ++iter; - } - if (iter != candidates.end()){ - type1 = iter->second.first; - } - // The type box holds the type badge, e.g. "(O) NORMAL". The letter "O" - // of the "NORMAL" label is a white ring of its own that also matches the - // Normal icon (Persian: 0.368, next to 0.076 for the real icon). - // find_type_symbols() drops only overlapping matches, so a single-type - // Normal Pokemon was read as Normal/Normal and matched nothing. No - // Pokemon has the same type twice, so a repeated type is one type. - if (type1 == type0){ - type1 = PokemonType::NONE; - } - return {type0, type1}; -} - -} // namespace std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, const ImageViewRGB32& screen) const{ // Start by reading the types. PokemonType type0, type1; @@ -310,7 +279,24 @@ std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, } logger.log(type_str); - std::tie(type0, type1) = summary_types(candidates); + type0 = PokemonType::NONE; + type1 = PokemonType::NONE; + { + auto iter = candidates.begin(); + if (iter != candidates.end()){ + type0 = iter->second.first; + ++iter; + } + // The type box holds the type badge, e.g. "(O) NORMAL". The letter "O" + // of the "NORMAL" label is a white ring of its own that also matches the + // Normal icon (Persian: 0.368, next to 0.076 for the real icon), so a + // single-type Normal Pokemon read as Normal/Normal and matched nothing. + // No Pokemon has the same type twice: a repeated type is one type. + if (iter != candidates.end() && iter->second.first != type0){ + type1 = iter->second.first; + ++iter; + } + } } // Compile a list of all possible mons that match the type. From f527b029180d51b0b2399e73e8957f63f02c4c89 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 20:16:41 -0800 Subject: [PATCH 4/5] Max Lair: keep the summary read's length; note the repeated type above it Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp index 3bd7e78f9f..5a8fbfa263 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp @@ -261,6 +261,9 @@ std::set BattleMenuReader::read_opponent( // dump_image(logger, MODULE_NAME, "MaxLair-read_opponent", screen); return result; } +// A type read twice is one type: in the summary's type box the "O" of a +// "NORMAL" label also matches the Normal icon (Persian: 0.368, next to 0.076 +// for the real icon), and no Pokemon has the same type twice. std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, const ImageViewRGB32& screen) const{ // Start by reading the types. PokemonType type0, type1; @@ -287,11 +290,6 @@ std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, type0 = iter->second.first; ++iter; } - // The type box holds the type badge, e.g. "(O) NORMAL". The letter "O" - // of the "NORMAL" label is a white ring of its own that also matches the - // Normal icon (Persian: 0.368, next to 0.076 for the real icon), so a - // single-type Normal Pokemon read as Normal/Normal and matched nothing. - // No Pokemon has the same type twice: a repeated type is one type. if (iter != candidates.end() && iter->second.first != type0){ type1 = iter->second.first; ++iter; From d93a3ee222285aa3b541edafd799948612ba6a24 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 20:19:51 -0800 Subject: [PATCH 5/5] Max Lair: the repeated-type note next to the type read Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_Detect_BattleMenu.cpp | 23 ++++++++----------- 1 file changed, 10 insertions(+), 13 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp index 5a8fbfa263..2de94be6ce 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.cpp @@ -261,9 +261,6 @@ std::set BattleMenuReader::read_opponent( // dump_image(logger, MODULE_NAME, "MaxLair-read_opponent", screen); return result; } -// A type read twice is one type: in the summary's type box the "O" of a -// "NORMAL" label also matches the Normal icon (Persian: 0.368, next to 0.076 -// for the real icon), and no Pokemon has the same type twice. std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, const ImageViewRGB32& screen) const{ // Start by reading the types. PokemonType type0, type1; @@ -282,18 +279,18 @@ std::set BattleMenuReader::read_opponent_in_summary(Logger& logger, } logger.log(type_str); + // A type read twice is one type: in the summary's type box the "O" of a + // "NORMAL" label also matches the Normal icon (Persian: 0.368, next to + // 0.076 for the real icon), and no Pokemon has the same type twice. type0 = PokemonType::NONE; type1 = PokemonType::NONE; - { - auto iter = candidates.begin(); - if (iter != candidates.end()){ - type0 = iter->second.first; - ++iter; - } - if (iter != candidates.end() && iter->second.first != type0){ - type1 = iter->second.first; - ++iter; - } + auto iter = candidates.begin(); + if (iter != candidates.end()){ + type0 = iter->second.first; + ++iter; + } + if (iter != candidates.end() && iter->second.first != type0){ + type1 = iter->second.first; } }