Ejemplo n.º 1
0
 public void Quarry(Point centralPoint, float widthOfSearch, List <Point> found)
 {
     if (!IntersectsWithRect(centralPoint.loc.X, centralPoint.loc.Y, widthOfSearch))
     {
         return;
     }
     else
     {
         colour = new Vector3(1, 1, 0);
         foreach (Point other in points)
         {
             if (centralPoint != other && Contains(other.loc, new Vector2(centralPoint.loc.X, centralPoint.loc.Y), new Vector2(widthOfSearch, widthOfSearch)))
             {
                 found.Add(other.Copy());
             }
         }
     }
     if (isDivided)
     {
         topleft.Quarry(centralPoint, widthOfSearch, found);
         topright.Quarry(centralPoint, widthOfSearch, found);
         botleft.Quarry(centralPoint, widthOfSearch, found);
         botright.Quarry(centralPoint, widthOfSearch, found);
     }
 }
Ejemplo n.º 2
0
        //public void UpdatePheromones()
        //{
        //   List<Pheromone> toRemove = new List<Pheromone>();

        //   foreach (var p in pathPheromones)
        //   {
        //      if (p.durationLeft == 0)
        //         toRemove.Add(p);
        //      else
        //         p.UpdateSaturation();
        //   }

        //   pathPheromones.RemoveAll(p => toRemove.Contains(p));

        //   toRemove = new List<Pheromone>();

        //   foreach (var p in foodPheromones)
        //   {
        //      if (p.durationLeft == 0)
        //         toRemove.Add(p);
        //      else
        //         p.UpdateSaturation();
        //   }

        //   foodPheromones.RemoveAll(p => toRemove.Contains(p));

        //   foreach (var ant in ants)
        //   {
        //      if (ant.isCarryingFood)
        //         foodPheromones.Add(new Pheromone(3, ant.loc, 150));
        //      else
        //         pathPheromones.Add(new Pheromone(3, ant.loc, 150));
        //   }
        //}

        public void SeekFood(QTree foodQTree)
        {
            foreach (var ant in ants)
            {
                if (!ant.isCarryingFood)
                {
                    List <Point> neibs = new List <Point>();
                    foodQTree.Quarry(new Point(ant.loc + ant.vel.Normalized() * ant.size * 3.5f), ant.size * 5f, neibs);

                    if (neibs.Count != 0)
                    {
                        Point minNeib = neibs[0];
                        float minDist = Vector2.Distance(neibs[0].loc, ant.loc);

                        foreach (var n in neibs)
                        {
                            float dist = Vector2.Distance(n.loc, ant.loc);
                            if (dist < minDist)
                            {
                                minDist = dist;
                                minNeib = n;
                            }
                        }

                        if (minDist < ant.size)
                        {
                            ant.isCarryingFood        = true;
                            ant.vel                  *= -1;
                            ant.pheromoneDurationLeft = ant.pheromoneDuration;
                        }
                        else
                        {
                            ant.Steer(minNeib.loc, 1f);
                        }
                    }
                }
            }
        }