Munchkin Swarm help

I am stuck on Munchkin Swarm on python. I can’t figure out what the code should be. Please help me.
My code so far is:

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

I’ve tried a lot of different codes and none of them have worked.

A hint: you can’t compare self.findNearestEnemy() to 10 with a < operator, because it returns an enemy object, not a number. You want to compare the distanceTo(enemy) with 10 with a < operator (you want to cleave if the distance is less than 10).

I have problems aswell I took your advice, but this doesn’t seem to work for me. It says I have to find the distance, but i did. Here’s my code

loop:
    enemy=self.findnearestEnemy
    if self.distanceTo(enemy)< 10:
        self.cleave(enemy)
    else: 
        self.attack("chest")

(Gallowned and I solved this in the chat.)

This is what I have

# If the ogres rush at you, cleave them!
# If they stay 10 meters away, attack the "Chest".

loop:
    enemy = 
    if self.distanceTo(enemy):
        self.cleave(enemy)
    else:
        self.attack("Chest")

if self.distanceTo(enemy): just asks whether the distance is truthy. Since distance is a number, that’ll be true whenever it’s not zero. But it’s always more than zero. You probably want to see whether the distance is less than 10 with if self.distanceTo(enemy) < 10:.

loop {
var enemy = this.findNearestEnemy();
var dast = this.distanceTo(enemy);

if (dast < 3) {
    if (this.isReady("cleave")) {
        this.cleave(enemy);            
    }
    if (!this.isReady("cleave")) {
        this.attack(enemy);
    }
}
if (dast > 10) {
        this.attack("Chest");        
}

}

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

this the best I have so far ill post the real answer when figure it out.

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

Success!!!

1 Like

Are you sure its right? Because I tried it and I think else is wrong. I tried to even fix else too and it didn’t work.

I finally got a code.

loop:
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")   
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    self.attack("Chest")
    enemy = self.findNearestEnemy()
    self.cleave(enemy)
    loop:
        self.attack("Chest")   
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        self.attack("Chest")
        enemy = self.findNearestEnemy()
        self.cleave(enemy)

I don’t think this is how it should be done.
I’m going to assume that the everything but the loops should be intended.

This code is not correct (it is not wrong, but also not correct) because:

  1. Your second loop will never be executed, because the first one never stops running.
  2. You should only cleave when they are closer than 10 units.
  3. You should not cleave unless the enemies are closer than 10 units.

Programming Style tip:

  1. You should check if this.sReady("cleave") before cleaving.

I assume you just got the timing right with all your attacks, and it might even work, but if your enemies close in too late, you don’t catch anyone with your cleave, and if they close in too early you get damage up to a point where you die unless you have a lot of HP.

2 Likes

This is what I have.

It works perfectly.

[Snip] Don’t post correct code.

4 Likes

Thanks i was having trouble! :sun_with_face: :+1:

Hello, LumpyImp, and welcome. For future reference, please read the FAQ on how to format your code.

Please do not post correct code on the forums, as it gives players the answer without them learning the required material.

please help. I tried everything, including what was on this post. i’m so confused. please help.

i gave up and restarted. this is what i have:

loop:
self.findNearestEnemy()
self.attack(enemy)
self.attack(enemy)

Hello, Hannah, and welcome. Please format your code according the FAQ.

You have to define an enemy before you attack one. Instead of self.findNearestEnemy(), use enemy = self.findNearestEnemy().

1 Like

You don’t have to do all that! All I did was self.attack(“Chest”) and it let me win.

Thank you for your opinion. Unfortunately, some players have less armor than you do, and so they must utilize this strategy instead of simply attacking the chest.

Has it occurred to you that this thread is twenty days old, and Hannah has likely already solved this level and moved on? Please leave the dead resting.

Need help nothing helps.
while True:
enemy = self.findNearestEnemy()
distance = hero.distanceTo(enemy)

enemy = hero.findNearestEnemy
if enemy < 10:
ready = hero.isReady(“cleave”)
hero.cleave(enemy)

else:
hero.attack(“Chest”)
hero.attack(“Chest”)