My code works but soldiers aren’t strong enough
function collect() {
let item = hero.findNearestItem();
let coin = item.pos;
if (hero.gold < 25 && item.value > 2) {
hero.moveXY(coin.x, coin.y);
}
else if (hero.gold < 25 && item.value > 1) {
hero.moveXY(coin.x, coin.y);
}
else{
hero.moveXY(coin.x, coin.y);
}
if (hero.gold > 40) {
hero.summon("soldier");
hero.summon("soldier");
}
}
function command() {
let friends = hero.findFriends();
let enemy = hero.findNearestEnemy();
for (let i = 0; i < friends.length; i++) {
let friend = friends[i];
if (friend.type == "soldier" && enemy) {
hero.command(friend, "attack", enemy);
} else if (friend.type == "soldier" && !enemy) {
hero.command(friend, "move", {
"x": 85,
"y": 45
});
continue;
} if (friend.type == "soldier" && friend.health < 100) {
hero.command(friend, "move", {
"x": 17,
"y": 46
});
}
}
}
while (true) {
collect();
command();
}