Author | &&& |
Submission date | 2011-06-20 19:11:30.881048 |
Rating | 6042 |
Matches played | 4966 |
Win rate | 61.52 |
Use rpsrunner.py to play unranked matches on your computer.
import random
#Weighted random beat previous inputs
def weighted_choice(C, p):
x = random.random()
for elmt in range(len(C)):
if x <= p[elmt]:
return C[elmt]
x -= p[elmt]
if not input:
beat={'R':'P','P':'S','S':'R','':'R'}
output=random.choice("RPS")
history=""
else:
history+=input
L=len(history)
p = q = range(1,L+1)
q=float(sum(q))
for i in range(L):
p[i]/=q
output=beat[weighted_choice(history,p)]