I'm trying to generate a maze in Objective-C. I've constructed a graph and connected all the edges (I think). However, I'm getting stuck when trying to make the actual maze.
Here's the code I'm using:
- (void)visitFromCurrentPoint:(GridPoint *)point fromPreviousVertex:(Vertex *)prev {
if ([grid allVerticiesVisited]) {
NSLog(@"done!");
return;
}
Vertex *cur = [grid vertexAtPoint:point];
[grid setVertextVisited:cur];
NSArray *borderingVerticies = [grid verticiesBorderingPoint:point];
Vertex *randomVertex;
int random = arc4random()%[borderingVerticies count];
randomVertex = [borderingVerticies objectAtIndex:random];
if (![randomVertex visited]) {
[cur.edgeList removeObject:prev];
[prev.edgeList removeObject:cur];
[self visitFromCurrentPoint:[randomVertex point] fromPreviousVertex:cur];
}
else {
[self visitFromCurrentPoint:point fromPreviousVertex:cur];
}
}
However, this doesn't work and I get a stack overflow. Can you see what I'm doing wrong?
Thanks in advance!