Automated shapeshifting for function recovery in damaged robots