f9febf

This program has been disqualified.


Authorzacstewart
Submission date2013-11-17 20:39:41.307334
Rating5004
Matches played6
Win rate50.0

Source code:

import random
from itertools import izip

class Markov(object):
  MAX_SUBMOVE = 3

  def __init__(self):
    self.moves = []
    self.reset()

  def incrememnt_next_move(self, preceding_moves, move):
    if not preceding_moves in self.next_moves:
      self.next_moves[preceding_moves] = []
    self.next_moves[preceding_moves].append(move)

  def add_moves(self, moves):
    move = moves[-1]
    preceding_moves = moves[:-1]

    self.incrememnt_next_move(preceding_moves, move)

  def add_move(self, move):
    self.moves.append(move)

    if len(self.moves) > 1:
      self.reset()

      for moves in zip(*[self.moves[i:] for i in range(self.MAX_SUBMOVE)]):
        self.add_moves(moves)

  def reset(self):
    self.next_moves = {}

  def choice(self):
    try:
      candiate_moves = self.next_moves[tuple(self.moves[-2:])]
    except KeyError:
      candiate_moves = ('R', 'P', 'S')
    return random.choice(candiate_moves)

if input == '':
  markov = Markov()
else:
  markov.add_move(input)

output = markov.choice()