A semi-analytical solution to the forward-reverse shock hydrodynamics of the gamma-ray burst afterglow