BothCM_CH11RP6

This program has been disqualified.


Authordavid.werecat
Submission date2014-12-13 21:26:27.888144
Rating5766
Matches played2
Win rate100.0

Source code:

#Created by David Catt on December 13, 2014
import random
class CntModel:
    def __init__(self, decay):
        self.decay = decay
        self.prob = [0.0, 0.0, 0.0]
    def predict(self):
        if self.prob[0] > self.prob[1]:
            if self.prob[0] > self.prob[2]:
                return 0
            else:
                return 2
        else:
            if self.prob[1] > self.prob[2]:
                return 1
            else:
                return 2
    def update(self, val):
        self.prob[0] *= self.decay
        self.prob[1] *= self.decay
        self.prob[2] *= self.decay
        self.prob[val] += 1.0
class CtxModel:
    def __init__(self, order, decay):
        self.order = order
        self.decay = decay
        self.mask = (3 ** order) << 2
        self.prob = [0.0 if (i & 3) < 3 else random.randint(0, 2) for i in range(0, self.mask)]
        self.ctx = 0
    def predict(self):
        tvl = 0
        tpr = 0.0
        prb = 0.0
        p0 = self.prob[self.ctx]
        p1 = self.prob[self.ctx+1]
        p2 = self.prob[self.ctx+2]
        pm = 0
        if p1 > p0:
            if p1 > p2:
                pm = 1
            else:
                pm = 2
        elif p2 > p0:
            pm = 2
        v0 = 0
        v1 = 1
        if p0 > p1:
            if p1 < p2:
                p1 = p2
                v1 = 2
        elif p0 < p2:
            p0 = p2
            v0 = 2    
        rn = random.random() * (p0 + p1)
        if rn <= p0:
            return pm, self.prob[self.ctx + 3], v0
        else:
            return pm, self.prob[self.ctx + 3], v1
    def update(self, cvl, val):
        self.prob[self.ctx] *= self.decay
        self.prob[self.ctx + 1] *= self.decay
        self.prob[self.ctx + 2] *= self.decay
        self.prob[self.ctx + 3] = val
        self.prob[self.ctx + val] += 1.0
        self.ctx = ((self.ctx * 3) + (cvl << 2)) % self.mask
    def nxtctx(self, cvl):
        self.ctx = ((self.ctx * 3) + (cvl << 2)) % self.mask
class ModelSwitch:
    def __init__(self, count, decay):
        self.value = [1,0,-1,-1,1,0,0,-1,1]
        self.count = count
        self.decay = decay
        self.weigh = [0.0] * count
        self.pred = [0] * count
    def setvalue(self, idx, val):
        self.pred[idx] = val
    def predict(self):
        return self.pred[self.weigh.index(max(self.weigh))]
    def update(self, val):
        val *= 3
        for i in range(0, self.count):
            self.weigh[i] = (self.weigh[i] * self.decay) + self.value[val + self.pred[i]]

if input == "":
    winner = [1,2,0]
    nval = {"R":0,"P":1,"S":2,"":0}
    cval = ["R","P","S"]
    mdls = [CtxModel((i % 6) + 1, 0.93) if i < 24 else CtxModel((((i - 24) % 4) + 1) * 2, 0.93) for i in range(0, 32)]
    zmdl0 = CntModel(0.93)
    zmdl1 = CntModel(0.93)
    msse = ModelSwitch(301, 0.93)
    lval = 0
else:
    val = nval[input]
    for i in range(0, 6):
        mdls[i].update(val, val)
        mdls[i+6].update(lval, val)
        mdls[i+12].update(val, lval)
        mdls[i+18].update(lval, lval)
    for i in range(24, 28):
        mdls[i].nxtctx(val)
        mdls[i].update(lval, val)
        mdls[i+4].nxtctx(val)
        mdls[i+4].update(lval, lval)
    zmdl0.update(val)
    zmdl1.update(lval)
    msse.update(val)
pv = 0
for i in range(0, 32):
    p1,p2,p3 = mdls[i].predict()
    msse.setvalue(i, p1)
    p1 = winner[p1]
    msse.setvalue(i + 32, p1)
    p1 = winner[p1]
    msse.setvalue(i + 64, p1)
    msse.setvalue(i + 96, p2)
    p2 = winner[p2]
    msse.setvalue(i + 128, p2)
    p2 = winner[p2]
    msse.setvalue(i + 160, p2)
    msse.setvalue(i + 192, p3)
    p3 = winner[p3]
    msse.setvalue(i + 224, p3)
    p3 = winner[p3]
    msse.setvalue(i + 256, p3)
pv = zmdl0.predict()
msse.setvalue(288, pv)
pv = winner[pv]
msse.setvalue(289, pv)
pv = winner[pv]
msse.setvalue(290, pv)
pv = zmdl1.predict()
msse.setvalue(291, pv)
pv = winner[pv]
msse.setvalue(292, pv)
pv = winner[pv]
msse.setvalue(293, pv)
pv = nval[input]
msse.setvalue(294, pv)
pv = winner[pv]
msse.setvalue(295, pv)
pv = winner[pv]
msse.setvalue(296, pv)
pv = lval
msse.setvalue(297, pv)
pv = winner[pv]
msse.setvalue(298, pv)
pv = winner[pv]
msse.setvalue(299, pv)
msse.setvalue(300, random.randint(0, 2))
lval = winner[msse.predict()]
output = cval[lval]