Skip to content

Robust leg planner: held open legs (off by default) - #428

Merged
dayfine merged 2 commits into
nav/connected-mapsfrom
nav/robust-held-legs
Nov 12, 2026
Merged

dayfine merged 2 commits into
nav/connected-mapsfrom
nav/robust-held-legs

Conversation

@dayfine

@dayfine dayfine commented Nov 12, 2026

Copy link
Copy Markdown
Owner

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

dayfine and others added 2 commits November 12, 2026 03:54
…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
dayfine added a commit that referenced this pull request Nov 12, 2026
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 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: 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 where step_tiles(n) stops.
  • Ledge hop: travelled jumps by 2, so n and n+1 both get the post-hop state, matching step_tiles overshooting.
  • Blocked: the remaining entries get the current stepped if held_at, else nullopt, the same as step_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

  1. Low: held_ends_safe calls model.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 defines step_tiles(from, to) only for one step. Both current models happen to be fine: ToyGame returns 1, and BDSP's distance returns 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 that from == to must return 0 or 1.

  2. Low: robust_legs_cost does 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_tile when costs.hold_open_legs would make the leg held.
    • Joining uses leg.held, but the cost uses costs.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 unsafe like nullopt, or say in the comment that held legs are costed from costs, not from leg.held.

  3. Nit: the same walk is written twice. step_tiles and step_prefixes both implement the step-until-n walk, and step_tiles now has one caller (to_wall_leg). That caller could use step_prefixes(model, place, direction, (int)hit.tiles).back(), and step_tiles could 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::filesystem or 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_prefixes is 34 lines and open_leg is 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.

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