Package nqueens.lab

Class DefaultImmutableQueenLocations

java.lang.Object
nqueens.lab.DefaultImmutableQueenLocations
All Implemented Interfaces:
ImmutableQueenLocations

@Immutable
public final class DefaultImmutableQueenLocations
extends java.lang.Object
implements ImmutableQueenLocations
Author:
__STUDENT_NAME__, Dennis Cosgrove (http://www.cse.wustl.edu/~cosgroved/)
  • Constructor Summary

    Constructors 
    Constructor Description
    DefaultImmutableQueenLocations​(int boardSize)  
  • Method Summary

    Modifier and Type Method Description
    DefaultImmutableQueenLocations createNext​(int row, int col)
    This method should create a new board state by adding a queen in the specified row and column to the queens in this current board.
    boolean equals​(java.lang.Object obj)  
    int getBoardSize()
    Chess boards are square.
    java.util.List<java.lang.Integer> getCandidateColumnsInRow​(int row)
    Given this instance's board state, return a list of columns which would be threat free in the specified row.
    java.util.Optional<java.lang.Integer> getColumnOfQueenInRow​(int row)
    This method should tell you which column a queen is in for a given row.
    int hashCode()  
    boolean isLocationThreatFree​(int row, int col)
    Checks to see whether the given square on the board is threat free.
    java.lang.String toString()  

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Constructor Details

  • Method Details

    • createNext

      public DefaultImmutableQueenLocations createNext​(int row, int col)
      Description copied from interface: ImmutableQueenLocations
      This method should create a new board state by adding a queen in the specified row and column to the queens in this current board.
      Specified by:
      createNext in interface ImmutableQueenLocations
      Parameters:
      row - The row where the next queen will be placed.
      col - The column where the next queen will be placed.
      Returns:
      the next board
    • getBoardSize

      public int getBoardSize()
      Description copied from interface: ImmutableQueenLocations
      Chess boards are square. The board size indicates both the number of rows on a board and, at the same time, the number of columns on the board. For a standard sized chess board, this would return 8.
      Specified by:
      getBoardSize in interface ImmutableQueenLocations
      Returns:
      The size of the board.
    • getColumnOfQueenInRow

      public java.util.Optional<java.lang.Integer> getColumnOfQueenInRow​(int row)
      Description copied from interface: ImmutableQueenLocations
      This method should tell you which column a queen is in for a given row. Note that each row can only have a single queen, so this method will return the column of that queen. For example, if a queen is placed in (row=2, column=3) then getColumnOfQueenInRow(2) would return Optional.of(3). If no queen is placed in row 2, then getColumnOfQueenInRow(2) would return Optional.empty().
      Specified by:
      getColumnOfQueenInRow in interface ImmutableQueenLocations
      Parameters:
      row - The row to look for a placed queen.
      Returns:
      the column of the queen in the given row, if she exists.
    • getCandidateColumnsInRow

      public java.util.List<java.lang.Integer> getCandidateColumnsInRow​(int row)
      Description copied from interface: ImmutableQueenLocations
      Given this instance's board state, return a list of columns which would be threat free in the specified row. For example, for an 8x8 board, if a single queen was placed in (row=0, column=4) then the candidate columns for row=1 would be [0,1,2,6,7]. The candidate columns for row=2 would be [0,1,3,5,7].
      Specified by:
      getCandidateColumnsInRow in interface ImmutableQueenLocations
      Parameters:
      row - The row
      Returns:
      a list of threat free columns
    • isLocationThreatFree

      public boolean isLocationThreatFree​(int row, int col)
      Description copied from interface: ImmutableQueenLocations
      Checks to see whether the given square on the board is threat free. Note: this method returns false if a queen is already in the specified row, even if she resides in the specified column.
      Specified by:
      isLocationThreatFree in interface ImmutableQueenLocations
      Parameters:
      row - The row of the square to check.
      col - The column of the square to check.
      Returns:
      true if there is are no queens on the board which could attack that location, otherwise false.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class java.lang.Object
    • equals

      public boolean equals​(java.lang.Object obj)
      Overrides:
      equals in class java.lang.Object