def findPathToClosestDot(self, gameState):
   "Returns a path (a list of actions) to the closest dot, starting from gameState"
   # Here are some useful elements of the startState
   startPosition = gameState.getPacmanPosition()
   food = gameState.getFood()
   walls = gameState.getWalls()
   problem = AnyFoodSearchProblem(gameState)
   return search.uniformCostSearch(problem) 
    def findPathToClosestDot(self, gameState):
        "Returns a path (a list of actions) to the closest dot, starting from gameState"
        # Here are some useful elements of the startState
        startPosition = gameState.getPacmanPosition()
        food = gameState.getFood()
        walls = gameState.getWalls()
        problem = AnyFoodSearchProblem(gameState)

        "*** YOUR CODE HERE ***"
        from search import uniformCostSearch
        return uniformCostSearch(problem)
        util.raiseNotDefined()
    def findPathToClosestDot(self, gameState):
        """
        Returns a path (a list of actions) to the closest dot, starting from
        gameState.
        """
        # Here are some useful elements of the startState
        startPosition = gameState.getPacmanPosition()
        food = gameState.getFood()
        walls = gameState.getWalls()
        problem = AnyFoodSearchProblem(gameState)

        # We can use either any positionalSearch Algorithms to calculate the nearest food node path
        return search.uniformCostSearch(problem)
Exemple #4
0
 def findPathToClosestDot(self, gameState):
     "Returns a path (a list of actions) to the closest dot, starting from gameState"
     # Here are some useful elements of the startState
     startPosition = gameState.getPacmanPosition()
     food = gameState.getFood()
     walls = gameState.getWalls()
     problem = AnyFoodSearchProblem(gameState)
     
     "*** YOUR CODE HERE ***"
     copyFoodGrid = list(food.copy())[:]
     height = len(copyFoodGrid)
     width = len(copyFoodGrid[0])
     x,y = closestDot(startPosition,copyFoodGrid,width,height)
     searchFood = PositionSearchProblem(gameState, lambda x: 1, (x,y), startPosition)
     action = search.uniformCostSearch(searchFood)
     return action
    def findPathToClosestDot(self, gameState):
        """
        Returns a path (a list of actions) to the closest dot, starting from
        gameState.
        """
        # Here are some useful elements of the startState
        startPosition = gameState.getPacmanPosition()
        food = gameState.getFood()
        walls = gameState.getWalls()
        problem = AnyFoodSearchProblem(gameState)
        
        "*** YOUR CODE HERE ***"
        
        
#         Radiate outward in cardinal directions
# If the direction has a food pellet apply 

        return search.uniformCostSearch(problem)
Exemple #6
0
	def findPathToClosestDot(self, gameState):
		"""
		Returns a path (a list of actions) to the closest dot, starting from
		gameState.
		"""
		# Here are some useful elements of the startState
		startPosition = gameState.getPacmanPosition()
		food = gameState.getFood()
		walls = gameState.getWalls()
		problem = AnyFoodSearchProblem(gameState)

		"*** YOUR CODE HERE ***"
		foodWhere = food.asList()
		dis = dict()
		for f in foodWhere:
			dis[f] = mazeDistance(startPosition, f, gameState)
		nearest = min(dis, key=dis.get)
		print nearest
		return search.uniformCostSearch(problem)
		util.raiseNotDefined()
Exemple #7
0
def foodHeuristic(state, problem):
    """
    Your heuristic for the FoodSearchProblem goes here.

    This heuristic must be consistent to ensure correctness.  First, try to come up
    with an admissible heuristic; almost all admissible heuristics will be consistent
    as well.

    If using A* ever finds a solution that is worse uniform cost search finds,
    your heuristic is *not* consistent, and probably not admissible!  On the other hand,
    inadmissible or inconsistent heuristics may find optimal solutions, so be careful.

    The state is a tuple ( pacmanPosition, foodGrid ) where foodGrid is a
    Grid (see game.py) of either True or False. You can call foodGrid.asList()
    to get a list of food coordinates instead.

    If you want access to info like walls, capsules, etc., you can query the problem.
    For example, problem.walls gives you a Grid of where the walls are.

    If you want to *store* information to be reused in other calls to the heuristic,
    there is a dictionary called problem.heuristicInfo that you can use. For example,
    if you only want to count the walls once and store that value, try:
      problem.heuristicInfo['wallCount'] = problem.walls.count()
    Subsequent calls to this heuristic can access problem.heuristicInfo['wallCount']
    """
    position, foodGrid = state
    height = foodGrid.height
    width = foodGrid.width
    num = 0
    #count number of foods remaining
    for x in range(width):
      for y in range(height):
        if foodGrid[x][y]:
          num+=1
    #to get that sweet 3rd point, we do an actual search when we get to low numbaz
    if num < 5:
      problem = FoodSearchNoWallsProblem(position,foodGrid,height,width)
      actions = search.uniformCostSearch(problem)
      return problem.getCostOfActions(actions)
    return num
Exemple #8
0
 def runTest(self):
     print "Path result for DFS:",search.depthFirstSearch(self)
     print "Path result for BFS:",search.breadthFirstSearch(self)
     print "Path result for UCS:",search.uniformCostSearch(self)
     #print "Path result for A*:",search.aStarSearch(self,search.nullHeuristic)
     print "Path result for A* with letter heuristic:",search.aStarSearch(self,letterHeuristic)
Exemple #9
0
 def __init__(self):
     self.searchFunction = lambda prob: search.uniformCostSearch(prob)
     self.searchType = FoodSearchProblem
Exemple #10
0
		solution.display()
	else:
		print 'No solution found!!'
	'''



	n = 5
	strategy = search.astar

	puzzle = game.NPuzzle(n)
	puzzle.randomStartState()
	puzzle.randomGoalState(47)
	puzzle.startState.display()
	puzzle.goalState.display()

	if strategy == search.bfs:
		solution = search.breadthFirstSearch(puzzle)
	elif strategy == search.dfs:
		solution  = search.depthFirstSearch(puzzle)
	elif strategy == search.ucs:
		solution  = search.uniformCostSearch(puzzle)
	elif strategy == search.dls:
		solution = search.depthLimitedSearch(puzzle,6)
	elif strategy == search.astar:
		solution = search.astar(puzzle, game.manhattanDistance)

	if solution != None:
		solution.display()
	else:
		print 'No solution found!!'