U-PathAStar Demo

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.nodeIdFieldstring
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);
}

Algorithm Performance

Performance Metrics

Run pathfinding to see performance metrics

Priority Queue

Queue Operations

PriorityQueue.create() → Object
Creates new priority queue instance for A* algorithm
queue.push(priority, payload)
Adds item to queue with given priority
queue.pop() → any
Removes and returns lowest priority item

Legend

Start Position
End Position
Optimal Path
Wall