Skip to content

BBQ: verify the egg before hatching and restore the lead on failure (C17) - #33

Closed
dayfine wants to merge 17 commits into
mainfrom
bbq/hatch-egg-verify
Closed

dayfine wants to merge 17 commits into
mainfrom
bbq/hatch-egg-verify

Conversation

@dayfine

@dayfine dayfine commented Oct 23, 2026 •

Copy link
Copy Markdown
Owner

Part of PokemonAutomation/ComputerControl#263.

Update after lab R8 (2026-10-22): the first diagnosis (stale summary panel) was wrong. BoxCurrentEggDetector checks that a summary-panel row is blank, which only tells eggs apart in the stats/judge view; in the default view every occupied slot reads as an egg, so the two-frame check couldn't help (R8 swapped the Litten in again). The scan now uses BoxEggDetector on the slot icons, as Egg Hatcher does: works in any view, all 30 slots from one frame, no cursor moves. The lead check after the swap uses the same detector on party slot 1. The failed-hatch recovery was confirmed on the Switch (lead restored, back to the plaza); a stats-view variant of the scan hatched and paid +200 BP in R8. The icon scan itself builds but hasn't run on the Switch yet.

Depends on: nothing. Based on main. quest_hatch_egg() on main matches lab R7 except for one return_to_plaza() argument, so this also cherry-picks onto the lab.

Problem (C17)

In the bbq-r7 run (2026-10-22 18:39), quest_hatch_egg() moved the cursor to box slot (0,0), logged "Cursor moved." at 18:39:36.417 and "Found egg." 15 ms later. The slot actually held a hatched Litten, put back there by the previous hatch. It swapped the Litten into party slot 0, rode for 10 minutes, threw "No more egg hatch after 10 minutes", and stopped with the lead still in the box.

Root cause: the scan loop does take a new snapshot after each cursor move, but only after wait_for_all_requests(). The summary panel had not caught up with the cursor yet, so BoxCurrentEggDetector / SomethingInBoxSlotDetector read the panel from the previous selection. The egg check made right after the cursor move uses that frame.

Fix (all in quest_hatch_egg())

  1. Settle and confirm: a new helper, box_cursor_slot_is_egg(), waits 300 ms and needs two snapshots in a row (300 ms apart) that both show an egg. The scan loop uses it. In the worst case (30 slots, no egg) the scan takes about 9 s longer.
  2. Check the lead: after the swap the cursor sits on party slot 0, so the same helper checks that the lead is an egg. This happens before leaving the box, since there is no cheap way to check for an egg in the overworld. If the lead is not an egg, it is swapped straight back.
  3. Restore after a failed hatch: an OperationFailedException from hatch_eggs_anywhere() (for example the 10-minute timeout) is caught and logged. The usual path then re-enters the box, swaps party slot 0 back into the slot it came from, and returns to the plaza. The quest stays on the list, so process_and_do_quest() counts it as a failed attempt (retries up to NUM_RETRIES, then skips it) instead of ending the program. The same applies when the lead check fails.

If the hatch fails in a state where enter_box_system_from_overworld() cannot recover (for example stuck in a dialog), the program still stops there, as it does today.

M8a (Codex) covers wider party restoration. This PR is the minimal version for the hatch path only.

Testing

  • Compiles. Only PokemonSV_BlueberryQuests.cpp was compiled, using R6's configure.
  • Console-only: the detection and restore logic is tied directly to video snapshots and box navigation. No cheap test seam exists, so this PR adds no native tests. It needs a live BBQ run with an egg quest. Lab R8 has it.

How to review

There is one function plus one helper, so read the diff top to bottom. The changes:

  • the detectors moved into box_cursor_slot_is_egg()
  • the hatch call is wrapped in try/catch
  • the leave/hatch/re-enter block sits under the lead check

🤖 Generated with Claude Code

https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

dayfine and others added 11 commits October 20, 2026 11:52
quest_hatch_egg() could pick a hatched Pokemon as the egg: it read the
summary panel right after the cursor move, before the panel updated.
Now it waits for the panel to settle and needs two fresh snapshots that
both show an egg, rechecks the party lead after the swap, and swaps the
lead back into its box slot if the hatch step fails.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
The summary-panel detector only tells eggs apart in the stats or judge view;
in the default view every occupied slot reads as an egg (R7 and R8 swapped a
Litten in and rode for 10 minutes). BoxEggDetector matches the egg sprite in
the grid, so it works in any view, and one frame covers all 30 slots without
moving the cursor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
main moved the quest token map, BBQuests_string_to_enum/enum_to_string and
CameraAngle out of BlueberryQuests (PokemonAutomation#1631), and the BP crop into
read_BP_from_image (PokemonAutomation#1628). Took main's versions and kept only this branch's
log_bbq_snapshot() in BlueberryQuests; BlueberryCatchPhoto.cpp now includes
BlueberryQuests.h directly, since its header no longer pulls it in. Unknown
quests now log as an empty slug (main's enum_to_string) instead of "unknown".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine dayfine added farmer Farming programs game:sv Scarlet/Violet labels Nov 1, 2026
dayfine and others added 4 commits November 2, 2026 07:01
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
dayfine and others added 2 commits November 7, 2026 07:01
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine

dayfine commented Nov 9, 2026

Copy link
Copy Markdown
Owner Author

Superseded by consolidated Tree 4 PR #275.

@dayfine dayfine closed this Nov 9, 2026
@dayfine
dayfine deleted the bbq/hatch-egg-verify branch November 13, 2026 03:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

farmer Farming programs game:sv Scarlet/Violet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant