Last active
September 1, 2022 19:05
-
-
Save triffid/8d041c5948a8c9407c005e75aeb2cd57 to your computer and use it in GitHub Desktop.
rock paper scissors lizard spock python POC
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
#!/usr/bin/env python3 | |
import random | |
choices = ["scissors","paper","rock","lizard","spock"] | |
interactions = [ | |
[ "", "cut", "", "behead", ""], | |
[ "", "", "wraps", "", "disproves"], | |
[ "smashes", "", "", "crushes", ""], | |
[ "", "eats", "", "", "poisons"], | |
[ "smashes", "", "vaporizes", "", ""] | |
] | |
mychoice = random.randrange(0,len(choices)) | |
while True: | |
yourchoice_str = input("Choose one of " + ",".join(choices) + ": ").lower() | |
if yourchoice_str in choices: | |
break; | |
print("Unrecognised input!") | |
yourchoice = choices.index(yourchoice_str) | |
diff = (mychoice - yourchoice + len(choices)) % len(choices) | |
print("I chose " + choices[mychoice] + ", you chose " + choices[yourchoice]) | |
if (diff == 0): | |
print("Tie.") | |
elif (diff % 2): | |
print(choices[yourchoice] + " " + interactions[yourchoice][mychoice] + " " + choices[mychoice] + ", You win.") | |
else: | |
print(choices[mychoice] + " " + interactions[mychoice][yourchoice] + " " + choices[yourchoice] + ", I win!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment