bb markov except its bad

Authorluis
Submission date2019-04-16 13:23:35.211977
Rating1695
Matches played245
Win rate15.92

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

Source code:

import random
import math

TEMPERATURE = 0.3
RPS = {"R": 0, "P": 1, "S": 2, 0: "R", 1: "P", 2: "S"}

if input == "":
    lastAction = None
    markovChain = [[1.0, 1.0, 1.0] for i in range(3)]
else:
    newAction = RPS[input]
    if lastAction != None:
        markovChain[lastAction][newAction] += 1.0
    lastAction = newAction

def prediction(action):
    count = markovChain[lastAction][action]
    return count / float(sum(markovChain[lastAction]))

choice = 0
if (lastAction == None):
    choice = random.randint(0, 2)
else:
    total = float(sum(markovChain[lastAction]))
    preds = [markovChain[lastAction][i] / total for i in range(3)]
    probs = [math.exp((preds[(i + 1) % 3] - preds[(i - 1) % 3]) / TEMPERATURE) for i in range(3)]
    pick = random.random() * float(sum(probs))
    while (True):
        pick -= probs[choice]
        if (pick <= 0):
            break
        if (choice == 2):
            break
        choice += 1
output = RPS[choice]