def generate_move_with_filter(board, use_pattern, check_selfatari): """ Arguments --------- check_selfatari: filter selfatari moves? Note that even if True, this filter only applies to pattern moves use_pattern: Use pattern policy? """ if board.last_move != None: # AtariCapture move atari_capture_move = GoBoardUtil_Go3.generate_atari_capture_move(board) if atari_capture_move: return atari_capture_move # AtariDefense move atari_defense_moves = GoBoardUtil_Go3.generate_atari_defense_moves(board) if len(atari_defense_moves) > 0: return random.choice(atari_defense_moves) if use_pattern: moves = GoBoardUtil.generate_pattern_moves(board) move = GoBoardUtil.filter_moves_and_generate(board, moves, check_selfatari) if move: return move return GoBoardUtil.generate_random_move(board, board.current_player,True)
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 generate_all_policy_moves(self, 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: atari_moves,msg = self.generate_atari_moves(board) atari_moves = GoBoardUtil.filter_moves(board, atari_moves, check_selfatari) if len(atari_moves) > 0: return atari_moves, msg 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" return GoBoardUtil.generate_random_moves(board,True), "Random"