vanilladocs
vanillapunch.com
API / misc/pathfinder

misc/pathfinder

그리드 길찾기. (A*)

Grid pathfinding. (A*)

PathFinderextends Object

짝Counterpart: vanilla-engine PathFinder

그리드 길찾기. (A*)

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

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
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));
정적staticstatic findPath(columnCount, rowCount, start, goal, isBlockedHandler)#0.3.0 부터since 0.3.0소스source

경로 탐색. (정적)

Finds a path. (static)

columnCountnumber
격자의 열 수.Number of grid columns.
rowCountnumber
격자의 행 수.Number of grid rows.
startobject
{ column, row }
goalobject
{ column, row }
isBlockedHandlerFunction
(column, row) => boolean

반환Returnsobject[] | null 시작 칸을 뺀 도착 칸까지의 { column, row } 배열. (시작과 도착이 같으면 빈 배열, 길이 없거나 시작이나 도착이 격자 밖이거나 도착 칸이 막혔으면 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)

짝Counterpart: vanilla-engine PathFinder.find_path