@Override
    public int update(int h, int dRow, int dCol) {    
        int now = 0;
        int old = 0;
        if (dCol == 0) {
            int numOwnRow = puzzle.lastMove / 4;
            if (puzzle.getEmptyRow() == numOwnRow) {
                now = calHorizontal(numOwnRow);
                puzzle.setCell(numOwnRow, puzzle.getEmptyCol(), puzzle.getLastMove());
                old = calHorizontal(numOwnRow);
                puzzle.setCell(numOwnRow, puzzle.getEmptyCol(), puzzle.getEmpty());
            } else {
                if (puzzle.getEmptyRow() - dRow == numOwnRow) {
                    now = calHorizontal(numOwnRow);
                    puzzle.setCell(numOwnRow, puzzle.getEmptyCol(), puzzle.getEmpty());
                    old = calHorizontal(numOwnRow);
                    puzzle.setCell(numOwnRow, puzzle.getEmptyCol(), puzzle.getLastMove());
                }
            }       
        } else {
            int numOwnCol = puzzle.lastMove % 4;
            if (puzzle.getEmptyCol() == numOwnCol) {
                now = calVertical(numOwnCol);
                puzzle.setCell(puzzle.getEmptyRow(), numOwnCol, puzzle.getLastMove());
                old = calVertical(numOwnCol);
                puzzle.setCell(puzzle.getEmptyRow(), numOwnCol, puzzle.getEmpty());
            } else {
                if (puzzle.getEmptyCol() - dCol == numOwnCol) {
                    now = calVertical(numOwnCol);
                    puzzle.setCell(puzzle.getEmptyRow(), numOwnCol, puzzle.getEmpty());
                    old = calVertical(numOwnCol);
                    puzzle.setCell(puzzle.getEmptyRow(), numOwnCol, puzzle.getLastMove());
                }
            }
        }
        return h + md.update(0, dRow, dCol) + now - old;      
    }