## 18. Amazing - part 2

Here's the cause of the problem we had at the end of part 1: we put down a beeper and, before we had the chance to move, tested to see if we were not next to a beeper. Since we were next to a beeper, we never go the chance to get in the while loop. Perhaps we can change the program to add a `move()` before we start the loop, as follows:

    put_beeper()
    move()
    while not on_beeper():
        if front_is_clear():
            move()
        else:
            turn_left()

    turn_off()

Try it!

### Not so simple world

Let's try the program we wrote on a slightly more complicated world, like the one below which you can easily reproduce. You may want to save the world to a world file before you try your program.

When you try your program, you will see that the result is not exactly what we wanted: Reeborg takes a shortcut, and doesn't go all the way around.

The problem is that we assumed that Reeborg only had to move forward or turn left to go around the world; we never took into account situations where we would have wanted him to make a right turn. What Reeborg needs to do is first to check on his right to see if there is still a wall; if not, we have him make a right turn. Here's a modified program that attempts to do just that:

    def turn_right():
        repeat(turn_left, 3)

    put_beeper()
    move()
    while not on_beeper():
        if right_is_clear():
            turn_right()
        elif front_is_clear():
            move()
        else:
            turn_left()

    turn_off()

Does it work? Read it carefully to decide for yourself. Then try it to confirm your opinion, or make any change you think appropriate.

Amazing - part1 - - Amazing - part 3