【发布时间】:2020-01-08 13:40:23
【问题描述】:
我正在使用带有 alpha-beta 修剪的 minimax 方法创建一个国际象棋 AI。我正在尝试了解 alpha-beta 修剪的工作原理,但在设置特定搜索深度的国际象棋方面却无法理解。
带有 alpha-beta 的 minimax 如何解决牺牲一块以获得优势 2-3 前进?会不会只看祭品的位置,马上把那根树枝当作坏的丢弃,从而错过了好的“祭品”?
感谢您对改进的任何澄清或建议。到目前为止,这是我的代码:
def minimax(board, depth, alpha, beta, maximizing_player):
board.is_human_turn = not maximizing_player
children = board.get_all_possible_moves()
if depth == 0 or board.is_draw or board.is_check_mate:
return None, evaluate(board)
best_move = random.choice(children)
if maximizing_player:
max_eval = -math.inf
for child in children:
board_copy = copy.deepcopy(board)
board_copy.move(child)
current_eval = minimax(board_copy, depth - 1, alpha, beta, False)[1]
if current_eval > max_eval:
max_eval = current_eval
best_move = child
alpha = max(alpha, current_eval)
if beta <= alpha:
break
return best_move, max_eval
else:
min_eval = math.inf
for child in children:
board_copy = copy.deepcopy(board)
board_copy.move(child)
current_eval = minimax(board_copy, depth - 1, alpha, beta, True)[1]
if current_eval < min_eval:
min_eval = current_eval
best_move = child
beta = min(beta, current_eval)
if beta <= alpha:
break
return best_move, min_eval
【问题讨论】:
-
国际象棋 AI 很难编程。基于 2-3 层 的任何东西都会遇到 horizon effect 的坏情况(你的问题的答案“它不只是看看牺牲的位置并立即丢弃那个分支吗? ,因此错过了好的“牺牲”?”是一个强调的“是”)。没有简单的解决方案。在Chess(它有一个关于国际象棋引擎的活动标签)上问这个问题可能会更好。
-
谢谢约翰,会试试的!