The paper deals with a free gait generation algorithm for the straight line motion of a multi-legged walking robot in rough terrain. This method employs a heuristic graph search procedure because of the huge searching space of legged locomotion. In advance, deadlock situation and inefficiencies are avoided. This algorithm generates only statically stable walking of 6 legs robot. Footholds, stability constraint and kinematic constraint are considered when gaits are generated. This method does not consider the choice of the leg grounding point. The choice of leg grounding point is consider in other method. The paper includes verification experiments in a simulator.