當我執行它時,它給我一個錯誤,即太多的值解壓縮? 我如何使它正常工作。值錯誤:太多的值解壓
stack = util.Stack()
closed = []
child = []
index = 0
currNode = problem.getStartState()
node = currNode
stack.push(node)
while not stack.isEmpty():
node = stack.pop()
if problem.isGoalState(node):
print "true"
closed.append(node)
else:
child = problem.getSuccessors(node)
for nodes in child:
stack.push(nodes)
closed.append(node)
return None
錯誤是:
File line 90, in depthFirstSearch
child = problem.getSuccessors(node)
File line 179, in getSuccessors
x,y = state
**ValueError: too many values to unpack**
爲getsuccessor FUNC的代碼是:
def getSuccessors(self, state):
"""
Returns successor states, the actions they require, and a cost of 1.
"""
successors = []
for action in [Directions.NORTH, Directions.SOUTH, Directions.EAST, Directions.WEST]:
x,y = state
dx, dy = Actions.directionToVector(action)
nextx, nexty = int(x + dx), int(y + dy)
if not self.walls[nextx][nexty]:
nextState = (nextx, nexty)
cost = self.costFn(nextState)
successors.append((nextState, action, cost))
返回的值該功能最初:
problem.getStartState() - (5, 5)
problem.isGoalState(problem.getStartState())- False
problem.getSuccessors(problem.getStartState()) - [((5, 4), 'South', 1), ((4, 5), 'West', 1)]
如果有人需要更多的信息,請讓我知道。 – Shilpa 2010-07-14 22:48:48
@Shilpa:錯誤發生在179行,所以你應該在那裏發佈代碼。 – sth 2010-07-14 22:52:28
179行是 x,y =州 我編輯了我的問題。請參閱getSuccessor函數。 – Shilpa 2010-07-14 22:57:31