/// <summary> /// Aids a reproducer in giving birth. /// </summary> /// <param name="reproducer">The reproducer that is to give birth.</param> public void BirthAnimal(IReproducer reproducer) { // Birth animal. IReproducer baby = this.b168.BirthAnimal(reproducer); // If the baby is an animal... if (baby is Animal) { // Add the baby to the zoo's list of animals. this.AddAnimal(baby as Animal); } }
/// <summary> /// The button that births an aniaml. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void birthAnimalButton_Click(object sender, RoutedEventArgs e) { // Create a new bird. Animal bird = new Hummingbird("Jeffery", 23, 23, Gender.Male); // Make the bird pregnant. Then reprodudce. Lay egg. bird.MakePregnant(); IReproducer baby = bird.Reproduce(); // Create a new dingo, and make the dingo reproduce. Animal dude = new Dingo("jim", 32, 23, Gender.Male); IReproducer babyTwo = dude.Reproduce(); }
/// <summary> /// Creates another reproducer of its own type. /// </summary> /// <returns>The resulting baby reproducer.</returns> public override IReproducer Reproduce() { // Create a baby reproducer. IReproducer baby = base.Reproduce(); // If the animal is not a platypus and baby is an eater... if (this.GetType() != typeof(Platypus) && baby is IEater) { // Feed the baby. this.FeedNewborn(baby as IEater); } return(baby); }
/// <summary> /// Gives birth to a baby animal and feeds it. /// </summary> /// <returns>The baby animal.</returns> public IReproducer Reproduce() { // Make mother animal to be no longer pregnant. this.isPregnant = false; IReproducer baby = this.ReproduceBehavior.Reproduce(this); if (baby is Animal) { this.AddChild(baby as Animal); } return(baby); }
/// <summary> /// Creates another reproducer of its own type. /// </summary> /// <returns>The resulting baby reproducer.</returns> public override IReproducer Reproduce() { // Lay an egg. IReproducer baby = this.LayEgg(); // If the baby is hatchable... if (baby is IHatchable) { // Hatch the baby out of its egg. this.HatchEgg(baby as IHatchable); } // Return the (hatched) baby. return(baby); }
/// <summary> /// Births a reproducer. /// </summary> /// <returns>The resulting baby reproducer.</returns> public IReproducer BirthAnimal() { IReproducer baby = null; // Have the vet deliver the reproducer. if (this.PregnantAnimals.Count != 0) { baby = this.vet.DeliverAnimal(this.PregnantAnimals.Dequeue()); // Increase the temperature due to the heat generated from birthing. this.Temperature += 0.5; } return(baby); }
/// <summary> /// Creates another reproducer of its own type. /// </summary> /// <returns>The resulting baby reproducer.</returns> public override IReproducer Reproduce() { // Lay an egg. IReproducer result = this.LayEgg(); // If the baby is hatchable... if (result is IHatchable) { // Hatch the baby (egg). this.HatchEgg(result as IHatchable); } // Return the (hatched) baby. return(result); }
/// <summary> /// Births a reproducer. /// </summary> /// <param name="reproducer">The reproducer that is to give birth.</param> /// <returns>The resulting baby reproducer.</returns> public IReproducer BirthAnimal(IReproducer reproducer) { IReproducer baby = null; // If the reproducer is present and is pregnant... if (reproducer != null && reproducer.IsPregnant) { baby = this.vet.DeliverAnimal(reproducer); // Increase the temperature due to the heat generated from birthing. this.Temperature += 0.5; } return(baby); }
/// <summary> /// Has an animal reproduce. /// </summary> /// <param name="mother">The pregnant mother animal.</param> /// <returns>The baby animal.</returns> public IReproducer Reproduce(Animal mother) { IReproducer result = this.LayEgg(mother); if (result is IHatchable) { this.HatchEgg(result as IHatchable); } else { // TODO: Handle the situation where the baby isn't hatchable } return(result); }
/// <summary> /// Creates another reproducer of its own type. /// </summary> /// <returns>The resulting baby reproducer.</returns> public virtual IReproducer Reproduce() { IReproducer baby = null; baby = this.ReproduceBehavior.Reproduce(this); int randomGender = random.Next(0, 2); (baby as Animal).Gender = (randomGender == 0) ? Gender.Male : Gender.Female; this.children.Add(baby as Animal); // Make mother not pregnant after giving birth. this.isPregnant = false; return(baby); }
/// <summary> /// Births a reproducer. /// </summary> /// <param name="reproducer">The reproducer that is to give birth.</param> /// <returns>The resulting baby reproducer.</returns> public IReproducer BirthAnimal() { IReproducer baby = null; // If the reproducer is present and is pregnant... if (this.PregnantAnimals != null && this.PregnantAnimals.Count != 0) { // Give the deliver animal method the first animal in the stack. baby = this.vet.DeliverAnimal(this.PregnantAnimals.Dequeue()); // Increase the temperature due to the heat generated from birthing. this.Temperature += 0.5; } return(baby); }
/// <summary> /// Aids the specified reproducer in delivering its baby. /// </summary> /// <param name="reproducer">The reproducer that is to give birth.</param> /// <returns>The resulting baby reproducer.</returns> public IReproducer DeliverAnimal(IReproducer reproducer) { // Sterilize birthing area. this.SterilizeBirthingArea(); // Give birth. IReproducer baby = reproducer.Reproduce(); // Wash up birthing area. this.WashUpBirthingArea(); // Increase counter. this.animalDeliveryCount++; return baby; }
/// <summary> /// Has an animal lay an egg. /// </summary> /// <param name="mother">The pregnant mother animal.</param> /// <returns>The baby animal.</returns> private IReproducer LayEgg(Animal mother) { // Define and initialize a result variable. IReproducer result = null; // Set the baby animal weight based upon its type. double weight = mother.Weight * (mother.BabyWeightPercentage / 100); // Create a baby animal of the same type as the mother. Gender gender = LayEggBehavior.random.Next(0, 2) == 0 ? Gender.Female : Gender.Male; result = (IReproducer)Activator.CreateInstance(mother.GetType(), "Baby", 0, weight, gender); // Reduce the mother's weight by 1.5 times the baby's weight. mother.Weight -= weight * 1.5; // Return result. return(result); }
/// <summary> /// Births a reproducer. /// </summary> /// <param name="reproducer">The reproducer that is to give birth.</param> /// <returns>The resulting baby reproducer.</returns> public IReproducer BirthAnimal() { IReproducer baby = null; // If the reproducer is present and is pregnant... if (this.PregnantAnimals.Count != 0) { // Have the vet deliver the reproducer. baby = this.vet.DeliverAnimal(this.PregnantAnimals.Dequeue()); // Increase the birthing room's temperature due to the heat generated from birthing. this.Temperature += 0.5; } else { throw new NullReferenceException("No animals in the zoo are currently pregnant."); } return(baby); }
/// <summary> /// Aids the specified reproducer in delivering its baby. /// </summary> /// <param name="reproducer">The reproducer that is to give birth.</param> /// <returns>The resulting baby reproducer.</returns> public IReproducer DeliverAnimal(IReproducer reproducer) { // Sterilize birthing area. this.SterilizeBirthingArea(); // Give birth. IReproducer baby = reproducer.Reproduce(); if (baby is IMover) { // Make the baby move. (baby as IMover).Move(); } if (baby is Animal) { // Name the baby. (baby as Animal).Name = "Baby"; } return(baby); }
/// <summary> /// Has an animal reproduce. /// </summary> /// <param name="mother">The pregnant mother animal.</param> /// <returns>The baby animal.</returns> public IReproducer Reproduce(Animal mother) { // Define and initialize a result variable. IReproducer baby = null; // Set the baby animal weight based upon its type. double weight = mother.Weight * (mother.BabyWeightPercentage / 100); // Create a baby animal of the same type as the mother. Gender gender = GiveBirthBehavior.random.Next(0, 2) == 0 ? Gender.Female : Gender.Male; baby = (IReproducer)Activator.CreateInstance(mother.GetType(), "Baby", 0, weight, gender); // Reduce the mother's weight by 1.5 times the baby's weight. mother.Weight -= weight * 1.5; if (mother is Mammal) { this.FeedNewborn(mother as Mammal, baby as Mammal); } // Return result. return(baby); }
public void values_init() { //---pobranie danych z bazy danych--- var db = new BazaDanychDataContext(); IDictionary<Przedmiot, IList<Prowadzący>> prowadzacyZajecia; IList<Zajecia> genotyp; InitializeFromDataBase(db, this.comboBox1.Text, out genotyp, out prowadzacyZajecia); Application.DoEvents(); //---przypisanie genotypu--- Timetable.Genome = genotyp; //---randomy--- DoubleRandomGenerator randMutation = new DoubleRandomGenerator(); DoubleRandomGenerator randSelector = new DoubleRandomGenerator(); IntegerRandomGenerator randGen = new IntegerRandomGenerator(); IntegerRandomGenerator randMateUp = new IntegerRandomGenerator(); IntegerRandomGenerator randGenSelector = new IntegerRandomGenerator(); //---komponenty algorytmu--- population = new List<Timetable>(); mutation = new TimetableTeacherMutation(prowadzacyZajecia, randMutation, randGenSelector, 0.02); breeder = new TimetableFactory(mutation, randMateUp); evalSelector = new TimetableEvaluator(); //Timetable primeChromosome = breeder.CreateNew(); reproducer = new CrossOverReproducer<Timetable, TimetableLocus, Zajecia>(randMateUp, breeder, new CrossOverReproducer<Timetable, TimetableLocus, Zajecia>.Config() { ChildCount = 2, ParentCount = 2 }); selector = new RouletSelector<Timetable, TimetableLocus, Zajecia>(evalSelector, randSelector); //---inicjacja populacji--- (calosciowy plan dla uczelni) //Application.DoEvents(); for (int i = 0; i < MaxPopulationCount; i++) population.Add(breeder.CreateNew()); //moze zrobic tak... //populacje duzych planow rozpic na N populacjie mniejszych planow //dla kazdego duzego planu //duzy plan uzyskany z populacji rozbic na mniejsze juz teraz //stworzyc populacje pomiejszych planow //przeprowadzic iteracje GA //potem wszystkie te plany skonkatenowac //odtworzyc populacje duzych planow //i ocenic... it = 0; this.wykres.Series[0].Points.Clear(); this.wykres.Series[1].Points.Clear(); this.comboBox1.Enabled = true; this.poprzedni.Enabled = false; this.nastepny.Enabled = true; wybranaGrupa_SelectedIndexChanged(null, null); this.dataGridView1.ReadOnly = false; this.dataGridView1.AllowUserToDeleteRows = true; this.dataGridView2.ReadOnly = false; this.dataGridView2.AllowUserToDeleteRows = true; this.dataGridView3.ReadOnly = false; this.dataGridView3.AllowUserToDeleteRows = true; this.dataGridView4.ReadOnly = false; this.dataGridView4.AllowUserToDeleteRows = true; this.dataGridView5.ReadOnly = false; this.dataGridView5.AllowUserToDeleteRows = true; }
public IReadOnlyCollection <Creature> Reproduce(IReproducer reproducer) { return(reproducer.Reproduce(this)); }