UNPKG

@2d-game-grid/square

Version:
20 lines (19 loc) 728 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.mapHeuristic = mapHeuristic; const pathfinding_1 = require("pathfinding"); /** * @param grid The grid * @param heuristic The heuristic algorithm or a custom heuristic function * @returns A heuristic function for the pathfinding */ function mapHeuristic(grid, heuristic) { return typeof heuristic === 'function' ? (col, row) => heuristic(grid.getCell({ row, col })) : { MANHATTAN: pathfinding_1.Heuristic.manhattan, CHEBYSHEV: pathfinding_1.Heuristic.chebyshev, EUCLIDEAN: pathfinding_1.Heuristic.euclidean, OCTILE: pathfinding_1.Heuristic.octile, }[heuristic]; }