Help with "Mad Maxer"


#1

Here is my code

loop:
    maxDistance = 0
    enemyIndex = 0
    enemies = self.findEnemies()

    # Look at all the enemies to figure out which one is farthest away.
    while enemyIndex < len(enemies):
        target = enemies[enemyIndex]
        enemyIndex += 1

        # Is this enemy farther than the farthest we've seen so far?
        distance = self.distanceTo(target)
        if distance > maxDistance:
            maxDistance = distance
            farthest = target

    if farthest:
            # Take out the farthest enemy!
            self.attack(farthest)
            farthest = None

I don’t know what is wrong. It tries to attack the flying enemy, but can’t. He gives up on that and starts to kill the witches and dies.


#2

Currently your hero attacks the farthest enemy once, After attacking it once, he searches for the enemy that is now farthest. And since your hero is now close to the flying enemy, it is not the farthest anymore. So you have to search the farthest, attack him until he is dead and only then start the search for a new enemy.


#3

I replaced

if farthest:
            # Take out the farthest enemy!
            self.attack(farthest)
            farthest = None

with

    if farthest:
        while farthest.health>0:
            if self.isReady("cleave"):
                self.cleave(farthest)
            else:
                self.attack(farthest)

and it worked. Thank you for the help.