The millimeter-long soil-dwelling nematode Caenorhabditis elegans propels itself by producing undulations that propagate along its body and turns by assuming highly curved shapes. According to our recent study [V. Padmanabhan et al. , PLoS ONE7, e40121 (2012)10.1371/journal.pone.0040121] all these postures can be accurately described by a piecewise-harmonic-curvature model. We combine this curvature-based description with highly accurate hydrodynamic bead models to evaluate the normalized velocity and turning angles for a worm swimming in an unconfined fluid and in a parallel-wall cell. We find that the worm moves twice as fast and navigates more effectively under a strong confinement, due to the large transverse-to-longitudinal resistance-coefficient ratio resulting from the wall-mediated far-field hydrodynamic coupling between body segments. We also note that the optimal swimming gait is similar to the gait observed for nematodes swimming in high-viscosity fluids. Our bead models allow us to determine the effects of confinement and finite thickness of the body of the nematode on its locomotion. These effects are not accounted for by the classical resistive-force and slender-body theories.