This program has been disqualified.
Author | dllu |
Submission date | 2011-05-23 03:54:07.860451 |
Rating | 8495 |
Matches played | 206 |
Win rate | 84.95 |
import random
import math
lastmatch=0
lastmatch3=0
limit = 25
if not input:
urmoves=""
mymoves=""
predictor1='R'
predictor2='P'
predictor3='S'
predictor4='R'
blloutput=bloutput=output=random.choice(['R','P','S'])
predictor1score=1.1
predictor2score=0.1
predictor3score=0.7
predictor4score=0.4
matchHistory=""
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
if input==oldpredictor4:
predictor4score+=0.1
elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor4]:
predictor4score-=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,-1):
match=0
j=1
while j<=i and 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'])
heatR = heatP = heatS = 0
for i in range(len(urmoves)-1,limit+1,-1):
match3=0
j=1
while j<=i and urmoves[i-j]==urmoves[len(urmoves)-j]:
match3+=1
if match3>lastmatch3:
lastmatch3=match3
energy=math.pow(j, math.log(j)+1)*(2*len(urmoves)-2-i)
heatR+={'R':energy,'P':-energy,'S':0}[urmoves[i]]
heatP+={'R':0,'P':energy,'S':-energy}[urmoves[i]]
heatS+={'R':-energy,'P':0,'S':energy}[urmoves[i]]
if match>limit:
break
j+=1
if match3>limit:
break
if heatR>heatP and heatR>heatS:
predictor3 = 'R'
elif heatP > heatS:
predictor3 = 'P'
else:
predictor3 = 'S'
#Predictor 4: assume that the opponent plays like a Boltzmann Compressor
matchHistory+=loutput
bcindex = 0
bclimit = 50
bcheatR = bcheatP = bcheatS = 0
while bcindex < len(matchHistory)-2:
bcindex2=bcindex
bcindex3=len(matchHistory)-2
bclength = 0
while bcindex2 >=0:
if matchHistory[bcindex2]!=matchHistory[bcindex3] or matchHistory[bcindex2+1]!=matchHistory[bcindex3+1]:
break
bcindex2-=2
bcindex3-=2
bclength+=1
if bclength>bclimit:
break
bcpredict=matchHistory[bcindex+3]
bcenergy = math.pow(bclength+1,math.log(bclength+1)+1)
bcheatR+={'R':0,'P':-bcenergy,'S':bcenergy}[bcpredict]
bcheatP+={'R':bcenergy,'P':0,'S':-bcenergy}[bcpredict]
bcheatS+={'R':-bcenergy,'P':bcenergy,'S':0}[bcpredict]
bcindex+=2
if bcheatR>bcheatP and bcheatR>bcheatS:
predictor4 = 'R'
elif bcheatP>bcheatS:
predictor4 = 'P'
else:
predictor4 = 'S'
#compare predictors
if predictor1score>predictor2score and predictor1score>predictor3score and predictor1score>predictor4score:
output = predictor1
elif predictor2score>predictor3score and predictor2score>predictor4score:
output = predictor2
elif predictor3score>predictor4score:
output = predictor3
else:
output = predictor4
output = {'R':'P', 'P':'S', 'S':'R'}[output]
mymoves+=output
oldpredictor1=predictor1
oldpredictor2=predictor2
oldpredictor3=predictor3
oldpredictor4=predictor4
loutput=output
matchHistory+=predictor4