_proto but maybe better

Authorq.q
Submission date2018-03-08 23:38:33.950460
Rating3703
Matches played245
Win rate37.14

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

Source code:

import random

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
    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[:-2]: # process 2 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
        else:
            _ = amts.index(max(amts))
            if _ == 0:
                rw += .3
            elif _ == 1:
                pw += .3
            else:
                sw += .3
    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]