def test_solve_N_x_N(self, board_size, nb_soluce): board = generate_board(board_size) boards = solve_n_queen_all_soluce(board_size, board) assert len(boards) == nb_soluce for soluce in boards: is_a_soluce, nb_queen = is_soluce(board_size, soluce) assert is_a_soluce assert nb_queen == board_size
def solve_n_queen_big(board_size: int, board: Chessboard) -> tuple[Chessboard, bool]: solution = None retries = 10 while solution is None: if retries < 1: break solution = main(board_size, board, 100) retries -= 1 return solution, utils.is_soluce(board_size, solution)[0]
def test_solve_N_x_N_with_small_func(self, board_size): board = generate_board(board_size) t1 = time.time() board, solved = solve_n_queen_small(board_size, board) assert solved t2 = time.time() print( f"\nTest of size {board_size} took {t2 - t1} seconds to be solved") is_a_soluce, nb_queen = is_soluce(board_size, board) assert is_a_soluce assert nb_queen == board_size
def main(board_size: int, board: Chessboard, max_iterations: int = 0) -> Chessboard: it = 1 board = init(board_size, board) while not utils.is_soluce(board_size, board)[0]: next_queen = conflicted_queen(board_size, board) board = repair(board_size, board, next_queen) it += 1 # utils.print_board(N, board) # print(f'it #{it}') if 0 < max_iterations < it: board = None break return board
def test_is_not_soluce(self): board = self.get_wrong_board_full() is_a_soluce, nb_queen = is_soluce(4, board) assert not is_a_soluce assert nb_queen == 4
def test_is_soluce_not_full(self): board = self.get_good_board_not_full() is_a_soluce, nb_queen = is_soluce(4, board) assert not is_a_soluce assert nb_queen == 3
def test_is_soluce_soluce(self): board = self.get_board_soluce() is_a_soluce, nb_queen = is_soluce(4, board) assert is_a_soluce assert nb_queen == 4
def test_is_soluce_empty(self): board = generate_board(4) is_a_soluce, nb_queen = is_soluce(4, board) assert not is_a_soluce assert nb_queen == 0