Its easy if you have doors seperating the areas.

By passing a door or other "plane" you can always determine wich room
was entered and which one was left.
Then you only spwan into rooms that are not the current
or the one adjacent to the current.
(hence the invisible rooms)