Skip to content

Instantly share code, notes, and snippets.

@yoniLavi
Last active April 28, 2022 11:02
Show Gist options
  • Select an option

  • Save yoniLavi/841fcc814d67e32604f9c85b6b6dccce to your computer and use it in GitHub Desktop.

Select an option

Save yoniLavi/841fcc814d67e32604f9c85b6b6dccce to your computer and use it in GitHub Desktop.
An extensible implementation of rock-paper-scissors-lizard-spock
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