regexRanking-1

This program has been disqualified.


Authoreakosin
Submission date2014-04-23 16:36:00.726019
Rating5589
Matches played84
Win rate57.14

Source code:

# regexRanking-1
# eakosin
# A rather un-mathematical approach.
# Keeping ranked buffers of past moves and
# an active circular-like buffer.
# Regex match sub-sequences from beginning of
# buffer, taking into account rank of buffer.

import random
import time
import uuid
import re
import math

activeBufferSize = 4
search = [2, activeBufferSize]
staticBufferNumber = (3 ** 5)
staticBufferSize = 5
staticBufferDecay = (3 ** 5)
decayRate = 1


if(input == ""):
	activeBuffer = []
	staticBuffers = [[]]
	bufferDecay = [[0,False]]
	random.seed((int(uuid.uuid1()) * int(uuid.uuid4())) % time.time())
	output = random.choice(['R', 'P', 'S'])
else:
	#Insert in the active buffer up to 3^5 values
	activeBuffer.insert(0,input)
	if(len(activeBuffer) > (3 ** activeBufferSize)):
		activeBuffer.pop()
	
	#Insert into the current static buffer up to 3^6 values
	staticBuffers[0].insert(0, input)
	#Allocate new buffer if size is reached
	if(len(staticBuffers[0]) > (3 ** staticBufferSize)):
		staticBuffers.insert(0, [])
		bufferDecay[0][0] = staticBufferDecay
		bufferDecay.insert(0, [0,False])
	#If number of static buffers exceeds 3^5, remove buffer of smallest decay
	if(len(staticBuffers) > staticBufferNumber):
		smallest = [1, bufferDecay[1][0]]
		for i in range(1,len(bufferDecay)):
			if(smallest[1] > bufferDecay[i][0]):
				smallest = [i, bufferDecay[i][0]]
		staticBuffers.pop(smallest[0])
		
	#Set all buffer tracking to false
	for i in range(len(bufferDecay)):
		bufferDecay[i][1] = False
		
	#Build regex match [0:3^n] characters where n = [1,2,3,4,5]
	regex = []
	for i in range(search[0], search[1] + 1):
		regex.append([re.compile("." + "".join(activeBuffer[0:(3**i)])),(3**i)])
		
	#Iterate through buffers and regex match
	results = []
	# power = int(math.pow(
	for i in range(len(staticBuffers)):
		bufferString = "".join(staticBuffers[i])
		for r in range(len(regex)):
			if(regex[r][1] > len(bufferString)):
				match = regex[r][0].search(bufferString)
				if(match):
					results.append([bufferDecay[i], match.groups(0)[0]])
					bufferDecay[i][0] += (3 ** r)
					bufferDecay[i][1] = True
				else:
					bufferDecay[i][0] -= decayRate
	
	#Process results
	random.seed((int(uuid.uuid1()) + int(uuid.uuid4())) % time.time())
	maxResult = [float("-inf"), random.choice(['R', 'P', 'S'])]
	for i in range(len(results)):
		if(maxResult[0] < results[i][0]):
			maxResult = [results[i][0], results[i][1]]
	# print maxResult[1]
	output = maxResult[1]