Ejemplo n.º 1
0
    static void Main()
    {
        Random random = new Random();
        var    xdoc   = new XmlDocument();

        xdoc.Load("samples.xml");

        int counter = 1;

        foreach (XmlNode xnode in xdoc.FirstChild.ChildNodes)
        {
            if (xnode.Name == "#comment")
            {
                continue;
            }

            Model  model;
            string name = xnode.Get <string>("name");
            Console.WriteLine($"< {name}");

            if (xnode.Name == "overlapping")
            {
                model = new OverlappingModel(name, xnode.Get("N", 2), xnode.Get("width", 48), xnode.Get("height", 48),
                                             xnode.Get("periodicInput", true), xnode.Get("periodic", false), xnode.Get("symmetry", 8), xnode.Get("ground", 0));
            }
            else if (xnode.Name == "simpletiled")
            {
                model = new SimpleTiledModel(name, xnode.Get <string>("subset"),
                                             xnode.Get("width", 10), xnode.Get("height", 10), xnode.Get("periodic", false), xnode.Get("black", false));
            }
            else
            {
                continue;
            }

            for (int i = 0; i < xnode.Get("screenshots", 2); i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write("> ");
                    int  seed     = random.Next();
                    bool finished = model.Run(seed, xnode.Get("limit", 0));
                    if (finished)
                    {
                        Console.WriteLine("DONE");
                        model.Graphics().Save($"{counter} {name} {i}.png");
                        break;
                    }
                    else
                    {
                        Console.WriteLine("CONTRADICTION");
                    }
                }
            }

            counter++;
        }
    }
Ejemplo n.º 2
0
    static void Main()
    {
        Random    random = new Random();
        XDocument xdoc   = XDocument.Load("samples.xml");

        int counter = 1;

        foreach (XElement xelem in xdoc.Root.Elements("overlapping", "simpletiled"))
        {
            Model  model;
            string name = xelem.Get <string>("name");
            Console.WriteLine($"< {name}");

            if (xelem.Name == "overlapping")
            {
                model = new OverlappingModel(name, xelem.Get("N", 2), xelem.Get("width", 48), xelem.Get("height", 48),
                                             xelem.Get("periodicInput", true), xelem.Get("periodic", false), xelem.Get("symmetry", 8), xelem.Get("ground", 0));
            }
            else if (xelem.Name == "simpletiled")
            {
                model = new SimpleTiledModel(name, xelem.Get <string>("subset"),
                                             xelem.Get("width", 10), xelem.Get("height", 10), xelem.Get("periodic", false), xelem.Get("black", false));
            }
            else
            {
                continue;
            }

            for (int i = 0; i < xelem.Get("screenshots", 2); i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write("> ");
                    int  seed     = random.Next();
                    bool finished = model.Run(seed, xelem.Get("limit", 0));
                    if (finished)
                    {
                        Console.WriteLine("DONE");

                        model.Graphics().Save($"{counter} {name} {i}.png");
                        if (model is SimpleTiledModel && xelem.Get("textOutput", false))
                        {
                            System.IO.File.WriteAllText($"{counter} {name} {i}.txt", (model as SimpleTiledModel).TextOutput());
                        }

                        break;
                    }
                    else
                    {
                        Console.WriteLine("CONTRADICTION");
                    }
                }
            }

            counter++;
        }
    }
