pick_by_winrate_penalty3

AuthorAntiDog
Submission date2018-08-08 13:33:16.088090
Rating4536
Matches played273
Win rate45.05

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

Source code:

import random
#pick_by_winrate
output = ""
if input == "":
	output = "P"
	oponentmoves = ""
	wins = {}
	lastIn = ""
	lastOut= ""
else:
	def beats(x,y):
		if x == "R" and y == "S": return True
		if x == "P" and y == "R": return True
		if x == "S" and y == "P": return True
		return False

	best_wr = 0
	best_output = random.choice(["R","P","S"])
	if lastIn != "" and lastOut != "":
		id = ""+lastIn+lastOut
		if beats(lastOut, lastIn):
			if id in wins:
				wins[id] = wins[id] + 1
			else:
				wins[id] = 1.0
		elif beats(lastIn, lastOut):
			if id in wins:
				wins[id] = wins[id] - 1
			else:
				wins[id] = -1.0
		for w in wins:
			if len(w) < 2:
				wins.pop(w, None)
				continue
			if w[0] == input and wins[w] > best_wr:
				best_wr = wins[w]
				best_output = w[1]
	output = best_output
	lastIn = input
lastOut = output