# misc/pathfinder (vanilla.js 0.4.0)

> https://vanillapunch.com/docs/vanilla.js/0.4.0/api/misc/pathfinder/

Grid pathfinding. (A*)

## PathFinder extends Object

Grid pathfinding. (A*)
- 4-directional movement, Manhattan distance heuristic, manages the open list with a binary min-heap.
- A cell is blocked if isBlockedHandler(column, row) is true.
- The result is an array of { column, row } up to the goal cell, excluding the start cell. null if there is no path.

Example: Find a path around a wall

```js
import { PathFinder } from "./build/vanilla.js";

const mapRows = [
	"....",
	"###.",
	"....",
];
const isBlocked = (column, row) => {
	return mapRows[row][column] === "#";
};
const path = PathFinder.findPath(4, 3, { column: 0, row: 0 }, { column: 0, row: 2 }, isBlocked);
console.log(path.length);
console.log(JSON.stringify(path));
```

- `static findPath(columnCount, rowCount, start, goal, isBlockedHandler)` (static, since 0.3.0): Finds a path. (static)
  - `columnCount` number: Number of grid columns.
  - `rowCount` number: Number of grid rows.
  - `start` object: { column, row }
  - `goal` object: { column, row }
  - `isBlockedHandler` Function: (column, row) => boolean
  - returns object[] | null: Array of { column, row } up to the goal cell, excluding the start cell. (An empty array if start and goal are the same; null if there is no path, the start or goal is outside the grid, or the goal cell is blocked)
