Skip to content

Instantly share code, notes, and snippets.

@new-guy
Created August 25, 2015 23:16
Show Gist options
  • Save new-guy/59f5e6f630cf5b3da520 to your computer and use it in GitHub Desktop.
Save new-guy/59f5e6f630cf5b3da520 to your computer and use it in GitHub Desktop.
function getCachedPath(originPosition, destinationPosition)
{
var originString = originPosition.roomName + "x" + originPosition.x + "y" + originPosition.y;
var destinationString = destinationPosition.roomName + "x" + destinationPosition.x + "y" + destinationPosition.y;
if(Memory.pathCache === undefined)
{
Memory.pathCache = {};
}
if(Memory.pathCache[originString] === undefined)
{
Memory.pathCache[originString] = {};
}
if(Memory.pathCache[originString][destinationString] === undefined || Memory.pathCache[originString][destinationString].length === 0)
{
Memory.pathCache[originString][destinationString] = originPosition.findPathTo(destinationPosition, {ignoreCreeps: true});
//console.log('Generating path to ' + destinationString + ' from ' + originString + ' length: ' + Memory.pathCache[originString][destinationString].length);
}
else
{
//console.log('Cache hit to ' + destinationString + ' from ' + originString + " " + Memory.pathCache[originString][destinationString].length);
}
return Memory.pathCache[originString][destinationString];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment