_proto

Authorq.q
Submission date2018-03-08 22:59:14.604210
Rating2744
Matches played259
Win rate27.8

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

Source code:

import random

# instantiate on first round
if input == "":
    moveHistory = []
    random.seed()
    output = random.choice("RPS")
else:
    # instantiate weights
    rw = 0 # rock       \
    pw = 0 # paper       |-> weights
    sw = 0 # scissors   /
    moveHistory.append(input)

    # give a bit of weight to the most common choice(s)
    amts = [0,0,0]
    for i in moveHistory: # process history
        if i == "R":
            amts[0] += 1
        elif i == "P":
            amts[1] += 1
        else:
            amts[2] += 1
    if amts[0] == amts[1] == amts[2]: # TODO golf
        pass
    elif amts[0] == amts[1]:
        rw += .1
        pw += .1
    elif amts[0] == amts[2]:
        rw += .1
        sw += .1
    elif amts[1] == amts[2]:
        pw += .1
        sw += .1
    else:
        _ = amts.index(max(amts))
        if _ == 0:
            rw += .2
        elif _ == 1:
            pw += .2
        else:
            sw += .2

            
    # see if player is hitting the same one a bunch of times and add weight

    streaking = ""
    try: # needs some context first or it'll error
        for i in moveHistory[:-5]: # process 5 recent
            if i == "R":
                amts[0] += 1
            elif i == "P":
                amts[1] += 1
            else:
                amts[2] += 1
        if amts[0] == amts[1] == amts[2]: # TODO golf
            pass
        elif amts[0] == amts[1]:
            rw += .2
            pw += .2
        elif amts[0] == amts[2]:
            rw += .2
            sw += .2
        elif amts[1] == amts[2]:
            pw += .2
            sw += .2
        else:
            _ = amts.index(max(amts))
            if _ == 0:
                rw += .4
            elif _ == 1:
                pw += .4
            else:
                sw += .4
    except:
        pass

    # look at last choice
    if input == "R":
        rw += .1
    elif input == "P":
        pw += .1
    else:
        sw += .1

    # weakness pairs
    matches = {
        "R" : "P",
        "P" : "S",
        "S" : "R"
    }
    # look at weights
    weights = {
        "R" : rw,
        "P" : pw,
        "S" : sw
    }
    stager = max(weights, key=weights.get) # get first max
    for i in weights:
        if stager == weights[i]: # check and see if it's tied
            random.seed()
            stager = random.choice([stager, weights[i]])
            break
    output = matches[stager]