private static void VerifyMazeSize(MazeGenerator.Maze maze, ushort width, ushort height)
        {
            maze.Dimension.X.Should().Be(width);
            maze.Dimension.Y.Should().Be(height);

            int pathCount = 0;

            for (int x = 0; x < maze.Dimension.X; x++)
            {
                if (maze[0, x] == CaseType.Path)
                {
                    pathCount++;
                }
                if (maze[maze.Dimension.Y - 1, x] == CaseType.Path)
                {
                    pathCount++;
                }
            }
            for (int y = 1; y < maze.Dimension.Y - 1; y++)
            {
                if (maze[y, 0] == CaseType.Path)
                {
                    pathCount++;
                }
                if (maze[y, maze.Dimension.X - 1] == CaseType.Path)
                {
                    pathCount++;
                }
            }

            pathCount.Should().Be(2);
        }
        private static void VerifyHasEntranceAndExit(MazeGenerator.Maze maze)
        {
            int pathCount = 0;

            for (int x = 0; x < maze.Dimension.X; x++)
            {
                if (maze[0, x] == CaseType.Path)
                {
                    pathCount++;
                }
                if (maze[maze.Dimension.Y - 1, x] == CaseType.Path)
                {
                    pathCount++;
                }
            }
            for (int y = 1; y < maze.Dimension.Y - 1; y++)
            {
                if (maze[y, 0] == CaseType.Path)
                {
                    pathCount++;
                }
                if (maze[y, maze.Dimension.X - 1] == CaseType.Path)
                {
                    pathCount++;
                }
            }

            pathCount.Should().Be(2);
        }
Example #3
0
        internal static void AssertThatWallAreSplittedIn2Blocks(this MazeGenerator.Maze maze)
        {
            var wallEntrance = GetWallEntranceNeihboors(maze, maze.Entrance);

            wallEntrance.Count.Should().Be(2);

            var AllBlackWalls = GetAllBlack(maze).ToList();
            var firstSide     = GetLinkedWalls(maze, wallEntrance.First(), new List <(int x, int y)>(AllBlackWalls)).Distinct().ToList();
            var secondSide    = GetLinkedWalls(maze, wallEntrance.Last(), new List <(int x, int y)>(AllBlackWalls)).Distinct().ToList();

            foreach (var first in firstSide)
            {
                AllBlackWalls.Should().Contain(first);
                AllBlackWalls.Remove(first);
            }
            foreach (var second in secondSide)
            {
                AllBlackWalls.Should().Contain(second);
                AllBlackWalls.Remove(second);
            }


            foreach (var test in AllBlackWalls)
            {
                maze.Board[test.y, test.x] = CaseType.Debug;
            }

            AllBlackWalls.Should().BeEmpty();
        }
Example #4
0
        void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            //uiProgressLabel.Text = "Saving...";

            maze = e.Result as Maze;
            //((GrowingTreeMaze)maze).DrawMaze(Color.Black, Convert.ToInt32(uiCorridorWidthNum.Value)).Save(uiSaveMazeDialog.FileName, ImageFormat.Bmp);

            //uiProgressLabel.Text = String.Format("Done in {0}", time.ToString());
            //uiGenerateButton.Enabled = true;
            //uiProgressBar.Value = 0;
        }
        public void ShouldContentOnlyPathAndWall(int seed, GeneratorType generatorType)
        {
            var rand      = new Rand(new Random(seed));
            var generator = new Generator(rand);
            var width     = rand.Next() % 25 + 50;
            var height    = rand.Next() % 25 + 50;

            MazeGenerator.Maze maze = generator.Generate(width, height, generatorType);

            maze.AssertContainOnlyWallAndPath();
        }
Example #6
0
        internal static void AssertContainOnlyWallAndPath(this MazeGenerator.Maze maze)
        {
            int caseFound = 0;

            foreach (var caseType in maze.Board)
            {
                if (caseType != CaseType.Path && caseType != CaseType.Wall)
                {
                    caseFound++;
                }
            }
            caseFound.Should().Be(0);
        }
Example #7
0
        internal static void AssertEntranceLinkedToExit(this MazeGenerator.Maze maze)
        {
            var wallEntrance    = maze.Entrance;
            var processedPath   = new List <(int x, int y)>();
            var toBeProcessPath = new List <(int x, int y)> {
                wallEntrance
            };

            while (toBeProcessPath.Any())
            {
                var first = toBeProcessPath.First();
                processedPath.Add(first);
                toBeProcessPath.Remove(first);
                var nextMoves = GetPathNeihboors(maze, first).Where(pos => !processedPath.Contains(pos) && !toBeProcessPath.Contains(pos));
                toBeProcessPath.AddRange(nextMoves.ToList());
            }
            processedPath.Should().Contain(maze.Exit);
        }
Example #8
0
        internal static void AssertNoSquarePathExist(this MazeGenerator.Maze maze)
        {
            List <(int x, int y)> errorList = new List <(int x, int y)>();

            for (int x = 0; x < maze.Dimension.X - 1; x++)
            {
                for (int y = 0; y < maze.Dimension.Y - 1; y++)
                {
                    if (maze[y, x] == CaseType.Path &&
                        maze[y, x + 1] == CaseType.Path &&
                        maze[y + 1, x] == CaseType.Path &&
                        maze[y + 1, x + 1] == CaseType.Path)
                    {
                        errorList.Add((x, y));
                    }
                }
            }

            errorList.Should().BeEmpty();
        }
