Help with level "distracting dungeon"


#1

Hi guys,
I am stocked on this level.
I think I haven’t understood the nested while loops yet, I can’t find the mistakes in my code. Do you have an idea for me? My hero just runs against the wall after defeating the two first enemies…

# Navigate the mountain maze with a peasant pal.
# Advanced while-loop usage is required!

peasant = hero.findNearest(hero.findFriends())
while True:
    # Command your friend to build a decoy towards x + 1:
    hero.command(peasant, "buildXY", "decoy", hero.pos.x+1, hero.pos.y)
    tDest = {"x": hero.pos.x, "y": hero.pos.y + 28};
    while hero.distanceTo(tDest) > 1:
        hero.move(tDest)
        hero.command(peasant, "move", tDest)
    # Create a new x/y dict +28 units away in the x dir:
    tDest = {"x": hero.pos.x + 28, "y": hero.pos.y};
    # Find the nearest enemy:
    enemy = hero.findNearest(hero.findEnemies())
    while enemy:
        while enemy.health > 0: 
            hero.attack(enemy)
        enemy = hero.findNearest(hero.findEnemies())
    while peasant.distanceTo(tDest) > 1:
        hero.command(peasant, "move", tDest)
        hero.wait(3)

#2
while peasant.distanceTo(tDest) > 1:
        hero.command(peasant, "move", tDest)
        hero.wait(3)

// Move the hero and peasant towards second point


#3

Thank you, i fixed that and now i also got the speed of ring equip. But now my hero is killed because he runs after the “brawlers” and get killed near the ende of the labyrinth.

I tried:

        while enemy.health > 0 and enemy.type != "brawler": 
            hero.attack(enemy)

But know there’s an infinite loop (error message).


#4

If enemy exist and enemy type is brawler your hero do nothing while part below executed again and again

while enemy:


       enemy = hero.findNearest(hero.findEnemies())

#5

I still just can’t solve this level. now i am running out of time after hero attacked successfully all brawlers. Any idea or suggestion?

# Navigate the mountain maze with a peasant pal.
# Advanced while-loop usage is required!

peasant = hero.findNearest(hero.findFriends())
while True:
    # Command your friend to build a decoy towards x + 1:
    hero.command(peasant, "buildXY", "decoy", hero.pos.x+1, hero.pos.y)
    tDest = {"x": hero.pos.x, "y": hero.pos.y + 28};
    while hero.distanceTo(tDest) > 1:
        hero.move(tDest)
        hero.command(peasant, "move", tDest)
    # Create a new x/y dict +28 units away in the x dir:
    tDest = {"x": hero.pos.x + 28, "y": hero.pos.y};
    # Find the nearest enemy:
    enemy = hero.findNearest(hero.findEnemies())
    while enemy:
        while enemy.health > 0: 
            if enemy.type == "brawler": 
                if hero.isReady("power-up"):
                    hero.powerUp()
                else:
                    if hero.canCast("chain-lightning", enemy): 
                        hero.cast("chain-lightning", enemy)
                    else: 
                        hero.attack(enemy)
            else: 
                hero.attack(enemy)
        
        enemy = hero.findNearest(hero.findEnemies())
    while peasant.distanceTo(tDest) > 1:
        hero.move(tDest)
        hero.command(peasant, "move", tDest)
        
        

#6

Ok. I finally solved it!


#7

how do u have a hint