From 98ac3be875a30ad97162949aa929c7363d0bf2b3 Mon Sep 17 00:00:00 2001 From: metamuffin Date: Sun, 11 Aug 2024 19:22:29 +0200 Subject: improve framework and start work on simple algo --- server/bot/src/pathfinding.rs | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'server/bot/src/pathfinding.rs') 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, from: IVec2, to: IVec2) -> Option { + 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, from: IVec2, to: IVec2) -> Option { #[derive(Debug, PartialEq, Eq)] struct Open(i32, IVec2, IVec2, i32); -- cgit v1.2.3-70-g09d2