This program has been disqualified.
Author | eakosin |
Submission date | 2014-04-24 14:20:47.696948 |
Rating | 4442 |
Matches played | 206 |
Win rate | 42.23 |
# regexRanking-4
# 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 = 27
search = [1, 3]
staticBufferNumber = (3 ** 4)
staticBufferSize = 81
staticBufferDecay = 81
decayRate = 3
try:
firstRun = firstRun or True
except:
firstRun = False
if(not firstRun):
activeBuffer = []
staticBuffers = [[]]
bufferDecay = [0]
rounds, hits = 0, 0
if(input == ""):
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) > activeBufferSize):
activeBuffer.pop()
#Insert into the current static buffer up to staticBufferSize values
staticBuffers[0].insert(0, input)
#Allocate new buffer if size is reached
if(len(staticBuffers[0]) > staticBufferSize):
staticBuffers.insert(0, [])
bufferDecay[0] = staticBufferDecay
bufferDecay.insert(0, 0)
#If number of static buffers exceeds staticBufferNumber, 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 = []
# print "Round"
for i in range(search[0], search[1] + 1):
regexString = '(.)' + ''.join(activeBuffer[0:(3**i)])
# print regexString
regex.append([re.compile(regexString),(3**i)])
#Iterate through buffers and regex match
results = []
for i in range(1,len(staticBuffers)):
# print i
bufferString = "".join(staticBuffers[i])
# print bufferString
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(1)[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]
rock = 0
paper = 0
scissors = 0
for i in range(len(results)):
# print results[i]
if(results[i][1] == "R"):
rock += max(0, results[i][0])
elif(results[i][1] == "P"):
paper += max(0, results[i][0])
elif(results[i][1] == "S"):
scissors += max(0, results[i][0])
if(rock + paper + scissors == 0):
random.seed((int(uuid.uuid1()) + int(uuid.uuid4())) % time.time())
output = random.choice(['R', 'P', 'S'])
else:
# print rock, paper, scissors
hits += 1
if(rock > scissors):
if(paper > rock):
output = "P"
else:
output = "R"
elif(paper > scissors):
output = "P"
else:
output = "S"
# print output
# rounds += 1
# if(rounds % 100 == 0):
# print hits
# print output