Пример #1
0
 public static SimulationConfiguration LoadConfigOrDefault()
 {
     if (File.Exists("Simulation.cfg"))
     {
         string                  sourceText       = File.ReadAllText("Simulation.cfg");
         Deserializer            yamlDeserializer = new Deserializer();
         SimulationConfiguration deserialized     = yamlDeserializer.Deserialize <SimulationConfiguration>(sourceText);
         CheckLoadedConfig(deserialized);
         // Write config with updated values
         SerializerBuilder builder = new SerializerBuilder();
         builder.EmitDefaults();
         Serializer yamlSerializer = builder.Build();
         string     serialized     = yamlSerializer.Serialize(deserialized);
         File.WriteAllText("Simulation.cfg", serialized);
         return(deserialized);
     }
     else
     {
         // Write out default config if there is no config for easier adjustment
         SerializerBuilder builder = new SerializerBuilder();
         builder.EmitDefaults();
         Serializer yamlSerializer = builder.Build();
         string     serialized     = yamlSerializer.Serialize(DefaultConfig);
         File.WriteAllText("Simulation.cfg", serialized);
         return(DefaultConfig);
     }
 }
Пример #2
0
 public static void CheckLoadedConfig(SimulationConfiguration config)
 {
     if (config.TickInterval <= 0)
     {
         Console.WriteLine("Reset TickInterval in config from {0} to {1}", config.TickInterval, 0.01f);
         config.TickInterval = 0.01f;
     }
 }
Пример #3
0
        public static void CheckLoadedConfig(SimulationConfiguration config)
        {
            if (config.TickInterval <= 0)
            {
                Console.WriteLine("Reset TickInterval in config from {0} to {1}", config.TickInterval, 0.01f);
                config.TickInterval = 0.01f;
            }

            if (config.NumCreatureTasks == 0)
            {
                config.NumCreatureTasks = Environment.ProcessorCount;
            }
            config.NumberOfStartNeuronLayers = Math.Max(1, config.NumberOfStartNeuronLayers);
            config.MinCreatures             = Math.Max(1, config.MinCreatures);
            config.TileMapSizeX             = Math.Max(1, config.TileMapSizeX);
            config.TileMapSizeY             = Math.Max(1, config.TileMapSizeY);
            config.MateBrainPercentage      = Math.Max(0.0f, Math.Min(1.0f, config.MateBrainPercentage));
            config.AddRemoveLayerPercentage = Math.Max(0.0f, Math.Min(1.0f, config.AddRemoveLayerPercentage));
            config.WaterPercentage          = Math.Max(0.0f, Math.Min(1.0f, config.WaterPercentage));
        }