Rock-paper-scissors: Difference between revisions

m
no edit summary
(Added a Red answer)
mNo edit summary
Line 4,825:
Red [Purpose: "Implement a rock-paper-scissors game with weighted probability"]
 
choices: ["r" "p" "s"]
prior: ["r" "p" "s"]
win: ["p" "s" "r"]
lose: ["s" "r" "p"]
 
forever [
Line 4,832 ⟶ 4,834:
pchoice: ask ""
unless any [pchoice = "r" pchoice = "p" pchoice = "s"] [break]
cchoice: random/only prior
pindex: index? find priorchoices pchoice
cindex: index? find win cchoice
Line 4,841 ⟶ 4,844:
true [print "you win"]
]
append prior win/:pindex ;adds what would have beaten player
lx: none
unless (find/skip prior lose/:pindex 3) = none [lx: (index? find/skip prior lose/:pindex 3) - 1]
unless lx = none [remove skip prior lx] ;removes what would have lost to player
]
</lang>
Anonymous user