Author | moreda |
Submission date | 2019-07-15 14:34:28.363261 |
Rating | 5220 |
Matches played | 225 |
Win rate | 52.89 |
Use rpsrunner.py to play unranked matches on your computer.
import random
if not input:
actions = ["R", "P", "S"]
map = {"R":0, "P":1, "S":2}
beat = {"R":"P", "P":"S", "S":"R"}
history = [[[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]], [[0, 0, 0], [0, 0, 0], [0, 0, 0]]]
output = random.choice(actions)
n = 1
last_action = output
last_opponent = ""
last_last_action = ""
last_last_opponent = ""
else:
n += 1
if n<=2:
output = random.choice(actions)
last_last_action = last_action
last_action = output
last_opponent = input
else:
last_last_opponent = last_opponent
last_opponent = input
history[map[last_last_opponent]][map[last_opponent]][map[last_last_action]] += 1
ans = [history[map[last_opponent]][0][map[last_action]], history[map[last_opponent]][1][map[last_action]], history[map[last_opponent]][2][map[last_action]]]
ans = 0 if ans[2]<ans[0]>ans[1] else( 1 if ans[2]<ans[1]>ans[0] else 2)
last_last_action = last_action
output = beat[actions[ans]]
last_action = output