Код: Выделить всё
def alphabeta(board, node, depth, a, b, maximizer):
if depth == 0:
return evaluate.node(node)
if maximizer == True:
value = -10**3 # Number that's smaller than what the evaluation algorithm can return
for child in board.get_all_nodes(node):
m = alphabeta(board, child, depth-1, a, b, False)
value = max(value, m)
a = max(a, value)
if a >= b:
break
return value
else:
value = 10**3 # Number that's bigger than what the evaluation algorithm can return
for child in board.get_all_nodes(node):
m = alphabeta(board, child, depth - 1, a, b, True)
value = min(value, m)
b = min(b, value)
if a >= b:
break
return value
Подробнее здесь: https://stackoverflow.com/questions/601 ... ta-pruning