xsccssv

Authorcadcdcc
Submission date2019-06-21 14:54:50.577774
Rating6190
Matches played200
Win rate61.0

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

Source code:

import random

lastmatch=0

if not input:
	urmoves=""
	mymoves=""
	predictor1='R'
	predictor2='P'
	blloutput=bloutput=output=random.choice(['R','P','S'])
	predictor1score=0.5
	predictor2score=0.2
else:
	if input==oldpredictor1:
		predictor1score+=0.1
	elif input=={'R':'P', 'P':'S', 'S':'R'}[oldpredictor1]:
		predictor1score-=0.1
	if input==oldpredictor2:
		predictor2score+=0.1
	elif input=={'R':'P', 'P':'S', 'S':'R'}[oldpredictor2]:
		predictor2score-=0.1
		
	#Predictor 1
	predictor1 = random.choice(['R','P','S'])
	urmoves+=input
	for i in range(len(urmoves)-1,20,-1):
		match=0
		j=1
		while mymoves[i-j]==mymoves[len(urmoves)-j]:
			match+=1
			if match>lastmatch:
				lastmatch=match
				predictor1=urmoves[i]
			if match>20:
				break
			j+=1
		if match>20:
			break
			
	#Predictor 2
	blloutput = bloutput
	bloutput = input
	if loutput == {'R':'P','P':'S','S':'R'}[blloutput]:
		predictor2 = {'R':'R','P':'P','S':'S'}[bloutput]
	elif loutput == {'R':'S','P':'R','S':'P'}[blloutput]:
		predictor2 = {'R':'P','P':'S','S':'R'}[bloutput]
	elif loutput == {'R':'R','P':'P','S':'S'}[blloutput]:
		predictor2 = {'R':'S','P':'R','S':'P'}[bloutput]
	
	predictor2 = {'P':'R', 'S':'P', 'R':'S'}[predictor2]
	#compare predictors
	if predictor1score>predictor2score:
		output=predictor1
	elif predictor2score>predictor1score:
		output=predictor2
	else:
		output=random.choice([predictor1,predictor2])
	
	output =  {'R':'P', 'P':'S', 'S':'R'}[output]

mymoves+=output
oldpredictor1=predictor1
oldpredictor2=predictor2
loutput=output