Skip to content

Instantly share code, notes, and snippets.

@gmjosack
Created October 27, 2013 18:54
Show Gist options
  • Save gmjosack/7186437 to your computer and use it in GitHub Desktop.
Save gmjosack/7186437 to your computer and use it in GitHub Desktop.
This is just a simple solution to the game https://node-defender.herokuapp.com/
var enemy, attackModes, positions, types, mostPos, closestPos;
positions = {};
types = {};
enemy = _.first(roundInfo.getMobs());
commander.target(enemy.id);
commander.attackMode('power');
_.each(roundInfo.getMobs(), function(mob, idx){
if (!_.has(positions, mob.position)) positions[mob.position] = [];
positions[mob.position].push(mob);
if (!_.has(types, mob.type)) types[mob.type] = [];
types[mob.type].push(mob);
});
mostPos = _.max(_.pairs(positions), function(elem){
return elem[1].length;
})[0];
closestPos = _.min(_.keys(positions));
commander.target(positions[closestPos][0].id);
if (closestPos >= 2){
commander.attackMode('ranged');
if (_.has(types, "flyer")){
var furthest = _.first(types.flyer);
_.each(types.flyer, function(mob, idx){
if (mob.position > furthest.position) furthest = mob;
});
commander.target(furthest.id);
}
}
if (positions[mostPos].length >= 3){
commander.target(positions[mostPos][0].id);
commander.attackMode('collateral');
}
if (_.has(positions, 0)){
_.each(positions[0], function(mob, idx){
if (mob.type == "grunt" || mob.type == "bruiser" || mob.type == "trooper"){
commander.target(mob.id);
commander.attackMode('power');
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment