From 1fe211c81d25844dddb0a0872bb71d55d8d870c9 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 9 Nov 2026 22:08:06 -0800 Subject: [PATCH] Max Lair: read a single-type Normal opponent in the summary The "O" of the summary's "NORMAL" type label also matches the Normal icon, so a single-type Normal opponent read as Normal/Normal and matched nothing; a type read twice is now one type. Adds an image test on a Persian summary. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_Detect_BattleMenu.cpp | 68 ++++++++++++++++--- 1 file changed, 58 insertions(+), 10 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 5f53191aab..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 @@ -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" @@ -278,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()){ - 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; } } @@ -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"} + ); }