diff --git a/search/searchAgents.py b/search/searchAgents.py index 8f35e27..f43a88b 100644 --- a/search/searchAgents.py +++ b/search/searchAgents.py @@ -381,8 +381,21 @@ def cornersHeuristic(state, problem): corners = problem.corners # These are the corner coordinates walls = problem.walls # These are the walls of the maze, as a Grid (game.py) + "*** YOUR CODE HERE ***" - return 0 # Default to trivial solution + currentPosition, currentCornerSet = state + currentCornerList = list(currentCornerSet) + nb_corners = len(currentCornerList) + # Si on est sur le but, on retourne 0 tel que mentionne dans l'enonce + if problem.isGoalState(state): + return 0 + else: + # Liste des distances de Manhattan vers les sommets restants + mh=[] + for i in range(nb_corners): + mh.append(util.manhattanDistance(currentPosition,currentCornerList[i])) + # On retourne la plus grande distance, qui est le meilleur scenario possible pour terminer + return max(mh) class AStarCornersAgent(SearchAgent): "A SearchAgent for FoodSearchProblem using A* and your foodHeuristic" @@ -476,7 +489,15 @@ def foodHeuristic(state, problem): """ position, foodGrid = state "*** YOUR CODE HERE ***" - return 0 + foodList = foodGrid.asList() + nb_food = len(foodList) + if problem.isGoalState(state): + return 0 + for food in foodList: + mh=[] + for i in range(nb_food): + mh.append(util.manhattanDistance(position,foodList[i])) + return max(mh) class ClosestDotSearchAgent(SearchAgent): "Search for all food using a sequence of searches" @@ -507,6 +528,7 @@ class ClosestDotSearchAgent(SearchAgent): problem = AnyFoodSearchProblem(gameState) "*** YOUR CODE HERE ***" + return search.breadthFirstSearch(problem) util.raiseNotDefined() class AnyFoodSearchProblem(PositionSearchProblem): @@ -543,6 +565,7 @@ class AnyFoodSearchProblem(PositionSearchProblem): x,y = state "*** YOUR CODE HERE ***" + return self.food[x][y] util.raiseNotDefined() def mazeDistance(point1, point2, gameState):