Help! How can I go through Fragile Maze?

# Escape from the maze!
# Some doors are blocked, some open when you are near them.

DBR = 16
startRoom = {"x": 18, "y": 19}
hero.move(startRoom)
while True:
    # up
    if hero.isPathClear(hero.pos, {'x': hero.pos.x, 'y': hero.pos.y + DBR}):
        hero.moveXY(hero.pos.x, hero.pos.y + DBR)
    elif hero.isPathClear(hero.pos, {'x': hero.pos.x + DBR, 'y': hero.pos.y}):
        hero.moveXY(hero.pos.x + DBR, hero.pos.y)
        # right
    elif hero.isPathClear(hero.pos, {'x': hero.pos.x, 'y': hero.pos.y - DBR}):
        hero.moveXY(hero.pos.x, hero.pos.y - DBR)
        # down
    elif hero.isPathClear(hero.pos, {'x': hero.pos.x - DBR, 'y': hero.pos.y}):
        hero.moveXY(hero.pos.x - DBR, hero.pos.y)
        # left
    

Here is my code. What is wrong?

The basic concept of your code is a good start, but you need to consider how to prevent your hero from back tracking. My hero got stuck with your code going up and down when backtracking sent him back up first. Also, instead of making a priority of if’s, make sure you check for all possibilities, then pick one that isn’t going backwards, unless you hit a dead end.

I tried his code, it was circling.

you are supposed to use your own code to pass this level not by using other’s code

2 Likes

you could just use flags, I use flags and ritics blink ability and it worked perfectly

how in the world can you do that because it is restricted you know

This topic was a long time ago. I already restarted so I’m not there anymore :frowning:. Thanks for helping me on it. :slight_smile: