Skip to content

Instantly share code, notes, and snippets.

@les-peters
Created November 25, 2019 13:52
Show Gist options
  • Save les-peters/98ad8fa69bab827fae10304928c11fe7 to your computer and use it in GitHub Desktop.
Save les-peters/98ad8fa69bab827fae10304928c11fe7 to your computer and use it in GitHub Desktop.
cassidoo-1125.py
# Implement the game rock, paper, scissors.
import random
from datetime import datetime
random.seed(datetime.now())
matrix = [
['TIE', 'LOSE', 'WIN'],
['WIN', 'TIE', 'LOSE'],
['LOSE', 'WIN', 'TIE']]
moves = "RPS"
matrix_rpslk = [
['TIE', 'LOSE', 'WIN', 'WIN', 'LOSE'],
['WIN', 'TIE', 'LOSE', 'LOSE', 'WIN'],
['LOSE', 'WIN', 'TIE', 'WIN', 'LOSE'],
['LOSE', 'WIN', 'LOSE', 'TIE', 'WIN'],
['WIN', 'LOSE', 'WIN', 'LOSE', 'TIE']]
moves_rpslk = "RPSLK"
def play(moves, matrix):
play_on = True
while play_on == True:
input = raw_input(moves + ' shoot! ').upper()
i = 0
u = -1
for c in moves:
if c == input:
u = i
i += 1
if u ==-1:
print('illegal move')
exit()
c = int(random.random() * len(moves))
if matrix[u][c] != 'TIE':
print('YOU ' + matrix[u][c] + '!')
play_on = False
else:
print('Tie... go again')
play(moves, matrix)
play(moves_rpslk, matrix_rpslk)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment