Friendly minefield

while True:
    enemy = hero.findNearestEnemy()
    if enemy.pos.y > hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y + 4)
    enemy = hero.findNearestEnemy()
    if enemy.pos.y < hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y - 4)
    else:
        hero.moveXY(hero.pos.x + 12, hero.pos.y)

the 4rth munchkin will not move away so my hero can move anywhere else

Hello, Welcome to the Forum.

I can’t find that level in the list. What is the actual name of this level? This will help us make sure we are matching the instructions and be able to test the code.

One thing I did notice, you don’t need to reassign the enemy variable if you use elif instead of a second if. By doing this, you may be counteracting your first if.

    enemy = hero.findNearestEnemy()
    if enemy.pos.y > hero.pos.y:
        hero.moveXY(hero.pos.x, hero.pos.y + 4)
    enemy = hero.findNearestEnemy() # remove this 
    if enemy.pos.y < hero.pos.y: # change to elif
        hero.moveXY(hero.pos.x, hero.pos.y - 4)

To play any level, just type codecombat.com/play/level/insert level name
So this level would be codecombat.com/play/level/friendly-minefield
However, it is subscriber only, so I can’t really help with that.

1 Like