Timber Turncoat (JavaScript) help please

Seems like this should work, and I’m not sure what else to try. What am I missing?

while (true) {
    let item = hero.findNearestItem();
    if (item) {
        hero.move(item.pos);
    }
    if (hero.gold >= hero.costOf("soldier")) {
        hero.summon("soldier");
    }
    let friends = hero.findFriends();
    for (let friend of friends) {
        if (friend.type == "soldier") {
            let enemy = friend.findNearestEnemy();
            if (enemy) {
                hero.command(friend, "attack", enemy);
                if (friend.health < 100) {
                    hero.command(friend, "move", {x: 20,y: 46});
                }
            } else {
                hero.command(friend, "move", {x: 78,y: 46});
                
            }
        }
    }
}

Changed this: if (friend.health < 100)
To this: if (friend.health < friend.maxHealth/3)

Success!

Pretty sure I had tried this before, but oh well - I’ll take it!

This topic was automatically closed 12 hours after the last reply. New replies are no longer allowed.