St Andrews Castle is a ruin located in the coastal Royal Burgh of St Andrews in Fife, Scotland. The castle sits on a rocky promontory overlooking a small beach called Castle Sands and the adjoining North Sea. There has been a castle standing at the site since the times of Bishop Roger (1189–1202), son of the Earl of Leicester. It housed the burgh’s wealthy and powerful bishops while St Andrews served as the ecclesiastical centre of Scotland during the years before the Protestant Reformation. In their Latin charters, the Archbishops of St Andrews wrote of the castle as their palace, signing, "apud Palatium nostrum." The castle's grounds are now maintained by Historic Environment Scotland as a scheduled monument. The site is entered through a visitor centre with displays on its history. Some of the best surviving carved fragments from the castle are displayed in the centre, which also has a shop. Wars of Scottish Independence During the Wars of Scottish Independence, the castle was destroyed and rebuilt several times as it changed hands between the Scots and the English. Soon after the sack of Berwick in 1296 by Edward I of England, the castle was taken and made ready for the English king in 1303. In 1314, however, after the Scottish victory at Bannockburn, the castle was retaken and repaired by Bishop William Lamberton, Guardian of Scotland, a loyal supporter of King Robert the Bruce. The English had recaptured it again by the 1330s and reinforced its defences in 1336, but were not successful in holding the castle. Sir Andrew Moray, Regent of Scotland in the absence of David II, recaptured it after a siege lasting three weeks. Shortly after this, in 1336–1337, it was destroyed by the Scots to prevent the English from once again using it as a stronghold. It remained in this ruined state until Bishop Walter Trail rebuilt it at the turn of the century. His castle forms the basis of what can be seen today. He completed work on the castle in about 1400 and died within its walls in 1401. Home to kings Several notable figures spent time in the castle over the next several years. James I of Scotland (1406–1437) received part of his education from Bishop Henry Wardlaw, the founder of St Andrews University in 1410. A later resident, Bishop James Kennedy, was a trusted advisor of James II of Scotland (1437–1460).