Expand description
A* Search Algorithm
A* is an informed search algorithm that finds the shortest path using a heuristic function to guide the search. It’s widely used in pathfinding for games, robotics, and navigation systems.
§Examples
use advanced_algorithms::graph::{Graph, astar};
let mut graph = Graph::new(4);
graph.add_edge(0, 1, 1.0);
graph.add_edge(1, 2, 1.0);
graph.add_edge(2, 3, 1.0);
// Simple heuristic: assume all remaining distance is 1
let heuristic = |node: usize| if node == 3 { 0.0 } else { 1.0 };
let result = astar::find_path(&graph, 0, 3, heuristic).unwrap();
assert_eq!(result.1.len(), 4); // Path has 4 nodesStructs§
- GridPos
- Grid coordinates for 2D pathfinding
Functions§
- find_
path - Finds shortest path from start to goal using A* algorithm
- find_
path_ bounded - A* algorithm with early termination and path weight limit