public void Save() { //genomes.Clear(); //species.Clear(); //for (int i = 0; i < agents.Count; i++) // { // genomes.Add(agents[i].GetComponent<Brain>().GetGenome()); // } if (neat.speciation) { List <Species> species = neat.GetSpecies(); SpeciesWrapper sw = new SpeciesWrapper(); sw.species = species; sw.generation = neat.GetGeneration(); sw.gt = neat.GetTracker(); Debug.Log(sw.species.Count); string json = JsonUtility.ToJson(sw); Debug.Log(json); //PlayerPrefs.DeleteKey("Genomes"); PlayerPrefs.SetString("Genomes", json); Debug.Log(json); Debug.Log(neat.GetGenomes()[0]); } else { List <Genome> genomes = new List <Genome>(); List <Genome> genomes2 = neat.GetGenomes(); for (int i = 0; i < genomes2.Count; i++) { genomes.Add(genomes2[i].Copy()); } Debug.Log(genomes.Count); GenomesWrapper gw = new GenomesWrapper(); gw.genomes = genomes; gw.generation = neat.GetGeneration(); gw.gt = neat.GetTracker(); string json = JsonUtility.ToJson(gw); //PlayerPrefs.DeleteKey("Genomes"); PlayerPrefs.SetString("Genomes", json); Debug.Log(json); } impf.OnSave(); }
public void Write(int generation, float best, float avg, int cons, int nodes, int species) { Neat neat = GetComponent <Neat>(); StringBuilder csv = new StringBuilder(); if (neat.GetGeneration() == 1) { csv.AppendLine("generation, best fitness, average fitness, number of connections, number of nodes, number of species"); name = System.DateTime.Now.ToString("-yyyy-MM-dd-HH-mm-ss"); } List <GameObject> agents = gen.GetAgents(); csv.AppendLine(generation + "," + best + "," + avg + "," + cons + "," + nodes + "," + species); string path = Path.Combine(Application.persistentDataPath, "data\\data" + name + ".csv"); //File.Delete(path); File.AppendAllText(path, csv.ToString()); }