public static int costFunction(TetrisBoard TB, int i, int j, int k, boolean DEBUG) {
    if (DEBUG) {
      System.out.println("cost fn ("+i+", "+j+", "+k+")");
      TetrisBoard.printTetromino(i);
    }
    
    int cost = Integer.MAX_VALUE;
    int ret = TB.dropTetromino(i,j,k,TB.tilemarker);
    if (ret >= 0) {
      int countLines = TB.countLines(); // number of full lines
      int hole       = TB.hole();       // number of holes
      // maximal height (value from 0 to BOARDH (exclusive), as seen from the bottom)
      int maxHeight  = TetrisBoard.BOARDH - (TB.maxHeight() - TetrisBoard.TMARGIN) - 1;
      // height at pos k
      int currHeight = TetrisBoard.BOARDH - (TB.getHeight(k) - TetrisBoard.TMARGIN) - 1; 
      // count for all rows (from left to right) in TetrisBoard.Board
      // number of changes from value 0 (empty) to a positive value (filled)
      int horizontalDiff = TB.horizontalDiff(); 
      // count for all columns (from top to bottom) in TetrisBoard.Board
      // number of changes from value 0 (empty) to a positive value (filled)
      int verticalDiff = TB.verticalDiff();
      // the cost function for a board configuration
      cost =  verticalDiff * 100 * 100 + (horizontalDiff+hole) * 100 + maxHeight * 80 + currHeight;
      if (!TB.filledlinebef && countLines == 1) cost += 100;
      if ((TB.filledlinebef && countLines >= 1) || countLines >= 2) {
        cost = 0;
      }
    }
    
    TB.deleteTile(TB.tilemarker);
    
    if (DEBUG) 
      System.out.println("cost " + cost);
    return cost;
  }