Example #1
0
        static void Main(string[] args)
        {
            var result = RandomGrid.Generate(5);

            foreach (var i in result)
            {
                Console.WriteLine($"({i.P}, {i.Q})");
            }
        }
Example #2
0
    static void Main(string[] args)
    {
        RandomGrid grid = new RandomGrid(Convert.ToInt32(args[0]), Convert.ToInt32(args[1]));
        GameOfLife game = new GameOfLife(grid.grid);

        while (true)
        {
            game.Play();
        }
    }
Example #3
0
        /// <summary>
        /// 绘制连接图像。
        /// </summary>
        /// <param name="n">矩阵边长。</param>
        public static void Draw(int n, TextBox log, Log WinBox)
        {
            logBox = log;

            // 生成路径。
            log.AppendText("\r\n开始生成连接……");
            bag = RandomGrid.Generate(n);
            log.AppendText("\r\n生成连接完成");

            // 新建画布窗口。
            log.AppendText("\r\n启动画布……");
            Form2 matrix = new Form2();

            matrix.StartPosition = FormStartPosition.Manual;
            matrix.Location      = new Point(WinBox.Left - matrix.ClientRectangle.Width, WinBox.Top);
            matrix.Show();
            log.AppendText("\r\n画布已启动,开始绘图……");
            graphics = matrix.CreateGraphics();

            // 获取绘图区域。
            RectangleF rect  = matrix.ClientRectangle;
            float      unitX = rect.Width / (n + 1);
            float      unitY = rect.Height / (n + 1);

            // 绘制点。
            log.AppendText("\r\n绘制点……");
            points = new PointF[n * n];
            for (int row = 0; row < n; row++)
            {
                for (int col = 0; col < n; col++)
                {
                    points[row * n + col] = new PointF(unitX * (col + 1), unitY * (row + 1));
                    graphics.FillEllipse(Brushes.Black, unitX * (col + 1), unitY * (row + 1), 5, 5);
                }
            }
            log.AppendText("\r\n绘制点完成");

            // 绘制连接。
            log.AppendText("\r\n开始绘制连接……");
            connections = new List <Connection>();
            foreach (Connection c in bag)
            {
                connections.Add(c);
            }
            timer = new Timer
            {
                Interval = 500
            };
            timer.Tick += DrawOneLine;
            timer.Start();
        }
Example #4
0
    public void GeneratesRandomGrid()
    {
        RandomGrid randomGrid = new RandomGrid(2, 2);

        Assert.That(randomGrid.grid, Has.Count.EqualTo(2));
    }
Example #5
0
        static void Main(string[] args)
        {
            var n = 40;
            var t = 4;

            // quick-find
            Console.WriteLine("Quick-Find");
            long last = 0;
            long now  = 0;

            for (var i = 0; i < t; i++, n *= 2)
            {
                Console.WriteLine("N:" + n * n);
                var connections = RandomGrid.GetConnections(n);

                var quickFind = new QuickFindUF(n * n);
                now = RunTest(quickFind, connections);
                if (last == 0)
                {
                    Console.WriteLine("平均用时(毫秒):" + now);
                    last = now;
                }
                else
                {
                    Console.WriteLine("平均用时(毫秒):" + now + "\t比值:" + (double)now / last);
                    last = now;
                }
            }

            // quick-union
            Console.WriteLine("Quick-Union");
            n = 40;
            for (var i = 0; i < t; i++, n *= 2)
            {
                Console.WriteLine("N:" + n * n);
                var connections = RandomGrid.GetConnections(n);

                var quickFind = new QuickUnionUF(n * n);
                now = RunTest(quickFind, connections);
                if (last == 0)
                {
                    Console.WriteLine("平均用时(毫秒):" + now);
                    last = now;
                }
                else
                {
                    Console.WriteLine("平均用时(毫秒):" + now + "\t比值:" + (double)now / last);
                    last = now;
                }
            }

            // 加权 quick-union
            Console.WriteLine("Weighted Quick-Union");
            n = 40;
            for (var i = 0; i < t; i++, n *= 2)
            {
                Console.WriteLine("N:" + n * n);
                var connections = RandomGrid.GetConnections(n);

                var quickFind = new WeightedQuickUnionUF(n * n);
                now = RunTest(quickFind, connections);
                if (last == 0)
                {
                    Console.WriteLine("平均用时(毫秒):" + now);
                    last = now;
                }
                else
                {
                    Console.WriteLine("平均用时(毫秒):" + now + "\t比值:" + (double)now / last);
                    last = now;
                }
            }
        }
Example #6
0
        private void vToolStripMenuItem_Click(object sender, EventArgs e)
        {
            RandomGrid rg = new RandomGrid();

            rg.Show();
        }