Exemple #1
0
        public void DeletePheromones(int id)
        {
            PheromoneStack pheromoneStack = pheromoneStacks[id];

            foreach (PheromoneStackItem pheromoneStackItem in pheromoneStack.PheromoneItems)
            {
                Pheromone pheromone = pheromoneStackItem.Pheromone;
                pheromone.PheromoneItems.Remove(pheromoneStackItem.PheromoneItem);
                if (pheromone.PheromoneItems.Count == 0)
                {
                    Items.Remove(pheromone.Pos);
                }
            }
            pheromoneStacks.Remove(id);
        }
Exemple #2
0
        public PheromoneItem Deposit(Player player, Position pos, PheromoneType pheromoneType, float intensity, bool isStatic)
        {
            Pheromone pheromone;

            if (!Items.ContainsKey(pos))
            {
                pheromone     = new Pheromone();
                pheromone.Pos = pos;
                player.Game.Pheromones.Add(pheromone);
            }
            else
            {
                pheromone = Items[pos];
            }
            return(pheromone.Deposit(player.PlayerModel.Id, intensity, pheromoneType, isStatic));
        }
Exemple #3
0
        public int DropPheromones(Player player, Position pos, int range, PheromoneType pheromoneType, float intensity, bool isStatic)
        {
            PheromoneStack pheromoneStack = new PheromoneStack();

            PheromoneStack.pheromoneStackCounter++;
            int counter = PheromoneStack.pheromoneStackCounter;

            pheromoneStacks.Add(counter, pheromoneStack);

            Dictionary <Position, TileWithDistance> tiles = player.Game.Map.EnumerateTiles(pos, range, false);

            foreach (TileWithDistance tileWithDistance in tiles.Values)
            {
                float totaldistance = range - tileWithDistance.Distance;
                float distance      = (totaldistance * 100) / range / 100;

                float relativIntensity = distance * intensity;

                PheromoneStackItem pheromoneStackItem = new PheromoneStackItem();

                Pheromone pheromone;
                pheromone = FindAt(tileWithDistance.Pos);
                if (pheromone == null)
                {
                    pheromone     = new Pheromone();
                    pheromone.Pos = tileWithDistance.Pos;
                    player.Game.Pheromones.Add(pheromone);
                }

                pheromoneStackItem.Pheromone     = pheromone;
                pheromoneStackItem.Distance      = distance;
                pheromoneStackItem.PheromoneItem = pheromone.Deposit(player.PlayerModel.Id, relativIntensity, pheromoneType, isStatic);

                pheromoneStack.PheromoneItems.Add(pheromoneStackItem);
            }

            return(counter);
        }
Exemple #4
0
        private bool SmellFood(Player player)
        {
            if (SmellFoodCooldown > 0)
            {
                SmellFoodCooldown--;
                return(false);
            }



            List <AntDestination> possibleTiles = new List <AntDestination>();

            Dictionary <Position, TileWithDistance> tiles = player.Game.Map.EnumerateTiles(PlayerUnit.Unit.Pos, 3, false, matcher: tile =>
            {
                Pheromone pheroHere = player.Game.Pheromones.FindAt(tile.Pos);
                if (tile.Metal > 0)
                {
                    AddDestination(possibleTiles, player, tile.Tile, 0.6f, false, PheromoneType.None);
                    return(true);
                }
                else if (pheroHere != null)
                {
                    AddDestination(possibleTiles, player, tile.Tile, 0.2f, false, PheromoneType.ToFood);
                    return(true);
                }
                return(false);
            });

            AntDestination bestMetal     = null;
            AntDestination bestPheromone = null;

            foreach (AntDestination antDestination in possibleTiles)
            {
                if (antDestination.Tile.Metal > 0 && (bestMetal == null || bestMetal.Tile.Metal > antDestination.Tile.Metal))
                {
                    bestMetal = antDestination;
                }
                if (antDestination.Pheromone != null &&
                    (bestPheromone == null ||
                     antDestination.Pheromone.GetIntensityF(player.PlayerModel.Id, PheromoneType.ToFood) > bestPheromone.Pheromone.GetIntensityF(player.PlayerModel.Id, PheromoneType.ToFood)))
                {
                    bestPheromone = antDestination;
                }
            }
            // Turn ant to food
            if (bestMetal != null)
            {
                Direction d = TurnToPos(bestMetal.Tile.Pos);
                if (d != Direction.C && d != PlayerUnit.Unit.Direction)
                {
                    SmellFoodCooldown         = 1;
                    PlayerUnit.Unit.Direction = d;
                    return(true);
                }
            }
            else if (bestPheromone != null)
            {
                Direction d = TurnToPos(bestPheromone.Tile.Pos);
                if (d != Direction.C && d != PlayerUnit.Unit.Direction)
                {
                    SmellFoodCooldown         = 1;
                    PlayerUnit.Unit.Direction = d;
                    return(true);
                }
            }

            /* Move there leads to locks
             * foreach (AntDestination antDestination in possibleTiles)
             * {
             *  Unit cntrlUnit = PlayerUnit.Unit;
             *
             *  Move move = player.Game.MoveTo(cntrlUnit.Pos, antDestination.Tile.Pos, cntrlUnit.Engine);
             *  if (move != null)
             *  {
             *      if (!Control.IsOccupied(player, moves, move.Positions[1]))
             *      {
             *          moves.Add(move);
             *          DropPheromone(player, PheromoneType.ToHome);
             *          return true;
             *      }
             *  }
             * }
             */
            SmellFoodCooldown = 0;
            return(false);
        }
Exemple #5
0
 public void Add(Pheromone pheromone)
 {
     Items.Add(pheromone.Pos, pheromone);
 }