Trash Compactor

This program has been disqualified.


AuthorEbTech
Submission date2011-05-23 17:58:30.154456
Rating7257
Matches played4625
Win rate74.01

Source code:

import math
import random

if input == "":
	matchHistory = ""
	candidate = ['P','P','P','P','P','P','P']
	score = [0,0,0,0,0,0,0]
else:
	matchHistory += input
	for i in range(0, 6):
		score[i] *= 0.95
		score[i] += (4 + {'R':0,'P':1,'S':2}[candidate[i]] - {'R':0,'P':1,'S':2}[input])%3 - 1
	
candidate[0] = random.choice(['R','P','S'])
candidate[1] = random.choice(['R','P','S'])
candidate[4] = random.choice(['R','P','S'])
index = 0
limit = 50
longestMatch = 0

while index < len(matchHistory)-2:
	index2 = index
	index3 = len(matchHistory)-2
	length = 0
	while index2 >= 0:
		if matchHistory[index2] != matchHistory[index3] or matchHistory[index2+1] != matchHistory[index3+1]:
			break
		index2 -= 2
		index3 -= 2
		length += 1
		if length > limit:
			break
	if length > longestMatch:
		longestMatch = length
		candidate[1] = matchHistory[index+3]
		candidate[4] = matchHistory[index+2]
	if length > limit:
		break
	index += 2

for i in [2,3,5,6]:
	candidate[i] = {'R':'S','P':'R','S':'P'}[candidate[i-1]]

best = 0
output = candidate[0]
for i in range(1, 6):
	if (score[i] > score[best]):
		best = i
		output = candidate[i]
matchHistory += output