def __init__(self, strategy): try: self.game = Game(id='2') self._parser = Parser(self.game) self._planner = Planner(strategy, self.game) except: logging.exception("Error while constructing Bot:")
class Bot: def __init__(self, strategy): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game) def run(self): while not stdin.closed: try: line = stdin.readline().strip() if len(line) == 0: continue moves = self.interpret(line) if moves: self.sendMoves(moves) except EOFError: return def interpret(self, line): if line.startswith('action'): return self._planner.makeMove() else: self._parser.parse(line) @staticmethod def sendMoves(moves): stdout.write(','.join(moves) + '\n') stdout.flush()
class Bot: def __init__(self, strategy): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game, argv[1:]) # print "argv is ", argv def run(self): while not stdin.closed: try: line = stdin.readline().strip() if len(line) == 0: continue moves = self.interpret(line) if moves: self.sendMoves(moves) except EOFError: return def interpret(self, line): if line.startswith('action'): return self._planner.makeMove() else: self._parser.parse(line) @staticmethod def sendMoves(moves): stdout.write(','.join(moves) + '\n') stdout.flush()
def __init__(self, strategy): try: self.game = Game(id='1') self._parser = Parser(self.game) self._planner = Planner(strategy, self.game) with open('botout-1.txt', 'w') as out: out.write('hi\n') except: logging.exception("Error while constructing Bot:")
class Bot: def __init__(self, strategy): try: self.game = Game(id='1') self._parser = Parser(self.game) self._planner = Planner(strategy, self.game) with open('botout-1.txt', 'w') as out: out.write('hi\n') except: logging.exception("Error while constructing Bot:") def run(self): while not stdin.closed: try: line = stdin.readline().strip() with open('botout-1.txt', 'a') as out: out.write(line + '\n') if len(line) == 0: continue moves = self.interpret(line) if moves: moves = self.game.me.field.expand_downs( deepcopy(self.game.piece), moves) self.sendMoves(moves) with open('botout-1.txt', 'a') as out: out.write('moves: ' + ','.join(moves) + '\n') except: logging.exception("Error while makin moves:") def interpret(self, line): if line.startswith('action'): return self._planner.makeMove() elif line == 'result won': self.game.over = True self._planner.won() elif line == 'result lost': self.game.over = True self._planner.lost() else: self._parser.parse(line) @staticmethod def sendMoves(moves): stdout.write(','.join(moves) + '\n') stdout.flush()
class Bot: def __init__(self, strategy): try: self.game = Game(id='2') self._parser = Parser(self.game) self._planner = Planner(strategy, self.game) except: logging.exception("Error while constructing Bot:") def run(self): while not stdin.closed: try: line = stdin.readline().strip() if len(line) == 0: continue moves = self.interpret(line) if moves: moves = self.game.me.field.expand_downs(deepcopy(self.game.piece), moves) self.sendMoves(moves) lines = [''.join(list(map(bitToPixel, l))) for l in self.game.me.field.field] board = '\n'.join(lines) + "\n\n" with open('games/game-' + n + '.txt', 'a') as out: out.write(board) except: logging.exception("2Error while makin moves:") def interpret(self, line): if line.startswith('action'): return self._planner.makeMove() elif line == 'result won': self.game.over = True self._planner.won() elif line == 'result lost': self.game.over = True self._planner.lost() else: self._parser.parse(line) @staticmethod def sendMoves(moves): stdout.write(','.join(moves) + '\n') stdout.flush()
def __init__(self, strategy, w1=1.0, w2=0.0, p=True): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game, w1, w2) self.fname = 'p3_output.txt' self.p = p if p: self.my_output = open(self.fname,'w')
class Bot: def __init__(self, strategy, w1=1.0, w2=0.0, p=True): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game, w1, w2) self.fname = 'p3_output.txt' self.p = p if p: self.my_output = open(self.fname,'w') def run(self): while not stdin.closed: try: line = stdin.readline().strip() if len(line) == 0: continue if line == 'bob': exit() if self.p: self.my_output.write(line+'\n') moves = self.interpret(line) if moves: self.sendMoves(moves) except EOFError: if self.p: self.my_output.close() self.strategy.close() return def interpret(self, line): if line.startswith('action'): return self._planner.makeMove() else: self._parser.parse(line) @staticmethod def sendMoves(moves): stdout.write(','.join(moves) + '\n') stdout.flush()
def __init__(self, strategy): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game)
def __init__(self, strategy): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game) self._writer = open('bot.txt','wb')
def __init__(self, strategy): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game, argv[1:])
def __init__(self, strategy, params): self.game = Game() self._parser = Parser(self.game) self._planner = Planner.create(strategy, self.game, params)