This program has been disqualified.
Author | Byron Knoll |
Submission date | 2011-05-31 08:40:46.451065 |
Rating | 6569 |
Matches played | 3796 |
Win rate | 68.2 |
import random
# initialization
if input=="":
maxHistoryLength = 200
history = ""
dictionary = {}
lastOutput = ""
# update history
history += input + lastOutput
if len(history) > maxHistoryLength:
history = history[1:maxHistoryLength+1]
# update dictionary
index = 0
while index < len(history)-1:
key = history[index:len(history)-1]
if dictionary.has_key(key):
dictionary[key] = dictionary[key] + 1
else:
dictionary[key] = 1
index+=1
# make prediction
order = len(history)-1
output = ""
while order >= 0:
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 > 0 and rockCount > paperCount and rockCount > scissorsCount:
if random.random() < 0.5:
output = "P"
else:
output = "R"
elif paperCount > 0 and paperCount > scissorsCount:
if random.random() < 0.5:
output = "S"
else:
output = "P"
elif scissorsCount > 0:
if random.random() < 0.5:
output = "R"
else:
output = "S"
order -= 1
if output != "":
break
if output == "":
output=random.choice(["R","P","S"])
lastOutput = output