Rock-paper-scissors: Difference between revisions
Content added Content deleted
(Added a Red answer) |
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: ["r" "p" "s"] |
prior: ["r" "p" "s"] |
||
win: ["p" "s" "r"] |
win: ["p" "s" "r"] |
||
lose: ["s" "r" "p"] |
|||
forever [ |
forever [ |
||
Line 4,832: | Line 4,834: | ||
pchoice: ask "" |
pchoice: ask "" |
||
unless any [pchoice = "r" pchoice = "p" pchoice = "s"] [break] |
unless any [pchoice = "r" pchoice = "p" pchoice = "s"] [break] |
||
cchoice: random/only prior |
cchoice: random/only prior |
||
pindex: index? find |
pindex: index? find choices pchoice |
||
cindex: index? find win cchoice |
cindex: index? find win cchoice |
||
Line 4,841: | Line 4,844: | ||
true [print "you win"] |
true [print "you win"] |
||
] |
] |
||
append prior win/:pindex ;adds what would have beaten player |
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> |
</lang> |