UNPKG

@2d-game-grid/square

Version:
17 lines (16 loc) 611 B
import * as pathfinding from 'pathfinding'; /** * @param grid The grid * @param heuristic The heuristic algorithm or a custom heuristic function * @returns A heuristic function for the pathfinding */ export function mapHeuristic(grid, heuristic) { return typeof heuristic === 'function' ? (col, row) => heuristic(grid.getCell({ row, col })) : { MANHATTAN: pathfinding.Heuristic.manhattan, CHEBYSHEV: pathfinding.Heuristic.chebyshev, EUCLIDEAN: pathfinding.Heuristic.euclidean, OCTILE: pathfinding.Heuristic.octile, }[heuristic]; }