/// <summary> /// Simulates the Multiplication Activity of Rabbits /// </summary> /// <returns> /// Number of Rabbits that were Born /// </returns> private int rabbitMultipliaction() { int num = Rabbit.BirthRate[RabbitsCount][VegetationLevel] * (RabbitsCount / 2); Generation <Rabbit> newBorn = new Generation <Rabbit>(num); RabbitsGenerations.Add(newBorn); RabbitsGenerations.Sort(); return(num); }
/// <summary> /// Merge The Current Lis tof Rabbits Generation with another One /// </summary> /// <param name="o"> The List of Rabbits To merge With</param> public void Merge(List <Generation <Rabbit> > o) { RabbitsGenerations.Sort(); foreach (Generation <Rabbit> g in o) { int t = RabbitsGenerations.BinarySearch(g); if (t < 0) { t = ~t; RabbitsGenerations.Insert(t, g); } else { RabbitsGenerations[t].Animals.AddRange(g.Animals); } RabbitsCount += g.Count; } }
/// <summary> /// Simulates the Prey Activity of Foxes /// </summary> /// <param name="Date"the Day on which the Simulation Occurs</param> private void preyTheFoxes(int Date) { float prop = Fox.MinFoodProp; int AllowedWeekly = Fox.MinFoodAllowedWeekly; if (VegetationLevel > Fox.PlantationCoverRabbits) { prop = Fox.MaxFoodProp; AllowedWeekly = Fox.MaxFoodAllowedWeekly; } foreach (Generation <Fox> gen in FoxesGenerations) { foreach (Fox f in gen.Animals) { int i = 0; int e = 0; Random r = new Random(); while (f.EatenThisWeek + e < AllowedWeekly && i < RabbitsCount) { double t = r.NextDouble(); if (t <= prop) { e++; int rab = r.Next(RabbitsGenerations.Count); if (RabbitsGenerations.Count == 0) { return; } RabbitsGenerations[rab].Animals.RemoveAt(r.Next(RabbitsGenerations[rab].Count)); if (RabbitsGenerations[rab].Count == 0) { RabbitsGenerations.RemoveAt(rab); } RabbitsCount--; } i++; } f.Eat(e, Date); } } }