RPS_FA_Plus

AuthorTeleZ
Submission date2017-12-29 01:06:40.365050
Rating7822
Matches played266
Win rate77.07

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
  while N<0:
    N+=3
  return N

if not input:
  DNA=[""]*3
  hist=[[0]*3]*2
  eval=[0]*3
  subs=[0]*24
  prin=[[0]*24]*3
  meta=[0]*3
  output=random.choice("RPS")
else:
  if len(DNA[2])>0:
    for i in range(3):
      q=mdl(subs[prin[i].index(max(prin[i]))]-k2i[input])
      if q==2:
        q=-1
      meta[i]=0.9*meta[i]+q
    for j in range(24):
      q=mdl(subs[j]-k2i[input])
      if q==2:
        q=-1
      prin[1][j]*=0.8
      prin[2][j]*=0.5
      for i in range(3):
        prin[i][j]+=q
  DNA[0]+=input
  DNA[1]+=output
  DNA[2]+=kon[input+output]
  for i in range(2):
    for j in range(3):
      hist[i][j]=0
  i=min(26,len(DNA[2]))
  j=-1
  while i>1 and j<0:
    i-=1
    RNA=DNA[2][-i:]
    j=DNA[2].find(RNA,0,-1)
  k=j
  while j>=0:
    q=i+j
    for k in range(2):
      hist[k][k2i[DNA[k][q]]]+=1
    j=DNA[2].find(RNA,j+1,-1)
  for i in range(2):
    if k<0:
      q=random.randint(0,len(DNA[2])-1)
      k=k2i[DNA[i][q]]-5
    else:
      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]=mdl(k-j+i)
      subs[3*i+j+6]=mdl(k2i[DNA[i][q]]-j+i+1)
  for k in range(2):
    i=min(26,len(DNA[2]))
    j=-1
    while i>1 and j<0:
      i-=1
      RNA=DNA[k][-i:]
      j=DNA[k].rfind(RNA,0,-1)
    if j<0:
      q=random.randint(0,len(DNA[2])-1)
    else:
      q=i+j
    for i in range(2):
      for j in range(3):
        subs[6*k+3*i+j+12]=mdl(k2i[DNA[i][q]]-j+i+1)
  i=meta.index(max(meta))
  output=i2k[subs[prin[i].index(max(prin[i]))]]