コード例 #1
0
        public static void SpawnOn(World world, PointF pos, double intensity = 100)
        {
            if (intensity > 100)
            {
                intensity = 100;
            }

            Pheromone[] neighbours = world.GameObjectsNear(pos)
                                     .Select(each => each as Pheromone)
                                     .Where(p => p != null)
                                     .ToArray();

            if (neighbours.Length == 0)
            {
                // No objects there
                Pheromone clone = new Pheromone(intensity);
                clone.Position = pos;
                world.Add(clone);
            }
            else
            {
                foreach (Pheromone p in neighbours)
                {
                    if (p.Intensity < intensity)
                    {
                        p.Intensity = intensity;
                    }
                }
            }
        }
コード例 #2
0
        public static List <Pheromone> PheromonesNear(PointF pos, World world)
        {
            List <Pheromone> nearPheromones = new List <Pheromone>();

            //if (pos.X > 1 && pos.X < 124 && pos.Y > 1 && pos.Y < 124)
            //{
            pos = Mod(pos, world.size);

            for (int x = -1; x < 2; x++)
            {
                for (int y = -1; y < 2; y++)
                {
                    if ((int)pos.X + x > 0 && (int)pos.X + x < 125)
                    {
                        if ((int)pos.Y + y > 0 && (int)pos.Y + y < 125)
                        {
                            Pheromone pheromoneTest = (Pheromone)pheromones[(int)pos.X + x, (int)pos.Y + y];
                            if (pheromoneTest != null)
                            {
                                if (world.Dist(pos, pheromoneTest.Position) < 1)
                                {
                                    nearPheromones.Add(pheromoneTest);
                                }
                            }
                        }
                    }
                }
            }
            //}
            return(nearPheromones);
        }
コード例 #3
0
        public static void SpawnOn(World world, PointF pos, double intensity = 100)
        {
            if (intensity > 100)
            {
                intensity = 100;
            }

            List <Pheromone> neighbours = PheromonesNear(pos, world);

            //List<Pheromone> neighbours = world.PheromonesTestNear(pos)
            //    .Select(each => each as Pheromone)
            //    .Where(p => p != null).ToList();

            if (neighbours.Count == 0)//Solo si la cantidad de vecinos es 0 deberia ejecutarse.
            {
                // No objects there
                Pheromone clone = new Pheromone(intensity);//Clona
                clone.Position = pos;

                //Verifica si ya hay una feromona en esa posición.
                Pheromone pheromoneVerification = (Pheromone)pheromones[(int)pos.X, (int)pos.Y];
                if (pheromoneVerification != null)
                {
                    world.Remove(pheromoneVerification);
                    pheromones[(int)pos.X, (int)pos.Y] = clone;
                    world.Add(clone);
                }
                else
                {
                    pheromones[(int)pos.X, (int)pos.Y] = clone;
                    world.Add(clone);
                }

                //if (world.IsInside(clone.Position))
                //{

                //}
                //else
                //{
                //    clone.Position = Mod(clone.Position, world.size);
                //    world.Add(clone);
                //}
            }
            else
            {
                foreach (Pheromone p in neighbours)
                {
                    if (p.Intensity < intensity)
                    {
                        p.Intensity = intensity;
                    }
                }
            }
        }
コード例 #4
0
 private void ReleasePheromone(World world)
 {
     Pheromone.SpawnOn(world, Position, world.Dist(Position, world.Center) * 1.5);
 }
コード例 #5
0
 public void Remove(Pheromone obj)
 {
     comida.Remove(obj);
 }
コード例 #6
0
 public void Add(Pheromone obj)
 {
     comida.Add(obj);
 }