public static DNAData LoadDna(string DnafileName)
    {
        TextAsset textAsset = Resources.Load(DnafileName) as TextAsset;

        if (textAsset != null)
        {
            Stream          stream    = new MemoryStream(textAsset.bytes);
            BinaryFormatter formatter = new BinaryFormatter();
            data = formatter.Deserialize(stream) as DNAData;

            return(data);
        }

        return(null);
    }
Ejemplo n.º 2
0
    private void postDNA(List <GameObject> snapShotPopulation, List <float> scoreList)
    {
        SerializedGeneration currentGen = new SerializedGeneration(generation);

        RestClient.Put(api + "/generation.json", currentGen).Then((response) => {
            int i = 0;
            foreach (GameObject bot in snapShotPopulation)
            {
                Brain botBrain = bot.GetComponent <Brain>();
                DNA botDNA     = botBrain.dna;
                float score    = scoreList[i];

                DNAData botRecord = new DNAData(botDNA.genes, botDNA.fGenes, botDNA.dnaLength, botDNA.maxValue, score);

                RestClient.Put(api + "/currentSession/" + (generation - 1) + "/" + i + ".json", botRecord);
                i++;
            }
        });
    }
    public static bool LoadToNeuroEvolution(string resourcesFileName)
    {
        data = DnaDataManager.LoadDna(resourcesFileName);

        if (data != null)
        {
            data.SaveDNA(data.DeserializeDNA(), Application.persistentDataPath + "/temp");

            NeuroEvolution.LoadMembers(Application.persistentDataPath + "/temp");
            for (int i = 0; i < NeuroEvolution.members.Count; i++)
            {
                NeuroEvolution.trainQ.Enqueue(NeuroEvolution.members[i]);
            }
            return(true);
        }
        else
        {
            return(false);
        }
    }
 public static void Save(string fileName)
 {
     data = new DNAData();
     data.SaveDNA(NeuroEvolution.members, Application.dataPath + "/Resources/" + fileName + ".bytes");
 }