コード例 #1
0
        /// <summary>
        /// Erntfernt Ameisen die keine Energie mehr haben.
        /// </summary>
        /// <param name="colony">betroffenes Volk</param>
        private void removeAnt(CoreColony colony)
        {
            List <CoreAnt> liste = new List <CoreAnt>();

            for (int i = 0; i < colony.VerhungerteInsekten.Count; i++)
            {
                CoreAnt ant = colony.VerhungerteInsekten[i] as CoreAnt;
                if (ant != null && !liste.Contains(ant))
                {
                    liste.Add(ant);
                    colony.Statistik.StarvedAnts++;
                    PlayerCall.HasDied(ant, CoreKindOfDeath.Starved);
                }
            }

            for (int i = 0; i < colony.EatenInsects.Count; i++)
            {
                CoreAnt ant = colony.EatenInsects[i] as CoreAnt;
                if (ant != null && !liste.Contains(ant))
                {
                    liste.Add(ant);
                    colony.Statistik.EatenAnts++;
                    PlayerCall.HasDied(ant, CoreKindOfDeath.Eaten);
                }
            }

            for (int i = 0; i < colony.BeatenInsects.Count; i++)
            {
                CoreAnt ant = colony.BeatenInsects[i] as CoreAnt;
                if (ant != null)
                {
                    if (!liste.Contains(ant))
                    {
                        liste.Add(ant);
                        colony.Statistik.BeatenAnts++;
                        PlayerCall.HasDied(ant, CoreKindOfDeath.Beaten);
                    }
                }
            }

            for (int i = 0; i < liste.Count; i++)
            {
                CoreAnt ant = liste[i];
                if (ant != null)
                {
                    colony.EntferneInsekt(ant);

                    for (int j = 0; j < Playground.Fruits.Count; j++)
                    {
                        CoreFruit fruit = Playground.Fruits[j];
                        fruit.TragendeInsekten.Remove(ant);
                    }
                }
            }

            colony.VerhungerteInsekten.Clear();
            colony.EatenInsects.Clear();
            colony.BeatenInsects.Clear();
        }
コード例 #2
0
        /// <summary>
        /// Prüft ob die Ameise eine Markierung bemerkt.
        /// </summary>
        /// <param name="ameise">betroffene Ameise</param>
        private static void ameiseUndMarkierungen(CoreAnt ameise)
        {
            CoreMarker marker = ameise.colony.Marker.FindMarker(ameise);

            if (marker != null)
            {
                PlayerCall.SmellsFriend(ameise, marker);
                ameise.SmelledMarker.Add(marker);
            }
        }
コード例 #3
0
 /// <summary>
 /// Prüft ob eine Ameise ein Obsstück sieht.
 /// </summary>
 /// <param name="ameise">betroffene Ameise</param>
 private void ameiseUndObst(CoreAnt ameise)
 {
     for (int i = 0; i < Playground.Fruits.Count; i++)
     {
         CoreFruit obst       = Playground.Fruits[i];
         int       entfernung = CoreCoordinate.BestimmeEntfernungI(ameise.CoordinateBase, obst.CoordinateBase);
         if (ameise.ZielBase != obst && entfernung <= ameise.SichtweiteI)
         {
             PlayerCall.Spots(ameise, obst);
         }
     }
 }
コード例 #4
0
 /// <summary>
 /// Prüft ob eine Ameise einen Zuckerhaufen sieht.
 /// </summary>
 /// <param name="ant">betroffene Ameise</param>
 private void ameiseUndZucker(CoreAnt ant)
 {
     for (int i = 0; i < Playground.SugarHills.Count; i++)
     {
         CoreSugar sugar      = Playground.SugarHills[i];
         int       entfernung = CoreCoordinate.BestimmeEntfernungI(ant.CoordinateBase, sugar.CoordinateBase);
         if (ant.ZielBase != sugar && entfernung <= ant.SichtweiteI)
         {
             PlayerCall.Spots(ant, sugar);
         }
     }
 }
