Skip to content

Instantly share code, notes, and snippets.

@kartikkukreja
Last active August 29, 2015 14:22
Show Gist options
  • Save kartikkukreja/a938e70dbe73c81b4a78 to your computer and use it in GitHub Desktop.
Save kartikkukreja/a938e70dbe73c81b4a78 to your computer and use it in GitHub Desktop.
Graph Search Algorithm
def graphSearch(problem, strategy):
start = problem.getStartState()
explored = set([start[0]])
strategy.push(start)
while not strategy.empty():
node = strategy.pop()
if problem.isGoalState(node):
return node[1]
for move in problem.getSuccessors(node):
if move[0] not in explored:
explored.add(move[0])
strategy.push(move)
return None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment