Granatewerfer 3

This program has been disqualified.


Authordllu
Submission date2011-05-25 16:34:52.175020
Rating7500
Matches played4
Win rate75.0

Source code:

import random

lastmatch =0
lastmatch1=0
lastmatch2=0

limit = 15

predictors=range(14)
best=-100

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

if not input:
	oldpredictors=range(14)
	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]
	
	rockRating = scissorsRating = paperRating = 0
	rockRating2 = scissorsRating2 = paperRating2 = 0
else:
	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
	
	for i in range(len(urmoves)-1,limit+1,-1):
		match1=0
		match2=0
		fail=[0,0,0]
		j=1
		while j<=i:
			
			if urmoves[i-j]==urmoves[len(urmoves)-j] and mymoves[i-j]==mymoves[len(urmoves)-j] and not done:
				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[len(urmoves)-j] and not done1:
				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[len(urmoves)-j] and not done2:
				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 and done1 and done2 or fail==[1,1,1]:
				break
			j+=1
		
		if done and done1 and done2 or i<len(urmoves)-200:
			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]