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