This program has been disqualified.
Author | EbTech |
Submission date | 2011-05-23 16:56:11.610225 |
Rating | 6952 |
Matches played | 105 |
Win rate | 69.52 |
import random
import math
lastmatch =0
lastmatch1=0
lastmatch3=0
limit = 30
import math
if not input:
urmoves=""
mymoves=""
predictorSOL=random.choice(['R','P','S'])
predictor0=random.choice(['R','P','S'])
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'])
predictorSOLscore=0.6
predictor0score=1.2
predictor1score=0.95
predictor2score=0.1
predictor3score=0.7
predictor4score=0.4
predictor5score=0.4
predictor6score=0.4
matchHistory=""
SOLmatchHistory = ""
else:
SOLmatchHistory += input
mymoves += input
loutput = input
if fakeinput==oldpredictorSOL:
predictorSOLscore+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictorSOL]:
predictorSOLscore-=0.1
if fakeinput==oldpredictor0:
predictor0score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor0]:
predictor0score-=0.1
if fakeinput==oldpredictor1:
predictor1score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor1]:
predictor1score-=0.1
if fakeinput==oldpredictor2:
predictor2score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor2]:
predictor2score-=0.1
if fakeinput==oldpredictor3:
predictor3score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor3]:
predictor3score-=0.1
if fakeinput==oldpredictor4:
predictor4score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor4]:
predictor4score-=0.1
if fakeinput==oldpredictor5:
predictor5score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor5]:
predictor5score-=0.1
if fakeinput==oldpredictor6:
predictor6score+=0.1
elif fakeinput=={'R':'S', 'P':'R', 'S':'P'}[oldpredictor6]:
predictor6score-=0.1
predictorSOLscore*=0.84
predictor0score*=0.84
predictor1score*=0.84
predictor2score*=0.84
predictor3score*=0.84
predictor4score*=0.84
predictor5score*=0.84
predictor6score*=0.84
#Predictor 0: assume that if opponent and I play the same sequence of moves, opponent will reply the same
predictor0 = random.choice(['R','P','S'])
urmoves+=fakeinput
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] and urmoves[i-j]==urmoves[len(urmoves)-j]:
match+=1
if match>lastmatch:
lastmatch=match
predictor0=urmoves[i]
if match>limit:
break
j+=1
if match>limit:
break
#Predictor 1: assume that if I play the same sequence of moves, the opponent will reply the same
predictor1 = random.choice(['R','P','S'])
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>lastmatch1:
lastmatch1=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 = fakeinput
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]
index = 0
limit = 50
heatR = heatP = heatS = 0
while index < len(SOLmatchHistory)-2:
index2 = index
index3 = len(SOLmatchHistory)-2
length = 0
while index2 >= 0:
if SOLmatchHistory[index2] != SOLmatchHistory[index3] or SOLmatchHistory[index2+1] != SOLmatchHistory[index3+1]:
break
index2 -= 2
index3 -= 2
length += 1
if length > limit:
break
predict = SOLmatchHistory[index+3]
energy = math.pow(length+1, math.log(length+1)+1)
if predict == 'R':
heatP += energy
heatS -= energy
elif predict == 'P':
heatS += energy
heatR -= energy
else:
heatR += energy
heatP -= energy
index += 2
if heatR > heatP and heatR > heatS:
predictorSOL = "S"
elif heatP > heatS:
predictorSOL = "R"
else:
predictorSOL = "P"
#compare predictors
if predictorSOLscore>predictor0score and predictorSOLscore>predictor1score and predictorSOLscore>predictor2score and predictorSOLscore>predictor3score and predictorSOLscore>predictor4score and predictorSOLscore>predictor5score and predictorSOLscore>predictor6score:
output = predictorSOL
if predictor0score>predictor1score and predictor0score>predictor2score and predictor0score>predictor3score and predictor0score>predictor4score and predictor0score>predictor5score and predictor0score>predictor6score:
output = predictor0
elif 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
if predictorSOLscore<0 and predictor1score<0 and predictor2score<0 and predictor3score<0 and predictor4score<0 and predictor5score<0 and predictor6score<0:
output=random.choice(['R','P','S'])
oldpredictorSOL=predictorSOL
oldpredictor0=predictor0
oldpredictor1=predictor1
oldpredictor2=predictor2
oldpredictor3=predictor3
oldpredictor4=predictor4
oldpredictor5=predictor5
oldpredictor6=predictor6
matchHistory+=predictor4
output = {'R':'P','P':'S','S':'R'}[output]
SOLmatchHistory += output
fakeinput = output