Mountain Mercenaries (Python)

When I run this code, all that happens is that I summon some soldiers with the gold I already have, and then I am frozen building something.

# Gather coins to summon soldiers and have them attack the enemy.

while True:
    # Move to the nearest coin.
    # Use move instead of moveXY so you can command constantly.
    coins = hero.findNearest(hero.findItems())
    coinIndex = 0
    while coinIndex < len(coins):
        coin = coins[coinIndex]
        if coin:
    coinIndex += 1
    # If you have funds for a soldier, summon one.
    if > hero.costOf("soldier"):
    enemy = hero.findNearest(hero.findEnemies())
    soldiers = hero.findFriends()
    soldierIndex = 0
    while soldierIndex < len(soldiers):
        soldier = soldiers[soldierIndex]
        if enemy:
            hero.command(soldier, "attack", enemy)
        soldierIndex += 1
        # Use the 'attack' command to make your soldiers attack.
        #hero.command(soldier, "attack", enemy)

I eventually die because my soldiers are attacking but they eventually die am I am still frozen in place.

you should change all of this (or self :smile:) to

    coin = hero.findNearest(hero.findItems())

because you don’t need to loop through coins, you only need to focus on one coin

1 Like