【发布时间】:2018-08-05 23:13:27
【问题描述】:
我正在研究解决 2048 的 minimax 算法的实现。在迭代对象列表并将此值传递给递归函数时遇到问题。代码是:
def MAXIMIZE(state,deep):
if deep == 10:
return (None,greed(state))
tup = (None, -1000000) #maxChild, maxUtility
moves = state.getAvailableMoves()
#children by moves
children = []
children.append(state.clone().move(m) for m in moves)
for child in children:
temp,utility = MINIMIZE(child,deep + 1)
if utility > tup[1]:
tup = (child, utility)
return tup
def MINIMIZE(state,deep):
if deep == 10:
return (None, greed(state))
tup = (None, +10000000)
cells = state.getAvailableCells() # this is where I get an error - "'generator' object has no attribute 'getAvailableCells'"
children = []
children.append(state.clone().setCellValue(cell, 2) for cell in cells)
for child in children:
temp,utility = MAXIMIZE(child,deep + 1)
if utility < tup[1]:
tup = (child,utility)
return tup
在 MINIMIZE 函数中,行 - cells = state.getAvailableCells() 给出“'generator' object has no attribute 'getAvailableCells'” 谁能帮我解决这个问题? (我是物理系的学生,对Python的了解有限。我去各种现有的问题,但不能理解。)
【问题讨论】:
-
修复缩进。这不运行。
标签: python recursion generator minimax