2010-07-17 10 views
0

Je suis capable de passer par la première fonction .... mais la deuxième func ne fonctionne pas .... GetActionproblème du temps d'exécution Python-

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 

ceci est ma fonction: quand j'exécute, ça me donne la valeur de node mais au lieu de ça, ça me donne une erreur. La valeur de i = 0 dans la fonction d'action d'obtention. Je ne sais pas, pourquoi il n'augmente pas.

while stack.isEmpty()!= 0: 
     node = stack.pop() 
     print node 

Erreur:

(5, 5) 
Path found with total cost of 999999 in 0.0 seconds 
Search nodes expanded: 1 
None 
+0

Ce n'est pas une erreur, c'est juste une sortie normale. – Zaz

Répondre

1

Ajoutez l'instruction d'impression comme ci-dessous et dites-moi ce qu'il dit. self.actions est probablement le type None ou pas un objet semblable à une liste. Vous pourriez vouloir vérifier == Aucun comme l'autre.

self.actionIndex += 1 
print self.actions 
if i < len(self.actions): 
    return self.actions[i]  
else: 
    return Directions.STOP 

Le problème est probablement quelque part ici:

problem = self.searchType(state) # Makes a new search problem 
self.actions = self.searchFunction(problem) # Find a path 

faisant self.actions == Aucun

Vous pourriez déboguer plus avec:

problem = self.searchType(state) # Makes a new search problem 
print problem 
self.actions = self.searchFunction(problem) # Find a path 

pour vérifier si le problème fonctionne ... si c'est le cas, searchFunction ne trouve pas le chemin ou quelque chose ne va pas et il est retourné g Aucun.

+0

plz vérifier à nouveau la question – Shilpa

+0

ya..i a édité la question ... vous pouvez vérifier l'erreur à la fin de la question. – Shilpa

+0

ce que shud je fais maintenant ?? Vous avez raison .. il est aucun – Shilpa