Пример #1
0
        public void SaveGeneration()
        {
            var saveTo = new GeneticSaveData <T>();

            saveTo.Generation             = this.Generation;
            saveTo.AllGenesFromPopulation = new List <T[]>(Population.Count);
            for (int i = 0; i < Population.Count; i++)
            {
                saveTo.AllGenesFromPopulation.Add(new T[Population[i].Genes.Length]);
                Array.Copy(Population[i].Genes, saveTo.AllGenesFromPopulation[i], Population[i].Genes.Length);
            }
        }
Пример #2
0
        public bool readFrom(string name)
        {
            // 1 Check folder
            if (!Directory.Exists(Application.persistentDataPath + "/Previous"))
            {
                return(false);
            }
            // 2
            BinaryFormatter     bf   = new BinaryFormatter();
            FileStream          file = File.Open(Application.persistentDataPath + "/Previous/" + name + ".data", FileMode.Open);
            GeneticSaveData <T> save = (GeneticSaveData <T>)bf.Deserialize(file);

            file.Close();
            if (save.AllGenesFromPopulation.Count > 0)
            {
                this.Generation             = save.Generation;
                this.AllGenesFromPopulation = save.AllGenesFromPopulation;
                return(true);
            }
            return(false);
        }