Skip to content

Instantly share code, notes, and snippets.

/ Secret
Created Sep 13, 2016

What would you like to do?
from enum import Enum
class Game(object):
choices = Enum("Game.choices", "rock paper scissors")
results = Enum("Game.results", "win lose draw")
result_table = {choices.rock: {choices.paper: results.lose,
choices.paper: {choices.rock:,
choices.scissors: results.lose},
choices.scissors: {choices.rock: results.lose,
def result_of(cls, a, b):
return result_table[a].get(b, cls.results.draw)
def choose(cls, prompt):
while True:
tmp = input(prompt)
result = cls.choices[tmp.lower()]
except KeyError:
continue # failed validation
return result
def __init__(self):
"""Maybe set up high score tracking here? I don't know"""
def play(self):
p1 = self.choose("Player 1: ")
p2 = self.choose("Player 2: ")
p1_wins = self.result_of(a, b)
if p1_wins ==
# celebrate
elif p1_wins == self.results.lose:
# mourn
else: # self.results.draw
# play again?
g = Game()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.