# misc/pathfinder (vanilla.js 0.4.0)

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

그리드 길찾기. (A*)

## PathFinder extends Object

그리드 길찾기. (A*)
- 4방향 이동, 맨해튼 거리 휴리스틱, 이진 최소 힙으로 열린 목록을 관리한다.
- isBlockedHandler(column, row) 가 참이면 막힌 칸이다.
- 결과는 시작 칸을 제외하고 도착 칸까지의 { column, row } 배열. 길이 없으면 null.

예제: 벽을 돌아가는 길 찾기

```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): 경로 탐색. (정적)
  - `columnCount` number: 격자의 열 수.
  - `rowCount` number: 격자의 행 수.
  - `start` object: { column, row }
  - `goal` object: { column, row }
  - `isBlockedHandler` Function: (column, row) => boolean
  - returns object[] | null: 시작 칸을 뺀 도착 칸까지의 { column, row } 배열. (시작과 도착이 같으면 빈 배열, 길이 없거나 시작이나 도착이 격자 밖이거나 도착 칸이 막혔으면 null)
