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; } } } }
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); }
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; } } } }
private void ReleasePheromone(World world) { Pheromone.SpawnOn(world, Position, world.Dist(Position, world.Center) * 1.5); }
public void Remove(Pheromone obj) { comida.Remove(obj); }
public void Add(Pheromone obj) { comida.Add(obj); }