Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. 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 create a programming algorithm to plan how to handle this problem. 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. work out how to do the diagonals in a single routine (multiple passes through the routine are fine.) More points for elegance of code. Sample run (with only 1 queen positioned) Enter number of queens to be positioned: 1 Enter row, column separated by space (0-7) 4 4 36 non-attacked squares left. + - - - + - - - - + - - + - - + - - + - + - + - - - - + + + - - + + + + Q + + + - - - + + + - - - - + - + - + - - + - - + - - + With 1 queens only 36 positions were left to be attacked. Thanks for playing.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions