Author | Jerry |
Submission date | 2012-11-12 21:30:02.112401 |
Rating | 5650 |
Matches played | 733 |
Win rate | 57.98 |
Use rpsrunner.py to play unranked matches on your computer.
import random
def beats( a ):
if a == 'R':
return 'P'
if a == 'P':
return 'S'
if a == 'S':
return 'R'
def record( a ):
records[a] += 1
choices = list(['R','P','S'])
if input == '':
prev = None
turn = 0
output = random.choice(choices)
records = dict()
records['R'] = 0
records['P'] = 0
records['S'] = 0
else:
turn += 1
if prev != None and prev != beats( input ):
record( input )
choices.append( beats( max(records.iterkeys(), key=lambda k: records[k]) ) )
output = random.choice( choices )
prev = output