So, some of my soldiers will attack, some will just stand there, my hero just runs around collecting coins, and Hector always dies.
// If the peasant is damaged, the flowers will shrink!
function summonSoldiers() {
if (hero.gold >= hero.costOf("soldier")) {
hero.summon("soldier");
}
}
// Define the function: commandSoldiers
function commandSoldiers() {
var soldiers = hero.findByType("soldier", hero.findFriends());
var soldierIndex =0;
for(var i =0; i< soldiers.length; i++){
var soldier = soldiers[soldierIndex];
var enemy = soldier.findNearestEnemy();
if(enemy){
hero.command(soldier, 'attack', enemy);
}
}
}
// Define the function: pickUpNearestCoin
function pickUpNearestCoin(){
var coin = hero.findNearestItem();
if (coin){
hero.move(coin.pos);
}
}
var peasant = hero.findByType("peasant")[0];
while(true) {
summonSoldiers();
// commandSoldiers();
commandSoldiers();
// pickUpNearestCoin();
pickUpNearestCoin();
}