Author | Eppie |
Submission date | 2020-02-01 19:11:56.311971 |
Rating | 5048 |
Matches played | 204 |
Win rate | 52.45 |
Use rpsrunner.py to play unranked matches on your computer.
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
if counts['R'] != 0 or counts['P'] != 0 or counts['S'] != 0:
break
v, k = max((v, k) for k, v in counts.items())
output = counters[k]