Return a move from alpha-beta

无人久伴 提交于 2019-12-24 08:45:07

问题


I'm trying to use the alpha-beta minimax pruning algorithm to return a valid move from my board. The algorithm returns the correct value, but I have no idea how I would return the move as well. In the case of this code, I would want to return the child in get_successor_states when the value of bestValue is more than the current alpha. I thought about returning two values at the end of the max and min like return bestValue, child but I have no idea how I would get that to work with the other calls

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

来源:https://stackoverflow.com/questions/40098878/return-a-move-from-alpha-beta

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!