The Agrippa Defense die too quickly

I am stuck on the Agrippa Defense. I do not know how to cleave on the third wave because when the third wave comes my code goes to the self.attack instead of the first part with the cleaving. Here is the code:

loop:
    enemy = self.findNearestEnemy()
    if enemy:
        distance=self.distanceTo(enemy)
        if distance<5 and self.isReady("cleave"):
                self.cleave(enemy)  
        else:
            self.attack(enemy)

Please help.


Update: I was able to complete the level by buying an upgrade in armor so I had more hit points, meaning I could survive long enough where the third wave didn’t 1 shot me. Since i survived a little longer I was able to cleave it and finish the level.

Was there a way to beat this level without buying new armor?

Think about it.
The level tells you to cleave and attack but you don’t have to do what the level tells you just complete the goals.
If hp is your problem try cleaving and shielding

Could it be that "cleave" hadn’t cooled down enough to use it again? I think that’s what happened to me.

This level is pretty tough to get with the if/else nesting. Actually, we intended that you shouldn’t attack when they are further than 5m away, too. That gives you the most time to recharge your cleave in between fights.