A* pathfinding through an ndarray of cost values.
Implemented by wrapping ndarray accessors around abstract-pathfinder.
npm install --save ndarray-pathfinder
var finder = require('ndarray-pathfinder')
// array through which to pathfinding
var arr = new ndarray(new Float32Array(25), [5, 5])
// barriers
arr.set(1, 1, 100)
arr.set(2, 1, 100)
arr.set(3, 1, 100)
// start/end nodes
var start = [0, 0]
var goal = [3, 3]
// returns path as array of n-length arrays
var path = finder(arr, start, goal)
// path: [ [0,0], [0,1], ... ]
var preferDiag = true
var costFcn = function(value) {
if (value < 0) return -1
return 1 + value
}
var path = finder(arr, start, goal, preferDiagonal, costFcn)
preferDiagonal
- a flag that adds a small term to the heuristic to prefer cells closer the goalcostFunction
- a function to convert ndarray values to movement costs
- Orthogonal (l1) moves only for now
- Should work in any dimension (2D or above)
Andy Hall. MIT license.