RPS v6.8

Authortzoidis
Submission date2016-07-18 18:09:03.896142
Rating4195
Matches played399
Win rate44.11

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'}
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=""
   mRNA=""
   tRNA=""
   hist=[[0]*3]*2
   eval=[0]*3
   flag=[False]*4
   subs=[[0]*6]*4
   prin=[[[0]*6]*4]*4
   meta=[0]*4
   output=random.choice("RPS")
else:
   for i in range(4):
       x=0
       y=0
       for j in range(4):
           for k in range(6):
               if prin[i][j][k]>prin[i][x][y]:
                  x=j
                  y=k
       if flag[x]:
          re=mdl(subs[x][y]-k2i[input])
          if re==2:
             meta[i]-=1
          else:
             meta[i]+=re
   for j in range(4):
       for k in range(6):
           prin[1][j][k]*=0.9
           prin[3][j][k]*=0.9
           if flag[j]:
              re=mdl(subs[j][k]-k2i[input])
              if re==0:
                 for i in range(2,4):
                     prin[i][j][k]-=0.1
              elif re==1:
                 for i in range(4):
                     prin[i][j][k]+=1
              elif re==2:
                 for i in range(4):
                     if i<2 or prin[i][j][k]<2:
                        prin[i][j][k]-=1
                     else:
                        prin[i][j][k]*=0.5
   tRNA+=input
   mRNA+=output
   DNA+=kon[input+output]
   i=-1
   j=min(5,len(DNA))
   while i<0 and j>1:
         j-=1
         RNA=DNA[-j:]
         i=DNA.rfind(RNA,0,-1)
   flag[0]=(i>=0)
   if flag[0]:
      k=mdl(k2i[tRNA[i+j]]+1)
      j=mdl(k2i[mRNA[i+j]]-1)
      for i in range(3):
          subs[0][i]=mdl(k-i)
      for i in range(3):
          subs[0][i+3]=mdl(j-i)
   i=-1
   j=min(5,len(DNA))
   while i<0 and j>1:
         j-=1
         RNA=tRNA[-j:]
         i=tRNA.rfind(RNA,0,-1)
   flag[1]=(i>=0)
   if flag[1]:
      k=mdl(k2i[tRNA[i+j]]+1)
      j=mdl(k2i[mRNA[i+j]]-1)
      for i in range(3):
          subs[1][i]=mdl(k-i)
      for i in range(3):
          subs[2][i+3]=mdl(j-i)
   i=-1
   j=min(5,len(DNA))
   while i<0 and j>1:
         j-=1
         RNA=mRNA[-j:]
         i=mRNA.rfind(RNA,0,-1)
   flag[1]=flag[1] and (i>=0)
   flag[2]=flag[1]
   if flag[1]:
      k=mdl(k2i[tRNA[i+j]]+1)
      j=mdl(k2i[mRNA[i+j]]-1)
      for i in range(3):
          subs[2][i]=mdl(k-i)
      for i in range(3):
          subs[1][i+3]=mdl(j-i)
   for i in range(2):
       for j in range(3):
           hist[i][j]=0
   for i in range(len(DNA)):
       hist[0][k2i[tRNA[i]]]+=1
       hist[1][k2i[mRNA[i]]]+=1
   flag[3]=((hist[0][0]<>hist[0][1] or hist[0][1]<>hist[0][2]) and
            (hist[1][0]<>hist[1][1] or hist[1][1]<>hist[1][2]))
   if flag[3]:
      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[3][i]=mdl(j-i)
      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[3][i+3]=mdl(j-i+1)
   output=random.choice("RPS")
   i=meta.index(max(meta))
   if max(meta)>0:
      x=0
      y=0
      for j in range(4):
          for k in range(6):
              if prin[i][j][k]>prin[i][x][y]:
                 x=j
                 y=k
   if flag[x] and prin[i][x][y]>0:
      output=i2k[subs[x][y]]