Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active August 29, 2015 14:22
Show Gist options
  • Save kartikkukreja/a676cea69bf76abaa861 to your computer and use it in GitHub Desktop.
Save kartikkukreja/a676cea69bf76abaa861 to your computer and use it in GitHub Desktop.
Iterative Deepening DFS
def depthLimitedDFS(problem, state, depth):
if problem.isGoalState(state):
return state[1]
if depth <= 0:
return None
for move in problem.getSuccessors(state):
solution = depthLimitedDFS(problem, move, depth-1)
if solution is not None:
return solution
return None
def iterativeDeepeningDFS(problem):
depth = 1
while True:
solution = depthLimitedDFS(problem, problem.getStartState(), depth)
if solution is not None:
return solution
depth += 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment