Exemple #1
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 #2
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);
    }
Exemple #3
0
    public static bool Verbesser(bool[,] ar, int generate, ref int x, ref int y)
    {
        var replacementsmade = false;

        x = 0;
        y = 0;
        int ax = 0;
        int ay = 0;

        var orig_pr = Tafel.PrüfRichtung(ar, out x, out y);


        for (var i = 1; i < Tafel.TW - 5; i++)
        {
            for (var j = 1; j < Tafel.TH - 1; j++)
            {
                var v0 = ar[i + 0, j];
                var v1 = ar[i + 1, j];
                var v2 = ar[i + 2, j];
                var v3 = ar[i + 3, j];
                if ((v0 == !v1) && (v0 == !v2) && (v0 == v3))
                {
                    var r = rand.Next(0, 4);
                    ar[i + r, j] = !ar[i + r, j];

                    var new_pr = (generate == 2)
                                    ?    Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay)
                                    :  (
                        (generate == 1)
                                                ? Tafel.PrüfRichtung(ar, out ax, out ay)
                        //else muss 3 sein
                                                : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay)
                        );

                    if (new_pr != orig_pr)
                    {
                        ar[i + r, j] = !ar[i + r, j];
                    }
                    else
                    {
                        x = ax;
                        y = ay;
                        replacementsmade = true;
                    }
                }
            }
        }


        for (var i = 1; i < Tafel.TW - 1; i++)
        {
            for (var j = 1; j < Tafel.TH - 4; j++)
            {
                var v0 = ar[i, j];
                var v1 = ar[i, j + 1];
                var v2 = ar[i, j + 2];
                var v3 = ar[i, j + 3];
                if ((v0 == !v1) && (v0 == !v2) && (v0 == v3))
                {
                    var r = rand.Next(0, 4);
                    ar[i, j + r] = !ar[i, j + r];

                    var new_pr = (generate == 2)
                                    ?    Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay)
                                    :  (
                        (generate == 1)
                                                ? Tafel.PrüfRichtung(ar, out ax, out ay)
                        //else muss 3 sein
                                                : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay)
                        );
                    if (new_pr != orig_pr)
                    {
                        ar[i, j + r] = !ar[i, j + r];
                    }
                    else
                    {
                        x = ax;
                        y = ay;
                        replacementsmade = true;
                    }
                }
            }
        }


        for (var i = 1; i < Tafel.TW - 6; i++)
        {
            for (var j = 1; j < Tafel.TH - 1; j++)
            {
                var v0 = ar[i + 0, j];
                var v1 = ar[i + 1, j];
                var v2 = ar[i + 2, j];
                var v3 = ar[i + 3, j];
                var v4 = ar[i + 4, j];
                if ((v0 == v1) && (v0 == v2) && (v0 == v3) && (v0 == v4))
                {
                    var r = rand.Next(0, 5);
                    ar[i + r, j] = !ar[i + r, j];

                    var new_pr = (generate == 2)
                                    ?    Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay)
                                    :  (
                        (generate == 1)
                                                ? Tafel.PrüfRichtung(ar, out ax, out ay)
                        //else muss 3 sein
                                                : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay)
                        );
                    if (new_pr != orig_pr)
                    {
                        ar[i + r, j] = !ar[i + r, j];
                    }
                    else
                    {
                        x = ax;
                        y = ay;
                        replacementsmade = true;
                    }
                }
            }
        }

        for (var i = 1; i < Tafel.TW - 1; i++)
        {
            for (var j = 1; j < Tafel.TH - 6; j++)
            {
                var v0 = ar[i, j + 0];
                var v1 = ar[i, j + 1];
                var v2 = ar[i, j + 2];
                var v3 = ar[i, j + 3];
                var v4 = ar[i, j + 4];
                if ((v0 == v1) && (v0 == v2) && (v0 == v3) && (v0 == v4))
                {
                    var r = rand.Next(0, 5);
                    ar[i, j + r] = !ar[i, j + r];

                    var new_pr = (generate == 2)
                                    ?    Tafel.PrüfRichtungMitHinzufügen(ar, out ax, out ay)
                                    :  (
                        (generate == 1)
                                                ? Tafel.PrüfRichtung(ar, out ax, out ay)
                        //else muss 3 sein
                                                : Tafel.PrüfRichtungMitHinzuhinzufügen(ar, out ax, out ay)
                        );

                    if (new_pr != orig_pr)
                    {
                        ar[i, j + r] = !ar[i, j + r];
                    }
                    else
                    {
                        x = ax;
                        y = ay;
                        replacementsmade = true;
                    }
                }
            }
        }

        return(replacementsmade);
    }
Exemple #4
0
    // Update is called once per frame
    void Update()
    {
        if (startstring != "")
        {
            _ar         = Tafel.FromString(startstring);
            startstring = "";
        }

        if (regentex)
        {
            regentex = false;
            StartCoroutine("GenTex");
        }
        if (l1)
        {
            l1 = false;

            _ar = Tafel.mitNiveau(1, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l2)
        {
            l2 = false;

            _ar = Tafel.mitNiveau(2, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l3)
        {
            l3 = false;

            _ar = Tafel.mitNiveau(3, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l4)
        {
            l4 = false;

            _ar = Tafel.mitNiveau(4, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l5)
        {
            l5 = false;

            _ar = Tafel.mitNiveau(5, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l6)
        {
            l6 = false;

            _ar = Tafel.mitNiveau(6, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l7)
        {
            l7 = false;

            _ar = Tafel.mitNiveau(7, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l8)
        {
            l8 = false;

            _ar = Tafel.mitNiveau(8, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l9)
        {
            l9 = false;

            _ar = Tafel.mitNiveau(9, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l10)
        {
            l10 = false;

            _ar = Tafel.mitNiveau(10, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l11)
        {
            l11 = false;

            _ar = Tafel.mitNiveau(11, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l12)
        {
            l12 = false;

            _ar = Tafel.mitNiveau(12, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l13)
        {
            l13 = false;

            _ar = Tafel.mitNiveau(13, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l14)
        {
            l14 = false;

            _ar = Tafel.mitNiveau(14, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }
        if (l15)
        {
            l15 = false;

            _ar = Tafel.mitNiveau(15, out _d, out _x, out _y);
            Debug.Log(Tafel.ToString(_ar));
        }

        if (Input.GetKeyDown(KeyCode.P) && _ar != null)
        {
            _d = Tafel.PrüfRichtungMitHinzuhinzufügen(_ar, out _x, out _y);
            Debug.Log("PrüfRichtungMitHinzuhinzufügen " + _d);
        }

        var generate = -1;

        if (Input.GetKeyDown(KeyCode.N))
        {
            generate = 1;
        }
        else if (Input.GetKeyDown(KeyCode.M))
        {
            generate = 2;
        }
        else if (Input.GetKeyDown(KeyCode.Comma))
        {
            generate = 3;
        }

        if (Input.GetKeyDown(KeyCode.Alpha1))
        {
            density = 0.1f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha2))
        {
            density = 0.2f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha3))
        {
            density = 0.3f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha4))
        {
            density = 0.4f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha5))
        {
            density = 0.5f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha6))
        {
            density = 0.6f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha7))
        {
            density = 0.7f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha8))
        {
            density = 0.8f;
        }
        if (Input.GetKeyDown(KeyCode.Alpha9))
        {
            density = 0.9f;
        }

        if (generate > 0)
        {
            Tafel.GenerateWithDensity(generate, density, out _d, out _x, out _y, false);
        }
        if (_ar != null)
        {
            ZeigTafel(_ar, _d, _x, _y);
        }
    }