[Help] Timber Turncoat

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);
    }
            }
        }
    }

Whats the retreat code? if (friend.health === 100)? If so try if (friend.health < 100)

SOS!!! What’s wrong with my code?
My friends can not kill at least one enemy!

while True:

coin = hero.findNearestItem()
if coin:
    hero.move(coin.pos)
if  hero.gold > hero.costOf("soldier"):
    hero.summon("soldier")



for friend in hero.findFriends():
    if friend.type == "soldier":
        distance = hero.distanceTo(friend)
        if distance < 20:
            if friend.health < friend.maxHealth:
                if hero.canCast("regen", friend):
                    hero.cast("regen", friend)
        enemy = hero.findNearestEnemy()
        if enemy and enemy.health > 0:
            hero.command(friend, "attack", enemy)
        if friend.health < friend.maxHealth*0.3:
            hero.command(friend, "move", {"x": 24, "y": 46})
        else:
            hero.command(friend, "move", {"x": 80, "y": 46})

try telling them to defend instead of move , i swear to god , that took me like 2 days to figure out , i figure that by now you’ve already moved on from this but still

There’s a bit of a cheat: just summon burls which destroy the enemy!

Most people aren’t subscribers :sob:

Can I ask you for some help on two levels on Cloudrip Mountain? If you say yes I will message the question as it isn’t on topic.

Yeah sure (20 charssss)