Author | russ |
Submission date | 2012-09-12 11:13:39.345183 |
Rating | 2359 |
Matches played | 782 |
Win rate | 19.31 |
Use rpsrunner.py to play unranked matches on your computer.
from random import randrange
def bias(history):
r = 0
p = 0
s = 0
for move in history:
if move == 'R':
r += 1
elif move == 'P':
p += 1
else:
s += 1
if s > p and s > r:
return 'S', (float(s) / (s+p+r)) * 100
elif p > r and p > s:
return 'P', (float(p) / (s+p+r)) * 100
elif r > p and r > s:
return 'R', (float(r) / (s+p+r)) * 100
else:
return None
def best(input):
moves = ['R', 'P', 'S']
move = bias(input)
if not move:
return moves[randrange(3)]
return move[0]
if input == '':
history = ''
else:
history += input
output = best(history)