Beispiel #1
0
 /// <summary>
 /// Erstellt eine neue AIAnt instance und setzt die zugewiesene Ameise und conf property.
 /// </summary>
 /// <param name="ant">Die Ameise</param>
 /// <param name="conf">Die Gameconfig</param>
 /// <returns>die AIANt instance</returns>
 public IAIAnt createAIAntInstance(Ant ant, Config conf)
 {
     try {
         AIAntBase obj = (AIAntBase) Activator.CreateInstance(antAI);
         obj.Ant = ant;
         obj.Conf = conf;
         return obj;
     } catch (System.Exception) {
         throw new InvalidDLLFileException();
     }
 }
Beispiel #2
0
        /// <summary>
        /// Berechnet die Kosten anhand der übergebenen Ameise.
        /// </summary>
        /// <param name="ant">Die Ameise</param>
        public static double calculateCost(Ant ant)
        {
            if (ant.ViewRange < VIEWRANGE_MIN || ant.ViewRange > VIEWRANGE_MAX) {
                throw new ArgumentException(String.Format(Messages.ERROR_INVALID_VALUE, ant.ViewRange, Messages.VIEWRANGE, VIEWRANGE_MIN, VIEWRANGE_MAX));
            }

            if (ant.isCarry()) {
                return calculateCostCarry(ant.ViewRange, ant.MoveRangeFactor, ant.MaxInventory, ant.Health, ant.Owner.AI.Playername);
            } else if (ant.isScout()) {
                return calculateCostScout(ant.ViewRange, ant.MoveRangeFactor, ant.MaxInventory, ant.Health, ant.Owner.AI.Playername);
            } else if (ant.isWarrior()) {
                return calculateCostWarrior((ant as Warrior).AttackPower, ant.ViewRange, ant.MoveRangeFactor, ant.MaxInventory, ant.Health, ant.Owner.AI.Playername);
            }
            throw new RuntimeException("Unknown ant type.");
        }
Beispiel #3
0
 private bool resolveAntCoords(Ant ant, Base b)
 {
     if (!Game.Board.BoardObjects.hasAntOnCoords(b.Coords)) {
         ant.Coords = b.Coords;
         return true;
     } else {
         List<Coordinates> adjCoords = b.Coords.getAdjacentCoordinates(3);
         foreach (Coordinates coords in adjCoords) {
             if (!Game.Board.BoardObjects.isValidCoords(coords)) {
                 continue;
             }
             if (!Game.Board.BoardObjects.hasAntOnCoords(coords)) {
                 ant.Coords = coords;
                 return true;
             }
         }
         return false;
     }
 }
Beispiel #4
0
 private bool buyAnt(Ant ant)
 {
     double cost = Helper.CostCalculator.calculateCost(ant);
     Base b = getBase();
     if (!resolveAntCoords(ant, b) || !Player.pay(cost)) {
         return false;
     }
     ant.AI = Player.AILoader.createAIAntInstance(ant, Game.Conf);
     return Game.Board.BoardObjects.add(ant);
 }
Beispiel #5
0
 /// <summary>
 /// Erhöht die Anzahl der Ameisen eines Ameisentyps um eins.
 /// </summary>
 /// <param name="ant">Die neue Ameise.</param>
 public void incrementAnts(Ant ant)
 {
     AntCount++;
     if (ant.isCarry()) {
         CarryCount++;
     } else if (ant.isScout()) {
         ScoutCount++;
     } else if (ant.isWarrior()) {
         WarriorCount++;
     } else {
         throw new RuntimeException("Unknown ant type.");
     }
 }
Beispiel #6
0
 /// <summary>
 /// Verringert die Anzahl der Ameisen eines Ameisentyps um eins.
 /// </summary>
 /// <param name="ant">Die zu verringernde Ameise.</param>
 public void decreaseAnts(Ant ant)
 {
     DeathCount++;
     AntCount--;
     if (ant.isCarry()) {
         CarryCount--;
     } else if (ant.isScout()) {
         ScoutCount--;
     } else if (ant.isWarrior()) {
         WarriorCount--;
     } else {
         throw new RuntimeException("Unknown ant type.");
     }
 }
Beispiel #7
0
 public bool isEnemy(Ant ant)
 {
     return ant.Owner != Owner;
 }
Beispiel #8
0
        /// <summary>
        /// Benachrichtigt andere Ameisen.
        /// </summary>
        /// <param name="coords">Die Koordinaten welche den anderen Ameisen mitgeteilt werden soll</param>
        /// <param name="ant">Die Ameise welche mitteilt</param>
        public void notifyAnts(HashSet<Coordinates> coords, Ant ant)
        {
            BoardObject[] objs = getBoardObjectsInView(ant.Coords, ant.ViewRange * 2);
            for (int i = 0;i < objs.Length;i++) {
                BoardObject obj = objs[i];
                if (obj == ant) {
                    continue;
                }

                if (obj.isAnt()) {
                    Ant antToNotify = obj as Ant;
                    antToNotify.AI.notify(coords);
                }
            }
        }
Beispiel #9
0
 private BoardObject[] getBoardObjectsInView(Ant ant)
 {
     return getBoardObjectsInView(ant.Coords, ant.ViewRange);
 }
Beispiel #10
0
 public bool isEnemy(Ant ant)
 {
     return(ant.Owner != Owner);
 }