我正在尝试在 Objective-C 中生成一个迷宫。我已经构建了一个图并连接了所有边(我认为)。但是,我在尝试制作真正的迷宫时遇到了困难。
这是我正在使用的代码:
- (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];
}
}
但是,这不起作用,我得到堆栈溢出。你能看出我做错了什么吗?
提前致谢!