This program has been disqualified.
Author | Byron Knoll |
Submission date | 2011-05-31 08:35:16.661582 |
Rating | 6277 |
Matches played | 3765 |
Win rate | 65.05 |
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:
output = "P"
elif paperCount > 0 and paperCount > scissorsCount:
output = "S"
elif scissorsCount > 0:
output = "R"
order -= 1
if output != "":
break
if output == "":
output=random.choice(["R","P","S"])
lastOutput = output