Help in Toil and Trouble

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!

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.

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.

Thank you , i did make it.

how do you find the nearest witch?

I’m not sure try looking up tutorials.

Also for future reference make sure to create another post for this. This post has been dead for over for years so it doesn’t make a lot of sense to bring it back.

Thanks!:slight_smile:

Something like this should work:

soldier.findNerest(hero.findByType("witch"))
1 Like