The Averager

This program has been disqualified.


AuthorMrMasterplan
Submission date2011-06-10 11:17:56.391356
Rating6284
Matches played1468
Win rate58.65

Source code:

class FighterBot:
	"""docstring for FighterBot"""
	def __init__(self, name,code):
		self.bot_name = name
		self.code = compile(code,name,'exec')
		self.locals = {}
		self.globals = {}
	
	def roll(self,opponents_choice=""):
		self.locals['input'] = opponents_choice
		exec(self.code,self.globals,self.locals)
		return self.locals['output']

if not input:
	bots=[FighterBot("DNA","""
#DNA Polymerase
#This enzyme helps with DNA replication.
import random
if not input:
	limit = 5
	telomere = 27
	DNA_strand0=""
	DNA_strand1=""
	DNA_strand2=output = random.choice(['R','P','S'])
	DNA_strand3="" #Unlike most other DNA, this one has four strands
	base_pairs = range(telomere)
	for i in range(telomere):
		base_pairs[i] = random.choice(['R','P','S'])
	nucleotide_frequency = range(telomere,0,-1)
	helicase=[0,0,0,0,0,0]
	deoxyribonuclease = {'RP':'a','PS':'a','SR':'a','PR':'b','SP':'b','RS':'b','RR':'c','PP':'c','SS':'c'}
	ribonuclease = {'RP':'I','PS':'A','SR':'M','PR':'S','SP':'U','RS':'P','RR':'E','PP':'R','SS':'B'}
else:
	for i in range(telomere):
		nucleotide_frequency[i]*=0.9
		if input==mRNA[i]:
			nucleotide_frequency[i]+=telomere*0.3
		elif input=={'R':'S', 'P':'R', 'S':'P'}[mRNA[i]]:
			nucleotide_frequency[i]-=telomere*0.28
		else:
			nucleotide_frequency[i]-=telomere*0.02
	DNA_strand1+=input
	DNA_strand3+=deoxyribonuclease[input+output]
	DNA_strand0+=ribonuclease[input+output]
	length = len(DNA_strand2)
	j=limit
	if j>length:
		j=length
	i = DNA_strand2.rfind(DNA_strand2[length-j:length-1],0,length-2)
	while i==-1:
		j-=1
		i = DNA_strand2.rfind(DNA_strand2[length-j:length-1],0,length-2)
		if j<2:
			break
	if i==-1 or j+i>=length:
		base_pairs[0] = base_pairs[2] = random.choice(['R','P','S'])
	else:
		base_pairs[0] = DNA_strand1[j+i]
		base_pairs[1] = {'R':'P','P':'S','S':'R'}[DNA_strand2[j+i]]
	j=limit
	if j>length:
		j=length
	i = DNA_strand1.rfind(DNA_strand1[length-j:length-1],0,length-2)
	while i==-1:
		j-=1
		i = DNA_strand1.rfind(DNA_strand1[length-j:length-1],0,length-2)
		if j<2:
			break
	if i==-1 or j+i>=length:
		base_pairs[2] = base_pairs[3] = random.choice(['R','P','S'])
	else:
		base_pairs[2] = DNA_strand1[j+i]
		base_pairs[3] = {'R':'P','P':'S','S':'R'}[DNA_strand2[j+i]]
	j=limit
	if j>length:
		j=length
	i = DNA_strand0.rfind(DNA_strand0[length-j:length-1],0,length-2)
	while i==-1:
		j-=1
		i = DNA_strand0.rfind(DNA_strand0[length-j:length-1],0,length-2)
		if j<2:
			break
	if i==-1 or j+i>=length:
		base_pairs[4] = base_pairs[5] = random.choice(['R','P','S'])
	else:
		base_pairs[4] = DNA_strand1[j+i]
		base_pairs[5] = {'R':'P','P':'S','S':'R'}[DNA_strand2[j+i]]
	j=limit
	if j>length:
		j=length
	i = DNA_strand3.rfind(DNA_strand3[length-j:length-1],0,length-2)
	while i==-1:
		j-=1
		i = DNA_strand3.rfind(DNA_strand3[length-j:length-1],0,length-2)
		if j<2:
			break
	if i==-1 or j+i>=length:
		base_pairs[6] = base_pairs[7] = random.choice(['R','P','S'])
	else:
		base_pairs[6] = DNA_strand1[j+i]
		base_pairs[7] = {'R':'P','P':'S','S':'R'}[DNA_strand2[j+i]]
		
	for i in range(8,24):
		base_pairs[i] = {'R':'S','P':'R','S':'P'}[base_pairs[i-8]]
		
	base_pairs[26] = random.choice(['R','P','S'])
		
	#Helicase
	helicase[0] = helicase[0]*0.95+{'R':0,'P':-0.1,'S':0.1}[DNA_strand2[length-1]]
	helicase[1] = helicase[1]*0.95+{'R':0.1,'P':0,'S':-0.1}[DNA_strand2[length-1]]
	helicase[2] = helicase[2]*0.95+{'R':-0.1,'P':0.1,'S':0}[DNA_strand2[length-1]]
	base_pairs[24] = {0:'R',1:'P',2:'S',3:'R',4:'P',5:'S'}[helicase.index(max(helicase[0:3]))]
	
	helicase[3] = helicase[3]*0.95+{'R':0.1,'P':0,'S':-0.1}[input]
	helicase[4] = helicase[4]*0.95+{'R':-0.1,'P':0.1,'S':0}[input]
	helicase[5] = helicase[5]*0.95+{'R':0,'P':-0.1,'S':0.1}[input]
	base_pairs[25] = {0:'R',1:'P',2:'S',3:'R',4:'P',5:'S'}[helicase.index(max(helicase[3:6]))]
		
	output = {'R':'P', 'P':'S', 'S':'R'}[base_pairs[nucleotide_frequency.index(max(nucleotide_frequency))]]
	output = {0:output,1:random.choice(['R','P','S'])}[length%16==11]
	DNA_strand2+=output
mRNA = base_pairs
"""), FighterBot("Granat","""
import random

lastmatch =0
lastmatch1=0
lastmatch2=0

limit = 6

best=-100



if not input:
	urmoves=""
	mymoves=""
	output=random.choice(['R','P','S'])
	predictorscore=[1.2,0.7,0.7,0.6,0.6,0.6,0,0,0,0,0,0,0,0]
	oldpredictors=predictors=['P','P','P','P','P','P','P','P','P','P','P','P','P','P',]
	
	length=0
	
	rockRating = scissorsRating = paperRating = 0
	rockRating2 = scissorsRating2 = paperRating2 = 0
else:
	for i in range(6):
		predictors[i]=random.choice(['R','P','S'])
	for i in range(14):
		predictorscore[i]*=0.87
		if input==oldpredictors[i]:
			predictorscore[i]+=0.11
		elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictors[i]]:
			predictorscore[i]-=0.10
		else:
			predictorscore[i]-=0.03
	
	#Predictor 0-11: History matching
	urmoves+=input
	done=0
	done1=0
	done2=0
	
	length+=1
	
	for i in range(length-1,limit+1,-1):
		match=0
		match1=0
		match2=0
		fail=[0,0,0]
		j=1
		while j<=i:
			if urmoves[i-j]==urmoves[length-j] and mymoves[i-j]==mymoves[length-j] and not (done or fail[0]):
				match+=1
				if match>lastmatch:
					lastmatch=match
					predictors[0]=urmoves[i]
					predictors[1]=mymoves[i]
				if match>limit:
					done=1
			elif not done:
				match=0
				fail[0]=1
			if mymoves[i-j]==mymoves[length-j] and not (done1 or fail[1]):
				match1+=1
				if match1>lastmatch1:
					lastmatch1=match1
					predictors[2]=urmoves[i]
					predictors[3]=mymoves[i]
				if match1>limit:
					done1=1
			elif not done1:
				match1=0
				fail[1]=1
			if urmoves[i-j]==urmoves[length-j] and not (done2 or fail[2]):
				match2+=1
				if match2>lastmatch2:
					lastmatch2=match2
					predictors[4]=urmoves[i]
					predictors[5]=mymoves[i]
				if match2>limit:
					done2=1
			elif not done2:
				match2=0
				fail[2]=1
			if (done or fail[0]) and (done1 or fail[1]) and (done2 or fail[2]):
				break
			j+=1
		
		if (done and done1 and done2) or (i<length-160):
			break
	
	predictors[1]={'R':'P','P':'S','S':'R'}[predictors[1]]
	predictors[3]={'R':'P','P':'S','S':'R'}[predictors[3]]
	predictors[5]={'R':'P','P':'S','S':'R'}[predictors[5]]
	
	#Predictor 7-12: Opponent plays like Predictor 1-6
	for i in range(7,12):
		predictors[i] = {'R':'S','P':'R','S':'P'}[predictors[i-6]]
	
	#Predictor 13: Opponent plays like Boltzmann counter
	rockRating *= 0.95
	scissorsRating *= 0.95
	paperRating *= 0.95
	if mymoves[len(mymoves)-1] == "R":
		paperRating += 0.1
		scissorsRating -= 0.1
	elif mymoves[len(mymoves)-1] == "P":
		scissorsRating += 0.1
		rockRating -= 0.1
	elif mymoves[len(mymoves)-1] == "S":
		rockRating += 0.1
		paperRating -= 0.1
	if rockRating>scissorsRating and rockRating>paperRating:
		predictors[12] = "R"
	elif paperRating>scissorsRating:
		predictors[12] = "P"
	else:
		predictors[12] = "S"
		
	#Predictor 14: I play like Boltzmann counter
	rockRating2 *= 0.95
	scissorsRating2 *= 0.95
	paperRating2 *= 0.95
	if input=='R':
		rockRating2+=0.1
		paperRating2-=0.1
	elif input=='P':
		paperRating2+=0.1
		scissorsRating2-=0.1
	else:
		scissorsRating2+=0.1
		rockRating2=0.1
	if rockRating2>scissorsRating2 and rockRating2>paperRating2:
		predictors[13] = "R"
	elif paperRating2>scissorsRating2:
		predictors[13] = "P"
	else:
		predictors[13] = "S"
		

	
	#compare predictors
	for i in range(14):
		if predictorscore[i]>best:
			output = predictors[i]
			best = predictorscore[i]
			
output = {'R':'P','P':'S','S':'R'}[output] #attempt to win
if len(mymoves)%17==11 or best<0:
	output = random.choice(['R','P','S'])
mymoves+=output

for i in range(14):
	oldpredictors[i]=predictors[i]
"""),FighterBot("trash","""import math
import random

if input == "":
	matchHistory = ""
	candidate = ['P','P','P','P','P','P','P']
	score = [0,0,0,0,0,0,0]
else:
	matchHistory += input
	for i in range(0, 6):
		score[i] *= 0.95
		score[i] += (4 + {'R':0,'P':1,'S':2}[candidate[i]] - {'R':0,'P':1,'S':2}[input])%3 - 1
	
candidate[0] = random.choice(['R','P','S'])
candidate[1] = random.choice(['R','P','S'])
candidate[4] = random.choice(['R','P','S'])
index = 0
limit = 50
longestMatch = 0

while index < len(matchHistory)-2:
	index2 = index
	index3 = len(matchHistory)-2
	length = 0
	while index2 >= 0:
		if matchHistory[index2] != matchHistory[index3] or matchHistory[index2+1] != matchHistory[index3+1]:
			break
		index2 -= 2
		index3 -= 2
		length += 1
		if length > limit:
			break
	if length > longestMatch:
		longestMatch = length
		candidate[1] = matchHistory[index+3]
		candidate[4] = matchHistory[index+2]
	if length > limit:
		break
	index += 2

for i in [2,3,5,6]:
	candidate[i] = {'R':'S','P':'R','S':'P'}[candidate[i-1]]

best = 0
output = candidate[0]
for i in range(1, 6):
	if (score[i] > score[best]):
		best = i
		output = candidate[i]
matchHistory += output
""")]

score={'R':0,'P':0,'S':0}
for bot in bots:
	out=bot.roll(input)
	score[out]+=1
	if input:
		if score[out] > len(bots)/2:
			break
output=max([(v,k) for k,v in score.items()])[1]