This program has been disqualified.
Author | zacstewart |
Submission date | 2013-11-17 20:39:41.307334 |
Rating | 5004 |
Matches played | 6 |
Win rate | 50.0 |
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()