Formation of gas and ice giant planets