aboutsummaryrefslogtreecommitdiff
path: root/server/bot/src/pathfinding.rs
diff options
context:
space:
mode:
Diffstat (limited to 'server/bot/src/pathfinding.rs')
-rw-r--r--server/bot/src/pathfinding.rs12
1 files changed, 12 insertions, 0 deletions
diff --git a/server/bot/src/pathfinding.rs b/server/bot/src/pathfinding.rs
index 87ccf391..ec557e28 100644
--- a/server/bot/src/pathfinding.rs
+++ b/server/bot/src/pathfinding.rs
@@ -42,6 +42,18 @@ impl Path {
}
}
+pub fn find_path_to_neighbour(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Path> {
+ let mut paths = Vec::new();
+ for xo in -1..=1 {
+ for yo in -1..=1 {
+ let to = to + IVec2::new(xo, yo);
+ if walkable.contains(&to) {
+ paths.extend(find_path(walkable, from, to))
+ }
+ }
+ }
+ paths.into_iter().min_by_key(|p| p.0.len())
+}
pub fn find_path(walkable: &HashSet<IVec2>, from: IVec2, to: IVec2) -> Option<Path> {
#[derive(Debug, PartialEq, Eq)]
struct Open(i32, IVec2, IVec2, i32);