Author | nk! |
Submission date | 2017-12-14 18:43:32.507510 |
Rating | 4512 |
Matches played | 319 |
Win rate | 45.45 |
Use rpsrunner.py to play unranked matches on your computer.
import random
user = input
opponentMoves = ["R","P","R","S","P","S"]
last4 = opponentMoves[-4:]
def count_substring(opponentMoves, last4):
count = 0
for i in range(len(opponentMoves)):
count += opponentMoves[i:i+5]==last4
return count
if user == "":
opponentMoves.append("")
elif user == "R":
opponentMoves.append("R")
elif user == "P":
opponentMoves.append("P")
elif user == "S":
opponentMoves.append("S")
countR = count_substring(opponentMoves, last4 + ["R"])
countP = count_substring(opponentMoves, last4 + ["P"])
countS = count_substring(opponentMoves, last4 + ["S"])
if countR>countP and countP>countS:
output = "P"
elif countP>countR and countR>countS:
output = "S"
elif countS>countP and countP>countR:
output = "R"
else: #countS == countP == countR:
output = random.choice(["R","P","S"])