Skip to content

Instantly share code, notes, and snippets.

@new-guy
Created August 23, 2015 05:41
Show Gist options
  • Save new-guy/b267ab1873725a746a68 to your computer and use it in GitHub Desktop.
Save new-guy/b267ab1873725a746a68 to your computer and use it in GitHub Desktop.
Room.prototype.getLargestEnergyPile = function()
{
var droppedEnergyArray = this.find(FIND_DROPPED_ENERGY);
//console.log(droppedEnergyArray.length);
if(droppedEnergyArray.length === 0) return null;
var largestPile = droppedEnergyArray[0];
for(var i = 0; i < droppedEnergyArray.length; i++)
{
var currentPile = droppedEnergyArray[0];
if(currentPile.energy > largestPile.energy)
{
largestPile = currentPile;
}
}
return largestPile;
}
var energyPile = room.getLargestEnergyPile();
//console.log(energyPile);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment