;This program for sheriff
;motor a - left wheel
;motor b - right wheel
;Outlaw motors a and b are reversed to allow for one
;program to run both robots
;Sheriff initialize 1 - to play song
;Outlaw initialize 0
global [black dead am-i-sheriff]
to duel
walk-out
back-to-back
pace
turn-around
draw-and-fire
end
to walk-out
go-straight 50
wait 10
end
to go-straight :tenths
ab, thisway onfor :tenths
end
to back-to-back
turn-left
waituntil [sees-black? front-sensor] stop-motion 1
wait 10
ifelse am-i-sheriff [lone-ranger irsend 47]
[waituntil [ir = 47]]
wait 10
end
to turn-left
right-wheel on thisway
left-wheel on thatway
end
to stop-motion :tenths
ab, rd onfor :tenths
left-wheel off
right-wheel off
end
to left-wheel
a,
end
to right-wheel
b,
end
to sees-black? :sensor-value
output :sensor-value > black
end
to front-sensor
output sensor 0
end
to initialize :sheriff
setblack 75
printblack
setam-i-sheriff :sheriff
end
to printblack
type [black=] print black
end
to lone-ranger
repeat 2 [note 70 1 wait .5
note 70 1 wait .5
note 70 1.5 wait .5]
note 70 1 wait .5
note 70 1 wait .5
note 75 1.5 wait .5
note 77 1.5 wait .5
note 79 1.5 wait .5
note 70 1 wait .5
note 70 1 wait .5
note 70 1.5 wait .5
note 70 1 wait .5
note 70 1 wait .5
note 75 1.5 wait .5
note 79 1 wait .5
note 79 1 wait .5
note 77 1.5 wait .5
note 74 1.5 wait .5
note 70 1.5 wait .5
repeat 2 [note 70 1 wait .5
note 70 1 wait .5
note 70 1.5 wait .5]
note 70 1 wait .5
note 70 1 wait .5
note 75 1.5 wait .5
note 77 1.5 wait .5
note 79 1.5 wait .5
note 75 1 wait .5
note 79 1 wait .5
note 82 6 wait 1.5
note 79 1 wait .5
note 79 1 wait .5
note 75 1.5 wait .5
note 79 1.5 wait .5
note 75 1.5
end
to pace
go-straight 40
wait 20
end
to turn-around
turn-right
waituntil [sees-black? front-sensor] stop-motion 4
end
to turn-right
left-wheel on thisway
right-wheel on thatway
end
to draw-and-fire
setdead 0
wait 20
forever [if (and (ir = 53) (not dead)) [die]]
wait (random 60)
ifelse dead [do-nothing] [draw]
;; if (not dead) [draw]
end
to die
setdead 1
stoprules ; Kill any draw process currently going
c, thisway onfor 100
taps
end
to do-nothing
end
to draw
d, onfor 20
if (not dead)
[launch [repeat 10 [irsend 53 wait 1]]
d, onfor 80
]
end
to taps
note 70 7 wait .5
note 70 3 wait .5
note 75 13 wait 3
note 70 7 wait .5
note 75 3 wait .5
note 79 13 wait 3
repeat 2 [note 70 5 wait .5
note 75 3 wait .5
note 79 5 wait 3]
note 70 5 wait .5
note 75 3 wait .5
note 79 13 wait 3
note 75 7 wait .5
note 79 3 wait .5
note 82 13 wait 3
note 79 7 wait .5
note 75 3 wait .5
note 70 13 wait 3
note 70 7 wait .5
note 70 3 wait .5
note 75 13 wait 3
end