Author | hannah |
Submission date | 2017-12-14 15:20:27.448150 |
Rating | 2022 |
Matches played | 318 |
Win rate | 17.61 |
Use rpsrunner.py to play unranked matches on your computer.
if input == "": # initialize variables for the first round
totalCount = rockCount = paperCount = scissorsCount = 0
moves = ""
elif input == "R":
totalCount += 1
moves = moves + "R"
elif input == "P":
totalCount += 1
moves = moves + "P"
elif input == "S":
totalCount += 1
moves += "S"
if len(moves) > 4:
lastChars = moves[-4:]
else:
lastChars = ""
def count_substring(STR, SUB):
n = len(SUB) # SUB is lastChars + R, S, or P
if len(STR) < n:
return 0
occurCount = 0
lastPosition = n-1
firstPosition = 0
occurCount = 0
while lastPosition < totalCount:
lastPosition += 1
firstPosition += 1
if SUB == STR[firstPosition:lastPosition]:
occurCount += 1
return occurCount
rockCount = count_substring(moves, lastChars+"R")
paperCount = count_substring(moves, lastChars+"P")
scissorsCount = count_substring(moves, lastChars+"S")
if rockCount > paperCount and rockCount > scissorsCount:
output = "P" # paper beats rock
elif paperCount >= scissorsCount and paperCount >= scissorsCount:
output = "S" # scissors beats paper
else:
output = "R" # rock beats scissors