/** * This code takes a board input where the upper left is (1,1) and the lower right is (8,8). It * then displays the board and gives the queens using those coordinates. The calculations are done * as if the upper left is (0,0) and the lower right is (7,7) */ public static void EightQueens(int a, int b) { ChessBoard temp = new ChessBoard(); temp.copy(board); if (board.getSpace(a, b) == " ") { if (board.queenAmount() != 8) { board.placeQueen(a, b); // place queen for (int i = 0; i < 8; i++) for (int j = 0; j < 8; j++) { // count++; //for checking total calculations if (board.getSpace(i, j) != " ") { } // System.out.println( "cannot place queen at ("+i+","+j+")"); else EightQueens(i, j); } if (board.queenAmount() != 8) board.copy(temp); // retrace steps to the most previous bord } } /** * The next two sections of code change the solutions from a (0,0-7,7) scale to the "Layman's * scale" of (1,1-8,8) */ if (board.queenAmount() == 8) System.out.println("Queen location: (" + (a + 1) + "," + (b + 1) + ")"); if (m == a && b == n) { System.out.println("Initial placement (" + (a + 1) + "," + (b + 1) + ")"); // the next line shows the amount of computations the program took to calculate the solution // total+=count; board.display(); } }
/** * This methods does calculations using a chessboard as if the upper left corner was (0,0) and the * lower right corner was (7,7). It then displays the board and the queen locations using standard * chessboard identifications. */ public static void letterEightQueens(int a, int b) { ChessBoard temp = new ChessBoard(nByn); temp.copy(board); if (board.getSpace(a, b) == " ") { if (board.queenAmount() != nByn) { board.placeQueen(a, b); // place queen for (int i = 0; i < nByn; i++) for (int j = 0; j < nByn; j++) { // count++; //for checking total calculations if (board.getSpace(i, j) != " ") { } // System.out.println( "cannot place queen at ("+i+","+j+")"); else letterEightQueens(i, j); } if (board.queenAmount() != nByn) board.copy(temp); // retrace steps to the most previous bord } } /** * The next two sections of code change the integer solutions to the character solution, namely, * converts from a (0,0-7,7) scale to an (a1-h8) scale */ if (board.queenAmount() == nByn) // if there are 8 queens on the board System.out.println("Queen location: " + (char) (b + 97) + (nByn - a)); if (m == a && b == n) { System.out.println("Initial placement " + (char) (b + 97) + (nByn - a)); // the next line shows the amount of computations the program took to calculate the solution // total+=count; board.display(); } }