A* Documentation
Astar Methods
b8.AStar.pathfind(start, goal, isWalkable, gridWidth, gridHeight)
A Pathfinding Algorithm for grid-based games.
The A algorithm is a popular pathfinding and graph traversal algorithm. It is widely used in games and other applications to find the shortest path between two points. The algorithm combines the benefits of Dijkstra’s algorithm and a heuristic approach to efficiently find the optimal path.
Key Concepts:
- Open List: A priority queue of nodes to be explored, sorted by their total cost (f).
- Closed List: A set of nodes that have already been explored.
- Heuristic (h): An estimate of the cost to reach the goal from a given node.
- Cost (g): The actual cost to reach a node from the start.
- Total Cost (f): The sum of g and h (f = g + h).
This implementation assumes a grid-based game where movement is restricted to horizontal and vertical directions. The algorithm explores neighboring cells and calculates their costs to determine the optimal path.
Parameters
-
start (Object): The starting position with properties
colandrow. -
goal (Object): The goal position with properties
colandrow. -
isWalkable (Function): A function that takes
colandrowcoordinates and returnstrueif the cell is walkable. - gridWidth (number): The width of the grid.
- gridHeight (number): The height of the grid.
Returns
- (Array<Object>|null): - The shortest path as an array of positions
{col, row}, ornullif no path is found.