Ok I think my code is correct but my soldiers get overwhelmed and the warlock keeps resurrecting the munchkins. Also when you look at the retreat code, they don’t.
while(true) {
// Collect gold.
var item = hero.findNearestItem();
if (item) {
hero.move(item.pos);
}
// If you have enough gold, summon a soldier.
if (hero.gold > 20) {
hero.summon("soldier");
// Use a for-loop to command each soldier.
var friends = hero.findFriends();
for(var friendIndex = 0; friendIndex < friends.length; friendIndex++) {
var friend = friends[friendIndex];
if(friend.type == "soldier") {
var enemy = friend.findNearestEnemy();
// If there's an enemy, command her to attack.
// Careful! If your soldiers are defeated, a warlock will appear!
// Otherwise, move her to the right side of the map.
if (enemy) {
hero.command(friend, "attack", enemy);
}else{
hero.command(friend, "move", {'x' : 79, 'y' : 38});
}
}
if (friend.health === 100) {
hero.command(friend, "move", hero.pos);
}
}
}
}