I have seen in the news lately that Egypt and Israel are digging water filled trenches, moats, to stop the digging of tunnels. I had assumed that medieval moats were to distance siege engines; were they actually to prevent tunnels?
There was a thread on this last week
Basically, the original castles were made of wood and dirt. A moat, besides creating a defensive trench, also provided the dirt used for the earthworks.
Later, when castles were made of stone and got bigger/awesomer/harder to attack, water moats had the additional utility of flooding tunnels and keeping bad guys further away.