This is a Node.JS implementation for AStar path finding algorithm. This implementation uses primitive data types (Number and Byte/Buffer) to present location and block data that significantly improve the speed and have a good control on memory consumption
npm install node-pathfinding
var array2d, buf, grid, height, path, pathfinding, width;
pathfinding = require("node-pathfinding");
array2d = [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [1, 1, 0, 0], [1, 0, 0, 0]];
width = 4;
height = 5;
// generate grid from 2D array
buf = pathfinding.bytesFrom2DArray(width, height, array2d);
grid = pathfinding.buildGrid(width, height, buf);
path = pathfinding.findPath(1, 0, 1, 4, grid);
console.log("path:" + path);
// print the path
console.log("path on grid :" + (grid.toString(1 << 16 | 0, 1 << 16 | 4, path)));
// output:
// path:65536,131072,131073,196609,196610,196611,196612,131076,65540
// path on grid :[Grid(width=4, height=5)]
// Dump: ░=walkable, ▓=blocked
// ▓S1░
// ░▓23
// ░░▓4
// ▓▓░5
// ▓E76
x << 16 | y
Try node tests/sync_astar_continue_test.js
it does a continuous test of pathfinding on some map fixtures, and the vm memory recycled correctly.