コード例 #1
0
    // private List<GameObject> tempLevelButtons;


    public void InitializeLSystems(LSystemWrapper[] retrievedLSystems)
    {
        int retrieved = retrievedLSystems?.Length ?? 0;

        for (int i = 0; i < RatingSystem.MAX_LSYSTEMS; i++)
        {
            if (i < retrieved)
            {
                RatingSystem.lSystems.Add(LSystem.Decode(retrievedLSystems[i].GetString()));
            }
            else
            {
                RatingSystem.lSystems.Add(new LSystem(16, 3, 0.2f));
            }
            RatingSystem.GenerateXMLs(i, 5);
        }
    }
コード例 #2
0
    /// <summary>
    /// When its the sql call is done
    /// retrievedLSystems will be null numLSystemsNeeded was 0
    /// </summary>
    /// <param name="retrievedLSystems"></param>
    public void GetPopulationCallBack(LSystemWrapper[] retrievedLSystems)
    {
        //int retrieved = retrievedLSystems?.Length ?? 0;

        //int kept = RatingSystem.keptForEvolution.Count;

        foreach (LSystemWrapper wrapper in retrievedLSystems)
        {
            RatingSystem.keptForEvolution.Add(new RatingSystem.LSystemEvolution(LSystem.Decode(wrapper.GetString())));
        }

        while (RatingSystem.keptForEvolution.Count < RatingSystem.MAX_LSYSTEMS)
        {
            RatingSystem.keptForEvolution.Add(new RatingSystem.LSystemEvolution(new LSystem(16, 3, 0.2f)));
        }

        //for (int i = kept; i < RatingSystem.MAX_LSYSTEMS; i++)
        //{
        //    if (i - kept < retrieved)
        //    {
        //        RatingSystem.keptForEvolution.Add(new RatingSystem.LSystemEvolution(LSystem.Decode(retrievedLSystems[i].GetString())));
        //    }
        //    else
        //    {
        //        RatingSystem.keptForEvolution.Add(new RatingSystem.LSystemEvolution(new LSystem(10, 3)));
        //    }
        //}
        // keptforevolution will contain a list of levels to run evolution on
        // TODO: Run evolution here and replace RatingSystem.keptForEvolution with the list of newly created LSystems

        RatingSystem.ClearAll();
#if UNITY_WEBGL && !UNITY_EDITOR
        EvolveScene.iterations = 5;
#else
        EvolveScene.iterations = 10;
#endif
        //ABSceneManager.Instance.LoadScene("LevelSelectMenu");
        ABSceneManager.Instance.LoadScene("Evolution");
        //RatingSystem.GenerateXMLs(RatingSystem.CurrentLSystemIndex, 5); // hardcoded height
        //LoadScreenshots(RatingSystem.CurrentLSystemIndex);
        //GenerateNewLevels(RatingSystem.CurrentLSystemIndex);
    }
コード例 #3
0
    static void Main(string[] args)
    {
        //File path for level xml
        string path = "../../levels/level-04.xml";


        Dictionary <string, string> materialKey = new Dictionary <string, string>
        {
            { "W", "wood" },
            { "S", "stone" },
            { "I", "ice" },
            { "A", "air" }
        };

        Dictionary <string, Tuple <List <string>, List <double> > > rules1 = new Dictionary <string, Tuple <List <string>, List <double> > >
        {
            { "1", new Tuple <List <string>, List <double> >(new List <string> {
                    "1", "212"
                }, new List <double> {
                    0.80, 0.20
                }) },
            { "4", new Tuple <List <string>, List <double> >(new List <string> {
                    "4", "141"
                }, new List <double> {
                    0.60, 0.40
                }) },
            { "2", new Tuple <List <string>, List <double> >(new List <string> {
                    "2", "26262"
                }, new List <double> {
                    0.20, 0.80
                }) }
        };

        Dictionary <string, Tuple <List <string>, List <double> > > rules2 = new Dictionary <string, Tuple <List <string>, List <double> > >
        {
            { "2", new Tuple <List <string>, List <double> >(new List <string> {
                    "2", "234"
                }, new List <double> {
                    0.80, 0.20
                }) },
            { "4", new Tuple <List <string>, List <double> >(new List <string> {
                    "654", "34652"
                }, new List <double> {
                    0.60, 0.40
                }) },
            { "6", new Tuple <List <string>, List <double> >(new List <string> {
                    "6", "64574"
                }, new List <double> {
                    0.20, 0.80
                }) }
        };

        //LSystem r1 = new LSystem(rules1, 3, 5);
        LSystem r1 = new LSystem(6, 10);
        //LSystem r2 = new LSystem(rules2, 3, 5);
        LSystem r2 = new LSystem(6, 10);

        LSystem r3 = LSystem.Crossover(r1, r2);

        //Iterate through L-system
        r3.Iterate(3);

        //Start writing in level file
        StartFile(path);
        WriteBlocksToFile(r3, path);
        EndFile(path);

        foreach (string axiom in r3.iterations)
        {
            Console.WriteLine(axiom);
        }

        string encodedString = LSystem.Encode(r3);

        Console.WriteLine(encodedString);
        LSystem decodedLSystem = LSystem.Decode(encodedString);

        Console.WriteLine(LSystem.Encode(decodedLSystem));


        Console.ReadKey();
    }