Rock-paper-scissors: Difference between revisions

J
(→‎{{header|Java}}: Added fixes for expandability, added rules for RPScLSp in comments)
(J)
Line 220:
}
}</lang>
 
=={{header|J}}==
 
<lang j>require'misc strings'
game=:3 :0
outcomes=. rps=. 0 0 0
choice=. 1+?3
while.#response=. prompt' Choose Rock, Paper or Scissors: ' do.
playerchoice=. 1+'rps' i. tolower {.deb response
if.4 = choice do.
smoutput 'Unknown response.'
smoutput 'Enter an empty line to quit'
continue.
end.
smoutput ' I choose ',choice {::;:'. Rock Paper Scissors'
smoutput (r=. 3 | choice-playerchoice) {:: 'Draw';'I win';'You win'
outcomes=. outcomes+0 1 2 = r
rps=. rps+1 2 3=playerchoice
choice=. 1+3|(?0) I.~ (}:%{:)+/\ 0, rps
end.
('Draws:','My wins:',:'Your wins: '),.":,.outcomes
)</lang>
 
Example use (playing to give the computer implementation the advantage):
 
<lang j> game''
Choose Rock, Paper or Scissors: rock
I choose Scissors
You win
Choose Rock, Paper or Scissors: rock
I choose Paper
I win
Choose Rock, Paper or Scissors: rock
I choose Paper
I win
Choose Rock, Paper or Scissors: rock
I choose Paper
I win
Choose Rock, Paper or Scissors: rock
I choose Paper
I win
Choose Rock, Paper or Scissors:
Draws: 0
My wins: 4
Your wins: 1</lang>
 
 
=={{header|Java}}==
6,962

edits