Author | TeleZ |
Submission date | 2017-08-30 04:19:59.660010 |
Rating | 7129 |
Matches played | 353 |
Win rate | 70.82 |
Use rpsrunner.py to play unranked matches on your computer.
import random
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=[""]*3
flag=False
subs=[0]*6
prin=[[0]*6]*3
meta=[0]*3
output=random.choice("RPS")
else:
if flag:
for i in range(3):
j=prin[i].index(max(prin[i]))
k=mdl(subs[j]-k2i[input])
if k==2:
meta[i]-=1
else:
meta[i]+=k
for j in range(6):
for i in range(1,3):
prin[i][j]*=0.9
k=mdl(subs[j]-k2i[input])
if k==1:
for i in range(3):
prin[i][j]+=1
elif k==2:
for i in range(3):
if i<2:
prin[i][j]-=1
elif prin[i][j]<3:
prin[i][j]-=1.5
else:
prin[i][j]*=0.5
elif prin[2][j]<3:
prin[2][j]-=0.25
else:
prin[2][j]=0.75*prin[2][j]+0.5
DNA[0]+=input
DNA[1]+=output
DNA[2]+=i2k[mdl(k2i[output]-k2i[input])]
i=min(26,len(DNA[2]))
j=-1
while i>1 and j<0:
i-=1
RNA=DNA[2][-i:]
j=DNA[2].rfind(RNA,0,-1)
flag=(j>=0)
output=random.choice("RPS")
if flag:
k=i+j
for i in range(2):
for j in range(3):
subs[3*i+j]=mdl(k2i[DNA[i][k]]-k2i[DNA[i][k-1]]+k2i[DNA[i][len(DNA[2])-1]]-j+i+1)
i=meta.index(max(meta))
output=i2k[subs[prin[i].index(max(prin[i]))]]