Sum2

AuthorJustinF
Submission date2011-06-15 09:12:35.695960
Rating3666
Matches played5149
Win rate34.63

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 = []
else:
  turn += 1
  oppStack.append(encode[input])

if turn < 2:
  output = random.choice(('R', 'P', 'S'))
else:
  output = decode[sum(oppStack[-2::]) % 3]