Connect Four中的Alpha-beta

时间:2017-04-05 22:53:38

标签: artificial-intelligence minimax alpha-beta-pruning

我将minimax算法应用于连接四游戏中的alpha-beta修剪后返回非常糟糕的移动选择。

def get_next_move(board, player, depth, alpha, beta) :
    score = get_score(board, depth)
    if score is not None :
        return score, board
    if depth == 0 :
        return 0, board

    if player is AI :
        best = LOSS
        best_move = None
        possible_moves = get_possible_moves(board, player)

        for move in possible_moves :
            move_score = get_next_move(move, PLAYER, depth-1, alpha, beta)[0]
            if move_score >= best :
                best = move_score
                best_move = move
                alpha = max(alpha, best)
            if alpha >= beta :
                break
        return best, best_move
    else :
        best = WIN
        best_move = None
        possible_moves = get_possible_moves(board, player)

        for move in possible_moves :
            move_score = get_next_move(move, AI, depth-1, alpha, beta)[0]
            if move_score <= best :
                best = move_score
                best_move = move
                beta = min(best, beta)

            if beta <= alpha :
                break
        return best, best_move

在我尝试实施alpha-beta之前,一切正常。

0 个答案:

没有答案