Skip to content

Instantly share code, notes, and snippets.

@taptapdan
Created January 17, 2016 21:07
Show Gist options
  • Save taptapdan/8192c69df133e2c35370 to your computer and use it in GitHub Desktop.
Save taptapdan/8192c69df133e2c35370 to your computer and use it in GitHub Desktop.
CodeCombat: The Bane of Soldiers Solution
// http://codecombat.com/play/level/the-bane-of-soldiers
// Robobombs explode when they die or touch an enemy.
// Split up your soldiers so that they don't all get exploded together.
while (true) {
var friends = this.findFriends();
var enemies = this.findEnemies();
var targets = [];
// Determine which units are being targetted by bombs
for (var j = 0; j < enemies.length; j++) {
targets.push(enemies[j].target);
}
// For each unit
for (var i = 0; i < friends.length; i++) {
var friend = friends[i];
if (targets.indexOf(friend) == -1) {
// if the unit is not being target,
// then move the unit left
this.command(friend, "move", {
x: friend.pos.x - 5,
y: 32
});
} else {
// if the unit is being targetted,
// then move the unit up (away from the others)
this.command(friend, "move", {
x: friend.pos.x,
y: friend.pos.y + 5
});
}
}
}
@SpinoffHeyyyyy
Copy link

tyty

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment