Repository navigation
[Max Lair] Don't use a non-boss as boss in State - #1851
Conversation
|
Potentially could do more refactor of PokemonSwSh_MaxLair_Run_Battle.cpp as well and add tests there. Let me know if you prefer that to happen. |
| 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); |
There was a problem hiding this comment.
Misreads are quite common. If I'm reading this correctly, this will throw and reset the adventure on a misread even if it's temporary. This happens a lot when the opponent has a lot of bright colors and the camera pans over it with the name overlaid when the read happens.
Generally speaking, we will allow incorrect information if it still results in forward progress. But the only reason why it matters here with the boss is to avoid accidentally taking a boss.
There was a problem hiding this comment.
Yes ran into this and it reset 13 runs straight in Standard.
- Removed some sources of the misread (when opponent is indeed ambiguous)
- Removed the
return falsehere, which only affects the move selection below (so might affect win rate)
|
Because this touches a critical part of the program, and your Claude said it didn't do any actual tests, please run this for 20 - 50 adventures and log all the failures and recoveries to make sure they flow properly. Xerneas is a good candidate boss because the antlers are bright and the same color as the name at the top of the screen. So they very often will interfere with the OCR. I do know there are non-bosses that have this problem, but I don't remember any particular one off the top of my head. |
Port the state fix and regressions from e17fba3 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.
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
I ran (in Standard):
The thing with Xerneas is that I've caught it before this, so on caught menu there are always only 3 opponents even if I won. |
pa-devbot
left a comment
There was a problem hiding this comment.
AI review: Verified on the PR head: pa-build succeeds and the full CLI suite passes (20,353 passed, 0 failed, 3 audio env-skips, all unrelated). I also hand-checked all 19 MaxLairBossState table cases against the new accept_opponent() / boss_if_caught() and they all match.
Assessment: well-scoped fix. Both root causes are addressed:
bosscan only ever be assigned from a slug that passesis_boss(), so a rental misread can no longer be remembered as the boss and survive a later correct read — that was what crashedEndBattleDecider_BossFinder::get_filter()on the caught screen.boss_if_caught()now returns the boss only atwins == 4, so a lost adventure no longer takes the boss-caught path.
The "keep going instead of resetting" change is safe as far as I can trace: select_move() already handles an empty opponent (random move), so a fully failed read degrades to suboptimal move choice instead of a crash. Keying the summary-path override on in_boss_battle_with_known_boss() also fixes the old !state.boss.empty() case where a remembered rental blocked state.opponent = {state.boss}.
Questions (for the author, who has console test results):
- Cheer-only consoles. If a console's team is wiped out before the boss battle and the boss is caught by the surviving consoles, does that console still get the ball-throw screen (so
throw_ballsincrements it towins == 4)? If not, itsboss_if_caught()is""at the caught screen, and BossFinder treats its end of adventure as "boss not caught" (continue) where the old code applied the boss action (e.g.CATCH_AND_STOP_PROGRAMon the host, which knows the boss from the den sprite). Is that intended? - Co-op non-host consoles.
Run_CaughtScreen.cpp:205uses the local state (state_tracker[console_index]), but only the host getsstate.bossfrom the den sprite read; a non-host's localbossdepends on its own battle-4 read. If that read fails,boss_if_caught()is""even withwins == 4, so that console may continue while the host stops. This predates the PR (the old code returned""there too), but passinginfer_actual_state(console_index)there would majority-vote the host's boss across consoles and make the end-of-adventure decision consistent.
Notes / optional follow-ups (not blockers):
- If
inferred.bossis empty or unknown,BossFinder::get_filter()still throws fromthrow_balls(den-sprite read failed at start and all battle-4 reads failed). Rare and pre-existing, but the same crash family; a fallback (normal ball or error-dump) would harden it. PokemonSwSh_MaxLair_Run_Battle.cpp:84:snapshotis only assigned inside theretryblock. The finaldump_imageis only reachable when the secondaccept_opponent()fails, which today impliesretrywas true (nothing mutatesstatein between), so it is safe — but a one-line comment would guard against a future edit dumping a default-constructed snapshot.- The Run_Battle refactor suggested in the thread is fine as a follow-up: the stage-matching logic now lives in
GlobalStateand is table-tested, which is the part that needed the regression coverage.
I think so -- though I never played this in a multi-switch / multi-player mode.
So supposedly this won't happen
Acknowledged since it's preexisting and thus out-of-scope |
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…< 3) 74c0512 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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
|
Seems to be pre-existing issues that got validated more strictly now (that opponent cannot be empty): Then neither persian variants matches types and opponents become empty. Seems this is because the For this one, we can go back to header read when summary read is empty (32c94cc), and then |
|
I have some more questions now. When OCR is completely unreliable (which is often the case for Chinese) and there are multiple (or none) results throughout the adventure, will this error? The priorities in descending order of importance are:
In the case where OCR is unreliable, we want the program to continue as long as it doesn't read a boss in the first 3 battles. |
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 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
|
Actually the bug I was fixing was indeed an OCR failure: This is from the release log SerialPrograms-20261101-153713815683.log, at 2026-11-02 06:13:06: I was battling Kyurem 酋雷姆, and The game is in Traditional Chinese, but OCR turned the boss's name, Kyurem, into the Latin junk "[TabeQ]". The string matcher then fuzzy-matched that junk against the Chinese dictionary. Every candidate was a weak match, and it took the best one, Mimikyu (log10p -1.5), over a near-tie (-1.3). So right now the risk is So let me see, I am making these change minimal now to just show:
|
… (Persian) From PokemonAutomation/Arduino-Source#1851. Read by the MaxLairSummaryOpponentReader test. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
… (Persian) (#45) From PokemonAutomation/Arduino-Source#1851. Read by the MaxLairSummaryOpponentReader test. Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
|
Do you have a screenshot of the OCR failure? So we can add it to the test suite? |
No, I only have the logs (given the OCR misread itself doesn't fail, but the wrong name will fail in later step). This can be hard to reproduce I guess given reading the name while in battle will contain the background so it's nondeterministic. I searched my logs for ~20 Kyurem battles and the OCR misread happened just once. So retrying from summary read should be more defensive. Or we would read it in battle from multiple frames and get a vote? |
|
If it's truly an OCR misread, I would expect that the OCR read on Kyurem should nearly always fail. I wonder if we're misdiagnosing the issue. I wonder if it would be good idea to just record the screen + output window with OBS, to see if you can catch the error. |
|
ok let me record some kyurem videos and try to run OCR against each frames |
|
@jw098 I recorded a 5-mins long video with Kyerum boss and asked AI to run OCR on every single frame and check what the result is. I am not sure if our sampling of what frame to run OCR against is deterministic, but seems to me the issue is that there is a really long tail (and it might depend on what's in the background), and once in a million time that garbage result might be matches with a valid pokemon name? Full OCR results below:OCR Accuracy Evaluation: Kyurem Max Lair Raid
1. Summary Metrics
2. Determinism AnalysisTesseract OCR is 100% deterministic on static image crops. A 3-run verification across 50 frames confirmed 0 inconsistencies ( 3. Full Distribution of All 177 Unique Outputs (703 Frames)3.1 Exact Match — Clean (1 unique string, 447 frames / 63.58%)
3.2 Exact Match — With Edge / Punctuation Noise (44 unique strings, 91 frames / 12.94%)
3.3 Fuzzy Match (60 unique strings, 86 frames / 12.23%)
3.4 Missed / Occluded Frames (72 unique strings, 79 frames / 11.24%)
|
|
That's one possibility. The other possibility is that the program thinks it's on a screen where it can read Kyurem's name, but it was actually on a different screen where there was no text in that box. The OCR then hallucinates text from the background image. In which case the issue isn't the OCR, but with our state machine being out of sync. |
|
@jw098 right, though either way a misread OCR should be handled, right? The idea is that an invalid read (non-boss) is treated the same way as an empty string (which already falls back to summary read iirc). That handles all garbage / invalid OCR reads no matter where they come from. |

Base:
main; follows the merged test-only preparation in #1846. This diff contains only the behavior fix.The Problem
Boss Finder could remember a OCR misread (
mimikyu-disguised) as the legendary boss, retain it after correctly reading Kyurem, and crash on the caught screen after a loss.The Fix
Only take valid boss name as boss
Though, this will leave an empty boss name, which still crashes BossFinder when determining boss balls
Error log: bug report.log