From c9066b38814f75045b793fff74c134bbc9864e9e Mon Sep 17 00:00:00 2001 From: dayfine Date: Thu, 5 Nov 2026 23:06:23 -0800 Subject: [PATCH 1/7] Fix Max Lair boss inference and boss-catch reporting --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 23 +++++++++---- .../Framework/PokemonSwSh_MaxLair_State.h | 11 ++++--- .../PokemonSwSh_MaxLair_State_Tests.cpp | 32 +++++++------------ .../Options/PokemonSwSh_MaxLair_Options.h | 1 + .../PokemonSwSh_MaxLair_Run_Battle.cpp | 13 +++----- 5 files changed, 41 insertions(+), 39 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 b6bd7a8349..5267153517 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -24,22 +24,31 @@ bool is_boss_battle(const GlobalState& state){ } // namespace +bool GlobalState::in_boss_battle_with_known_boss() const{ + return is_boss_battle(*this) && is_boss(boss); +} + bool GlobalState::accept_opponent(){ - const std::string opponent_slug = opponent.empty() ? "" : *opponent.begin(); - // A boss before the end means something is out-of-sync. - if (!is_boss_battle(*this) && is_boss(opponent_slug)){ + if (opponent.size() != 1){ + return false; + } + const std::string& opponent_slug = *opponent.begin(); + // Reject the OCR read if the opponent species doesn't match the current stage: + // a legendary boss read during battles 1-3, or a non-boss rental read in battle 4. + if (is_boss(opponent_slug) != is_boss_battle(*this)){ return false; } - // Infer the boss if we don't know it. - if (is_boss_battle(*this) && boss.empty()){ + if (is_boss_battle(*this) && !in_boss_battle_with_known_boss()){ boss = opponent_slug; } return true; } std::string GlobalState::boss_if_caught() const{ - // The identified boss is reported whether or not it was caught. - return boss; + // A failed adventure (e.g. wins == 3, only lost to the boss) can still have + // an identified boss, but no boss catch: catching the boss requires winning + // the fourth battle (wins == 4). + return wins == 4 && is_boss(boss) ? boss : ""; } std::string PlayerState::dump() const{ 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 e6aa8e7050..f0c51b8978 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -172,9 +172,13 @@ struct GlobalState{ size_t find_player_index(size_t console_id) const; void clear_battle_state(); - // 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. + // True during the fourth (boss) battle when a boss has already been identified. + bool in_boss_battle_with_known_boss() const; + + // Returns false when the opponent read doesn't fit this battle stage (not + // exactly one opponent, or a boss before the fourth battle / a rental at + // it), so the caller retries the read. On an accepted read at the fourth + // battle, records the boss unless a boss is already known. bool accept_opponent(); // The same boss, but only if the adventure caught it, else empty: for the @@ -182,7 +186,6 @@ struct GlobalState{ // 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/Framework/PokemonSwSh_MaxLair_State_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp index b5b27ac65b..ebdd434f3a 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,26 +68,22 @@ 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"}, + .input = {.name = "Mimikyu at boss stage must retry", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, }, - // 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"}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = ""}, }, - // 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"}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = ""}, }, { .input = {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, @@ -97,25 +93,21 @@ const BossStateTestCase CASES[] = { .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 = ""}, + .input = {.name = "empty boss-stage read must retry", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = false, .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"}, + .input = {.name = "ambiguous boss-stage read must retry", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, }, - // 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"}, + .input = {.name = "rejected read preserves known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, + .expectation = {.accepted = false, .boss = "kyurem", .boss_if_caught = ""}, }, - // 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"}, + .input = {.name = "fourth win cannot legitimize rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, + .expectation = {.accepted = false, .boss = "mimikyu-disguised", .boss_if_caught = ""}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h index c6ce85547a..28fc60e5d7 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h @@ -61,6 +61,7 @@ class EndBattleDecider{ virtual const std::string& boss_ball( size_t console_index, const std::string& boss_slug ) const = 0; + // boss_slug is empty when the adventure ended without catching the boss. virtual CaughtScreenAction end_adventure_action( size_t console_index, const std::string& boss_slug, const PathStats& path_stats, 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 ba8dcd4059..819f29cd81 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 @@ -75,12 +75,9 @@ bool read_battle_menu( std::set mon = reader.read_opponent(stream.logger(), context, stream.video()); bool retry = !process_header_read(stream.logger(), state, std::move(mon)); - std::string opponent = state.opponent.empty() - ? "" - : *state.opponent.begin(); - // If we see a boss before the end. Something is wrong. Retry. - if (state.wins != 3 && is_boss(opponent)){ + // The fourth battle must be a boss; earlier battles must be rentals. + if (!state.accept_opponent()){ retry = true; } @@ -97,7 +94,7 @@ bool read_battle_menu( pbf_mash_button(context, BUTTON_B, 3000ms); state.opponent = std::move(mon); - if (state.wins == 3 && !state.boss.empty()){ + if (state.in_boss_battle_with_known_boss()){ if (!state.opponent.empty() && *state.opponent.begin() != state.boss){ stream.log( "Inconsistent Boss: Expected " + state.boss + ", Read: " + *state.opponent.begin(), @@ -111,8 +108,8 @@ bool read_battle_menu( 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); + stream.log("Opponent does not match the battle stage after summary read.", COLOR_RED); + dump_image(stream.logger(), MODULE_NAME, "UnexpectedBattleOpponent", snapshot); return false; } From aab6684308df3e2eb1a93405531def64a216be8c Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 7 Nov 2026 20:28:08 -0800 Subject: [PATCH 2/7] Max Lair: preserve supported rental-form ambiguity Port the state fix and regressions from e17fba3fc in fork #172. Supported rental forms sharing one OCR species remain candidates before the boss stage; unrelated, unknown and boss-stage ambiguity still reject. Preserve the existing inline opponent-read flow. The 19 native state tests reproduced two failures before the fix and all pass after it. No console actions performed. --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 28 ++++++++++++- .../Framework/PokemonSwSh_MaxLair_State.h | 8 ++-- .../PokemonSwSh_MaxLair_State_Tests.cpp | 40 +++++++++++++++++++ 3 files changed, 71 insertions(+), 5 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 5267153517..021cdff794 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -22,6 +22,29 @@ bool is_boss_battle(const GlobalState& state){ return state.wins == 3; } +// Some supported rental forms share an OCR species name even after the +// summary read (Lycanroc and Basculin). Preserve that candidate set rather +// than treating it as a stage mismatch. Unrelated/unknown species are not +// interchangeable, and every candidate must have AI data and be a non-boss. +bool compatible_rental_forms(const std::set& candidates){ + if (candidates.empty()){ + return false; + } + const auto& slugs = maxlair_slugs(); + const auto first = slugs.find(*candidates.begin()); + if (first == slugs.end() || first->second.name_slug.empty()){ + return false; + } + for (const std::string& slug : candidates){ + const auto found = slugs.find(slug); + if (found == slugs.end() || found->second.name_slug != first->second.name_slug || + is_boss(slug) || get_maxlair_mon_nothrow(slug) == nullptr){ + return false; + } + } + return true; +} + } // namespace bool GlobalState::in_boss_battle_with_known_boss() const{ @@ -29,9 +52,12 @@ bool GlobalState::in_boss_battle_with_known_boss() const{ } bool GlobalState::accept_opponent(){ - if (opponent.size() != 1){ + if (opponent.empty()){ return false; } + if (opponent.size() > 1){ + return wins < 3 && compatible_rental_forms(opponent); + } const std::string& opponent_slug = *opponent.begin(); // Reject the OCR read if the opponent species doesn't match the current stage: // a legendary boss read during battles 1-3, or a non-boss rental read in battle 4. 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 f0c51b8978..7ed8720f35 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -175,10 +175,10 @@ struct GlobalState{ // True during the fourth (boss) battle when a boss has already been identified. bool in_boss_battle_with_known_boss() const; - // Returns false when the opponent read doesn't fit this battle stage (not - // exactly one opponent, or a boss before the fourth battle / a rental at - // it), so the caller retries the read. On an accepted read at the fourth - // battle, records the boss unless a boss is already known. + // Accepts one opponent matching this stage. Before the fourth battle, + // also accepts supported non-boss forms sharing one OCR species name, + // preserving the candidate set. Boss-stage reads still need one boss; + // records it unless a boss is already known. Otherwise retries the read. bool accept_opponent(); // The same boss, but only if the adventure caught it, else empty: for the 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 ebdd434f3a..aa38dd4c9e 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 @@ -56,6 +56,9 @@ class Test_MaxLairBossState : public UnitTest{ if (state.boss != expected.boss){ return std::format("Expected boss '{}', got '{}'", expected.boss, state.boss); } + if (state.opponent != input.opponent){ + return "Expected opponent candidates to be preserved."; + } state.wins = input.final_wins; const std::string caught = state.boss_if_caught(); if (caught != expected.boss_if_caught){ @@ -69,6 +72,43 @@ class Test_MaxLairBossState : public UnitTest{ }; const BossStateTestCase CASES[] = { + { + .input = {.name = "form ambiguity is only valid during rental battles", .wins = 4, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "nihilego", .final_wins = 4}, + .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = "nihilego"}, + }, + { + .input = {.name = "Lycanroc forms at battle two", .wins = 1, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "nihilego", .final_wins = 1}, + .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, + }, + { + .input = {.name = "Basculin forms at battle three", .wins = 2, .opponent = {"basculin-blue-striped", "basculin-red-striped"}, .boss = "nihilego", .final_wins = 2}, + .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, + }, + { + .input = {.name = "rental forms cannot pass boss stage", .wins = 3, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, + }, + { + .input = {.name = "different rentals are not form ambiguity", .wins = 1, .opponent = {"lycanroc-midday", "magmar"}, .boss = "nihilego", .final_wins = 1}, + .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, + }, + { + .input = {.name = "mixed boss and rental cannot pass rental stage", .wins = 1, .opponent = {"lycanroc-midday", "nihilego"}, .boss = "nihilego", .final_wins = 1}, + .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, + }, + { + .input = {.name = "unknown form slug cannot pass", .wins = 1, .opponent = {"lycanroc-midday", "lycanroc-unknown"}, .boss = "nihilego", .final_wins = 1}, + .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, + }, + { + .input = {.name = "empty rental read still rejects", .wins = 1, .opponent = {}, .boss = "nihilego", .final_wins = 1}, + .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, + }, + { + .input = {.name = "multiple boss candidates cannot infer a boss", .wins = 3, .opponent = {"kyurem", "nihilego"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = false, .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 = ""}, From 76266bac8d91436a0e29fdb89617bf18895d264a Mon Sep 17 00:00:00 2001 From: dayfine Date: Sat, 7 Nov 2026 23:43:42 -0800 Subject: [PATCH 3/7] Max Lair: keep going on an opponent misread instead of resetting A read that still doesn't fit the battle stage after the summary retry is almost always an OCR misread, and a wrong opponent only costs move choice. Log it and continue instead of resetting the adventure. The boss stays protected: accept_opponent() still never records a rental as the boss. Drop the rental-form whitelist: an ambiguous read is fine in a rental battle as long as no candidate is a boss, which is all that matters once a mismatch no longer resets. Co-Authored-By: Claude Fable 5.1 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 27 ++++++------------- .../Framework/PokemonSwSh_MaxLair_State.h | 8 +++--- .../PokemonSwSh_MaxLair_State_Tests.cpp | 8 ++---- .../PokemonSwSh_MaxLair_Run_Battle.cpp | 4 +-- 4 files changed, 17 insertions(+), 30 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 021cdff794..6ace91caef 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -22,27 +22,13 @@ bool is_boss_battle(const GlobalState& state){ return state.wins == 3; } -// Some supported rental forms share an OCR species name even after the -// summary read (Lycanroc and Basculin). Preserve that candidate set rather -// than treating it as a stage mismatch. Unrelated/unknown species are not -// interchangeable, and every candidate must have AI data and be a non-boss. -bool compatible_rental_forms(const std::set& candidates){ - if (candidates.empty()){ - return false; - } - const auto& slugs = maxlair_slugs(); - const auto first = slugs.find(*candidates.begin()); - if (first == slugs.end() || first->second.name_slug.empty()){ - return false; - } +bool has_boss_candidate(const std::set& candidates){ for (const std::string& slug : candidates){ - const auto found = slugs.find(slug); - if (found == slugs.end() || found->second.name_slug != first->second.name_slug || - is_boss(slug) || get_maxlair_mon_nothrow(slug) == nullptr){ - return false; + if (is_boss(slug)){ + return true; } } - return true; + return false; } } // namespace @@ -56,7 +42,10 @@ bool GlobalState::accept_opponent(){ return false; } if (opponent.size() > 1){ - return wins < 3 && compatible_rental_forms(opponent); + // Forms sharing one OCR species name (Lycanroc, Basculin) stay + // ambiguous even after the summary read. That is fine for a rental + // battle as long as no candidate is a boss. It cannot identify the boss. + return wins < 3 && !has_boss_candidate(opponent); } const std::string& opponent_slug = *opponent.begin(); // Reject the OCR read if the opponent species doesn't match the current stage: 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 7ed8720f35..8f28058667 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -176,9 +176,11 @@ struct GlobalState{ bool in_boss_battle_with_known_boss() const; // Accepts one opponent matching this stage. Before the fourth battle, - // also accepts supported non-boss forms sharing one OCR species name, - // preserving the candidate set. Boss-stage reads still need one boss; - // records it unless a boss is already known. Otherwise retries the read. + // also accepts an ambiguous read with no boss candidate, preserving the + // candidate set. Boss-stage reads still need one boss; records it unless + // a boss is already known. Returns false for a read that doesn't fit: + // the caller retries it through the summary, and keeps going if it + // still doesn't fit. A misread is not a reason to reset the adventure. bool accept_opponent(); // The same boss, but only if the adventure caught it, else empty: for the 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 aa38dd4c9e..666472b9ac 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 @@ -89,17 +89,13 @@ const BossStateTestCase CASES[] = { .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, }, { - .input = {.name = "different rentals are not form ambiguity", .wins = 1, .opponent = {"lycanroc-midday", "magmar"}, .boss = "nihilego", .final_wins = 1}, - .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, + .input = {.name = "two different rentals at battle two", .wins = 1, .opponent = {"lycanroc-midday", "magmar"}, .boss = "nihilego", .final_wins = 1}, + .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, }, { .input = {.name = "mixed boss and rental cannot pass rental stage", .wins = 1, .opponent = {"lycanroc-midday", "nihilego"}, .boss = "nihilego", .final_wins = 1}, .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, }, - { - .input = {.name = "unknown form slug cannot pass", .wins = 1, .opponent = {"lycanroc-midday", "lycanroc-unknown"}, .boss = "nihilego", .final_wins = 1}, - .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, - }, { .input = {.name = "empty rental read still rejects", .wins = 1, .opponent = {}, .boss = "nihilego", .final_wins = 1}, .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, 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 819f29cd81..7e2993b8d0 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 @@ -107,10 +107,10 @@ bool read_battle_menu( context.wait_for_all_requests(); + // Probably a misread. It only costs move choice; a reset would cost the adventure. if (!state.accept_opponent()){ - stream.log("Opponent does not match the battle stage after summary read.", COLOR_RED); + stream.log("Opponent does not match the battle stage after summary read. Continuing.", COLOR_RED); dump_image(stream.logger(), MODULE_NAME, "UnexpectedBattleOpponent", snapshot); - return false; } // Read misc. From 74c05121b53e4f1f487776a4c2b313626b5d7528 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 18:31:59 -0800 Subject: [PATCH 4/7] Max Lair: use is_boss_battle() for the stage check in accept_opponent() Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 6ace91caef..171132ff55 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -45,7 +45,7 @@ bool GlobalState::accept_opponent(){ // Forms sharing one OCR species name (Lycanroc, Basculin) stay // ambiguous even after the summary read. That is fine for a rental // battle as long as no candidate is a boss. It cannot identify the boss. - return wins < 3 && !has_boss_candidate(opponent); + return !is_boss_battle(*this) && !has_boss_candidate(opponent); } const std::string& opponent_slug = *opponent.begin(); // Reject the OCR read if the opponent species doesn't match the current stage: From 32c94cc434a7fd1de7e3fb0061552cc73baf4360 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 20:43:28 -0800 Subject: [PATCH 5/7] Max Lair: keep the battle read's candidates when the summary read is empty An ambiguous battle read (both Persian forms) was replaced by an empty summary read, which accept_opponent() rejects. Keeping the candidates lets a rental battle go on with the ambiguity it already accepts. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_State_Tests.cpp | 4 ++++ .../PokemonSwSh_MaxLair_Run_Battle.cpp | 20 ++++++++++++++++--- 2 files changed, 21 insertions(+), 3 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 666472b9ac..7ad67c3126 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 @@ -80,6 +80,10 @@ const BossStateTestCase CASES[] = { .input = {.name = "Lycanroc forms at battle two", .wins = 1, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "nihilego", .final_wins = 1}, .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, }, + { + .input = {.name = "Persian forms at battle one", .wins = 0, .opponent = {"persian", "persian-alola"}, .boss = "", .final_wins = 0}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, + }, { .input = {.name = "Basculin forms at battle three", .wins = 2, .opponent = {"basculin-blue-striped", "basculin-red-striped"}, .boss = "nihilego", .final_wins = 2}, .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, 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 7e2993b8d0..073cc9cdff 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 @@ -55,6 +55,20 @@ bool process_header_read( return false; } +// An empty summary read tells us less than an ambiguous header read +// (e.g. both Persian forms): keep the header's candidates. +std::set summary_or_header_read( + Logger& logger, + std::set summary, + const std::set& header +){ + if (summary.empty() && header.size() > 1){ + logger.log("Summary read failed. Keeping the battle read: " + set_to_str(header), COLOR_ORANGE); + return header; + } + return summary; +} + bool read_battle_menu( ProgramEnvironment& env, @@ -74,7 +88,7 @@ bool read_battle_menu( // Read raid mon. std::set mon = reader.read_opponent(stream.logger(), context, stream.video()); - bool retry = !process_header_read(stream.logger(), state, std::move(mon)); + bool retry = !process_header_read(stream.logger(), state, mon); // The fourth battle must be a boss; earlier battles must be rentals. if (!state.accept_opponent()){ @@ -90,9 +104,9 @@ bool read_battle_menu( context.wait_for_all_requests(); snapshot = stream.video().snapshot(); - mon = reader.read_opponent_in_summary(stream.logger(), snapshot); + std::set summary = reader.read_opponent_in_summary(stream.logger(), snapshot); pbf_mash_button(context, BUTTON_B, 3000ms); - state.opponent = std::move(mon); + state.opponent = summary_or_header_read(stream.logger(), std::move(summary), mon); if (state.in_boss_battle_with_known_boss()){ if (!state.opponent.empty() && *state.opponent.begin() != state.boss){ From 2d06ef7aa75843b888de82e6744a5a6d52e673b9 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 20:58:54 -0800 Subject: [PATCH 6/7] Max Lair: an ambiguous read is accepted only in rental battles (wins < 3) 74c05121b replaced the `wins < 3` check on ambiguous reads in accept_opponent() with `!is_boss_battle()`, which also accepted an ambiguous read at wins == 4, after the last battle. That broke the existing test "form ambiguity is only valid during rental battles". Add is_rental_battle() and use it there. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 171132ff55..6889ee649b 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -22,6 +22,11 @@ bool is_boss_battle(const GlobalState& state){ return state.wins == 3; } +// Battles 1-3 are against rentals. After the fourth there is no battle. +bool is_rental_battle(const GlobalState& state){ + return state.wins < 3; +} + bool has_boss_candidate(const std::set& candidates){ for (const std::string& slug : candidates){ if (is_boss(slug)){ @@ -45,7 +50,7 @@ bool GlobalState::accept_opponent(){ // Forms sharing one OCR species name (Lycanroc, Basculin) stay // ambiguous even after the summary read. That is fine for a rental // battle as long as no candidate is a boss. It cannot identify the boss. - return !is_boss_battle(*this) && !has_boss_candidate(opponent); + return is_rental_battle(*this) && !has_boss_candidate(opponent); } const std::string& opponent_slug = *opponent.begin(); // Reject the OCR read if the opponent species doesn't match the current stage: From 78b8bfe6e3ba7d82798c1f0a65e2ec61ebf53402 Mon Sep 17 00:00:00 2001 From: dayfine Date: Sun, 8 Nov 2026 23:16:51 -0800 Subject: [PATCH 7/7] Max Lair: limit the fix to not recording a wrong boss Back to main's behavior except one rule: at the boss stage, accept_opponent() records the boss only from a single boss-species read. A rental misread (Kyurem read as Mimikyu on 2026-11-02, which later crashed Boss Finder) no longer becomes the boss; a later turn's correct read still records it. Reverts the other changes in this PR (stage-mismatch retries, the rental-form ambiguity rules, the summary fallback, continuing instead of resetting, and boss_if_caught() requiring four wins) to keep the change to that one rule. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 45 +++--------- .../Framework/PokemonSwSh_MaxLair_State.h | 14 ++-- .../PokemonSwSh_MaxLair_State_Tests.cpp | 71 ++++++------------- .../Options/PokemonSwSh_MaxLair_Options.h | 1 - .../PokemonSwSh_MaxLair_Run_Battle.cpp | 35 ++++----- 5 files changed, 47 insertions(+), 119 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 6889ee649b..53150be1bf 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -22,53 +22,26 @@ bool is_boss_battle(const GlobalState& state){ return state.wins == 3; } -// Battles 1-3 are against rentals. After the fourth there is no battle. -bool is_rental_battle(const GlobalState& state){ - return state.wins < 3; -} - -bool has_boss_candidate(const std::set& candidates){ - for (const std::string& slug : candidates){ - if (is_boss(slug)){ - return true; - } - } - return false; -} - } // namespace -bool GlobalState::in_boss_battle_with_known_boss() const{ - return is_boss_battle(*this) && is_boss(boss); -} - bool GlobalState::accept_opponent(){ - if (opponent.empty()){ - return false; - } - if (opponent.size() > 1){ - // Forms sharing one OCR species name (Lycanroc, Basculin) stay - // ambiguous even after the summary read. That is fine for a rental - // battle as long as no candidate is a boss. It cannot identify the boss. - return is_rental_battle(*this) && !has_boss_candidate(opponent); - } - const std::string& opponent_slug = *opponent.begin(); - // Reject the OCR read if the opponent species doesn't match the current stage: - // a legendary boss read during battles 1-3, or a non-boss rental read in battle 4. - if (is_boss(opponent_slug) != is_boss_battle(*this)){ + const std::string opponent_slug = opponent.empty() ? "" : *opponent.begin(); + // A boss before the end means something is out-of-sync. + if (!is_boss_battle(*this) && is_boss(opponent_slug)){ return false; } - if (is_boss_battle(*this) && !in_boss_battle_with_known_boss()){ + // Infer the boss if we don't know it. Only a single boss species counts: + // a rental read here is a misread (Kyurem read as Mimikyu, 2026-11-02) + // and must not become the boss. A later turn's read can still record it. + if (is_boss_battle(*this) && boss.empty() && opponent.size() == 1 && is_boss(opponent_slug)){ boss = opponent_slug; } return true; } std::string GlobalState::boss_if_caught() const{ - // A failed adventure (e.g. wins == 3, only lost to the boss) can still have - // an identified boss, but no boss catch: catching the boss requires winning - // the fourth battle (wins == 4). - return wins == 4 && is_boss(boss) ? boss : ""; + // The identified boss is reported whether or not it was caught. + return boss; } std::string PlayerState::dump() const{ 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 8f28058667..4b34bfecec 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -172,15 +172,10 @@ struct GlobalState{ size_t find_player_index(size_t console_id) const; void clear_battle_state(); - // True during the fourth (boss) battle when a boss has already been identified. - bool in_boss_battle_with_known_boss() const; - - // Accepts one opponent matching this stage. Before the fourth battle, - // also accepts an ambiguous read with no boss candidate, preserving the - // candidate set. Boss-stage reads still need one boss; records it unless - // a boss is already known. Returns false for a read that doesn't fit: - // the caller retries it through the summary, and keeps going if it - // still doesn't fit. A misread is not a reason to reset the adventure. + // 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 + // and the read is a single boss species. bool accept_opponent(); // The same boss, but only if the adventure caught it, else empty: for the @@ -188,6 +183,7 @@ struct GlobalState{ // 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/Framework/PokemonSwSh_MaxLair_State_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp index 7ad67c3126..fbd162aa6e 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 @@ -56,9 +56,6 @@ class Test_MaxLairBossState : public UnitTest{ if (state.boss != expected.boss){ return std::format("Expected boss '{}', got '{}'", expected.boss, state.boss); } - if (state.opponent != input.opponent){ - return "Expected opponent candidates to be preserved."; - } state.wins = input.final_wins; const std::string caught = state.boss_if_caught(); if (caught != expected.boss_if_caught){ @@ -71,59 +68,30 @@ class Test_MaxLairBossState : public UnitTest{ BossStateTestCase m_scenario; }; +// Cases marked TODO record the current, wrong behaviour. const BossStateTestCase CASES[] = { { - .input = {.name = "form ambiguity is only valid during rental battles", .wins = 4, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "nihilego", .final_wins = 4}, - .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = "nihilego"}, - }, - { - .input = {.name = "Lycanroc forms at battle two", .wins = 1, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "nihilego", .final_wins = 1}, - .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, - }, - { - .input = {.name = "Persian forms at battle one", .wins = 0, .opponent = {"persian", "persian-alola"}, .boss = "", .final_wins = 0}, + .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, }, { - .input = {.name = "Basculin forms at battle three", .wins = 2, .opponent = {"basculin-blue-striped", "basculin-red-striped"}, .boss = "nihilego", .final_wins = 2}, - .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, - }, - { - .input = {.name = "rental forms cannot pass boss stage", .wins = 3, .opponent = {"lycanroc-midday", "lycanroc-midnight"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, - }, - { - .input = {.name = "two different rentals at battle two", .wins = 1, .opponent = {"lycanroc-midday", "magmar"}, .boss = "nihilego", .final_wins = 1}, - .expectation = {.accepted = true, .boss = "nihilego", .boss_if_caught = ""}, - }, - { - .input = {.name = "mixed boss and rental cannot pass rental stage", .wins = 1, .opponent = {"lycanroc-midday", "nihilego"}, .boss = "nihilego", .final_wins = 1}, - .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, - }, - { - .input = {.name = "empty rental read still rejects", .wins = 1, .opponent = {}, .boss = "nihilego", .final_wins = 1}, - .expectation = {.accepted = false, .boss = "nihilego", .boss_if_caught = ""}, - }, - { - .input = {.name = "multiple boss candidates cannot infer a boss", .wins = 3, .opponent = {"kyurem", "nihilego"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, - }, - - { - .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .input = {.name = "Mimikyu at boss stage is not the boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, }, { - .input = {.name = "Mimikyu at boss stage must retry", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, + .input = {.name = "Kyurem after a rejected Mimikyu read", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, }, + // A wrong boss can no longer be recorded (see the cases above); one that + // is already known is kept. { .input = {.name = "Kyurem after Mimikyu misidentification", .wins = 3, .opponent = {"kyurem"}, .boss = "mimikyu-disguised", .final_wins = 3}, - .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = ""}, + .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 = ""}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = "kyurem"}, }, { .input = {.name = "identified boss caught", .wins = 3, .opponent = {"kyurem"}, .boss = "", .final_wins = 4}, @@ -133,21 +101,24 @@ const BossStateTestCase CASES[] = { .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 must retry", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, + .input = {.name = "empty boss-stage read", .wins = 3, .opponent = {}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, }, { - .input = {.name = "ambiguous boss-stage read must retry", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, - .expectation = {.accepted = false, .boss = "", .boss_if_caught = ""}, + .input = {.name = "ambiguous boss-stage read is not the boss", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .final_wins = 3}, + .expectation = {.accepted = true, .boss = "", .boss_if_caught = ""}, }, + // 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 = "rejected read preserves known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .final_wins = 3}, - .expectation = {.accepted = false, .boss = "kyurem", .boss_if_caught = ""}, + .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: a rental boss recorded before this fix is still reported as caught. { - .input = {.name = "fourth win cannot legitimize rental boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "mimikyu-disguised", .final_wins = 4}, - .expectation = {.accepted = false, .boss = "mimikyu-disguised", .boss_if_caught = ""}, + .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"}, }, }; diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h index 28fc60e5d7..c6ce85547a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Options/PokemonSwSh_MaxLair_Options.h @@ -61,7 +61,6 @@ class EndBattleDecider{ virtual const std::string& boss_ball( size_t console_index, const std::string& boss_slug ) const = 0; - // boss_slug is empty when the adventure ended without catching the boss. virtual CaughtScreenAction end_adventure_action( size_t console_index, const std::string& boss_slug, const PathStats& path_stats, 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 073cc9cdff..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 @@ -55,20 +55,6 @@ bool process_header_read( return false; } -// An empty summary read tells us less than an ambiguous header read -// (e.g. both Persian forms): keep the header's candidates. -std::set summary_or_header_read( - Logger& logger, - std::set summary, - const std::set& header -){ - if (summary.empty() && header.size() > 1){ - logger.log("Summary read failed. Keeping the battle read: " + set_to_str(header), COLOR_ORANGE); - return header; - } - return summary; -} - bool read_battle_menu( ProgramEnvironment& env, @@ -88,10 +74,13 @@ bool read_battle_menu( // Read raid mon. std::set mon = reader.read_opponent(stream.logger(), context, stream.video()); - bool retry = !process_header_read(stream.logger(), state, mon); + bool retry = !process_header_read(stream.logger(), state, std::move(mon)); + std::string opponent = state.opponent.empty() + ? "" + : *state.opponent.begin(); - // The fourth battle must be a boss; earlier battles must be rentals. - if (!state.accept_opponent()){ + // If we see a boss before the end. Something is wrong. Retry. + if (state.wins != 3 && is_boss(opponent)){ retry = true; } @@ -104,11 +93,11 @@ bool read_battle_menu( context.wait_for_all_requests(); snapshot = stream.video().snapshot(); - std::set summary = reader.read_opponent_in_summary(stream.logger(), snapshot); + mon = reader.read_opponent_in_summary(stream.logger(), snapshot); pbf_mash_button(context, BUTTON_B, 3000ms); - state.opponent = summary_or_header_read(stream.logger(), std::move(summary), mon); + state.opponent = std::move(mon); - if (state.in_boss_battle_with_known_boss()){ + if (state.wins == 3 && !state.boss.empty()){ if (!state.opponent.empty() && *state.opponent.begin() != state.boss){ stream.log( "Inconsistent Boss: Expected " + state.boss + ", Read: " + *state.opponent.begin(), @@ -121,10 +110,10 @@ bool read_battle_menu( context.wait_for_all_requests(); - // Probably a misread. It only costs move choice; a reset would cost the adventure. if (!state.accept_opponent()){ - stream.log("Opponent does not match the battle stage after summary read. Continuing.", COLOR_RED); - dump_image(stream.logger(), MODULE_NAME, "UnexpectedBattleOpponent", snapshot); + 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; } // Read misc.