pick_by_winrate_penalty2

AuthorAntiDog
Submission date2018-08-08 13:20:00.480740
Rating4797
Matches played281
Win rate46.26

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

Source code:

import random
#pick_by_winrate
output = ""
if input == "":
	output = "P"
	oponentmoves = ""
	lastIn = "P"

	input = "s"
	wins = {}
else:
	def beats(x,y):
		if x == "R":
			if y == "S": return True
		if x == "P":
			if y == "R": return True
		if x == "S":
			if y == "P": return True
		return False
	if lastIn != "" and lastOut != "":
		if beats(lastOut, lastIn):
			id = ""+lastIn+lastOut
			if id in wins:
				wins[id] = wins[id] + 1
			else:
				wins[id] = 1
		if beats(lastIn, lastOut):
			id = ""+lastIn+lastOut
			if id in wins:
				wins[id] = wins[id] - 1
			else:
				wins[id] = -1
		best_wr = 0
		best_output = random.choice(["R","P","S"])
		for w in wins:
			if len(w) < 2:
				continue
			if w[0] == input and wins[w] > best_wr:
				best_wr = wins[w]
				best_output = w[1]
		output = best_output
		print lastIn, lastOut, input, best_output, best_wr
lastIn = input
lastOut = output