# DualModel_Test0

 Author david.werecat Submission date 2018-08-02 13:13:44.066590 Rating 6796 Matches played 285 Win rate 71.58

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

## Source code:

``````import random
class SubModel:
def __init__(self, order):
self.ctx = 0
self.msk = 1 << (order << 1)
self.mem = [random.randint(0, 2) for i in range(0, self.msk)]
self.msk -= 1
def predict(self):
return self.mem[self.ctx]
def update(self, val, cvl):
self.mem[self.ctx] = val
self.ctx = ((self.ctx << 2) + cvl) & self.msk
class IndirectModel:
def __init__(self, order, subOrder):
self.ctx = 0
self.msk = 1 << (order << 1)
self.mem = [SubModel(subOrder) for i in range(0, self.msk)]
self.msk -= 1
def predict(self):
return self.mem[self.ctx].predict()
def update(self, val, cvl):
self.mem[self.ctx].update(val, cvl)
def next(self, val):
self.ctx = ((self.ctx << 2) + val) & self.msk
class ModelPicker:
def __init__(self, count, decay):
self.count = count
self.preds = [0 for i in range(0, count)]
self.weigh = [0.0 for i in range(0, count)]
self.decay = decay
def setpred(self, idx, val):
self.preds[idx] = val
def setpreds(self, idx, vals):
vl = len(vals)
for vi in range(0, vl):
self.preds[idx] = vals[vi]
idx += 1
def predict(self):
#self.preds[self.weigh.index(max(self.weigh))]
idx = 0
mxv = -10000.0
tmv = 0
for i in range(0, self.count):
tmv = self.weigh[i]
if tmv > mxv:
mxv = tmv
idx = i
return self.preds[idx]
def update(self, val):
val *= 3
for i in range(0, self.count):
self.weigh[i] = (self.weigh[i] * self.decay) + SCOR[val + self.preds[i]]
if input == "":
SCOR = [1,-1,0,0,1,-1,-1,0,1]
VMAP = {"R":0,"P":1,"S":2}
CMAP = ["R","P","S"]
WINS = [1,2,0]
iUUU = IndirectModel(4, 2)
iUUT = IndirectModel(4, 2)
iUTU = IndirectModel(4, 2)
iUTT = IndirectModel(4, 2)
iTUU = IndirectModel(4, 2)
iTUT = IndirectModel(4, 2)
iTTU = IndirectModel(4, 2)
iTTT = IndirectModel(4, 2)
iBUU = IndirectModel(6, 2)
iBUT = IndirectModel(6, 2)
iBTU = IndirectModel(6, 2)
iBTT = IndirectModel(6, 2)
sse = ModelPicker(46, 0.9)
tval = random.randint(0, 2)
uval = random.randint(0, 2)
else:
tval = VMAP[input]
iUUU.update(uval, uval)
iUUU.next(uval)
iUUT.update(tval, uval)
iUUT.next(uval)
iUTU.update(uval, tval)
iUTU.next(uval)
iUTT.update(tval, tval)
iUTT.next(uval)
iTUU.update(uval, uval)
iTUU.next(tval)
iTUT.update(tval, uval)
iTUT.next(tval)
iTTU.update(uval, tval)
iTTU.next(tval)
iTTT.update(tval, tval)
iTTT.next(tval)
iBUU.update(uval, uval)
iBUU.next(tval)
iBUU.next(uval)
iBUT.update(tval, uval)
iBUT.next(tval)
iBUT.next(uval)
iBTU.update(uval, tval)
iBTU.next(tval)
iBTU.next(uval)
iBTT.update(tval, tval)
iBTT.next(tval)
iBTT.next(uval)
sse.update(tval)
sse.preds[0] = iUUU.predict()
sse.preds[1] = iUUT.predict()
sse.preds[2] = iUTU.predict()
sse.preds[3] = iUTT.predict()
sse.preds[4] = iTUU.predict()
sse.preds[5] = iTUT.predict()
sse.preds[6] = iTTU.predict()
sse.preds[7] = iTTT.predict()
sse.preds[8] = iBUU.predict()
sse.preds[9] = iBUT.predict()
sse.preds[10] = iBTU.predict()
sse.preds[11] = iBTT.predict()
sse.preds[12] = tval
sse.preds[13] = uval
for i in range(0, 14):
sse.preds[i + 14] = WINS[sse.preds[i]]
sse.preds[i + 28] = WINS[sse.preds[i + 14]]
sse.setpreds(42, [0, 1, 2, random.randint(0, 2)])
uval = WINS[sse.predict()]
output = CMAP[uval]``````