Created
January 17, 2016 21:07
-
-
Save taptapdan/8192c69df133e2c35370 to your computer and use it in GitHub Desktop.
CodeCombat: The Bane of Soldiers Solution
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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 | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
tyty