Author | 0dkt3958vv8n4279 |
Submission date | 2014-10-11 08:40:12.872594 |
Rating | 4177 |
Matches played | 584 |
Win rate | 46.06 |
Use rpsrunner.py to play unranked matches on your computer.
#!/bin/python
from pprint import pprint
from operator import itemgetter
from random import choice
input = ""
if not len(input):
n_back = 3
moves = ""
#moves = "PRSSPRPSPRPSPRPSPRPRPSRPSRPSRP"
moves += input
move_hash = {}
for i in range(len(moves)):
cur = moves[i:i+n_back]
if len(cur) < n_back: continue
nxt = moves[i+n_back:i+n_back+1]
if not len(nxt): continue
# print cur, nxt
if not move_hash.has_key(cur):
move_hash[cur] = {}
if not move_hash[cur].has_key(nxt):
move_hash[cur][nxt] = 0
else:
move_hash[cur][nxt] += 1
# pprint(move_hash)
if len(input) and len(input) >= n_back:
d = move_hash[moves[-n_back:]]
prediction = sorted(d.items(), key=itemgetter(1))
if prediction == "P": output = "S"
elif prediction == "R": output = "P"
elif prediction == "S": output = "R"
else:
output = choice(["R","P","S"])
moves = moves[-(n_back+1):]