Exemple #1
0
        private void button26_Click(object sender, EventArgs e)
        {
            int size = 5;

            Form f = new Form();
            f.Size = new System.Drawing.Size(1100, 1100);
            f.Show();

            Task.Run(() =>
            {

                var g = f.CreateGraphics();

                int width = 1024;
                int height = 1024;

                g.FillRectangle(Brushes.Black, 0, 0, width + 1, height + 1);

                //for (int y = 0; y < 10; y++)
                //{
                //    for (int x = 0; x < 10; x++)
                //    {
                //        g.DrawRectangle(Pens.Red, x * 128, y * 128, 128, 128);
                //    }
                //}

                AlgorithmBacktrackSmartMemory curalg = new AlgorithmBacktrackSmartMemory();

                Maze m = curalg.Generate(width / size, height / size, InnerMapType.Hybrid, 5, (x, y, cur, tot) =>
                {
                    curXInMaze = x;
                    curYInMaze = y;
                    currentStepsToCalcPercentage = cur;
                    totalStepsToCalcPercentage = tot;
                    g.FillRectangle(Brushes.Red, x * size, y * size, size, size);
                    //Thread.Sleep(20);
                    g.FillRectangle(Brushes.White, x * size, y * size, size, size);
                });

                var path = PathFinderDepthFirstSmart.GoFind(m.InnerMap, (x, y, pathThing) =>
                {
                    if (pathThing)
                    {
                        g.FillRectangle(Brushes.Green, x * size, y * size, size, size);
                    }
                    else
                    {
                        g.FillRectangle(Brushes.Gray, x * size, y * size, size, size);
                    }

                });

                m.SaveMazeAsImage("hybridmaze.png", ImageFormat.Png, path, MazeSaveType.ColorDepth32Bits);
            });
        }
Exemple #2
0
        private void button25_Click(object sender, EventArgs e)
        {
            int sizezzz = int.Parse(comboBox4.SelectedItem.ToString().Replace(".", ""));

            //Passing an int into the action like this is faster because else it will get stuck on the heap/stack or w/e I guess :o
            var actionToRun = new Action<int>((size) =>
            {
                Algorithm curalg = new AlgorithmBacktrackSmartMemory();
                Stopwatch w = new Stopwatch();
                w.Start();
                //int size = (int)Math.Pow(2.0, 19.0);

                DebugMSG("Generating maze of size: " + size);
                DebugMSG("Saved size it should be: " + Math.Pow((double)size, 2.0) / 1024.0 / 1024.0 / 8.0 + " mb");
                DebugMSG("Or in GB: " + Math.Pow((double)size, 2.0) / 1024.0 / 1024.0 / 1024.0 / 8.0 + " gb");
                lastMegaTerrorMaze = curalg.Generate(size, size, InnerMapType.Hybrid, 1337, (x, y, cur, tot) =>
                {
                    curXInMaze = x;
                    curYInMaze = y;
                    currentStepsToCalcPercentage = cur;
                    totalStepsToCalcPercentage = tot;
                });
                w.Stop();
                DebugMSG("Generating time: " + w.Elapsed.TotalSeconds);
                TrimAndGCCollect();
            });

            Task.Run(() => { actionToRun(sizezzz); TrimAndGCCollect(); });
        }