import java.io.*; /** * This class is used to solve a generalized version of the * Eight Queens Problem. */ public class QueensProblem { public static final int MAX_DIMEN = 12; public static final int MIN_DIMEN = 2; public static final int DEFAULT_DIMEN = 8; private int dimen; private boolean[][] board; //--------------------------------------------------------------- public QueensProblem(int inDimen) { if ((inDimen < MIN_DIMEN) || (inDimen > MAX_DIMEN)) { dimen = DEFAULT_DIMEN; } // if else { dimen = inDimen; } // else board = new boolean[dimen][dimen]; } // constructor QueensProblem(int) //--------------------------------------------------------------- public void addQueen(int row, int col) { if ((row < 0) || (row >= dimen) || (col < 0) || (col >= dimen)) { System.out.println("Bad queen position: (" + row + "," + col + ")"); } // if else if (board[row][col]) { System.out.println("Valid board position, but already occupied"); } // else if else { board[row][col] = true; } // else } // addQueen(int,int) //--------------------------------------------------------------- public void removeQueen(int row, int col) { if ((row < 0) || (row >= dimen) || (col < 0) || (col >= dimen)) { System.out.println("Bad queen position: (" + row + "," + col + ")"); } // if else if (!board[row][col]) { System.out.println("Valid board position, but no queen to remove"); } // else if else { board[row][col] = false; } // else } // removeQueen(int,int) //--------------------------------------------------------------- public void printBoard() { int row, col; //--- Print a bunch of blank lines to move old board off screen --- for (int i = 0; i < 10; i++) { System.out.println("\n"); } // for i // FILL IN HERE } // printBoard() //--------------------------------------------------------------- /** * Prints "YES, two or more queens can attack each other." if any two * queens are lined up horizontally, vertically, or diagonally. * Prints "NO, there are no attacks." otherwise. */ public void checkForAttacks() { // FILL IN HERE } // checkForAttacks() //--------------------------------------------------------------- } // class QueensProblem