Author | Patrick |
Submission date | 2013-12-05 17:56:31.517489 |
Rating | 6004 |
Matches played | 619 |
Win rate | 59.94 |
Use rpsrunner.py to play unranked matches on your computer.
# Rating Decay Bot
# Uses ranking derived from current input, overall variable counts, and pattern recognition
# Ratings are decreased 10% per iteration, so current ratings have more weight than older ratings.
# 12/4/2013
#
import random
import math
buffer_Length = 8
if not input:
# Initilization
beat = {'R':'P','P':'S','S':'R'}
encoding = { 'R': 0, 'P' : 1, 'S' : 2}
rCtr = pCtr = sCtr = rLast = pLast = sLast = 0
rRate = pRate= sRate = 0
oppHistory = ""
histBuffer = ""
searcher = ""
output=random.choice(['R','P','S'])
else :
#record current input
oppHistory += str(encoding[input])
rRate *= .9
pRate *= .9
sRate *= .9
#update ratings based on input
if input == "R":
rCtr += 1
rLast = 0
pLast += 1
sLast += 1
pRate += 0.05
sRate -= 0.05
elif input == "P":
pCtr += 1
rLast += 1
pLast = 0
sLast += 1
sRate += 0.05
rRate -= 0.05
elif input == "S":
sCtr += 1
rLast += 1
pLast += 1
sLast = 0
rRate += 0.05
pRate -= 0.05
# check for same pattern in history
histBuffer += str(encoding[input])
if len(histBuffer)> buffer_Length :
histBuffer = histBuffer[1:]
idx = oppHistory.rfind(histBuffer, 0, -1)
if idx != -1 :
#pattern found so improve rating of RPS that would beat most likely to come next
next = oppHistory[idx + 1]
if next == encoding['R'] :
pRate += 0.05
sRate -= 0.05
elif next == encoding['P'] :
sRate += 0.05
rRate -= 0.05
elif next == encoding['S'] :
rRate += 0.05
pRate -= 0.05
expRock = math.exp(rRate)
expScissors = math.exp(sRate)
expPaper = math.exp(pRate)
#Determing the next move to be played from rankings
Rating = random.random()* (expRock + expScissors + expPaper)
if Rating < expRock:
output = "R"
elif Rating < (expRock + expPaper):
output = "P"
else:
output = "S"