Author | narkee |
Submission date | 2011-06-10 12:31:00.622836 |
Rating | 2584 |
Matches played | 5021 |
Win rate | 25.21 |
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+random.random()*0.2
pPaper = len(filter(lambda z:z[1]=='P',data))/lData+random.random()*0.2
pSciss = len(filter(lambda z:z[1]=='S',data))/lData+random.random()*0.2
if pRock > pPaper and pRock > pSciss:
output = 'R'
elif pPaper > pRock and pPaper > pSciss:
output = 'P'
else:
output = 'S'
else:
output = random.choice(['R','P','S'])
if last:
history.append([last])
last = output