首页 > 解决方案 > 如何使用 4x4 tic tac toe 的 minimax 算法使 AI 更有效?

问题描述

因此,当代码运行时,AI 会卡在生成动作上。我想知道可能是因为计算的可能性太多,而且计算时间太长。有什么方法可以增加深度或其他任何东西来提高 AI 的效率吗?谢谢!

def minimax(board, depth, isMaximizing):
    if (checkWhichMarkWon(bot)):
        return 1
    elif (checkWhichMarkWon(player)):
        return -1
    elif (checkDraw()):
        return 0

    if (isMaximizing):
        bestScore = -800
        for key in board.keys():
            if (board[key] == ' '):
                board[key] = bot
                score = minimax(board, depth + 1, False)
                board[key] = ' '
                if (score > bestScore):
                    bestScore = score
        return bestScore

    else:
        bestScore = 800
        for key in board.keys():
            if (board[key] == ' '):
                board[key] = player
                score = minimax(board, depth + 1, True)
                board[key] = ' '
                if (score < bestScore):
                    bestScore = score
        return bestScore

标签: artificial-intelligencetic-tac-toeminimaxdepth

解决方案


推荐阅读