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