Answered step by step
Verified Expert Solution
Question
1 Approved Answer
N Queens C++ The N-Queens Problem is identical to the 8-Queens Problem except we vary the size of the board. So, we can find the
N Queens C++
The N-Queens Problem is identical to the 8-Queens Problem except we vary the size of the board. So, we can find the placement of queens on a 44 board (the 4Queens Problem) or a 99 board (the 9-Queens Problem), etc. Your solution to the N-Queens Problem will be implemented entirely in the class ChessBoard which will at minimum include: You should break additional functionality down into private helper methods, but do not add additional public methods. Specifications for the items in the UML diagram: boardPtr - pointer to a 2-dimensional character array on the heap which stores the board. If you need a refresher on how 2-D arrays on the heap work see here and scroll down to the section titled "Dynamic memory allocation for two-dimensional arrays." boardSize - Tracks the size of the board. Valid sizes are 4 through 12. For example, if boardSize is 10 the board is 1010. placeQueens (int column) - Implements the provided recursive pseudocode (see the end of this document) to find placements for the queens on the board. The call placeQueens (column) begins the search for a valid placement of a queen at the indicated column in row 0 . For instance, placeQueens (4) begins checking to see if a queen can be placed in row index 0 , column index 4 on the board. placequeens () returns true if a queen is successfully placed in column and all columns to the right of column. ChessBoard () - Default constructor which sets the default board size to 8 . ChessBoard (int) - Constructor which sets the board size to the given int. If the int 12 it sets the size to 12 . setsize (1nt) - Deletes the existing board and resets the board to be the size given. displayBoard () - Displays the board to the screen. Queens are displayed as a Q. Blank squares on the board should be displayed as a single *, Individual squares on the board display with 1 space between them. So, a 44 board is displayed as: Additional Requirements - ChesaBoard must be implemented as ChessBoard.h and ChessBoard.cpp. - Your ChessBoard must work with the supplied main.cpp. - You must implement placeQueens () recursively based on the algorithm given in the pseudocode at the end of this document. Iterative solutions or recursive solutions drastically different from the pseudocode will not be accepted. ALgorithm This is a modified version of the algorithm from the textbook. All rows have been considered in column without a successful queen placement. Backtrack by returning false. 1// end e1se I // end placeQueens ()Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started