Help in Toil and Trouble


#1

i have a problem in Toil and Trouble.Witches win every time.My soldiers die. I can not make it work . Here is my code:

def chooseTarget(friend):
    if friend.type == "archer":
        if len(self.findByType("thrower")) > 0:
            return friend.findNearest(self.findByType("thrower"))
        elif len(self.findByType("witch")) > 0:
            return friend.findNearest(self.findByType("witch"))
        else:
            return friend.findNearest(self.findEnemies())
    elif friend.type == "soldier":
        return friend.findNearest(self.findByType("witch"))

loop:
    friends = self.findFriends()
    for friend in friends:
        # Use your chooseTarget function to decide what to attack.
        chooseTarget(friend)
        pass

help me plzzzzzzzzzzzzz! Thank you very much!


#2

Please format your code according to the FAQ. It makes it easier for us to be able to read your code and figure out the problem. Please do this in the future.


#3

FYI, you have to make your soldiers attack the nearest witch to them FIRST. Otherwise the soldiers won’t have enough health to take out the witches. But, the archers are fine. Also, it has to be with your friends vision not yours.


#4

Thank you , i did make it.


TOIL AND TROUBLE in the mountain