从alpha-beta返回一个移动

时间:2016-10-18 03:08:26

标签: python minimax alpha-beta-pruning

我尝试使用alpha-beta minimax修剪算法从我的电路板返回有效的移动。该算法返回正确的值,但我不知道如何返回该移动。对于此代码,当bestValue的值大于当前alpha时,我希望在get_successor_states中返回子项。我想在最大值和最小值的末尾返回两个值,如return bestValue, child,但我不知道如何使用其他调用

def alpha_beta_pruning(board, depth, alpha, beta, isMaximizingPlayer):

    if depth == 0:
        return evaluate_state(board)
    if isMaximizingPlayer:
        bestValue = -sys.maxint - 1
        bestMove = None
        for child in get_successor_states(board):
            temp_board = copy.deepcopy(board)
            temp_board.move_queen(child[0], child[1])
            temp_board.shoot_arrow(child[2])
            bestValue = max(bestValue, alpha_beta_pruning(temp_board, depth-1, alpha, beta, False))
            del temp_board
            alpha = max(alpha, bestValue)
            if beta <= alpha:
                break
        return bestValue
    else:
        bestValue = sys.maxint
        for child in get_successor_states(board):
            temp_board = copy.deepcopy(board)
            temp_board.move_queen(child[0], child[1])
            temp_board.shoot_arrow(child[2])
            bestValue = min(bestValue, alpha_beta_pruning(temp_board, depth-1, alpha, beta, True))
            del temp_board
            beta = min(beta, bestValue)
            if beta <= alpha:
                break
        return bestValue

0 个答案:

没有答案