This program has been disqualified.
Author | JustinF |
Submission date | 2011-06-15 11:35:40.545025 |
Rating | 6390 |
Matches played | 2412 |
Win rate | 62.52 |
import random
def occurances(string, sub):
count, start = 0,0
while True:
start = string.find(sub, start) + 1
if start > 0:
count+=1
else:
return count
def countBest(history, start, end):
best = [[0, 'R'],[0, 'P'],[0, 'S']]
for x in xrange(len(history)-start, len(history)-end-1, -1):
key = history[x:]
countRock = occurances(history, key + 'R')
countScissor = occurances(history, key + 'P')
countPaper = occurances(history, key + 'S')
print key, countRock, countScissor, countPaper
if countRock + countScissor + countPaper == 0:
break
else:
best[0][0] += countRock
best[1][0] += countScissor
best[2][0] += countPaper
return best
beats = {'R': 'P', 'P': 'S', 'S': 'R'}
if not input:
output = random.choice(('R', 'P', 'S'))
myStack = ''
oppStack = ''
else:
oppStack += input
myChoices = sorted(countBest(myStack, 2, 5))
if myChoices[0][0] == myChoices[1][0] == myChoices[2][0]:
myOutput = random.choice(('R', 'P', 'S'))
elif myChoices[0][0] == myChoices[1][0]:
myOutput = random.choice((myChoices[0][1], myChoices[1][1]))
else:
myOutput = myChoices[0][1]
oppChoices = sorted(countBest(oppStack, 2, 5))
if oppChoices[0][0] == oppChoices[1][0] == oppChoices[2][0]:
oppOutput = random.choice(('R', 'P', 'S'))
elif oppChoices[1][0] == oppChoices[2][0]:
oppOutput = random.choice((beats[oppChoices[1][1]], beats[oppChoices[2][1]]))
else:
oppOutput = beats[oppChoices[2][1]]
output = random.choice((myOutput, oppOutput))
myStack += output