Once damaged, the robots will start testing out different limb combinations to figure out how to keep walking forward. Each experiment feeds the robot’s decision on how to keep moving—once it finds one that works well enough, it will carry on its merry way.

Mouret told Quartz that he hopes the team’s work will make it easier for robots to keep working in dangerous emergency situations, such as finding survivors after an earthquake, putting out forest fires, or shutting down a nuclear plant after a meltdown. “They can be trained to be dangerous,” Mouret said of robots, but “they can also be our best friends!”

In the video, a six-legged robot finds a new way to walk after one leg is damaged in just 40 seconds. The robot can even figure out how to keep going when it’s completely missing two limbs. ”It almost looks like a wounded animal, limping away,” the video says.

The scientists also tested out their algorithm on an arm-shaped robot to see if it could adapt if one of the motors that control its bending movement stopped working. The algorithm worked just as well as it did on the six-legged robot. According to IEEE, this research suggests that the algorithm could work on any robot with enough “degrees of freedom”—essentially limbs or joints—to adapt the way it moves.

For the experiment, the scientists broke and even ripped off their test robots’ limbs to test their adaptability. This seems to be part of a growing trend of scientists abusing robots—Boston Dynamics released a video in February showing how its robots deal with being kicked.

Hopefully this treatment of robots won’t come back to bite—or kick—us.

📬 Sign up for the Daily Brief

Our free, fast, and fun briefing on the global economy, delivered every weekday morning.