Skip to content

BBQ Farmer: reuse verified quest panel reads after a failed-quest reroll (C9) - #22

Closed
dayfine wants to merge 32 commits into
bbq/replan-after-rerollfrom
bbq/panel-read-reuse
Closed

dayfine wants to merge 32 commits into
bbq/replan-after-rerollfrom
bbq/panel-read-reuse

Conversation

@dayfine

@dayfine dayfine commented Oct 22, 2026 •

Copy link
Copy Markdown
Owner

Depends on: fork #13 (bbq/replan-after-reroll, M7b), which is stacked on fork #12 (bbq/reuse-quest-board, M7a). Base branch: bbq/replan-after-reroll, so the diff shows only this change. None of these is upstream yet; the upstream base is PokemonAutomation/Arduino-Source main.

Part of PokemonAutomation/ComputerControl#263.

Problem

In the R3 live run (2026-10-22 07:39–07:40), one failed quest with OUT_OF_RETRIES = Reroll made the round loop read the quest panel 3 times before the next attempt, with no game action that could change the panel between those reads and the ones just before them:

  1. (a) The out-of-retries reroll verifies its result by reading the panel, but BBQGameActions::reroll_quest() returned nothing, so scheduling read the panel again ("Reading quest panel for scheduling").
  2. (b) M7a only reuses a verify read with 4 known slots. Boards without a 4th quest give 3-slot reads, so the exclusions-table reroll that followed was also read again for scheduling.
  3. (c) "Reading quest panel before dispatch" ran right after a fresh scheduling read. M7a only skipped it when scheduling had reused a panel.

Each read is about 4–5 s.

Change

  • (a) BBQGameActions::reroll_quest() returns the verified read from reroll_quest_slot() (when reroll_quest() found it reusable). run_bbq_rounds() uses it to plan the next round, unless the round ended with a save: the save resets the game, so the panel is read again after one. The date fix in end_round() does not change the quests.
  • (b) reroll_quest() also reuses a 3-slot read, but only when the panel used for that reroll had 3 slots too, every slot is known, and every other slot agrees with that panel. A 3-slot read after a 4-slot panel (a missed 4th quest) is still not reused, nor is a 4-slot read after a 3-slot panel.
    • Remaining risk: both reads could have missed the same 4th quest. A fresh read can miss it too, so this is the same outcome with one fewer chance to see it. The quest is then left out of one plan; no BP is spent on it and no completion is counted. A 3-slot read never forgets a failed quest (forget_quests_gone_from_panel() needs 4 known slots), so a missed 4th slot cannot give a failed quest new attempts.
  • (c) The first dispatch of a round always reuses the panel that its work was chosen from. process_quest_list() only returns work when it changed nothing in game (any reroll returns an empty list), and nothing runs between it and the first dispatch. The interface comment now says so.

