Intelligent robots that can adapt to injury, or even become more powerful under attack, are a mainstay of science fiction. Now scientists have developed the real-life version: robots that can “adapt like animals” to injuries and recover within minutes.

The ability for robots to cope with unforeseen challenges is seen as a crucial step towards the widespread use of smart machines everywhere from the home to the battlefield, but until now scientists have struggled to develop machines that work alone without human intervention.

Jeff Clune, a computer scientist at the University of Wyoming, said: “Everything we take for granted works so well because nature’s worked at it for so long. If we get a splinter in our heel, we just start walking on our tiptoes, we don’t even think about how we’re doing it.”

Clune and his colleagues have managed to reproduce this “animal-like” ability to adapt to injury in a six-legged walking robot and a mechanical arm designed to pick up objects.

Videos recorded by the researchers show the six-legged robot initially flailing helplessly like a squashed spider after the power is cut to one of its legs. But after trying out a variety of alternative strategies, within two minutes it has adopted an entirely new gait – something akin to a pounce – allowing it to proceed towards a target despite being damaged.

Crucially, the robots adapt through an “intelligent trial and error” strategy that allows them to cope with new challenges independently, rather than being pre-programmed to deal with every imaginable obstacle. This meant that the robots frequently surprised their makers with the solutions they came up with and in some cases their performance even improved following the damage, due to new strategies they devised.

“It definitely can produce unpredictable results,” said Clune. “In one of our examples, once the robot lost one of its legs it discovered a new, even faster way to walk.”

In another instance, the scientists challenged the robot to walk without any of its feet touching the ground – a command they assumed it would fail at. “It flipped over on its back and walked with its elbows,” Clune said. “It can be very creative.”

Similarly, the mechanical arm quickly learned to cope with several of its motors being switched off.

The idea of an adaptable robot with the potential to become more powerful over time may have echoes of a sinister science fiction plot. In Star Trek, the Borg collective of robots, declares: “Your biological and technological distinctiveness will be added to our own. Resistance is futile.”

But in reality, Clune says, scientists are still trying to overcome the basics of developing robots that can walk on uneven terrain in unknown weather conditions or handle delicate objects.

“The things that are easiest for humans are the hardest for robots,” he said. “That’s one of the startling things for AI research.”

The study, published in the journal Nature, describes the new algorithms that underpin the advance, which are seen as a departure from previous approaches. Before the robot is deployed, it uses a computer simulation of its own body to create a detailed map of the types of movements it can make – something the researchers describe as the robot’s “simulated childhood”.

“If you watch children play, they work out how their body works by moving in all different ways,” said Clune. “This means when we’re damaged we have intuitions about different ways to move.”

Similarly, once the robot is damaged, it falls back on its map of behaviours that it can perform and uses this to guide a series of rapid experiments into new ways that it can move.

Antoine Cully, of the Pierre and Marie Curie University in France and the lead author, said: “Once damaged, the robot becomes like a scientist. Each behaviour it tries is like an experiment and, if one behaviour doesn’t work, the robot is smart enough to rule out that entire type of behaviour and try a new type.”