Last active
August 29, 2015 14:22
-
-
Save kartikkukreja/a938e70dbe73c81b4a78 to your computer and use it in GitHub Desktop.
Graph Search Algorithm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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