question 5 fonctionne
This commit is contained in:
parent
bd195195e7
commit
db5810d5d1
2 changed files with 30 additions and 3 deletions
|
@ -188,6 +188,7 @@ def uniformCostSearch(problem):
|
|||
maFileEtat.push(succNoeudCourant,succCostChemin)
|
||||
# Ajouter le nouveau chemin dans la file avec son cout
|
||||
maFileChemin.push(listeDirections+[succDirection],succCostChemin)
|
||||
# si noeud existant, mettre a jour le cout si meilleur
|
||||
elif (succNoeudCourant in [i[0] for i in maFileEtat.heap]):
|
||||
maFileEtat.update(succNoeudCourant,succCostChemin)
|
||||
listeDirections = maFileChemin.pop()
|
||||
|
@ -240,6 +241,7 @@ def aStarSearch(problem, heuristic=nullHeuristic):
|
|||
maFileEtat.push(succNoeudCourant,succCostChemin)
|
||||
# Ajouter le nouveau chemin dans la file avec son cout
|
||||
maFileChemin.push(listeDirections+[succDirection],succCostChemin)
|
||||
# si noeud existant, mettre a jour le cout si meilleur
|
||||
elif (succNoeudCourant in [i[0] for i in maFileEtat.heap]):
|
||||
maFileEtat.update(succNoeudCourant,succCostChemin)
|
||||
listeDirections = maFileChemin.pop()
|
||||
|
|
|
@ -288,6 +288,8 @@ class CornersProblem(search.SearchProblem):
|
|||
# Please add any code here which you would like to use
|
||||
# in initializing the problem
|
||||
"*** YOUR CODE HERE ***"
|
||||
self.cornerSet = {(1,1), (1,top), (right, 1), (right, top)}
|
||||
self.defaultCost = 1
|
||||
|
||||
def getStartState(self):
|
||||
"""
|
||||
|
@ -295,14 +297,24 @@ class CornersProblem(search.SearchProblem):
|
|||
space)
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
util.raiseNotDefined()
|
||||
return (self.startingPosition,self.cornerSet)
|
||||
|
||||
def isGoalState(self, state):
|
||||
"""
|
||||
Returns whether this search state is a goal state of the problem.
|
||||
"""
|
||||
"*** YOUR CODE HERE ***"
|
||||
util.raiseNotDefined()
|
||||
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
|
||||
|
||||
def getSuccessors(self, state):
|
||||
"""
|
||||
|
@ -325,7 +337,20 @@ class CornersProblem(search.SearchProblem):
|
|||
# hitsWall = self.walls[nextx][nexty]
|
||||
|
||||
"*** YOUR CODE HERE ***"
|
||||
|
||||
currentPosition, currentCornerSet = state
|
||||
x,y = currentPosition
|
||||
dx, dy = Actions.directionToVector(action)
|
||||
nextx, nexty = int(x + dx), int(y + dy)
|
||||
nextPosition = (nextx, nexty)
|
||||
hitsWall = self.walls[nextx][nexty]
|
||||
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()
|
||||
# Si la position est un coin, alors enlever de l'ensemble
|
||||
currentCornerSet2.discard(currentPosition)
|
||||
nextCornerState = (nextPosition,currentCornerSet2)
|
||||
successors.append((nextCornerState, action, self.defaultCost))
|
||||
self._expanded += 1 # DO NOT CHANGE
|
||||
return successors
|
||||
|
||||
|
|
Loading…
Reference in a new issue