There are several questions regarding this game, even a king-of-the-hill contest here. But I think all those challenges and contests need a way to automatically determine the winner of a game. So:
Challenge
Given two inputs in the range ["rock", "paper", "scissors", "lizard", "spock"]
representing the selections for player 1 and player 2, determine the winner of the match.
Rules
[Winner] [action] [loser]
-----------------------------
scissors cut paper
paper covers rock
rock crushes lizard
lizard poisons spock
spock smashes scissors
scissors decapitates lizard
lizard eats paper
paper disproves spock
spock vaporizes rock
rock crushes scissors
Restrictions
- Input will be a pair of strings in the given range (no other strings can be used). You can use arrays of chars if you want, as long as they represent any of the mentioned values.
- You can choose whether to use lowercase, uppercase (
"ROCK"
) or camel case ("Rock"
) for the input strings, as long as the chosen case is the same for all inputs. - Output will be a trio of values that determine the winner, which can be anything you want as long as the answers are consistent. Example:
1
if the first input wins,2
if the second input wins,0
if there is a tie. Or maybeA
if the first input wins,B
if the second input wins,<empty string>
if there is a tie.
Goal
This is code-golf, so may the shortest program/method/function/lambda for each language win!
Tests
[Input 1] [Input 2] [Output: 1/2/0]
-----------------------------------
rock paper 2
rock scissors 1
lizard spock 1
spock rock 1
spock paper 2
rock rock 0
cake
trick). \$\endgroup\$