Variable Geometry Turbine 2

This program has been disqualified.


Authordllu
Submission date2011-05-23 02:41:29.028703
Rating7895
Matches played209
Win rate78.95

Source code:

import random

lastmatch=0
lastmatch3=0

limit = 30

if not input:
	urmoves=""
	mymoves=""
	predictor1='R'
	predictor2='P'
	predictor3='S'
	blloutput=bloutput=output=random.choice(['R','P','S'])
	predictor1score=1.0
	predictor2score=0.2
	predictor3score=0.5
else:
	if input==oldpredictor1:
		predictor1score+=0.1
	elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor1]:
		predictor1score-=0.1
	if input==oldpredictor2:
		predictor2score+=0.1
	elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor2]:
		predictor2score-=0.1
	if input==oldpredictor3:
		predictor3score+=0.1
	elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor3]:
		predictor3score-=0.1
		
	#Predictor 1: assume that if I play the same sequence of moves, the opponent will reply the same
	predictor1 = random.choice(['R','P','S'])
	urmoves+=input
	for i in range(len(urmoves)-1,limit,-1):
		match=0
		j=1
		while mymoves[i-j]==mymoves[len(urmoves)-j]:
			match+=1
			if match>lastmatch:
				lastmatch=match
				predictor1=urmoves[i]
			if match>limit:
				break
			j+=1
		if match>limit:
			break
			
	#Predictor 2: assume that the opponent plays like Probably not very strong 3.1
	blloutput = bloutput
	bloutput = input
	if loutput == {'R':'P','P':'S','S':'R'}[blloutput]:
		predictor2 = {'R':'R','P':'P','S':'S'}[bloutput]
	elif loutput == {'R':'S','P':'R','S':'P'}[blloutput]:
		predictor2 = {'R':'P','P':'S','S':'R'}[bloutput]
	elif loutput == {'R':'R','P':'P','S':'S'}[blloutput]:
		predictor2 = {'R':'S','P':'R','S':'P'}[bloutput]
	
	predictor2 = {'P':'R', 'S':'P', 'R':'S'}[predictor2]
	
	#Predictor 3: assume that if the opponent plays the same sequence of moves, he will continue the same
	predictor3 = random.choice(['R','P','S'])
	for i in range(len(urmoves)-1,limit,-1):
		match3=0
		j=1
		while urmoves[i-j]==urmoves[len(urmoves)-j]:
			match3+=1
			if match3>lastmatch3:
				lastmatch3=match3
				predictor3=urmoves[i]
			if match>limit:
				break
			j+=1
		if match3>limit:
			break
	
	#compare predictors
	if predictor1score>predictor2score and predictor1score>predictor3score:
		output = predictor1
	elif predictor2score>predictor3score:
		output = predictor2
	else:
		output = predictor3
	
	output =  {'R':'P', 'P':'S', 'S':'R'}[output]

mymoves+=output
oldpredictor1=predictor1
oldpredictor2=predictor2
oldpredictor3=predictor3
loutput=output