Rock-paper-scissors: Difference between revisions
Content added Content deleted
Line 1,578: | Line 1,578: | ||
<lang rascal>import Prelude; |
<lang rascal>import Prelude; |
||
rel[str, str] whatbeats = {<"Rock", " |
rel[str, str] whatbeats = {<"Rock", "Scissors">, <"Scissors", "Paper">, <"Paper", "Rock">}; |
||
list[str] |
list[str] ComputerChoices = ["Rock", "Paper", "Scissors"]; |
||
str CheckWinner(a, b){ |
str CheckWinner(a, b){ |
||
Line 1,591: | Line 1,591: | ||
public str RPS(human){ |
public str RPS(human){ |
||
computer = getOneFrom( |
computer = getOneFrom(ComputerChoices); |
||
x = if(human=="Rock") "Paper"; elseif(human=="Paper") " |
x = if(human == "Rock") "Paper"; elseif(human == "Paper") "Scissors"; else "Rock"; |
||
ComputerChoices += x; |
|||
order = order + x; |
|||
return "Computer played <computer>. <CheckWinner(human, computer)> wins!"; |
return "Computer played <computer>. <CheckWinner(human, computer)> wins!"; |
||
}</lang> |
}</lang> |
||
Line 1,604: | Line 1,604: | ||
rascal>RPS("Rock") |
rascal>RPS("Rock") |
||
str: "Computer played |
str: "Computer played Scissors. Rock wins!" |
||
rascal>RPS("Rock") |
rascal>RPS("Rock") |