Skip to content

Instantly share code, notes, and snippets.

@waterlink
Created October 15, 2018 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save waterlink/a7411ffe1b77dcde084fe29daa753505 to your computer and use it in GitHub Desktop.
Save waterlink/a7411ffe1b77dcde084fe29daa753505 to your computer and use it in GitHub Desktop.
step - 16
fun play(first: Throw, second: Throw): Winner {
if (first == second) {
return TIE
}
return when (first vs second) {
// classic rules
SCISSORS beats PAPER,
PAPER beats ROCK,
ROCK beats SCISSORS -> FIRST_PLAYER
// additional modern rules
ROCK beats LIZARD,
LIZARD beats SPOCK,
SPOCK beats SCISSORS,
SCISSORS beats LIZARD,
LIZARD beats PAPER,
PAPER beats SPOCK,
SPOCK beats ROCK -> FIRST_PLAYER
else -> SECOND_PLAYER
}
}
private infix fun Throw.vs(other: Throw) = this to other
private infix fun Throw.beats(other: Throw) = this to other
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment