Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- to switch-traffic-lights
- let horizontals patches with [signal? != nobody and (dir = "W" or dir = "E")]
- let verticals patches with [signal? != nobody and (dir = "S" or dir = "N")]
- switch-list-traffic-lights horizontals
- switch-list-traffic-lights verticals
- end
- to switch-list-traffic-lights [lights]
- ask lights[
- set ticks-signal ticks-signal + 1
- ]
- ifelse [signal?] of one-of lights = "red-light" and [ticks-signal] of one-of lights >= 50 + 4
- [
- ask lights[
- set ticks-signal 0
- set pcolor green
- set signal? "green-light"
- ]
- ]
- [
- ifelse [signal?] of one-of lights = "orange-light" and [ticks-signal] of one-of lights >= 4
- [
- ask lights[
- set ticks-signal 0
- set pcolor red
- set signal? "red-light"
- ]
- ]
- [
- if [signal?] of one-of lights = "green-light" and [ticks-signal] of one-of lights >= 50
- [
- ask lights[
- set ticks-signal 0
- set pcolor orange
- set signal? "orange-light"
- ]
- ]
- ]
- ]
- end
- to signal-event
- switch-traffic-lights
- end
Add Comment
Please, Sign In to add comment