ppm2

AuthorEppie
Submission date2020-02-01 18:30:21.238172
Rating3764
Matches played201
Win rate34.33

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 = 6

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]