Author | nk! |
Submission date | 2017-12-14 19:18:22.475200 |
Rating | 5754 |
Matches played | 317 |
Win rate | 58.36 |
Use rpsrunner.py to play unranked matches on your computer.
#RPS Contest
#K and N
#Final draft:
#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
if user == "":
opponentMoves = []
elif user == "R":
opponentMoves.append("R")
elif user == "P":
opponentMoves.append("P")
elif user == "S":
opponentMoves.append("S")
#This makes a list of the opponent moves.
def count_substring(opponentMoves, last4):
count = 0
for i in range(len(opponentMoves)):
count += opponentMoves[i:i+5]==last4
return count
#This function uses a loop to return the number of times the last4 of opponentMoves
#occurs in opponentMoves as a whole.
last4 = opponentMoves[-4:]
#Defines the last 4 of opponentMoves as last4.
countR = count_substring(opponentMoves, last4 + ["R"])
countP = count_substring(opponentMoves, last4 + ["P"])
countS = count_substring(opponentMoves, last4 + ["S"])
#Makes a count for each move option counting the number of times it occurs after last4.
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:
output = random.choice(["R","P","S"])
#Returns the most frequent move after last4 that appears in opponentMoves.