Question
C++ NON-ATTACKED SQUARES In chess, the queen attacks all squares that are in the column, row, and diagonals on which the queen lies, as shown
C++
NON-ATTACKED SQUARES
In chess, the queen attacks all squares that are in the column, row, and diagonals on which the queen lies, as shown in this diagram:
A chessboard consists of 8 rows and 8 columns. Starting with an empty chessboard, we can say that there exist 64 non-attacked squares. If we place a queen at the location given above ([4][4], considering the upper left hand corner [0][0]), we are now left with 36 non-attacked squares.
If we place another queen on the board, we will be left with fewer non-attacked squares. This is a variation on the N-Queens problem. Consider first the problem if you have the positions of 5 queens, one at a time. After the position of each queen is given, you will output the number of non-attacked squares left.
INPUT: Your program should accept two integers, separated by a space, representing the row and column in which the queen is to be placed. Your program should allow for five sets of input positions.
OUTPUT: After each queens position is accepted on input, you must output the number of non-attacked squares on the chessboard in the form: XX non-attacked squares left. EXAMPLE: Enter queens position: 4 4
36 non-attacked squares left. Enter queens position: 2 3
20 non-attacked squares left. Enter queens position: 3 6
12 non-attacked squares left. Enter queens position: 7 0
5 non-attacked squares left. Enter queens position: 2 6
4 non-attacked squares left.
In addition to the above your program should prompt for the number of queens to be placed. Dont allow more than 8 (by default after that everything is covered.)
Edit the positions for valid locations (0 7) or ( 1 8) if you prefer.
After the last queen is positioned, display the chessboard showing the positions of the Queen as Q, the attacked positions as +, and the non-attacked positions as Then display the final number of queens used and the number of non-attacked positions.
You must use functions to handle some of the chores, such as displaying the board and finding the attacked squares. Complete all the tasks, indicated, using functions, the data structure of your choice, commented & readable code, and a solid programming algorithm. Work out how to do the diagonals in a single routine (multiple passes through the routine are fine.)
comments should be meaningful and not line by line, but based on routines.
Sample run (with only 1 queen positioned)
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