So I am on munchkin swarm, and my code doesn’t have problems as far as I know, but when I use it, I don’t break the chest in time, I don’t think I can do this without like a claymore or something.
loop:
enemy = self.findNearestEnemy()
enemyDistance = self.distanceTo(enemy.pos)
if self.isReady("cleave"):
if enemyDistance < 10:
self.cleave(enemy)
else:
self.attack(enemy)
else self.attack("Chest")
You have a very specific task:
Only cleave when they come close, otherwise attack the chest.
Your first code does not accomplish this.
Your second code does.
As J_F_B_M states, the task is to attack the chest.
This (I suspect) is to help teach us how to prioritize our operations better.
I created a bit of code that detects how many units are nearby, and I only cleave when the number exceeds a threshold.