python-执行时间问题
问题描述:
我能够去通过第一个功能....但第二FUNC没有运行....的getActionpython-执行时间问题
def registerInitialState(self, state):
"""
This is the first time that the agent sees the layout of the game board. Here, we
choose a path to the goal. In this phase, the agent should compute the path to the
goal and store it in a local variable. All of the work is done in this method!
state: a GameState object (pacman.py)
"""
if self.searchFunction == None: raise Exception, "No search function provided for SearchAgent"
starttime = time.time()
problem = self.searchType(state) # Makes a new search problem
self.actions = self.searchFunction(problem) # Find a path
totalCost = problem.getCostOfActions(self.actions)
print('Path found with total cost of %d in %.1f seconds' % (totalCost, time.time() - starttime))
if '_expanded' in dir(problem): print('Search nodes expanded: %d' % problem._expanded)
def getAction(self, state):
"""
Returns the next action in the path chosen earlier (in registerInitialState). Return
Directions.STOP if there is no further action to take.
state: a GameState object (pacman.py)
"""
if 'actionIndex' not in dir(self): self.actionIndex = 0
i = self.actionIndex
self.actionIndex += 1
if i < len(self.actions):
return self.actions[i]
else:
return Directions.STOP
Error: File line 114, in getAction
if i < len(self.actions):
TypeError: len() of unsized object
这是我的功能:当我执行,它让我感到节点的价值,但不是它,它给了我错误。 get操作函数中的i = 0的值。我不知道,为什么它不增加。
while stack.isEmpty()!= 0:
node = stack.pop()
print node
错误:
(5, 5)
Path found with total cost of 999999 in 0.0 seconds
Search nodes expanded: 1
None
答
添加打印语句按以下,并告诉我它说什么。 self.actions可能是None类型或不是类似列表的对象。你可能想要像另一个一样检查== None。
self.actionIndex += 1
print self.actions
if i < len(self.actions):
return self.actions[i]
else:
return Directions.STOP
所以问题应该是介于浏览:
problem = self.searchType(state) # Makes a new search problem
print problem
self.actions = self.searchFunction(problem) # Find a path
检查:
problem = self.searchType(state) # Makes a new search problem
self.actions = self.searchFunction(problem) # Find a path
使self.actions ==无
你可以进一步与调试问题正在起作用..如果是这样,searchFunction没有找到路径或出现问题,并且它正在返回g无。
这不是一个错误,这只是正常的输出。 – Zaz 2010-08-03 10:47:30