/// <summary> /// Generate tester gameobjects given the species list /// </summary> private void GeneratePopulation() { generationNumberText.text = "Generation Number: " + (generationNumber + 1); ResetWorld(); //reset world actualPopulationSize = 0; List <int[]> allID = new List <int[]>(); //2D id //x,y,z of placing the objects float x = -90f; float y = 0; float z = 80f; List <Population> species = speciesManager.GetSpecies(); int numberOfSpecies = species.Count; //save species count //create id's based on number of species in the species list for (int i = 0; i < species.Count; i++) { int numberOfNets = species[i].GetPopulation().Count; for (int j = 0; j < numberOfNets; j++) { allID.Add(new int[] { i, j }); } } for (int i = 0; i < species.Count; i++) { List <NEATNet> population = species[i].GetPopulation(); for (int j = 0; j < population.Count; j++) { //pick a random id, save it locally and remove it from the id list int randomIndex = UnityEngine.Random.Range(0, allID.Count); int[] randomId = allID[randomIndex]; allID.RemoveAt(randomIndex); if (x >= 90 && x > 0) { x = -90f; z += -25f; } else { x += 20f; } if (spawnInGrid == true) { CreateIndividual(new Vector3(x, y, z), species[randomId[0]].GetPopulation()[randomId[1]], species[i].GetColor(), randomId, randomAngle); } else { CreateIndividual(Vector3.zero, species[randomId[0]].GetPopulation()[randomId[1]], species[i].GetColor(), randomId, randomAngle); } actualPopulationSize++; } } draw.AddColorData(speciesManager.GetSpeciesColorData()); /*//create id's based on number of species in the species list * for (int i = 0; i < numberOfSpecies; i++) { * int numberOfNets = species[i].Count; * for (int j = 0; j < numberOfNets; j++) { * allID.Add(new int[] {i,j}); * } * } * * for (int i = 0; i < numberOfSpecies; i++) { //run through species count * int numberOfNets = species[i].Count; //number of species at i * * for (int j = 0; j < numberOfNets; j++) { //run through all species at i * //pick a random id, save it locally and remove it from the id list * int randomIndex = UnityEngine.Random.Range(0, allID.Count); * int[] randomId = allID[randomIndex]; * allID.RemoveAt(randomIndex); * * //create gameobject given location, network address, color and id value * Color color = new Color(colors[randomId[0], 0], colors[randomId[0], 1], colors[randomId[0], 2]); * //Color color = Color.red; * * //update withd and height location * if (width % 16 == 0 && width > 0) { * width = -16f; * height += -2f; * } * else { * width += 2f; * } * * if(spawnInGrid == true) * CreateIndividual(new Vector3(width, height, 0f), species[randomId[0]][randomId[1]], color, randomId); * else * CreateIndividual(Vector3.zero, species[randomId[0]][randomId[1]], color, randomId); * } * }*/ }
/// <summary> /// Generate tester gameobjects given the species list /// </summary> private void GeneratePopulation() { generationNumberText.text = "Generation Number: " + (generationNumber + 1); ResetWorld(); //reset world actualPopulationSize = 0; List <int[]> allID = new List <int[]>(); //2D id //x,y,z of placing the objects float x = -90f; float y = 0; float z = 80f; List <Population> species = speciesManager.GetSpecies(); int numberOfSpecies = species.Count; //save species count //create id's based on number of species in the species list for (int i = 0; i < species.Count; i++) { int numberOfNets = species[i].GetPopulation().Count; for (int j = 0; j < numberOfNets; j++) { allID.Add(new int[] { i, j }); } } for (int i = 0; i < species.Count; i++) { List <NEATNet> population = species[i].GetPopulation(); for (int j = 0; j < population.Count; j++) { //pick a random id, save it locally and remove it from the id list int randomIndex = UnityEngine.Random.Range(0, allID.Count); int[] randomId = allID[randomIndex]; allID.RemoveAt(randomIndex); if (x >= 90 && x > 0) { x = -90f; z += -25f; } else { x += 20f; } if (spawnInGrid == true) { CreateIndividual(new Vector3(x, y, z), species[randomId[0]].GetPopulation()[randomId[1]], species[i].GetColor(), randomId, randomAngle); } else { CreateIndividual(Vector3.zero, species[randomId[0]].GetPopulation()[randomId[1]], species[i].GetColor(), randomId, randomAngle); } actualPopulationSize++; } } draw.AddColorData(speciesManager.GetSpeciesColorData()); }