Example #1
0
        private void InitCell(Point point, char c)
        {
            KilledAntsMap[point] = new List<Cell>();
            if (c >= '0' && c <= '9')
            {
                int command = c - '0';
                var hill = new Hill(point, command, this);
                Armies[command].Hills.Add(hill);
                OriginalMap[point] = hill;
                ObjectsMap[point] = new Empty(point, this);

            }
            else if (c >= 'a' && c <= 'j')
            {
                int command = c - 'a';
                var ant = new Ant(point, command, this);
                Armies[command].Ants.Add(ant);
                OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this);
                ObjectsMap[point] = ant;
            }
            else if (c >= 'A' && c <= 'J')
            {
                int command = c - 'A';
                var hill = new Hill(point, command, this);
                Armies[command].Hills.Add(hill);
                var ant = new Ant(point, command, this);
                Armies[command].Ants.Add(ant);
                OriginalMap[point] = hill;
                ObjectsMap[point] = ant;
            }
            else if (c == '*')
            {
                var food = new Food(point, this);
                Food.Add(food);
                OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this);
                ObjectsMap[point] = food;
            }
            else if (c == '!')
            {
                OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this);
                ObjectsMap[point] = new Empty(point, this);
                KilledAntsMap[point].Add(new Ant(point, -1, this).GetDead());
            }
            else if (c == '%')
            {
                OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Water, this);
                ObjectsMap[point] = new Empty(point, this);
            }
            else if (c == '.')
            {
                OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Land, this);
                ObjectsMap[point] = new Empty(point, this);
            }
            else
            {
                OriginalMap[point] = new UnMovableCell(point, Cell.CellType.Unseen, this);
                ObjectsMap[point] = new Empty(point, this);
            }
        }
Example #2
0
        public int GetEnemiesCount(Ant ant)
        {
            var commandId = ant.CommandNumber;

            var statistic = GetPointStatistic(ant.Coords, AttackRadius2);
            int sum = 0;
            for (int i = 0; i < statistic.Length; i++ )
            {
                if (i != commandId)
                    sum += statistic[i];
            }
            return sum;
        }
Example #3
0
        public bool IsAntDead(Ant ant, Dictionary<Ant, int> enemiesCount)
        {
            var antEnemiesCount = enemiesCount[ant];

            return GetNearCells(ant.Coords, AttackRadius2)
                        .Where(cell => cell is Ant && ((Ant)cell).CommandNumber != ant.CommandNumber && !((Ant)cell).IsDead)
                        .Select(cell => (Ant) cell)
                        .Any(enemy => enemiesCount[enemy] <= antEnemiesCount);
        }
Example #4
0
 public void AntCreation()
 {
     foreach (var army in Armies)
     {
         var emptyHills = army.Hills.Where(hill => ObjectsMap[hill.Coords].Type == Cell.CellType.Empty).ToList();
         while (emptyHills.Count != 0 && army.HiveSize != 0)
         {
             var idx = Rndom.Next(emptyHills.Count);
             var ant = new Ant(emptyHills[idx].Coords, army.Idx, this);
             ObjectsMap[emptyHills[idx].Coords] = ant;
             army.Ants.Add(ant);
             emptyHills.RemoveAt(idx);
             army.HiveSize--;
         }
     }
 }