ppm1

AuthorEppie
Submission date2020-02-01 18:17:09.123750
Rating3889
Matches played207
Win rate39.61

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

Source code:

import random

moves = ['R', 'P', 'S']
counters = {'R': 'P', 'P': 'S', 'S': 'R'}
max_context = 5

if not input:
    history = []
    output = random.choice(moves)
else:
    history.append(input)
    counts = {'R': 0, 'P': 0, 'S': 0}
    max_context_len = min(len(history) - 1, max_context)
    for context_len in range(max_context_len, 0, -1):
        current_context = history[-context_len:]
        for i in range(len(history) - context_len - 1):
            if current_context == history[i:i+context_len]:
                n = history[i+context_len+1]
                counts[n] += 1
    v, k = max((v, k) for k, v in counts.items())
    output = counters[k]