解決できないセグメンテーション違反の問題があります。詳細は以下をご覧ください。このプログラムは、「完璧な」迷路を生成することになっています。
Maze.cp http://pastebin.com/gYazVk4h
Maze.h http://pastebin.com/cT4GddgB
main.cpp
#include "Maze.h"
#include <iostream>
#include <vector>
#include <algorithm>
#include <getopt.h> // includes the getopt command for input flags
#include <stdlib.h> // for EXIT_FAILURE and EXIT_SUCCESS
#include <stack>
using namespace std;
int main(int argc, char const *argv[])
{
Maze labyrinth;
labyrinth.Create_maze(15, 40);
labyrinth.Print_maze();
return 0;
}
他の 2 つのファイルも同様に貼り付けることができますが、それらは非常に大きいため、ペーストビンに保存しておく方が賢明だと思います。
とにかく、実行するとセグメンテーション違反が発生します。 注 1 : 38 行目と 39 行目で、while ループのコメントを解除し、for ループをコメント アウトする必要があります。デバッグに for ループを使用していました。
注2:問題は119行目から121行目にあると思いますが、よくわかりません。さまざまな種類を試してみましたが、解決方法がわかりません。
注 3 : Mazeworks DOT com の次の疑似コードに従っています。
create a CellStack (LIFO) to hold a list of cell locations
set TotalCells = number of cells in grid
choose a cell at random and call it CurrentCell
set VisitedCells = 1
while VisitedCells < TotalCells
find all neighbors of CurrentCell with all walls intact
if one or more found
choose one at random
knock down the wall between it and CurrentCell
push CurrentCell location on the CellStack
make the new cell CurrentCell
add 1 to VisitedCells else
pop the most recent cell entry off the CellStack
make it CurrentCell endIf
endWhile