示例#1
0
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}")
示例#2
0
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)
示例#3
0
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))
示例#4
0
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))
示例#5
0
def test_seven_queens():
    pieces = 7
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 40
示例#6
0
 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())
示例#7
0
def test_one_queen():
    pieces = 1
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 1
示例#8
0
def test_twelve_queens():
    pieces = 12
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 14200
示例#9
0
def test_eleven_queens():
    pieces = 11
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 2680
示例#10
0
def test_solutions_backtracking_ten():

    problem = NQueens(10, 2)
    assert problem.solutions_count == 724
    assert len(problem.solutions) == 724
示例#11
0
def test_solutions_brute_force_nine():

    problem = NQueens(9, 1)
    assert problem.solutions_count == 352
    assert len(problem.solutions) == 352
示例#12
0
def test_solutions_backtracking_eight():

    problem = NQueens(8, 2)
    assert problem.solutions_count == 92
    assert len(problem.solutions) == 92
示例#13
0
def test_six_queens():
    pieces = 6
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 4
示例#14
0
def test_five_queens():
    pieces = 5
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 10
示例#15
0
def test_four_queens():
    pieces = 4
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 2
示例#16
0
def test_three_queens():
    pieces = 3
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 0
示例#17
0
def test_two_queens():
    pieces = 2
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 0
示例#18
0
def test_solutions_brute_force_ten():

    problem = NQueens(10, 1)
    assert problem.solutions_count == 724
    assert len(problem.solutions) == 724
示例#19
0
def test_eigth_queens():
    pieces = 8
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 92
示例#20
0
def test_solutions_backtracking_nine():

    problem = NQueens(9, 2)
    assert problem.solutions_count == 352
    assert len(problem.solutions) == 352
示例#21
0
def test_nine_queens():
    pieces = 9
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 352
示例#22
0
def test_solutions_brute_force_eight():

    problem = NQueens(8, 1)
    assert problem.solutions_count == 92
    assert len(problem.solutions) == 92
示例#23
0
def test_ten_queens():
    pieces = 10
    queens = NQueens(pieces)
    solutions = queens.solve()
    assert solutions == 724