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 queue
import is_goal
import Sucessors
def BreadthFirstSearch(state): def BreadthFirstSearch(state, successor, isgoal):
"""accepts start state""" """accepts start state, Please do not change this function"""
toDo = queue.Queue() toDo = queue.Queue()
toDo.put([state]) toDo.put([state])
explored = {state} explored = {state}
while not toDo.empty(): while not toDo.empty():
path = toDo.get() path = toDo.get()
current = path[-1] current = path[-1]
if is_goal.isgoal(current): if isgoal(current):
return path return path
for next_state in Sucessors.sucessor(current): for next_state in successor(current):
if not (next_state in explored): if next_state not in explored:
explored.add(next_state) explored.add(next_state)
path.append(next_state) path2 = path + [next_state]
toDo.put(path) toDo.put(path2)
return "Error Path not found" 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