Repository navigation
Robust leg planner: held open legs (off by default) - #428
Conversation
…ault) RobustLegCosts::hold_open_legs plans open legs that may end off as holds (RobustLeg::held) that pay no per_open_tile; a held leg whose possible ends past the shortest enter tall grass, a wander place or hop a ledge is not used, and held legs are never joined. per_open_wild_tile adds to each wild tile an open leg enters. open_leg() now steps each place once for all its lengths (step_prefixes). Same code as on bdsp/start-certainty. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
…e ends; held costs Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss # Conflicts: # SerialPrograms/Source/Pokemon/Navigation/Pokemon_RobustLegPlanner_Tests.cpp
dayfine
left a comment
There was a problem hiding this comment.
Reviewed SHA: 6bf2fec
Verdict
APPROVED
Scope: the two commits on top of nav/connected-maps (e2f4e3a planner, 6bf2fec tests). The header is byte-identical to BDSP #400's merge 8d8a3ee (git diff 8d8a3ee3f 6bf2fece9 -- .../Pokemon_RobustLegPlanner.h is empty). The test file adds 5 plan cases and 4 cost cases on top of that.
Correctness
Default-off leaves plans unchanged. With hold_open_legs = false and per_open_wild_tile = 0, held is always false, so unsafe is never set, per_open_tile is charged as before, and joins() reduces to the old direction == && !prev.to_wall test in all three places (consolidate, relax, robust_legs_cost). open_leg still pushes after per place, then per n, in the same order. It still returns nullopt on the same first failing (place, n).
step_prefixes matches step_tiles for every n. I traced the three cases:
- Normal step: entry n is pushed on the first step where
travelled >= n, which is wherestep_tiles(n)stops. - Ledge hop:
travelledjumps by 2, so n and n+1 both get the post-hop state, matchingstep_tilesovershooting. - Blocked: the remaining entries get the current
steppedifheld_at, elsenullopt, the same asstep_tiles(n)for any n past the block.
Wild, wander and along_wander are accumulated the same way.
The held-leg refusal logic is sound. held_ends_safe checks ends[1..] for a ledge hop (step_tiles > 1), wild or wander. ends[0] (the shortest end) is exempt, as the comment says: a tap would meet it too. An unsafe length is skipped (continue) rather than ending the length loop (break), so a longer held leg can still be planned. That is right, because a longer leg's shortest end can be past the bad tile. The tests cover grass, wander and ledge refusals, each against a passing control layout, plus the off-by-default case.
Findings
-
Low:
held_ends_safecallsmodel.step_tiles(a, a). When an end is held at a wall, consecutive ends repeat (ends[i-1] == ends[i]). The Model contract at the top of the header definesstep_tiles(from, to)only for one step. Both current models happen to be fine: ToyGame returns 1, and BDSP'sdistancereturns 0. A future model that asserts or returns 2 would wrongly refuse every held leg that ends at a wall. Fix: skip equal pairs (if (ends[i] == ends[i - 1]){ continue; }, or compare with the model's less), or note in the contract thatfrom == tomust return 0 or 1. -
Low:
robust_legs_costdoes not match the planner for held legs.- It ignores
Expansion::unsafe. A held leg the planner would refuse is still charged its full expansion cost, which includes wild tiles. The doc says "a leg it would not plan costs its tiles and legs without wild or wander tiles". - The fallback still adds
per_open_tilewhencosts.hold_open_legswould make the leg held. - Joining uses
leg.held, but the cost usescosts.hold_open_legs. Legs planned with holds on and costed with holds off get mixed treatment.
This is off by default and the function is only used to score hand-written legs, so it is not blocking. Either treat
unsafelikenullopt, or say in the comment that held legs are costed fromcosts, not fromleg.held. - It ignores
-
Nit: the same walk is written twice.
step_tilesandstep_prefixesboth implement the step-until-n walk, andstep_tilesnow has one caller (to_wall_leg). That caller could usestep_prefixes(model, place, direction, (int)hit.tiles).back(), andstep_tilescould then go. This is a follow-up, since the header is meant to stay identical to 8d8a3ee.
Style (AGENTS.md)
- Brace style and control-flow formatting: OK.
- CRLF is preserved in both files.
- No Qt,
std::filesystemor threads. - The new struct fields have default member initializers, so designated initializers that leave them out are fine on Windows Clang.
- Comments explain the reasons.
- Code health: 0 failures. Advisories only:
step_prefixesis 34 lines andopen_legis 35 lines (the advisory threshold is 25, the limit 50), and the header is 550 lines.
Checks
- Code health was run locally against
origin/nav/connected-maps, from the local agents checkout (f51e843): exit 0. - CI at review time: build, code-health, no-tabs and native-codec passed. native-schema failed, which is the known pre-existing Runtime map reader link failure.
ubuntu / build(unit tests) was still pending, so I did not see the new cases run. - No local compile.
The held-open-leg changes to the shared robust leg planner were made on BDSP's #400, so that PR carried edits to a shared file. This moves them here unchanged: RobustLegCosts::hold_open_legs plans open legs that may end off as holds (RobustLeg::held, no per_open_tile), refuses a held leg whose ends past the shortest enter tall grass, a wander place or hop a ledge, never joins held legs, and adds per_open_wild_tile; open_leg() now walks each place once for all lengths. Both new costs default off, so existing plans do not change. Tested with the Pokemon::RobustLegPlanner suite (30 pass), which adds cases for the grass, wander and ledge refusals and the held-leg costs.
🤖 Generated with Claude Code
https://claude.ai/code/session_013VUubhHeYSMGSSDXZkKZss