Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/156.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
生成一个随机的;迷宫三维阵列C++; 所以我在学习学校分配,因为我在学习C++。与其说我在寻找代码,不如说是帮助我理解/想出解决这个问题的正确算法_C++_Maze - Fatal编程技术网

生成一个随机的;迷宫三维阵列C++; 所以我在学习学校分配,因为我在学习C++。与其说我在寻找代码,不如说是帮助我理解/想出解决这个问题的正确算法

生成一个随机的;迷宫三维阵列C++; 所以我在学习学校分配,因为我在学习C++。与其说我在寻找代码,不如说是帮助我理解/想出解决这个问题的正确算法,c++,maze,C++,Maze,我需要创建一个由1和0组成的(5x5x5)3d迷宫。随机填充(0,0,0表示开始时为1,4,4,4表示结束时为1除外) 这就是我所做的。 我制作了一个立方体对象: #include "cube.h" Cube :: Cube(int cube_value) { cube_value = 0; chk_up = false; chk_down = false; chk_left = false; chk_right = false; chk_fron

我需要创建一个由1和0组成的(5x5x5)3d迷宫。随机填充(0,0,0表示开始时为1,4,4,4表示结束时为1除外)

这就是我所做的。 我制作了一个立方体对象:

#include "cube.h"
Cube :: Cube(int cube_value)
{
    cube_value = 0;
    chk_up = false;
    chk_down = false;
    chk_left = false;
    chk_right = false;
    chk_front = false;
    chk_back = false;
}
Cube :: ~Cube(void){}
在我的迷宫管理类中,我初始化如下

PathFinder::PathFinder()
{
    // initializing / sizing 5x5x5 Maze
Maze.resize(5);
    for(int y = 0; y < 5 ; ++y)
    {
        Maze[y].resize(5);
        for(int z = 0; z<5 ; ++z)
        {
            Maze[y][z].resize(5);
        }
    }

    int at_x = 0;
    int at_y = 0;
    int at_z = 0;
}
PathFinder::PathFinder()
{
//初始化/调整5x5x5迷宫的大小
迷宫。调整大小(5);
对于(int y=0;y<5;++y)
{
迷宫[y]。调整大小(5);
对于(intz=0;z
void PathFinder::fillmaze()
{
int atx=0,aty=0,atz=0;
而(atz
void PathFinder::fillmaze()
{
int atx=0,aty=0,atz=0;

虽然(阿特兹,有没有一个原因它必须进入一个点,然后从另一个点出来?你读了吗?埃维特-假设迷宫将从一端开始,在另一端开始,因此这些点上的路径需要有一个有效的数字。n0rd-我没有看到,谢谢你的参考,我将研究它。有没有理由它必须进入一个点int,然后从另一端出来?你读到了吗?evit-假设迷宫从一端开始,在另一端开始,因此这些点的路径需要有一个有效的数字。n0rd-我还没有看到,谢谢你的参考,我将研究它。
class PathFinder : public PathfinderInterface {
private:
    int at_x;
    int at_y;
    int at_z;
public:
    vector<vector<vector<Cube> > > Maze;

    PathFinder();
    virtual ~PathFinder();

    string getMaze();

    void createRandomMaze();

    bool importMaze(string file_name);

    vector<string> solveMaze();
};
void PathFinder :: fillmaze()
{
    Maze[0][0][0].cube_value = 1;
    Maze[4][4][4].cube_value = 1;
    int atx = 0 , aty = 0 , atz = 0;
    while(atx<5 && aty < 5 && atz < 5)
    {

        if(atz == 5)
        {
            aty = aty + 1;
        }
        if(aty == 5)
        {
            atx = atx + 1;
            atx = 0;
        }

        for(atz=0 ; atz<5 ; ++atz)
        {
            if((atx!= 0 && aty!=0 && atz!=0) || (atx!=4 && aty!=4 && atz!= 4) )
            {
                Maze[atx][aty][atz].cube_value = (rand() % 2);
            }
        }
    }
}
void PathFinder :: fillmaze()
{
    int atx = 0 , aty = 0 , atz = 0;
    while(atz<=4)
    {
    if(atx == 5)
    {
        aty = aty + 1;
    }
    if(aty == 5)
    {
        aty = 0;
        atz = atz + 1;
    }
    if(atz < 5)
    {

            for(atx=0 ; atx<5 ; ++atx)
            {
                     Maze[atx][aty][atz].cube_value = (rand() % 2);
            }

    }
    }
         Maze[0][0][0].cube_value = 1;
         Maze[4][4][4].cube_value = 1;

 }