Restless dead - it's restless


#1
# This level is supposed to be VERY hard! You may need a great strategy and or gear to complete it!

# Find and defeat the yeti then gather its essence for the ritual.
# You might want to gather the coins the yeti leaves behind, you'll need them to summon an army
# Stand at the summoning stone (red x) to begin summoning
# Now you just have to survive the undead hoard
def beginning():
    while True:
        item = hero.findNearestItem()
        enemy = hero.findNearestEnemy()
        if item:
            hero.moveXY(item.pos.x, item.pos.y)
        if enemy:
            hero.attack(enemy)
        if hero.gold > 270:
            break
pass

def summon():
    while True:
        if hero.gold > hero.costOf("soldier"):
            hero.summon("soldier")
        if hero.gold < hero.costOf("soldier"):
            break
    
def army():
        friends = hero.findFriends()
        for friend in friends:
            enemies = friend.findEnemies()
            for enemy in enemies:
                if enemy:
                    hero.command(friend, "attack", enemy) 
                if not friend:
                    break
                

def bye():
    enemies = hero.findEnemies()
    for enemy in enemies:
        if enemy and hero.isReady("devour"):
            hero.devour(enemy)
        elif enemy:
            hero.attack(enemy)

hero.moveXY(51, 37)
beginning()
hero.moveXY(19, 40)
summon()

while True:
    army()
    bye()

Been stuck a while on this. For some reason my hero after attacking then always starts moving away to one side but I am not sure why; any ideas?! Thanks in advance