Why reeborg does not working well in Python

55 views Asked by At

I am new to Python and I was trying to train on reeborg website and it went fine، but on hurdle 4 I tried everything I know but The bot still does not working well

This is my code:

def turn_right():
    turn_left()
    turn_left()
    turn_left()


while not at_goal():
    if front_is_clear():
        while front_is_clear():
            if not wall_on_right():
                turn_right()
                move()
                turn_right()

            move()

        if wall_on_right():
            turn_left()

    else:
        if not wall_on_right():
            turn_right()
            move()
            turn_right()

        if wall_on_right():
            turn_left()

        while wall_on_right():
            move()

Can someone help me?

1

There are 1 answers

0
André On

Watch your program execute: the error occurs when Reeborg reaches the top of the world and the world border, which is a wall, messes up with you logic. You are trying to do too many things in a complex set of if/while conditions.

Break your code into more separate functions, each function containing either a single if/else set of instructions, or a single while loop.

Try then to string together the following general step:

  1. Walk to the bottom of a hurdle.
  2. Turn to face "up".
  3. Jump over a single hurdle until you reach the bottom facing down.
  4. turn towards the next and move towards it.

Repeat steps 1 to 4 until you reach the goal.