我尝试为 minmax 算法创建一个实现,并且需要创建一个包含所有可能移动的树。在 python 3.7 中使用 anytree 模块创建树,但是当尝试在第一个树级别迭代并构建下一个级别时收到错误。
Traceback (most recent call last):
Hello from the pygame community. https://www.pygame.org/contribute.html
File "C:/Users/User/PycharmProjects/Tema5AI/Main.py", line 217, in <module>
min_max_algorithm(game)
File "C:/Users/User/PycharmProjects/Tema5AI/Main.py", line 209, in min_max_algorithm
new_node = Node((game, i, 0), parent=(pre, fill, node))
File "C:\Users\User\PycharmProjects\Tema5AI\venv\lib\site-packages\anytree\node\node.py", line 66, in __init__
self.parent = parent
File "C:\Users\User\PycharmProjects\Tema5AI\venv\lib\site-packages\anytree\node\nodemixin.py", line 126, in parent
msg = "Parent node %r is not of type 'NodeMixin'." % (value)
TypeError: not all arguments converted during string formatting
我的构建树代码是:
def min_max_algorithm(game):
first_black_move = util.get_all_available_black(game)
root = Node(game)
for i in first_black_move:
node = Node((game, i, 0), parent=root)
for pre, fill, node in RenderTree(root):
first_white_move = util.get_all_available_white(game)
for i in first_white_move:
new_node = Node((game, i, 0), parent=(pre, fill, node))
for pre, fill, node in RenderTree(root):
print("%s%s" % (pre, node.name))
更确切地说,问题是:如何通过当前树将子节点添加到节点?
以下问题对我没有帮助: How to specify children in anytree and print a tree