Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b1dc5b6

Browse files
committed
Simplified recursive_dls.
1 parent 83bb6e4 commit b1dc5b6

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

search.py

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,22 +159,19 @@ def depth_limited_search(problem, limit=50):
159159
# Would this not be more elegant with an exception instead of 'cutoff'?
160160
# Or would an exception work better for the _successful_ case? ;-)
161161
def recursive_dls(node, problem, limit):
162-
cutoff_occurred = False
163162
if problem.goal_test(node.state):
164163
return node
165164
elif node.depth == limit:
166165
return 'cutoff'
167166
else:
167+
nonresult = None
168168
for successor in node.expand(problem):
169169
result = recursive_dls(successor, problem, limit)
170170
if result == 'cutoff':
171-
cutoff_occurred = True
171+
nonresult = 'cutoff'
172172
elif result != None:
173173
return result
174-
if cutoff_occurred:
175-
return 'cutoff'
176-
else:
177-
return None
174+
return nonresult
178175
# Body of depth_limited_search:
179176
return recursive_dls(Node(problem.initial), problem, limit)
180177

0 commit comments

Comments
 (0)