Diamond Honduras

This program has been disqualified.


AuthorEbTech
Submission date2011-07-08 22:57:00.719130
Rating7587
Matches played1577
Win rate76.92

Source code:

# learn about Martian cuisine at http://www.codeforces.com/contest/77/problem/E

import random

if not input:
	beat = {'R':'P','P':'S','S':'R'}
	fusion = {'RP':'a','PS':'b','SR':'c','PR':'d','SP':'e','RS':'f','RR':'g','PP':'h','SS':'i'}
	limits = [5,11,24,52]
	moves = ["","",""]
	numPredictors = 6*len(limits)*len(moves)
	numMetapredictors = 6
	predictors = [random.choice("RPS") for i in range(numPredictors)]
	predictorscore = [random.random() for i in range(numPredictors)]
	opponentscore = [random.random() for i in range(numPredictors)]
	metapredictors = [random.choice("RPS") for i in range(numMetapredictors)]
	metascore = [12,12,0,0,0,0]
	threat = [0,0,0]
	outcome = 0
	length = 0
	output = random.choice("RPS")
else:
	oldoutcome = outcome
	if (beat[input] == output):
		outcome = 1
	elif (input == beat[output]):
		outcome = -1
	else:
		outcome = 0
	threat[oldoutcome + 1] *= 0.96
	threat[oldoutcome + 1] -= 0.04*outcome
	weight = 0.18 + 0.04*random.random()
	for i in range(numPredictors):
		predictorscore[i] *= 1 - weight
		predictorscore[i] += weight*(beat[input] == predictors[i])
		predictorscore[i] -= weight*(input == beat[predictors[i]])
		opponentscore[i] *= 1 - weight
		opponentscore[i] += weight*(beat[output] == predictors[i])
		opponentscore[i] -= weight*(output == beat[predictors[i]])
		if input == beat[predictors[i]] and random.random() < weight:
			predictorscore[i] = 0
		if output == beat[predictors[i]] and random.random() < weight:
			opponentscore[i] = 0
	for i in range(numMetapredictors):
		metascore[i] *= 1 - weight/5
		metascore[i] += weight/5*(beat[input] == metapredictors[i])
		metascore[i] -= weight/5*(input == beat[metapredictors[i]])
		if input == beat[metapredictors[i]] and random.random() < weight/2:
			metascore[i] = 0
	moves[0] += input
	moves[1] += output
	moves[2] += fusion[input+output]
	length += 1
	
	for z in range(3*len(limits)):
		j = min(length-1, limits[z//3])
		while not moves[z%3][length-j:length] in moves[z%3][0:length-1]:
			j-=1
		i = moves[z%3].rfind(moves[z%3][length-j:length], 0, length-1)
		predictors[2 * z] = moves[0][i+j]
		predictors[2*z+1] = moves[1][i+j]
	for i in range(numPredictors/3, numPredictors):
		predictors[i] = beat[predictors[i - numPredictors/3]]
	weight = max(predictorscore)
	metapredictors[0] = predictors[predictorscore.index(weight)]
	metapredictors[1] = beat[predictors[opponentscore.index(max(opponentscore))]]
	for i in range(numMetapredictors/3, numMetapredictors):
		metapredictors[i] = beat[metapredictors[i - numMetapredictors/3]]
	
	if length < 40*(1.1-weight) or random.random() < 2*threat[outcome+1]+0.1:
		output = random.choice("RPS")
	else:
		output = metapredictors[metascore.index(max(metascore))]