dalek test 16

Authornk!
Submission date2017-12-14 18:50:23.872020
Rating6163
Matches played322
Win rate59.94

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

Source code:

#RPS Contest Project

#1 output start with random until certain number of list data
#2 function that will make a list of opponent's moves
#3 use list to predict next move based on frequency/patterns
#4 output based on 

import random

user = input

#opponentMoves = ["R","P","R","S"]



def count_substring(opponentMoves, last4):
    count = 0
    for i in range(len(opponentMoves)):
        count += opponentMoves[i:i+5]==last4
    return count

if user == "":
    opponentMoves = []
    #opponentMoves.append("")
elif user == "R":
    opponentMoves.append("R")
elif user == "P":
    opponentMoves.append("P")
elif user == "S":
    opponentMoves.append("S")

last4 = opponentMoves[-4:]

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