# Move to the nearest coin.
# Use move instead of moveXY so you can command constantly.
item = hero.findNearestItem()
# If you have funds for a soldier, summon one.
if hero.gold > hero.costOf("soldier"):
enemy = hero.findNearestEnemy()
soldiers = hero.findFriends()
soldierIndex = 0
soldier = soldiers[soldierIndex]
# Loop over all your soldiers and order them to attack.
while soldierIndex < len(soldiers):
hero.command(soldier, "attack", enemy)
soldierIndex += 1
# Use the 'attack' command to make your soldiers attack.
#hero.command(soldier, "attack", enemy)