PostIt_v3_4Length

This program has been disqualified.


AuthorJustinF
Submission date2011-06-15 12:48:16.974770
Rating5798
Matches played2693
Win rate56.11

Source code:

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')
    countPaper = occurances(history, key + 'P')
    countScissor = occurances(history, key + 'S')
    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, 4)
  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