diff --git a/Breath-First Search/breadth_first_search.py b/Breath-First Search/breadth_first_search.py index 038881fd4f9f2c827e1da355c96d9156c4cab959..b24cdc96330435486e58fb1aa98e4c5a491e9cf8 100644 --- a/Breath-First Search/breadth_first_search.py +++ b/Breath-First Search/breadth_first_search.py @@ -1,21 +1,19 @@ 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"