Ejemplo n.º 1
0
        public bool BuildExtension(Ant ant)
        {
            // check conditions
            if (ant.BrickBag < MotherNature.BRICKS_TO_BUILD)
            {
                return(false);                                             // not enough bricks in the bag
            }
            if (ant.GetType().Name != "WorkerAnt")
            {
                return(false);                                   // only workers can build
            }
            if (!ConstructibleSpot(ant.SDLocation))
            {
                return(false);                                    // Bad spot
            }
            // find closest point of the anthill
            double distmin = myWorld.width;
            int    closest = 0;

            for (int idx = 0; idx < hill.Count(); idx++)
            {
                if (Helpers.Distance(hill[idx], ant.SDLocation) < distmin)
                {
                    distmin = Helpers.Distance(hill[idx], ant.SDLocation);
                    closest = idx;
                }
            }
            int insertat;
            // find the points before and after the closest
            int before = (closest == 0 ? hill.Count() - 1 : closest - 1);
            int after  = (closest == hill.Count() - 1 ? 0 : closest + 1);

            if (Helpers.Distance(hill[before], ant.SDLocation) < Helpers.Distance(hill[after], ant.SDLocation))
            {
                insertat = closest;
            }
            else
            {
                insertat = after;
            }

            hill.Insert(insertat, ant.SDLocation);
            return(true);
        }
Ejemplo n.º 2
0
        int IMotherNature.BagSize(Ant ant, Resource resource)
        {
            int res = 0;

            if (resource.GetType() == typeof(Food))
            {
                res = Ant.FOOD_BAG_SIZE;
                if (ant.GetType().Name == "FarmerAnt")
                {
                    res *= 20;                                    // farmers can carry 20 times more food
                }
            }
            else if (resource.GetType() == typeof(Brick))
            {
                res = Ant.BRICK_BAG_SIZE;
                if (ant.GetType().Name == "WorkerAnt")
                {
                    res *= 20;                                    // workers can carry 20 times more bricks
                }
            }
            res += (int)(ant.Strength / 10.0); // strength allow ants to carry more
            return(res);
        }
Ejemplo n.º 3
0
 /// <summary>
 /// Remove an ant from the colony (it's dead or illegal)
 /// </summary>
 /// <param name="ant"></param>
 public void Dispose(Ant ant)
 {
     ants.Remove(ant);
 }
Ejemplo n.º 4
0
 List <Pheromon> IMotherNature.SmellAround(Ant ant)
 {
     return(pheromons.Where(phero => new Vector(phero.Location.X - ant.X, phero.Location.Y - ant.Y).Length < Ant.SMELL_RANGE * phero.Intensity && ant.Colony == phero.Colony).ToList());
 }