June 2018 Update
This commit is contained in:
parent
ba8067c3b7
commit
22f33d4004
5278 changed files with 84726 additions and 14379 deletions
|
|
@ -1,19 +1,19 @@
|
|||
/*REXX program plays rock─paper─scissors with a human; tracks what human tends to use. */
|
||||
!= '────────'; err=! '***error***'; @.=0 /*some constants for this program. */
|
||||
prompt=! 'Please enter one of: Rock Paper Scissors (or Quit)'
|
||||
!= '────────'; err=! '***error***'; @.=0 /*some constants for this program. */
|
||||
prompt= ! 'Please enter one of: Rock Paper Scissors (or Quit)'
|
||||
$.p='paper' ; $.s='scissors'; $.r='rock' /*list of the choices in this program. */
|
||||
t.p=$.r ; t.s=$.p ; t.r=$.s /*thingys that beats stuff. */
|
||||
w.p=$.s ; w.s=$.r ; w.r=$.p /*stuff " " thingys. */
|
||||
b.p='covers'; b.s='cuts' ; b.r='breaks' /*verbs: how the choice wins. */
|
||||
|
||||
do forever; say; say prompt; say /*prompt the CBLF; then get a response.*/
|
||||
c=word($.p $.s $.r, random(1, 3)) /*choose the computer's first pick. */
|
||||
do forever; say; say prompt; say /*prompt the CBLF; then get a response.*/
|
||||
c=word($.p $.s $.r, random(1, 3) ) /*choose the computer's first pick. */
|
||||
m=max(@.r, @.p, @.s); c=w.r /*prepare to examine the choice history*/
|
||||
if @.p==m then c=w.p /*emulate JC's: The Amazing Karnac. */
|
||||
if @.s==m then c=w.s /* " " " " " */
|
||||
c1=left(c,1) /*C1 is used for faster comparing. */
|
||||
parse pull u; a=strip(u) /*get the CBLF's choice/pick (answer). */
|
||||
upper a c1 ; a1=left(a,1) /*uppercase choices, get 1st character.*/
|
||||
c1=left(c, 1) /*C1 is used for faster comparing. */
|
||||
parse pull u; a=strip(u) /*get the CBLF's choice/pick (answer). */
|
||||
upper a c1 ; a1=left(a, 1) /*uppercase choices, get 1st character.*/
|
||||
ok=0 /*indicate answer isn't OK (so far). */
|
||||
select /*process/verify the CBLF's choice. */
|
||||
when words(u)==0 then say err 'nothing entered'
|
||||
|
|
@ -27,9 +27,8 @@ b.p='covers'; b.s='cuts' ; b.r='breaks' /*verbs: how the choice wins.
|
|||
|
||||
if \ok then iterate /*answer ¬OK? Then get another choice.*/
|
||||
@.a1=@.a1+1 /*keep a history of the CBLF's choices.*/
|
||||
say ! 'computer chose: ' c
|
||||
if a1==c1 then do; say ! 'draw.'; iterate; end
|
||||
if $.a1==t.c1 then say ! 'the computer wins. ' ! $.c1 b.c1 $.a1
|
||||
else say ! 'you win! ' ! $.a1 b.a1 $.c1
|
||||
end /*forever*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
say ! 'computer chose: ' c
|
||||
if a1== c1 then do; say ! 'draw.'; iterate; end
|
||||
if $.a1==t.c1 then say ! 'the computer wins. ' ! $.c1 b.c1 $.a1
|
||||
else say ! 'you win! ' ! $.a1 b.a1 $.c1
|
||||
end /*forever*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
|
|
@ -7,17 +7,17 @@ w.p= $.L $.s ; w.s= $.v $.r ; w.r= $.v $.p ; w.L= $.r $
|
|||
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)
|
||||
|
||||
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. */
|
||||
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. */
|
||||
m=max(@.r,@.p,@.s,@.L,@.v) /*used in examining CBLF's history. */
|
||||
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 @.r==m then c=word(w.r,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)) /* " " " " " */
|
||||
c1=left(c,1) /*C1 is used for faster comparing. */
|
||||
parse pull u; a=strip(u) /*obtain the CBLF's choice/pick. */
|
||||
upper a c1 ; a1=left(a,1) /*uppercase the choices, get 1st char. */
|
||||
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 @.r==m then c=word(w.r, 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) ) /* " " " " " */
|
||||
c1=left(c, 1) /*C1 is used for faster comparing. */
|
||||
parse pull u; a=strip(u) /*obtain the CBLF's choice/pick. */
|
||||
upper a c1 ; a1=left(a, 1) /*uppercase the choices, get 1st char. */
|
||||
ok=0 /*indicate answer isn't OK (so far). */
|
||||
select /* [↓] process the CBLF's choice/pick.*/
|
||||
when words(u)==0 then say err 'nothing entered.'
|
||||
|
|
@ -26,23 +26,22 @@ whom.1=! 'the computer wins. ' !; whom.2=! "you win! " !; win=words(t.p)
|
|||
when abbrev('LIZARD', a) |,
|
||||
abbrev('ROCK', a) |,
|
||||
abbrev('PAPER', a) |,
|
||||
abbrev('Vulcan', a) |,
|
||||
abbrev('SPOCK', a,2) | ,
|
||||
abbrev('VULCAN', a) |,
|
||||
abbrev('SPOCK', a,2) |,
|
||||
abbrev('SCISSORS',a,2) then ok=1 /*it's a valid choice for the human. */
|
||||
otherwise say err 'you entered a bad choice: ' u
|
||||
end /*select*/
|
||||
|
||||
if \ok then iterate /*answer ¬OK? Then get another choice.*/
|
||||
@.a1=@.a1+1 /*keep a history of the CBLF's choices.*/
|
||||
@.a1= @.a1 + 1 /*keep a history of the CBLF's choices.*/
|
||||
say ! 'computer chose: ' c
|
||||
if a1==c1 then say ! 'draw.' /*Oh rats! The contest ended up a draw*/
|
||||
else do who=1 for 2 /*either the computer or the CBLF won. */
|
||||
if who==2 then parse value a1 c1 with c1 a1
|
||||
do j=1 for win /*see who won. */
|
||||
if $.a1\==word(t.c1,j) then iterate /*not this 'un. */
|
||||
say whom.who $.c1 word(b.c1,j) $.a1 /*notify winner.*/
|
||||
if $.a1 \== word(t.c1, j) then iterate /*not this 'un. */
|
||||
say whom.who $.c1 word(b.c1, j) $.a1 /*notify winner.*/
|
||||
leave /*leave J loop.*/
|
||||
end /*j*/
|
||||
end /*who*/
|
||||
end /*forever*/
|
||||
/*stick a fork in it, we're all done. */
|
||||
end /*forever*/ /*stick a fork in it, we're all done. */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue