Author | moreda |
Submission date | 2019-07-17 11:52:06.267944 |
Rating | 5531 |
Matches played | 234 |
Win rate | 57.69 |
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
r=random.randint(0,100)
if 30>=r>=13:
random.choice(actions)
else:
output = beat[actions[ans]]
last_action = output