def run(): label_find_the_result.config(text="Result:") label_time.config(text="Time:") label_steps.config(text="Steps:") btn_run.config(state=tk.DISABLED) btn_reset.config(state=tk.DISABLED) radio_dfs.config(state=tk.DISABLED) radio_bfs.config(state=tk.DISABLED) radio_bestfs.config(state=tk.DISABLED) radio_hc.config(state=tk.DISABLED) algorithm = alg.get() res = "" steps = 0 time_start = time.time() if algorithm == 1: res = DFS.solve(puzzle_in, window) print("DFS: ", res) elif algorithm == 2: res = BFS.solve(puzzle_in, window) print("BFS: ", res) elif algorithm == 3: res = BestFirstSearch.solve(puzzle_in, window) print("Best First Search: ", res) elif algorithm == 4: res = HillClimbing.solve(puzzle_in, window) print("Hill Climbing: ", res) time_end = time.time() if res is None: solution = "No!" else: solution = "Yes!" steps = len(res) output(solution, time_end - time_start, steps) btn_run.config(state=tk.NORMAL) btn_reset.config(state=tk.NORMAL) radio_dfs.config(state=tk.NORMAL) radio_bfs.config(state=tk.NORMAL) radio_bestfs.config(state=tk.NORMAL) radio_hc.config(state=tk.NORMAL)
import sys sys.path.append('problems') sys.path.append('algorithms') from nqueens import NQueens from bfs import BFS if __name__ == "__main__": #added just for easy testing, change to True/False if you want/do not want pruning. do_prune = True problem = NQueens(9, do_prune) bfs = BFS() #added just for easy testing, change to True/False if you want/do not want all solutions. find_all_solutions = True bfs.solve(problem, find_all_solutions) #added so duplicate solutions will not be printed if find_all_solutions == False: bfs.print_solution() bfs.print_stats()