From 32e6a215aaf8a81365fafc945e80eb6caa9cace3 Mon Sep 17 00:00:00 2001 From: CircleCI Date: Thu, 2 Jan 2025 21:51:00 -0300 Subject: [PATCH] =?UTF-8?q?=C3=AFmproved=20a=20star?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bracket-pathfinding/Cargo.toml | 1 + bracket-pathfinding/src/astar.rs | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/bracket-pathfinding/Cargo.toml b/bracket-pathfinding/Cargo.toml index 50f631c1..41f763ba 100755 --- a/bracket-pathfinding/Cargo.toml +++ b/bracket-pathfinding/Cargo.toml @@ -23,6 +23,7 @@ bracket-algorithm-traits = { path = "../bracket-algorithm-traits", version = "~0 num-rational = { version = "0.4", default-features = false, features = ["std"] } rayon = { version = "1.5.0", optional = true } smallvec = "~1" +hashbrown = "0.13.2" [dev-dependencies] crossterm = "~0.25" diff --git a/bracket-pathfinding/src/astar.rs b/bracket-pathfinding/src/astar.rs index c46c15a9..f0701f76 100755 --- a/bracket-pathfinding/src/astar.rs +++ b/bracket-pathfinding/src/astar.rs @@ -1,6 +1,7 @@ use bracket_algorithm_traits::prelude::BaseMap; +use hashbrown::HashMap; use std::cmp::Ordering; -use std::collections::{BinaryHeap, HashMap}; +use std::collections::BinaryHeap; use std::convert::TryInto; /// Bail out if the A* search exceeds this many steps. @@ -109,13 +110,13 @@ impl AStar { let s = Node { idx, f: q.g + cost + distance_to_end, - g: cost, + g: q.g + cost, }; // If a node with the same position as successor is in the open list with a lower f, skip add let mut should_add = true; if let Some(e) = self.parents.get(&idx) { - if e.1 < s.g { + if e.1 <= s.g { should_add = false; } }