Ejemplo n.º 3
0
    public static void DoTheDance()
    {
        Random random = new Random();
        var xdoc = new XmlDocument();
        xdoc.Load("mapGen.xml");

        int counter = 1;
        foreach (XmlNode xnode in xdoc.FirstChild.ChildNodes)
        {
            if (xnode.Name == "#comment") continue;

            Model model;
            string name = xnode.Get<string>("name");
            Console.WriteLine($"< {name}");

            if (xnode.Name == "overlapping") model = new OverlappingModel(name, xnode.Get("N", 2), xnode.Get("width", 48), xnode.Get("height", 48),
                xnode.Get("periodicInput", true), xnode.Get("periodic", false), xnode.Get("symmetry", 8), xnode.Get("ground", 0));
            else if (xnode.Name == "simpletiled") model = new SimpleTiledModel(name, xnode.Get<string>("subset"),
                xnode.Get("width", 10), xnode.Get("height", 10), xnode.Get("periodic", false), xnode.Get("black", false));
            else continue;

            for (int i = 0; i < xnode.Get("screenshots", 2); i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write("> ");
                    int seed = random.Next();
                    bool finished = model.Run(seed, xnode.Get("limit", 0));
                    if (finished)
                    {
                        Console.WriteLine("DONE");

                        model.Graphics().Save($"{counter} {name} {i}.png");
                        if (model is SimpleTiledModel && xnode.Get("textOutput", false))
                            System.IO.File.WriteAllText($"{counter} {name} {i}.txt", (model as SimpleTiledModel).TextOutput());

                        break;
                    }
                    else Console.WriteLine("CONTRADICTION");
                }
            }

            counter++;
        }

        Otter.Util.Log("EGG");
    }
Ejemplo n.º 4
0
    public void Generate()
    {
        obmap = new  Dictionary <string, GameObject>();

        if (output == null)
        {
            Transform ot = transform.Find("output-tiled");
            if (ot != null)
            {
                output = ot.gameObject;
            }
        }
        if (output == null)
        {
            output = new GameObject("output-tiled");
            output.transform.parent   = transform;
            output.transform.position = this.gameObject.transform.position;
            output.transform.rotation = this.gameObject.transform.rotation;
        }

        for (int i = 0; i < output.transform.childCount; i++)
        {
            GameObject go = output.transform.GetChild(i).gameObject;
            if (Application.isPlaying)
            {
                Destroy(go);
            }
            else
            {
                DestroyImmediate(go);
            }
        }
        group            = new GameObject(xml.name).transform;
        group.parent     = output.transform;
        group.position   = output.transform.position;
        group.rotation   = output.transform.rotation;
        group.localScale = new Vector3(1f, 1f, 1f);
        rendering        = new GameObject[width, depth];
        this.model       = new SimpleTiledModel(xml.text, subset, width, depth, periodic);
        undrawn          = true;
    }
Ejemplo n.º 5
0
    static void Main()
    {
        Stopwatch sw = Stopwatch.StartNew();

        Random    random = new Random();
        XDocument xdoc   = XDocument.Load("samples.xml");

        int masterCounter = 0;

        foreach (XElement xelem in xdoc.Root.Elements("overlapping", "simpletiled"))
        {
            var screenshotCount = xelem.Get("screenshots", 10);

            for (int i = 0; i < screenshotCount; i++)
            {
                Parallel.For(0, attempts, (k) => {
                    Model model;
                    string name = xelem.Get <string>("name");
                    Console.WriteLine($"< {name}");

                    if (xelem.Name == "overlapping")
                    {
                        model = new OverlappingModel(name, xelem.Get("N", 2), xelem.Get("width", 48), xelem.Get("height", 48),
                                                     xelem.Get("periodicInput", true), xelem.Get("periodic", false), xelem.Get("symmetry", 8), xelem.Get("ground", 0));
                    }
                    else if (xelem.Name == "simpletiled")
                    {
                        model = new SimpleTiledModel(name, xelem.Get <string>("subset"),
                                                     xelem.Get("width", 10), xelem.Get("height", 10), xelem.Get("periodic", false), xelem.Get("black", false));
                    }
                    else
                    {
                        return;
                    }

                    while (masterCounter < screenshotCount)
                    {
                        Console.Write("> ");
                        int seed      = random.Next();
                        bool finished = model.Run(seed, xelem.Get("limit", 0));
                        if (finished)
                        {
                            Console.WriteLine("DONE");

                            var counter = Interlocked.Exchange(ref masterCounter, masterCounter + 1);

                            model.Graphics().Save($"{counter} {name} {i}.png");
                            if (model is SimpleTiledModel && xelem.Get("textOutput", false))
                            {
                                System.IO.File.WriteAllText($"{counter} {name} {i}.txt", (model as SimpleTiledModel).TextOutput());
                            }

                            return;
                        }
                        else
                        {
                            //Console.WriteLine( $"CONTRADICTION Completed {model.CompletedNodes}" );
                        }
                    }
                });
            }
        }

        Console.WriteLine($"time = {sw.ElapsedMilliseconds}");
    }
