RPS Random weighted

AuthorAntiDog
Submission date2018-08-08 10:06:54.752700
Rating3889
Matches played269
Win rate36.43

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

Source code:

import random
if input == "":
	output = "P"
	oponentmoves = ""
else:
	oponentmoves += input
	if(len(oponentmoves) > 75):
		oponentmoves = oponentmoves[:75]
	r = 0.0
	p = 0.0
	s = 0.0
	for i in range(1,len(oponentmoves)):
		searchsequence = oponentmoves[len(oponentmoves)-i:]
		nextresults = oponentmoves.split(searchsequence)
		k = 0
		weight = 1.0
		for res in nextresults:
			n = 1
			k+=1
			weight = 1#(len(oponentmoves)+1)/float(len(res)+1)
			if k == 1:
				continue
			if res == "": 
				res = searchsequence
				n = len(",".join(oponentmoves.split(searchsequence)[1:]))
			if res[0] == "R":
				r += n *weight
			elif res[0] == "P":
				p += n *weight
			elif res[0] == "S":
				s += n *weight
			else:
				continue
	if r >= p and r >= s:
		output = "P"
	elif p >= s and p >= r:
		output = "S"
	else:
		output = "R" 
	if random.randint(1,50) == 33:
		output = "R"
	if random.randint(1,50) == 34:
		output = "S"
	if random.randint(1,50) == 32:
		output = "P"