From db9a9e53ca18911fb2045b7d6af4ed6df388eaaa Mon Sep 17 00:00:00 2001 From: mat Date: Mon, 5 Jan 2026 08:29:53 +0330 Subject: fix panic in a_star and some prep for pathfinder swimming --- azalea/src/pathfinder/astar.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) (limited to 'azalea/src/pathfinder/astar.rs') diff --git a/azalea/src/pathfinder/astar.rs b/azalea/src/pathfinder/astar.rs index 719036f0..04ffdb80 100644 --- a/azalea/src/pathfinder/astar.rs +++ b/azalea/src/pathfinder/astar.rs @@ -170,12 +170,12 @@ where } } - let best_path = determine_best_path(best_paths, 0); + let best_path_idx = determine_best_path_idx(best_paths, 0); log_perf_info(start_time, num_nodes, num_movements); Path { - movements: reconstruct_path(nodes, best_path, successors), + movements: reconstruct_path(nodes, best_paths[best_path_idx], successors), is_partial: true, - cost: best_path_scores[best_path], + cost: best_path_scores[best_path_idx], } } @@ -194,16 +194,16 @@ fn log_perf_info(start_time: Instant, num_nodes: usize, num_movements: usize) { ); } -fn determine_best_path(best_paths: [usize; 7], start: usize) -> usize { +fn determine_best_path_idx(best_paths: [usize; 7], start: usize) -> usize { // this basically makes sure we don't create a path that's really short - for node in best_paths { + for (i, &node) in best_paths.iter().enumerate() { if node != start { - return node; + return i; } } warn!("No best node found, returning first node"); - best_paths[0] + 0 } fn reconstruct_path( -- cgit v1.2.3