assuming you can represent as a 2D grid (array);
make a list if the castle walls when the user places them.
work through the list from start to finish, checking each wall part is a "legal" one next the the last.
then when you to the last entry, check to see if it´s next to the first one.. if it is, the caste is closed.
make a list if the castle walls when the user places them.
work through the list from start to finish, checking each wall part is a "legal" one next the the last.
then when you to the last entry, check to see if it´s next to the first one.. if it is, the caste is closed.