Guest User

Untitled

a guest
Dec 17th, 2018
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. to switch-traffic-lights
  2. let horizontals patches with [signal? != nobody and (dir = "W" or dir = "E")]
  3. let verticals patches with [signal? != nobody and (dir = "S" or dir = "N")]
  4.  
  5. switch-list-traffic-lights horizontals
  6. switch-list-traffic-lights verticals
  7.  
  8. end
  9.  
  10. to switch-list-traffic-lights [lights]
  11. ask lights[
  12. set ticks-signal ticks-signal + 1
  13. ]
  14.  
  15. ifelse [signal?] of one-of lights = "red-light" and [ticks-signal] of one-of lights >= 50 + 4
  16. [
  17. ask lights[
  18. set ticks-signal 0
  19. set pcolor green
  20. set signal? "green-light"
  21. ]
  22. ]
  23. [
  24. ifelse [signal?] of one-of lights = "orange-light" and [ticks-signal] of one-of lights >= 4
  25. [
  26. ask lights[
  27. set ticks-signal 0
  28. set pcolor red
  29. set signal? "red-light"
  30. ]
  31. ]
  32. [
  33. if [signal?] of one-of lights = "green-light" and [ticks-signal] of one-of lights >= 50
  34. [
  35. ask lights[
  36. set ticks-signal 0
  37. set pcolor orange
  38. set signal? "orange-light"
  39. ]
  40. ]
  41. ]
  42. ]
  43. end
  44.  
  45.  
  46. to signal-event
  47. switch-traffic-lights
  48. end
Add Comment
Please, Sign In to add comment