[Solved] Munchkin Swarm Python

I’m having an issue with Munchkin Swarm. Presently I’m using Python to code it and here is my code:

enemy = self.findNearestEnemy()
loop:
    if self.distanceTo(enemy) < 10:
       if self.isReady("cleave"):
            self.cleave(enemy)
        else:
            self.attack("Chest")
    else:
        self.attack("Chest")
Simple Code
enemy = self.findNearestEnemy()
loop:
    if self.distanceTo(enemy) < 7:
       self.cleave(enemy)
    else:
        self.attack("Chest")

I have attempted this code in simpler terms and it comes to the same effect. When the code runs it usually gets stuck at “self.cleave”. This code seems to cycle back through the “self.cleave” too soon. If I change the value for the distance it then doesn’t go off at all if it is below 6. The best time I seem to have gotten is 34.7 which looks to be 3/4 complete since it is the 2nd wave that kills me. Not sure what I’m doing wrong.

I tried something, I put the “enemy = self.findNearestEnemy” in the look and it fixed my issue

Ah, good debugging. Yeah, if the enemy assignment is not in the loop, then enemy will always have the value of the first enemy you saw.

[Don’t post correct solutions]

thanks so much, i spent 3 whole Computing lessons trying to do this my teacher didn’t even know…

I’m also having issues but my issue is that I cannot attack the munkins and I just keep on hitting the chest. I cant find the problem

`while True:
        enemy = hero.findNearestEnemy()
    distance = hero.distanceTo(hero.findNearestEnemy())
    if distance < 10:
        hero.attack(enemy)
    else:
        hero.attack("Chest")
    pass
    `

You put enemy in the wrong place, try deleting one indentation in line 2.

Don’t worry, I put new armor so my hero could last.