https://github.com/xzripper/astard
A* (A-Star) search algorithm for 2D spaces (grids) for D.
https://github.com/xzripper/astard
2d algorithm algorithms astar astar-algorithm astar-pathfinding d game-development pathfinding
Last synced: 3 months ago
JSON representation
A* (A-Star) search algorithm for 2D spaces (grids) for D.
- Host: GitHub
- URL: https://github.com/xzripper/astard
- Owner: xzripper
- License: mit
- Created: 2025-03-19T01:48:47.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2025-03-19T02:34:17.000Z (3 months ago)
- Last Synced: 2025-03-19T02:39:04.474Z (3 months ago)
- Topics: 2d, algorithm, algorithms, astar, astar-algorithm, astar-pathfinding, d, game-development, pathfinding
- Language: D
- Homepage: https://github.com/xzripper/AStarD
- Size: 0 Bytes
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# AStarD
A* (A-Star) search algorithm for 2D spaces (grids) with straightforward/diagonal movement with 4 available heuristics:
- **Manhattan**
- **Euclidean**
- **Octile**
- **Chebyshev**AStarD is extremely easy to use, while its performance fits within the average A* execution time.
[[0, 0], [1, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 8], [9, 8]]
```d
import AStarD.AStar;void main() {
int[][] grid = [
[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0],
[0, 0, 0, 0, 1, 1, 0, 0, 0, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 1, 0, 0, 0],
[1, 0, 1, 0, 0, 0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0],
[0, 1, 0, 1, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0],
[0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0],
[1, 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 0, 0, 1, 1, 0],
[0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 1, 0, 1, 1],
[0, 1, 0, 1, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 0],
[1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 0, 1, 1, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0],
[0, 0, 1, 0, 0, 1, 1, 1, 0, 1, 1, 0, 1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 0, 0, 0],
[1, 1, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1, 0, 1, 0, 0, 1],
[0, 0, 0, 1, 0, 1, 1, 0, 1, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 0, 0, 1, 1, 0, 1],
[0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 1, 1, 0, 0, 0, 1, 1, 0, 1, 0, 0, 0, 1, 1],
[1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 0, 1, 0, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0],
[1, 0, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 0],
[0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 1, 1, 0]
];AStar(grid, [0, 0], [9, 8], Heuristic.MANHATTAN, true); // Returns [[0, 0], [1, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 6], [6, 7], [7, 8], [8, 8], [9, 8]]
}
```**`AStar` signature:
`ASPath ASter(Grid2D p_Grid, Position2D p_Start, Position2D p_Target, Heuristic p_Heuristic, bool p_AllowDiagonalMovement)`
Where `ASPath` is `int[2][]`,
`Grid2D` is `int[][]`,
`Position2D` is `int[2]`.**