2005 Challenge Problem #5   (The Queens Problem)


There is a well-known puzzle that involves trying to place 8 queens on an 8x8 chess board so that no queen
can attack any other queen. (Recall that a queen can attack any piece located in the same row, the same column,
or either of the two diagonals passing through the queen's position.) For this challenge problem you will complete
code that implements a generalized version of this puzzle.

Look over the code in the file QueensProblem.java that has been provided. An object of class QueensProblem
uses a 2-D array to represent a chess board that can be as small as 2x2 and as large as 12x12. The method addQueen
allows the user to insert a queen at any position (note that rows and columns are numbered starting at 0), and the
method removeQueen allows the user to delete queens.

You are required to complete the methods printBoard and checkForAttacks. The method checkForAttacks
prints out "YES, two or more queens can attack each other." if any two queens are lined up horizontally,
vertically, or diagonally. Otherwise it prints out "NO, there are no attacks.". The method printBoard prints
the board to the output window. For example, a 5x5 board with queens in positions (0,3), (2,4), and (3,1) looks like:


---------------------
|   |   |   | Q |   |
---------------------
|   |   |   |   |   |
---------------------
|   |   |   |   | Q |
---------------------
|   | Q |   |   |   |
---------------------
|   |   |   |   |   |
---------------------


Note that horizontal lines are created using hyphens ('-'), and the inside of each square consists of the three characters
space-space-space (three spaces) if the square is empty, or space-Q-space if the square contains a queen.