Esempio n. 1
0
        public override void Update(IBee bee, UpdateContext context)
        {
            var beehive          = bee.Beehive;
            var currentBeesCount = beehive.Bees.Count();

            if (beehive.MaximumNumberOfBees > currentBeesCount)
            {
                var choice = random.NextDouble();

                if (choice < 0.9d)
                {
                    return;
                }

                var newbee = new Bee(beehive, currentBeesCount + 1, new WorkingBeeBehaviour(random.Next(100, 500)));

                beehive.AddBee(newbee);
            }
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        public async Task <ISimulationSession> RunAsync()
        {
            var random  = new Random();
            var options = await optionsProvider.GetOptionsAsync(CancellationToken.None);

            var beehives = new Collection <IBeehive>();

            foreach (var index in Enumerable.Range(1, options.NumberOfBeehives + 1))
            {
                var maximumNumberOfBees = random.Next(options.MinimumNumberOfBees, options.MaximumNumberOfBees);
                var beehive             = new Beehive(index, maximumNumberOfBees);
                var hasQueen            = false;

                beehives.Add(beehive);

                foreach (var num in Enumerable.Range(0, beehive.MaximumNumberOfBees))
                {
                    IBeeBehaviour behaviour;

                    if (hasQueen)
                    {
                        var lifetime = random.Next(100, 500);
                        behaviour = new WorkingBeeBehaviour(lifetime);
                    }
                    else
                    {
                        behaviour = new QueenBeeBehaviour();
                        hasQueen  = true;
                    }

                    var bee = new Bee(beehive, num, behaviour);

                    beehive.AddBee(bee);
                }
            }

            return(new SimulationSession(beehives, options.Interval, Cleanup));
        }