コード例 #5
0
        /// <summary>
        /// Prüft ob eine Ameise an ihrem Ziel angekommen ist.
        /// </summary>
        /// <param name="ant">betroffene Ameise</param>
        private static void ameiseUndZiel(CoreAnt ant)
        {
            // Ameisenbau.
            if (ant.ZielBase is CoreAnthill)
            {
                if (ant.GetragenesObstBase == null)
                {
                    ant.ZurückgelegteStreckeI = 0;
                    ant.ZielBase = null;
                    ant.SmelledMarker.Clear();
                    ant.colony.Statistik.CollectedFood += ant.AktuelleLastBase;
                    ant.AktuelleLastBase    = 0;
                    ant.AktuelleEnergieBase = ant.MaximaleEnergieBase;
                    ant.IstMüdeBase         = false;
                }
            }

            // Zuckerhaufen.
            else if (ant.ZielBase is CoreSugar)
            {
                CoreSugar zucker = (CoreSugar)ant.ZielBase;
                ant.ZielBase = null;
                if (zucker.Menge > 0)
                {
                    PlayerCall.TargetReached(ant, zucker);
                }
            }

            // Obststück.
            else if (ant.ZielBase is CoreFruit)
            {
                CoreFruit obst = (CoreFruit)ant.ZielBase;
                ant.ZielBase = null;
                if (obst.Menge > 0)
                {
                    PlayerCall.TargetReached(ant, obst);
                }
            }

            // Insekt.
            else if (ant.ZielBase is CoreInsect)
            {
            }

            // Anderes Ziel.
            else
            {
                ant.ZielBase = null;
            }
        }
