help v 2

This program has been disqualified.


Authorizzy
Submission date2017-12-08 17:26:09.018770
Rating4891
Matches played105
Win rate51.43

Source code:

import random

# comment this out when submitting
#moves = "PPPSSSSRR"
#input = "P"


if input=="":
	moves=""
	def count_substring(str, sub):
		if len(str)==0:
			return 0
		if str[0:len(sub)]==(sub):
			return 1 + count_substring(str[1:], sub)
		else:
			return 0+count_substring(str[1:], sub)



	def predictPatterns():
		rockCount=0
		paperCount=0
		scissorsCount=0
		last4=moves[-4:]
		last3=moves[-3:]
		last2=moves[-2:]

		# weight longer patterns more than shorter patterns, we did this by multiplyng by 5
		rockCount=count_substring(moves, last4+"R") * 5 + count_substring(moves, last3+"R") * 3 + count_substring(moves, last2+"R") 
		scissorsCount=count_substring(moves, last4+"S") * 5 + count_substring(moves, last3+"S") * 3 + count_substring(moves, last2+"S")
		paperCount=count_substring(moves, last4+"P") * 5 + count_substring(moves, last3+"P") * 3 + count_substring(moves, last2+"P")

	    # find the most likely outcome in order to counter it
		if rockCount > scissorsCount and rockCount > paperCount: 
			output = "P"
		elif scissorsCount > rockCount and scissorsCount > paperCount:
			output = "R"
		elif paperCount > rockCount and paperCount > scissorsCount:
			output = "S"
		else:
			output = random.choice(["R", "S", "P"])

		return output

moves=moves+input

# Pick random moves until we've seen enough to make predictions
if len(moves) > 550:
	output = random.choice(["R", "S", "P"])
else:
	output = predictPatterns()

# comment this when submitting
#print(output)