diff --git a/search/searchAgents.py b/search/searchAgents.py index 4e018db..8f35e27 100644 --- a/search/searchAgents.py +++ b/search/searchAgents.py @@ -308,14 +308,10 @@ class CornersProblem(search.SearchProblem): currentPosition, currentCornerSet = state # print "Validation du but a ", currentPosition, "Coins restants: ", currentCornerSet # On atteint le but s'il reste un seul coin a atteindre, et que c'est l'etat actuel - if len(currentCornerSet)==1: - if currentPosition in currentCornerSet: - # print "But atteint" - return True - else: - return False - else: - return False + # print "But atteint" + return (len(currentCornerSet)==1 and currentPosition in currentCornerSet) + + def getSuccessors(self, state): """ @@ -347,11 +343,11 @@ class CornersProblem(search.SearchProblem): if not hitsWall: # vu que le set est une structure mutable, j'en fais une copie a chaque fois, # sinon elle reste modifiee dans la boucle - currentCornerSet2 = currentCornerSet.copy() + currentCornerSetCopy = currentCornerSet.copy() # Si la position est un coin, alors enlever de l'ensemble - currentCornerSet2.discard(currentPosition) - nextCornerState = (nextPosition,currentCornerSet2) - successors.append((nextCornerState, action, self.defaultCost)) + currentCornerSetCopy.discard(currentPosition) + nextState = (nextPosition,currentCornerSetCopy) + successors.append((nextState, action, self.defaultCost)) self._expanded += 1 # DO NOT CHANGE return successors