def generate_all_policy_moves(board, pattern, check_selfatari): """ generate a list of policy moves on board for board.current_player. Use in UI only. For playing, use generate_move_with_filter which is more efficient """ if board.last_move != None: # AtariCapture atari_capture_move = GoBoardUtil_Go3.generate_atari_capture_move(board) if atari_capture_move: return [atari_capture_move], "AtariCapture" # AtariDefense atari_defense_moves = GoBoardUtil_Go3.generate_atari_defense_moves(board) if len(atari_defense_moves) > 0: return atari_defense_moves, "AtariDefense" # Pattern if pattern: pattern_moves = [] pattern_moves = GoBoardUtil.generate_pattern_moves(board) pattern_moves = GoBoardUtil.filter_moves(board, pattern_moves, check_selfatari) if len(pattern_moves) > 0: return pattern_moves, "Pattern" # Random return GoBoardUtil.generate_random_moves(board,True), "Random"
def get_move_prob(self): moves = GoBoardUtil.generate_random_moves(self.board) # legal and not eye-filling features = Feature.find_all_features(self.board) gammas_sum = 0 move_gammas = dict() if len(Features_weight) != 0: for move in moves: move_gammas[move] = Feature.compute_move_gamma(Features_weight, features[move]) gammas_sum += move_gammas[move] # normalize to get probability if gammas_sum: for move in move_gammas.keys(): move_gammas[move] /= gammas_sum if move_gammas and gammas_sum: move_prob_tuples = [(self.board.point_to_string(k), v) for (k, v) in move_gammas.items()] # sort list by probability and alphabetic order # based on # http://stackoverflow.com/questions/5212870/sorting-a-python-list-by-two-criteria # answered by jaap on Stack Overflow http://stackoverflow.com/users/1186954/jaap move_prob_tuples = sorted(move_prob_tuples, key=lambda k:(-k[1], k[0][0], k[0][1])) else: move_prob_tuples = list() move_prob_tuples.append(('pass', 1)) return move_prob_tuples
def random_moves_cmd(self, args): """ Return list of random moves (legal, but not eye-filling) """ moves = GoBoardUtil.generate_random_moves(self.board) if len(moves) == 0: self.respond("Pass") else: self.respond(GoBoardUtil.sorted_point_string(moves, self.board.NS))
def generate_all_policy_moves(board, pattern, check_selfatari): """ generate a list of policy moves on board for board.current_player. Use in UI only. For playing, use generate_move_with_filter which is more efficient """ if pattern: pattern_moves = [] pattern_moves = PatternUtil.generate_pattern_moves(board) pattern_moves = PatternUtil.filter_moves(board, pattern_moves, check_selfatari) if len(pattern_moves) > 0: return pattern_moves, "Pattern" return GoBoardUtil.generate_random_moves(board, True), "Random"