Author | nk! |
Submission date | 2017-12-14 18:40:49.681480 |
Rating | 5164 |
Matches played | 309 |
Win rate | 50.49 |
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+4]==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"])