@2d-game-grid/square
Version:
A simple square grid made for games
20 lines (19 loc) • 728 B
JavaScript
;
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];
}