dalek test 13

Authornk!
Submission date2017-12-14 18:40:49.681480
Rating5164
Matches played309
Win rate50.49

Use rpsrunner.py to play unranked matches on your computer.

Source code:

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"])