Beispiel #1
0
 private void DestroyQueen(GameObject queen)
 {
     Bees.Remove(queen);
     if (DestroyingBee != null)
     {
         DestroyingBee(queen);
     }
     if (DestroyingQueenBee != null)
     {
         DestroyingQueenBee(queen);
     }
     Destroy(queen);
 }
Beispiel #2
0
 private void DestroyDrone(GameObject drone)
 {
     Bees.Remove(drone);
     if (DestroyingBee != null)
     {
         DestroyingBee(drone);
     }
     if (DestroyingDroneBee != null)
     {
         DestroyingDroneBee(drone);
     }
     Destroy(drone);
 }
 protected override void OnSimObjectUpdating(SimObject simObject, SimModel simModel, SimState simState)
 {
     if (Bees.Count < 30 && Bees.Count < simState.MillisecondsSinceSimStart / 1000.0)
     {
         var bee = new Actor(SpawnLocation);
         if (simModel.DetectCollisions(bee).Any())
         {
             return;
         }
         bee.Behaviours.Add(new BeeBehaviour(_random, simObject));
         bee.Behaviours.Add(new NectarCarrierBehaviour());
         Bees.Add(bee);
         simModel.AddSimObject(bee);
     }
 }
Beispiel #4
0
        public GameObject CreateDroneBee(Vector2 position)
        {
            GameObject newBee = (GameObject)Instantiate(droneBee, position, Quaternion.identity);

            Bees.Add(newBee);
            newBee.transform.SetParent(worldCanvas.transform);

            if (BeeCreated != null)
            {
                BeeCreated(newBee);
            }
            if (DroneBeeCreated != null)
            {
                DroneBeeCreated(newBee);
            }
            return(newBee);
        }
Beispiel #5
0
        public BeesViewModel()
        {
            for (int i = 0; i < 10; i++)
            {
                Bees.Add(new WorkerBee());
            }

            for (int i = 0; i < 10; i++)
            {
                Bees.Add(new DroneBee());
            }

            for (int i = 0; i < 10; i++)
            {
                Bees.Add(new QueenBee());
            }
        }
Beispiel #6
0
        public void Test()
        {
            Bees          bee = new Bees();
            IOptiTestFunc f   = new Weierstrass();

            bee.dimension   = 10;
            bee.searchSpace = f.SearchSpace;
            double[] res = bee.Opti(f.Func);
            double   val = f.Func(res);

            Assert.AreEqual(f.MinimumValue, val, 5);

            bee             = new Bees();
            f               = new SumSquares();
            bee.dimension   = 10;
            bee.searchSpace = f.SearchSpace;
            res             = bee.Opti(f.Func);
            val             = f.Func(res);
            Assert.AreEqual(f.MinimumValue, val, 5);
        }
        public void Go(Random random)
        {
            hive.Go(random);

            for (int i = Bees.Count - 1; i >= 0; i--)
            {
                Bee bee = Bees[i];
                bee.Go(random);
                if (bee.CurrentState == BeeState.退休)
                {
                    Changed("蜜蜂 #" + bee.ID + ": 死亡,享年" + bee.Age + "回合");
                    Bees.Remove(bee);
                }
            }

            double totalNectarHarvested = 0;

            for (int i = Flowers.Count - 1; i >= 0; i--)
            {
                Flower flower = Flowers[i];
                flower.Go();
                totalNectarHarvested += flower.NectarHarVested;
                if (!flower.Alive)
                {
                    Flowers.Remove(flower);
                }
            }
            if (totalNectarHarvested > NectarHarvestedPerNewFlower && Flowers.Count <= MaxFlower)
            {
                foreach (Flower flower in Flowers)
                {
                    flower.NectarHarVested = 0;
                }
                AddFlower(random);
            }
        }
Beispiel #8
0
        /// <summary>
        /// Performs the colony search for the optimal food source.  Thread safe.
        /// </summary>
        /// <returns>A List of FoodSources that have been sorted by the fittest at the top.</returns>
        public List <FoodSource> Run()
        {
            List <FoodSource> employedBeeSelection = new List <FoodSource>();
            List <FoodSource> onlookerBeeSelection = new List <FoodSource>();

            //Send Employeed Bees
            Bees.Where(x => x.Status == Bee.StatusType.EMPLOYED).ToList().ForEach(bee => {
                lock (objFoodSource) {
                    PerformBeePrimaryAndNeighborFitness(foodSources[bee.RandomSolution[0]],
                                                        bee, employedBeeSelection);
                }
            });
            employedBeeSelection.Sort(new FoodSourceComparer());
            int topValue = (int)(employedBeeSelection.Count * .3d);             //top 30% dances win for health.

            //Each onlooker watches the dance of employed bees and chooses one of their sources depending on the dances,
            //and then goes to that source. After choosing a neighbour around that, she evaluates its nectar amount.
            Bees.Where(x => x.Status == Bee.StatusType.ONLOOKER).ToList().ForEach(bee => {
                int nextTest = Rand.Next(0, topValue);
                lock (objFoodSource) {
                    var primaryFoodSource = employedBeeSelection[nextTest];
                    PerformBeePrimaryAndNeighborFitness(primaryFoodSource, bee, onlookerBeeSelection);
                }
            });

            lock (objFoodSource) {
                //Abandoned food sources are determined and are replaced with the
                //new food sources discovered by scouts.
                foodSources.Sort(new FoodSourceComparer());

                //Reset the foodsources where the trial count has gone > MaxVisits.
                foodSources.Where(x => x.TrialsCount > MaxVisits).ToList().ForEach(x => {
                    x.TrialsCount = 0;
                    x.IsAbandoned = false;
                });

                //Load resources for scouts to identify.
                List <FoodSource> scoutFoodOptions = foodSources.Where(x => x.IsAbandoned).ToList();
                if (scoutFoodOptions == null)
                {
                    scoutFoodOptions = new List <FoodSource>();
                }

                lock (newFoodSourceQueueLock) {
                    while (newFoodSourceQueue.Count() > 0)
                    {
                        var fs = newFoodSourceQueue.Dequeue();
                        scoutFoodOptions.Add(fs);
                        lock (objFoodSource) foodSources.Add(fs);
                    }
                }

                if (scoutFoodOptions.Count > 0)
                {
                    //scouts -> explore IsAbandoned.  Clear the queue of new items.
                    //have the scouts attempt a query against any new sites to seed them into the future state.
                    Bees.Where(x => x.Status == Bee.StatusType.SCOUT).ToList().ForEach(bee =>
                    {
                        int randEntry = Rand.Next(scoutFoodOptions.Count - 1);
                        PerformBeePrimaryAndNeighborFitness(scoutFoodOptions[randEntry], bee, foodSources);
                        scoutFoodOptions.Remove(scoutFoodOptions[randEntry]);
                    });
                }
            }             //end lock

            return(foodSources);
        }