Rock-paper-scissors: Difference between revisions

Content added Content deleted
mNo edit summary
mNo edit summary
Line 4,825: Line 4,825:
Red [Purpose: "Implement a rock-paper-scissors game with weighted probability"]
Red [Purpose: "Implement a rock-paper-scissors game with weighted probability"]


choices: ["r" "p" "s"]
prior: rejoin choices: ["r" "p" "s"]
prior: ["r" "p" "s"]
win: ["p" "s" "r"]
lose: ["s" "r" "p"]


forever [
while [
print "choose rock: r, paper: p, or scissors: s"
find choices pchoice: ask "choose rock: r, paper: p, or scissors: s^/"
] [
pchoice: ask ""
print ["AI Draws:" cchoice: random/only prior]
unless any [pchoice = "r" pchoice = "p" pchoice = "s"] [break]
cwin: select "rpsr" pchoice
close: select "rspr" pchoice
print case [
cchoice: random/only prior
pchoice = cchoice ["tie"]
pindex: index? find choices pchoice
cchoice = cwin ["you lose"]
cindex: index? find win cchoice
'else ["you win"]
case [
pchoice = cchoice [print "tie"]
pindex = cindex [print "you lose"]
true [print "you win"]
]
]
append prior win/:pindex ;adds what would have beaten player
append prior cwin ;adds what would have beaten player
remove find prior close ;removes what would have lost to player
lx: none
unless (find prior lose/:pindex) = none [lx: (index? find prior lose/:pindex) - 1]
unless lx = none [remove skip prior lx] ;removes what would have lost to player
]
]
</lang>
</lang>