TDGuy
December 7, 2014, 1:21pm
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.
TDGuy
December 7, 2014, 1:23pm
2
I tried something, I put the “enemy = self.findNearestEnemy” in the look and it fixed my issue
nick
December 7, 2014, 3:45pm
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.
how2uz
January 24, 2015, 7:10pm
4
[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.