spectral3

Authorpyfex
Submission date2011-06-10 19:43:32.665890
Rating5623
Matches played4845
Win rate57.89

Use rpsrunner.py to play unranked matches on your computer.

Source code:

import random

if input == "":
  strats = [(2,0), (2,1), (3,0), (3,1), (3,2), (4,0), (4,1), (4,2), (4,3), (5,0), (5,1), (5,2), (5,3), (5,4),
            (6,0), (6,1), (6,2), (6,3), (6,4), (6,5), (7,0), (7,1), (7,2), (7,3), (7,4), (7,5), (7,6)]
  spec = [None] * len(strats)
  for i, s in enumerate(spec):
    spec[i] = []
  round = 1
  canditates = [None] * len(strats)
  correct = [0] * len(strats)
  output = random.choice(['R', 'P', 'S'])
  score = {'RR': 0, 'PP': 0, 'SS': 0,
           'PR': 1, 'RS': 1, 'SP': 1,
           'RP': -1, 'SR': -1, 'PS': -1,}
  counter = {'P': 'S', 'S': 'R', 'R': 'P'}
  index = random.randint(0, len(strats)-1)
else:
  for i,c in enumerate(canditates):
    if c is None:
      continue
    sc = score[c+input]
    if sc == 1:
      correct[i] += 1
    if sc == -1:
      correct[i] = 0
 
  for i, (j,k) in enumerate(strats):
    if round % j == k:
       spec[i].append(input)

  for i, s in enumerate(spec):
    if s != []:
      canditates[i] = counter[random.choice(spec[i])]
  
  possible_strats = [i for i, (a, b) in enumerate(strats) if round % a == b]
  
  round += 1
  
  best_correct = max([correct[i] for i in possible_strats])
  best_indices = [i for i in possible_strats if best_correct == correct[i]]
  best_index = random.choice(best_indices)
  b = canditates[best_index]
  if b == None:
    output = random.choice(['R','P', 'S'])
  else:
    output = b