Iocaine Ensemble V7

This program has been disqualified.


AuthorByron Knoll
Submission date2011-06-11 06:12:07.209078
Rating6227
Matches played1246
Win rate65.89

Source code:

import random

# initialization
if input=="":
	numPredictors = 10
	maxHistoryLength = 100
	history1 = ""
	history2 = ""
	history3 = ""
	lastOutput = ""
	scores = []
	predictions = []
	index = 0
	while index < numPredictors:
		scores.append(0)
		predictions.append("")
		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,1,2 = PPM model opponent)
order = len(history1)-1
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[0] = "P"
		predictions[1] = "S"
		predictions[2] = "R"
		break
	elif paperCount > 0 and paperCount > scissorsCount:
		predictions[0] = "S"
		predictions[1] = "R"
		predictions[2] = "P"
		break
	elif scissorsCount > 0:
		predictions[0] = "R"
		predictions[1] = "P"
		predictions[2] = "S"
		break
	order -= 1

# make prediction (3,4,5 = PPM model me)
order = len(history2)-1
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[3] = "P"
		predictions[4] = "S"
		predictions[5] = "R"
		break
	elif paperCount > 0 and paperCount > scissorsCount:
		predictions[3] = "S"
		predictions[4] = "R"
		predictions[5] = "P"
		break
	elif scissorsCount > 0:
		predictions[3] = "R"
		predictions[4] = "P"
		predictions[5] = "S"
		break
	order -= 1

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

# make prediction (7,8,9 = PPM model both)
order = len(history3)-1
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[7] = "P"
		predictions[8] = "S"
		predictions[9] = "R"
		break
	elif paperCount > 0 and paperCount > scissorsCount:
		predictions[7] = "S"
		predictions[8] = "R"
		predictions[9] = "P"
		break
	elif scissorsCount > 0:
		predictions[7] = "R"
		predictions[8] = "P"
		predictions[9] = "S"
		break
	order -= 1

# choose move
best = -1000
index = 0
while index < numPredictors:
	if scores[index] > best:
		best = scores[index]
		if predictions[index] == "R":
			output = random.choice(["P","R"])
		elif predictions[index] == "P":
			output = random.choice(["P","S"])
		else:
			output = random.choice(["S","R"])
	index += 1
lastOutput = output