Author | dedekind |
Submission date | 2019-10-14 01:07:44.126245 |
Rating | 5673 |
Matches played | 225 |
Win rate | 54.67 |
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
opponentPicksWeights = [0,0,0]
pickWeights = [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:
opponentPicksWeights[i] = (pick/float(totalOpPicks))
i += 1
pickWeights[0] = opponentPicksWeights[2]
pickWeights[1] = opponentPicksWeights[0]
pickWeights[2] = opponentPicksWeights[1]
choise = weighted_choice_b(pickWeights)
if choise > 2:
choise -= 1
output = picks[choise]