So here's my base map:
(It won't necessarily be 5x5, just using this as an example.)
It's kinda boring the way it is with all the rooms connected. I want it to be more of a randomly generated labyrinth, where every room is accessible like so:
I've tried setting the hallways randomly:
foreach(Room r)
{
r.northWall = randomBoolean();
r.southWall = randomBoolean();
r.eastWall = randomBoolean();
r.westWall = randomBoolean();
}
But that almost always ends up with rooms that you're unable to go to, like this:
And often some rooms have no hallways at all. I tried saying each room must have a minimum of 2 hallways, but it still doesn't fix the problem that sometimes there an inaccessible areas.
How should I go about doing this? I'm not too worried about the speed, as long as it's not ridiculously slow (Some levels will have 100+ rooms).
randomInt(1,4)
other rooms in random directions until doing a flood fill hits all squares. Everything is guaranteed to be connected but depending on your use case, it might not be a very interesting map... – Anko Dec 09 '13 at 22:27