This program has been disqualified.
Author | eakosin |
Submission date | 2014-04-23 19:24:29.614080 |
Rating | 4611 |
Matches played | 111 |
Win rate | 46.85 |
# regexRanking-3
# 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 = [3, activeBufferSize]
staticBufferNumber = (3 ** 5)
staticBufferSize = 5
staticBufferDecay = (3 ** 5)
decayRate = 9
if(input == ""):
activeBuffer = []
staticBuffers = [[]]
bufferDecay = [0]
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] = staticBufferDecay
bufferDecay.insert(0, 0)
#If number of static buffers exceeds 3^5, remove buffer of smallest decay
if(len(staticBuffers) > staticBufferNumber):
smallest = [1, bufferDecay[1]]
for i in range(1,len(bufferDecay)):
if(smallest[1] > bufferDecay[i]):
smallest = [i, bufferDecay[i]]
staticBuffers.pop(smallest[0])
#Build regex match [0:3^n] characters where n = [search[0] - search[1]]
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 = []
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):
bufferDecay[i] += (3 ** r)
results.append([bufferDecay[i], match.groups(0)[0]])
else:
bufferDecay[i] -= 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]]
output = maxResult[1]