Question: I need help with this code, it is searchAgents.py def foodHeuristic(state, problem): *** TTU READ THIS *** Your heuristic for the FoodSearchProblem goes here.

I need help with this code, it is searchAgents.py

def foodHeuristic(state, problem):

"*** TTU READ THIS ***

""" Your heuristic for the FoodSearchProblem goes here.

position, foodGrid = state cal_cost=0

"*** YOUR CODE HERE ***"

return cal_cost class AnyFoodSearchProblem(PositionSearchProblem):

def __init__(self, gameState):

"Stores information from the gameState. You don't need to change this."

# Store the food for later reference

self.food = gameState.getFood()

# Store info for the PositionSearchProblem (no need to change this)

self.walls = gameState.getWalls()

self.startState = gameState.getPacmanPosition()

self.costFn = lambda x: 1

self._visited, self._visitedlist, self._expanded = {}, [], 0 # DO NOT CHANGE

def isGoalState(self, state):

""" The state is Pacman's position. Fill this in with a goal test that will complete the problem definition. """

x,y = state

util.raiseNotDefined()

def mazeDistance(point1, point2, gameState):

""" Returns the maze distance between any two points, using the search functions you have already built. The gameState can be any game state -- Pacman's position in that state is ignored. Example usage: mazeDistance( (2,4), (5,6), gameState) This might be a useful helper function for your ApproximateSearchAgent. """

x1, y1 = point1

x2, y2 = point2

walls = gameState.getWalls()

assert not walls[x1][y1], 'point1 is a wall: ' + str(point1)

assert not walls[x2][y2], 'point2 is a wall: ' + str(point2)

prob = PositionSearchProblem(gameState, start=point1, goal=point2, warn=False, visualize=False)

return len(search.bfs(prob))

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!