From 9773f11b8179d2282a76d72c7665ad45bec1b4ff Mon Sep 17 00:00:00 2001 From: Riki Nakamura Date: Thu, 6 Aug 2026 10:33:39 +0900 Subject: [PATCH] fix: make the planner agree with the specification The model-based test found three disagreements. The planner fell back to the YX path without checking that it was clear, it built descending walks in the wrong order, and it kept the previous obstacle when reset without one. Co-authored-by: Claude Opus 5 (1M context) --- src/lib.rs | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 7986c78..d9900ce 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -72,8 +72,10 @@ pub fn plan(start: Position, goal: Position, obstacle: Option) -> Plan if path_is_clear(&path_xy, obstacle) { PlanResult::Plan(path_xy) - } else { + } else if path_is_clear(&path_yx, obstacle) { PlanResult::Plan(path_yx) + } else { + PlanResult::NoPlan } } @@ -122,7 +124,7 @@ fn walk(from: u8, dest: u8) -> Vec { (from..dest).map(|coordinate| coordinate + 1).collect() } else { // Descending: [from - 1, ..., dest]. - (dest..from).collect() + (dest..from).rev().collect() } } @@ -172,12 +174,7 @@ impl Planner { /// Replaces the inputs and forgets any previously computed result. pub fn reset(&mut self, start: Position, goal: Position, obstacle: Option) { - self.start = start; - self.goal = goal; - if obstacle.is_some() { - self.obstacle = obstacle; - } - self.result = PlanResult::Pending; + *self = Self::new(start, goal, obstacle); } /// Computes the plan for the current inputs.