コード例 #1
0
        public override void Build()
        {
            ConnectedAreas = new List <uint>()
            {
                0
            };
            for (uint col = 2; col < Width - 2; col += 2)
            {
                for (uint row = 1; row < Height - 1; row++)
                {
                    Cells[row * Width + col].Type = CellType.Wall;
                }
            }
            for (uint row = 2; row < Height - 2; row += 2)
            {
                for (uint col = 1; col < Width - 1; col++)
                {
                    Cells[row * Width + col].Type = CellType.Wall;
                }
            }
            for (uint i = 0; i < Cells.Length; i++)
            {
                if (Cells[i].Type == CellType.Lane)
                {
                    Cells[i].ToStart = i;
                }
            }
            Cells[1].Type    = CellType.Lane;
            Cells[1].ToStart = 0;
            Cells[Height * Width - 2].Type = CellType.Lane;

            List <Cell> unconnectedList = Cells.Where(x => ConnectedAreas.Contains(x.ToStart) && x.Type == CellType.Lane && CheckBoundry(x)).ToList();
            Direction   dir;

            while (unconnectedList.Count > 0)
            {
                foreach (Cell cell in unconnectedList)
                {
                    //if (Cells[cell.Y * Width + cell.X].ToStart > 0)
                    {
                        dir = (Direction)Rnd.Next(0, 4);
                        Expand(cell, dir);
                    }
                }
                if (Fun_onExpand != null)
                {
                    Fun_onExpand.Invoke();
                }
                unconnectedList = Cells.Where(x => ConnectedAreas.Contains(x.ToStart) && x.Type == CellType.Lane && CheckBoundry(x)).ToList();
            }
        }
コード例 #2
0
ファイル: MazeA.cs プロジェクト: foomow/Maze
        private void Expand(uint[] seeds)
        {
            List <uint> nextSeeds = new List <uint>();

            while (seeds.Length > 0)
            {
                nextSeeds.Clear();
                foreach (uint idx in seeds)
                {
                    uint[] candidates = Explore(idx);
                    if (candidates.Length > 0)
                    {
                        uint newIdx = candidates[Rnd.Next(0, candidates.Length)];
                        Cells[newIdx].Type = CellType.Wall;
                        nextSeeds.Add(newIdx);
                    }
                }
                if (Fun_onExpand != null)
                {
                    Fun_onExpand.Invoke();
                }
                seeds = nextSeeds.Distinct().ToArray();
            }
        }