Question: JAVA - 8ht Queens - only 1 and only symetrical solution necessrary + given parti of code. Please finish code to be as image and

JAVA - 8ht Queens - only 1 and only symetrical solution necessrary + given parti of code. Please finish code to be as image and explain code as max possible.

JAVA - 8ht Queens - only 1 and only symetrical solution necessrary

int chessBoard[][] = {{ 0, 0, 0, 0,0, 0, 0, 0 },{ 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 },{ 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 },{ 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }}; --understandable

public class Main {

static void printMatrix(int chessBoard[][]) ----understandable

{ for (int outer = 0; outer

for (int inner = 0; inner

System.out.print(" " + chessBoard[outer][inner]+ " ");

System.out.println();

}//end inner loop

}//end outer loop

}//end method

static boolean checkStep(int chessBoard[][], int rows, int cols) { --confused why there are passed rows and cols, maybe it is easer to re-edit code?

int l, m; for (l = 0; l

if (chessBoard[rows][l] == 1)

return false;

} //end for

for (l = rows, j = cols;l >= 0 && m >= 0; l--, m--){

if (chessBoard[l][m] == 1)

return false;

}//end for

for (l = rows, m = cols; m >= 0 && l

if (chessBoard[l][m] == 1)

return false;

}//end for

return true;

}//end method

public static boolean solve8Queen(int chessBoard[][], int cols) { --please explain full method step by step

if (col >= 8){

return true;

}

for (int l = 0; l

if (checkStep(chessBoard, l, cols)) {

chessBoard[l][cols] = 1;

if (solve8Queen(chessBoard, cols + 1)){

return true;

}

chessBoard[i][cols] = 0;

}

}

return false;

}

public static void main(String args[]){

int chessBoard[][] = { { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }, { 0, 0, 0, 0,0, 0, 0, 0 }};

//call the solution

if (!solve8Queen(chessBoard, 0)) { -- how it could be easier to call out method?

System.out.print("Solution not found");

return;

}

printMatrix(chessBoard); }//end main method }//end class

so yes, if there is easier version to re-redit code - please, up to you. Only 1 possible solution necessary not for N queens.

p.s. code from chegg

The only symmetrical solution to the eight queens puzzle (up to rotation and reflection)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!