// 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); } }
public void GenerateNewLevels() { RatingSystem.GenerateXMLs(lSystemIndex, 5); ABLevelSelect.loadXMLs(); levelSelect.LoadScreenshots(lSystemIndex); }
// Start is called before the first frame update void Start() { for (int i = 0; i < RatingSystem.keptForEvolution.Count; ++i) { if (RatingSystem.keptForEvolution[i].xmls.Count <= 0) { RatingSystem.GenerateXMLsForEvolution(i, 5); LoadXMLs(RatingSystem.keptForEvolution[i].xmls); RatingSystem.StartGetFitnessForEvolution(i); ABLevelSelector sel = gameObject.AddComponent <ABLevelSelector>(); sel.LevelIndex = 0; ABSceneManager.Instance.LoadScene("GameWorld", true, sel.UpdateLevelList); return; } } RatingSystem.EndGetFitnessForEvolution(); // TODO: Right here is when you have all the fitnesses for each lsystem in the RatingSystem.keptForEvolution // You can do more evolution here or pick the best 12 lSystems to put into RatingSystem.lSystems (for now just pick 12 lsystems, I'll make it possible to do more iterations tomorrow or something) List <LSystem> pop = new List <LSystem>(); List <float> fit = new List <float>(); // Getting lsystem and fitness foreach (RatingSystem.LSystemEvolution l in RatingSystem.keptForEvolution) { pop.Add(l.lSystem); fit.Add(l.fitness); } // Initialize LSystem evolver. LSystemEvolver evolver = new LSystemEvolver(NUM_RULES, MAX_WIDTH, MAX_HEIGHT, MUT_RATE); // Evolve population and store. List <LSystem> evolvedLSystems = null; if (SqlConnection.algorithm == Algorithm.MAPElites) { evolvedLSystems = evolver.EvolvePopulationMAPElitesEdition(RatingSystem.keptForEvolution); } else { evolvedLSystems = evolver.EvolvePopulation(pop, fit, MU, LAMBDA); } Debug.Log(evolvedLSystems.Count); RatingSystem.keptForEvolution.Clear(); --iterations; Debug.Log("finished iteration " + iterations); if (iterations > 0) { // do it again foreach (LSystem l in evolvedLSystems) { RatingSystem.keptForEvolution.Add(new RatingSystem.LSystemEvolution(l)); } ABSceneManager.Instance.LoadScene("Evolution"); } else { RatingSystem.lSystems = evolvedLSystems; // generate and load the XMLs for (int i = 0; i < RatingSystem.MAX_LSYSTEMS; ++i) { RatingSystem.GenerateXMLs(i, 5); } ABLevelSelect.loadXMLs(); // if you're done, then return to levelselectmenu MAKE SURE YOU HAVE 12 LSYSTEMS IN RATINGSYSTEM.LSYSTEM RatingSystem.keptForEvolution.Clear(); // maybe do this? ABSceneManager.Instance.LoadScene("LevelSelectMenu"); } }