Author | Great Driver |
Submission date | 2014-12-15 01:34:57.901456 |
Rating | 6986 |
Matches played | 551 |
Win rate | 69.69 |
Use rpsrunner.py to play unranked matches on your computer.
# state = last [depth]-turn sequence, both players' moves
# if we've seen state before, throw to beat weighted-avg opponent throw
# else random
import random
if input == "": # initialize
hist={}
last=""
output=""
depth=5
# record state for last play + opponent response
if (len(last) == 2*depth):
if (last not in hist):
hist[last] = ""
hist[last]+=input
# update state
last+=output+input
if len(last) > 2*depth:
last=last[2:]
# look for state in history, play accordingly
if last in hist:
beats = {"R": "P", "P": "S", "S": "R"}
output = beats[random.choice(hist[last])]
else:
output = random.choice("RPS")