diff --git a/Breath-First Search/breadth_first_search.py b/Breath-First Search/breadth_first_search.py deleted file mode 100644 index b24cdc96330435486e58fb1aa98e4c5a491e9cf8..0000000000000000000000000000000000000000 --- a/Breath-First Search/breadth_first_search.py +++ /dev/null @@ -1,19 +0,0 @@ -import queue - - -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 isgoal(current): - return path - for next_state in successor(current): - if next_state not in explored: - explored.add(next_state) - path2 = path + [next_state] - toDo.put(path2) - return "Error Path not found" diff --git a/Depth-First Search/Depth_first.py b/Depth-First Search/Depth_first.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/A-Star/A_Star.py b/Search_Algorithms/A_Star.py similarity index 100% rename from A-Star/A_Star.py rename to Search_Algorithms/A_Star.py diff --git a/Search_Algorithms/Search_Algorithms.py b/Search_Algorithms/Search_Algorithms.py new file mode 100644 index 0000000000000000000000000000000000000000..dbeae1269566e24da40aa315faaac46404bc8e8c --- /dev/null +++ b/Search_Algorithms/Search_Algorithms.py @@ -0,0 +1,39 @@ +import queue +from collections import deque + + +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 isgoal(current): + return path + for next_state in successor(current): + if next_state not in explored: + explored.add(next_state) + path2 = path + [next_state] + toDo.put(path2) + return "Error Path not found" + + +def DepthFirstSearch(state, successor, isgoal): + """accepts start state, Please do not change this function""" + toDo = deque() + toDo.append([state]) + explored = {state} + while not toDo: + path = toDo.pop() + current = path[-1] + if isgoal(current): + return path + for next_state in successor(current): + if next_state not in explored: + explored.add(next_state) + path2 = path + [next_state] + toDo.append(path2) + return "Error Path not found" + diff --git a/Breath-First Search/Sucessors.py b/Search_Algorithms/Sucessors.py similarity index 100% rename from Breath-First Search/Sucessors.py rename to Search_Algorithms/Sucessors.py diff --git a/Breath-First Search/is_goal.py b/Search_Algorithms/is_goal.py similarity index 100% rename from Breath-First Search/is_goal.py rename to Search_Algorithms/is_goal.py diff --git a/Breath-First Search/solution testing.py b/Search_Algorithms/solution testing.py similarity index 98% rename from Breath-First Search/solution testing.py rename to Search_Algorithms/solution testing.py index 971dced11355d6d9ff470435a8f18f186486429c..669fa3d2261be95ce55cd5ce01f574328a505fe2 100644 --- a/Breath-First Search/solution testing.py +++ b/Search_Algorithms/solution testing.py @@ -1,4 +1,4 @@ -import breadth_first_search +import Search_Algorithms import Sucessors import is_goal