Package nqueens.core

Interface ImmutableQueenLocations

All Known Implementing Classes:
DefaultImmutableQueenLocations

public interface ImmutableQueenLocations
Author:
Dennis Cosgrove (http://www.cse.wustl.edu/~cosgroved/)
  • Method Summary

    Modifier and Type Method Description
    ImmutableQueenLocations 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.
    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.
    boolean isLocationThreatFree​(int row, int col)
    Checks to see whether the given square on the board is threat free.
  • Method Details

    • getBoardSize

      int getBoardSize()
      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.
      Returns:
      The size of the board.
    • getColumnOfQueenInRow

      java.util.Optional<java.lang.Integer> getColumnOfQueenInRow​(int row)
      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().
      Parameters:
      row - The row to look for a placed queen.
      Returns:
      the column of the queen in the given row, if she exists.
    • isLocationThreatFree

      boolean isLocationThreatFree​(int row, int col)
      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.
      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.
    • getCandidateColumnsInRow

      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. 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].
      Parameters:
      row - The row
      Returns:
      a list of threat free columns
    • createNext

      ImmutableQueenLocations 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.
      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