From a51b467a4fe2ab99bae282435c9ba7bd2451f055 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=C3=A7ois=20Pelletier?= Date: Sun, 3 Feb 2019 15:10:58 -0500 Subject: [PATCH] premiere question resolue --- search/search.py | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/search/search.py b/search/search.py index d1fa4e7..2c63913 100644 --- a/search/search.py +++ b/search/search.py @@ -87,8 +87,36 @@ def depthFirstSearch(problem): print "Start's successors:", problem.getSuccessors(problem.getStartState()) """ "*** YOUR CODE HERE ***" + maPile = util.Stack() + maListeFermee = [] + # Verifier si le depart est un but + if problem.isGoalState(problem.getStartState()): + return [] + # Mettre le premier noeud et un chemin vide dans la pile + maPile.push((problem.getStartState(),list())) + # Rechercher tant que la pile n'est pas vide + while (not maPile.isEmpty()): + # Extraire le noeud courant + noeudCourant, listeDirections = maPile.pop() + # print "Noeud courant: ", noeudCourant + # La marquer comme visite + maListeFermee.append(noeudCourant) + # Verifier si c'est un but + if(problem.isGoalState(noeudCourant)): + # print "Nous avons atteint le but !" + return listeDirections + break + # Effectuer la recherche + for s in problem.getSuccessors(noeudCourant): + # Decomposer le tuple pour faciliter la lecture + succNoeudCourant, succDirection, succCost = s + # Verifier si le noeud n'est pas deja visite + if (succNoeudCourant not in maListeFermee): + # Dans ce cas, ajouter le noeud et le chemin pour s'y rendre a la pile + # print "Ajout du noeud à la pile: ", succNoeudCourant + maPile.push((succNoeudCourant,listeDirections+[succDirection])) util.raiseNotDefined() - + def breadthFirstSearch(problem): """Search the shallowest nodes in the search tree first.""" "*** YOUR CODE HERE ***"