# detailedbalanceT7

This program has been disqualified.

 Author momo Submission date 2011-06-18 09:18:22.767246 Rating 7402 Matches played 2203 Win rate 71.22

## Source code:

``````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]])

def seqfreq(hi, l):
N = len(hi)
count =  [[0,0,0],[0,0,0]]
a = 0
b = 0
for pos in range(max(l, N-cutoff), N):
j = 0
inc = 1 + (pos * decay)
while (hi[pos-j] == hi[N-1 - j]) and j < l:
j += 1
if (j == l):
count[0][hi[pos-j][0]] += inc
count[1][(hi[pos-j][1]+a)%3] += inc

j0 = j
while (hi[pos-j][0] == hi[N-1 - j][0]) and j < l:
j += 1
if (j == l):
count[0][hi[pos-j][0]] += inc
count[1][(hi[pos-j][1]+a)%3] += inc
j = j0
while (hi[pos-j][1] == hi[N-1 - j][1]) and j < l:
j += 1
if (j == l):
count[0][hi[pos-j][0]] += inc
count[1][(hi[pos-j][1]+a)%3] += inc
return count

if (1):
if (input == ""):
N = 1
L = 4
cutoff = 320
AR1 = 0.88 #0.85
states = ["R","S","P"]
st = [0,1,2]
sdic = {"R":0, "S":1, "P":2}
decay = 0.001
decay2 = 0.5
res = [[0, 1, -1], [-1, 0, 1], [1, -1, 0]]
total=0
r=0
M = 3
models = [1]*(M*3+1)

state = [1]*(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

count0 = seqfreq(hi, L)
count = [[count0[0][i] + count0[1][(i+0)% 3] for i in st]]
count += [[count0[0][i] + count0[1][(i+1)% 3] for i in st]]
count += [[count0[0][i] + count0[1][(i+2)% 3] for i in st]]

i = 0;  prognosis[i] = best(count[0])
i += 3; prognosis[i] = best(count[1])
i += 3; prognosis[i] = best(count[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

if(random.choice([0,1])): thebest = highest(state[0:-1])
else:
thebest = highest(state)
choices += [thebest]

yo = prognosis[thebest]

output = states[yo]

N = N + 1``````