mytest1

Authorswaggymcflash
Submission date2018-06-12 22:48:48.008870
Rating2611
Matches played295
Win rate22.71

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

Source code:

# Strategy:
# Use KT mixture to make sequential predictions.

if input == "":
    import random, collections, math
    
    def argmax(lst):
        return lst.index(max(lst))
    
    # Make prediction based on probability distribution defined by:
    # probs = [p1, p2, p3] = [prob(Rock), prob(Paper), prob(Scissors)]
    def get_pred(probs):
        # if one probability dominates others, choose that one
        # ex. [0.1, 0.1, 0.8] -> just pick 3 (scissors)
        thresh = 0.5
        if max(probs) > thresh:
            return argmax(probs)
        
        roll = random.random()
        if roll <= probs[0]:
            return 0 # rock
        elif roll <= probs[0] + probs[1]:
            return 1 # paper
        else:
            return 2 #scissors
    
    alpha = 1/2 # KT
#     alpha = 1   # Laplace
    cnts = [alpha] * 3
    dct = {"R": 0, "P":1, "S":2}
    lst = ["R", "P", "S"]
    
    
    output = random.choice(["R", "P", "S"])

else:
    cnts[dct[input]] += 1
#     output = lst[(argmax(cnts) + 1) % 3]
    probs = [x/sum(cnts) for x in cnts]    
    output = lst[(get_pred(probs) + 1) % 3]