Code
def chooseTarget(friend):
friends = hero.findFriends()
for friend in friends:
if friend.type == "soldier":
return "attack-witch"
elif friend.type == "archer":
return "attack-nearest"
def attackWitch():
soldiers = hero.findByType("soldier")
for soldier in soldiers:
witch = soldier.findNearest(hero.findByType("witch"))
if witch:
hero.command(soldier, "attack", witch)
def attackNearest():
archers = hero.findByType("archer")
for archer in archers:
enemy = archer.findNearest(archer.findEnemies())
hero.command(archer, "attack", enemy)
while True:
friends = hero.findFriends()
for friend in friends:
# Use your chooseTarget function to decide what to attack.
target = chooseTarget(friend)
if target == "attack-witch":
attackWitch()
elif target == "attack-nearest":
attackNearest()
pass
Error
Everyone dies before all the ogres are dead. There were 2 ogres left when everyone died.
Lydia