# This program solves the Eight Queens problem. # This version prints a single solution. from ChessBoard import * # Places queens on the given board, # starting with the given column. # Returns True if successful and False if no solution found. def place_queens(board, col = 0): if not board.valid(): return False elif col >= board.size(): return True else: for row in range(board.size()): board.place(row, col) # choose if place_queens(board, col + 1): # explore return True board.remove(row, col) # un-choose return False def main(): size = int(input("Board size? ")) board = ChessBoard(size) if place_queens(board): print("One solution is as follows:") print(board) else: print("No solution found.") main()