From e4cca7e1faa1d0b7ef5de2a7f01e2d7cd5fb329e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Fri, 8 Feb 2019 23:52:38 -0500 Subject: [PATCH] =?UTF-8?q?code=20fonctionne=20pour=20tous=20les=20num?= =?UTF-8?q?=C3=A9ros?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- search/searchAgents.py | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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):