This program has been disqualified.
Author | JustinF |
Submission date | 2011-06-15 14:02:12.744932 |
Rating | 5584 |
Matches played | 2356 |
Win rate | 57.98 |
import random
def occurances(string, sub):
count = start = 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') * len(key)
countPaper = occurances(history, key + 'P') * len(key)
countScissor = occurances(history, key + 'S') * len(key)
print key, countRock, countPaper, countScissor
if countRock + countScissor + countPaper == 0:
break
else:
best[0][0] += countRock
best[1][0] += countPaper
best[2][0] += countScissor
return best
beats = {'R': 'P', 'P': 'S', 'S': 'R'}
if not input:
output = random.choice(('R', 'P', 'S'))
myStack = ''
oppStack = ''
else:
oppStack += input
myChoices = countBest(myStack, 1, 5)
oppChoices = countBest(oppStack, 1, 4)
choices = sorted([[myChoices[0][0] - oppChoices[2][0], 'R'], [myChoices[1][0] - oppChoices[0][0], 'P'], [myChoices[2][0] - oppChoices[1][0], 'S']])
if choices[0][0] == choices[1][0] == choices[2][0]:
output = random.choice(('R', 'P', 'S'))
elif choices[0][0] == choices[1][0]:
output = random.choice((choices[0][1], choices[1][1]))
else:
output = choices[0][1]
myStack += output