Iocaine PPM V2

This program has been disqualified.


AuthorByron Knoll
Submission date2011-05-31 09:21:14.613931
Rating7269
Matches played3768
Win rate71.76

Source code:

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[3] = "R"
	predictions[4] = "P"
	predictions[5] = "S"
elif prediction == "P":
	predictions[3] = "P"
	predictions[4] = "S"
	predictions[5] = "R"
else:
	predictions[3] = "S"
	predictions[4] = "R"
	predictions[5] = "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