ARST3

AuthorARST
Submission date2017-07-08 06:01:34.337380
Rating6412
Matches played350
Win rate62.29

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

Source code:

if input == "":
    import random
    import collections
    random.seed()

    RPS = ['R', 'P', 'S']
    COUNTERS = {'R':'P', 'P':'S', 'S':'R', '':''}
    inputs = []

    def bestOfThree(alg):
        most_common = collections.Counter((alg(), alg(), alg())).most_common()[0]
        if most_common[1] >= 2:
            return most_common[0]
        else:
            return alg()

    def a1():
        return COUNTERS[random.choice(inputs[-200:])]

    def a2():
        return COUNTERS[random.choice(inputs[-50:])]

    def a3():
        return COUNTERS[random.choice(inputs[-10:])]

    def a4():
        return bestOfThree(a1)

    def a5():
        return bestOfThree(a2)

    def a6():
        return bestOfThree(a3)

    def leftHandScore(left, right):
        if left == COUNTERS[right]:
            return 1
        elif COUNTERS[left] == right:
            return -1
        else:
            return 0

    algs = (a5, a4, a6, a2, a1, a3)
    last_outputs = [''] * len(algs)
    score_lists = [[]] * len(algs)

    output = random.choice(RPS)

else:
    inputs.append(input)

    best_score = -9999
    for i in range(len(algs)):
        score_lists[i].append(leftHandScore(last_outputs[i], input))
        last_outputs[i] = algs[i]()

        recent_score_sum = sum(score_lists[i][-10:])
        if recent_score_sum > best_score:
            best_score = recent_score_sum
            best_index = i

    if len(inputs) < 10 or random.random() < 0.8:
        output = random.choice(RPS)
    else:
        output = last_outputs[best_index]