Ejemplo n.º 6
0
    static void Main()
    {
#if (VERSIONING)
        Console.WriteLine("Version number: {0}", Versioning.VersionNumber);
#else
        Console.WriteLine("There seems to be no versioning available.");
#endif

        Stopwatch sw = Stopwatch.StartNew();

        Random    random = new Random();
        XDocument xdoc   = XDocument.Load("samples.xml");

        int counter = 1;
        foreach (XElement xelem in xdoc.Root.Elements("overlapping", "simpletiled"))
        {
            Model  model;
            string name = xelem.Get <string>("name");
            Log($"Now processing picture <{name}>");

            if (xelem.Name == "overlapping")
            {
                model = new OverlappingModel(
                    name,
                    xelem.Get("N", 2),
                    xelem.Get("width", 48),
                    xelem.Get("height", 48),
                    xelem.Get("periodicInput", true),
                    xelem.Get("periodic", false),
                    xelem.Get("symmetry", 8),
                    xelem.Get("ground", 0));
                Log("\tProcessing as overlapping model");
            }

            else if (xelem.Name == "simpletiled")
            {
                model = new SimpleTiledModel(
                    name,
                    xelem.Get <string>("subset"),
                    xelem.Get("width", 10),
                    xelem.Get("height", 10),
                    xelem.Get("periodic", false),
                    xelem.Get("black", false));
                Log("\tProcessing as simpletiled model");
            }
            else
            {
                Log("\tDid not find a valid model. Moving on to the next picture..");
                continue;
            }

            for (int i = 0; i < xelem.Get("screenshots", 2); i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    int seed = random.Next();
                    Log($"\tFor process #{i+1} the random seed is {seed}");
                    bool finished = model.Run(seed, xelem.Get("limit", 0));
                    if (finished)
                    {
                        Log("\t-->SUCCESS<--");

                        model.Graphics().Save($"{counter} {name} {i}.png");

                        Log($"\tSaving result with name {counter} {name} {i}.png");
                        if (model is SimpleTiledModel && xelem.Get("textOutput", false))
                        {
                            System.IO.File.WriteAllText($"{counter} {name} {i}.txt", (model as SimpleTiledModel).TextOutput());
                        }

                        break;
                    }
                    else
                    {
                        Log("\t-->CONTRADICTION<--");
                        continue;
                    }
                }
            }

            counter++;
        }
        Log($"time = {sw.ElapsedMilliseconds}");

        Console.ReadLine();
    }
