Time Warp

This program has been disqualified.


AuthorEbTech
Submission date2011-06-26 22:21:53.456499
Rating7618
Matches played2138
Win rate75.21

Source code:

# prediction by time travel

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 = [6,16,40,2,12,4]
	warps = [0,0,0,5,5,15]
	moves = ["","",""]
	numPredictors = 6*len(limits)*len(moves)
	numMetapredictors = 6
	predictors = [random.choice("RPS") for i in range(numPredictors)]
	predictorscore = [2*random.random() for i in range(numPredictors)]
	opponentscore = [2*random.random() for i in range(numPredictors)]
	metapredictors = [random.choice("RPS") for i in range(numMetapredictors)]
	metascore = [20,10,0,0,0,0]
	threat = [0,0,0]
	outcome = 0
	length = 0
	output = random.choice(['R','P','S'])
	wait = random.randint(18, 30)
else:
	oldoutcome = outcome
	if (beat[input] == output):
		outcome = 1
	elif (input == beat[output]):
		outcome = -1
	else:
		outcome = 0
	threat[oldoutcome + 1] *= 0.958
	threat[oldoutcome + 1] -= 0.042*outcome
	for i in range(numPredictors):
		predictorscore[i] *= 0.8
		predictorscore[i] += (beat[input] == predictors[i])
		predictorscore[i] -= (input == beat[predictors[i]])
		opponentscore[i] *= 0.8
		opponentscore[i] += (beat[output] == predictors[i])
		opponentscore[i] -= (output == beat[predictors[i]])
		if input == beat[predictors[i]] and random.random() < 0.5:
			predictorscore[i] = 0
		if output == beat[predictors[i]] and random.random() < 0.5:
			opponentscore[i] = 0
	for i in range(numMetapredictors):
		metascore[i] *= 0.958
		metascore[i] += (beat[input] == metapredictors[i])
		metascore[i] -= (input == beat[metapredictors[i]])
		if input == beat[metapredictors[i]] and random.random() < 0.5:
			metascore[i] = 0
	moves[0] += input
	moves[1] += output
	moves[2] += fusion[input+output]
	length += 1
	
	for z in range(3*len(limits)):
	    wormhole = length - warps[z//3]
	    if wormhole <= 0:
		predictors[2 * z] = random.choice("RPS")
		predictors[2*z+1] = random.choice("RPS")
	    else:
		j = min(wormhole-1, limits[z//3])
		while not moves[z%3][wormhole-j:wormhole] in moves[z%3][0:wormhole-1]:
			j-=1
		i = moves[z%3].rfind(moves[z%3][wormhole-j:wormhole], 0, wormhole-1)
		predictors[2 * z] = moves[0][i+j+warps[z//3]]
		predictors[2*z+1] = moves[1][i+j+warps[z//3]]
	for i in range(numPredictors/3, numPredictors):
		predictors[i] = beat[predictors[i - numPredictors/3]]
	metapredictors[0] = predictors[predictorscore.index(max(predictorscore))]
	metapredictors[1] = beat[predictors[opponentscore.index(max(opponentscore))]]
	for i in range(numMetapredictors/3, numMetapredictors):
		metapredictors[i] = beat[metapredictors[i - numMetapredictors/3]]
	
	if length < wait or random.random() < 0.4*threat[outcome+1]+0.1:
		output = random.choice("RPS")
	else:
		output = metapredictors[metascore.index(max(metascore))]