public IEnumerable <LifeModel> CreateNewGeneration(int generationCount) { var rnd = new Random(); var newGeneration = new List <LifeModel>(); for (int i = 0; i < generationCount; i++) { var tempValue = ((double)rnd.Next(10, 14)) / 10; var isPlus = rnd.Next(2); var speed = isPlus > 0 ? Speed * (2 - tempValue) : Speed * tempValue; tempValue = ((double)rnd.Next(10, 14)) / 10; isPlus = rnd.Next(2); var width = isPlus > 0 ? Size.Width * (2 - tempValue) : Size.Width * tempValue; var size = new Size((int)width, (int)width); tempValue = ((double)rnd.Next(10, 14)) / 10; isPlus = rnd.Next(2); var saturation = isPlus > 0 ? Saturation * (2 - tempValue) : Saturation * tempValue; var config = new LifeConfiguration() { HungerValue = 0, Size = size, Speed = (int)speed, SaturationValue = (int)saturation }; var nextgenObj = new LifeModel(config); newGeneration.Add(nextgenObj); } return(newGeneration); }
public static LifeModel CreateRandomLife() { var rnd = new Random(); var size = rnd.Next(5, 50); var posX = rnd.Next(0, 800); var posY = rnd.Next(0, 800); var lifeConfig = new LifeConfiguration() { Size = new Size(size, size), Position = new Point(posX, posY), Speed = rnd.Next(2, 10), HungerValue = rnd.Next(1, 30), SaturationValue = rnd.Next(1, 30) }; return(new LifeModel(lifeConfig)); }
public LifeModel(LifeConfiguration configuration) : base(configuration.Position, configuration.Size) { Speed = configuration.Speed; Saturation = ((double)configuration.SaturationValue) / 10; }