This program has been disqualified.
Author | Colm |
Submission date | 2011-06-06 19:17:10.146781 |
Rating | 7208 |
Matches played | 2853 |
Win rate | 70.84 |
import random
# A combination of two approaches -
# "CompressorV3" by Byron Knoll
# "rock is dead, paper killed it" by Colm
# switches method based on their historical performance
if input=="":
matchHistory = ""
else:
matchHistory += input + last_output
prediction = random.choice(["R","P","S"])
index = 1
longestMatch = 0
limit = 30
while index < len(matchHistory)-1:
index2 = index
index3 = len(matchHistory)-1
length = 0
while index2 >= 0:
if matchHistory[index2] != matchHistory[index3]:
break
index2 -= 1
index3 -= 1
length += 1
if length > limit:
break
if length > longestMatch:
longestMatch = length
prediction = matchHistory[index+1]
if length > limit:
break
index += 2
compressor_output = {'R':'P', 'P':'S', 'S':'R'}[prediction]
def get_most_likely(ij) :
r = results[ij]['R']
p = results[ij]['P']
s = results[ij]['S']
total = r+p+s
prob_moves = {"P":r/total,"S":p/total,"R":s/total}
random_num = random.uniform(0,1)
for move, prob in prob_moves.items():
if random_num < prob :
break
random_num = random_num - prob
return move
moves = ['R','P','S']
if input not in moves:
results = {}
scores = {}
compressor_score = 0
dead_score = 0
dead_output = random.choice(moves)
for i in moves :
for j in moves :
results[(i,j)] = {"R":1.0,"P":1.0,"S":1.0}
scores = {"RR":0,"PP":0,"SS":0,"RS":1,"RP":-1,"SP":1,"SR":-1,"PR":1,"PS":-1}
else :
compressor_score += scores["%s%s" % (last_compressor_move,input)]
dead_score += scores["%s%s" % (last_dead_move,input)]
if last_input in moves :
results[(last_output,last_input)][input] = results[(last_output,last_input)][input] + 1.0
ij = (last_output,input)
dead_output = get_most_likely(ij)
if compressor_score > dead_score :
output = compressor_output
else :
output = dead_output
last_input = input
last_output = output
last_compressor_move = compressor_output
last_dead_move = dead_output