有没有办法并行化以下negamax算法?
01 function negamax(node, depth, color)
02 if depth = 0 or node is a terminal node
03 return color * the heuristic value of node
04 bestValue := −∞
05 foreach child of node
06 v := −negamax(child, depth − 1, −color)
07 bestValue := max( bestValue, v )
08 return bestValue
最佳答案
当这样表述时,作为单个递归函数,并不容易。
最简单的方法是将它分成两个函数:一个专门用于您在树的根部的第一次调用,然后另一个函数被调用并递归地继续调用自身。在根版本中,您可以通过子级并行化循环,并将不同的值存储在列表中。然后你只需要一个非并行循环来找到列表中的最大值,但这会立即完成。
请注意,如果您继续进行 alpha-beta 修剪等增强功能,这将变得更加复杂;像我在这里建议的那样天真地并行化第一个循环将显着减少可以通过 alpha-beta 修剪修剪的节点数量
关于algorithm - 如何并行化negamax算法?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48976035/