This program has been disqualified.
Author | dllu |
Submission date | 2011-05-23 07:34:15.390317 |
Rating | 8333 |
Matches played | 132 |
Win rate | 83.33 |
import random
import math
lastmatch=0
lastmatch3=0
limit = 30
if not input:
urmoves=""
mymoves=""
predictor1=random.choice(['R','P','S'])
predictor2=random.choice(['R','P','S'])
predictor3=random.choice(['R','P','S'])
predictor4=random.choice(['R','P','S'])
predictor5=random.choice(['R','P','S'])
predictor6=random.choice(['R','P','S'])
blloutput=bloutput=output=random.choice(['R','P','S'])
predictor1score=1.1
predictor2score=0.1
predictor3score=0.7
predictor4score=0.4
predictor5score=0.4
predictor6score=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
if input==oldpredictor5:
predictor5score+=0.1
elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor5]:
predictor5score-=0.1
if input==oldpredictor6:
predictor6score+=0.1
elif input=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor6]:
predictor6score-=0.1
predictor1score*=0.8
predictor2score*=0.8
predictor3score*=0.8
predictor4score*=0.8
predictor5score*=0.8
predictor6score*=0.8
#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]
predictor6=mymoves[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
predictor3=urmoves[i]
predictor5=mymoves[i]
if match>limit:
break
j+=1
if match3>limit:
break
#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'
#Predictor 5: assume that the opponent tries to beat Predictor 1
predictor5={'R':'P', 'P':'S', 'S':'R'}[predictor5]
#Predictor 6: assume that the opponent tries to beat Predictor 3
predictor6={'R':'P', 'P':'S', 'S':'R'}[predictor6]
#compare predictors
if predictor1score>predictor2score and predictor1score>predictor3score and predictor1score>predictor4score and predictor1score>predictor5score and predictor1score>predictor6score:
output = predictor1
elif predictor2score>predictor3score and predictor2score>predictor4score and predictor2score>predictor5score and predictor2score>predictor6score:
output = predictor2
elif predictor3score>predictor4score and predictor3score>predictor5score and predictor3score>predictor6score:
output = predictor3
elif predictor4score>predictor5score and predictor4score>predictor6score:
output = predictor4
elif predictor5score>predictor6score:
output = predictor5
else:
output = predictor6
output = {'R':'P','P':'S','S':'R'}[output] #attempt to win
#output = {'R':'S','P':'R','S':'P'}[output] #attempt to lose
if predictor1score<0 and predictor2score<0 and predictor3score<0 and predictor4score<0 and predictor5score<0 and predictor6score<0:
output=random.choice(['R','P','S'])
mymoves+=output
oldpredictor1=predictor1
oldpredictor2=predictor2
oldpredictor3=predictor3
oldpredictor4=predictor4
oldpredictor5=predictor5
oldpredictor6=predictor6
loutput=output
matchHistory+=predictor4