Class NeighborQueen

java.lang.Object
  |
  +--Queen
        |
        +--NeighborQueen

class NeighborQueen
extends Queen

Package-wide visible class. Located in file QueensOO.java. Represents a queen with her neighbor. Used by public class QueensOO.


Field Summary
protected  Queen neighbor
          immediate left neighbor of a Queen
 
Fields inherited from class Queen
column, row
 
Constructor Summary
NeighborQueen(int c, Queen n)
          Initializes a new NeighborQueen object.
 
Method Summary
protected  boolean advance()
          Advance one row if possible (realizes the backtracking)
 boolean findSolution()
          Tries to advance the Queen to a conflict free position.
protected  boolean predecCanAttack(Queen queen)
          Test whether this Queen (with position Queen.row, Queen.column) or any of its predecessors can attack another Queen
 void printSolution()
          Prints the position of the current Queen and all predecessors
 
Methods inherited from class java.lang.Object
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait
 

Field Detail

neighbor

protected final Queen neighbor
immediate left neighbor of a Queen
Constructor Detail

NeighborQueen

public NeighborQueen(int c,
                     Queen n)
Initializes a new NeighborQueen object.
Parameters:
n: - the left neighbor Queen
Method Detail

findSolution

public boolean findSolution()
Tries to advance the Queen to a conflict free position.
Overrides:
findSolution in class Queen
Returns:
true if the Queen is at or can be advanced to a conflict free position with all Queens left of it, false otherwise.
See Also:
advance()

advance

protected boolean advance()
Advance one row if possible (realizes the backtracking)
Overrides:
advance in class Queen
Returns:
true if the Queen and its neighbors can be positioned without conflict, false otherwise

predecCanAttack

protected boolean predecCanAttack(Queen queen)
Test whether this Queen (with position Queen.row, Queen.column) or any of its predecessors can attack another Queen
Overrides:
predecCanAttack in class Queen
Parameters:
queen - Queen to test
Returns:
true if attack is possible, false otherwise

printSolution

public void printSolution()
Prints the position of the current Queen and all predecessors
Overrides:
printSolution in class Queen