fix: return when isGoal
This commit is contained in:
parent
7a31882480
commit
f0c5c6d84a
@ -100,6 +100,8 @@ def depthFirstSearch(problem: SearchProblem):
|
||||
path = path + [direction]
|
||||
visited.append(new_state)
|
||||
isGoal = problem.isGoalState(new_state)
|
||||
if isGoal:
|
||||
break
|
||||
for (_state, _direction, _cost) in problem.getSuccessors(new_state): # (state, direction, cost)
|
||||
stack.push(((_state, _direction, _cost), path))
|
||||
path = path[1:]
|
||||
@ -130,6 +132,8 @@ def breadthFirstSearch(problem: SearchProblem):
|
||||
path = path + [direction]
|
||||
visited.append(new_state)
|
||||
isGoal = problem.isGoalState(new_state)
|
||||
if isGoal:
|
||||
break
|
||||
for (_state, _direction, _cost) in problem.getSuccessors(new_state): # (state, direction, cost)
|
||||
queue.push(((_state, _direction, _cost), path))
|
||||
path = path[1:]
|
||||
@ -161,6 +165,8 @@ def uniformCostSearch(problem: SearchProblem):
|
||||
costs = costs + cost
|
||||
visited.append(new_state)
|
||||
isGoal = problem.isGoalState(new_state)
|
||||
if isGoal:
|
||||
break
|
||||
for (_state, _direction, _cost) in problem.getSuccessors(new_state): # (state, direction, cost)
|
||||
queue.push(((_state, _direction, _cost), path, costs), costs+_cost)
|
||||
path = path[1:]
|
||||
|
||||
Loading…
Reference in New Issue
Block a user