Pathfinding
Interactive Grid
Click Generate Maze, then Find Path to see A* in action
Grid Configuration
0.3
API Overview
This is a GENERIC A* implementation, it doesn't assume a grid or anything. It can traverse any graph structure as long as you provide an `eachNeighbor()` function that returns neighboring nodes.Pathfinding Functions
PathAStar.find(startNode, endNode, eachNeighbor, getCost, getCostHeuristic) → Object
Finds optimal path between two nodes using A* algorithm. Returns result object with path array and debug information.
PathAStar.extractPath(history, endNode, idField) → Array
Extracts complete path from pathfinding history
Configuration
PathAStar.config.nodeIdField → string
Field used for node identification (default: 'id')
PathAStar.config.defaultLinearDistance(fromNode, toNode) → number
Default Euclidean distance calculation between nodes
Usage Examples
// Define neighbor function function getNeighbors(node, callback) { const dirs = [[0,-1], [1,0], [0,1], [-1,0]]; dirs.forEach(([dx, dy]) => { const x = node.x + dx; const y = node.y + dy; if (isWalkable(x, y)) { callback({x, y, id: `${x},${y}`}); } }); } // Find path const result = PathAStar.find( startNode, endNode, getNeighbors ); if (result.result === 'path') { console.log('Path found:', result.path); }