From 614bba2e1682bb9c1fe0cfe7690b2de933018f42 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 21:52:24 -0800 Subject: [PATCH 1/5] Max Lair: read the boss from the summary when it is still unknown At the boss battle, a battle-screen read that is not a single boss species now triggers the summary read, so a rental misread no longer leaves the boss empty. BossFinder falls back to the normal ball for an empty or unknown boss instead of throwing. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 11 +++++ .../Framework/PokemonSwSh_MaxLair_State.h | 5 +++ .../PokemonSwSh_MaxLair_State_Tests.cpp | 44 +++++++++++++++++++ .../PokemonSwSh_MaxLair_BossFinder.cpp | 22 +++++++--- .../PokemonSwSh_MaxLair_Run_Battle.cpp | 10 ++--- 5 files changed, 79 insertions(+), 13 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 53150be1bf..78e9ed48cd 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -39,6 +39,17 @@ bool GlobalState::accept_opponent(){ return true; } +bool GlobalState::opponent_needs_summary_read() const{ + const std::string opponent_slug = opponent.empty() ? "" : *opponent.begin(); + if (!is_boss_battle(*this)){ + // A boss before the end means the read is wrong. + return is_boss(opponent_slug); + } + // At the boss battle, read the summary until a single boss species is + // known, so a rental misread does not leave the boss empty. + return boss.empty() && !(opponent.size() == 1 && is_boss(opponent_slug)); +} + 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 4b34bfecec..34c8027c28 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -178,6 +178,11 @@ struct GlobalState{ // and the read is a single boss species. bool accept_opponent(); + // Whether the battle-screen opponent read should be replaced by a read + // from the summary: a boss before the fourth battle, or, at the fourth + // battle with no boss known yet, a read that is not a single boss species. + bool opponent_needs_summary_read() 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 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 fbd162aa6e..2ec70cfedc 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 @@ -122,12 +122,56 @@ const BossStateTestCase CASES[] = { }, }; +struct SummaryReadTestCase{ + std::string name; + uint8_t wins; + std::set opponent; + std::string boss; + bool needs_summary_read; +}; + +class Test_MaxLairSummaryRead : public UnitTest{ +public: + explicit Test_MaxLairSummaryRead(SummaryReadTestCase scenario) + : UnitTest("PokemonSwSh::MaxLairSummaryRead - " + 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 needs_read = state.opponent_needs_summary_read(); + if (needs_read != m_scenario.needs_summary_read){ + return std::format("Expected needs_summary_read={}, got {}", m_scenario.needs_summary_read, needs_read); + } + return true; + } + +private: + SummaryReadTestCase m_scenario; +}; + +const SummaryReadTestCase SUMMARY_READ_CASES[] = { + {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .needs_summary_read = false}, + {.name = "boss before three wins", .wins = 2, .opponent = {"kyurem"}, .boss = "", .needs_summary_read = true}, + {.name = "rental at boss stage with unknown boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .needs_summary_read = true}, + {.name = "empty read at boss stage with unknown boss", .wins = 3, .opponent = {}, .boss = "", .needs_summary_read = true}, + {.name = "ambiguous read at boss stage with unknown boss", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .needs_summary_read = true}, + {.name = "boss at boss stage", .wins = 3, .opponent = {"kyurem"}, .boss = "", .needs_summary_read = false}, + {.name = "rental at boss stage with known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .needs_summary_read = false}, +}; + } void add_tests_MaxLairBossState(UnitTestDatabase& database){ for (const BossStateTestCase& scenario : CASES){ database.add(scenario); } + for (const SummaryReadTestCase& scenario : SUMMARY_READ_CASES){ + database.add(scenario); + } } } diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp index 3ddd84eead..cba858097d 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp @@ -133,17 +133,23 @@ class EndBattleDecider_BossFinder : public EndBattleDecider{ virtual const std::string& boss_ball( size_t console_index, const std::string& boss_slug ) const override{ - return get_filter(boss_slug).ball.slug(); + // An unknown boss (unread or misread) falls back to the normal ball. + const BossActionRow* filter = find_filter(boss_slug); + if (filter == nullptr){ + return normal_ball(console_index); + } + return filter->ball.slug(); } virtual CaughtScreenAction end_adventure_action( size_t console_index, const std::string& boss_slug, const PathStats& path_stats, bool any_shiny, bool boss_is_shiny ) const override{ - if (boss_slug.empty()){ + const BossActionRow* filter = find_filter(boss_slug); + if (filter == nullptr){ return CaughtScreenAction::TAKE_NON_BOSS_SHINY_AND_CONTINUE; } - switch (get_filter(boss_slug).action){ + switch (filter->action){ case BossAction::CATCH_AND_STOP_PROGRAM: return CaughtScreenAction::STOP_PROGRAM; case BossAction::CATCH_AND_STOP_IF_SHINY: @@ -154,19 +160,21 @@ class EndBattleDecider_BossFinder : public EndBattleDecider{ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid enum."); } virtual bool is_in_save_list(const std::string& boss_slug) const override{ - return get_filter(boss_slug).save_on_the_go; + const BossActionRow* filter = find_filter(boss_slug); + return filter != nullptr && filter->save_on_the_go; } private: - const BossActionRow& get_filter(const std::string& boss_slug) const{ + // Returns nullptr for an empty or unrecognized boss slug. + const BossActionRow* find_filter(const std::string& boss_slug) const{ for (const StaticTableRow* row : m_boss_list.table()){ const BossActionRow& filter = static_cast(*row); if (boss_slug == filter.slug()){ - return filter; + return &filter; } } - throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unrecognized boss slug: " + boss_slug); + return nullptr; } private: 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 3685caa3a5..2507dcd9f8 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,7 @@ 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)){ + if (state.opponent_needs_summary_read()){ retry = true; } @@ -371,6 +366,9 @@ StateMachineAction throw_balls( bool boss = inferred.wins == 4; if (boss){ + if (inferred.boss.empty()){ + stream.log("Boss is unknown at the fourth win.", COLOR_RED); + } ball = decider.boss_ball(console_index, inferred.boss); }else{ ball = decider.normal_ball(console_index); From 3bd2b6a7f3d2ff66b8a66b09d930739a9ec25b2d Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 21:53:19 -0800 Subject: [PATCH 2/5] Max Lair: code health for the summary-read tests Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_State_Tests.cpp | 60 ++++++++++++++----- .../PokemonSwSh_MaxLair_Run_Battle.cpp | 3 - 2 files changed, 45 insertions(+), 18 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 2ec70cfedc..09d89188fa 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 @@ -122,29 +122,39 @@ const BossStateTestCase CASES[] = { }, }; -struct SummaryReadTestCase{ +struct SummaryReadTestCaseInput{ std::string name; uint8_t wins; std::set opponent; std::string boss; +}; + +struct SummaryReadTestCaseExpectation{ bool needs_summary_read; }; +struct SummaryReadTestCase{ + SummaryReadTestCaseInput input; + SummaryReadTestCaseExpectation expectation; +}; + class Test_MaxLairSummaryRead : public UnitTest{ public: explicit Test_MaxLairSummaryRead(SummaryReadTestCase scenario) - : UnitTest("PokemonSwSh::MaxLairSummaryRead - " + scenario.name) + : UnitTest(std::format("PokemonSwSh::MaxLairSummaryRead - {}", scenario.input.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ + const SummaryReadTestCaseInput& input = m_scenario.input; + const SummaryReadTestCaseExpectation& expected = m_scenario.expectation; GlobalState state; - state.wins = m_scenario.wins; - state.opponent = m_scenario.opponent; - state.boss = m_scenario.boss; + state.wins = input.wins; + state.opponent = input.opponent; + state.boss = input.boss; const bool needs_read = state.opponent_needs_summary_read(); - if (needs_read != m_scenario.needs_summary_read){ - return std::format("Expected needs_summary_read={}, got {}", m_scenario.needs_summary_read, needs_read); + if (needs_read != expected.needs_summary_read){ + return std::format("Expected needs_summary_read={}, got {}", expected.needs_summary_read, needs_read); } return true; } @@ -154,15 +164,35 @@ class Test_MaxLairSummaryRead : public UnitTest{ }; const SummaryReadTestCase SUMMARY_READ_CASES[] = { - {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = "", .needs_summary_read = false}, - {.name = "boss before three wins", .wins = 2, .opponent = {"kyurem"}, .boss = "", .needs_summary_read = true}, - {.name = "rental at boss stage with unknown boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "", .needs_summary_read = true}, - {.name = "empty read at boss stage with unknown boss", .wins = 3, .opponent = {}, .boss = "", .needs_summary_read = true}, - {.name = "ambiguous read at boss stage with unknown boss", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = "", .needs_summary_read = true}, - {.name = "boss at boss stage", .wins = 3, .opponent = {"kyurem"}, .boss = "", .needs_summary_read = false}, - {.name = "rental at boss stage with known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem", .needs_summary_read = false}, + { + .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = ""}, + .expectation = {.needs_summary_read = false}, + }, + { + .input = {.name = "boss before three wins", .wins = 2, .opponent = {"kyurem"}, .boss = ""}, + .expectation = {.needs_summary_read = true}, + }, + { + .input = {.name = "rental at boss stage with unknown boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = ""}, + .expectation = {.needs_summary_read = true}, + }, + { + .input = {.name = "empty read at boss stage with unknown boss", .wins = 3, .opponent = {}, .boss = ""}, + .expectation = {.needs_summary_read = true}, + }, + { + .input = {.name = "ambiguous read at boss stage with unknown boss", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = ""}, + .expectation = {.needs_summary_read = true}, + }, + { + .input = {.name = "boss at boss stage", .wins = 3, .opponent = {"kyurem"}, .boss = ""}, + .expectation = {.needs_summary_read = false}, + }, + { + .input = {.name = "rental at boss stage with known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem"}, + .expectation = {.needs_summary_read = false}, + }, }; - } void add_tests_MaxLairBossState(UnitTestDatabase& database){ 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 2507dcd9f8..acd8a5a9d1 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 @@ -358,12 +358,9 @@ StateMachineAction throw_balls( state.players[2].health.value.dead = 0; state.players[3].health.value.dead = 0; - GlobalState inferred = state_tracker.synchronize(stream.logger(), console_index); - std::string ball; - bool boss = inferred.wins == 4; if (boss){ if (inferred.boss.empty()){ From de21f801f90575333c660277ce4b77cf285945e3 Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 22:32:24 -0800 Subject: [PATCH 3/5] Max Lair: decide the boss from a read that fits the stage Add GlobalState::opponent_fits_stage() and use it in accept_opponent() and process_header_read(), so a read that does not fit the battle stage falls back to the summary read. boss_if_caught() returns the boss only after the fourth win. throw_balls() uses the normal ball when the boss is unknown, so BossFinder stays unchanged from main. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../Framework/PokemonSwSh_MaxLair_State.cpp | 36 +++++---- .../Framework/PokemonSwSh_MaxLair_State.h | 18 ++--- .../PokemonSwSh_MaxLair_State_Tests.cpp | 73 +++++++++---------- .../PokemonSwSh_MaxLair_BossFinder.cpp | 22 ++---- .../PokemonSwSh_MaxLair_Run_Battle.cpp | 33 +++++---- 5 files changed, 86 insertions(+), 96 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 78e9ed48cd..b00840ef4a 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.cpp @@ -24,35 +24,33 @@ bool is_boss_battle(const GlobalState& state){ } // namespace -bool GlobalState::accept_opponent(){ +bool GlobalState::opponent_fits_stage() const{ 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)){ + return !is_boss(opponent_slug); } - // 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; + if (!boss.empty()){ + return opponent.size() == 1 && opponent_slug == boss; } - return true; + // A rental read here is a misread (Kyurem read as Mimikyu, 2026-11-02). + return opponent.size() == 1 && is_boss(opponent_slug); } -bool GlobalState::opponent_needs_summary_read() const{ - const std::string opponent_slug = opponent.empty() ? "" : *opponent.begin(); +bool GlobalState::accept_opponent(){ + const bool fits = opponent_fits_stage(); if (!is_boss_battle(*this)){ - // A boss before the end means the read is wrong. - return is_boss(opponent_slug); + // A boss before the end means something is out-of-sync. + return fits; + } + if (boss.empty() && fits){ + boss = *opponent.begin(); } - // At the boss battle, read the summary until a single boss species is - // known, so a rental misread does not leave the boss empty. - return boss.empty() && !(opponent.size() == 1 && is_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; + // The boss is caught only if the fourth battle was won. + return wins == 4 ? 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 34c8027c28..e1ec843268 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State.h @@ -172,23 +172,21 @@ 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 - // and the read is a single boss species. + // Whether the opponent read fits this battle stage: before the fourth + // battle, any non-boss; at the fourth battle, exactly the known boss, or a + // single boss species when no boss is known yet. + bool opponent_fits_stage() const; + + // Returns false when the read doesn't fit a battle before the fourth (a + // boss there), so the caller retries the read. At the fourth battle, + // records the boss if none is known and the read fits. bool accept_opponent(); - // Whether the battle-screen opponent read should be replaced by a read - // from the summary: a boss before the fourth battle, or, at the fourth - // battle with no boss known yet, a read that is not a single boss species. - bool opponent_needs_summary_read() 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/Framework/PokemonSwSh_MaxLair_State_Tests.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/Framework/PokemonSwSh_MaxLair_State_Tests.cpp index 09d89188fa..fd6651d6ee 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,7 +68,6 @@ 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}, @@ -86,12 +85,11 @@ const BossStateTestCase CASES[] = { // 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 = "mimikyu-disguised", .boss_if_caught = "mimikyu-disguised"}, + .expectation = {.accepted = true, .boss = "mimikyu-disguised", .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}, @@ -101,7 +99,6 @@ 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 = ""}, @@ -110,87 +107,89 @@ const BossStateTestCase CASES[] = { .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 = "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 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"}, + .expectation = {.accepted = true, .boss = "kyurem", .boss_if_caught = ""}, }, }; -struct SummaryReadTestCaseInput{ +struct FitsStageTestCaseInput{ std::string name; uint8_t wins; std::set opponent; std::string boss; }; -struct SummaryReadTestCaseExpectation{ - bool needs_summary_read; +struct FitsStageTestCaseExpectation{ + bool fits; }; -struct SummaryReadTestCase{ - SummaryReadTestCaseInput input; - SummaryReadTestCaseExpectation expectation; +struct FitsStageTestCase{ + FitsStageTestCaseInput input; + FitsStageTestCaseExpectation expectation; }; -class Test_MaxLairSummaryRead : public UnitTest{ +class Test_MaxLairFitsStage : public UnitTest{ public: - explicit Test_MaxLairSummaryRead(SummaryReadTestCase scenario) - : UnitTest(std::format("PokemonSwSh::MaxLairSummaryRead - {}", scenario.input.name)) + explicit Test_MaxLairFitsStage(FitsStageTestCase scenario) + : UnitTest(std::format("PokemonSwSh::MaxLairFitsStage - {}", scenario.input.name)) , m_scenario(std::move(scenario)) {} virtual UnitTestResult run(Logger&, CancellableScope&) const override{ - const SummaryReadTestCaseInput& input = m_scenario.input; - const SummaryReadTestCaseExpectation& expected = m_scenario.expectation; + const FitsStageTestCaseInput& input = m_scenario.input; + const FitsStageTestCaseExpectation& expected = m_scenario.expectation; GlobalState state; state.wins = input.wins; state.opponent = input.opponent; state.boss = input.boss; - const bool needs_read = state.opponent_needs_summary_read(); - if (needs_read != expected.needs_summary_read){ - return std::format("Expected needs_summary_read={}, got {}", expected.needs_summary_read, needs_read); + const bool fits = state.opponent_fits_stage(); + if (fits != expected.fits){ + return std::format("Expected fits={}, got {}", expected.fits, fits); } return true; } private: - SummaryReadTestCase m_scenario; + FitsStageTestCase m_scenario; }; -const SummaryReadTestCase SUMMARY_READ_CASES[] = { +const FitsStageTestCase FITS_STAGE_CASES[] = { { .input = {.name = "rental before three wins", .wins = 2, .opponent = {"mimikyu-disguised"}, .boss = ""}, - .expectation = {.needs_summary_read = false}, + .expectation = {.fits = true}, }, { .input = {.name = "boss before three wins", .wins = 2, .opponent = {"kyurem"}, .boss = ""}, - .expectation = {.needs_summary_read = true}, + .expectation = {.fits = false}, }, { .input = {.name = "rental at boss stage with unknown boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = ""}, - .expectation = {.needs_summary_read = true}, + .expectation = {.fits = false}, }, { .input = {.name = "empty read at boss stage with unknown boss", .wins = 3, .opponent = {}, .boss = ""}, - .expectation = {.needs_summary_read = true}, + .expectation = {.fits = false}, }, { .input = {.name = "ambiguous read at boss stage with unknown boss", .wins = 3, .opponent = {"kyurem", "mimikyu-disguised"}, .boss = ""}, - .expectation = {.needs_summary_read = true}, + .expectation = {.fits = false}, }, { .input = {.name = "boss at boss stage", .wins = 3, .opponent = {"kyurem"}, .boss = ""}, - .expectation = {.needs_summary_read = false}, + .expectation = {.fits = true}, }, { .input = {.name = "rental at boss stage with known boss", .wins = 3, .opponent = {"mimikyu-disguised"}, .boss = "kyurem"}, - .expectation = {.needs_summary_read = false}, + .expectation = {.fits = false}, + }, + { + .input = {.name = "known boss at boss stage", .wins = 3, .opponent = {"kyurem"}, .boss = "kyurem"}, + .expectation = {.fits = true}, + }, + { + .input = {.name = "other boss at boss stage with known boss", .wins = 3, .opponent = {"zekrom"}, .boss = "kyurem"}, + .expectation = {.fits = false}, }, }; } @@ -199,8 +198,8 @@ void add_tests_MaxLairBossState(UnitTestDatabase& database){ for (const BossStateTestCase& scenario : CASES){ database.add(scenario); } - for (const SummaryReadTestCase& scenario : SUMMARY_READ_CASES){ - database.add(scenario); + for (const FitsStageTestCase& scenario : FITS_STAGE_CASES){ + database.add(scenario); } } diff --git a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp index cba858097d..3ddd84eead 100644 --- a/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp +++ b/SerialPrograms/Source/VideoGames/PokemonSwSh/MaxLair/PokemonSwSh_MaxLair_BossFinder.cpp @@ -133,23 +133,17 @@ class EndBattleDecider_BossFinder : public EndBattleDecider{ virtual const std::string& boss_ball( size_t console_index, const std::string& boss_slug ) const override{ - // An unknown boss (unread or misread) falls back to the normal ball. - const BossActionRow* filter = find_filter(boss_slug); - if (filter == nullptr){ - return normal_ball(console_index); - } - return filter->ball.slug(); + return get_filter(boss_slug).ball.slug(); } virtual CaughtScreenAction end_adventure_action( size_t console_index, const std::string& boss_slug, const PathStats& path_stats, bool any_shiny, bool boss_is_shiny ) const override{ - const BossActionRow* filter = find_filter(boss_slug); - if (filter == nullptr){ + if (boss_slug.empty()){ return CaughtScreenAction::TAKE_NON_BOSS_SHINY_AND_CONTINUE; } - switch (filter->action){ + switch (get_filter(boss_slug).action){ case BossAction::CATCH_AND_STOP_PROGRAM: return CaughtScreenAction::STOP_PROGRAM; case BossAction::CATCH_AND_STOP_IF_SHINY: @@ -160,21 +154,19 @@ class EndBattleDecider_BossFinder : public EndBattleDecider{ throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Invalid enum."); } virtual bool is_in_save_list(const std::string& boss_slug) const override{ - const BossActionRow* filter = find_filter(boss_slug); - return filter != nullptr && filter->save_on_the_go; + return get_filter(boss_slug).save_on_the_go; } private: - // Returns nullptr for an empty or unrecognized boss slug. - const BossActionRow* find_filter(const std::string& boss_slug) const{ + const BossActionRow& get_filter(const std::string& boss_slug) const{ for (const StaticTableRow* row : m_boss_list.table()){ const BossActionRow& filter = static_cast(*row); if (boss_slug == filter.slug()){ - return &filter; + return filter; } } - return nullptr; + throw InternalProgramError(nullptr, PA_CURRENT_FUNCTION, "Unrecognized boss slug: " + boss_slug); } private: 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 acd8a5a9d1..37af485ddd 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 @@ -32,7 +32,7 @@ bool process_header_read( ){ if (mon.size() == 1){ state.opponent = std::move(mon); - return true; + return state.opponent_fits_stage(); } if (mon.size() > 1){ logger.log("Ambiguous Read Result: " + set_to_str(mon), COLOR_PURPLE); @@ -41,7 +41,7 @@ bool process_header_read( "Using previous known value to disambiguate: " + set_to_str(mon), COLOR_PURPLE ); - return true; + return state.opponent_fits_stage(); } } if (state.opponent.size() == 1){ @@ -49,7 +49,7 @@ bool process_header_read( "Failed to read opponent from battle. Using previously known value: " + set_to_str(state.opponent), COLOR_ORANGE ); - return true; + return state.opponent_fits_stage(); } return false; @@ -75,9 +75,6 @@ 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)); - if (state.opponent_needs_summary_read()){ - retry = true; - } VideoSnapshot snapshot; if (retry){ @@ -340,6 +337,20 @@ StateMachineAction run_move_select( +std::string choose_ball( + Logger& logger, const GlobalState& inferred, + size_t console_index, const EndBattleDecider& decider +){ + if (inferred.wins != 4){ + return decider.normal_ball(console_index); + } + if (inferred.boss.empty()){ + logger.log("Boss is unknown at the fourth win. Using the normal ball.", COLOR_RED); + return decider.normal_ball(console_index); + } + return decider.boss_ball(console_index, inferred.boss); +} + StateMachineAction throw_balls( AdventureRuntime& runtime, ProgramEnvironment& env, size_t console_index, @@ -360,16 +371,8 @@ StateMachineAction throw_balls( GlobalState inferred = state_tracker.synchronize(stream.logger(), console_index); - std::string ball; bool boss = inferred.wins == 4; - if (boss){ - if (inferred.boss.empty()){ - stream.log("Boss is unknown at the fourth win.", COLOR_RED); - } - ball = decider.boss_ball(console_index, inferred.boss); - }else{ - ball = decider.normal_ball(console_index); - } + const std::string ball = choose_ball(stream.logger(), inferred, console_index, decider); BattleBallReader reader(stream, language); pbf_press_button(context, BUTTON_A, 400ms, 600ms); From df868d1c51d1abf1a5f5dd3dc623dd018331e30d Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 22:48:03 -0800 Subject: [PATCH 4/5] MaxLair: plain boss_ball call with a comment on when the boss can still be empty Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../PokemonSwSh_MaxLair_Run_Battle.cpp | 24 +++++++------------ 1 file changed, 9 insertions(+), 15 deletions(-) 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 37af485ddd..efb0b48900 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 @@ -337,20 +337,6 @@ StateMachineAction run_move_select( -std::string choose_ball( - Logger& logger, const GlobalState& inferred, - size_t console_index, const EndBattleDecider& decider -){ - if (inferred.wins != 4){ - return decider.normal_ball(console_index); - } - if (inferred.boss.empty()){ - logger.log("Boss is unknown at the fourth win. Using the normal ball.", COLOR_RED); - return decider.normal_ball(console_index); - } - return decider.boss_ball(console_index, inferred.boss); -} - StateMachineAction throw_balls( AdventureRuntime& runtime, ProgramEnvironment& env, size_t console_index, @@ -371,8 +357,16 @@ StateMachineAction throw_balls( GlobalState inferred = state_tracker.synchronize(stream.logger(), console_index); + std::string ball; + bool boss = inferred.wins == 4; - const std::string ball = choose_ball(stream.logger(), inferred, console_index, decider); + if (boss){ + // Still crashes (BossFinder throws on an empty boss) if no battle-screen + // or summary read in the boss battle gave a boss species (OCR misses). + ball = decider.boss_ball(console_index, inferred.boss); + }else{ + ball = decider.normal_ball(console_index); + } BattleBallReader reader(stream, language); pbf_press_button(context, BUTTON_A, 400ms, 600ms); From 1f7bceb36b617e055e2468e89b906c3b39e110db Mon Sep 17 00:00:00 2001 From: dayfine Date: Tue, 10 Nov 2026 22:52:20 -0800 Subject: [PATCH 5/5] MaxLair: reword the boss-ball crash comment Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss --- .../MaxLair/Program/PokemonSwSh_MaxLair_Run_Battle.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 efb0b48900..2715609322 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 @@ -361,8 +361,8 @@ StateMachineAction throw_balls( bool boss = inferred.wins == 4; if (boss){ - // Still crashes (BossFinder throws on an empty boss) if no battle-screen - // or summary read in the boss battle gave a boss species (OCR misses). + // This will crash if `inferred.boss` is still empty after battle-screen + // and the fallback summary read (OCR misses). ball = decider.boss_ball(console_index, inferred.boss); }else{ ball = decider.normal_ball(console_index);