Flammenwerfer 3

This program has been disqualified.


Authordllu
Submission date2011-05-23 22:20:50.947762
Rating5159
Matches played126
Win rate51.59

Source code:

import random
import math

lastmatch =0
lastmatch1=0
lastmatch2=0
heatR=heatP=heatS=[0,0,0,0,0,0]


predictors=range(12)

for i in range(12):
	predictors[i]=random.choice(['R','P','S'])

if not input:
	oldpredictors=range(12)
	urmoves=""
	mymoves=""
	output=random.choice(['R','P','S'])
	predictorscore=[1.2,0.7,0.7,0.6,0.6,0.6,0.1,0.1,0.1,0.1,0.1,0.1]
else:
	#if len(mymoves)<40:
	#	limit = len(mymoves)
	#else:
	#	limit = 40
	
	limit = 30
	
	for i in range(12):
		predictorscore[i]*=0.83
		predictorscore[i]+=(input==oldpredictors[i])/10.0
		predictorscore[i]-=(input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictors[i]])/10.0
	
	#Predictor 0-11: History matching
	urmoves+=input
	done=0
	done1=0
	done2=0
		
	for i in range(len(urmoves)-1,limit+1,-1):
		match=0
		j=1
		predictur=random.choice(['R','P','S'])
		predictmy=random.choice(['R','P','S'])
		while j<=i and mymoves[i-j]==mymoves[len(urmoves)-j] and urmoves[i-j]==urmoves[len(urmoves)-j]:
			match+=1
			if match>lastmatch:
				lastmatch=match
				if not done:
					predictors[0]=urmoves[i]
				if not done:
					predictors[1]=mymoves[i]
				predictur = urmoves[i]
				predictmy = mymoves[i]
			if match>limit:
				done=1
				break
			j+=1
			
		energy = math.pow(match+1,math.log(match+1)+1)
		if predictur=='R':
			heatR[0]+=energy
			heatP[0]-=energy
		elif predictur=='P':
			heatP[0]+=energy
			heatS[0]-=energy
		else:
			heatS[0]+=energy
			heatR[0]-=energy
		if predictmy=='R':
			heatR[1]+=energy
			heatP[1]-=energy
		elif predictmy=='P':
			heatP[1]+=energy
			heatS[1]-=energy
		else:
			heatS[1]+=energy
			heatR[1]-=energy
		
		match=0
		j=1
		while j<=i and mymoves[i-j]==mymoves[len(urmoves)-j]:
			match+=1
			if match>lastmatch1:
				lastmatch1=match
				if not done1:
					predictors[2]=urmoves[i]
				if not done1:
					predictors[3]=mymoves[i]
				predictur = urmoves[i]
				predictmy = mymoves[i]
			if match>limit:
				done1=1
				break
			j+=1
		energy = math.pow(match+1,math.log(match+1)+1)
		if predictur=='R':
			heatR[2]+=energy
			heatP[2]-=energy
		elif predictur=='P':
			heatP[2]+=energy
			heatS[2]-=energy
		else:
			heatS[2]+=energy
			heatR[2]-=energy
		if predictmy=='R':
			heatR[3]+=energy
			heatP[3]-=energy
		elif predictmy=='P':
			heatP[3]+=energy
			heatS[3]-=energy
		else:
			heatS[3]+=energy
			heatR[3]-=energy
		match=0
		j=1
		while j<=i and urmoves[i-j]==urmoves[len(urmoves)-j]:
			match+=1
			if match>lastmatch2:
				lastmatch2=match
				if not done2:
					predictors[4]=urmoves[i]
				if not done2:
					predictors[5]=mymoves[i]
				predictur = urmoves[i]
				predictmy = mymoves[i]
			if match>limit:
				done2=1
				break
			j+=1
		energy = math.pow(match+1,math.log(match+1)+1)
		if predictur=='R':
			heatR[4]+=energy
			heatP[4]-=energy
		elif predictur=='P':
			heatP[4]+=energy
			heatS[4]-=energy
		else:
			heatS[4]+=energy
			heatR[4]-=energy
		if predictmy=='R':
			heatR[5]+=energy
			heatP[5]-=energy
		elif predictmy=='P':
			heatP[5]+=energy
			heatS[5]-=energy
		else:
			heatS[5]+=energy
			heatR[5]-=energy
	
	predictors[1]={'R':'S', 'P':'R', 'S':'P'}[predictors[1]]
	predictors[3]={'R':'S', 'P':'R', 'S':'P'}[predictors[3]]
	predictors[5]={'R':'S', 'P':'R', 'S':'P'}[predictors[5]]
	for i in range(6,12):
		if heatR[i-6]>heatP[i-6] and heatR[i-6]>heatS[i-6]:
			predictors[i]='R'
		elif heatP[i-6]>heatS[i-6]:
			predictors[i]='P'
		else:
			predictors[i]='S'
	predictors[7]={'R':'S', 'P':'R', 'S':'P'}[predictors[7]]
	predictors[9]={'R':'S', 'P':'R', 'S':'P'}[predictors[9]]
	predictors[11]={'R':'S', 'P':'R', 'S':'P'}[predictors[11]]
		
	
	#compare predictors
	best=-1
	for i in [0,2,4,1,3,5,6,8,10,7,9,11]:
		if predictorscore[i]>best:
			output = predictors[i]
			best = predictorscore[i]
			
	if best<-0.5:
		output=random.choice(['R','P','S'])
			
output = {'R':'P','P':'S','S':'R'}[output] #attempt to win			
mymoves+=output

for i in range(12):
	oldpredictors[i]=predictors[i]