From 55ef06f8682846fc4e6db8183ade8e70bc4f2ad0 Mon Sep 17 00:00:00 2001 From: hal8174 Date: Tue, 27 Feb 2024 22:02:40 +0100 Subject: [PATCH] Fix bugs. --- examples/brute_force.rs | 2 ++ src/belt_finding/brute_force.rs | 31 ++++++++++++++++++++++++++ src/belt_finding/conflict_avoidance.rs | 12 ++++++---- 3 files changed, 41 insertions(+), 4 deletions(-) diff --git a/examples/brute_force.rs b/examples/brute_force.rs index a03fc49..f605d9c 100644 --- a/examples/brute_force.rs +++ b/examples/brute_force.rs @@ -16,6 +16,7 @@ enum Problem { Mid, Snake, Weaving, + Debug, } impl Problem { @@ -25,6 +26,7 @@ impl Problem { Problem::Mid => problems::mid(), Problem::Snake => problems::snake(), Problem::Weaving => problems::weaving(), + Problem::Debug => problems::debug(), } } } diff --git a/src/belt_finding/brute_force.rs b/src/belt_finding/brute_force.rs index 66f5a7a..7cbfc0a 100644 --- a/src/belt_finding/brute_force.rs +++ b/src/belt_finding/brute_force.rs @@ -802,4 +802,35 @@ pub mod problems { b.build() } + + pub fn debug() -> Bruteforce { + let mut b = BruteforceBuilder::new(5, 10); + + b.set_blocked_range(0, 0, 4, 0, true); + b.set_blocked_range(0, 9, 4, 9, true); + b.set_blocked_range(0, 0, 0, 9, true); + b.set_blocked_range(4, 0, 4, 9, true); + + // b.set_blocked_range(3, 2, 3, 3, true); + // b.set_blocked_range(3, 5, 3, 6, true); + + b.add_path( + (Position::new(0, 2), Direction::Right), + (Position::new(3, 2), Direction::Right), + ); + b.add_path( + (Position::new(0, 3), Direction::Right), + (Position::new(3, 5), Direction::Right), + ); + b.add_path( + (Position::new(0, 6), Direction::Right), + (Position::new(3, 6), Direction::Right), + ); + b.add_path( + (Position::new(0, 7), Direction::Right), + (Position::new(3, 3), Direction::Right), + ); + + b.build() + } } diff --git a/src/belt_finding/conflict_avoidance.rs b/src/belt_finding/conflict_avoidance.rs index b6af824..433283b 100644 --- a/src/belt_finding/conflict_avoidance.rs +++ b/src/belt_finding/conflict_avoidance.rs @@ -88,10 +88,10 @@ impl ConflictAvoidance { dir: problem.end[i].1, }); - p.push(PathField::Belt { - pos: problem.end[i].0, - dir: problem.end[i].1, - }); + // p.push(PathField::Belt { + // pos: problem.end[i].0, + // dir: problem.end[i].1, + // }); belts.push(p); } @@ -370,6 +370,10 @@ impl ConflictAvoidance { ), ); candidate.extend_range(&conflicts); + if candidate != c && !candidates.iter().any(|c| c == &candidate) { + candidates.push(candidate); + } + // dbg!(&candidates); } }