Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- stack = []
- enum Direction { LEFT, RIGHT}
- def detect(distance): #return whether odometer is reading less than 30
- return True #if the US reading is less than the distance (bug antenna)
- def find_closest_wall(): #calculates what the nearest wall or river is, in the direction perpendicaular to the direction of travel
- return LEFT
- def avoid():
- avoid_direction = find_closest_wall() == Direction.LEFT ? Direction.RIGHT : Direction.RIGHT #opposite of the closest_wall direction
- rotate(90, avoid_direction) # blocking
- stack.add(avoid_direction)
- while stack: #is not empty
- if detect(30):
- rotate(90, avoid_direction) # blocking
- stack.push(avoid_direction) #push rotation onto stack to undo eventually
- else:
- straight(30, "forward")
- rotate(90, stack.pop())
- if obstacle:
- avoid()
- stack = [right]
- stack = [right, right]
- stack = [right]
- stack = []
- stack = [right]
- stack = []
- stack = []
- stack = []
- stack = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement