Anonymous user
Rock-paper-scissors: Difference between revisions
m
→{{header|REXX}}: eliminated the need for a statement.
m (→{{header|REXX}}: changed comments in the REXX section header and program note (output section).) |
m (→{{header|REXX}}: eliminated the need for a statement.) |
||
Line 3,419:
::* keeps track of the human player's responses (to hopefully make computer winning choices)
::* uses proper "English" ''rock breaks scissors''
<lang rexx>/*REXX pgm plays
!= '────────';
$.p='paper'; $.s='scissors'; $.r='rock' /*computer's choices.
b.p=' covers '; b.s=' cuts '; b.r=' breaks ' /*how the choice wins
do forever;
c=word('rock paper scissors',random(1,3))
m=max(@.r,@.p,@.s); f='paper' /*prepare to examine the history.*/
if @.p==m then f='scissors' /*emulate JC's The Amazing Karnac*/
if @.s==m then f='rock' /* " " " " " */
if m\==0 then c=f /*choose based on CBLF's history.*/
c1=left(c,1)
parse pull u; a=strip(u)
upper a
ok=0 /*indicate answer isn't OK so far*/
select /*process the CBLF's choice. */
when words(u)==0 then say er 'nothing entered'
when words(u)>1 then say er 'too many choices: ' u
when abbrev('QUIT',
when abbrev('ROCK', a)
abbrev('PAPER', a) |,
abbrev('SCISSORS',a) then ok=1 /*a valid answer by CBLF.*/
otherwise say er 'you entered a bad choice:' u
Line 3,446:
if \ok then iterate /*answer ¬ OK? Then get another.*/
@.a1
say ! 'computer chose: ' c
if a1==c1
if a1=='R' & c1=='S' |,
a1=='S' & c1=='P' |,
Line 3,455:
end /*forever*/
/*stick a fork in it, we're done.*/</lang>
'''output''' with various responses from the user (output shown is a screen scraping):
<pre>
|