Skip to content
Snippets Groups Projects
Commit 4d246422 authored by Michael Mutote's avatar Michael Mutote
Browse files

22202956

first commit breadth first search, algorithm done. tested with Maze problem
parent c419cf3f
No related branches found
No related tags found
No related merge requests found
import queue
import is_goal
import Sucessors
def BreadthFirstSearch(state):
"""accepts start state"""
def BreadthFirstSearch(state, successor, isgoal):
"""accepts start state, Please do not change this function"""
toDo = queue.Queue()
toDo.put([state])
explored = {state}
while not toDo.empty():
path = toDo.get()
current = path[-1]
if is_goal.isgoal(current):
if isgoal(current):
return path
for next_state in Sucessors.sucessor(current):
if not (next_state in explored):
for next_state in successor(current):
if next_state not in explored:
explored.add(next_state)
path.append(next_state)
toDo.put(path)
path2 = path + [next_state]
toDo.put(path2)
return "Error Path not found"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment