Rock-paper-scissors: Difference between revisions
Content added Content deleted
m (→traditional, 3 choices: added/changed comments and whitespace.) |
m (→extended, 5 choices: added/changed whitespace and comments.) |
||
Line 4,463: | Line 4,463: | ||
This REXX version supports more choices: <big> rock paper scissors lizard Spock </big> |
This REXX version supports more choices: <big> rock paper scissors lizard Spock </big> |
||
<lang rexx>/*REXX pgm plays rock─paper─scissors─lizard─Spock with human; tracks human usage trend. */ |
<lang rexx>/*REXX pgm plays rock─paper─scissors─lizard─Spock with human; tracks human usage trend. */ |
||
!= '────────'; err=! |
!= '────────'; err=! "***error***"; @.=0 /*some constants for this REXX program.*/ |
||
prompt=! 'Please enter one of: Rock Paper SCissors Lizard SPock (Vulcan) (or Quit)' |
prompt=! 'Please enter one of: Rock Paper SCissors Lizard SPock (Vulcan) (or Quit)' |
||
$.p='paper' ; $.s= |
$.p='paper' ; $.s="scissors" ; $.r="rock" ; $.L='lizard' ; $.v="Spock" /*names of the thingys*/ |
||
t.p= $.r $.v ; t.s= $.p $.L ; t.r= $.s $.L ; t.L= $.p $.v ; t.v= $.r $.s /*thingys beats stuff.*/ |
t.p= $.r $.v ; t.s= $.p $.L ; t.r= $.s $.L ; t.L= $.p $.v ; t.v= $.r $.s /*thingys beats stuff.*/ |
||
w.p= $.L $.s ; w.s= $.v $.r ; w.r= $.v $.p ; w.L= $.r $.s ; w.v= $.L $.p /*stuff beats thingys.*/ |
w.p= $.L $.s ; w.s= $.v $.r ; w.r= $.v $.p ; w.L= $.r $.s ; w.v= $.L $.p /*stuff beats thingys.*/ |
||
b.p='covers disproves'; b.s="cuts decapitates"; b.r='breaks crushes'; b.L="eats poisons"; b.v='vaporizes smashes' /*how the choice wins.*/ |
b.p='covers disproves'; b.s="cuts decapitates"; b.r='breaks crushes'; b.L="eats poisons"; b.v='vaporizes smashes' /*how the choice wins.*/ |
||
whom.1=! 'the computer wins. ' !; whom.2=! "you win! " !; win=words(t.p) |
whom.1= ! 'the computer wins. ' !; whom.2= ! "you win! " !; win= words(t. p) |
||
do forever; say; say prompt; |
do forever; say; say prompt; say /*prompt CBLF; then get a response. */ |
||
c=word($.p $.s $.r $.L $.v, random(1, 5) ) /*the computer's first choice/pick. */ |
c=word($.p $.s $.r $.L $.v, random(1, 5) ) /*the computer's first choice/pick. */ |
||
m=max(@.r,@.p,@.s,@.L,@.v) |
m=max(@.r, @.p, @.s, @.L, @.v) /*used in examining CBLF's history. */ |
||
if @.p==m then c=word(w.p, random(1, 2) ) |
if @.p==m then c= word(w.p, random(1, 2) ) /*emulate JC's The Amazing Karnac. */ |
||
if @.s==m then c=word(w.s, random(1, 2) ) |
if @.s==m then c= word(w.s, random(1, 2) ) /* " " " " " */ |
||
if @.r==m then c=word(w.r, random(1, 2) ) |
if @.r==m then c= word(w.r, random(1, 2) ) /* " " " " " */ |
||
if @.L==m then c=word(w.L, random(1, 2) ) |
if @.L==m then c= word(w.L, random(1, 2) ) /* " " " " " */ |
||
if @.v==m then c=word(w.v, random(1, 2) ) |
if @.v==m then c= word(w.v, random(1, 2) ) /* " " " " " */ |
||
c1=left(c, 1) |
c1= left(c, 1) /*C1 is used for faster comparing. */ |
||
parse pull u; a=strip(u) |
parse pull u; a= strip(u) /*obtain the CBLF's choice/pick. */ |
||
upper a c1 ; a1=left(a, 1) |
upper a c1 ; a1= left(a, 1) /*uppercase the choices, get 1st char. */ |
||
ok=0 /*indicate answer isn't OK (so far). */ |
ok=0 /*indicate answer isn't OK (so far). */ |
||
select /* [↓] process the CBLF's choice/pick.*/ |
select /* [↓] process the CBLF's choice/pick.*/ |