/** * @class Simplified Dijkstra's algorithm: all edges have a value of 1 * @augments ROT.Path * @see ROT.Path */ ROT.Path.Dijkstra = function(toX, toY, passableCallback, options) { ROT.Path.call(this, toX, toY, passableCallback, options); this._computed = {}; this._todo = []; this._add(toX, toY, null); } ROT.Path.Dijkstra.extend(ROT.Path); /** * Compute a path from a given point * @see ROT.Path#compute */ ROT.Path.Dijkstra.prototype.compute = function(fromX, fromY, callback) { var key = fromX+","+fromY; if (!(key in this._computed)) { this._compute(fromX, fromY); } if (!(key in this._computed)) { return; } var item = this._computed[key]; while (item) { callback(item.x, item.y); item = item.prev; } } /** * Compute a non-cached value */ ROT.Path.Dijkstra.prototype._compute = function(fromX, fromY) { while (this._todo.length) { var item = this._todo.shift(); if (item.x == fromX && item.y == fromY) { return; } var neighbors = this._getNeighbors(item.x, item.y); for (var i=0;i