Cyborg Duckling

This program has been disqualified.


AuthorEbTech
Submission date2011-05-27 06:09:46.394156
Rating8750
Matches played72
Win rate87.5

Source code:

import math
import random

if not input:
    hist = [[[[[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3]] for i in range(9)] for j in range(9)] for k in range(9)]
    a_hist = [[[[[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3],[1/3,1/3]] for i in range(9)] for j in range(9)] for k in range(9)]
    prev = [0,0,0,0]
    olast = 0
    ilast = 0
    candidate = [1,0,1,2,0,1,2]
    score = [1,2,0,0,0,0,2]
    weight = [[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0],[0,0,0]]
else:
    ilast = {'R':0, 'P':1, 'S':2}[input]
    for i in range(7):
        score[i] *= 0.96
        for j in range(3):
            score[i] += ((4 + j - ilast) % 3 - 1)*weight[i][j]
    
    hist[prev[3]][prev[0]][prev[1]][prev[2]][0] *= 0.55
    hist[prev[3]][prev[0]][prev[1]][prev[2]][1] *= 0.55
    a_hist[prev[3]][prev[0]][prev[1]][prev[2]][0] *= 0.55
    a_hist[prev[3]][prev[0]][prev[1]][prev[2]][1] *= 0.55
    if ilast < 2:
        hist[prev[3]][prev[0]][prev[1]][prev[2]][ilast] += 0.45
    if olast < 2:
        a_hist[prev[3]][prev[0]][prev[1]][prev[2]][olast] += 0.45
    for i in range(0,8):
        hist[prev[3]][i][prev[1]][prev[2]][0] *= 0.8
        hist[prev[3]][i][prev[1]][prev[2]][1] *= 0.8
        a_hist[prev[3]][i][prev[1]][prev[2]][0] *= 0.8
        a_hist[prev[3]][i][prev[1]][prev[2]][1] *= 0.8
        if ilast < 2:
            hist[prev[3]][i][prev[1]][prev[2]][ilast] += 0.2
        if olast < 2:
            a_hist[prev[3]][i][prev[1]][prev[2]][olast] += 0.2
        for j in range(0,8):
            hist[prev[3]][i][j][prev[2]][0] *= 0.92
            hist[prev[3]][i][j][prev[2]][1] *= 0.92
            a_hist[prev[3]][i][j][prev[2]][0] *= 0.92
            a_hist[prev[3]][i][j][prev[2]][1] *= 0.92
            if ilast < 2:
                hist[prev[3]][i][j][prev[2]][ilast] += 0.08
            if olast < 2:
                a_hist[prev[3]][i][j][prev[2]][olast] += 0.08
            for k in range(0,8):
                hist[prev[3]][i][j][k][0] *= 0.97
                hist[prev[3]][i][j][k][1] *= 0.97
                a_hist[prev[3]][i][j][k][0] *= 0.97
                a_hist[prev[3]][i][j][k][1] *= 0.97
                if ilast < 2:
                    hist[prev[3]][i][j][k][ilast] += 0.03
                if olast < 2:
                    a_hist[prev[3]][i][j][k][olast] += 0.03
    prev[0] = prev[1]
    prev[1] = prev[2]
    prev[2] = prev[3]
    prev[3] = 3*olast + ilast

prob = hist[prev[3]][prev[0]][prev[1]][prev[2]]
rateR = math.exp(5*(1-prob[0]-2*prob[1]))
rateP = math.exp(5*(2*prob[0]+prob[1]-1))
rateS = math.exp(5*(prob[1]-prob[0]))
randNum = random.random()*(rateR+rateP+rateS)
if randNum < rateR:
    candidate[1] = 0
elif randNum < rateR+rateP:
    candidate[1] = 1
else:
    candidate[1] = 2
weight[1][0] = rateR/(rateR+rateP+rateS)
weight[1][1] = rateP/(rateR+rateP+rateS)
weight[1][2] = rateS/(rateR+rateP+rateS)

prob = a_hist[prev[3]][prev[0]][prev[1]][prev[2]]
rateR = math.exp(5*(1-prob[0]-2*prob[1]))
rateP = math.exp(5*(2*prob[0]+prob[1]-1))
rateS = math.exp(5*(prob[1]-prob[0]))
randNum = random.random()*(rateR+rateP+rateS)
if randNum < rateR:
    candidate[4] = 0
elif randNum < rateR+rateP:
    candidate[4] = 1
else:
    candidate[4] = 2
weight[4][0] = rateR/(rateR+rateP+rateS)
weight[4][1] = rateP/(rateR+rateP+rateS)
weight[4][2] = rateS/(rateR+rateP+rateS)

candidate[0] = random.choice(['R','P','S'])
weight[0][0] = weight[0][1] = weight[0][2] = 0
for i in [2,3,5,6]:
    candidate[i] = (candidate[i-1] + 1) % 3
    weight[i][0] = weight[i-1][2]
    weight[i][1] = weight[i-1][0]
    weight[i][2] = weight[i-1][1]

best = score[0]
olast = candidate[0]
for i in range(1, 7):
    if (best < score[i]):
        best = score[i]
        olast = candidate[i]
output = {0:'R', 1:'P', 2:'S'}[olast]