Reeborgs Maze Puzzle
Lost in a maze
Reeborg was exploring a dark maze and the battery in its flashlight ran out.
Write a program using an if/elif/else statement so Reeborg can find the exit. The secret is to have Reeborg follow along the right edge of the maze, turning right if it can, going straight ahead if it can’t turn right, or turning left as a last resort.
What you need to know
- The functions
move()andturn_left(). - Either the test
front_is_clear()orwall_in_front(),right_is_clear()orwall_on_right(), andat_goal(). - How to use a
whileloop andif/elif/elsestatements. - It might be useful to know how to use the negation of a test (
notin Python).
Difficulty level










A robot located at (x, y) = (2, 5) carries no objects.
Goal to achieve:
The final position of the robot must be (x, y) = (6, 4)https://reeborg.ca/reeborg.html?lang=en&mode=python&menu=worlds%2Fmenus%2Freeborg_intro_en.json&name=Maze&url=worlds%2Ftutorial_en%2Fmaze1.json
def turn_right():
turn_left()
turn_left()
turn_left()
#turn_left()
while at_goal()==0:
if front_is_clear() and right_is_clear():
turn_right()
move()
elif front_is_clear():
move()
elif right_is_clear():
turn_right()
move()
else:
turn_left()
Comments
Post a Comment