Learning And Motion Planning For Gait-Based Legged Robots