;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; catmouse (v. cat) ; ; by ; ;*****************************jj.helen.sophie*******************************; ; program by jj, version 2 ; ; robotics wintersession 2009 ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; menu 1 [initialize] menu 2 [go] menu 3 [piece+10] menu 4 [piece-10] menu 5 [move-random] global [number light some card control other count suit songon piece diff] ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;useless comments;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; ;;sensor 0 = left eye ; ;;sensor 1 = right eye ; ;;switch 10 = back bumper ;;switch 7, 8 = front bumper ; ;;switch 15 = magnet ; ;;some = engine-on value ; ;;card = turn direction value ; ;;light = auto threshold value ; ;;thatway = forward; thisway = backward ; ;;a = left wheel; b = right wheel ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;moving on;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; to initialize setlight (((sensor 0) + (sensor 1)) / 2) print light a, setpower 5 b, setpower 5 ; c, setpower 2 setcontrol 1 setother 800 setpiece 50 setcount 0 end to go when [(switch 7)][setcontrol 0 go-backwards go-random-direction setcontrol 1] when [(switch 8)][setcontrol 0 go-forwards go-random-direction setcontrol 1] when [and (switch 7)(sees-enough-light?)][stoprules play-song] move-random end to sees-enough-light? output or((sensor 1) < (light - piece))((sensor 0) < (light - piece)) end to move-random loop [ ifelse ((not sees-enough-light?)) [ ; c, off if (control = 1) [a, thatway on b, thisway on] ] [ if (control = 1) [ ; c, on setdiff ((sensor 0) - (sensor 1)) ifelse ((sensor 0) < (sensor 1)) [if (control = 1) [left]] [if (control = 1) [right]] if (and ((0 - 7) < diff) (diff < 7)) [if (control = 1) [go-straight]] if (and(switch 7)(sees-enough-light?))[play-song] ]] ] end to go-backwards setsome ((random 7) + 8) ab, thisway onfor some end to go-random-direction setcard (random 16) setsuit (random 2) ifelse (suit = 0) [a, onfor card][b, onfor card] end to go-forwards setsome ((random 7) + 8) ab, thatway onfor some end to play-song setsongon 1 beethoven end to beethoven loop[ ab, off wait 6 repeat 3 [play_note 90 1 1] play_note 86 7 5 repeat 3 [play_note 88 1 1] play_note 85 7 5 repeat 3 [play_note 90 1 1] play_note 86 1 1 repeat 3 [play_note 91 1 1] play_note 90 1 1 repeat 3 [play_note 98 1 1] play_note 95 2 5 repeat 3 [play_note 90 1 1] play_note 85 1 1 repeat 3 [play_note 91 1 1] play_note 88 1 1 repeat 3 [play_note 100 1 1] play_note 97 2 5 ] end to play_note :frequency :duration :wait if songon [note :frequency :duration wait :wait] end to right a, thatway on b, off end to left a, off b, thatway on end to go-straight a, thatway on b, thatway on end to piece+10 setpiece piece + 10 print piece end to piece-10 setpiece piece - 10 print piece end