Author | mad |
Submission date | 2017-03-24 14:46:26.318793 |
Rating | 3461 |
Matches played | 386 |
Win rate | 34.2 |
Use rpsrunner.py to play unranked matches on your computer.
import math
import random
if input == "": # initialize variables for the first round
totalCntr = 1.0
rewardR = rewardP = rewardS = 0.0
rockOutCntr = paperOutCntr = scissorsOutCntr = 1.0
else:
totalCntr += 1
if ((input == "R") and (output == "R")):
rewardR += 0.5
elif ((input == "P") and (output == "P")):
rewardP += 0.5
elif ((input == "S") and (output == "S")):
rewardS += 0.5
elif ((input == "R") and (output == "P")):
rewardP += 1.0
elif ((input == "P") and (output == "S")):
rewardS += 1.0
elif ((input == "S") and (output == "R")):
rewardR += 1.0
xR = rewardR / totalCntr
xP = rewardP / totalCntr
xS = rewardS / totalCntr
ucbR = xR + math.sqrt(2 * math.log(totalCntr) / rockOutCntr)
ucbP = xP + math.sqrt(2 * math.log(totalCntr) / paperOutCntr)
ucbS = xS + math.sqrt(2 * math.log(totalCntr) / scissorsOutCntr)
ucblist = [ucbR, ucbP, ucbS]
maxv = float("-inf")
chlist = []
for i in range(3):
if (ucblist[i] > maxv):
maxv = ucblist[i]
chlist = [i]
elif (ucblist[i] == maxv):
chlist.append(i)
outval = random.choice(chlist);
if (outval == 0):
output = "R"
rockOutCntr += 1.0
elif (outval == 1):
output = "P"
paperOutCntr += 1.0
else:
output = "S"
scissorsOutCntr += 1.0