Skip to content

Instantly share code, notes, and snippets.

@taptapdan
Created January 17, 2016 19:27
Show Gist options
  • Save taptapdan/99a828152023f4489a36 to your computer and use it in GitHub Desktop.
Save taptapdan/99a828152023f4489a36 to your computer and use it in GitHub Desktop.
CodeCombat: Hunting Party Solution
// http://codecombat.com/play/level/hunting-party
// Strategy: move all troops continuously to the right,
// making sure to keep the archers behind the frontline
// so that the soldiers take the enemy attacks. Player
// character follows along the front line and heals
// any soldier/archer that is below max health.
var front = [ 30, 30, 30 ]; // Frontline for Groups
while (true) {
var friends = this.findFriends();
for (var i = 0; i < friends.length; i++) {
// Assign Groups to Friends
if (friends[i].pos.y > 56) {
friends[i].group = 0;
} else if (friends[i].pos.y < 37) {
friends[i].group = 2;
} else {
friends[i].group = 1;
}
// Movement, Groups
if (friends[i].type == "soldier") {
this.command(friends[i], "move", {
x: friends[i].pos.x + 5, y: friends[i].pos.y
});
if (friends[i].pos.x > front[friends[i].group]) {
front[friends[i].group] = friends[i].pos.x;
}
} else {
this.command(friends[i], "move", {
x: front[friends[i].group] - 5, y: friends[i].pos.y
});
}
// Healing
if (friends[i].health < friends[i].maxHealth) {
if (this.canCast("regen", friends[i])) {
this.cast("regen", friends[i]);
}
}
// Attack
var enemy = friends[i].findNearestEnemy();
if (enemy) {
this.command(friends[i], "attack", enemy);
}
}
// Movement, Me
this.move( { x: front[1], y: this.pos.y } );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment