# Stay alive for one minute.
# If you win, the next time you play will be more difficult and more rewarding!
# If you lose, you must wait a day before submitting again.
while True:
enemy = hero.findNearestEnemy()
item = hero.findNearestItem()
soldiers = hero.findFriends() # add an 's', make this an array
flag = hero.findFlag("green")
if enemy:
if hero.canCast("chain-lightning", enemy):
hero.cast("chain-lightning", enemy)
else:
hero.attack(enemy)
elif item:
hero.move(item.pos)
if hero.gold > hero.costOf("soldier"):
hero.summon("soldier")
for soldier in soldiers: # command each soldier in 'soldiers' array...
soldierEnemy = soldier.findNearestEnemy() # make a enemy
if soldierEnemy:
hero.command(soldier, "attack", soldierEnemy) #attack the enemy!
The reason you need to use a for-loop is because you need to select a single object to command, you cannot command ALL soldiers at once, even if the command method is really fast.
If you still have trouble about for-loop structures, you can check out this tutorial which covers 3 types of for-loops: Guide