コード例 #1
0
ファイル: Pools.cs プロジェクト: loophac/a-i-nts
 public Pheromone pickPheromone(TypePheromone type, Vector2 position, float smell)
 {
     if (this.PoolPheromones.Count == 0)
     {
         //TODO : remover quand on aura une idée de bonne taille, et extendre automatiquement
         throw new Exception("Pheromone pool is empty");
     }
     else
     {
         Pheromone p;
         lock (PoolPheromones)
         {
             p = PoolPheromones[PoolPheromones.Count - 1];
             PoolPheromones.RemoveAt(PoolPheromones.Count - 1);
         }
         p.Type = type;
         p.Smell = smell;
         p.Position = position;
         p.Enabled = true;
         p.Visible = true;
         game.Components.Add(p);
         if(type == TypePheromone.food)
             game.PheromonesFood.Add(p);
         else
             game.PheromonesWar.Add(p);
         return p;
     }
 }
コード例 #2
0
ファイル: Pools.cs プロジェクト: loophac/a-i-nts
 public Pheromone pickPheromone(TypePheromone type, Vector2 position, float smell)
 {
     if (this.PoolPheromones.Count == 0)
     {
         //TODO : remover quand on aura une idée de bonne taille, et extendre automatiquement
         throw new Exception("Pheromone pool is empty");
     }
     else
     {
         Pheromone p;
         lock (PoolPheromones)
         {
             p = PoolPheromones[PoolPheromones.Count - 1];
             PoolPheromones.RemoveAt(PoolPheromones.Count - 1);
         }
         p.Type     = type;
         p.Smell    = smell;
         p.Position = position;
         p.Enabled  = true;
         p.Visible  = true;
         game.Components.Add(p);
         if (type == TypePheromone.food)
         {
             game.PheromonesFood.Add(p);
         }
         else
         {
             game.PheromonesWar.Add(p);
         }
         return(p);
     }
 }
コード例 #3
0
ファイル: Ant.cs プロジェクト: loophac/a-i-nts
 protected void dropPheromone(TypePheromone type)
 {
     game.Reservoir.pickPheromone(type, position, Pheromone.SMELL_INIT);
 }
コード例 #4
0
ファイル: Ant.cs プロジェクト: loophac/a-i-nts
 protected void dropPheromone(TypePheromone type)
 {
     game.Reservoir.pickPheromone(type, position, Pheromone.SMELL_INIT);
 }
コード例 #5
0
        public Vector2 pheromonesAttraction(Vector2 position, TypePheromone type)
        {
            Vector2 attraction = Vector2.Zero;
            Vector2 attractionPhero;
            PheroSortedList scanPheromones ;

            if (type == TypePheromone.food)
            {
                scanPheromones = game.PheromonesFood;
            }
            else if (type == TypePheromone.war)
            {
                scanPheromones = game.PheromonesWar;
            }
            else
            {
                return attraction;
            }
            float smellXmin = owner.Position.X - TOLERANCE;
            float smellXmax = owner.Position.X + TOLERANCE;
            float smellYmin = owner.Position.Y - TOLERANCE;
            float smellYmax = owner.Position.Y + TOLERANCE;

            Pheromone indexPhero = new Pheromone(game,false);
            indexPhero.Position = new Vector2(smellXmin,0);
            int index;
            try
            {
                scanPheromones.Add(smellXmin, indexPhero);
                index = scanPheromones.IndexOfValue(indexPhero);
            }catch(ArgumentException){
                index = scanPheromones.IndexOfKey(smellXmin);
            }

            List<Pheromone> selected = new List<Pheromone>();

                for (int i = index; i < scanPheromones.Values.Count; i++)
                {
                    if (scanPheromones.Values[i].Position.X > smellXmax)
                    {
                        break;
                    }
                    if (scanPheromones.Values[i].Position.Y > smellYmin && scanPheromones.Values[i].Position.Y < smellYmax)
                    {
                        selected.Add(scanPheromones.Values[i]);
                    }
                }

            scanPheromones.Remove(indexPhero);
            foreach (Pheromone pheromone in selected)
            {
                attractionPhero = (pheromone.Position - position);
                float distance = attractionPhero.Length();
                float scallarProduct = attractionPhero.X * owner.Velocity.X + attractionPhero.Y * owner.Velocity.Y;
                if (totalAngle || scallarProduct > 0)
                {
                    attractionPhero.Normalize();
                    attractionPhero *=(Main.G_PHEROMONES * pheromone.Smell / (distance*distance*distance));
                    attraction += attractionPhero;
                }
            }
            return attraction;
        }
コード例 #6
0
        public Vector2 pheromonesAttraction(Vector2 position, TypePheromone type)
        {
            Vector2         attraction = Vector2.Zero;
            Vector2         attractionPhero;
            PheroSortedList scanPheromones;

            if (type == TypePheromone.food)
            {
                scanPheromones = game.PheromonesFood;
            }
            else if (type == TypePheromone.war)
            {
                scanPheromones = game.PheromonesWar;
            }
            else
            {
                return(attraction);
            }
            float smellXmin = owner.Position.X - TOLERANCE;
            float smellXmax = owner.Position.X + TOLERANCE;
            float smellYmin = owner.Position.Y - TOLERANCE;
            float smellYmax = owner.Position.Y + TOLERANCE;


            Pheromone indexPhero = new Pheromone(game, false);

            indexPhero.Position = new Vector2(smellXmin, 0);
            int index;

            try
            {
                scanPheromones.Add(smellXmin, indexPhero);
                index = scanPheromones.IndexOfValue(indexPhero);
            }catch (ArgumentException) {
                index = scanPheromones.IndexOfKey(smellXmin);
            }

            List <Pheromone> selected = new List <Pheromone>();

            for (int i = index; i < scanPheromones.Values.Count; i++)
            {
                if (scanPheromones.Values[i].Position.X > smellXmax)
                {
                    break;
                }
                if (scanPheromones.Values[i].Position.Y > smellYmin && scanPheromones.Values[i].Position.Y < smellYmax)
                {
                    selected.Add(scanPheromones.Values[i]);
                }
            }

            scanPheromones.Remove(indexPhero);
            foreach (Pheromone pheromone in selected)
            {
                attractionPhero = (pheromone.Position - position);
                float distance       = attractionPhero.Length();
                float scallarProduct = attractionPhero.X * owner.Velocity.X + attractionPhero.Y * owner.Velocity.Y;
                if (totalAngle || scallarProduct > 0)
                {
                    attractionPhero.Normalize();
                    attractionPhero *= (Main.G_PHEROMONES * pheromone.Smell / (distance * distance * distance));
                    attraction      += attractionPhero;
                }
            }
            return(attraction);
        }