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 ***" bfs = GraphSearch(GraphSearchType.BFS) return bfs.solve(problem)
def depthFirstSearch(problem): """ Search the deepest nodes in the search tree first. Your search algorithm needs to return a list of actions that reaches the goal. Make sure to implement a graph search algorithm. To get started, you might want to try some of these simple commands to understand the search problem that is being passed in: print("Start:", problem.getStartState()) print("Is the start a goal?", problem.isGoalState(problem.getStartState())) print("Start's successors:", problem.getSuccessors(problem.getStartState())) """ "*** YOUR CODE HERE ***" dfs = GraphSearch(GraphSearchType.DFS) return dfs.solve(problem, nullHeuristic)
def breadthFirstSearch(problem): """Search the shallowest nodes in the search tree first.""" "*** YOUR CODE HERE ***" bfs = GraphSearch(GraphSearchType.BFS) return bfs.solve(problem, nullHeuristic)
def aStarSearch(problem, heuristic=nullHeuristic): """Search the node that has the lowest combined cost and heuristic first.""" "*** YOUR CODE HERE ***" aStar = GraphSearch(GraphSearchType.ASTAR) return aStar.solve(problem, heuristic)
def uniformCostSearch(problem): """Search the node of least total cost first.""" "*** YOUR CODE HERE ***" ucs = GraphSearch(GraphSearchType.UCS) return ucs.solve(problem, nullHeuristic)