Пример #1
0
    def findPathToClosestCorner(self, gameState):
        startPosition = gameState.getPacmanPosition()
        food = gameState.getFood()
        walls = gameState.getWalls()
        problem = CornersProblem(gameState)
        #return greedySearch(problem, euclideanHeuristic)
        #return search.aStarSearch(problem,cornersHeuristic)

        return search.greedySearch(problem,
                                   cornersHeuristic)  #Desplazar a search.py
 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)
     import search
     return search.greedySearch(problem)
  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.
    
    state: a GameState object (pacman.py)
    """
    if self.searchFunction == None:
      import sys
      print "No search function provided for SearchAgent"
      sys.exit(1)

    # If you wrap your solution in the timing code provided, you'll know how long the pathfinding takes.
    starttime = time.time()
    self.searchFunction=lambda x: search.greedySearch(x, getFoodHeuristic(state))
    problem = self.searchType(state)
    self.actions = deque(self.searchFunction(problem))
    print 'Path found with total cost of %d in %.1f seconds' % (problem.getCostOfActions(self.actions), time.time() - starttime)
Пример #4
0
    board = []
    for _ in range(BOARD_SIZE):
        board.append([0] * BOARD_SIZE)

    # Set up initial gamestate
    game = GameState(snakePos, foodPos, board)

    # Repeat search n times
    for search_num in range(NUMBER_OF_SEARCHES):
        # Get resulting path nodes from performing a search
        problem = PositionSearchProblem(game)

        #path_nodes = search.depthFirstSearch(problem)
        #path_nodes = search.breadthFirstSearch(problem)
        path_nodes = search.greedySearch(
            problem,
            lambda node: manhattanDistance(node.state,
                                           (game.food.x, game.food.y)))

        # Print path nodes
        '''
		for node in path_nodes:
			print(node)
		'''

        # Check if a path was found
        if path_nodes is None:
            print("Could not find path")
            pygame.quit()
            exit()

        actions = [node.action for node in path_nodes]
Пример #5
0
 def __init__(self, searchFunction=None, searchType=FoodSearchProblem):
   self.searchFunction = lambda problem: search.greedySearch(problem, foodHeuristic)
   self.searchType = FoodSearchProblem
Пример #6
0
 def __init__(self):
     self.searchFunction = lambda prob: search.greedySearch(prob, greedyfoodHeuristic)
     self.searchType = FoodSearchProblem
Пример #7
0
def greedySearch(problem):
  return search.greedySearch(problem, greedyHeuristic)
Пример #8
0
def greedy(problem):
    return search.greedySearch(problem, greedyFoodHeuristic)
 def __init__(self, searchFunction=None, searchType=FoodSearchProblem):
   SearchAgent.__init__(self, (lambda x: search.greedySearch(x, getFoodHeuristic(None))), searchType)