This program has been disqualified.
Author | Byron Knoll |
Submission date | 2011-05-31 09:14:05.235371 |
Rating | 4981 |
Matches played | 3798 |
Win rate | 49.37 |
import random
# initialization
if input=="":
maxHistoryLength = 100
history1 = ""
history2 = ""
lastOutput = ""
scores = [0,0,0,0,0,0]
predictions = ["","","","","",""]
dictionary1 = {}
dictionary2 = {}
numPredictors = 6
# update scores
index = 0
while index < numPredictors:
if input==predictions[index]:
scores[index]+=1
if (input=="R" and predictions[index]=="P") or (input=="P" and predictions[index]=="S") or (input=="S" and predictions[index]=="R"):
scores[index]-=1
index += 1
# update history
history1 += input
if len(history1) > maxHistoryLength:
history1 = history1[1:maxHistoryLength+1]
history2 += lastOutput
if len(history2) > maxHistoryLength:
history2 = history2[1:maxHistoryLength+1]
# update dictionary
index = 0
while index < len(history1):
key = history1[index:len(history1)]
if dictionary1.has_key(key):
dictionary1[key] = dictionary1[key] + 1
else:
dictionary1[key] = 1
index+=1
index = 0
while index < len(history2):
key = history2[index:len(history2)]
if dictionary2.has_key(key):
dictionary2[key] = dictionary2[key] + 1
else:
dictionary2[key] = 1
index+=1
# make prediction (set 1)
order = len(history1)-1
prediction = ""
while order >= 0:
context = history1[len(history1)-order:len(history1)]
if dictionary1.has_key(context+"R"):
rockCount = dictionary1[context+"R"]
else:
rockCount = 0
if dictionary1.has_key(context+"P"):
paperCount = dictionary1[context+"P"]
else:
paperCount = 0
if dictionary1.has_key(context+"S"):
scissorsCount = dictionary1[context+"S"]
else:
scissorsCount = 0
if rockCount > 0 and rockCount > paperCount and rockCount > scissorsCount:
prediction = "P"
elif paperCount > 0 and paperCount > scissorsCount:
prediction = "S"
elif scissorsCount > 0:
prediction = "R"
order -= 1
if prediction != "":
break
if prediction == "R":
predictions[0] = "R"
predictions[1] = "P"
predictions[2] = "S"
elif prediction == "P":
predictions[0] = "P"
predictions[1] = "S"
predictions[2] = "R"
else:
predictions[0] = "S"
predictions[1] = "R"
predictions[2] = "P"
# make prediction (set 2)
order = len(history2)-1
prediction = ""
while order >= 0:
context = history2[len(history2)-order:len(history2)]
if dictionary2.has_key(context+"R"):
rockCount = dictionary2[context+"R"]
else:
rockCount = 0
if dictionary2.has_key(context+"P"):
paperCount = dictionary2[context+"P"]
else:
paperCount = 0
if dictionary2.has_key(context+"S"):
scissorsCount = dictionary2[context+"S"]
else:
scissorsCount = 0
if rockCount > 0 and rockCount > paperCount and rockCount > scissorsCount:
prediction = "P"
elif paperCount > 0 and paperCount > scissorsCount:
prediction = "S"
elif scissorsCount > 0:
prediction = "R"
order -= 1
if prediction != "":
break
if prediction == "R":
predictions[0] = "R"
predictions[1] = "P"
predictions[2] = "S"
elif prediction == "P":
predictions[0] = "P"
predictions[1] = "S"
predictions[2] = "R"
else:
predictions[0] = "S"
predictions[1] = "R"
predictions[2] = "P"
# choose move
best = -1000
index = 0
while index < numPredictors:
if scores[index] > best:
best = scores[index]
if predictions[index] == "R":
output = "P"
elif predictions[index] == "P":
output = "S"
else:
output = "R"
index += 1
lastOutput = output