This post has been updated with a comment from one of the lead scientists on the study.

You’re panting, trying to hold your breath. If that robot finds you, you’re toast. The door creaks open—and you shoot. You just blew the arm off the robot trying to kill you, but somehow it’s still coming! You fire again, and this time get a piece of its leg. Undaunted, it continues limping your way. As the robot descends, you curse the names of Antoine Cully and Jean-Baptiste Mouret.

That’s because Cully and Mouret are the scientists who led a group from Paris’s Pierre and Marie Curie University that may have just given robots the skill they need to beat humans in that dystopian future when the robot uprising begins.

These scientists have managed to create a new algorithm that lets robots keep working and “adapt to damage like natural animals,” according to the IEEE Spectrum.

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.