Bayes3

Authortk2
Submission date2014-07-15 05:37:31.302580
Rating7050
Matches played555
Win rate70.63

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

Source code:

import random
import math

def rand_dirichlet(a):
  p = [random.gammavariate(x,1) for x in a]
  s = sum(p)
  return [x / s for x in p]

def action(kappa):
  p = rand_dirichlet([x+1 for x in kappa])
  e = [p[(i+2)%3] - p[(i+1)%3] for i in xrange(3)]
  for i in xrange(3):
    if e[i] < e[(i+1)%3] == e[(i+2)%3]:
      return random.choice([(i+1)%3,(i+2)%3])
    if e[i] <= e[(i+1)%3] < e[(i+2)%3]:
      return (i+2)%3
  return random.choice([0,1,2])

if input == '':
  hands = 'RPS-'
  rhands = { 'R': 0, 'P': 1, 'S': 2, '': 3 }
  stat = [[0,0,0,0] for i in xrange(256)]
  hist = [[3, 3], [3, 3]]
  s = 255
  m = 3
o = rhands[input]
stat[s][o] += 1
hist[1][:] = hist[0][:]
hist[0][0] = m
hist[0][1] = o
s = 64 * hist[1][1] + 16 * hist[1][0] + 4 * hist[0][1] + hist[0][0]
m = action(stat[s][:3])
output = hands[m]