public List <IFowl> Birth() { List <IFowl> children = new List <IFowl>(); int numberOfChildren = NumberOfChildrenCalculation(); for (int i = 0; i < numberOfChildren; i++) { decimal randomNumber = (decimal)Coop.Random.NextDouble(); IFowl child; if (randomNumber <= RabbitConstraints.FemaleBirthRate) { child = new FemaleRabbit(Coop); } else { child = new MaleRabbit(Coop); } child.Mother = this; child.Father = this.Impregnating; children.Add(child); } IsPregnancy = false; Impregnating = null; PregnancyDate = null; return(children); }
private List <IMaleFowl> Mating(List <IFemaleFowl> femaleList, List <IMaleFowl> maleList, Dictionary <IMaleFowl, List <IFemaleFowl> > dictionary) { while (femaleList.Count > 0) { if (maleList.Count == 0) { maleList = dictionary.Keys.ToList(); } int maleIndex = Random.Next(0, maleList.Count); IMaleFowl selectedMale = maleList[maleIndex]; maleList.RemoveAt(maleIndex); int femaleIndex = Random.Next(0, femaleList.Count); IFemaleFowl selectedFemale = femaleList[femaleIndex]; femaleList.RemoveAt(femaleIndex); if (dictionary.TryGetValue(selectedMale, out List <IFemaleFowl> result)) { result.Add(selectedFemale); } else { List <IFemaleFowl> femaleFowls = new List <IFemaleFowl>(); femaleFowls.Add(selectedFemale); dictionary.Add(selectedMale, femaleFowls); } } return(maleList); }