/// <summary> /// Saves the given information about an evolution simulation of a creature in a file, so that /// it can be loaded and continued at the same generation again. /// The filename cannot contain dots (.) /// Throws: IllegalFilenameException /// /// Returns: The filename of the saved file. /// </summary> //public static string WriteSaveFile(string creatureName, Evolution.Task task, int timePerGen, int generationNumber, string creatureSaveData, List<ChromosomeInfo> bestChromosomes, List<string> currentChromosomes) { public static string WriteSaveFile(string creatureName, EvolutionSettings settings, NeuralNetworkSettings networkSettings, int generationNumber, string creatureSaveData, List <ChromosomeStats> bestChromosomes, List <string> currentChromosomes) { var splitOptions = new SplitOptions(); var date = System.DateTime.Now.ToString("yyyy-MM-dd"); //var taskName = Evolution.TaskToString(task); var filename = string.Format("{0} - {1} - {2} - Gen({3}).txt", creatureName, settings.task, date, generationNumber); // MAYBE IMPORTANT FOR THE FUTURE: Changed from Gen:i to Gen(i) var stringBuilder = new StringBuilder(); // Add the task type //stringBuilder.AppendLine(((int)task).ToString()); // Add the version number stringBuilder.AppendLine(string.Format("v {0}", version.ToString())); stringBuilder.Append(splitOptions.COMPONENT_SEPARATOR); // Add the time per generation //stringBuilder.AppendLine(settings.simulationTime.ToString()); //stringBuilder.Append(COMPONENT_SEPARATOR); // Add the encoded evolution settings stringBuilder.AppendLine(settings.Encode()); stringBuilder.Append(splitOptions.COMPONENT_SEPARATOR); // Add the encoded neural network settings stringBuilder.AppendLine(networkSettings.Encode()); stringBuilder.Append(splitOptions.COMPONENT_SEPARATOR); // Add the creature save data stringBuilder.AppendLine(creatureSaveData); stringBuilder.Append(splitOptions.COMPONENT_SEPARATOR); // Add the list of best chromosomes foreach (var chromosome in bestChromosomes) { stringBuilder.AppendLine(chromosome.ToString()); } stringBuilder.Append(splitOptions.COMPONENT_SEPARATOR); // Add the list of current chromosomes foreach (var chromosome in currentChromosomes) { stringBuilder.AppendLine(chromosome); } stringBuilder.Append(splitOptions.COMPONENT_SEPARATOR); var path = RESOURCE_PATH; //Path.Combine(RESOURCE_PATH, SAVE_FOLDER); path = Path.Combine(path, filename); int counter = 2; while (System.IO.File.Exists(path)) { //var pattern = new Regex(@"( \d+)?.txt"); var pattern = @"( \d+)?.txt"; filename = Regex.Replace(filename, pattern, string.Format(" {0}.txt", counter)); path = Path.Combine(RESOURCE_PATH, filename); //path = path.Replace(".txt", string.Format(" ({0}).txt", counter)); //filename = filename.Replace(".txt", string.Format(" ({0}).txt", counter)); counter++; } CreateSaveFolder(); File.WriteAllText(path, stringBuilder.ToString()); return(filename); }
private void SaveEvolutionSettings(EvolutionSettings settings) { PlayerPrefs.SetString(EVOLUTION_SETTINGS_KEY, settings.Encode()); }