Class Board

java.lang.Object
  extended by Board

public class Board
extends java.lang.Object

Stores information relevant to solving the n queens problem of placing n queens on an n-by-y board.


Constructor Summary
Board(int size)
          Constructs an empty size-by-size board.
 
Method Summary
 void place(int row, int col)
          Places a queen at position (row, col).
 void print()
          Displays the current board to System.out.
 void remove(int row, int col)
          Removes the queen at position (row, col).
 boolean safe(int row, int col)
          Returns true if it is safe to place a queen at position (row, col).
 int size()
          Returns the size of the board.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Board

public Board(int size)
Constructs an empty size-by-size board.

Parameters:
size - the size of the board.
Throws:
java.lang.IllegalArgumentException - if size is less than 1.
Method Detail

safe

public boolean safe(int row,
                    int col)
Returns true if it is safe to place a queen at position (row, col).

Parameters:
row - row of position to check.
col - column of position to check.
Returns:
true if it is safe to place a queen at position (row, col).
Throws:
java.lang.IllegalArgumentException - if row and col do not represent a legal board position.

place

public void place(int row,
                  int col)
Places a queen at position (row, col).

Parameters:
row - row of position to check.
col - column of position to check.
Throws:
java.lang.IllegalArgumentException - if it is not safe to place a queen at the given position.

remove

public void remove(int row,
                   int col)
Removes the queen at position (row, col).

Parameters:
row - row of position to check.
col - column of position to check.
Throws:
java.lang.IllegalArgumentException - if there is no queen at the given position.

size

public int size()
Returns the size of the board.

Returns:
the size of the board.

print

public void print()
Displays the current board to System.out.