Code


Home

Photos

Game

Code

About Us

 

We were worried about the reliability of IR communication between handyboards, so we decided to use light to communicate. Each handyboard had a LED light and a light sensor. To distinguish between a handyboard signalling a 'win' versus a handyboard signaling a turn change, turn changes were just one short light, and wins were several 'blinks'.

Defining the ports was difficult. I initially tried to define them as "a (or b, etc) in the initialize method, but that didn't work. Scott pointed out I needed new methods for each one.

I found that text stayed on the handyboard until new text overwrote it, so I developed a simple 'ClearHB' method that was very handy.

There are a lot of global variables, as local variables weren't functioning properly. Namely, the compiler couldn't handle them.

There were a few last minute changes. Our cars started having problems going backwards, so whereas previously a player answering a trivia question incorrectly would have moved back a space, now they just didn't move forward.

We were having problems with our code. Namely, it seemed to be killing handyboards left and right. Scott suggested we cut the program down, and we had fewer problems after that. Unfortunately, that meant we lost the kid trivia section, as well as many of the Wellesley College trivia questions. We also were planning on adding music for the end winning sequence, but decided that would take too much memory.

You can see the old code here.

Below is our 'pared down' version of code. This is for player 1. Player 2's code was almost identical, except for a few 'startTurns' in startGame were taken out.

New Code:

menu 1 [playGamePlayer1]
global [light white turnLoss
squareNum winSquare
roll count ans response switchTwo won blink]

to switchOne ;true, and used to 'roll' die
output switch 7
end


to switchTwo ;false
output switch 15
end


to lightSensor
output sensor 6
end


to reflSensor
output sensor 0
end


to initialize
setlight 180
setturnLoss 0
setwhite 100
setsquareNum 0
setwon 0
setblink 0
end

to charPort
a,
end


to lightPort
b,
end


to profPort
c,
end


to monsterPort
d,
end


to playGamePlayer1
initialize

startTurn ;for player one ONLY

loop[
waituntil [lightSensor < light]
waituntil [lightSensor > light]
setblink 0
when [lightSensor < light]
[setblink (blink + 1) ]

wait 40
stoprules ; KILL testBlink
wait 15
ifelse (blink < 2)
[
startTurn
]
[
clearHB
print [game over!]
initialize
startTurn ; if player 1
]
if (won = 1)
[
initialize
startTurn ;player 1 only
]
]
end

to clearHB ;to clear handyBoard screen
top print []
bottom print []
endto startTurn
ifelse (turnLoss = 1) ;if they lost a turn
[
lightPort onfor 20 ;turn on light so other knows its turn
setturnLoss 0
]
[
wait 10
top print [Press the true ]
bottom print [button to roll]
setroll rolldie
clearHB
print roll ;so player can see roll
wait 10
ifelse (or (roll = 1) (roll = 5)) ;if they roll a 1 or 5
[
clearHB
top print [Is the following]
bottom print [true or false?]
wait 15

trivia (random 20)
]
[fwd roll]
]
end


to rolldie
waituntil [switchOne]
ifelse ( or (squareNum = 1) (squareNum = 0) )
[
output ((random 3) + 2)
]
[
output ((random 5) + 1)
]
end

to playEnd
charPort off
print [Yay, you won!!]
profPort onfor 50
clearHB
lightPort onfor 5 ;blink to tell other handyboard player won
wait 5
lightPort onfor 5
wait 5
lightPort onfor 5
setwon 1
end


to fwd :number ;moves car ahead number spaces
setcount 0
loop[
ifelse (count < :number)
[charPort on thisway
waituntil [square?]
waituntil [not square?]
setcount (count + 1)
setsquareNum (squareNum + 1)
if (squareNum = 10)
[
charPort off
playEnd
stop
]
]
[
charPort off
if (not (:number = 1))
[translate squareNum]
stop
]
]
end


to square? ;if refl. sensor senses white, true
output (reflSensor > white )
end

to translate :res
if (:res = 2)
[top print [enjoy spring]
bottom print [break.Move ahead]
wait 4
fwd 1]
if (:res = 3)
[top print [Attacked by mons]
bottom print [ter. Lose turn.]
setturnLoss 1
wait 4
monsterPort thatway onfor 50
monsterPort thisway onfor 50]

