UNPKG

@2d-game-grid/square

Version:
17 lines (16 loc) 526 B
import {Heuristic} 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: Heuristic.manhattan, CHEBYSHEV: Heuristic.chebyshev, EUCLIDEAN: Heuristic.euclidean, OCTILE: Heuristic.octile, }[heuristic] }