No other behavior changes. Reads inside game steps (the reroll's own reads, the read after a quest attempt) are unchanged.

Panel reads by the round loop

From the native scenarios in PokemonSV_Tests.cpp (the "before" numbers follow the same scenario through #13's code):

Scenario Before After
R3 case: failed quest rerolled, then rerolled by the exclusions table, reads reusable (3-slot board) 7 total, 3 between the reroll and the next attempt 3 total, 0 between
Same, reads not reusable 7 total, 3 between 5 total, 2 between
Failed reroll on a 4-slot board, then a save unchanged, read fresh after the save unchanged
Every round one read before the first dispatch none

Tests

  • BBQReroll: new 3-slot cases (reused when the panel had 3 slots; not reused with an unknown slot, another changed slot, or a 4th quest the panel missed). Two existing 3-slot cases now expect the observation.
  • BBQFarmerRounds: the fake can now reroll a slot as an exclusions-table row does (table_rerolls), its reroll_quest() returns its read, and scenarios can assert a read count (expected_reads). New: the R3 case with and without reusable reads, and a failed reroll before a save. Existing expectations lose the read before each round's first dispatch (read process read do becomes read process do); "failed reroll on full board" now reuses its read.
  • Native runner (PokemonSV::BBQ*): 53 passed, 0 failed (BBQuestPlan 14, BBQReroll 17, BBQFarmerRounds 22) on 57088de, built with Ninja arm64 RelWithDebInfo. With the round-loop changes (a) and (c) reverted in place, 21 BBQFarmerRounds scenarios fail, including both new read-count scenarios (6 and 7 reads counted).

How to review

Read run_bbq_rounds() in PokemonSV_BBQSoloFarmer.cpp first, then the reuse condition in reroll_quest() (PokemonSV_BlueberryQuests.cpp), then the tests. Nothing is moved.

🤖 Generated with Claude Code

https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E

dayfine and others added 16 commits October 20, 2026 22:02
BBQSoloFarmer::program() runs its quest rounds inline against the
console, so the round logic (which quests count, when to stop, when to
save) can only be exercised by running the farmer on a Switch.

Move the round loop into run_bbq_rounds(), which takes the game actions
it depends on as a BBQGameActions interface: read the quests, process
them, do a quest, report a completed quest, and end the round (saving
if due). BBQSoloFarmer implements these with the calls they replace, in
the same order; the date fix, save/reset, stats and notification move
together into end_round(). Startup, flying to the plaza and
end-of-program handling stay in program(). The commented-out
single-quest debug block declares its own egg counter now that the loop
locals have moved.

process_quest_list() only reads its quest list and egg count, so take
them as const& and by value.

Add PokemonSV::BBQFarmerRounds, a table of scenarios run against a
simulated singleplayer quest panel: 3 blue quests, completed quests are
replaced, impossible quests are skipped, and a panel with nothing doable
is rerolled. Each scenario checks the number of completed quests and the
exact action sequence: finishing the round that reaches the goal, a
quest already gone, a failed quest, a panel with nothing doable, saving
at exact multiples, and stopping when out of eggs. No behavior
change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
The farmer saved and reset when the completion count was an exact
multiple of SAVE_NUM_QUESTS. A round that completed nothing while the
count sat at 0 or 50 saved again, and a round going from 49 to 52
skipped the 50 milestone entirely.

Compare the count before and after each round and ask end_round() to
save once when it crosses a multiple of the interval. Stalled rounds
and an interval of 0 never save. Fix the option label to say
"completing", not "attempting".

Add two PokemonSV::BBQFarmerRounds scenarios that fail with the old
rule: a round that skips past a milestone, and rounds with no
completions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
… out

process_quest_list() decided what to do with each quest and pressed
the buttons for it in the same loop, so the decisions could only be
checked on a Switch.

plan_quests() now makes the decisions from the options alone: which
quests to do, which panel slots to reroll, and whether to reroll all.
process_quest_list() carries out the plan, and opening the panel is a
shared helper instead of three copies.

All rerolls now move the cursor to the quest's slot. The out-of-eggs
reroll used to reroll the top slot; the egg quest is a red quest and
red quests are listed at the top, so this is the same in practice.
OOEggs::Stop reaching the planner is now an InternalProgramError,
since the farmer stops before that can happen.

Unit tests cover the plan for exclusions, duplicate rows, quests that
are not possible, and eggs.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
process_and_do_quest() gives up on a quest after NUM_RETRIES retries,
but the quest stays on the panel, so the next round attempts it again
with a fresh set of retries. A quest that cannot be done, such as a
sneak-up whose target does not spawn, is retried forever.

run_bbq_rounds() now remembers quests that failed all their attempts
and leaves them out of later rounds. A quest is forgotten once a read
of 4 known quests shows it gone, so it gets its attempts again if it
comes back. If only failed quests are doable, the farmer stops instead
of spending BP to reroll them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Move the out-of-eggs choice, the exclusions table rows, a single-slot
reroll and the reroll of every slot into file-local helpers, so
plan_quests() and process_quest_list() read as one level of steps.
Explain why the language-selection error is commented out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
reroll_slot() opened the quest panel, pressed DOWN once per slot from where
it assumed the cursor was, and pressed A twice. The panel does not always
open with the cursor on the top quest: on a Switch it opened where the
cursor was left, so the reroll paid for a different quest than planned.
Nothing checked the menu opened or the quest changed, so running out of
BP went unnoticed and the same quest was rerolled every round.

reroll_quest() now does a reroll through injectable BBQRerollActions:
open the reroll menu wherever the cursor is, see which quest the menu
opened next to from its arrow, move to the planned quest, and only then
confirm. Afterwards it reads the panel (up to 3 times, as OCR can miss a
read) to check the quest was replaced. Panel or menu not found stops
before spending BP; a quest not replaced stops without an error report,
as it usually means out of BP.

The arrow boxes for the top three slots were checked on a Switch; the
fourth uses the same spacing. Reroll-all is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
plan_quests() dropped quests the farmer cannot do (pickup, flying photo
and catch) before looking at the exclusions table, so a reroll row for
one of them did nothing: the quest stayed on the panel and blocked the
slot. Pickup could not be picked in the table at all.

The table is now applied first. Reroll and skip rows work for quests the
farmer cannot do; a run row for one is ignored, since there is no route
for it. Pickup is listed in the table.

With nothing to do and nothing rerolled, the first quest the farmer cannot
do that has no table row is rerolled instead of every quest, which costs
one reroll instead of three or four. Every quest is still rerolled when
there is no such quest.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
process_quest_list() takes the panel by const reference since PokemonAutomation#1632, so the rerolls work on a copy.
A quest that fails all its retries is skipped while it stays on the
panel. That keeps the farmer going, but the quest blocks its slot, and
if every doable quest is one that failed the farmer stops.

OUT_OF_RETRIES now chooses what happens:

- Skip (default): as before.
- Reroll: reroll the failed quest, so its slot gets a new quest. Uses
  reroll_quest_slot(), which checks which quest it pays for and that it
  was replaced.
- Stop: end the program there, through the normal end of program.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
# Conflicts:
#	SerialPrograms/Source/VideoGames/PokemonSV/Programs/Farming/PokemonSV_BBQSoloFarmer.cpp
dayfine and others added 10 commits October 22, 2026 21:21
Give BBQRoundsScenario's `never_completes`, `new_quests` a default member initializer (= {}), so
test cases that leave them out of a designated initializer compile on
the Windows Clang CI job.

That job builds with clang-cl /W4 /WX, which turns on
-Wmissing-designated-field-initializers: a designated initializer that
omits a field without a default member initializer is an error. Apple
clang's -Wextra does not enable that warning, so macOS builds miss it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Give BBQRerollScenario's `replacements`, `expected_rerolled_slots` a default member initializer (= {}), so
test cases that leave them out of a designated initializer compile on
the Windows Clang CI job.

That job builds with clang-cl /W4 /WX, which turns on
-Wmissing-designated-field-initializers: a designated initializer that
omits a field without a default member initializer is an error. Apple
clang's -Wextra does not enable that warning, so macOS builds miss it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Brings in the default member initializers for its test scenario fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Brings in the default member initializers for its test scenario fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Brings in the default member initializers for its test scenario fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Give BBQRerollScenario's `read_override`, `expected_observed_panel` a default member initializer (= {}), so
test cases that leave them out of a designated initializer compile on
the Windows Clang CI job.

That job builds with clang-cl /W4 /WX, which turns on
-Wmissing-designated-field-initializers: a designated initializer that
omits a field without a default member initializer is an error. Apple
clang's -Wextra does not enable that warning, so macOS builds miss it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Brings in the default member initializers for its test scenario fields.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Give BBQRoundsScenario's `expected_attempted` a default member initializer (= {}), so
test cases that leave them out of a designated initializer compile on
the Windows Clang CI job.

That job builds with clang-cl /W4 /WX, which turns on
-Wmissing-designated-field-initializers: a designated initializer that
omits a field without a default member initializer is an error. Apple
clang's -Wextra does not enable that warning, so macOS builds miss it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
After a failed quest was rerolled (OUT_OF_RETRIES = Reroll), the round
loop read the panel 3 times before the next attempt, each right after a
read of the same unchanged panel:

- The out-of-retries reroll now returns its verified read, and the next
  plan starts from it unless the round ended with a save and reset.
- reroll_quest() also reuses a 3-slot read when the panel used for the
  reroll had 3 slots, every slot is known and the other slots agree. A
  3-slot read after a 4-slot panel (a missed 4th quest) is still not
  reused.
- The first dispatch of a round reuses the panel its work was chosen
  from: process_quest_list() only returns work when it changed nothing.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
Give BBQRoundsScenario's `table_rerolls`, `expected_reads` a default member initializer (= {}), so
test cases that leave them out of a designated initializer compile on
the Windows Clang CI job.

That job builds with clang-cl /W4 /WX, which turns on
-Wmissing-designated-field-initializers: a designated initializer that
omits a field without a default member initializer is an error. Apple
clang's -Wextra does not enable that warning, so macOS builds miss it.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AKYzhrMnPK61XHWEch4a6E
@dayfine
dayfine force-pushed the bbq/panel-read-reuse branch from 57088de to f4d4c47 Compare October 23, 2026 04:25
@dayfine
dayfine force-pushed the bbq/replan-after-reroll branch from e4c5cc4 to 09982bb Compare October 28, 2026 08:14
dayfine and others added 2 commits October 30, 2026 07:45
The base was rebuilt since this branch forked: the stack under it was
re-merged onto main, the exclusions-table reroll (fork #9) was dropped, and
the BBQ tests moved to Programs/Farming/PokemonSV_BBQTests.cpp. Took the base
for everything except this PR's own change (7dfc056 + f4d4c47), which is
re-applied on top: reroll_quest() returns its verified read and 3-slot reads
are reusable when the panel had 3 slots; run_bbq_rounds() seeds the next plan
from it unless the round saved, and always reuses the scheduling panel for the
first dispatch, next to the base's doable-read guard and failed-quest filter.
Its tests moved into PokemonSV_BBQTests.cpp; the simulated process_quest_list()
keeps the base's out_of_bp, and the base-only round scenarios drop the read
before each round's first dispatch.

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 1 PR #272.

@dayfine dayfine closed this Nov 9, 2026
@dayfine
dayfine deleted the bbq/panel-read-reuse 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