 The royal court eventually moved to Madrid and the Alcázar then served as a state prison for almost two centuries before King Charles III founded the Royal Artillery School in 1762.It served this function for almost a hundred years until March 6, 1862 where a fire badly damaged most of the roofs.It was only in 1882 that the damaged roofs of the building were slowly restored to their original state, thanks to the existence of engravings made by José María Avrial in 1839.