Skip to content

Instantly share code, notes, and snippets.

@avdg
Last active August 29, 2015 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save avdg/d4dfe33cfd858cdcf58a to your computer and use it in GitHub Desktop.
Save avdg/d4dfe33cfd858cdcf58a to your computer and use it in GitHub Desktop.
Screeps dump
c.prototype.findClosest = function(b, c) {
var e = this;
c = d.clone(c || {});
var f = a.rooms[this.roomName];
if (!f) throw new Error("Could not access a room " + this.roomName);
if (d.isUndefined(b)) return null;
var g, j = null, k = f.getEndNodes(b, c);
if (!c.algorithm) {
var l, m = 0;
k.objects.forEach(function(a) {
var b = a.x, c = a.y, f = a.roomName;
a.pos && (b = a.pos.x, c = a.pos.y, f = a.pos.roomName);
var g = i(h(e.x - b), h(e.y - c));
(d.isUndefined(l) || l > g) && (l = g), m += g;
}), c.algorithm = m > 10 * l ? "dijkstra" : "astar";
}
if ("dijkstra" == c.algorithm && (g = 1, k.objects.forEach(function(a) {
var b = e.isEqualTo(a) ? -1 : e.isNearTo(a) ? 0 : 1;
g > b && (j = a, b = g);
}), 1 == g)) {
var n = f.findPath(this, k.key, c);
if (n.length > 0) {
var o = n[n.length - 1], p = f.getPositionAt(o.x, o.y);
j = d.find(k.objects, function(a) {
return p.isEqualTo(a);
});
}
}
return "astar" == c.algorithm && k.objects.forEach(function(a) {
var b, h = e.isEqualTo(a) ? -1 : e.isNearTo(a) ? 0 : (b = e.findPathTo(a, c)) && b.length > 0 && f.getPositionAt(b[b.length - 1].x, b[b.length - 1].y).isNearTo(a) ? b.length : void 0;
(d.isUndefined(g) || g >= h) && !d.isUndefined(h) && (g = h, j = a);
}), j;
}
'use strict';
var a, c, i, h; // Unknowns
var e = require('constants');
var _ = require('lodash');
c.prototype.findClosest = function(objects, options) {
var e = this;
options = _.clone(options || {});
var room = a.rooms[this.roomName];
if (!room)
throw new Error("Could not access a room " + this.roomName);
if (_.isUndefined(objects))
return null;
var g, j = null, endNodes = room.getEndNodes(objects, options);
if (!options.algorithm) {
var l, m = 0;
endNodes.objects.forEach(function(a) {
var b = a.x, c = a.y, f = a.roomName;
a.pos && (b = a.pos.x, c = a.pos.y, f = a.pos.roomName);
var g = i(h(e.x - objects), h(e.y - c));
(_.isUndefined(l) || l > g) && (l = g), m += g;
});
options.algorithm = m > 10 * l ? "dijkstra" : "astar";
}
if ("dijkstra" == options.algorithm && (g = 1, endNodes.objects.forEach(function(a) {
var b = e.isEqualTo(a) ? -1 : e.isNearTo(a) ? 0 : 1;
g > b && (j = a, b = g);
}), 1 == g)) {
var n = room.findPath(this, endNodes.key, options);
if (n.length > 0) {
var o = n[n.length - 1];
var p = room.getPositionAt(o.x, o.y);
j = _.find(endNodes.objects, function(a) {
return p.isEqualTo(a);
});
}
}
return "astar" == options.algorithm && endNodes.objects.forEach(function(a) {
var b, h = e.isEqualTo(a) ? -1 : e.isNearTo(a) ? 0 : (b = e.findPathTo(a, options)) && b.length > 0 && room.getPositionAt(b[b.length - 1].x, b[b.length - 1].y).isNearTo(a) ? b.length : void 0;
(_.isUndefined(g) || g >= h) && !_.isUndefined(h) && (g = h, j = a);
}), j;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment