コード例 #1
0
        public void GeneratingAMazeWithABlockInTheMiddleWorks()
        {
            var map = new BitArreintjeFastInnerMap(128, 128);

            for (int y = 33; y < 96; y++)
            {
                for (int x = 33; x < 96; x++)
                {
                    map[x, y] = true;
                }
            }

            var mapFactory    = new InnerMapFactoryCustom <BitArreintjeFastInnerMap>(map);
            var randomFactory = new RandomFactory <NetRandom>(1337);

            var algorithm    = new AlgorithmBacktrack();
            var generatedMap = algorithm.GoGenerate(mapFactory, randomFactory, null);

            var path = PathFinderDepthFirstSmartWithPos.GoFind(map, null);

            using (var fs = new FileStream("GeneratingAMazeWithABlockInTheMiddleWorks.png", FileMode.Create))
            {
                WithPath.SaveMazeAsImageDeluxePng(map, path, fs);
            }
        }
コード例 #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("😏"));
                }
            }
        }
コード例 #3
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"));
            }
        }