Author | tomos |
Submission date | 2018-04-18 19:54:58.345690 |
Rating | 5832 |
Matches played | 305 |
Win rate | 54.75 |
Use rpsrunner.py to play unranked matches on your computer.
if input == "":
import random
outs = ["R", "P", "S"]
c_hist = []
p_hist = []
w_count = 0
t_count = 0
l_count = 0
rps_map = {("R", "R"): {"R": 0, "P": 0, "S": 0},
("R", "P"): {"R": 0, "P": 0, "S": 0},
("R", "S"): {"R": 0, "P": 0, "S": 0},
("P", "R"): {"R": 0, "P": 0, "S": 0},
("P", "P"): {"R": 0, "P": 0, "S": 0},
("P", "S"): {"R": 0, "P": 0, "S": 0},
("S", "R"): {"R": 0, "P": 0, "S": 0},
("S", "P"): {"R": 0, "P": 0, "S": 0},
("S", "S"): {"R": 0, "P": 0, "S": 0}
}
def best(last_pair):
if (l_count - w_count) >= 10:
return outs[random.randint(0,2)]
if rps_map[last_pair]["R"] > rps_map[last_pair]["P"] and rps_map[last_pair]["R"] > rps_map[last_pair]["S"]:
return "P" # paper beats rock
elif rps_map[last_pair]["P"] > rps_map[last_pair]["R"] and rps_map[last_pair]["P"] > rps_map[last_pair]["S"]:
return "S" # scissors beats paper
elif rps_map[last_pair]["S"] > rps_map[last_pair]["R"] and rps_map[last_pair]["S"] > rps_map[last_pair]["P"]:
return "R" # rock beats scissors
else:
return outs[random.randint(0,2)] # Not enough data, make a random guess
# end def best
def beats(c, p):
global w_count, t_count, l_count
if c == p:
t_count += 1
elif c == "R" and p == "R":
t_count += 1
elif c == "R" and p == "P":
l_count += 1
elif c == "R" and p == "S":
w_count += 1
elif c == "P" and p == "R":
w_count += 1
elif c == "P" and p == "P":
t_count += 1
elif c == "P" and p == "S":
l_count += 1
elif c == "S" and p == "R":
l_count += 1
elif c == "S" and p == "P":
w_count += 1
elif c == "S" and p == "S":
t_count += 1
# end def beats
last_c = None
last_p = None
output = outs[random.randint(0,2)]
else:
c_hist.append(output)
p_hist.append(input)
beats(output, input)
if last_c is not None:
rps_map[(last_c, last_p)][input] += 1
output = best((output, input))
else:
output = outs[random.randint(0,2)]
last_c = output
last_p = input