public void ClickLoadPopulation()
    {
        DebugBot.DebugFunctionCall("LoadPopulationUI; ClickLoadPopulation(); ", debugFunctionCalls);
        Player currentPlayer = trainerModuleScript.gameController.masterTrainer.PlayerList[trainerModuleScript.gameController.masterTrainer.CurPlayer - 1];

        fileRootPath = Application.dataPath + "/SaveFiles/TrainingSaves/";
        string fileName = inputFieldFileName.text + fileExt;

        Debug.Log(fileRootPath + fileName);

        if (System.IO.File.Exists(fileRootPath + fileName))
        {
            TrainingSave trainingDataToLoad = ES2.Load <TrainingSave>(fileRootPath + fileName);;
            trainerModuleScript.gameController.masterTrainer.loadedTrainingSave = trainingDataToLoad;
            trainerModuleScript.gameController.masterTrainer.trainingModifierManager.activeTrainingModifierList = trainerModuleScript.gameController.masterTrainer.loadedTrainingSave.savedTrainingModifierList;
            // Leap of Faith:
            currentPlayer.masterPopulation                     = trainingDataToLoad.savedPopulation;
            GenomeNEAT.nextAvailableInnovationNumber           = trainingDataToLoad.savedPopulation.nextAvailableGeneInno;
            currentPlayer.masterPopulation.trainingGenerations = trainingDataToLoad.endGeneration; // keep track of total gens this population has trained on
            currentPlayer.masterPopulation.InitializeLoadedMasterAgentArray();                     // <-- somewhat hacky, re-assess later, but this is where the brains are created from genome
            currentPlayer.masterPopulation.isFunctional = true;
            currentPlayer.hasValidPopulation            = true;
            Debug.Log("Loaded Training Save!!! body nodes: " + currentPlayer.masterPopulation.templateGenome.ToString() + ", startGen: " + trainingDataToLoad.beginGeneration.ToString() + ", endGen: " + trainingDataToLoad.endGeneration.ToString());

            currentPlayer.masterCupid       = trainingDataToLoad.savedCrossoverManager;
            CrossoverManager.nextNodeInnov  = currentPlayer.masterCupid.savedNextNodeInnov;
            CrossoverManager.nextAddonInnov = currentPlayer.masterCupid.savedNextAddonInnov;

            trainerModuleScript.SetAllPanelsFromTrainerData();
        }
        else
        {
            Debug.LogError("No TrainingData File Exists!");
        }
    }
예제 #2
0
    public override void Read(ES2Reader reader, object c)
    {
        TrainingSave data = (TrainingSave)c;
        // Add your reader.Read calls here to read the data into the object.
        // Read the version number.
        int fileVersion = reader.Read <int>();

        // VERSION 0:
        if (fileVersion >= 0)
        {
            data.beginGeneration           = reader.Read <int>();
            data.endGeneration             = reader.Read <int>();
            data.savedCrossoverManager     = reader.Read <CrossoverManager>();
            data.savedFitnessComponentList = reader.ReadList <FitnessComponent>();
            data.savedMiniGameSettings     = reader.Read <MiniGameSettingsSaves>();
            data.savedPopulation           = reader.Read <Population>();
            data.savedTrialDataBegin       = reader.Read <TrialData>();
            data.savedTrialDataEnd         = reader.Read <TrialData>();
            data.savedTrainingModifierList = reader.ReadList <TrainingModifier>();
            if (fileVersion >= 1)
            {
                // new attributes
            }
        }
    }
예제 #3
0
    public override object Read(ES2Reader reader)
    {
        TrainingSave data = new TrainingSave();

        Read(reader, data);
        return(data);
    }
