def calculate_solution(pieces, full_board, short_board, save_db, get_db): """The eight queens puzzle in Python.""" t = time.process_time() queens = NQueens(pieces, full_board, short_board, save_db, get_db) solutions = queens.solve() print(f"Found {solutions} solutions.") elapsed_time = timedelta(seconds=time.process_time() - t) print(f"Time elapsed (hh:mm:ss.ms) {elapsed_time}")
def main(): n = get_size_input() type = get_type_algorithm() problem = NQueens(n, type) problem.print_solutions() # solutions = problem.solutions store_solutions(n, problem.solutions)
def main(): print('.: N-Queens Problem :.') size = int(input('Please enter the size of board: ')) n_queens = NQueens(size) dfs_solutions = n_queens.solve_dfs() bfs_solutions = n_queens.solve_bfs() for i, solution in enumerate(dfs_solutions): print('DFS Solution %d:' % (i + 1)) n_queens.print(solution) for i, solution in enumerate(bfs_solutions): print('BFS Solution %d:' % (i + 1)) n_queens.print(solution) print('Total DFS solutions: %d' % len(dfs_solutions)) print('Total BFS solutions: %d' % len(bfs_solutions))
def main(): print('.: N-Queens Problem :.') size = int(input('Please enter the size of board: ')) print_solutions = input('Do you want the solutions to be printed (Y/N): ').lower() == 'y' n_queens = NQueens(size) dfs_solutions = n_queens.solve_dfs() bfs_solutions = n_queens.solve_bfs() if print_solutions: for i, solution in enumerate(dfs_solutions): print('DFS Solution %d:' % (i + 1)) n_queens.print(solution) for i, solution in enumerate(bfs_solutions): print('BFS Solution %d:' % (i + 1)) n_queens.print(solution) print('Total DFS solutions: %d' % len(dfs_solutions)) print('Total BFS solutions: %d' % len(bfs_solutions))
def test_seven_queens(): pieces = 7 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 40
def test_n_queens(self): """Create two test cases instances for the N Queens Problem.""" agent1, agent2 = NQueens(5), NQueens(8) self.assertIn((3, 1, 4, 2, 0), agent1.run()) self.assertIn((7, 3, 0, 2, 5, 1, 6, 4), agent2.run())
def test_one_queen(): pieces = 1 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 1
def test_twelve_queens(): pieces = 12 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 14200
def test_eleven_queens(): pieces = 11 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 2680
def test_solutions_backtracking_ten(): problem = NQueens(10, 2) assert problem.solutions_count == 724 assert len(problem.solutions) == 724
def test_solutions_brute_force_nine(): problem = NQueens(9, 1) assert problem.solutions_count == 352 assert len(problem.solutions) == 352
def test_solutions_backtracking_eight(): problem = NQueens(8, 2) assert problem.solutions_count == 92 assert len(problem.solutions) == 92
def test_six_queens(): pieces = 6 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 4
def test_five_queens(): pieces = 5 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 10
def test_four_queens(): pieces = 4 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 2
def test_three_queens(): pieces = 3 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 0
def test_two_queens(): pieces = 2 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 0
def test_solutions_brute_force_ten(): problem = NQueens(10, 1) assert problem.solutions_count == 724 assert len(problem.solutions) == 724
def test_eigth_queens(): pieces = 8 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 92
def test_solutions_backtracking_nine(): problem = NQueens(9, 2) assert problem.solutions_count == 352 assert len(problem.solutions) == 352
def test_nine_queens(): pieces = 9 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 352
def test_solutions_brute_force_eight(): problem = NQueens(8, 1) assert problem.solutions_count == 92 assert len(problem.solutions) == 92
def test_ten_queens(): pieces = 10 queens = NQueens(pieces) solutions = queens.solve() assert solutions == 724