v6_bhyung_randinject

Authorbhyung
Submission date2018-08-27 02:33:18.994426
Rating5138
Matches played289
Win rate51.9

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

Source code:

import random
r = "R"
p = "P"
s = "S"
mem = []

if len(mem) < 2:
    output = random.choice([r,p,s])
    if input != "":
        mem.insert(0,input)
else:
    mem.insert(0,input)
    rr = rp = rs = pr = pp = ps = sr = sp = ss = 0
    for i in range(len(mem)-1):
        inject = random.random(0.0,1.0)
        if mem[i] == r and mem[i+1] == r:
            rr += 1 + inject
        elif mem[i] == r and mem[i+1] == p:
            rp += 1 + inject
        elif mem[i] == r and mem[i+1] == s:
            rs += 1 + inject
        elif mem[i] == p and mem[i+1] == r:
            pr += 1 + inject
        elif mem[i] == p and mem[i+1] == p:
            pp += 1 + inject
        elif mem[i] == p and mem[i+1] == s:
            ps += 1 + inject
        elif mem[i] == s and mem[i+1] == r:
            sr += 1 + inject
        elif mem[i] == s and mem[i+1] == p:
            sp += 1 + inject
        elif mem[i] == s and mem[i+1] == s:
            ss += 1 + inject
    
    # inject randomness(?)
    rr = rr/len(mem)
    rp = rp/len(mem)
    rs = rs/len(mem)
    pr = pr/len(mem)
    pp = pp/len(mem)
    ps = ps/len(mem)
    sr = sr/len(mem)
    sp = sp/len(mem)
    ss = ss/len(mem)

    if input == r:
        if rr > max(rp,rs):
            output = p
        elif rp > rs:
            output = s
        else:
            output = r
    elif input == p:
        if pr > max(pp,ps):
            output = p
        elif pp > ps:
            output = s
        else:
            output = r
    elif input == s:
        if sr > max(sp,ss):
            output = p
        elif sp > ss:
            output = s
        else:
            output = r