Iocaine Ensemble V5

This program has been disqualified.


AuthorByron Knoll
Submission date2011-06-03 06:36:54.810614
Rating6979
Matches played960
Win rate69.79

Source code:

import random

# initialization
if input=="":
	numPredictors = 2 * 3 * 3 + 1
	maxHistoryLength = 100
	history1 = ""
	history2 = ""
	history3 = ""
	lastOutput = ""
	scores = []
	predictions = []
	index = 0
	while index < numPredictors:
		scores.append(0)
		predictions.append(random.choice(["R","P","S"]))
		index+=1
	dictionary1 = {}
	dictionary2 = {}
	dictionary3 = {}

# 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 histories
history1 += input
if len(history1) > maxHistoryLength:
	history1 = history1[1:maxHistoryLength+1]
history2 += lastOutput
if len(history2) > maxHistoryLength:
	history2 = history2[1:maxHistoryLength+1]
history3 += input + lastOutput
if len(history3) > maxHistoryLength:
	history3 = history3[1:maxHistoryLength+1]

# update dictionaries
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)-1]
	if dictionary2.has_key(key):
		dictionary2[key] = dictionary2[key] + 1
	else:
		dictionary2[key] = 1
	index+=1
index = 0
while index < len(history3):
	key = history3[index:len(history3)]
	if dictionary3.has_key(key):
		dictionary3[key] = dictionary3[key] + 1
	else:
		dictionary3[key] = 1
	index+=1

# make prediction (0 = random)
predictions[0] = random.choice(["R","P","S"])

# make PPM predictions
orders = [len(history1)-1, 1]
count = 0
predictorIndex = 1
while count < len(orders):
	initOrder = orders[count]
	count += 1
	
	# make prediction (PPM model opponent)
	order = initOrder
	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:
			predictions[predictorIndex+0] = "P"
			predictions[predictorIndex+1] = "S"
			predictions[predictorIndex+2] = "R"
			break
		elif paperCount > 0 and paperCount > scissorsCount:
			predictions[predictorIndex+0] = "S"
			predictions[predictorIndex+1] = "R"
			predictions[predictorIndex+2] = "P"
			break
		elif scissorsCount > 0:
			predictions[predictorIndex+0] = "R"
			predictions[predictorIndex+1] = "P"
			predictions[predictorIndex+2] = "S"
			break
		order -= 1
	predictorIndex += 3

	# make prediction (PPM model me)
	order = initOrder
	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:
			predictions[predictorIndex+0] = "P"
			predictions[predictorIndex+1] = "S"
			predictions[predictorIndex+2] = "R"
			break
		elif paperCount > 0 and paperCount > scissorsCount:
			predictions[predictorIndex+0] = "S"
			predictions[predictorIndex+1] = "R"
			predictions[predictorIndex+2] = "P"
			break
		elif scissorsCount > 0:
			predictions[predictorIndex+0] = "R"
			predictions[predictorIndex+1] = "P"
			predictions[predictorIndex+2] = "S"
			break
		order -= 1
	predictorIndex += 3

	# make prediction (PPM model both)
	order = initOrder*2
	while order >= 0:
		context = history3[len(history3)-order:len(history3)]
		if dictionary3.has_key(context+"R"):
			rockCount = dictionary3[context+"R"]
		else:
			rockCount = 0
		if dictionary3.has_key(context+"P"):
			paperCount = dictionary3[context+"P"]
		else:
			paperCount = 0
		if dictionary3.has_key(context+"S"):
			scissorsCount = dictionary3[context+"S"]
		else:
			scissorsCount = 0
		if rockCount > 0 and rockCount > paperCount and rockCount > scissorsCount:
			predictions[predictorIndex+0] = "P"
			predictions[predictorIndex+1] = "S"
			predictions[predictorIndex+2] = "R"
			break
		elif paperCount > 0 and paperCount > scissorsCount:
			predictions[predictorIndex+0] = "S"
			predictions[predictorIndex+1] = "R"
			predictions[predictorIndex+2] = "P"
			break
		elif scissorsCount > 0:
			predictions[predictorIndex+0] = "R"
			predictions[predictorIndex+1] = "P"
			predictions[predictorIndex+2] = "S"
			break
		order -= 1
	predictorIndex += 3

# 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