# RPS v0.0

 Author tzoidis Submission date 2016-07-20 04:55:42.878593 Rating 2515 Matches played 405 Win rate 24.94

Use rpsrunner.py to play unranked matches on your computer.

## Source code:

``````import random

kon={'RR':'1','RP':'2','RS':'3','PR':'4','PP':'5','PS':'6','SR':'7','SP':'8','SS':'9'}
d0s={'1':0,'2':0,'3':0,'4':1,'5':1,'6':1,'7':2,'8':2,'9':2}
d1s={'1':0,'2':1,'3':2,'4':0,'5':1,'6':2,'7':0,'8':1,'9':2}
k2i={'R':0,'P':1,'S':2}
i2k={0:'R',1:'P',2:'S'}

def mdl(N):
N%=3
if N<0:
N+=3
return N

if not input:
DNA=""
flag=[False]*2
hist=[[0]*3]*2
eval=[0]*3
subs=[0]*6
prin=[[0]*6]*4
meta=[0]*4
skor=[0]*3
output=random.choice("RPS")
else:
if len(DNA)>0:
for i in range(3):
j=mdl(mdl(k-i)-k2i[input])
if k==2:
skor[i]-=1
else:
skor[i]+=j
for i in range(4):
j=prin[i].index(max(prin[i]))
if (j<3 and flag[0]) or (j>3 and flag[1]):
k=mdl(subs[j]-k2i[input])
if k==2:
meta[j]-=1
else:
meta[j]+=k
for j in range(6):
if (j<3 and flag[0]) or (j>3 and flag[1]):
prin[1][j]*=0.9
prin[3][j]*=0.9
k=mdl(subs[j]-k2i[input])
if k==0:
for i in range(2,4):
prin[i][j]-=0.1
elif k==1:
for i in range(4):
prin[i][j]+=1
elif k==2:
for i in range(4):
if i<2 or prin[i][j]<2:
prin[i][j]-=1
else:
prin[i][j]*=0.5
DNA+=kon[input+output]
for i in range(2):
for j in range(3):
hist[i][j]=0
i=-1
j=min(5,len(DNA))
while i<0 and j>1:
j-=1
RNA=DNA[-j:]
i=DNA.find(RNA,0,-1)
if i<0:
for k in range(len(DNA)):
hist[0][d0s[DNA[k]]]+=1
hist[1][d1s[DNA[k]]]+=1
while i>=0:
hist[0][d0s[DNA[i+j]]]+=1
hist[1][d1s[DNA[i+j]]]+=1
i=DNA.find(RNA,i+1,-1)
flag[0]=(hist[0][0]<>hist[0][1] or hist[0][1]<>hist[0][2])
flag[1]=(hist[1][0]<>hist[1][1] or hist[1][1]<>hist[1][2])
if flag[0]:
for i in range(3):
eval[i]=hist[0][mdl(i-1)]-hist[0][mdl(i+1)]
j=eval.index(max(eval))
for i in range(3):
subs[i]=mdl(j-i)
if flag[1]:
for i in range(3):
eval[i]=hist[1][mdl(i-1)]-hist[1][mdl(i+1)]
j=eval.index(max(eval))
for i in range(3):
subs[i+3]=mdl(j-i+1)
k=random.choice([0,1,2])
i=meta.index(max(meta))
if max(meta)>0:
j=prin[i].index(max(prin[i]))
if ((j<3 and flag[0]) or (j>3 and flag[1])) and max(prin[i])>0:
k=subs[j]
j=skor.index(max(skor))
output=i2k[mdl(k-j)]``````