So I eventually capitulated and decided to re-write the whole dungeon generator object. I originally started writing the first version as a proof-of-concept anyway, so I guess the move isn't really THAT drastic. However, it's a big job as my virtually un-commented, disorganised "rough draft" first version was over 22,000 lines long.
The new version that I've been writing for the last eight days is all very nicely laid out, modular, and split into neat functions, etc. It is also extensively commented and explained in detail at every step. I'm actually finding it a real joy to work on this way. I guess when I first had the notion of making a game which writes its own levels intelligently, I figured I'd get about a third of the way through development and come to my frikking senses ;-P but no, when it first started to actually work I got over-excited and decided to see the whole thing through to the end, and hey, the game is now going to be totally awesome because of it, and it has actually redirected the development process in a whole new direction.
So now that this dungeon generator is working, I'm re-doing it the way that it should have been done in the first place. By doing it in this new, neat and organised way, I will hopefully be able to find, fix and sort out the one or two nasty bugs that were sticking with it the whole time that I couldn't quite find. Mind you... Looking through the code in version 1, it's a miracle that I was able to find anything at all... So messy!
Anyway, I'm about a quarter of the way through the re-write, so as I get further I'll keep the updates posted.