Rock Paper Scissors Golf
This is a code-golf for playing rock, paper, scissors with a user.
by briguy37
JavaScript
//Golfed:
alert((r=[{v:"r",r:d="D",p:w="W",s:l="L"},{v:"p",r:l,p:d,s:w},{v:"s",r:w,p:l,s:d}][Math.random()*3|0]).v+r[prompt()])
//Ungolfed
/**
alert(
(
//Store the possible outcomes
randomRPSData =
//Create the data for if the computer chooses r, p, or s
[
{
value: "r",
r: (d = "Draw"),
p: (w = "Win"),
s: (l = "Lose")},
{
value: "p",
r: l,
p: d,
s: w},
{
value: "s",
r: w,
p: l,
s: d}
]
//Have the computer pick a random variable
[Math.random() * 3 | 0]
//Output the value the computer chose
).value
//Output whether the user won or not
+ randomRPSData[prompt()]
);**/