Exemple #1
0
    static bool[,] placeRandomCross(bool inverse, out int d, out int x, out int y)
    {
        d = rand.Next(0, 2) * 2 - 1;
        var o = d == -1 ? 1 : 0;

        if (inverse)
        {
            var a = Tafel.Random(0, 1);
            x = rand.Next(2, TW - 4);
            y = rand.Next(2, TH - 5);
            a[x + 1, y + 0]     = false;
            a[x + 0, y + 1 + o] = false;
            a[x + 1, y + 1]     = false;
            a[x + 2, y + 1 + o] = false;
            a[x + 1, y + 2]     = false;
            a[x + 1, y + 3]     = false;
            return(a);
        }
        else
        {
            var a = Tafel.Random(0, 0);
            x = rand.Next(1, TW - 3);
            y = rand.Next(1, TH - 4);
            a[x + 1, y + 0]     = true;
            a[x + 0, y + 1 + o] = true;
            a[x + 1, y + 1]     = true;
            a[x + 2, y + 1 + o] = true;
            a[x + 1, y + 2]     = true;
            a[x + 1, y + 3]     = true;
            return(a);
        }
    }
Exemple #2
0
    public static bool[,] GenerateManyCrosses()
    {
        int d = rand.Next(0, 2) * 2 - 1;
        var o = d == -1 ? 1 : 0;

        // int minx = 1;
        // int miny = 1;

        // int maxx = TW-2;
        // int maxy = TW-2;

        // int w = (maxx - minx) / 2-1;
        // int h = (maxy - miny) / 2-1;

        // var dx = w + 1;
        // var dy = h + 1;

        var num = rand.Next(4, 7);

        while (true)
        {
            var  a     = Tafel.Random(0, 0);
            bool valid = true;
            for (int i = 0; i < num; i++)
            {
                int x = rand.Next(1, TW - 3);
                int y = rand.Next(1, TH - 4);

                if (a[x + 1, y - 1] ||
                    a[x, y] || a[x + 2, y] ||
                    a[x - 1, y + 1 + o] || a[x + 3, y + 1 + o] ||
                    a[x, y + 2 - o] || a[x + 2, y + 2 - o] ||
                    a[x, y + 3] || a[x + 2, y + 3] ||
                    a[x + 1, y + 4])
                {
                    valid = false;
                    break;
                }
                a[x + 1, y + 0]     = true;
                a[x + 0, y + 1 + o] = true;
                a[x + 1, y + 1]     = true;
                a[x + 2, y + 1 + o] = true;
                a[x + 1, y + 2]     = true;
                a[x + 1, y + 3]     = true;
            }

            if (valid)
            {
                return(a);
            }
        }
    }
Exemple #3
0
    static void Main()
    {
        //TryTest();
        //return;

        var r    = new Random();
        int imax = 1000000000;

        Parallel.For(1, imax, i =>
        {
            var density = 0.1f + 0.8f * (float)i / (float)imax;
            bool[,] ar  = Tafel.Random(r.Next(), density);
            int x, y;
            var pr = Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out x, out y);
            //var pr = Tafel.PrüfRichtung(ar, out x, out y);
            if (pr == 1 || pr == -1)
            {
                ZeigTafel(ar, pr, x, y);
            }
        });
    }
Exemple #4
0
    public static bool[,] GenerateWithDensity(int generate, float density, out int pr, out int x, out int y, bool verbesser)
    {
        int i = 0;

        while (true)
        {
            i++;
            if (i > 1000000)
            {
                break;
            }
            bool[,] ar = Tafel.Random(rand.Next(0, 1000000), density);

            pr = generate == 1 ? Tafel.PrüfRichtung(ar, out x, out y)
                                        : (generate == 2 ? Tafel.PrüfRichtungMitHinzufügen(ar, out x, out y)
                                           : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out x, out y));

            if (pr == 1 || pr == -1)
            {
                if (verbesser)
                {
                    int c = 0;
                    while (Verbesser(ar, generate, ref x, ref y) && c < 100)
                    {
                        c++;
                    }
                }

                return(ar);
            }
        }

        x  = 0;
        y  = 0;
        pr = -2;
        return(null);
    }