Author | Great Driver |
Submission date | 2014-12-15 18:19:25.594790 |
Rating | 6690 |
Matches played | 532 |
Win rate | 70.86 |
Use rpsrunner.py to play unranked matches on your computer.
# state = recent history
# hist[state substring] = opponent most recent response
# use longest substring present in hist to build next throw
import random
if input == "":
hist={}
last=""
ply=10
minlen=3
beats = {"R": "P", "P": "S", "S": "R"}
else:
# record ONLY THIS RESPONSE in hist[state substring]
for i in range(minlen, len(last)+1):
hist[last[:i]] = input
# update state
last=output+input+last
if len(last) > ply:
last=last[:ply]
# look for state in history, play accordingly
try:
max_seen = last[:max(i for i in range(minlen,len(last)+1) if last[:i] in hist)]
output = beats[hist[max_seen]]
except: # none seen
output = random.choice("RPS")