@Test public void testN() { Queens q = new Queens(); for (Board board : q.findSolution(8).all()) { if (!board.isFull()) continue; int arr[] = board.pos; System.out.println(board); for (int y = 0; y < arr.length; y++) { for (int x = 0; x < arr.length; x++) { System.out.print((arr[x] == y) ? "Q " : "_ "); } System.out.println(); } System.out.println(); } }
public static void main(String[] args) { int row; // the array needed by the 8-Queens algorithm int[] queenList = new int[8]; // board will display the solution ChessBoard board = new ChessBoard(); Scanner keyIn = new Scanner(System.in); // enter a starting row for queen in column 0 System.out.print("Enter row for queen in column 0: "); row = keyIn.nextInt(); System.out.println(); // see if there is a solution if (Queens.queens(queenList, row)) { // insert the solution into the chessboard board.setQueens(queenList); // display the solution board.drawBoard(); } else System.out.println("No solution"); }