Example #9
0
 static void Main(string[] args)
 {
     var maze = new Maze(10,10);
     maze.Generate();
 }
Example #10
0
        private void createBtn_Click(object sender, EventArgs e)
        {
            //bool checkDim = Int32.TryParse(txtWidth.Text, out int result);
            int wid = 0;
            int hgt = 0;

            //Добавим проверку на корректность введенных размеров
            try
            {
                wid = int.Parse(txtWidth.Text);
                hgt = int.Parse(txtHeight.Text);

                if (wid < 5 || hgt < 5)
                {
                    throw new FormatException();
                }
            }
            catch (System.FormatException)
            {
                string            message = "Розмірність має бути не меншою ніж 5 в довжину і ширину";
                string            caption = "Помилка введення розміру";
                MessageBoxButtons buttons = MessageBoxButtons.OK;
                DialogResult      result;
                result         = MessageBox.Show(message, caption, buttons);
                txtWidth.Text  = "10";
                txtHeight.Text = "10";

                return;
            }



            int oddW = 0;
            int oddH = 0;

            //Обрабатываем случай с нечетными размерами
            if (wid % 2 != 0 && wid != 0)
            {
                oddW = 1;
            }
            if (hgt % 2 != 0 && hgt != 0)
            {
                oddH = 1;
            }

            //вычисляем ширину одной ячейки, чтобы автомасштабировать полученную картинку

            CellWid = picMaze.ClientSize.Width / (wid + 2);
            CellHgt = picMaze.ClientSize.Height / (hgt + 2);

            //Установим минимальный размер ячейки, чтобы глаза не выпадывали
            int CellMin = 10;

            if (CellWid < CellMin)
            {
                CellWid = CellMin;
                CellHgt = CellWid;
            }
            else if (CellHgt < CellMin)
            {
                CellHgt = CellMin;
                CellWid = CellHgt;
            }
            else if (CellWid > CellHgt)
            {
                CellWid = CellHgt;
            }
            else
            {
                CellHgt = CellWid;
            }


            Maze maze = new Maze(wid, hgt);

            //обрабатываем прорисовку финиша при нечетных размерах
            maze.finish.X = maze.finish.X + oddW;
            maze.finish.Y = maze.finish.Y + oddH;
            maze.CreateMaze();
            DrawMaze();

            inMaze = maze;

            void DrawMaze()
            {
                inBm.Dispose();
                //создаем битмап так, чтобы захватить и финиш и стенку за ним
                Bitmap bm = new Bitmap(
                    CellWid * (maze.finish.X + 2),
                    CellHgt * (maze.finish.Y + 2), System.Drawing.Imaging.PixelFormat.Format16bppRgb555);

                Brush whiteBrush = new SolidBrush(Color.White);
                Brush blackBrush = new SolidBrush(Color.Black);

                using (Graphics gr = Graphics.FromImage(bm))
                {
                    gr.SmoothingMode = SmoothingMode.AntiAlias;
                    for (var i = 0; i < maze._cells.GetUpperBound(0) + oddW; i++)
                    {
                        for (var j = 0; j < maze._cells.GetUpperBound(1) + oddH; j++)
                        {
                            Point     point = new Point(i * CellWid, j * CellWid);
                            Size      size  = new Size(CellWid, CellWid);
                            Rectangle rec   = new Rectangle(point, size);
                            if (maze._cells[i, j]._isCell)
                            {
                                gr.FillRectangle(whiteBrush, rec);
                            }
                            else
                            {
                                gr.FillRectangle(blackBrush, rec);
                            }
                        }
                    }

                    gr.FillRectangle(new SolidBrush(Color.Green),    //заливаем старт зеленым
                                     new Rectangle(new Point(maze.start.X * CellWid, maze.start.Y * CellWid),
                                                   new Size(CellWid, CellWid)));
                    gr.FillRectangle(new SolidBrush(Color.Red),       //а финиш красным
                                     new Rectangle(new Point(maze.finish.X * CellWid, maze.finish.Y * CellWid),
                                                   new Size(CellWid, CellWid)));
                }

                picMaze.Image = bm; //отображаем
                inBm          = bm;
            }
        }
Example #11
0
 private void OpenEntranceAndExit(Maze maze, (ushort x, ushort y) entrance, (ushort x, ushort y) exit)
Example #12
0
 private static bool IsCaseAgainWallWithHole(Maze maze, Area area, int x, int y)
 {
     return(x == area.X && maze[y, x - 1] != CaseType.Wall ||
            (x == area.X + area.Width - 1 && maze[y, x + 1] != CaseType.Wall));
 }
Example #13
0
 public RecursiveSplitMazeGenerator(IRand rand, Dimension dimension)
 {
     this.rand = rand;
     maze      = Maze.Build(dimension);
 }
 private void BuildInsideMaze(Maze maze, HashSet <(ushort x, ushort y)> possibilities)
Example #15
0
 private static List <(int x, int y)> GetPathNeihboors(MazeGenerator.Maze maze, (int, int) pos)