2010-07-17 74 views
0

我能夠去通過第一個功能....但第二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 
+0

這不是一個錯誤,這只是正常的輸出。 – Zaz 2010-08-03 10:47:30

回答

1

添加打印語句按以下,並告訴我它說什麼。 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無。

+0

plz再次檢查問題 – Shilpa 2010-07-17 10:10:49

+0

亞..我編輯了問題...你可以檢查問題結束時的錯誤。 – Shilpa 2010-07-17 10:24:05

+0

我現在在做什麼?你是對的。它是沒有的 – Shilpa 2010-07-17 10:25:44