RPS_nFA_Fix

AuthorTeleZ
Submission date2017-11-20 12:43:17.101690
Rating6420
Matches played327
Win rate62.08

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'}
n0k={'1':0,'2':0,'3':0,'4':1,'5':1,'6':1,'7':2,'8':2,'9':2}
n1k={'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

output=random.choice("RPS")
if not input:
   DNA=""
   flag=False
   hist=[[0]*3]*2
   eval=[0]*3
   subs=[0]*12
   prin=[[0]*12]*4
   meta=[0]*4
else:
   if flag:
      d=random.betavariate(4.6,1.4)
      for i in range(4):
          k=mdl(subs[prin[i].index(max(prin[i]))]-k2i[input])
          if k==2:
             k=-1
          meta[i]=d*meta[i]+k
      for j in range(12):
          k=mdl(subs[j]-k2i[input])
          if k==2:
             k=-1
          prin[1][j]*=0.8
          prin[2][j]*=0.5
          for i in range(3):
              prin[i][j]+=k
          prin[3][j]=0.9*prin[3][j]+1.1*k-0.1
   DNA+=kon[input+output]
   for i in range(2):
       for j in range(3):
           hist[i][j]=0
   i=min(11,len(DNA))
   j=-1
   while i>1 and j<0:
         i-=1
         RNA=DNA[-i:]
         j=DNA.find(RNA,0,-1)
   flag=(j>=0)
   while j>=0:
         k=i+j
         hist[0][n0k[DNA[k]]]+=1
         hist[1][n1k[DNA[k]]]+=1
         j=DNA.find(RNA,j+1,-1)
   if flag:
      for i in range(3):
          subs[i]=mdl(n0k[DNA[k]]-i+1)
          subs[i+3]=mdl(n1k[DNA[k]]-i-1)
      for i in range(2):
          for j in range(3):
              eval[j]=hist[i][mdl(j-1)]-hist[i][mdl(j+1)]
          k=eval.index(max(eval))
          for j in range(3):
              subs[3*i+j+6]=mdl(k-j+i)
      i=meta.index(max(meta))
      output=i2k[subs[prin[i].index(max(prin[i]))]]