I’m able to go through the first function….but the second func is not running….getaction
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
this is my function:when i execute, it shud give me the value of node but instead of it, it is giving me error. The value of i = 0 in the get action function. I dont know, why it is not incrementing.
while stack.isEmpty()!= 0:
node = stack.pop()
print node
Error:
(5, 5)
Path found with total cost of 999999 in 0.0 seconds
Search nodes expanded: 1
None
Add the print statement as per below and tell me what it says. self.actions is probably the None type or not a list-like object. You might want to check == None like the other one.
So the problem is probably somewhere in here:
making self.actions == None
You could debug further with:
to check if problem is working.. if so, searchFunction is not finding the path or something is going wrong and it is returning None.