diff --git a/Search_Algorithms/Search_Algorithms.py b/Search_Algorithms/Search_Algorithms.py index dbeae1269566e24da40aa315faaac46404bc8e8c..57c8331e150596f687f003b0f677fb499e6ff942 100644 --- a/Search_Algorithms/Search_Algorithms.py +++ b/Search_Algorithms/Search_Algorithms.py @@ -25,7 +25,7 @@ def DepthFirstSearch(state, successor, isgoal): toDo = deque() toDo.append([state]) explored = {state} - while not toDo: + while toDo: path = toDo.pop() current = path[-1] if isgoal(current): diff --git a/Search_Algorithms/solution testing.py b/Search_Algorithms/solution testing.py index 669fa3d2261be95ce55cd5ce01f574328a505fe2..63c1b2a59ef8d5284c2db9c11989735915a201ac 100644 --- a/Search_Algorithms/solution testing.py +++ b/Search_Algorithms/solution testing.py @@ -4,20 +4,22 @@ import is_goal # Maze Problem, note, the maze if fixed in the allowed state. -print(breadth_first_search.BreadthFirstSearch((4, 0), Sucessors.maze_successor, is_goal.is_goal_maze)) +# print(Search_Algorithms.BreadthFirstSearch((4, 0), Sucessors.maze_successor, is_goal.is_goal_maze)) # Sudoku -grid = ((5, 3, 0, 0, 7, 0, 0, 0, 0), - (6, 0, 0, 1, 9, 5, 0, 0, 0), - (0, 9, 8, 0, 0, 0, 0, 6, 0), - (8, 0, 0, 0, 6, 0, 0, 0, 3), - (4, 0, 0, 8, 0, 3, 0, 0, 1), - (7, 0, 0, 0, 2, 0, 0, 0, 6), - (0, 6, 0, 0, 0, 0, 2, 8, 0), - (0, 0, 0, 4, 1, 9, 0, 0, 5), +grid = ((1, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), + (0, 0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0, 8, 0, 0, 0, 0)) -sln = (breadth_first_search.BreadthFirstSearch(grid, Sucessors.sudoku_successor, is_goal.is_goal_sudoku)[-1]) +# sln = (Search_Algorithms.BreadthFirstSearch(grid, Sucessors.sudoku_successor, is_goal.is_goal_sudoku)[-1]) + +sln = (Search_Algorithms.DepthFirstSearch(grid, Sucessors.sudoku_successor, is_goal.is_goal_sudoku)[-1]) for rows in sln: print(rows) @@ -34,14 +36,16 @@ board = ((False, False, False, False, False, False, False, False, False), (False, False, False, False, False, False, False, False, False)) -sln = (breadth_first_search.BreadthFirstSearch(board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1]) +# sln = (Search_Algorithms.BreadthFirstSearch(board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1]) + +sln = (Search_Algorithms.DepthFirstSearch(board, Sucessors.queens_successor, is_goal.is_goal_queens)[-1]) output_tuple = tuple(tuple("Q" if value else "." for value in sln) for sln in sln) for rows in output_tuple: print(rows) - -puzzle = () - - -print(breadth_first_search.BreadthFirstSearch(puzzle, Sucessors.puzzle_successor, is_goal.is_goal_puzzle)[-1]) +# +# puzzle = () +# +# +# print(Search_Algorithms.BreadthFirstSearch(puzzle, Sucessors.puzzle_successor, is_goal.is_goal_puzzle)[-1])