Author | JustinF |
Submission date | 2011-06-15 09:14:53.019493 |
Rating | 4523 |
Matches played | 5302 |
Win rate | 46.68 |
Use rpsrunner.py to play unranked matches on your computer.
import random
encode = {'R': 0, 'P': 1, 'S': 2}
decode = {0: 'R', 1: 'P', 2: 'S'}
if not input:
turn = 0
oppStack = []
myStack = []
else:
turn += 1
oppStack.append(encode[input])
if turn < 2:
output = random.choice(('R', 'P', 'S'))
else:
output = decode[(sum(oppStack[-20::]) + sum(myStack[-20::])) % 3]
myStack.append(encode[output])