Skip to content

Instantly share code, notes, and snippets.

@triffid
Last active September 1, 2022 19:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save triffid/8d041c5948a8c9407c005e75aeb2cd57 to your computer and use it in GitHub Desktop.
Save triffid/8d041c5948a8c9407c005e75aeb2cd57 to your computer and use it in GitHub Desktop.
rock paper scissors lizard spock python POC
#!/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