Author | dedekind |
Submission date | 2019-10-14 00:41:10.459694 |
Rating | 3535 |
Matches played | 213 |
Win rate | 35.68 |
Use rpsrunner.py to play unranked matches on your computer.
import random
import bisect
def weighted_choice_b(weights):
totals = []
running_total = 0
for w in weights:
running_total += w
totals.append(running_total)
rnd = random.random() * running_total
return bisect.bisect_right(totals, rnd)
if input == "":
opponentPicks = [0,0,0]
totalOpPicks = 0
weights = [0,0,0]
picks = ["R","P","S"]
output = random.choice(picks)
elif (input == "R"):
opponentPicks[0] += 1
elif (input == "P"):
opponentPicks[1] += 1
else:
opponentPicks[2] += 1
totalOpPicks += 1
i = 0
for pick in opponentPicks:
weights[i] = (pick/float(totalOpPicks))
i += 1
choise = weighted_choice_b(weights)
if choise > 2:
choise -= 1
output = picks[choise]