;; Joust by Zach Johnson
;;
;;IR com:
;; Device 1 Device 2
;; ping 30-39 40-49
;; backup 11 12
;; time 21 22
;;
;; Device1
global [ misscount devid otherid pingcount watchcount timer]
to run
loop
[
timetogo
forward
backward
]
end
to timetogo
wait 100
loop
[
if 1 = c ir [stop]
send 21
send 21
]
end
to c :cmd
if :cmd > 29 [output 1 stop]
if :cmd = 22 [output 1 stop]
output 0
end
to forward
a, on
a, thatway
setmisscount 0
settimer 0
setpingcount 30
setwatchcount 41
loop
[
if 1 = watch ir [a, off stop]
ping
ping
]
end
to backward
a, on
a, thisway
loop
[
send 11
wait 2
if switcha [a, off stop]
]
end
to ping
send pingcount
end
to watch :cmd
;;we see the other
if :cmd = watchcount
[
setpingcount pingcount + 1
setwatchcount watchcount + 1
if pingcount = 200
[
setpingcount 30
setwatchcount 41
]
settimer 0
setmisscount 0
output 0
]
;;the other cart is backing up
if :cmd = 12
[
output 1
]
;; didn't see anything
settimer timer + 1
if timer > 10
[
setmisscount misscount + 1
if misscount = 5
[
output 1
]
]
output 0
end