コード例 #6
0
        /// <summary>
        /// Berechnet einen neuen Spielschritt
        /// </summary>
        /// <returns>Zustandskopie des Simulationsstandes nachdem der Schritt ausgeführt wurde</returns>
        /// <throws>RuleViolationException</throws>
        /// <throws>Exception</throws>
        public void Step(SimulationState simulationState)
        {
            currentRound++;

            #region Food

            removeSugar();
            spawnSugar();
            spawnFruit();

            #endregion

            #region Bugs

            Bugs.Grids[0].Clear();
            for (int i = 0; i < Teams.Length; i++)
            {
                for (int j = 0; j < Teams[i].Colonies.Length; j++)
                {
                    Bugs.Grids[0].Add(Teams[i].Colonies[j].Insects);
                }
            }

            // Lasse die Wanzen von der Spiel Befehle entgegen nehmen.
            //foreach (CoreBug wanze in Bugs.Insects) {
            //    wanze.NimmBefehleEntgegen = true;
            //}

            // Schleife über alle Wanzen.
            for (int bugIndex = 0; bugIndex < Bugs.Insects.Count; bugIndex++)
            {
                CoreBug bug = Bugs.Insects[bugIndex] as CoreBug;
                Debug.Assert(bug != null);

                bug.NimmBefehleEntgegen = true;

                // Finde Ameisen in Angriffsreichweite.
                List <CoreInsect> ants = Bugs.Grids[0].FindAnts(bug);

                // Bestimme wie der Schaden auf die Ameisen verteilt wird.
                if (ants.Count >= SimulationSettings.Custom.BugAttack)
                {
                    // Es sind mehr Ameisen in der SpielUmgebung als die Wanze
                    // Schadenpunke verteilen kann. Daher werden den Ameisen am
                    // Anfang der Liste jeweils ein Energiepunkt abgezogen.
                    for (int index = 0; index < SimulationSettings.Custom.BugAttack; index++)
                    {
                        ants[index].AktuelleEnergieBase--;
                        //((Ameise)ameisen[i]).WirdAngegriffen(wanze);
                        PlayerCall.UnderAttack((CoreAnt)ants[index], bug);
                        if (ants[index].AktuelleEnergieBase <= 0)
                        {
                            ants[index].colony.EatenInsects.Add(ants[index]);
                        }
                    }
                }
                else if (ants.Count > 0)
                {
                    // Bestimme die Energie die von jeder Ameise abgezogen wird.
                    // Hier können natürlich Rundungsfehler auftreten, die die Wanze
                    // abschwächen, die ignorieren wir aber.
                    int schaden = SimulationSettings.Custom.BugAttack / ants.Count;
                    for (int index = 0; index < ants.Count; index++)
                    {
                        ants[index].AktuelleEnergieBase -= schaden;
                        //((Ameise)ameisen[i]).WirdAngegriffen(wanze);
                        PlayerCall.UnderAttack((CoreAnt)ants[index], bug);
                        if (ants[index].AktuelleEnergieBase <= 0)
                        {
                            ants[index].colony.EatenInsects.Add(ants[index]);
                        }
                    }
                }

                // Während eines Kampfes kann die Wanze sich nicht bewegen.
                if (ants.Count > 0)
                {
                    continue;
                }

                // Bewege die Wanze.
                bug.Bewegen();
                if (bug.RestStreckeBase == 0)
                {
                    bug.DreheInRichtungBase(random.Next(360));
                    bug.GeheGeradeausBase(random.Next(160, 320));
                }
                bug.NimmBefehleEntgegen = false;
            }

            // Verhindere, daß ein Spieler einer gesichteten Wanze Befehle gibt.
            //for(int i = 0; i < Bugs.Insects.Count; i++) {
            //  CoreBug wanze = Bugs.Insects[i] as CoreBug;
            //  if(wanze != null) {
            //    wanze.NimmBefehleEntgegen = false;
            //  }
            //}

            #endregion

            #region Ants

            // Loop through all teams.
            for (int teamIndex = 0; teamIndex < Teams.Length; teamIndex++)
            {
                // Loop through all colonies in that team.
                for (int colonyIndex = 0; colonyIndex < Teams[teamIndex].Colonies.Length; colonyIndex++)
                {
                    CoreColony colony = Teams[teamIndex].Colonies[colonyIndex];

                    // Leere alle Buckets.
                    for (int casteIndex = 0; casteIndex < colony.AnzahlKasten; casteIndex++)
                    {
                        colony.Grids[casteIndex].Clear();
                    }

                    // Fülle alle Buckets, aber befülle keinen Bucket doppelt.
                    for (int casteIndex = 0; casteIndex < colony.AnzahlKasten; casteIndex++)
                    {
                        if (colony.Grids[casteIndex].Count == 0)
                        {
                            colony.Grids[casteIndex].Add(Bugs.Insects);
                            for (int j = 0; j < Teams.Length; j++)
                            {
                                for (int i = 0; i < Teams[j].Colonies.Length; i++)
                                {
                                    CoreColony v = Teams[j].Colonies[i];
                                    colony.Grids[casteIndex].Add(v.Insects);
                                }
                            }
                        }
                    }

                    // Schleife über alle Ameisen.
                    for (int antIndex = 0; antIndex < colony.Insects.Count; antIndex++)
                    {
                        CoreAnt ameise = colony.Insects[antIndex] as CoreAnt;
                        Debug.Assert(ameise != null);

                        // Finde und Zähle die Insekten im Sichtkreis der Ameise.
                        CoreBug wanze;
                        CoreAnt feind;
                        CoreAnt freund;
                        CoreAnt teammember;
                        int     bugCount, enemyAntCount, colonyAntCount, casteAntCount, teamAntCount;
                        colony.Grids[ameise.CasteIndexBase].FindAndCountInsects(
                            ameise,
                            out wanze,
                            out bugCount,
                            out feind,
                            out enemyAntCount,
                            out freund,
                            out colonyAntCount,
                            out casteAntCount,
                            out teammember,
                            out teamAntCount);
                        ameise.BugsInViewrange         = bugCount;
                        ameise.ForeignAntsInViewrange  = enemyAntCount;
                        ameise.FriendlyAntsInViewrange = colonyAntCount;
                        ameise.FriendlyAntsFromSameCasteInViewrange = casteAntCount;
                        ameise.TeamAntsInViewrange = teamAntCount;

                        // Bewege die Ameise.
                        ameise.Bewegen();

                        #region Reichweite

                        // Ameise hat ihre Reichweite überschritten.
                        if (ameise.ZurückgelegteStreckeI > colony.ReichweiteI[ameise.CasteIndexBase])
                        {
                            ameise.AktuelleEnergieBase = 0;
                            colony.VerhungerteInsekten.Add(ameise);
                            continue;
                        }

                        // Ameise hat ein Drittel ihrer Reichweite zurückgelegt.
                        else if (ameise.ZurückgelegteStreckeI > colony.ReichweiteI[ameise.CasteIndexBase] / 3)
                        {
                            if (ameise.IstMüdeBase == false)
                            {
                                ameise.IstMüdeBase = true;
                                PlayerCall.BecomesTired(ameise);
                            }
                        }

                        #endregion

                        #region Kampf

                        // Rufe die Ereignisse auf, falls die Ameise nicht schon ein
                        // entsprechendes Ziel hat.
                        if (wanze != null && !(ameise.ZielBase is CoreBug))
                        {
                            PlayerCall.SpotsEnemy(ameise, wanze);
                        }
                        if (feind != null && !(ameise.ZielBase is CoreAnt) ||
                            (ameise.ZielBase is CoreAnt && ((CoreAnt)ameise.ZielBase).colony == colony))
                        {
                            PlayerCall.SpotsEnemy(ameise, feind);
                        }
                        if (freund != null && !(ameise.ZielBase is CoreAnt) ||
                            (ameise.ZielBase is CoreAnt && ((CoreAnt)ameise.ZielBase).colony != colony))
                        {
                            PlayerCall.SpotsFriend(ameise, freund);
                        }
                        if (teammember != null && !(ameise.ZielBase is CoreAnt) ||
                            (ameise.ZielBase is CoreAnt && ((CoreAnt)ameise.ZielBase).colony != colony))
                        {
                            PlayerCall.SpotsTeamMember(ameise, teammember);
                        }

                        // Kampf mit Wanze.
                        if (ameise.ZielBase is CoreBug)
                        {
                            CoreBug k = (CoreBug)ameise.ZielBase;
                            if (k.AktuelleEnergieBase > 0)
                            {
                                int entfernung =
                                    CoreCoordinate.BestimmeEntfernungI(ameise.CoordinateBase, ameise.ZielBase.CoordinateBase);
                                if (entfernung < SimulationSettings.Custom.BattleRange * PLAYGROUND_UNIT)
                                {
                                    k.AktuelleEnergieBase -= ameise.AngriffBase;
                                    if (k.AktuelleEnergieBase <= 0)
                                    {
                                        Bugs.EatenInsects.Add(k);
                                        colony.Statistik.KilledBugs++;
                                        ameise.BleibStehenBase();
                                    }
                                }
                            }
                            else
                            {
                                ameise.ZielBase = null;
                            }
                        }

                        // Kampf mit feindlicher Ameise.
                        else if (ameise.ZielBase is CoreAnt)
                        {
                            CoreAnt a = (CoreAnt)ameise.ZielBase;
                            if (a.colony != colony && a.AktuelleEnergieBase > 0)
                            {
                                int entfernung =
                                    CoreCoordinate.BestimmeEntfernungI(ameise.CoordinateBase, ameise.ZielBase.CoordinateBase);
                                if (entfernung < SimulationSettings.Custom.BattleRange * PLAYGROUND_UNIT)
                                {
                                    PlayerCall.UnderAttack(a, ameise);
                                    a.AktuelleEnergieBase -= ameise.AngriffBase;
                                    if (a.AktuelleEnergieBase <= 0)
                                    {
                                        a.colony.BeatenInsects.Add(a);
                                        colony.Statistik.KilledAnts++;
                                        ameise.BleibStehenBase();
                                    }
                                }
                            }
                            else
                            {
                                ameise.ZielBase = null;
                            }
                        }

                        #endregion

                        // Prüfe ob die Ameise an ihrem Ziel angekommen ist.
                        if (ameise.AngekommenBase)
                        {
                            ameiseUndZiel(ameise);
                        }

                        // Prüfe ob die Ameise einen Zuckerhaufen oder ein Obststück sieht.
                        ameiseUndZucker(ameise);
                        if (ameise.GetragenesObstBase == null)
                        {
                            ameiseUndObst(ameise);
                        }

                        // Prüfe ob die Ameise eine Markierung bemerkt.
                        ameiseUndMarkierungen(ameise);

                        if (ameise.ZielBase == null && ameise.RestStreckeBase == 0)
                        {
                            PlayerCall.Waits(ameise);
                        }

                        PlayerCall.Tick(ameise);
                    }

                    removeAnt(colony);
                    spawnAnt(colony);

                    aktualisiereMarkierungen(colony);
                    removeFruit(colony);
                }
            }

            #endregion

            #region Bugs again

            removeBugs();
            healBugs();
            spawnBug();

            #endregion

            bewegeObstUndInsekten();

            erzeugeZustand(simulationState);
        }