Centrifugal Dumbledore 3

This program has been disqualified.


Authordllu
Submission date2011-07-12 19:23:51.460669
Rating7541
Matches played121
Win rate75.21

Source code:

#see also www.dllu.net/rps.html
import random
import re
numPre = 36
numMeta = 36
if not input:
	limit = 10
	beat={'R':'P','P':'S','S':'R'}
	moves=['','','']
	pScore=[[3]*numPre,[3]*numPre,[3]*numPre,[3]*numPre,[3]*numPre,[3]*numPre]
	centrifuge={'RP':'a','PS':'b','SR':'c','PR':'d','SP':'e','RS':'f','RR':'g','PP':'h','SS':'i'}
	length=0
	p=[random.choice("RPS")]*numPre
	m=[random.choice("RPS")]*numMeta
	mScore=[3]*numMeta
	helicase=[0,0,0,0,0,0]
	
	def weighted_square_choice(C, p):
		for i in range(len(p)):
			p[i]=p[i]**2;
		pS=float(sum(p));
		if pS==0:
			return C[0]
		for i in range(len(p)):
			p[i]=p[i]/pS;
		x = random.random()
		for elmt in range(len(C)):
			if x <= p[elmt]:
				return C[elmt]
			x -= p[elmt]
else:
	for i in range(numPre):
		pScore[0][i]=0.8*pScore[0][i]+((input==p[i])-(input==beat[beat[p[i]]]))*3
		pScore[1][i]=0.8*pScore[1][i]+((output==p[i])-(output==beat[beat[p[i]]]))*3
		pScore[2][i]=0.87*pScore[2][i]+(input==p[i])*3.3-(input==beat[p[i]])*0.9-(input==beat[beat[p[i]]])*3
		pScore[3][i]=0.87*pScore[3][i]+(output==p[i])*3.3-(output==beat[p[i]])*0.9-(output==beat[beat[p[i]]])*3
		pScore[4][i]=(pScore[4][i]+(input==p[i])*3)*(1-(input==beat[beat[p[i]]]))
		pScore[5][i]=(pScore[5][i]+(output==p[i])*3)*(1-(output==beat[beat[p[i]]]))
	for i in range(numMeta):
		mScore[i]=(mScore[i]+(input==m[i]))*(1-(input==beat[beat[m[i]]]))
	moves[0]+=centrifuge[input+output]
	moves[1]+=input		
	moves[2]+=output
	length+=1
	
	for y in range(3):
		j=min([length,limit])
		while j>=1 and not moves[y][length-j:length] in moves[y][0:length-1]:
			j-=1
		i = moves[y].rfind(moves[y][length-j:length],0,length-1)
				
		p[0+2*y] = moves[1][j+i]
		p[1+2*y] = beat[moves[2][j+i]]
	j=limit
	k={}
	while j>=1 and not moves[0][length-j:length] in moves[0][0:length-1]:
		j-=1
	for x in "abcdefghi":
		k[x] = len(re.findall(r'(?<=%s)%s' % (moves[0][length-j:length], x), moves[0][0:length-1]))
	kR =k['a']+k['f']+k['g']
	kP =k['b']+k['d']+k['h']
	kS =k['c']+k['e']+k['i']
	kR0=k['c']+k['d']+k['g']
	kP0=k['a']+k['e']+k['h']
	kS0=k['b']+k['f']+k['i']
	p[8]="RPS"[[kR -kS ,kP -kR ,kS -kP ].index(max([kR -kS ,kP -kR ,kS -kP ]))]
	p[9]="PSR"[[kR0-kS0,kP0-kR0,kS0-kP0].index(max([kR0-kS0,kP0-kR0,kS0-kP0]))]
	p[6]="RPS"[[kR     ,kP     ,kS     ].index(max([kR     ,kP     ,kS     ]))]
	p[7]="PSR"[[kR0    ,kP0    ,kS0    ].index(max([kR0    ,kP0    ,kS0    ]))]
	
	helicase[0] = helicase[0]*0.95+{'R':0,'P':-0.1,'S':0.1}[output]
	helicase[1] = helicase[1]*0.95+{'R':0.1,'P':0,'S':-0.1}[output]
	helicase[2] = helicase[2]*0.95+{'R':-0.1,'P':0.1,'S':0}[output]
	p[10] = {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]
	p[11] = {0:'R',1:'P',2:'S',3:'R',4:'P',5:'S'}[helicase.index(max(helicase[3:6]))]
	
	for i in range(12,12*3):
		p[i]=beat[beat[p[i-12]]]
		
	for i in range(0,6,2):
		m[i]=       p[pScore[i  ].index(max(pScore[i  ]))]
		m[i+1]=beat[p[pScore[i+1].index(max(pScore[i+1]))]]
		m[i+6]=     weighted_square_choice(p,pScore[i])
		m[i+7]=beat[weighted_square_choice(p,pScore[i+1])]
	for i in range(12,36):
		m[i]=beat[beat[m[i-12]]]
output = beat[m[mScore.index(max(mScore))]]
if random.randint(3,60)>length:
	output=beat[random.choice("RPS")]