# db9''

 Author momo Submission date 2011-09-01 11:51:41.410101 Rating 6735 Matches played 872 Win rate 69.04

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

## Source code:

``````#different fade
import random

def highest(v):
return random.choice([i for i in range(len(v)) if max(v) == v[i]])

def lowest(v):
return random.choice([i for i in range(len(v)) if min(v) == v[i]])

def best(c):
return highest([c[1]-c[2], c[2]-c[0], c[0]-c[1]])

if(1):
if (input == ""):
N = 1
AR1 = 0.85
states = ["R","S","P"]
st = [0,1,2]
sdic = {"R":0, "S":1, "P":2}
table = [0,0,0,{},{},{}]

decay2 = 0.5
res = [[0, 1, -1], [-1, 0, 1], [1, -1, 0]]
total=0
r=0
M = 9
models = [1]*(M*3+1)
state = [0] * (M*3+1)
yo = random.choice(st)
tu = random.choice(st)

pa = (yo, tu)
hi = [pa]
prognosis = [random.choice(st) for i in range(M*3+1)]
choices = []

else:
tu = sdic[input]
pa = (yo,tu)
hi += [pa]

state = [ AR1 * state[i] + res[prognosis[i]][tu] * models[i] for i in range(M*3+1)]

r = res[yo][tu]
total = total + r

count = [0,0,0,[[0,0,0],[0,0,0]],[[0,0,0],[0,0,0]],[[0,0,0],[0,0,0]]]
for mem in [3,4,5]:
if (N > mem + 1):

p = hi[N-mem-1:N-1]

s = hi[N-mem-2]

key0 = p
for key in [key0, [(i[0],-1) for i in key0], [ (-1,i[1]) for i in key0]]:
k = tuple([s] + key)
if (k in table[mem]): table[mem][k] += 1+N*fade

for y in st:
for t in st:
key0 = p
for key in [key0, [(i[0],-1) for i in key0], [(-1,i[1]) for i in key0]]:
k = tuple([(y,t)] + key)
if (k in table[mem]):
z = table[mem][k]
count[mem][0][y] += z
count[mem][1][t] += z

count3 = [[count[3][0][i] + count[3][1][(i+0)% 3] for i in st]]
count3 += [[count[3][0][i] + count[3][1][(i+1)% 3] for i in st]]
count3 += [[count[3][0][i] + count[3][1][(i+2)% 3] for i in st]]
count4 = [[count[4][0][i] + count[4][1][(i+0)% 3] for i in st]]
count4 += [[count[4][0][i] + count[4][1][(i+1)% 3] for i in st]]
count4 += [[count[4][0][i] + count[4][1][(i+2)% 3] for i in st]]
count5 = [[count[5][0][i] + count[5][1][(i+0)% 3] for i in st]]
count5 += [[count[5][0][i] + count[5][1][(i+1)% 3] for i in st]]
count5 += [[count[5][0][i] + count[5][1][(i+2)% 3] for i in st]]

i = 0;  prognosis[i] = best(count4[0])
i += 3; prognosis[i] = best(count4[1])
i += 3; prognosis[i] = best(count4[2])
i += 3; prognosis[i] = best(count5[0])
i += 3; prognosis[i] = best(count5[1])
i += 3; prognosis[i] = best(count5[2])
i += 3; prognosis[i] = best(count3[0])
i += 3; prognosis[i] = best(count3[1])
i += 3; prognosis[i] = best(count3[2])

assert(i+3==3*M)

# modelrandom
prognosis[3*M] = random.choice(st)

for i in range(M):
prognosis[i*3 + 1] = (prognosis[i*3] + 1) % 3
prognosis[i*3 + 2] = (prognosis[i*3+1] + 1) % 3

best = highest(state)
choices += [best]
yo = prognosis[best]

output = states[yo]

N = N + 1``````