global [count last-turn candle]
to main
setcount 0
setlast-turn 0
setcandle 0
run
end
to run
setcount 0
hallway
send 7 ; tell Ckt 1 to turn wheels off
send 2 ; tell Ckt 2 to check for candle
check-room
if (candle)
[into-room
send 7 ; to Ckt 1 - turn wheels off
send 3 ; to Ckt 2 - start extinguish
stop]
exit-room
if (last-turn = 8)
[send 12]
if (last-turn = 9)
[send 13]
run
end
to hallway
loop [if (sensorb > 10)
[resestt
waituntil [sensorb < 10]
if (timer < 2000)
[setcount 1
stop]
if (newir?)
[if ((ir = 8) or (ir = 9))
[setlast-turn ir]
]
end
to check-room
waituntil [newir?]
if ((ir = 0) or (ir = 1))
[setcandle ir]
end
to into-room
waituntil [sensorb > 10]
waituntil [sensorb < 10]
setcount 2
end
to exit-room
send 11 ; to Ckt 1 - back up
waituntil [sensorb > 10]
waituntil [sensorb < 10]
send 7 ; to Ckt 1 - wheels off
end