Skip to content

Instantly share code, notes, and snippets.

@ryancole
Created June 19, 2014 20:19
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 ryancole/97930f370e81ee7bd405 to your computer and use it in GitHub Desktop.
Save ryancole/97930f370e81ee7bd405 to your computer and use it in GitHub Desktop.
gold rush mode human
// get all items in this frame split into regions
function getRegionItems (items) {
var result = [];
items.forEach(function (item) {
var x = Math.floor(item.pos.x / 28);
var y = Math.floor(item.pos.y / 28);
var region = (x * 4) + y;
if (result[region] === undefined) {
result[region] = [item];
} else {
result[region].push(item);
}
});
return result;
}
// get most valuable region index
function getValuableRegionIndex (regions) {
var index = 0;
var previous = 0;
regions.forEach(function (region, i) {
if (region !== undefined) {
var sum = region.reduce(function (a, b) {
return a.bountyGold + b.bountyGold;
});
if (sum > previous) {
index = i;
}
}
});
return index;
}
// initialize state if its empty
var state = this.state || { };
// update the items grid
state.items = getRegionItems(this.getItems());
// update the most valuable cell
state.region = getValuableRegionIndex.call(this, state.items);
this.say(state.region);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment