I don’t quite get the move() method for coin collecting; till now I’ve been using the moveXY(). I’ve tried passing in the variable position, and when that didn’t work I tried using x,y of position, then coin.pos… now he does a slow ice-skating to each coin instead of rapidly collecting coins.
// Gather coins to summon soldiers and have them attack the enemy.
loop {
// Move to the nearest coin.
// Use move instead of moveXY so you can command constantly.
while (this.gold < this.costOf("soldier")) {
var coin = this.findNearest(this.findItems());
this.say("I need coins!");
this.move(coin.pos);
}
// If you have funds for a soldier, summon one.
if (this.gold > this.costOf("soldier")) {
this.say("I should summon something here!");
this.summon("soldier");
}
var enemy = this.findNearest(this.findEnemies());
if (enemy) {
// Loop over all your soldiers and order them to attack.
var soldiers = this.findFriends();
var soldierIndex = 0;
while (soldierIndex < soldiers.length){
var soldier = soldiers[soldierIndex];
soldierIndex++;
// Use the 'attack' command to make your soldiers attack.
this.command(soldier, "attack", enemy);
}
}
}