From f8d95d074c36ec35eee8def73b8d9f2b83c922cb Mon Sep 17 00:00:00 2001 From: metamuffin Date: Mon, 20 Oct 2025 00:56:32 +0200 Subject: Pathfinding avoids chairs --- server/bot/src/pathfinding.rs | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'server/bot/src/pathfinding.rs') diff --git a/server/bot/src/pathfinding.rs b/server/bot/src/pathfinding.rs index a32442b1..e17ca80c 100644 --- a/server/bot/src/pathfinding.rs +++ b/server/bot/src/pathfinding.rs @@ -15,11 +15,12 @@ along with this program. If not, see . */ +use hurrycurry_game_core::Game; use hurrycurry_protocol::glam::{IVec2, Vec2}; use log::{debug, trace}; use std::{ cmp::Ordering, - collections::{BinaryHeap, HashMap, HashSet}, + collections::{BinaryHeap, HashMap}, time::Instant, }; @@ -54,19 +55,19 @@ impl Path { } } -pub fn find_path_to_neighbour(walkable: &HashSet, from: IVec2, to: IVec2) -> Option { +pub fn find_path_to_neighbour(game: &Game, 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)) + if game.walkable.contains(&to) { + paths.extend(find_path(game, from, to)) } } } paths.into_iter().min_by_key(|p| p.segments.len()) } -pub fn find_path(walkable: &HashSet, from: IVec2, to: IVec2) -> Option { +pub fn find_path(game: &Game, from: IVec2, to: IVec2) -> Option { #[derive(Debug, PartialEq, Eq)] struct Open { heuristic: i32, @@ -87,6 +88,7 @@ pub fn find_path(walkable: &HashSet, from: IVec2, to: IVec2) -> Option, from: IVec2, to: IVec2) -> Option