artificial-intelligence - 如何使用 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
解决方案
推荐阅读
- docker - Docker:管理镜像构建依赖
- java - 什么时候应该使用同步方法,什么时候应该在 Java 中使用同步块?
- c# - 如何使用字符串变量访问子类
- mysql - mysql 行号无法正常使用订单
- kubernetes - 无法创建 pod 沙箱 [flannel]
- amazon-web-services - AWS SAM——我们能否在不部署整个堆栈的情况下为单个函数部署代码?
- vba - 保存附件返回 91 错误或不保存
- powerbi - 使用度量将一个表中的行除以另一个表中的行
- python - 'canvas.mpl_connect' 在类中不起作用
- google-apps-script - Google Apps 脚本突然失去对日历 API 的访问权限