Sum20_Both

AuthorJustinF
Submission date2011-06-15 09:14:53.019493
Rating4523
Matches played5302
Win rate46.68

Use rpsrunner.py to play unranked matches on your computer.

Source code:

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])