diff options
author | metamuffin <metamuffin@disroot.org> | 2024-08-11 19:22:29 +0200 |
---|---|---|
committer | metamuffin <metamuffin@disroot.org> | 2024-08-11 19:22:29 +0200 |
commit | 98ac3be875a30ad97162949aa929c7363d0bf2b3 (patch) | |
tree | 028ab01c471ca4d13ab659a7d5b9fd3a45a03e90 /server/bot/src/pathfinding.rs | |
parent | 012fbc3e6382a92de60a191690000b0e83653cc6 (diff) | |
download | hurrycurry-98ac3be875a30ad97162949aa929c7363d0bf2b3.tar hurrycurry-98ac3be875a30ad97162949aa929c7363d0bf2b3.tar.bz2 hurrycurry-98ac3be875a30ad97162949aa929c7363d0bf2b3.tar.zst |
improve framework and start work on simple algo
Diffstat (limited to 'server/bot/src/pathfinding.rs')
-rw-r--r-- | server/bot/src/pathfinding.rs | 12 |
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); |