#path-finding

stara

A* Search Algorithm

3 releases

0.0.3 Aug 17, 2024
0.0.2 Aug 14, 2024
0.0.1 Aug 13, 2024

#16 in #path-finding

Download history 311/week @ 2024-08-11 55/week @ 2024-08-18 24/week @ 2024-09-15 12/week @ 2024-09-22 61/week @ 2024-09-29

97 downloads per month

MIT license

17KB
304 lines

A* Pathfinding Library in Rust

Rust 🦀 library implementing the A* pathfinding algorithm. A* is used for efficiently finding the shortest path in a grid, mainly used for games.

Installation

Add the following to your Cargo.toml under [dependencies] to use it in your project:

[dependencies]
stara = "0.0.2"

Usage

Here’s an example of how to use the A* pathfinding algorithm with this library:

use stara::prelude::*;

fn main() {
    let start = VectorU::new(0, 0);
    let goal = VectorU::new(5, 5);
    let size = VectorU::new(7, 7);

    let mut grid = Grid::new(size, 1);

    // Setting an obstacle
    grid.set_cost(VectorU::new(3, 3), IMPASSABLE);

    let maybe_path = AStar::search(start, goal, &grid);
    if let Some(path) = maybe_path {
        println!("Path found: {:?}", path);
    } else {
        println!("No path found.");
    }
}

License

This project is licensed under the MIT License. See the LICENSE file for more details.

Dependencies

~17KB