if (:res = 4)
[top print [Get an A on exam]
bottom print [Move ahead]
wait 7
fwd 1]
if (:res = 5)
[top print [Internet goes]
bottom print [down. Lose turn.]
wait 7
setturnLoss 1]
if (:res = 6)
[top print [Free pizza lunch]
bottom print [Move ahead]
wait 7
fwd 1]
if (:res = 7)
[top print [Grades are def-]
bottom print [flated. Lose turn.]
wait 7
setturnLoss 1]
if (:res = 8)
[top print [Personal Lake]
bottom print [Day.Move ahead]
wait 7
fwd 1]
if (:res = 9)
[top print [Flamed on commun]
bottom print [-ity. Lose turn.]
wait 7
setturnLoss 1]
if (:res = 10)
[top print [Boston Marathon]
bottom print [Day.Move ahead]
wait 7
fwd 1]
lightPort onfor 2 ;turn on light so other knows its turn
;print [turning on light now!]
end

to answer
waituntil [or switchOne switchTwo]
if switchOne
[setresponse 1] ;true
if switchTwo
[setresponse 0] ;false
profPort off
end;0 is false, 1 is true
to trivia :num
profPort on
if (:num = 0)
[top print [The college was]
bottom print [founded in 1874]
setans 0]
if (:num = 1)
[top print [You can triple]
bottom print [major here]
setans 0]
if (:num = 2)
[top print [Paintshop Pond]
bottom print [exists on campus]
setans 1]
if (:num = 3)
[top print [Greenhouse is]
bottom print [open 365days/yr]
setans 1]
if (:num = 4)
[top print [There's asbestos]
bottom print [in the tunnels]
setans 1]
if (:num = 5)
[top print [New Dorms were]
bottom print [built in 1970]
setans 0]
if (:num = 6)
[top print [Science Center]
bottom print [has 6 floors]
setans 1]
if (:num = 7)
[top print [Wellesley has]
bottom print [a forge.]
setans 1]
if (:num = 8)
[top print [Billings is in]
bottom print [Science Center]
setans 0]
if (:num = 9)
[top print [We can cross-]
bottom print [reg @ Brandeis]
setans 1]
if (:num = 10)
[top print [DCW is our]
bottom print [10th president]
setans 0]
if (:num = 11)
[top print [WC was founded]
bottom print [by the Durants]
setans 1]
if (:num = 12)
[top print [our endowment is]
bottom print [about $1.4 bill]
setans 1]
if (:num = 13)
[top print [The art library]
bottom print [is in Founders]
setans 0]
if (:num = 14)
[top print [There are over]
bottom print [2500 students]
setans 0]
if (:num = 15)
[top print [Paramecium Pond]
bottom print [is natural]
setans 0]
if (:num = 16)
[top print [College Hall was]
bottom print [the 1st building]
setans 1]
if (:num = 17)
[top print [WC has had 3]
bottom print [male presidents]
setans 0]
if (:num = 18)
[top print [Classes used to]
bottom print [pick their color]
setans 1]
if (:num = 19)
[top print [Lake Hs does not]
bottom print [have an elevator]
setans 0]
if (:num = 20)
[top print [El in El Table]
bottom print [means elevator]
setans 1]

answer

ifelse (response = ans)
[clearHB
print [Correct!]
fwd 1]

[clearHB
print [Sorry, wrong]
]

lightPort onfor 10 ; turn on light so other knows its turn
end

Go to top of page

Old Code

menu 1 [playGames]
menu 2 [playTrivia]
menu 3 [playTrans]

global [light white lightSensor turnLoss
squareNum winSquare
roll count ans response switchTwo kid won blink]

;light - for turn change, so light from other handyboard according to light sensor
;white - # that for refl. sensor means white
;lightSensor - sensor number for light sensor
;turnLoss - if this is 1, person loses a turn (and then it
;changes back to 0), otherwise doesn't do anything
;squareNum - number of the square which user is on
;winSquare - the total # of sq on that side (so winning square)
;roll - roll of die. would be local but that doesn't work
;count - # of spaces moved in turn
;ans - t or f (0 = f, 1 = t) - correct answer
;response - person's response (0 or 1)
; kid - true if kid, false if adult. use this in startGame. test in startTurn
;won - 1 if game won, 0 otherwise
;blinks - counts # of blinks

to playTrivia
trivia (random 31)
end


to playTrans
translate 4
end

to switchOne ;true, and used to 'roll' die
output switch 7
end

to switchTwo ;false
output switch 15
end

to lightSensor
output sensor 6
end

to reflSensor
output sensor 0
end

to initialize
setlight 100 ; for testing now, make higher later?
setturnLoss 0
setwhite 200
setsquareNum 0
setwon 0
setblink 0
end

to charPort
a,
end

to lightPort
b,
end

to profPort
c,
end

to monsterPort
d,
end

to playGames
initialize
top print [Kid Version: T]
bottom print [WC Version: F]
waituntil [or switchOne switchTwo]
if switchOne
[setkid 1] ;kid version
if switchTwo
[setkid 0] ;WC version
clearHB

startTurn ;for player one ONLY

loop[
waituntil [lightSensor < light]
launch [testBlink]
wait 40
stoprules ; KILL testBlink
ifelse (blink < 2)
[
setblink 0
startTurn
]
[
initialize
startTurn ; if player 1
]
if (won = 1)
[playEnd
initialize
startTurn ;player 1 only
]
]
end


to testBlink
loop[
when [lightSensor < light]
[setblink (blink + 1) ]
]
end

;to startGame
; initialize
; top print [Kid Version: T]
; bottom print [WC Version: F]
; waituntil [or switchOne switchTwo]
; if switchOne
; [setkid 1] ;kid version
; if switchTwo
; [setkid 0] ;WC version
;clearHB
;startTurn ;player 1
;waitTurn ; player 2
;end

to clearHB ;to clear handyBoard screen
top print []
bottom print []
end


;to waitTurn
;loop [
;waituntil [lightSensor < light]
; startTurn
; if (setwon = 1)
;[stop]
;]
;end

to startTurn
ifelse (turnLoss = 1) ;if they lost a turn
[
lightPort onfor 20 ;turn on light so other knows its turn
setturnLoss 0
]
[
wait 10
top print [Press the true ]
bottom print [button to roll]
setroll rolldie
print roll ;so player can see roll
wait 10
ifelse (or (roll = 1) (roll = 5)) ;if they roll a 1 or 5
[
clearHB
top print [Is the following]
bottom print [true or false?]
wait 20
ifelse (kid = 0)
[trivia (random 31)]
[kidTrivia (random 20)]
]
[fwd roll]
]

end

to rolldie
waituntil [switchOne]
output ((random 5) + 1)
end


to playEnd
profPort onfor 50
lightPort onfor 5 ;blink to tell other handyboard player won
wait 5
lightPort onfor 5
wait 5
lightPort onfor 5
setwon 1
end

to fwd :number ;moves car ahead number spaces
setcount 0
loop[
ifelse (count < :number)
[charPort on thisway
waituntil [square?]
waituntil [not square?]
setcount (count + 1)
setsquareNum (squareNum + 1)
if (squareNum = 9)
[
playEnd
stop
]
]
[
top print [squareNum is]
bottom print squareNum
charPort off
if (not (:number = 1))
[translate squareNum]
stop
]
]
end

to square? ;if refl. sensor senses white, true
output (reflSensor > white )
end


to translate :res

if (:res = 2)
[top print [Locked out of]
bottom print [room. Lose turn.]
setturnLoss 1]
if (:res = 3)
[top print [Attacked by mons]
bottom print [ter. Lose turn.]
setturnLoss 1
monsterPort thisway onfor 15
monsterPort thatway onfor 15]

if (:res = 4)
[top print [Get an A on exam]
bottom print [Move ahead]
fwd 1]
if (:res = 5)
[top print [Internet goes]
bottom print [down. Lose turn.]
setturnLoss 1]
if (:res = 6)
[top print [Free pizza lunch]
bottom print [Move ahead]
fwd 1]
if (:res = 7)
[top print [Grades are def-]
bottom print [flated. Lose turn.]
setturnLoss 1]
if (:res = 8)
[top print [Personal Lake]
bottom print [Day.Move ahead]
fwd 1]
if (:res = 9)
[top print [Flamed on commun]
bottom print [-ity. Lose turn.]
setturnLoss 1]
if (:res = 10)
[top print [Boston Marathon]
bottom print [Day.Move ahead]
fwd 1]

lightPort onfor 2 ;turn on light so other knows its turn
end

to answer
waituntil [or switchOne switchTwo]
if switchOne
[setresponse 1] ;true
if switchTwo
[setresponse 0] ;false
profPort off
end


to backward ;always only 1 space backward
charPort on thatway
waituntil [square?]
waituntil [not square?]
setsquareNum (squareNum - 1)
top print [squareNum is]
bottom print squareNum
charPort off
end


;0 is false, 1 is true
to trivia :num
profPort on
if (:num = 0)
[top print [The college was]
bottom print [founded in 1874]
setans 0]
if (:num = 1)
[top print [You can triple]
bottom print [major here]
setans 0]
if (:num = 2)
[top print [Paintshop Pond]
bottom print [exists on campus]
setans 1]
if (:num = 3)
[top print [Greenhouse is]
bottom print [open 365days/yr]
setans 1]
if (:num = 4)
[top print [There's asbestos]
bottom print [in the tunnels]
setans 1]
if (:num = 5)
[top print [New Dorms were]
bottom print [built in 1970]
setans 0]
if (:num = 6)
[top print [Science Center]
bottom print [has 6 floors]
setans 1]
if (:num = 7)
[top print [Wellesley has]
bottom print [a forge.]
setans 1]
if (:num = 8)
[top print [Billings is in]
bottom print [Science Center]
setans 0]
if (:num = 9)
[top print [We can cross-]
bottom print [reg @ Brandeis]
setans 1]
if (:num = 10)
[top print [DCW is our]
bottom print [10th president]
setans 0]
if (:num = 11)
[top print [WC was founded]
bottom print [by the Durants]
setans 1]
if (:num = 12)
[top print [our endowment is]
bottom print [about $1.4 bill]
setans 1]
if (:num = 13)
[top print [The art library]
bottom print [is in Founders]
setans 0]
if (:num = 14)
[top print [There are over]
bottom print [2500 students]
setans 0]
if (:num = 15)
[top print [Paramecium Pond]
bottom print [is natural]
setans 0]
if (:num = 16)
[top print [College Hall was]
bottom print [the 1st building]
setans 1]
if (:num = 17)
[top print [WC has had 3]
bottom print [male presidents]
setans 0]
if (:num = 18)
[top print [Classes used to]
bottom print [pick their color]
setans 1]
if (:num = 19)
[top print [Lake Hs does not]
bottom print [have an elevator]
setans 0]
if (:num = 20)
[top print [El in El Table]
bottom print [means elevator]
setans 1]
if (:num = 21)
[top print [Pendleton used]
bottom print [to be Sci. Cntr]
setans 1]
if (:num = 22)
[top print [Largest telescope]
bottom print [in Obs is 35 in]
setans 0]
if (:num = 23)
[top print [Parking fee is]
bottom print [200 per year]
setans 0]
if (:num = 24)
[top print [RAs are paid]
setans 0]
if (:num = 25)
[top print [Dyke Ball used]
bottom print [to be mandatory]
setans 0]
if (:num = 26)
[top print [Pom is over 100]
bottom print [years old]
setans 1]
if (:num = 27)
[top print [Path around lake]
bottom print [waban is 4 miles]
setans 0]
if (:num = 28)
[top print [Parents wkend]
bottom print [is every spring]
setans 0]
if (:num = 29)
[top print [A Wellesley alum]
bottom print [is an astronaut]
setans 1]
if (:num = 30)
[top print [RCCs used to]
bottom print [be called DNCs]
setans 1]
if (:num = 31)
[top print [PLTC used to be]
bottom print [open 24hrs/day]
setans 1]

answer

ifelse (response = ans)
[clearHB
print [Correct!]
fwd 1]

[clearHB
print [Sorry, wrong]
backward]

lightPort onfor 10 ; turn on light so other knows its turn
end

to kidTrivia :num
profPort on
if (:num = 0)
[top print [Texas is the]
bottom print [largest state]
setans 0]
if (:num = 1)
[top print [H2O is water]
setans 0]
if (:num = 2)
[top print [A whale is the]
bottom print [largest animal]
setans 1]
if (:num = 3)
[top print [Washington D.C.]
bottom print [is a state]
setans 0]
if (:num = 4)
[top print [Washington]
bottom print [is a state]
setans 1]
if (:num = 5)
[top print [Wellesley College]
bottom print [is all-female]
setans 1]
if (:num = 6)
[top print [The American flag]
bottom print [has 13 stripes]
setans 1]
if (:num = 7)
[top print [A Wellesley alum]
bottom print [is an astronaut]
setans 1]
if (:num = 8)
[top print [Yeast is a]
bottom print [bacteria]
setans 1]
if (:num = 9)
[top print [Dolphins are a]
bottom print [kind of fish]
setans 0]
if (:num = 10)
[top print [A cube has 7]
bottom print [sides]
setans 0]
if (:num = 11)
[top print [A pentagon has]
bottom print [5 sides]
setans 1]
if (:num = 12)
[top print [Cotton comes]
bottom print [from sheep]
setans 0]
if (:num = 13)
[top print [Coffee comes as]
bottom print [beans.]
setans 1]
if (:num = 14)
[top print [Congress is in]
bottom print [the White House]
setans 0]
if (:num = 15)
[top print [Koalas are not]
bottom print [actually bears]
setans 1]
if (:num = 16)
[top print [Cleopatra was a]
bottom print [pharoah in Egypt]
setans 1]
if (:num = 17)
[top print [Flying fish have]
bottom print [feathers]
setans 0]
if (:num = 18)
[top print [XIV is 14 in]
bottom print [roman numerals]
setans 1]
if (:num = 19)
[top print [IX is 11 in]
bottom print [roman numerals]
setans 0]
answer
ifelse (response = ans)
[clearHB
print [Correct!]
fwd 1]
[clearHB
print [Sorry, wrong]
backward]

lightPort onfor 10 ;turn on light so other knows its turn
end

Go to top of page