From 9a2cb8186f9af289d0c379cb66c399f4463f6ee0 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 10:53:25 -0800 Subject: [PATCH 1/9] Max Lair: test the current boss inference through GlobalState helpers Move the boss-stage check and boss inference that read_battle_menu() runs after the summary read into GlobalState::infer_boss_from_opponent(), and the boss passed to end_adventure_action() into GlobalState::caught_boss(). No behavior change. Add native tests that pin down today's results, including the cases a later fix changes. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 18 +++++ .../Framework/PokemonSwSh_MaxLair_State.h | 8 ++ .../PokemonSwSh_MaxLair_Run_Battle.cpp | 11 +-- .../PokemonSwSh_MaxLair_Run_CaughtScreen.cpp | 2 +- .../PokemonSwSh/PokemonSwSh_Tests.cpp | 76 +++++++++++++++++++ 5 files changed, 104 insertions(+), 11 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp index eb935fdfb9..c8307a2477 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -5,6 +5,7 @@ */ #include "Common/Cpp/PrettyPrint.h" #include "Pokemon/Pokemon_Types.h" +#include "VideoGames/PokemonSwSh/Resources/PokemonSwSh_MaxLairDatabase.h" #include "PokemonSwSh_MaxLair_State.h" namespace PokemonAutomation{ @@ -13,6 +14,23 @@ namespace PokemonSwSh{ namespace MaxLairInternal{ +bool GlobalState::infer_boss_from_opponent(){ + const std::string slug = opponent.empty() ? "" : *opponent.begin(); + // A boss before the end means something is out-of-sync. + if (wins != 3 && is_boss(slug)){ + return false; + } + // Infer the boss if we don't know it. + if (wins == 3 && boss.empty()){ + boss = slug; + } + return true; +} +std::string GlobalState::caught_boss(size_t) const{ + // The identified boss is reported whether or not it was caught. + return boss; +} + std::string PlayerState::dump() const{ std::string str; str += console_id < 0 ? "NPC" : "Switch " + std::to_string(console_id); diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h index 37e0134457..c1bb7c7665 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -168,6 +168,14 @@ struct GlobalState{ size_t find_player_index(size_t console_id) const; void clear_battle_state(); + // Check the opponent against the current battle stage and infer the boss. + // Returns false when the read is out-of-sync with the battle stage. + bool infer_boss_from_opponent(); + + // Return the boss slug passed to end_adventure_action() after + // caught_count Pokemon were caught. + std::string caught_boss(size_t caught_count) const; + std::string dump() const; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp index ef8c42b9b7..4da9df3d27 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp @@ -106,25 +106,16 @@ bool read_battle_menu( } state.opponent = {state.boss}; } - - opponent = state.opponent.empty() - ? "" - : *state.opponent.begin(); } context.wait_for_all_requests(); - if (state.wins != 3 && is_boss(opponent)){ + if (!state.infer_boss_from_opponent()){ stream.log("Boss found before 3 wins. Something is seriously out-of-sync.", COLOR_RED); dump_image(stream.logger(), MODULE_NAME, "BossBeforeEnd", snapshot); return false; } - // Infer the boss if we don't know it. - if (state.boss.empty() && state.wins == 3){ - state.boss = opponent; - } - // Read misc. VideoSnapshot screen = stream.video().snapshot(); state.opponent_hp = reader.read_opponent_hp(stream.logger(), screen); diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp index dc2ba76de5..40262944c8 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp @@ -202,7 +202,7 @@ StateMachineAction run_caught_screen( } - const std::string& boss = state_tracker[console_index].boss; + const std::string boss = state_tracker[console_index].caught_boss(tracker.total()); CaughtScreenAction action = decider.end_adventure_action( console_index, boss, diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp index 704212d3d6..2e3c1280d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp @@ -4,7 +4,9 @@ * */ +#include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" +#include "VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_DialogBoxDetector.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_DialogTriangleDetector.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_BoxGenderDetector.h" @@ -21,7 +23,81 @@ namespace PokemonSwSh{ +namespace{ +using MaxLairInternal::GlobalState; + +struct BossStateCase{ + std::string name; + uint8_t wins; + std::set opponent; + std::string boss; + size_t caught_count; + bool expected_accepted; + std::string expected_boss; + std::string expected_caught_boss; +}; + +class Test_MaxLairBossState : public UnitTest{ +public: + explicit Test_MaxLairBossState(BossStateCase scenario) + : UnitTest("PokemonSwSh::MaxLairBossState - " + scenario.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + GlobalState state; + state.wins = m_scenario.wins; + state.opponent = m_scenario.opponent; + state.boss = m_scenario.boss; + const bool accepted = state.infer_boss_from_opponent(); + if (accepted != m_scenario.expected_accepted){ + return std::format("Expected opponent accepted={}, got {}", m_scenario.expected_accepted, accepted); + } + if (state.boss != m_scenario.expected_boss){ + return std::format("Expected boss '{}', got '{}'", m_scenario.expected_boss, state.boss); + } + const std::string caught = state.caught_boss(m_scenario.caught_count); + if (caught != m_scenario.expected_caught_boss){ + return std::format("Expected caught boss '{}', got '{}'", m_scenario.expected_caught_boss, caught); + } + return true; + } + +private: + BossStateCase m_scenario; +}; + +void add_tests_MaxLairBossState(UnitTestDatabase& database){ + const BossStateCase cases[] = { + {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .caught_count = 3, + .expected_accepted = true, .expected_boss = "", .expected_caught_boss = ""}, + {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .caught_count = 3, + .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_caught_boss = "mimikyu-disguised"}, + {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .caught_count = 3, + .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_caught_boss = "mimikyu-disguised"}, + {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .caught_count = 3, + .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .caught_count = 4, + .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .caught_count = 2, + .expected_accepted = false, .expected_boss = "", .expected_caught_boss = ""}, + {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .caught_count = 3, + .expected_accepted = true, .expected_boss = "", .expected_caught_boss = ""}, + {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .caught_count = 3, + .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .caught_count = 3, + .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + {.name = "four catches after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .caught_count = 4, + .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_caught_boss = "mimikyu-disguised"}, + }; + for (const BossStateCase& scenario : cases){ + database.add(scenario); + } +} +} + void add_tests(UnitTestDatabase& database){ + add_tests_MaxLairBossState(database); NintendoSwitch::PokemonSwSh::add_tests_DialogBoxDetector(database); NintendoSwitch::PokemonSwSh::add_tests_DialogTriangleDetector(database); NintendoSwitch::PokemonSwSh::add_tests_BoxGenderDetector(database); From 7e8668a005a2a1da4a14e6f0b1dcff80d679b138 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:14:00 -0800 Subject: [PATCH 2/9] Max Lair: rename the boss helpers to accept_opponent() and boss_if_caught() Comment the boss field and boss_if_caught() so the two are told apart: the boss known all adventure long versus the boss only when the adventure caught it, for the end-of-adventure decision. No behaviour change. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 4 +-- .../Framework/PokemonSwSh_MaxLair_State.h | 19 ++++++++---- .../PokemonSwSh_MaxLair_Run_Battle.cpp | 2 +- .../PokemonSwSh_MaxLair_Run_CaughtScreen.cpp | 2 +- .../PokemonSwSh/PokemonSwSh_Tests.cpp | 30 +++++++++---------- 5 files changed, 32 insertions(+), 25 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp index c8307a2477..14887403e1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -14,7 +14,7 @@ namespace PokemonSwSh{ namespace MaxLairInternal{ -bool GlobalState::infer_boss_from_opponent(){ +bool GlobalState::accept_opponent(){ const std::string slug = opponent.empty() ? "" : *opponent.begin(); // A boss before the end means something is out-of-sync. if (wins != 3 && is_boss(slug)){ @@ -26,7 +26,7 @@ bool GlobalState::infer_boss_from_opponent(){ } return true; } -std::string GlobalState::caught_boss(size_t) const{ +std::string GlobalState::boss_if_caught(size_t) const{ // The identified boss is reported whether or not it was caught. return boss; } diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h index c1bb7c7665..efa670e99e 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -146,6 +146,10 @@ struct GlobalState{ bool adventure_started = false; + // The adventure's boss as known from the start: the den's boss sprite, + // voted across consoles. Used all adventure long (path and move choice, + // the boss ball, the fourth battle's check, Save Path) and kept after a + // lost adventure. std::string boss; PathMap path; @@ -168,13 +172,16 @@ struct GlobalState{ size_t find_player_index(size_t console_id) const; void clear_battle_state(); - // Check the opponent against the current battle stage and infer the boss. - // Returns false when the read is out-of-sync with the battle stage. - bool infer_boss_from_opponent(); + // Returns false when the opponent read doesn't fit this battle stage (a + // boss before the fourth battle), so the caller retries the read. On an + // accepted read at the fourth battle, records the boss if none is known. + bool accept_opponent(); - // Return the boss slug passed to end_adventure_action() after - // caught_count Pokemon were caught. - std::string caught_boss(size_t caught_count) const; + // The same boss, but only if the adventure caught it (all four catches), + // else empty: for the end-of-adventure decision (end_adventure_action()), + // which must not apply the boss-caught rules after a loss. + // For now this returns boss whatever caught_count is. + std::string boss_if_caught(size_t caught_count) const; std::string dump() const; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp index 4da9df3d27..ba8dcd4059 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp @@ -110,7 +110,7 @@ bool read_battle_menu( context.wait_for_all_requests(); - if (!state.infer_boss_from_opponent()){ + if (!state.accept_opponent()){ stream.log("Boss found before 3 wins. Something is seriously out-of-sync.", COLOR_RED); dump_image(stream.logger(), MODULE_NAME, "BossBeforeEnd", snapshot); return false; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp index 40262944c8..9fc4abaacf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp @@ -202,7 +202,7 @@ StateMachineAction run_caught_screen( } - const std::string boss = state_tracker[console_index].caught_boss(tracker.total()); + const std::string boss = state_tracker[console_index].boss_if_caught(tracker.total()); CaughtScreenAction action = decider.end_adventure_action( console_index, boss, diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp index 2e3c1280d7..96dc9441b0 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp @@ -34,7 +34,7 @@ struct BossStateCase{ size_t caught_count; bool expected_accepted; std::string expected_boss; - std::string expected_caught_boss; + std::string expected_boss_if_caught; }; class Test_MaxLairBossState : public UnitTest{ @@ -49,16 +49,16 @@ class Test_MaxLairBossState : public UnitTest{ state.wins = m_scenario.wins; state.opponent = m_scenario.opponent; state.boss = m_scenario.boss; - const bool accepted = state.infer_boss_from_opponent(); + const bool accepted = state.accept_opponent(); if (accepted != m_scenario.expected_accepted){ return std::format("Expected opponent accepted={}, got {}", m_scenario.expected_accepted, accepted); } if (state.boss != m_scenario.expected_boss){ return std::format("Expected boss '{}', got '{}'", m_scenario.expected_boss, state.boss); } - const std::string caught = state.caught_boss(m_scenario.caught_count); - if (caught != m_scenario.expected_caught_boss){ - return std::format("Expected caught boss '{}', got '{}'", m_scenario.expected_caught_boss, caught); + const std::string caught = state.boss_if_caught(m_scenario.caught_count); + if (caught != m_scenario.expected_boss_if_caught){ + return std::format("Expected boss_if_caught '{}', got '{}'", m_scenario.expected_boss_if_caught, caught); } return true; } @@ -70,25 +70,25 @@ class Test_MaxLairBossState : public UnitTest{ void add_tests_MaxLairBossState(UnitTestDatabase& database){ const BossStateCase cases[] = { {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .caught_count = 3, - .expected_accepted = true, .expected_boss = "", .expected_caught_boss = ""}, + .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .caught_count = 3, - .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_caught_boss = "mimikyu-disguised"}, + .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .caught_count = 3, - .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_caught_boss = "mimikyu-disguised"}, + .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .caught_count = 3, - .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .caught_count = 4, - .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .caught_count = 2, - .expected_accepted = false, .expected_boss = "", .expected_caught_boss = ""}, + .expected_accepted = false, .expected_boss = "", .expected_boss_if_caught = ""}, {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .caught_count = 3, - .expected_accepted = true, .expected_boss = "", .expected_caught_boss = ""}, + .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .caught_count = 3, - .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .caught_count = 3, - .expected_accepted = true, .expected_boss = "kyurem", .expected_caught_boss = "kyurem"}, + .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "four catches after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .caught_count = 4, - .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_caught_boss = "mimikyu-disguised"}, + .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, }; for (const BossStateCase& scenario : cases){ database.add(scenario); From fd8407622bcb28e6cf22994666d95c82a42cbae1 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:28:34 -0800 Subject: [PATCH 3/9] Max Lair: decide boss_if_caught() from the battles won boss_if_caught() no longer takes the caught count: whether the boss was caught is decided from GlobalState::wins (the boss is the fourth battle), so it stays right if non-boss catches are ever skipped. It still returns the boss whatever the battles won; the tests set wins on the caught screen instead of passing a count. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 2 +- .../Framework/PokemonSwSh_MaxLair_State.h | 12 +++++---- .../PokemonSwSh_MaxLair_Run_CaughtScreen.cpp | 2 +- .../PokemonSwSh/PokemonSwSh_Tests.cpp | 25 ++++++++++--------- 4 files changed, 22 insertions(+), 19 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp index 14887403e1..f2f3620cef 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -26,7 +26,7 @@ bool GlobalState::accept_opponent(){ } return true; } -std::string GlobalState::boss_if_caught(size_t) const{ +std::string GlobalState::boss_if_caught() const{ // The identified boss is reported whether or not it was caught. return boss; } diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h index efa670e99e..e6aa8e7050 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -177,11 +177,13 @@ struct GlobalState{ // accepted read at the fourth battle, records the boss if none is known. bool accept_opponent(); - // The same boss, but only if the adventure caught it (all four catches), - // else empty: for the end-of-adventure decision (end_adventure_action()), - // which must not apply the boss-caught rules after a loss. - // For now this returns boss whatever caught_count is. - std::string boss_if_caught(size_t caught_count) const; + // The same boss, but only if the adventure caught it, else empty: for the + // end-of-adventure decision (end_adventure_action()), which must not apply + // the boss-caught rules after a loss. Decided from the battles won (the + // boss is the fourth battle), not from how many Pokemon were caught, so it + // stays right if non-boss catches are ever skipped. + // For now this returns boss whatever the battles won. + std::string boss_if_caught() const; std::string dump() const; }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp index 9fc4abaacf..6091b3daae 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Program/PokemonSwSh_MaxLair_Run_CaughtScreen.cpp @@ -202,7 +202,7 @@ StateMachineAction run_caught_screen( } - const std::string boss = state_tracker[console_index].boss_if_caught(tracker.total()); + const std::string boss = state_tracker[console_index].boss_if_caught(); CaughtScreenAction action = decider.end_adventure_action( console_index, boss, diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp index 96dc9441b0..ee984d7f82 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp @@ -31,7 +31,7 @@ struct BossStateCase{ uint8_t wins; std::set opponent; std::string boss; - size_t caught_count; + uint8_t final_wins; // wins on the caught screen bool expected_accepted; std::string expected_boss; std::string expected_boss_if_caught; @@ -56,7 +56,8 @@ class Test_MaxLairBossState : public UnitTest{ if (state.boss != m_scenario.expected_boss){ return std::format("Expected boss '{}', got '{}'", m_scenario.expected_boss, state.boss); } - const std::string caught = state.boss_if_caught(m_scenario.caught_count); + state.wins = m_scenario.final_wins; + const std::string caught = state.boss_if_caught(); if (caught != m_scenario.expected_boss_if_caught){ return std::format("Expected boss_if_caught '{}', got '{}'", m_scenario.expected_boss_if_caught, caught); } @@ -69,25 +70,25 @@ class Test_MaxLairBossState : public UnitTest{ void add_tests_MaxLairBossState(UnitTestDatabase& database){ const BossStateCase cases[] = { - {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .caught_count = 3, + {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, - {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .caught_count = 3, + {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .caught_count = 3, + {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .caught_count = 3, + {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .caught_count = 4, + {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .caught_count = 2, + {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2, .expected_accepted = false, .expected_boss = "", .expected_boss_if_caught = ""}, - {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .caught_count = 3, + {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, - {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .caught_count = 3, + {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .caught_count = 3, + {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - {.name = "four catches after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .caught_count = 4, + {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, }; for (const BossStateCase& scenario : cases){ From 033c76e63f4f0ceb882b722dbb790eb227169908 Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:43:15 -0800 Subject: [PATCH 4/9] SwSh Max Lair: mark the boss-state cases the next PR fixes Comments on the MaxLairBossState cases that record main's wrong behaviour, and a blank line between accept_opponent() and boss_if_caught(). Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp | 1 + .../Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp index f2f3620cef..ee479f8a70 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -26,6 +26,7 @@ bool GlobalState::accept_opponent(){ } return true; } + std::string GlobalState::boss_if_caught() const{ // The identified boss is reported whether or not it was caught. return boss; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp index ee984d7f82..0e1f8281ee 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp @@ -69,25 +69,33 @@ class Test_MaxLairBossState : public UnitTest{ }; void add_tests_MaxLairBossState(UnitTestDatabase& database){ + // Cases marked BUG record main's current, wrong behaviour; the next PR (#172) fixes them. const BossStateCase cases[] = { {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, + // BUG: main accepts a rental (Mimikyu) as the boss and reports it caught; the next PR (#172) makes this retry. {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, + // BUG: main keeps the rental it misread as the boss after the real boss is read; #172 replaces it with Kyurem. {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, + // BUG: main reports the boss as caught although the run ended without a fourth win; #172 reports no catch. {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2, .expected_accepted = false, .expected_boss = "", .expected_boss_if_caught = ""}, + // BUG: main accepts a boss stage where no opponent was read; #172 makes this retry. {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, + // BUG: main accepts a two-candidate read and takes the first as the boss; #172 makes this retry. {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, + // BUG: main accepts a rental read at the boss stage and reports the boss caught without a fourth win; #172 makes this retry and reports no catch. {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, + // BUG: main accepts a rental read and reports the rental as the caught boss; #172 makes this retry and reports no catch. {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, }; From e819c821e15792055e0e8662b3325e9dd4b55b6a Mon Sep 17 00:00:00 2001 From: dayfine Date: Mon, 2 Nov 2026 11:44:23 -0800 Subject: [PATCH 5/9] SwSh Max Lair: word the boss-state notes as TODOs Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E --- .../VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp index 0e1f8281ee..780a046ef1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp @@ -69,33 +69,33 @@ class Test_MaxLairBossState : public UnitTest{ }; void add_tests_MaxLairBossState(UnitTestDatabase& database){ - // Cases marked BUG record main's current, wrong behaviour; the next PR (#172) fixes them. + // Cases marked TODO record the current, wrong behaviour. const BossStateCase cases[] = { {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, - // BUG: main accepts a rental (Mimikyu) as the boss and reports it caught; the next PR (#172) makes this retry. + // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - // BUG: main keeps the rental it misread as the boss after the real boss is read; #172 replaces it with Kyurem. + // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - // BUG: main reports the boss as caught although the run ended without a fourth win; #172 reports no catch. + // TODO: to be fixed: the boss is reported caught without a fourth win. {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2, .expected_accepted = false, .expected_boss = "", .expected_boss_if_caught = ""}, - // BUG: main accepts a boss stage where no opponent was read; #172 makes this retry. + // TODO: to be fixed: a boss stage with no opponent read is accepted. {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, - // BUG: main accepts a two-candidate read and takes the first as the boss; #172 makes this retry. + // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - // BUG: main accepts a rental read at the boss stage and reports the boss caught without a fourth win; #172 makes this retry and reports no catch. + // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3, .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - // BUG: main accepts a rental read and reports the rental as the caught boss; #172 makes this retry and reports no catch. + // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4, .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, }; From 09e2b8cf6514af5dbe5d1f05b04c34e0600cb85a Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 21:15:56 -0800 Subject: [PATCH 6/9] Max Lair: add is_boss_battle() helper and rename slug to opponent_slug --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp index ee479f8a70..b6bd7a8349 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -14,15 +14,25 @@ namespace PokemonSwSh{ namespace MaxLairInternal{ +namespace{ + +// wins is incremented after each battle is won: battles 1-3 (wins < 3) are +// against rental Pokemon, and battle 4 (wins == 3) is against the legendary boss. +bool is_boss_battle(const GlobalState& state){ + return state.wins == 3; +} + +} // namespace + bool GlobalState::accept_opponent(){ - const std::string slug = opponent.empty() ? "" : *opponent.begin(); + const std::string opponent_slug = opponent.empty() ? "" : *opponent.begin(); // A boss before the end means something is out-of-sync. - if (wins != 3 && is_boss(slug)){ + if (!is_boss_battle(*this) && is_boss(opponent_slug)){ return false; } // Infer the boss if we don't know it. - if (wins == 3 && boss.empty()){ - boss = slug; + if (is_boss_battle(*this) && boss.empty()){ + boss = opponent_slug; } return true; } From f6b95cdc4ef8250bd70b768a29754c0c7c2bd788 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 21:37:32 -0800 Subject: [PATCH 7/9] SwSh MaxLair: move boss state tests to PokemonSwSh_MaxLair_State_Tests --- .../PokemonSwSh_MaxLair_State_Tests.cpp | 129 ++++++++++++++++++ .../PokemonSwSh_MaxLair_State_Tests.h | 25 ++++ .../PokemonSwSh/PokemonSwSh_Tests.cpp | 87 +----------- SerialPrograms/cmake/SourceFiles.cmake | 2 + 4 files changed, 158 insertions(+), 85 deletions(-) create mode 100644 SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp create mode 100644 SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp new file mode 100644 index 0000000000..036bd9f35a --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp @@ -0,0 +1,129 @@ +/* Max Lair State Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#include +#include +#include "Common/Cpp/TestRunners/UnitTest.h" +#include "VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h" +#include "PokemonSwSh_MaxLair_State_Tests.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSwSh{ +namespace MaxLairInternal{ +namespace{ + +struct BossStateTestCaseInput{ + std::string name; + uint8_t wins; + std::set opponent; + std::string boss; + uint8_t final_wins; // wins on the caught screen +}; + +struct BossStateTestCaseExpectation{ + bool accepted; + std::string boss; + std::string boss_if_caught; +}; + +using BossStateTestCase = std::pair; + +class Test_MaxLairBossState : public UnitTest{ +public: + explicit Test_MaxLairBossState(BossStateTestCase scenario) + : UnitTest("PokemonSwSh::MaxLairBossState - " + scenario.first.name) + , m_scenario(std::move(scenario)) + {} + + virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const BossStateTestCaseInput& input = m_scenario.first; + const BossStateTestCaseExpectation& expected = m_scenario.second; + GlobalState state; + state.wins = input.wins; + state.opponent = input.opponent; + state.boss = input.boss; + const bool accepted = state.accept_opponent(); + if (accepted != expected.accepted){ + return std::format("Expected opponent accepted={}, got {}", expected.accepted, accepted); + } + if (state.boss != expected.boss){ + return std::format("Expected boss '{}', got '{}'", expected.boss, state.boss); + } + state.wins = input.final_wins; + const std::string caught = state.boss_if_caught(); + if (caught != expected.boss_if_caught){ + return std::format("Expected boss_if_caught '{}', got '{}'", expected.boss_if_caught, caught); + } + return true; + } + +private: + BossStateTestCase m_scenario; +}; + +} + +void add_tests_MaxLairBossState(UnitTestDatabase& database){ + // Cases marked TODO record the current, wrong behaviour. + const BossStateTestCase cases[] = { + { + {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + {.accepted = true, .boss = "", .boss_if_caught = ""}, + }, + // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. + { + {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + }, + // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. + { + {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, + {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + }, + // TODO: to be fixed: the boss is reported caught without a fourth win. + { + {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3}, + {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + { + {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, + {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + { + {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2}, + {.accepted = false, .boss = "", .boss_if_caught = ""}, + }, + // TODO: to be fixed: a boss stage with no opponent read is accepted. + { + {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, + {.accepted = true, .boss = "", .boss_if_caught = ""}, + }, + // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. + { + {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, + {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. + { + {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, + {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. + { + {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, + {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + }, + }; + for (const BossStateTestCase& scenario : cases){ + database.add(scenario); + } +} + +} +} +} +} diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h new file mode 100644 index 0000000000..3044aa1792 --- /dev/null +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h @@ -0,0 +1,25 @@ +/* Max Lair State Tests + * + * From: https://github.com/PokemonAutomation/ + * + */ + +#ifndef PokemonAutomation_PokemonSwSh_MaxLair_State_Tests_H +#define PokemonAutomation_PokemonSwSh_MaxLair_State_Tests_H + +#include "Common/Cpp/TestRunners/UnitTestDatabase.h" + +namespace PokemonAutomation{ +namespace NintendoSwitch{ +namespace PokemonSwSh{ +namespace MaxLairInternal{ + + +void add_tests_MaxLairBossState(UnitTestDatabase& database); + + +} +} +} +} +#endif diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp index 780a046ef1..a6190002a1 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/PokemonSwSh_Tests.cpp @@ -4,9 +4,7 @@ * */ -#include #include "Common/Cpp/TestRunners/UnitTestDatabase.h" -#include "VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_DialogBoxDetector.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_DialogTriangleDetector.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_BoxGenderDetector.h" @@ -14,6 +12,7 @@ #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_MainMenuDetector.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_YCommDetector.h" #include "VideoGames/PokemonSwSh/Inference/PokemonSwSh_SelectionArrowFinder.h" +#include "VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h" #include "VideoGames/PokemonSwSh/MaxLair/Inference/PokemonSwSh_MaxLair_Detect_BattleMenu.h" #include "PokemonSwSh_Tests.h" @@ -23,90 +22,7 @@ namespace PokemonSwSh{ -namespace{ -using MaxLairInternal::GlobalState; - -struct BossStateCase{ - std::string name; - uint8_t wins; - std::set opponent; - std::string boss; - uint8_t final_wins; // wins on the caught screen - bool expected_accepted; - std::string expected_boss; - std::string expected_boss_if_caught; -}; - -class Test_MaxLairBossState : public UnitTest{ -public: - explicit Test_MaxLairBossState(BossStateCase scenario) - : UnitTest("PokemonSwSh::MaxLairBossState - " + scenario.name) - , m_scenario(std::move(scenario)) - {} - - virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - GlobalState state; - state.wins = m_scenario.wins; - state.opponent = m_scenario.opponent; - state.boss = m_scenario.boss; - const bool accepted = state.accept_opponent(); - if (accepted != m_scenario.expected_accepted){ - return std::format("Expected opponent accepted={}, got {}", m_scenario.expected_accepted, accepted); - } - if (state.boss != m_scenario.expected_boss){ - return std::format("Expected boss '{}', got '{}'", m_scenario.expected_boss, state.boss); - } - state.wins = m_scenario.final_wins; - const std::string caught = state.boss_if_caught(); - if (caught != m_scenario.expected_boss_if_caught){ - return std::format("Expected boss_if_caught '{}', got '{}'", m_scenario.expected_boss_if_caught, caught); - } - return true; - } - -private: - BossStateCase m_scenario; -}; - -void add_tests_MaxLairBossState(UnitTestDatabase& database){ - // Cases marked TODO record the current, wrong behaviour. - const BossStateCase cases[] = { - {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, - .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, - // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. - {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3, - .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. - {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3, - .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - // TODO: to be fixed: the boss is reported caught without a fourth win. - {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3, - .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4, - .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2, - .expected_accepted = false, .expected_boss = "", .expected_boss_if_caught = ""}, - // TODO: to be fixed: a boss stage with no opponent read is accepted. - {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3, - .expected_accepted = true, .expected_boss = "", .expected_boss_if_caught = ""}, - // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. - {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3, - .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. - {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3, - .expected_accepted = true, .expected_boss = "kyurem", .expected_boss_if_caught = "kyurem"}, - // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. - {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4, - .expected_accepted = true, .expected_boss = "mimikyu-disguised", .expected_boss_if_caught = "mimikyu-disguised"}, - }; - for (const BossStateCase& scenario : cases){ - database.add(scenario); - } -} -} - void add_tests(UnitTestDatabase& database){ - add_tests_MaxLairBossState(database); NintendoSwitch::PokemonSwSh::add_tests_DialogBoxDetector(database); NintendoSwitch::PokemonSwSh::add_tests_DialogTriangleDetector(database); NintendoSwitch::PokemonSwSh::add_tests_BoxGenderDetector(database); @@ -115,6 +31,7 @@ void add_tests(UnitTestDatabase& database){ NintendoSwitch::PokemonSwSh::add_tests_YCommDetector(database); NintendoSwitch::PokemonSwSh::add_tests_SelectionArrowFinder(database); NintendoSwitch::PokemonSwSh::MaxLairInternal::add_tests_MaxLairBattleMenuDetector(database); + NintendoSwitch::PokemonSwSh::MaxLairInternal::add_tests_MaxLairBossState(database); } diff --git a/SerialPrograms/cmake/SourceFiles.cmake b/SerialPrograms/cmake/SourceFiles.cmake index 8af8c7d6c7..32c8dbf362 100644 --- a/SerialPrograms/cmake/SourceFiles.cmake +++ b/SerialPrograms/cmake/SourceFiles.cmake @@ -2876,6 +2876,8 @@ file(GLOB LIBRARY_SOURCES Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_Notifications.h Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h + Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp + Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.h Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_StateMachine.cpp Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_StateMachine.h Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_StateTracker.cpp From aab7407872efaa5fe3808779090dae094f9e0407 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 21:40:56 -0800 Subject: [PATCH 8/9] SwSh MaxLair: make BossStateTestCase a struct with input and expectation fields --- .../PokemonSwSh_MaxLair_State_Tests.cpp | 51 ++++++++++--------- 1 file changed, 27 insertions(+), 24 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp index 036bd9f35a..451ffe0e52 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp @@ -30,18 +30,21 @@ struct BossStateTestCaseExpectation{ std::string boss_if_caught; }; -using BossStateTestCase = std::pair; +struct BossStateTestCase{ + BossStateTestCaseInput input; + BossStateTestCaseExpectation expectation; +}; class Test_MaxLairBossState : public UnitTest{ public: explicit Test_MaxLairBossState(BossStateTestCase scenario) - : UnitTest("PokemonSwSh::MaxLairBossState - " + scenario.first.name) + : UnitTest("PokemonSwSh::MaxLairBossState - " + scenario.input.name) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const BossStateTestCaseInput& input = m_scenario.first; - const BossStateTestCaseExpectation& expected = m_scenario.second; + const BossStateTestCaseInput& input = m_scenario.input; + const BossStateTestCaseExpectation& expected = m_scenario.expectation; GlobalState state; state.wins = input.wins; state.opponent = input.opponent; @@ -71,51 +74,51 @@ void add_tests_MaxLairBossState(UnitTestDatabase& database){ // Cases marked TODO record the current, wrong behaviour. const BossStateTestCase cases[] = { { - {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, - {.accepted = true, .boss = "", .boss_if_caught = ""}, + .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, }, // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. { - {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, - {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + .input = {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, }, // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. { - {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, - {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + .input = {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, }, // TODO: to be fixed: the boss is reported caught without a fourth win. { - {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3}, - {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + .input = {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, }, { - {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, - {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + .input = {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, }, { - {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2}, - {.accepted = false, .boss = "", .boss_if_caught = ""}, + .input = {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2}, + .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, }, // TODO: to be fixed: a boss stage with no opponent read is accepted. { - {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, - {.accepted = true, .boss = "", .boss_if_caught = ""}, + .input = {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, }, // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. { - {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, - {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + .input = {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, }, // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. { - {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, - {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + .input = {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, }, // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. { - {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, - {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + .input = {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, }, }; for (const BossStateTestCase& scenario : cases){ From 4eb6d5a270d1d16929fdcf6837d1fd7bf288be72 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 3 Nov 2026 21:47:38 -0800 Subject: [PATCH 9/9] SwSh MaxLair: move test case table to unnamed namespace for code health --- .../PokemonSwSh_MaxLair_State_Tests.cpp | 103 +++++++++--------- 1 file changed, 52 insertions(+), 51 deletions(-) diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp index 451ffe0e52..b5b27ac65b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp @@ -68,60 +68,61 @@ class Test_MaxLairBossState : public UnitTest{ BossStateTestCase m_scenario; }; +// Cases marked TODO record the current, wrong behaviour. +const BossStateTestCase CASES[] = { + { + .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, + }, + // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. + { + .input = {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + }, + // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. + { + .input = {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + }, + // TODO: to be fixed: the boss is reported caught without a fourth win. + { + .input = {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + { + .input = {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + { + .input = {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2}, + .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, + }, + // TODO: to be fixed: a boss stage with no opponent read is accepted. + { + .input = {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, + }, + // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. + { + .input = {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. + { + .input = {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, + }, + // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. + { + .input = {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + }, +}; + } void add_tests_MaxLairBossState(UnitTestDatabase& database){ - // Cases marked TODO record the current, wrong behaviour. - const BossStateTestCase cases[] = { - { - .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, - }, - // TODO: to be fixed: a rental at the boss stage is accepted as the boss and reported caught. - { - .input = {.name = "Mimikyu at boss stage", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, - }, - // TODO: to be fixed: a rental misread as the boss is kept after the real boss is read. - { - .input = {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, - }, - // TODO: to be fixed: the boss is reported caught without a fourth win. - { - .input = {.name = "identified boss lost", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, - }, - { - .input = {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, - .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, - }, - { - .input = {.name = "boss before three wins must retry", .wins = 2, .opponent = {"kyurem"}, .boss = "", .final_wins = 2}, - .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, - }, - // TODO: to be fixed: a boss stage with no opponent read is accepted. - { - .input = {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, - }, - // TODO: to be fixed: a two-candidate read is accepted and the first is taken as the boss. - { - .input = {.name = "ambiguous boss-stage read", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, - }, - // TODO: to be fixed: a rental read at the boss stage is accepted, and the boss is reported caught without a fourth win. - { - .input = {.name = "rental read after known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, - }, - // TODO: to be fixed: a rental read at the boss stage is accepted and the rental is reported as the caught boss. - { - .input = {.name = "fourth win after rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, - .expectation = {.accepted = true, .boss = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, - }, - }; - for (const BossStateTestCase& scenario : cases){ + for (const BossStateTestCase& scenario : CASES){ database.add(scenario); } }