public void GeneratesAMaze()
            {
                //Arrange
                var generator = new AlgorithmKruskal();

                long current    = 0;
                long total      = 0;
                var  mazeAction = new Action <int, int, long, long>((x, y, cur, tot) =>
                {
                    current = cur;
                    total   = tot;
                });

                //Act
                var map = generator.Generate <BitArreintjeFastInnerMap, NetRandom>(128, 128, mazeAction);

                //Assert
                Trace.WriteLine("Taken steps: " + current);
                Trace.WriteLine("Total steps: " + total);

                Assert.NotEqual(0, total);
                Assert.Equal(total, current);
                Assert.False(map[0, 0]);
                Assert.True(map[1, 1]);
            }
        public static void Test6()
        {
            int size = 4096;

            var alg  = new AlgorithmKruskal();
            var w    = Stopwatch.StartNew();
            var maze = alg.Generate <BitArreintjeFastInnerMap, NetRandom>(size, size, 1337, null);

            Console.WriteLine($"Generation time: {w.Elapsed}");

            w.Restart();
            var result = MazeVerifier.IsPerfectMaze(maze);

            Console.WriteLine($"Perfect maze verification time: {w.Elapsed}");
            Console.WriteLine($"Is our maze perfect?: {result}");

            using (var fs = new FileStream("KruskalMaze.png", FileMode.Create))
            {
                WithoutPath.MazeToImage(maze, fs);
            }
        }
Beispiel #3
0
        public void GenerateMaze()
        {
            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
            }
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
            }


            Algorithm alg;
            int       randomnumber = curMazeWidth < 2048 ? random.Next(3) : random.Next(2);

            if (randomnumber == 0)
            {
                alg = new AlgorithmBacktrack();
            }
            else if (randomnumber == 1)
            {
                alg = new AlgorithmDivision();
            }
            else
            {
                alg = new AlgorithmKruskal();
            }

            lastAlgorithm = alg.GetType().Name;

            currentMaze = alg.Generate(curMazeWidth, curMazeHeight, InnerMapType.BitArreintjeFast, null);
            var walls = currentMaze.GenerateListOfMazeWalls();

            currentPath = PathFinderDepthFirst.GoFind(currentMaze.InnerMap, null);


            determiner          = new LineOfSightDeterminer(currentMaze.InnerMap, currentPath);
            curChaseCameraPoint = null;

            VertexPositionNormalTexture[] vertices = new VertexPositionNormalTexture[walls.Count * 8];
            int[] indices = new int[walls.Count * 12];

            int curVertice = 0;
            int curIndice  = 0;



            foreach (var wall in walls)
            {
                //int factorHeight = 10;
                //int factorWidth = 10;

                WallModel model = new WallModel(wall);

                model.GoGenerateVertices(vertices, indices, ref curVertice, ref curIndice);
            }

            wallsCount = walls.Count;

            vertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionNormalTexture.VertexDeclaration, vertices.Length, BufferUsage.WriteOnly);
            indexBuffer  = new IndexBuffer(GraphicsDevice, IndexElementSize.ThirtyTwoBits, indices.Length, BufferUsage.WriteOnly);

            vertexBuffer.SetData(vertices);
            indexBuffer.SetData(indices);

            GeneratePath(currentPath);
        }