Rating Decay V2

AuthorPatrick
Submission date2013-12-04 22:16:30.923171
Rating6557
Matches played617
Win rate63.7

Use rpsrunner.py to play unranked matches on your computer.

Source code:

# 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
   
    #increase the rating of the overall top used value
    if rCtr > sCtr and rCtr > pCtr :
        rRate += 0.025
    elif pCtr < rCtr and pCtr < sCtr :
        pRate += 0.025
    elif sCtr < rCtr and sCtr < pCtr :
        sRate += 0.025

    # 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.025
            sRate -= 0.025
        elif next == encoding['P'] :
            sRate += 0.025
            rRate -= 0.025
        elif next == encoding['S'] :
            rRate += 0.025
            pRate -= 0.025

    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"