def genmove_cmd(self, args): """ Modify this function for Assignment 1 """ """ generate a move for color args[0] in {'b','w'} """ board_color = args[0].lower() if board_color != "w" and board_color != "b": self.respond('illegal move: "{}" wrong color'.format(args[0])) return color = color_to_int(board_color) if self.board.current_player != color: self.respond('illegal move: "{}" wrong color'.format(args[0])) return move = GoBoardUtil.generate_legal_moves(self.board, color) moves = GoBoardUtil.gen1_move(self.board, color, move) if moves != None: play = moves[random.randint(0,len(moves)-1)] self.board.play_move(play,color) else: self.respond("resign")
def get_move(self, board, color): move = GoBoardUtil.generate_legal_moves(board, color) moves = GoBoardUtil.gen1_move(board, color, move) if moves != None: rand = random.randint(0, len(moves) - 1) return moves[rand] return None
def gogui_rules_legal_moves_cmd(self, args): #"gogui-rules_legal_moves" """ Implement this function for Assignment 1 """ #"gogui-rules_legal_moves" # try: #board_color = args[0].lower() color = self.board.current_player move = GoBoardUtil.generate_legal_moves(self.board, color) moves = GoBoardUtil.gen1_move(self.board, color, move) coords = [] if moves == None: return self.respond(coords) for m in moves: coord = point_to_coord(m,self.board.size) coords.append(format_point(coord)) coords = ' '.join(sorted(coords)) self.respond(coords)
def gogui_rules_final_result_cmd(self, args): """ Implement this function for Assignment 1 """ response = "unknown" color = self.board.current_player move = GoBoardUtil.generate_legal_moves(self.board, color) moves = GoBoardUtil.gen1_move(self.board, color, move) if moves != None: self.respond(response) return if self.board.current_player == 1: response = "white" else: response = "black" self.respond(response)