Question: This is a part of the code form the fancy 8 queens problem. If you nee the entire code please let me know and i




This is a part of the code form the fancy 8 queens problem. If you nee the entire code please let me know and i will update the question.
What is the point of for loops and if statement in the bool ok function? What is it checking for? I used the bool ok function for the 1D 8 queens but this fancy 8 queens is a 2D array so why do we need this check? I would appreciate an in depth response. I appreciate any help thank you
\} // Create 2 more boxes to represent the queens, by drawing a picture of each queen in the 2D array. static box bq ={ \{white, white, white, white, white, white, white }, \{white, black, white, black, white, black, white\}, \{white, black, black, black, black, black, white\}, \{white, black, black, black, black, black, white\}, \{white, white, white, white, white, white, white\} \}; static box wq ={ \{black, black, black, black, black, black, black }, \{black, white, black, white, black, white, black\}, \{black, white, white, white, white, white, black\}, \{black, white, white, white, white, white, black\}, \{black, black, black, black, black, black, black\} \}; // Fill board with pointers to bb and wb in alternate positions. for (i=0;i=0){// NEXT COL: c++; // Move to the next column if (c>7) \{ // If you have passed the last column, a solution is found print (q);// Call the print function and backtrack c--; 3 else q[c]=1;// set to 1 so in inner loop you can start q[c] from 0 while (c>=0){// NEXT ROW: q[c]++;// Move to the next row \} // Create 2 more boxes to represent the queens, by drawing a picture of each queen in the 2D array. static box bq ={ \{white, white, white, white, white, white, white }, \{white, black, white, black, white, black, white\}, \{white, black, black, black, black, black, white\}, \{white, black, black, black, black, black, white\}, \{white, white, white, white, white, white, white\} \}; static box wq ={ \{black, black, black, black, black, black, black }, \{black, white, black, white, black, white, black\}, \{black, white, white, white, white, white, black\}, \{black, white, white, white, white, white, black\}, \{black, black, black, black, black, black, black\} \}; // Fill board with pointers to bb and wb in alternate positions. for (i=0;i=0){// NEXT COL: c++; // Move to the next column if (c>7) \{ // If you have passed the last column, a solution is found print (q);// Call the print function and backtrack c--; 3 else q[c]=1;// set to 1 so in inner loop you can start q[c] from 0 while (c>=0){// NEXT ROW: q[c]++;// Move to the next row
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
