fix some file extensions
This commit is contained in:
parent
68f8f3e56b
commit
f3a896c724
789 changed files with 91 additions and 62 deletions
|
|
@ -9,3 +9,5 @@ Rock Paper Scissors is a two player game. Each player chooses one of rock, paper
|
|||
If both players choose the same thing, there is no winner for that round.
|
||||
|
||||
For this task, the computer will be one of the players. The operator will select Rock, Paper or Scissors and the computer will keep a record of the choice frequency, and use that information to make a [[Probabilistic choice|weighted random choice]] in an attempt to defeat its opponent.
|
||||
|
||||
'''Extra credit:''' easy support for [[wp:Rock-paper-scissors#Additional_weapons|additional weapons]].
|
||||
|
|
|
|||
36
Task/Rock-paper-scissors/REXX/rock-paper-scissors.rexx
Normal file
36
Task/Rock-paper-scissors/REXX/rock-paper-scissors.rexx
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
/*REXX pgm plays rock-paper-scissors with a CBLF (carbon-based life form*/
|
||||
!='────────'; er='***error!***'; @.=0 /*some constants for pgm*/
|
||||
z=! 'Please enter one of: Rock Paper Scissors (or Quit)'
|
||||
$.p='paper'; $.s='scissors'; $.r='rock' /*computer's choices. */
|
||||
b.p=' covers '; b.s=' cuts '; b.r=' breaks ' /*how the choice wins.*/
|
||||
|
||||
do forever; say; say z; say /*prompt the CBLF & get response.*/
|
||||
c=word('rock paper scissors',random(1,3)) /*the computer's 1st pick*/
|
||||
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); upper c1 /*C1 is used for fast comparing.*/
|
||||
parse pull u; a=strip(u); /*get the CBLF's choice (answer).*/
|
||||
upper a; a1=left(a,1) /*uppercase answer, get 1st char.*/
|
||||
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',a) then do; say ! 'quitting.'; exit; end
|
||||
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
|
||||
end /*select*/
|
||||
|
||||
if \ok then iterate /*answer ¬ OK? Then get another.*/
|
||||
@.a1 = @.a1+1 /*keep track of CBLF's answers. */
|
||||
say ! 'computer chose: ' c
|
||||
if a1==c1 then do; say ! 'draw.'; iterate; end
|
||||
if a1=='R' & c1=='S' |,
|
||||
a1=='S' & c1=='P' |,
|
||||
a1=='P' & c1=='R' then say ! 'you win! ' ! $.a1 b.a1 $.c1
|
||||
else say ! 'the computer wins. ' ! $.c1 b.c1 $.a1
|
||||
end /*forever*/
|
||||
/*stick a fork in it, we're done.*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue