tzoidis_0

AuthorRPS v1.00
Submission date2016-07-22 18:53:29.793895
Rating3404
Matches played381
Win rate32.02

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

Source code:

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:
   flag=False
   hist=[[[0]*3]*3]*2
   output=random.choice("RPS")
elif not flag:
   flag=True
   put0=k2i[input]
   put1=k2i[output]
   output=random.choice("RPS")
else:
   hist[0][mdl(put1-put0)][mdl(k2i[input]-put1+1)]+=1
   hist[1][mdl(put0-put1)][mdl(k2i[output]-put0+1)]+=1
   put0=k2i[input]
   put1=k2i[output]
   i=max(hist[0][mdl(put1-put0)])
   j=max(hist[1][mdl(put0-put1)])
   if j>i:
      j=hist[1][mdl(put0-put1)].index(j)
      output=i2k[mdl(put0+hist[1][mdl(put0-put1)][j]+1)]
   else:
      i=hist[0][mdl(put1-put0)].index(i)
      output=i2k[mdl(put1+hist[0][mdl(put1-put0)][i])]