For decades, mankind has been dreaming of colonizing the Moon and Mars. This idea raises various scientific, technological and economic challenges. In 2009, lunar probe discovered moon cave, which may be optimal base for a habitable base protected from radiation. First exploration stages may include robotic mission. In this work authors designed algorithms that implement automatic robot rescue if communication was lost. A new method of measuring the efficiency of the rescue algorithm was developed — a complex parameter that includes the time to search for a communication site and the amount of energy consumed. The algorithms were tested and verified using computer simulation and using the physical robot developed in this work.