Anonymous user
Rock-paper-scissors: Difference between revisions
m
→{{header|REXX}}: added/changed comments and whitespace, used a template for the output.
m (→extended, 5 choices: added highlighting to the REXX preamble (the five choices).) |
m (→{{header|REXX}}: added/changed comments and whitespace, used a template for the output.) |
||
Line 3,888:
::* allows the human player to QUIT at any time
::* keeps track of the human player's responses (to hopefully make future computer winning choices)
::* uses proper "English", I.E.: ''rock breaks scissors''
<lang rexx>/*REXX program plays rock─paper─scissors with a human; tracks what human tends to use. */
!= '────────'; err=! '***error***'; @.=0
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. */
Line 3,897:
b.p='covers'; b.s='cuts' ; b.r='breaks' /*verbs: how the choice wins. */
do forever; say; say prompt;
c=word($.p $.s $.r,
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)
parse pull u; a=strip(u)
upper a c1 ; a1=left(a, 1)
ok=0 /*indicate answer isn't OK (so far). */
select /*process/verify the CBLF's choice. */
Line 3,918:
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==
if $.a1==t.c1 then say ! 'the computer wins. ' ! $.c1 b.c1 $.a1
else say ! 'you win! ' ! $.a1 b.a1 $.c1
▲ /*stick a fork in it, we're all done. */</lang>
▲'''output''' with various responses from the user (output shown is a screen scraping):
<pre>
──────── Please enter one of: Rock Paper Scissors (or Quit)
Line 3,979 ⟶ 3,978:
whom.1=! 'the computer wins. ' !; whom.2=! "you win! " !; win=words(t.p)
do forever; say; say prompt;
c=word($.p $.s $.r $.L $.v, random(1, 5
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 @.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)
parse pull u;
upper a c1 ;
ok=0 /*indicate answer isn't OK (so far). */
select /* [↓] process the CBLF's choice/pick.*/
Line 3,998 ⟶ 3,997:
abbrev('ROCK', a) |,
abbrev('PAPER', a) |,
abbrev('
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
Line 4,005 ⟶ 4,004:
if \ok then iterate /*answer ¬OK? Then get another choice.*/
@.a1= @.a1 +
say ! 'computer chose: ' c
if a1==c1 then say ! 'draw.' /*Oh rats! The contest ended up a draw*/
Line 4,011 ⟶ 4,010:
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
say whom.who $.c1 word(b.c1, j) $.a1
leave /*leave J loop.*/
end /*j*/
end /*who*/
{{out|output|text= is similar to the 1<sup>st</sup> REXX version.}} <br><br>
▲ /*stick a fork in it, we're all done. */</lang>
=={{header|Ruby}}==
|