def handle_genmove(self, args): colour = gtp_engine.interpret_colour(args[0]) for move_colour, vertex in self.iter: if move_colour == colour: if vertex == 'fail': raise GtpError("forced to fail") return vertex return "pass"
def handle_genmove(self, args): colour = gtp_engine.interpret_colour(args[0]) if self.row_to_play < self.boardsize: col = 4 if colour == 'b' else 6 result = format_vertex((self.row_to_play, col)) self.row_to_play += 1 return result else: return "pass"
def handle_time_left(self, args): # colour time stones try: colour = gtp_engine.interpret_colour(args[0]) time_remaining = gtp_engine.interpret_int(args[1]) stones_remaining = gtp_engine.interpret_int(args[2]) except IndexError: gtp_engine.report_bad_arguments() if stones_remaining == 0: stones_remaining = None self.time_status[colour] = (time_remaining, stones_remaining)
def handle_genmove(self, args): colour = gtp_engine.interpret_colour(args[0]) for move_colour, vertex in self.iter: if move_colour == colour: if callable(vertex): vertex = vertex() if vertex == 'fail': raise GtpError("forced to fail") if vertex.endswith('&exit'): raise GtpQuit(vertex[:-5]) return vertex return "pass"
def handle_play(self, args): try: colour_s, vertex_s = args[:2] except ValueError: gtp_engine.report_bad_arguments() colour = gtp_engine.interpret_colour(colour_s) move = gtp_engine.interpret_vertex(vertex_s, self.board_size) if move is None: self.simple_ko_point = None self.move_history.append(History_move(colour, None)) return row, col = move try: self.simple_ko_point = self.board.play(row, col, colour) self.simple_ko_player = opponent_of(colour) except ValueError: raise GtpError("illegal move") self.move_history.append(History_move(colour, move))
def _handle_genmove(self, args, for_regression=False, allow_claim=False): """Common implementation for genmove commands.""" try: colour = gtp_engine.interpret_colour(args[0]) except IndexError: gtp_engine.report_bad_arguments() game_state = Game_state() game_state.size = self.board_size game_state.board = self.board game_state.history_base = self.history_base game_state.move_history = self.move_history game_state.komi = self.komi game_state.for_regression = for_regression if self.simple_ko_point is not None and self.simple_ko_player == colour: game_state.ko_point = self.simple_ko_point else: game_state.ko_point = None game_state.handicap = self.handicap game_state.time_settings = self.time_settings game_state.time_remaining, game_state.canadian_stones_remaining = \ self.time_status[colour] generated = self.move_generator(game_state, colour) if allow_claim and generated.claim: return 'claim' if generated.resign: return 'resign' if generated.pass_move: if not for_regression: self.move_history.append( History_move(colour, None, generated.comments, generated.cookie)) return 'pass' row, col = generated.move vertex = format_vertex((row, col)) if not for_regression: try: self.simple_ko_point = self.board.play(row, col, colour) self.simple_ko_player = opponent_of(colour) except ValueError: raise GtpError("engine error: tried to play %s" % vertex) self.move_history.append( History_move(colour, generated.move, generated.comments, generated.cookie)) return vertex
def _handle_genmove(self, args, for_regression=False, allow_claim=False): """Common implementation for genmove commands.""" try: colour = gtp_engine.interpret_colour(args[0]) except IndexError: gtp_engine.report_bad_arguments() game_state = Game_state() game_state.size = self.board_size game_state.board = self.board game_state.history_base = self.history_base game_state.move_history = self.move_history game_state.komi = self.komi game_state.for_regression = for_regression if self.simple_ko_point is not None and self.simple_ko_player == colour: game_state.ko_point = self.simple_ko_point else: game_state.ko_point = None game_state.handicap = self.handicap game_state.time_settings = self.time_settings game_state.time_remaining, game_state.canadian_stones_remaining = \ self.time_status[colour] generated = self.move_generator(game_state, colour) if allow_claim and generated.claim: return 'claim' if generated.resign: return 'resign' if generated.pass_move: if not for_regression: self.move_history.append(History_move( colour, None, generated.comments, generated.cookie)) return 'pass' row, col = generated.move vertex = format_vertex((row, col)) if not for_regression: try: self.simple_ko_point = self.board.play(row, col, colour) self.simple_ko_player = opponent_of(colour) except ValueError: raise GtpError("engine error: tried to play %s" % vertex) self.move_history.append( History_move(colour, generated.move, generated.comments, generated.cookie)) return vertex
def handle_genmove(self, args): try: self.my_colour = gtp_engine.interpret_colour(args[0]) except IndexError: gtp_engine.report_bad_arguments() return self.proxy.pass_command("genmove", args)