This program has been disqualified.
Author | Byron Knoll |
Submission date | 2011-05-31 03:37:38.532768 |
Rating | 1512 |
Matches played | 258 |
Win rate | 15.12 |
# initialization
if input=="":
maxHistoryLength = 200
numPredictors = (maxHistoryLength+2)*3
scores = []
totalScores = []
index = 0
while index < numPredictors:
scores.append(1.0)
totalScores.append(1.0)
index+=1
history = ""
dictionary = {}
predictions = ["R", "P", "S"]
index = 3
while index < numPredictors:
predictions.append("")
index+=1
# update history
history += input
if len(history) > maxHistoryLength:
history = history[1:maxHistoryLength+1]
# update dictionary
index = 0
while index < len(history):
key = history[index:len(history)]
if dictionary.has_key(key):
dictionary[key] = dictionary[key] + 1
else:
dictionary[key] = 1
index+=1
# update scores
index = 0
while index < numPredictors:
if predictions[index] == input:
scores[index] += 1.0
totalScores[index] += 1.0
index+=1
# make predictions
order = 0
index = 3
while order <= maxHistoryLength:
context = history[len(history)-order:len(history)]
if dictionary.has_key(context+"R"):
rockCount = dictionary[context+"R"]
else:
rockCount = 0
if dictionary.has_key(context+"P"):
paperCount = dictionary[context+"P"]
else:
paperCount = 0
if dictionary.has_key(context+"S"):
scissorsCount = dictionary[context+"S"]
else:
scissorsCount = 0
if rockCount > paperCount and rockCount > scissorsCount:
predictions[index] = "R"
predictions[index+1] = "P"
predictions[index+2] = "S"
elif paperCount > scissorsCount:
predictions[index] = "P"
predictions[index+1] = "S"
predictions[index+2] = "R"
else:
predictions[index] = "S"
predictions[index+1] = "R"
predictions[index+2] = "P"
index += 3
order += 1
# choose move
best = 0
index = 0
while index < numPredictors:
if scores[index]/totalScores[index] > best:
best = scores[index]
if predictions[index] == "R":
output = "P"
elif predictions[index] == "P":
output = "S"
else:
output = "R"
index += 1