# Ogre Witches have some unpleasant surprises ready for you. # Define a chooseTarget function which takes a friend argument # Returns a target to attack, depending on the type of friend. # Soldiers should attack the witches, archers should attack nearest enemy. def chooseTarget(friend): enemies = friend.findEnemies() enemy = friend.findNearest(enemies) witches = self.findByType("witch", enemies) witch = friend.findNearest(witches) if friend and friend.type is "soldier" and enemy and witch and witch.health > 0: friend.command(friend, "attack", witch) if friend and friend.type is "archer" and enemy: self.command(friend, "attack", enemy) loop: friends = self.findFriends() for friend in friends: # Use your chooseTarget function to decide what to attack. chooseTarget(friend)
The biggest mistakes are the smallest.
yay I finally did it!!
you asked your friend to command him/herself.