public void setPiece(Piece piece, Point p) {
    final Square sq = squares[p.getX()][p.getY()];
    sq.setPiece(piece);

    // Keep track of the kings
    if (piece == WHITE_KING && whiteKing != sq) {
      whiteKing.setPiece(null);
      whiteKing = sq;
    } else if (piece == BLACK_KING && blackKing != sq) {
      blackKing.setPiece(null);
      blackKing = sq;
    }
  }
 /**
  * Returns the list of pieces that are attacking the king of <code>color</code> or
  * <code>null</null> if king is not in check.
  *
  * @param color King's color.
  * @param toKing King's location on the board.
  * @return The list of pieces attacking king or <code>null</code> if not in check.
  */
 public List<Square> kingAttackers(Color color, Point toKing) {
   List<Square> result = null;
   final Color opponent = color.getOpponentColor();
   Iterator<Square> iter = getIterator(opponent);
   while (iter.hasNext()) {
     final Square square = iter.next();
     if (square.getPiece().isLegalMove(square.getPoint(), toKing, this)) {
       if (result == null) {
         result = new ArrayList<>();
       }
       result.add(square);
     }
   }
   return result;
 }