step - 16
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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