Author | izzy |
Submission date | 2017-12-07 22:35:17.958180 |
Rating | 2606 |
Matches played | 314 |
Win rate | 22.93 |
Use rpsrunner.py to play unranked matches on your computer.
import random
# comment this out when submitting
#moves = "PPPSSSSRR"
#input = "P"
if input=="":
moves=""
def count_substring(str,sub):
count_substring=0
for i in range(len(str)):
if str[0:len(sub)]==sub:
count_substring+=1
return count_substring
def predictPatterns():
rockCount=0
paperCount=0
scissorsCount=0
last4=moves[-4:]
last3=moves[-3:]
last2=moves[-2:]
# weight longer patterns more than shorter patterns, we did this by multiplyng by 5
rockCount=count_substring(moves, last4+"R") * 5 + count_substring(moves, last3+"R") * 3 + count_substring(moves, last2+"R")
scissorsCount=count_substring(moves, last4+"S") * 5 + count_substring(moves, last3+"S") * 3 + count_substring(moves, last2+"S")
paperCount=count_substring(moves, last4+"P") * 5 + count_substring(moves, last3+"P") * 3 + count_substring(moves, last2+"P")
# find the most likely outcome in order to counter it
if rockCount > scissorsCount and rockCount > paperCount:
output = "P"
elif scissorsCount > rockCount and scissorsCount > paperCount:
output = "R"
elif paperCount > rockCount and paperCount > scissorsCount:
output = "S"
else:
output = random.choice(["R", "S", "P"])
return output
moves=moves+input
# Pick random moves until we've seen enough to make predictions
if len(moves) < 50:
output = random.choice(["R", "S", "P"])
else:
predictPatterns()
# comment this when submitting
#print(output)