Last active
April 28, 2022 11:02
-
-
Save yoniLavi/841fcc814d67e32604f9c85b6b6dccce to your computer and use it in GitHub Desktop.
An extensible implementation of rock-paper-scissors-lizard-spock
This file contains hidden or 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
| ACTIONS = ["rock", "paper", "scissors", "spock", "lizard"] | |
| OUTCOMES = ["Tie", "P1 wins", "P2 wins", "P1 wins", "P2 wins"] | |
| ACTION_ENUM = {v: i for (i, v) in enumerate(ACTIONS)} | |
| def play(action1, action2): | |
| outcome_int = (ACTION_ENUM[action1] - ACTION_ENUM[action2]) % len(ACTIONS) | |
| return OUTCOMES[outcome_int] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment