Advertisement
Guest User

Untitled

a guest
Nov 15th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.04 KB | None | 0 0
  1. stack = []
  2. enum Direction { LEFT, RIGHT}
  3.  
  4. def detect(distance): #return whether odometer is reading less than 30
  5. return True #if the US reading is less than the distance (bug antenna)
  6.  
  7. def find_closest_wall(): #calculates what the nearest wall or river is, in the direction perpendicaular to the direction of travel
  8. return LEFT
  9.  
  10.  
  11.  
  12.  
  13. def avoid():
  14. avoid_direction = find_closest_wall() == Direction.LEFT ? Direction.RIGHT : Direction.RIGHT #opposite of the closest_wall direction
  15.  
  16. rotate(90, avoid_direction) # blocking
  17. stack.add(avoid_direction)
  18.  
  19. while stack: #is not empty
  20. if detect(30):
  21. rotate(90, avoid_direction) # blocking
  22. stack.push(avoid_direction) #push rotation onto stack to undo eventually
  23. else:
  24. straight(30, "forward")
  25. rotate(90, stack.pop())
  26.  
  27.  
  28. if obstacle:
  29. avoid()
  30.  
  31.  
  32. stack = [right]
  33. stack = [right, right]
  34. stack = [right]
  35. stack = []
  36. stack = [right]
  37. stack = []
  38. stack = []
  39. stack = []
  40. stack = []
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement