Munchkin Swarm Python


#1

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.


#2

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


#3

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.


#4

[Don’t post correct solutions]


#5

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