Esempio n. 1
0
            public void GeneratesAMaze()
            {
                //Arrange
                var generator = new AlgorithmBacktrack();

                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]);
            }
Esempio n. 2
0
        public async Task Start(CommandContext ctx)
        {
            if (ctx.Channel.IsPrivate)
            {
                await ctx.TriggerTypingAsync();

                var interactivity = ctx.Client.GetInteractivityModule();

                var generator = new AlgorithmBacktrack();
                var map       = generator.Generate <BitArreintjeFastInnerMap, NetRandom>(StaticRandom.Next(64, 128), StaticRandom.Next(64, 128), null);
                int steps;
                while ((steps = PathFinderDepthFirstSmartWithPos.GoFind(map, null).Count - 1) == -1)
                {
                    map = generator.Generate <BitArreintjeFastInnerMap, NetRandom>(StaticRandom.Next(64, 128), StaticRandom.Next(64, 128), null);
                }

                using (var stream = new MemoryStream())
                {
                    WithPath.SaveMazeAsImageDeluxePng(map, new List <MazePointPos>(), stream);
                    stream.Seek(0, SeekOrigin.Begin);
                    await ctx.RespondWithFileAsync(stream, "Maze.png");
                }

                var response = await interactivity.WaitForMessageAsync(message => message.Author.Id == ctx.User.Id &&
                                                                       message.Channel.IsPrivate, TimeSpan.FromSeconds(3.0));

                await ctx.TriggerTypingAsync();

                if (response == null)
                {
                    await(await ctx.RespondAsync("Too late!")).CreateReactionAsync(DiscordEmoji.FromUnicode("⌛"));
                    return;
                }

                if (steps.ToString().Equals(response.Message.Content, StringComparison.Ordinal))
                {
                    await response.Message.CreateReactionAsync(DiscordEmoji.FromUnicode("🎉"));

                    await ctx.RespondAsync("You did it! The flag is Pycon_{{35c4p3_7h3_L4byr1n7h}}.");
                }
                else
                {
                    await(await ctx.RespondAsync("You lost!")).CreateReactionAsync(DiscordEmoji.FromUnicode("😏"));
                }
            }
        }
Esempio n. 3
0
        public void GenerateMaze()
        {
            if (indexBuffer != null)
            {
                indexBuffer.Dispose();
            }
            if (vertexBuffer != null)
            {
                vertexBuffer.Dispose();
            }



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

            currentPath = PathFinderDepthFirst.GoFind(maze.InnerMap, 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);
        }
Esempio n. 4
0
        private void GenerateMazeWithThisTypeAndShowTime(InnerMapType type, int size)
        {
            Stopwatch w = new Stopwatch();

            w.Start();

            AlgorithmBacktrack back = new AlgorithmBacktrack();

            DebugMSG("Generating maze of type: " + type + " of size: " + size);
            Maze maze = back.Generate(size, size, type, null);

            //var path = PathFinderDepthFirst.GoFind(new MazePoint(1, 1), new MazePoint(size - 3, size - 3), maze.InnerMap);
            //maze.SaveMazeAsBmpWithPath4bpp("maze.bmp", path);
            DebugMSG("Ok done, time: " + w.Elapsed.TotalSeconds);
            DebugMSG("");
        }
        public static void Test4()
        {
            int size = 16384;

            var alg  = new AlgorithmBacktrack();
            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}");
        }
Esempio n. 6
0
            public void GeneratesAPerfectMaze()
            {
                //Arrange
                var generator = new AlgorithmBacktrack();

                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.True(MazeVerifier.IsPerfectMaze(map));
            }
        public static void Test1()
        {
            var alg = new AlgorithmBacktrack();

            int size = 16384;

            var w   = Stopwatch.StartNew();
            var map = alg.Generate <BitArreintjeFastInnerMap, XorShiftRandom>(size, size, null);

            Console.WriteLine($"Generated maze in {w.Elapsed}");
            Console.WriteLine("Saving maze...");

            w.Restart();
            WithoutPath.SaveMaze("output.png", map);

            Console.WriteLine($"Saved maze in: {w.Elapsed}");


            //Console.WriteLine(map.GenerateMapAsString());

            Console.WriteLine("Written file");
        }
Esempio n. 8
0
        public ActionResult GenerateMazeWithPathSeed(int seed, int width, int height)
        {
            var alg = new AlgorithmBacktrack();

            var w   = Stopwatch.StartNew();
            var map = alg.Generate <BitArreintjeFastInnerMap, NetRandom>(width, height, seed, null);
            var mazeGenerationTime = w.Elapsed;

            w.Restart();
            var path = PathFinderDepthFirstSmartWithPos.GoFind(map, null);
            var pathGenerationTime = w.Elapsed;

            w.Restart();
            using (var memoryStream = new MemoryStream())
            {
                WithPath.SaveMazeAsImageDeluxePng(map, path, memoryStream);
                var toImageTime = w.Elapsed;

                Console.WriteLine($"Maze generation time: {mazeGenerationTime}, Path find time: {pathGenerationTime}, To image time: {toImageTime}");

                var data = memoryStream.ToArray();
                return(File(data, "image/png"));
            }
        }