Author | narkee |
Submission date | 2011-06-10 02:55:52.674609 |
Rating | 4783 |
Matches played | 5436 |
Win rate | 48.01 |
Use rpsrunner.py to play unranked matches on your computer.
import random
if not input:
history = []
output = random.choice(['R','P','S'])
last = ''
elif len(history)==0:
output = random.choice(['R','P','S'])
else:
history[-1].append(input)
data = filter(lambda z:z[0]==last,history)
lData = float(len(data))
if lData:
pRock = len(filter(lambda z:z[1]=='R',data))/lData
pPaper = len(filter(lambda z:z[1]=='P',data))/lData
pSciss = len(filter(lambda z:z[1]=='S',data))/lData
if pRock > pPaper and pRock > pSciss:
output = 'P'
elif pPaper > pRock and pPaper > pSciss:
output = 'S'
else:
output = 'R'
else:
output = random.choice(['R','P','S'])
if last:
history.append([last])
last = output