I've already read this question, and done research on my question, but I find that I don't have a suitable answer yet.
I want to build a generic data structure in ruby with which I can implement any (2d, rectangular) maze-generating algorithm I see fit. To start, I'll be implementing Randomized Prim's and Depth-First Search, and later I will want to implement Sidewinder and others. The goal is to be able to generate a wide variety of different looking mazes. And FYI, a wall isn't a 'filled' cell - it's the divider between two adjacent cells and is either solid or not.
But the problem I face is that all the algorithms need to know about different things. Prim's, for instance, says to pick a Cell
and add its Walls
to a wall_list
. That's fine, I can start with this:
class Cell
def get_surrounding_walls
# some code
end
end
class Wall
@solid = true
def remove
@solid = false
end
end
wall_list = []
But now I start running into confusion about how to store specific details. Should I have a multi-dimensional array of cells? And do cells keep track of their own four walls? If I do that, then I have to multiply complexity when I toggle a Wall, as I need to get the neighboring cell's wall as well. If I get a cell to keep track of only, say, its RIGHT and DOWN walls, then I increase complexity in getting the status of the UP and LEFT walls.
If, on the other hand, cells and walls are maintained in separate lists, should I have one array for all walls, or one for UP/DOWN walls and one for LEFT/RIGHT walls? In the first case, it's easier to select a random wall, and query specific walls for their status, but harder to actually structure - walls don't line up nicely with a grid. And it makes it harder for a Cell to know about the walls that surround it.
Should I be tracking cells at all? Common sense says they need to be objects, because some later algorithms will require cells to know which set their in. But if I wanted to use some sort of Graph, like an Adjacency Matrix, then the whole structure seems set up to only track walls. Also, for large mazes, the matrix gets prohibitively large.
This is likely a case of Analysis Paralysis, but the fact remains that I don't know where to start.