PostIt_Joined

This program has been disqualified.


AuthorJustinF
Submission date2011-06-15 11:49:40.407055
Rating2195
Matches played2357
Win rate19.9

Source code:

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')
    countPaper = occurances(history, key + 'P')
    countScissor = occurances(history, key + 'S')
    print key, countRock, countScissor, countPaper
    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, 6)
  oppChoices = countBest(oppStack, 1, 6)
  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