class IOPokerBot(object): """Generic Poker Bot, can read & write lines. Subclasses should mix-in parser & action delegates """ def __init__(self, io_input, io_output, log_output): self.io_input = io_input self.action_out = io_output self.log_out = log_output self.brain = Brain(self) def run(self): """ Main run loop """ while not self.io_input.closed: try: rawline = self.io_input.readline() if len(rawline) == 0: break line = rawline.strip() self.brain.parse_line(line) except EOFError: return def say(self, line): """Writes a line where the game controller can see it""" self.write_line(line, self.action_out) self.log("SAID :: {l}".format(l=line)) def log(self, line): """Writes a line somewhere we can log it""" self.write_line(line, self.log) def write_line(self, line, dest): if line and dest: dest.write(line) dest.write('\n') dest.flush()