예제 #4
0
    public override void Write(object obj, ES2Writer writer)
    {
        TrainingSave data = (TrainingSave)obj;

        // Add your writer.Write calls here.
        writer.Write(0); // Version 1 is current version number
        // Make sure to edit Read() function to properly handle version control!
        // VERSION 0:
        writer.Write(data.beginGeneration);
        writer.Write(data.endGeneration);
        writer.Write(data.savedCrossoverManager);
        writer.Write(data.savedFitnessComponentList);
        writer.Write(data.savedMiniGameSettings);
        writer.Write(data.savedPopulation);
        writer.Write(data.savedTrialDataBegin);
        writer.Write(data.savedTrialDataEnd);
        writer.Write(data.savedTrainingModifierList);
        // VERSION 1:
    }
    public override object Read(ES2Reader reader)
	{
		TrainingSave data = new TrainingSave();
		Read(reader, data);
		return data;
	}
    public void ClickSaveCurrentPopulation() {
		DebugBot.DebugFunctionCall("SavePopulationUI; ClickSaveCurrentPopulation(); ", debugFunctionCalls);
		Player currentPlayer = trainerModuleScript.gameController.masterTrainer.PlayerList[trainerModuleScript.gameController.masterTrainer.CurPlayer-1];
		populationRef = currentPlayer.masterPopulation;
        saveRootPath = Application.dataPath + "/SaveFiles/TrainingSaves/";

        string fileName = inputFieldFileSaveName.text + fileExt;
		Debug.Log( saveRootPath + fileName);
		
		if(populationRef != null) { 
			Population populationToSave = populationRef;  // Current player's population
			
			bool save = true;
			if(System.IO.File.Exists (saveRootPath + fileName) && !toggleOverwriteSaves.isOn) {  
				Debug.Log ("File Already Exists!");
				save = false;
			}
			if(fileName == "") {
				Debug.Log ("No Filename Specified!");
				save = false;
			}            
			
			if(save) {   // SAVE:
                Debug.Log("SAVE TRAININGSAVE!!! filename: " + saveRootPath + fileName + ", pop size: " + populationToSave.masterAgentArray.Length.ToString());

                // Create wrapper to hold all save info:
                TrainingSave trainingSave = new TrainingSave();
                populationToSave.nextAvailableGeneInno = GenomeNEAT.nextAvailableInnovationNumber;
                currentPlayer.masterCupid.savedNextNodeInnov = CrossoverManager.nextNodeInnov;
                currentPlayer.masterCupid.savedNextAddonInnov = CrossoverManager.nextAddonInnov; // Save status of Inno#'s!!!!

                trainingSave.savedPopulation = populationToSave;
                trainingSave.beginGeneration = populationToSave.trainingGenerations;
                trainingSave.endGeneration = trainingSave.beginGeneration + trainerModuleScript.gameController.masterTrainer.PlayingCurGeneration - 1; // Check if -1 is needed
                trainingSave.savedPopulation.trainingGenerations = trainingSave.endGeneration;  // update it so that when it is loaded it has the proper start gen#

                trainingSave.savedCrossoverManager = currentPlayer.masterCupid;
                trainingSave.savedFitnessComponentList = currentPlayer.masterTrialsList[0].fitnessManager.gameFitnessComponentList;
                trainingSave.savedMiniGameSettings = new MiniGameSettingsSaves();
                // Copy the settings from the minigame instance into the SaveWrapper:
                currentPlayer.masterTrialsList[0].miniGameManager.miniGameInstance.gameSettings.CopySettingsToSave(trainingSave.savedMiniGameSettings);

                trainingSave.savedTrainingModifierList = trainerModuleScript.gameController.masterTrainer.trainingModifierManager.activeTrainingModifierList;

                trainingSave.savedTrialDataBegin = currentPlayer.dataManager.generationDataList[0].trialDataArray[0];
                trainingSave.savedTrialDataEnd = currentPlayer.dataManager.generationDataList[trainerModuleScript.gameController.masterTrainer.PlayingCurGeneration - 1].trialDataArray[0];
               
                ES2.Save(trainingSave, saveRootPath + fileName);
			}
		}
		else {
			Debug.LogError("No Population Exists!");
		}
	}
예제 #7
0
    public void ClickSaveCurrentPopulation()
    {
        DebugBot.DebugFunctionCall("SavePopulationUI; ClickSaveCurrentPopulation(); ", debugFunctionCalls);
        Player currentPlayer = trainerModuleScript.gameController.masterTrainer.PlayerList[trainerModuleScript.gameController.masterTrainer.CurPlayer - 1];

        populationRef = currentPlayer.masterPopulation;
        saveRootPath  = Application.dataPath + "/SaveFiles/TrainingSaves/";

        string fileName = inputFieldFileSaveName.text + fileExt;

        Debug.Log(saveRootPath + fileName);

        if (populationRef != null)
        {
            Population populationToSave = populationRef;              // Current player's population

            bool save = true;
            if (System.IO.File.Exists(saveRootPath + fileName) && !toggleOverwriteSaves.isOn)
            {
                Debug.Log("File Already Exists!");
                save = false;
            }
            if (fileName == "")
            {
                Debug.Log("No Filename Specified!");
                save = false;
            }

            if (save)                // SAVE:
            {
                Debug.Log("SAVE TRAININGSAVE!!! filename: " + saveRootPath + fileName + ", pop size: " + populationToSave.masterAgentArray.Length.ToString());

                // Create wrapper to hold all save info:
                TrainingSave trainingSave = new TrainingSave();
                populationToSave.nextAvailableGeneInno        = GenomeNEAT.nextAvailableInnovationNumber;
                currentPlayer.masterCupid.savedNextNodeInnov  = CrossoverManager.nextNodeInnov;
                currentPlayer.masterCupid.savedNextAddonInnov = CrossoverManager.nextAddonInnov; // Save status of Inno#'s!!!!

                trainingSave.savedPopulation = populationToSave;
                trainingSave.beginGeneration = populationToSave.trainingGenerations;
                trainingSave.endGeneration   = trainingSave.beginGeneration + trainerModuleScript.gameController.masterTrainer.PlayingCurGeneration - 1; // Check if -1 is needed
                trainingSave.savedPopulation.trainingGenerations = trainingSave.endGeneration;                                                           // update it so that when it is loaded it has the proper start gen#

                trainingSave.savedCrossoverManager     = currentPlayer.masterCupid;
                trainingSave.savedFitnessComponentList = currentPlayer.masterTrialsList[0].fitnessManager.gameFitnessComponentList;
                trainingSave.savedMiniGameSettings     = new MiniGameSettingsSaves();
                // Copy the settings from the minigame instance into the SaveWrapper:
                currentPlayer.masterTrialsList[0].miniGameManager.miniGameInstance.gameSettings.CopySettingsToSave(trainingSave.savedMiniGameSettings);

                trainingSave.savedTrainingModifierList = trainerModuleScript.gameController.masterTrainer.trainingModifierManager.activeTrainingModifierList;

                trainingSave.savedTrialDataBegin = currentPlayer.dataManager.generationDataList[0].trialDataArray[0];
                trainingSave.savedTrialDataEnd   = currentPlayer.dataManager.generationDataList[trainerModuleScript.gameController.masterTrainer.PlayingCurGeneration - 1].trialDataArray[0];

                ES2.Save(trainingSave, saveRootPath + fileName);
            }
        }
        else
        {
            Debug.LogError("No Population Exists!");
        }
    }