/// <summary> /// Loads the simulation from save file with the format version 2 /// </summary> /// <param name="name">The name of the simulation save.</param> /// <param name="content">The Content of the save file.</param> public static SimulationData ParseSimulationData(string name, string content, LegacySimulationLoader.SplitOptions splitOptions) { var creatureName = name.Split('-')[0].Replace(" ", ""); if (string.IsNullOrEmpty(creatureName)) { creatureName = "Unnamed"; } var components = content.Split(splitOptions.SPLIT_ARRAY, System.StringSplitOptions.None); var simulationSettings = SimulationSettings.Decode(components[1]); var networkSettings = NeuralNetworkSettings.Decode(components[2]); var creatureData = components[3]; var creatureDesign = CreatureSerializer.ParseCreatureDesign(creatureData); creatureDesign.Name = creatureName; var bestChromosomesData = new List <string>(components[4].Split(splitOptions.NEWLINE_SPLIT, StringSplitOptions.None)); var bestChromosomes = new List <ChromosomeData>(); foreach (var chromosomeData in bestChromosomesData) { if (chromosomeData != "") { var stats = ChromosomeStats.FromString(chromosomeData); var data = new StringChromosomeData(stats.chromosome, stats.stats); bestChromosomes.Add(data.ToChromosomeData()); } } var chromosomeComponents = components[5].Split(splitOptions.NEWLINE_SPLIT, StringSplitOptions.None); var currentChromosomes = new List <float[]>(); foreach (var chromosome in chromosomeComponents) { if (chromosome != "") { currentChromosomes.Add(ConversionUtils.BinaryStringToFloatArray(chromosome)); } } var sceneDescription = DefaultSimulationScenes.DefaultSceneForObjective(simulationSettings.Objective); sceneDescription.PhysicsConfiguration = ScenePhysicsConfiguration.Legacy; return(new SimulationData( simulationSettings, networkSettings, creatureDesign, sceneDescription, bestChromosomes, currentChromosomes.ToArray(), bestChromosomes.Count )); }
/// <summary> /// Loads the simulation from save file with the format version 2 /// </summary> /// <param name="filename">The Filename has to end on .txt .</param> /// <param name="content">The Content of the save file.</param> private static void LoadSimulationFromSaveFileV2(string filename, string content, SplitOptions splitOptions, CreatureBuilder creatureBuilder, Evolution evolution) { var creatureName = filename.Split('-')[0].Replace(" ", ""); var components = content.Split(splitOptions.SPLIT_ARRAY, System.StringSplitOptions.None); var evolutionSettings = EvolutionSettings.Decode(components[1]); var networkSettings = NeuralNetworkSettings.Decode(components[2]); var creatureData = components[3]; CreatureSaver.LoadCreatureFromContents(creatureData, creatureBuilder); var bestChromosomesData = new List <string>(components[4].Split(splitOptions.NEWLINE_SPLIT, StringSplitOptions.None)); var bestChromosomes = new List <ChromosomeStats>(); foreach (var chromosomeData in bestChromosomesData) { if (chromosomeData != "") { bestChromosomes.Add(ChromosomeStats.FromString(chromosomeData)); } } var chromosomeComponents = components[5].Split(splitOptions.NEWLINE_SPLIT, StringSplitOptions.None); var currentChromosomes = new List <string>(); foreach (var chromosome in chromosomeComponents) { if (chromosome != "") { currentChromosomes.Add(chromosome); } } var currentGeneration = bestChromosomes.Count + 1; evolution.Settings = evolutionSettings; creatureBuilder.ContinueEvolution(evolution, () => { CreatureSaver.SaveCurrentCreatureName(creatureName); evolution.ContinueEvolution(currentGeneration, evolutionSettings, networkSettings, bestChromosomes, currentChromosomes); }); }