Skip to content

Pokemon Navigation: robust leg planner shared by the tile games - #412

Merged
dayfine merged 7 commits into
nav/connected-mapsfrom
nav/robust-leg-planner
Nov 12, 2026
Merged

dayfine merged 7 commits into
nav/connected-mapsfrom
nav/robust-leg-planner

Conversation

@dayfine

@dayfine dayfine commented Nov 12, 2026 •

Copy link
Copy Markdown
Owner

Base nav/connected-maps (#408); the diff shows only this change.

BDSP's robust route search, lifted into Pokemon/Navigation as a template over a step model, so FRLG can plan on it too (AutoStory unification seam 2).

  • Pokemon::plan_robust_legs() searches over the sets of places the player may stand on after each leg: open legs may end open_error tiles off, walls bring the set back together. robust_legs_cost() prices given legs the same way.
  • The model gives one step, its tile count (ledge hop 2), whether the player is held there, and wild / wander places. State is anything with == and an order, so a world tile (BDSP) or a map and a tile (FRLG) both fit.
  • The search, the leg costs and the leg joining are BDSP's RobustSearch / to_wall_leg / open_leg from PokemonBDSP_AutoStory_RoutePlanner.cpp, moved with the world calls replaced by model calls; nothing in it is new.
  • BDSP switches to it in the child PR; FRLG follows.
  • Open for FRLG, not done here: this step model is a second interface next to Pokemon_LegPlanner.h's (press()/Step<State>), so each game writes two adapters over the same rules. Warps and game actions (doors, Surf, spin tiles) are not legs, so FRLG has to plan each stretch between warps on its own.

Testing

  • New Pokemon::RobustLegPlanner suite (table rows on a toy grid: walls, open-leg spread, doors, ledge hops, tall grass, wander zones, search limits, open_error_per 0, a walk that never stops, costs) passes in the headless runner, built together with the BDSP child, which also passes its PokemonBDSP::AutoStory suites including the plan golden.

🤖 Generated with Claude Code

https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss

dayfine and others added 2 commits November 11, 2026 20:48
BDSP's search over the sets of tiles a player may stand on after an
uncertain open leg, lifted as a template over a step model so it can plan
on any state (a world tile, or a map and a tile).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…put and expectation cases

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

@dayfine dayfine left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed SHA: 4206f33

Reviewed against nav/connected-maps (own diff only). Shared infra, held to the infra bar.

Verdict

NEEDS_REWORK (changes needed)

Correctness: I compared the template with the BDSP code it replaces (RobustSearch, step_tiles, slide_to_wall, to_wall_leg, open_leg, robust_route_cost in PokemonBDSP_AutoStory_RoutePlanner.cpp on bdsp/connected-maps). It is the same algorithm line for line: the same error formula, the same costs, the same per-leg discount for a continued open leg, the same max_spread/max_searched limits, consolidation moved from legs_to() to consolidate() with the same rule, and relax() copies the leg into the node before moving after into the queue. So BDSP plans cannot change. Code Health: 0 failures (advisory: to_wall_leg and robust_legs_cost 32 lines).

Findings

  1. (Medium) The tests are not data-driven. Each row holds a function pointer plus an expectation.description string that nothing reads, and the map, start, goal, costs and expected legs live inside five hand-written functions with compound if checks. That is the shape the repo's test rule exists to prevent (input and expectation structs, inputs visible in the row, one UnitTest over a table). Make the row {rows, from, goal, costs overrides} -> {expected legs as text, or "no plan"} and compare describe() output, so a failure prints expected and actual plans.
  2. (Medium) open_error_per = 0 divides by zero. costs.open_error + tiles / costs.open_error_per runs whenever tiles > exact_open_tiles. FRLG's planned setup is "open_error 0" for timed holds, and zeroing the growth term is the obvious way to write that. Either treat 0 as "no growth", or reject it with InternalProgramError at the top of plan_robust_legs()/robust_legs_cost(), and document that exact legs are exact_open_tiles = max_open_tiles.
  3. (Medium) Coverage gaps in what is claimed game-neutral. No case has step_tiles() > 1 (the ledge hop that the header calls out), the wild cost, max_spread rejecting a wide spread, max_searched giving up, or two open legs the same way being joined. The toy model's step_tiles() is always 1. These are the parts FRLG will lean on (FRLG ledges); one row each.
  4. (Low, FRLG fit) The API is neutral in its state type, so MapPlace works, with three gaps worth deciding before FRLG builds on it:
    • It is a second step-model concept beside Pokemon_LegPlanner.h (press()/Step<State>/StateHash there; step()/step_tiles()/wild()/wander()/StateLess here). Each game now writes two adapters over the same rules (BDSP's StoryWorldModel and RobustWorldModel in #413). At least share the names (held_at already matches) and say in the header how the two relate.
    • It has no warps or game actions (Surf, doors, spin tiles): a stop that isn't held is never used, so a plan cannot cross a warp. That is fine if FRLG plans each warp-to-warp segment separately; say so in the header as the caller's job.
    • StateLess must be hand-written because MapPlace/TilePos have no order (see #408 finding 3); with <=> there, the concept could default to std::less<State>.
  5. (Low) slide_to_wall() loops until step() returns nothing. On one stitched BDSP grid that always ends; on connected maps a loop of edge connections (or a model bug) hangs the planner. Bound it (e.g. by max_searched or a tile cap) and treat the cap as "not held".
  6. (Note for #413 and the lab line) RobustLegCosts::per_wander_tile = 3 duplicates BDSP's TilePlanCosts default. BDSP never uses the shared default (it copies its own), so this is harmless now; see #413 about the lab's 15.

Notes

  • Fork Draft CI is red from the base (Pokemon_StoryStepJson_Tests.cpp:150 GCC dangling-pointer, inherited), so the suite ran only locally.
  • const std::function<…>& goal matches Pokemon_LegPlanner.h; fine.

dayfine and others added 3 commits November 12, 2026 00:15
…0; capped slide (#412 review)

Each row now holds the map, starts, goal and costs, and the expected plan
as text; one runner compares describe() output. New rows cover a ledge hop,
tall grass, max_spread, max_searched, joined open legs and a walk that
never stops. open_error_per 0 adds no growth instead of dividing by zero,
and slide_to_wall() gives up as not held after 1024 steps. The header says
how this step model relates to LegPlanner's and that warps are the
caller's job.

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

dayfine commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Review addressed at ffdf9ae (fix: 1ca9ec4, plus #408 merged in).

  1. The tests are data-driven. Each PlanCase row holds the rows, wrap flag, starts, goal and RobustLegCosts, and expects the plan as describe() text or "none". A second table, CostCase, holds legs and their expected cost. One runner per table, and a failure prints the planned and expected text. The unused description strings are gone.
  2. When open_error_per is 0, no growth is added: the error is open_error, and with both 0 open legs are exact. This is in open_leg_error() and documented on the struct. Rows cover both settings, plus a cost row.
  3. New rows: a ledge hop (south 2 to wall; can't climb back), tall grass taken versus walked round when per_wild_tile = 20, an open leg spreading and then a wall gathering, max_spread = 1 giving no plan, max_searched = 1 giving up, two open legs the same way joined (max_open_tiles = 2), and a wrapping row that never stops.
  4. The toy model uses std::less<TilePos> now that TilePos is ordered. BDSP's RobustWorldModel keeps its y-then-x order, so its plans don't change. The header now says warps and actions aren't legs, so callers plan each stretch between warps, and that this step model and LegPlanner's describe the same rules. The FRLG gaps (second step-model interface, no warps or actions) are noted in the description, not implemented.
  5. slide_to_wall() gives up after MAX_STEPS_TO_WALL (1024) steps and treats that as not held. The wrap row covers it.

Local headless run: 20/20 RobustLegPlanner rows pass, and the BDSP golden is unchanged. Code health: 0.

@dayfine

dayfine commented Nov 12, 2026

Copy link
Copy Markdown
Owner Author

Merged base nav/connected-maps at 29841ed (merge commit 138d27f), which brings in nav/grid-story-steps 0ac724b. This merge was clean; the only conflict upstream of it was in SerialPrograms/Source/ComputerPrograms/ComputerPrograms_UnitTestRunner.cpp, resolved in #408 by keeping both registrations:

     Pokemon::add_tests_MapData(ret);
     Pokemon::add_tests_ConnectedMaps(ret);
+    Pokemon::add_tests_MoveMechanics(ret);
     Pokemon::add_tests_RuntimeMap(ret);

(the #include lines for both test headers auto-merged; SourceFiles.cmake auto-merged with each file listed once). Code health: 0 failures.

@dayfine dayfine left a comment

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed SHA: 138d27f

Re-review of the fix (1ca9ec4) against my review at 4206f33; the later merges (ffdf9ae, 138d27f) bring only base changes: git diff origin/nav/connected-maps...138d27fab is still just the planner header, its tests, the test registration and SourceFiles.cmake.

Verdict

APPROVED

Earlier points:

  1. Data-driven tests: resolved. PlanCase rows hold rows, wrap flag, starts, goal and costs, and expect describe() text or "none"; CostCase rows hold legs and the expected cost. A failure prints the planned and expected text.
  2. open_error_per = 0: resolved. The formula now lives only in open_leg_error(), which returns open_error when open_error_per <= 0. It is documented on the struct and covered by two plan rows and one cost row.
  3. Coverage: resolved. There are rows for a ledge hop (step_tiles 2), a ledge that can't be climbed, cheap and costly tall grass, max_spread, max_searched, two open legs joined, and a walk that never stops.
  4. FRLG fit: addressed in the header. It says how this step model relates to LegPlanner's, that warps are the caller's job, and that std::less<State> works for TilePos/MapPlace. Keeping two adapters is a design choice I'm leaving open.
  5. Unbounded slide: resolved. slide_to_wall() stops after MAX_STEPS_TO_WALL (1024) steps with held = false, and its only caller checks held before it uses stop/tiles. The wrapping-row test exercises this.
  6. Note only; nothing needed here.

Checks: Fork Draft CI on 138d27f is green, and all 20 Pokemon::RobustLegPlanner cases pass in its log (16 plan, 4 cost). Code Health passes. Both files are CRLF throughout. The red "Runtime map reader" (native-schema) job fails on the base too and is not from this PR.

No new findings.

@dayfine
dayfine merged commit 7e357d0 into nav/connected-maps Nov 12, 2026
13 of 16 checks passed
@dayfine
dayfine deleted the nav/robust-leg-planner 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

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant