This program has been disqualified.
Author | evolvingstuff |
Submission date | 2011-06-19 07:46:57.763870 |
Rating | 7626 |
Matches played | 348 |
Win rate | 78.74 |
from random import *
#always choose highest weight
def findMatchMe(history_me, history_yu, depth):
prefix = history_me[-depth:]
i = history_me[:-1].rfind(prefix)
if i > -1:
return history_yu[i+depth]
else:
return None
def findMatchYu(history_yu, depth):
prefix = history_yu[-depth:]
i = history_yu[:-1].rfind(prefix)
if i > -1:
return history_yu[i+depth]
else:
return None
def findMatchUs(history_us, depth):
prefix = history_us[-depth*2:]
i = history_us[:-2].rfind(prefix)
if i > -1:
return history_us[i+depth*2].upper()
else:
return None
if input == "":
shift = {None:None, 'R':'P', 'P':'S', 'S':'R'}
initial_random_moves = 10
decay = 0.6
history_me, history_yu, history_us = '', '', ''
markov_depth = 13
weight_random = 1
weights = [[[1 for k in range(markov_depth)] for j in range(3)] for i in range(3)]
predictions = [[[None for k in range(markov_depth)] for j in range(3)] for i in range(3)]
chosen_prediction = None
output = choice(['R','P','S'])
chosen_i, chosen_j, chosen_k = -1, -1, -1
else:
#store histories
history_me += output
history_yu += input
history_us += input.lower() + output
#decay models and update weights based on input observation
weight_random *= decay
if input != chosen_prediction:
weight_random += 1
for i in range(3):
for j in range(3):
for k in range(markov_depth):
if chosen_prediction != None:
weights[i][j][k] *= decay
if input == predictions[i][j][k]:
weights[i][j][k] += 1
#make new predictions
tot_weight = 0
tot_weight += weight_random
prediction = None
for i in range(3):
for j in range(3):
for k in range(markov_depth):
predictions[i][j][k] = None
if i == 0:
prediction = findMatchMe(history_me, history_yu, k+1)
elif i == 1:
prediction = findMatchYu(history_yu, k+1)
else:
prediction = findMatchUs(history_us, k+1)
for j2 in range(j): #iocane-shift
prediction = shift[shift[prediction]]
if prediction != None:
predictions[i][j][k] = prediction
tot_weight += weights[i][j][k]
chosen_prediction = None
#choose highest weight
mx = 0
for i in range(3):
for j in range(3):
for k in range(markov_depth):
if predictions[i][j][k] != None and weights[i][j][k] > mx:
mx = weights[i][j][k]
chosen_prediction = predictions[i][j][k]
#choose action
if len(history_me) < initial_random_moves or chosen_prediction == None:
output = choice(['R','P','S'])
else:
output = shift[chosen_prediction]