Ejemplo n.º 7
0
    static void Main()
    {
        Stopwatch sw = Stopwatch.StartNew();

        Random    random = new Random();
        XDocument xdoc   = XDocument.Load("samples.xml");

        foreach (XElement xelem in xdoc.Root.Elements("overlapping", "simpletiled"))
        {
            Model  model;
            string name = xelem.Get <string>("name");
            Console.WriteLine($"< {name}");

            bool   isOverlapping   = xelem.Name == "overlapping";
            int    size            = xelem.Get("size", isOverlapping ? 48 : 24);
            int    width           = xelem.Get("width", size);
            int    height          = xelem.Get("height", size);
            bool   periodic        = xelem.Get("periodic", false);
            string heuristicString = xelem.Get <string>("heuristic");
            var    heuristic       = heuristicString == "Scanline" ? Model.Heuristic.Scanline : (heuristicString == "MRV" ? Model.Heuristic.MRV : Model.Heuristic.Entropy);

            if (isOverlapping)
            {
                int  N             = xelem.Get("N", 3);
                bool periodicInput = xelem.Get("periodicInput", true);
                int  symmetry      = xelem.Get("symmetry", 8);
                int  ground        = xelem.Get("ground", 0);

                model = new OverlappingModel(name, N, width, height, periodicInput, periodic, symmetry, ground, heuristic);
            }
            else
            {
                string subset          = xelem.Get <string>("subset");
                bool   blackBackground = xelem.Get("blackBackground", false);

                model = new SimpleTiledModel(name, subset, width, height, periodic, blackBackground, heuristic);
            }

            for (int i = 0; i < xelem.Get("screenshots", 2); i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write("> ");
                    int  seed    = random.Next();
                    bool success = model.Run(seed, xelem.Get("limit", -1));
                    if (success)
                    {
                        Console.WriteLine("DONE");
                        model.Graphics().Save($"{name} {seed}.png");
                        if (model is SimpleTiledModel stmodel && xelem.Get("textOutput", false))
                        {
                            System.IO.File.WriteAllText($"{name} {seed}.txt", stmodel.TextOutput());
                        }
                        break;
                    }
                    else
                    {
                        Console.WriteLine("CONTRADICTION");
                    }
                }
            }
        }

        Console.WriteLine($"time = {sw.ElapsedMilliseconds}");
    }
Ejemplo n.º 8
0
    static void Main()
    {
        int       stageCount = 25;
        Stopwatch sw         = Stopwatch.StartNew();
        String    timeStamp  = "";    // DateTime.Now.ToString("yyyyMMddHHmmssffff");
        Random    random     = new Random();
        XDocument xdoc       = XDocument.Load("samples.xml");

        using (StreamWriter w = File.CreateText("answer.txt"))
        {
            w.WriteLine(stageCount.ToString());
        }
        int counter = 1;

        foreach (XElement xelem in xdoc.Root.Elements("overlapping", "simpletiled"))
        {
            Model  model;
            string name = xelem.Get <string>("name");
            Console.WriteLine($"< {name}");

            if (xelem.Name == "overlapping")
            {
                model = new OverlappingModel(name, xelem.Get("N", 2), xelem.Get("width", 48), xelem.Get("height", 48),
                                             xelem.Get("periodicInput", true), xelem.Get("periodic", false), xelem.Get("symmetry", 8), xelem.Get("ground", 0));
            }
            else if (xelem.Name == "simpletiled")
            {
                model = new SimpleTiledModel(timeStamp, name, xelem.Get <string>("subset"),
                                             xelem.Get("width", 10), xelem.Get("height", 10), xelem.Get("periodic", false), xelem.Get("black", false));
            }
            else
            {
                continue;
            }

            for (int i = 0; i < xelem.Get("screenshots", stageCount); i++)
            {
                for (int k = 0; k < 10; k++)
                {
                    Console.Write("> ");
                    int  seed     = random.Next();
                    bool finished = model.Run(seed, xelem.Get("limit", 0));
                    if (finished)
                    {
                        Console.WriteLine("DONE");

                        //model.Graphics().Save($"{counter} {name} {i}.png");
                        //model.Graphics().Save("image/" + i + ".png");
                        string outputFileName = "image/" + i + ".png";
                        using (MemoryStream memory = new MemoryStream())
                        {
                            using (FileStream fs = new FileStream(outputFileName, FileMode.Create, FileAccess.ReadWrite))
                            {
                                model.Graphics().Save(memory, ImageFormat.Png);
                                byte[] bytes = memory.ToArray();
                                fs.Write(bytes, 0, bytes.Length);
                            }
                        }
                        if (model is SimpleTiledModel && xelem.Get("textOutput", false))
                        {
                            System.IO.File.WriteAllText($"{counter} {name} {i}.txt", (model as SimpleTiledModel).TextOutput());
                        }

                        break;
                    }
                    else
                    {
                        Console.WriteLine("CONTRADICTION");
                    }
                }
            }

            counter++;
        }

        Console.WriteLine($"time = {sw.ElapsedMilliseconds}");
    }