public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            //递归分割
            RecursiveDivision(0, mazeWall.RowLength, 0, mazeWall.ColLength);

            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
        public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;
            walls.Clear();

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            //初始化并查集
            UnionFindSet set = new UnionFindSet
                                   (mazeWall.RowLength * mazeWall.ColLength);

            Init();


            while (walls.Count > 0)
            {
                int randomIndex = Random.Range(0, walls.Count);
                var _wall       = walls[randomIndex];



                if (set.Union(
                        GetUnionSetIndex(_wall.Key),
                        GetUnionSetIndex(_wall.Value)))
                {
                    mazeWall.OpenArea(_wall.Key, _wall.Value);
                }

                walls.RemoveAt(randomIndex);
            }



            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
Beispiel #3
0
        public static MazeWall Generate(MazeWall wall)
        {
            walls.Clear();

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            //随机选择一个开始区域
            WallArea fistArea = RandChooseBeginArea();

            AddNerabyWall(fistArea);

            while (walls.Count > 0)
            {
                int randomIndex = Random.Range(0, walls.Count);
                var _wall       = walls[randomIndex];
                if (checkWall(_wall))
                {
                    if (checkArea(_wall.Key))
                    {
                        AddNerabyWall(_wall.Key);
                    }
                    if (checkArea(_wall.Key))
                    {
                        AddNerabyWall(_wall.Value);
                    }
                    mazeWall.OpenArea(_wall.Key, _wall.Value);
                }
                else
                {
                    walls.RemoveAt(randomIndex);
                }
            }

            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
Beispiel #4
0
        public static MazeWall Generate(MazeWall wall)
        {
            mazeWall = wall;
            count    = 0;
            _stack.Clear();

            //封闭全部墙壁
            mazeWall.ClosedAllWall();

            int maxCount = mazeWall.RowLength * mazeWall.ColLength;

            //随机选择一个开始区域
            WallArea fistArea = RandChooseBeginArea();

            ++count;
            _stack.Push(fistArea);

            WallArea?curArea = fistArea;

            while (count < maxCount)
            {
                if (null == curArea)
                {
                    //退回上一个区域
                    _stack.Pop();
                    curArea = _stack.Peek();
                    continue;
                }
                curArea = CheckNearby((WallArea)curArea);
            }

            //随机选择迷宫起点终点
            mazeWall.RandomOpenStartAndPoint();
            mazeWall.RandomOpenStartAndPoint();

            return(mazeWall);
        }
 /// <summary>
 /// 显示迷宫
 /// </summary>
 public void ShowWaze(MazeWall mw)
 {
     row = mw.row;
     col = mw.col;
     GenerateMaze();
 }
 public void TestKruskalUnionFind()
 {
     ResetMaze();
     MazeWall mw = Kruskal.Generate(new MazeWall(Size));
     //ShowWaze(mw);
 }
 public void TestRandomPrime()
 {
     ResetMaze();
     MazeWall mw = Prim.Generate(new MazeWall(Size));
     //ShowWaze(mw);
 }
 public void TestRecursiveDivision()
 {
     ResetMaze();
     MazeWall mw = RecursiveSegmentation.Generate(new MazeWall(Size));
     //ShowWaze(mw);
 }
 public void TestRecursiveBacktracking()
 {
     ResetMaze();
     MazeWall mw = DFS.Generate(new MazeWall(Size));
     //ShowWaze(mw);
 }