Example #1
0
        /// <summary>
        /// If the ant has no assigned tasks, it waits for new tasks. This method 
        /// is called to inform you that it is waiting.
        /// Read more: "http://wiki.antme.net/en/API1:Waiting"
        /// </summary>
        public override void Waiting()
        {
            if (CurrentLoad > 5)
            {
                if (DistanceToAnthill > 20)
                {
                    TurnToDetination(hill);
                    GoForward(DistanceToAnthill - 10);
                }
                else
                    GoToAnthill();
                return;
            }
            if (timera == null) timera = this;
            if (hill == null)
            {
                GoToAnthill();
                hill = Destination as Anthill;
                Stop();
            }
            if (Caste == "north")
            {
                if (Direction != 270)
                    TurnToDirection(270);
                if (!absolute[0])
                    GoForward();
                else
                    GoForward(50);
                return;
            }
            if (Caste == "east")
            {
                if (Direction != 0)
                    TurnToDirection(0);
                if (!absolute[1])
                    GoForward();
                else
                    GoForward(50);
                if (!absolute[2])
                    GoForward();
                else
                    GoForward(50);
                return;
            }
            if (Caste == "south")
            {
                if (Direction != 90)
                    TurnToDirection(90);
                if (!absolute[2])
                    GoForward();
                else
                    GoForward(50);
                return;
            }
            if (Caste == "west")
            {
                if (Direction != 180)
                    TurnToDirection(180);
                if (!absolute[3])
                    GoForward();
                else
                    GoForward(50);
                return;
            }
            if (Caste == "fighter2" && !IsTired && spotted)
            {
                double distance, direction, x, y;
                getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out x, out y);
                getdistance(x, y, basex, basey, out distance);
                if (distance > 50)
                {
                    getdirection(x, y, basex, basey, out direction);
                    TurnToDirection(Convert.ToInt32(direction));
                    GoForward(Convert.ToInt32(distance));
                    Think("Infiltrieren");
                    return;
                }
                else
                {
                }
            }
            if (IsTired && (Caste != "sugar" || (CurrentLoad > MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
            {
                if (DistanceToAnthill > 10)
                {
                    if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
                    GoForward(DistanceToAnthill - 5);
                }
                else
                    GoToDestination(hill);
                return;
            }
            if (Caste == "searcher")
            {
                int distance = 0;
                double x, y, lx, ly, direction, distanz, angle;
                distance = (searcher.IndexOf(this)) * Viewrange + Viewrange;
                getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out x, out y);

                if (distance == 0)
                {
                    Think("ERROR");
                    GoToDestination(hill);
                    return;
                }
                if (DistanceToAnthill < distance - 20)
                {
                    bool alle = true;
                    Think("falsch");
                    if (DistanceToAnthill > 5)
                    {
                        Think("korrigiere" + Convert.ToInt32(distance) + " " + DistanceToAnthill);
                        if (x > 0)
                        {
                            if (y > 0)
                            {
                                angle = 135;
                            }
                            else
                            {
                                angle = 225;
                            }
                        }
                        else
                        {
                            if (y > 0)
                            {
                                angle = 45;
                            }
                            else
                            {
                                angle = 315;
                            }
                        }
                        getcordsa(distance, angle, out lx, out ly);
                        getdirection(x, y, lx, ly, out direction);
                        getdistance(x, y, lx, ly, out distanz);
                        TurnToDirection(Convert.ToInt32(direction));
                        GoForward(Convert.ToInt32(distanz) - 10);
                        return;
                    }
                    else
                    {
                        int rd = 0;
                        Think("richte aus");
                        for (int i = 0; i < 4; i++)
                        {
                            if (!absolute[i])
                            {
                                if (Direction != 45)
                                    TurnToDirection(45);
                                alle = false;
                                rd = 1;
                            }
                        }
                        if (alle)
                        {
                            double distanceh;
                            getdistance(x, y, basex, basey, out distanceh);
                            if (entfernung[0] > entfernung[2])
                            {
                                if (entfernung[1] > entfernung[3])
                                {
                                    if (Direction != 315)
                                        TurnToDirection(315);
                                    rd = 0;
                                }
                                else
                                {
                                    if (Direction != 225)
                                        TurnToDirection(225);
                                    rd = 3;
                                }
                            }
                            else
                            {
                                if (entfernung[1] > entfernung[3])
                                {
                                    if (Direction != 45)
                                        TurnToDirection(45);
                                    rd = 1;
                                }
                                else
                                {
                                    if (Direction != 135)
                                        TurnToDirection(135);
                                    rd = 2;
                                }
                            }
                        }

                        if (alle || time > 13000)
                            GoForward(distance);
                    }
                    return;
                }
                else
                {
                    Think("aufgestellt" + distance);
                    bool r = false;
                    if (searcher.IndexOf(this) % 2 == 0)
                        r = true;
                    if (Coordinate.GetDegreesBetween(this, hill) >= 210 && Coordinate.GetDegreesBetween(this, hill) <= 240)
                    {
                        if (r)
                        {
                            if (Direction != 270)
                                TurnToDirection(270);
                        }
                        else if (Direction != 180)
                            TurnToDirection(180);
                        GoForward(Convert.ToInt32(DistanceToAnthill * 1.15 / 0.70710678118));
                        return;
                    }
                    else if (Coordinate.GetDegreesBetween(this, hill) >= 120 && Coordinate.GetDegreesBetween(this, hill) <= 150)
                    {
                        if (r)
                        {
                            if (Direction != 180)
                                TurnToDirection(180);
                        }
                        else if (Direction != 90)
                            TurnToDirection(90);
                        GoForward(Convert.ToInt32(DistanceToAnthill * 1.15 / 0.70710678118));
                        return;
                    }
                    else if (Coordinate.GetDegreesBetween(this, hill) >= 30 && Coordinate.GetDegreesBetween(this, hill) <= 60)
                    {
                        if (r)
                        {
                            if (Direction != 90)
                                TurnToDirection(90);
                        }
                        else if (Direction != 0)
                            TurnToDirection(0);
                        GoForward(Convert.ToInt32(DistanceToAnthill * 1.15 / 0.70710678118));
                        return;
                    }
                    else if (Coordinate.GetDegreesBetween(this, hill) >= 300 && Coordinate.GetDegreesBetween(this, hill) <= 330)
                    {
                        if (r)
                        {
                            if (Direction != 0)
                                TurnToDirection(0);
                        }
                        else if (Direction != 270)
                            TurnToDirection(270);
                        GoForward(Convert.ToInt32(DistanceToAnthill * 1.15 / 0.70710678118));
                        return;
                    }
                    else
                    {
                        Think("falsch");
                        if (DistanceToAnthill > 5)
                        {
                            Think("korrigiere" + Coordinate.GetDegreesBetween(this, hill));
                            getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out x, out y);
                            if (x > 0)
                            {
                                if (y > 0)
                                {
                                    angle = 135;
                                }
                                else
                                {
                                    angle = 225;
                                }
                            }
                            else
                            {
                                if (y > 0)
                                {
                                    angle = 45;
                                }
                                else
                                {
                                    angle = 315;
                                }
                            }
                            getcordsa(distance, angle, out lx, out ly);
                            getdirection(x, y, lx, ly, out direction);
                            getdistance(x, y, lx, ly, out distanz);
                            TurnToDirection(Convert.ToInt32(direction));
                            GoForward(Convert.ToInt32(distanz) - 10);
                            return;
                        }
                        else
                        {
                            bool alle = true;
                            Think("richte aus");
                            for (int i = 0; i < 4; i++)
                            {
                                if (!absolute[i])
                                {
                                    if (Direction != 45)
                                        TurnToDirection(45);
                                    alle = false;
                                }
                            }
                            if (alle)
                            {
                                if (entfernung[0] > entfernung[2])
                                {
                                    if (entfernung[1] > entfernung[3])
                                    {
                                        if (Direction != 315)
                                            TurnToDirection(315);
                                    }
                                    else
                                    {
                                        if (Direction != 225)
                                            TurnToDirection(225);
                                    }
                                }
                                else
                                {
                                    if (entfernung[1] > entfernung[3])
                                    {
                                        if (Direction != 45)
                                            TurnToDirection(45);
                                    }
                                    else
                                    {
                                        if (Direction != 135)
                                            TurnToDirection(135);
                                    }
                                }
                            }
                            GoForward(distance);
                            return;
                        }
                    }
                }
            }
            else if (Caste == "star")
            {
                int that = 0;
                for (int i = 1; i < 20; i++)
                {
                    if (stars[i] == Ameisenliste.IndexOf(this))
                    {
                        that = i;
                    }
                }
                if (DistanceToAnthill > 5 && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
                {
                    Think("back");
                    if (DistanceToAnthill > 10)
                    {
                        if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
                        GoForward(DistanceToAnthill - 5);
                    }
                    else
                        GoToDestination(hill);
                    return;
                }
                else
                {
                    if (Direction != (359 / 8) * that)
                        TurnToDirection((359 / 8) * that);
                    GoForward(Convert.ToInt32(Range / 2.1));
                    Think("Ich bin ein Star!");
                    return;
                }
            }
            if (hill == null)
            {
                GoToAnthill();
                hill = Destination as Anthill;
                Stop();
            }
            if (IsTired && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
            {
                if (DistanceToAnthill > 10)
                {
                    if (Direction != Coordinate.GetDegreesBetween(this, hill))
                        if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
                    GoForward(DistanceToAnthill - 5);
                }
                else
                    GoToDestination(hill);
                return;
            }
            else if (Caste != "sugar" || CurrentLoad < MaximumLoad / 10 && CarryingFruit == null)
            {
                if (Coordinate.GetDistanceBetween(this, hill) < 10) TurnToDirection(norandom); norandom += 5;
                GoForward(50);
            }
            if (wirdangegriffen[Ameisenliste.IndexOf(this)] != 0)
            {
                for (int i = 0; i < 300; i++)
                {
                    if (verfugbar[i, 0] == wirdangegriffen[Ameisenliste.IndexOf(this)])
                    {
                        Think(i + "Vergessen weil unbeschäftigt");
                        aimedbug[i] = null;
                        for (int u = 2; u < 300; u++)
                        {
                            verfugbar[i, u] = 0;
                        }
                        verfugbar[i, 1] = 0;
                        verfugbar[i, 0] = 0;
                        aimedposition[i, 0] = 0;
                        aimedposition[i, 1] = 0;
                    }
                }
                wirdangegriffen[Ameisenliste.IndexOf(this)] = 0;
            }

            if (Caste == "fighter" || Caste == "fighter3")
            {
                if (Coordinate.GetDistanceBetween(this, hill) < 20) TurnByDegrees(RandomNumber.Number(360));
                GoForward(40);

                for (int i = 0; i < 300; i++)
                {
                    for (int u = 2; u < 300; u++)
                    {
                        if (verfugbar[i, u] == Ameisenliste.IndexOf(this) && aimedbug[i] != null && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10 || Direction != Coordinate.GetDegreesBetween(this, hill))) && (Caste != "fighter2" || !spotted))
                        {
                            if (!IsTired && WalkedRange < Range / 3)
                                Attack(aimedbug[i]);
                            else
                                GoToDestination(hill);
                            return;
                        }
                    }
                }

                int ld = 1000000;
                int angriff = 0;

                for (int i = 0; i < 300; i++)
                {
                    if (aimedbug[i] != null)
                        if (Coordinate.GetDistanceBetween(aimedbug[i], hill) < ld && verfugbar[i, 1] < 15)
                        {
                            ld = Coordinate.GetDistanceBetween(aimedbug[i], hill);
                            angriff = i;
                        }
                }

                if (aimedbug[angriff] != null && verfugbar[angriff, 1] < 15 && !IsTired)
                    for (int i = 2; i < 300; i++)
                    {
                        if (verfugbar[angriff, i] == 0 && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
                        {
                            verfugbar[angriff, i] = Ameisenliste.IndexOf(this);
                            verfugbar[angriff, 1]++;
                            if (!IsTired && WalkedRange < Range / 3)
                                Attack(aimedbug[angriff]);
                            else
                                GoToDestination(hill);
                            Think("Angriff" + angriff);
                            return;
                        }
                    }
            }

            if (Caste == "sugar")
            {
                double x, y;
                double direction, distance;
                int nearest = 0;
                double lowestdistance = 3000000000000000;
                getcordsa(Coordinate.GetDistanceBetween(this, hill), Coordinate.GetDegreesBetween(this, hill), out x, out y);
                for (int i = 0; i < 4; i++)
                {
                    if (zucker[i] != null)
                    {
                        distance = Coordinate.GetDistanceBetween(this, zucker[i]);
                        if (distance < lowestdistance && distance < Range / 3)
                        {
                            lowestdistance = distance;
                            nearest = i;
                        }
                    }
                }
                if (lowestdistance < this.Range / 3 && zucker[nearest] != null)
                {
                    if (unterwegs[nearest, 1] * MaximumLoad < zucker[nearest].Amount * 1.8 && CurrentLoad < MaximumLoad / 10)
                    {
                        if (Coordinate.GetDistanceBetween(this, zucker[nearest]) > 2 && Range - WalkedRange - Coordinate.GetDistanceBetween(this, zucker[nearest]) > Range * 2 / 3 && !IsTired && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)))
                        {
                            if (Direction != Coordinate.GetDegreesBetween(this, zucker[nearest]))
                                TurnToDetination(zucker[nearest]);
                            GoForward(Convert.ToInt32(Coordinate.GetDistanceBetween(this, zucker[nearest]) / 1.1));
                            return;
                        }
                        else if (Range - WalkedRange - Coordinate.GetDistanceBetween(this, zucker[nearest]) > Range * 2 / 3 && !IsTired)
                            GoToDestination(zucker[nearest]);
                    }
                    else if (CurrentLoad < MaximumLoad / 10 && Range - WalkedRange - Coordinate.GetDistanceBetween(this, zucker[nearest]) > Range * 2 / 3 && !IsTired)
                    {
                        for (int i = 0; i < 4; i++)
                        {
                            if (zucker[i] != null)
                            {
                                int distanz = Convert.ToInt32(Coordinate.GetDistanceBetween(this, zucker[i]));
                                if (zucker[i] != null && Range - WalkedRange - distanz > Range * 2 / 3)
                                {
                                    TurnToDetination(zucker[i]);
                                    GoForward(distanz);
                                    return;
                                }
                            }
                        }
                        if (Direction != Coordinate.GetDegreesBetween(this, zucker[nearest]))
                            TurnToDetination(zucker[nearest]);
                        GoForward(Coordinate.GetDistanceBetween(this, (zucker[nearest])) / 2);
                    }
                    for (int i = 0; i < 4; i++)
                    {
                        if (zucker[nearest].Id == unterwegs[i, 0])
                        {
                            for (int u = 2; u < 100; u++)
                            {
                                if (unterwegs[i, u] == Ameisenliste.IndexOf(this)) break;
                                else if (unterwegs[i, u] == 0)
                                {
                                    unterwegs[i, u] = Ameisenliste.IndexOf(this);
                                    unterwegs[i, 1]++;
                                    break;
                                }
                            }
                        }
                    }
                }
                else
                {
                    if (Coordinate.GetDistanceBetween(this, hill) < 20)
                    {
                        TurnToDirection(RandomNumber.Number(180));
                        GoForward(50);
                    }
                }
            }
            else if (Caste == "default" && CarryingFruit == null)
            {
                for (int i = 0; i < 10; i++)
                {
                    for (int u = 2; u < 10; u++)
                    {
                        if (apfelliste[i, u] == Ameisenliste.IndexOf(this) && apple[i] != null && Range - WalkedRange - Coordinate.GetDistanceBetween(this, apple[i]) > Range * 2 / 3)
                        {
                            if (Coordinate.GetDistanceBetween(this, apple[i]) > 20)
                            {
                                if (Direction != Coordinate.GetDegreesBetween(this, apple[i]))
                                    TurnToDetination(apple[i]);
                                GoForward(Coordinate.GetDistanceBetween(this, apple[i]) - 10);
                            }
                            else
                                GoToDestination(apple[i]);
                            return;
                        }
                    }
                    if ((apfelliste[i, 0] != 0 || apfelliste[i, 1] != 0) && apfelliste[i, 1] < 5 && apple[i] != null && Range - WalkedRange - Coordinate.GetDistanceBetween(this, apple[i]) > Range * 2 / 3)
                    {
                        apfelliste[i, 1]++;
                        for (int u = 2; u < 10; u++)
                        {
                            if (apfelliste[i, u] == 0)
                            {
                                apfelliste[i, u] = Ameisenliste.IndexOf(this);
                                if (Coordinate.GetDistanceBetween(this, apple[i]) > 20)
                                {
                                    if (Direction != Coordinate.GetDegreesBetween(this, apple[i]))
                                        TurnToDetination(apple[i]);
                                    GoForward(Coordinate.GetDistanceBetween(this, apple[i]) - 10);
                                }
                                else
                                    GoToDestination(apple[i]);
                                break;
                            }
                        }
                    }
                }
            }
            else if (Caste == "stand" && (Caste != "fighter2" || !spotted))
            {
                if (DistanceToAnthill > 10)
                {
                    if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
                    GoForward(DistanceToAnthill - 5);
                }
                else
                    GoToDestination(hill);
                return;
            }
            else if ((Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)))
            {
                if (Coordinate.GetDistanceBetween(this, hill) < 10) TurnToDirection(norandom); norandom += 5;
                GoForward(50);
            }
            if (DistanceToAnthill > 10 && Caste != "fighter2" && false)
                GoToAnthill();
            else if (CurrentLoad < 5 && CarryingFruit == null)
            {
                if (Coordinate.GetDistanceBetween(this, hill) < 10)
                    TurnToDirection(norandom); norandom += 5;
                GoForward(50);
            }
        }
Example #2
0
 /// <summary>
 /// This method is called in every simulation round, regardless of additional 
 /// conditions. It is ideal for actions that must be executed but that are not 
 /// addressed by other methods.
 /// Read more: "http://wiki.antme.net/en/API1:Tick"
 /// </summary>
 public override void Tick()
 {
     if (norandom > 360) norandom -= 360;
     if (timera == null) timera = this;
     if (Caste == "fighter2" && spotted)
     {
         double distance, x, y;
         getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out x, out y);
         getdistance(x, y, basex, basey, out distance);
         if (distance > 50)
         {
         }
         else if (!(Destination is Ant) && Destination == null && CurrentSpeed > 2)
         {
             Stop();
         }
     }
     if (verfolgen != null)
         if (verfolgen.CurrentEnergy < verfolgen.MaximumEnergy / 2 || time - lastv > 20000)
             verfolgen = null;
     if (verfolgen != null && !spotted)
         Think("verfolge...");
     if (verfolgen != null)
         if ((verfolgen.CurrentLoad < verfolgen.MaximumLoad / 5 && verfolgen.CarriedFruit == null) && !spotted)
         {
             double xm, ym, xtm, ytm, x, y;
             getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out xm, out ym);
             getcordsa(Coordinate.GetDistanceBetween(verfolgen, this), Coordinate.GetDegreesBetween(verfolgen, this), out xtm, out ytm);
             x = xm + xtm;
             y = ym + ytm;
             basex = x;
             basey = y;
             if (Caste == "fighter2")
             {
                 TurnToDetination(verfolgen);
                 GoForward(Coordinate.GetDistanceBetween(this, verfolgen));
                 Think("Infiltriere");
             }
             Think("gefunden; X:" + Convert.ToInt32(x) + " Y: " + Convert.ToInt32(y));
             spotted = true;
             verfolgen = null;
         }
     if (Caste == "fighter2" && spotted) return;
     double xt, yt;
     getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out xt, out yt);
     if (Caste == "star")
         Think("star");
     if (hill == null)
     {
         GoToAnthill();
         hill = Destination as Anthill;
         Stop();
     }
     if (this == timera)
     {
         time += 50;
     }
     if (Caste == "star") return;
     if (Caste == "north")
     {
         if (DistanceToAnthill > entfernung[0])
         {
             entfernung[0] = DistanceToAnthill;
         }
         else if (DistanceToAnthill < entfernung[0] - 5)
             absolute[0] = true;
         Think(entfernung[0].ToString() + absolute[0]);
         if (DistanceToAnthill == 0 && Direction != 270)
         {
             if (Direction != 270)
                 TurnToDirection(270);
             if (!absolute[0])
                 GoForward();
             else
                 GoForward(50);
         }
         return;
     }
     if (Caste == "east")
     {
         if (DistanceToAnthill > entfernung[1])
         {
             entfernung[1] = DistanceToAnthill;
         }
         else if (DistanceToAnthill < entfernung[1] - 5)
             absolute[1] = true;
         Think(entfernung[1].ToString() + absolute[1]);
         if (DistanceToAnthill == 0 && Direction != 0)
         {
             if (Direction != 0)
                 TurnToDirection(0);
             if (!absolute[1])
                 GoForward();
             else
                 GoForward(50);
         }
         return;
     }
     if (Caste == "south")
     {
         if (DistanceToAnthill > entfernung[2])
         {
             entfernung[2] = DistanceToAnthill;
         }
         else if (DistanceToAnthill < entfernung[2] - 5)
             absolute[2] = true;
         Think(entfernung[2].ToString() + absolute[2]);
         if (DistanceToAnthill == 0 && Direction != 90)
         {
             if (Direction != 90)
                 TurnToDirection(90);
             if (!absolute[2])
                 GoForward();
             else
                 GoForward(50);
         }
         return;
     }
     if (Caste == "west")
     {
         if (DistanceToAnthill >= entfernung[3])
         {
             entfernung[3] = DistanceToAnthill;
         }
         else if (DistanceToAnthill < entfernung[3] - 5)
             absolute[3] = true;
         Think(entfernung[3].ToString() + absolute[3]);
         if (DistanceToAnthill == 0 && Direction != 180)
         {
             if (Direction != 180)
                 TurnToDirection(180);
             if (!absolute[3])
                 GoForward();
             else
                 GoForward(50);
         }
         return;
     }
     for (int i = 0; i < 100; i++)
     {
         if (hill == null)
         {
             GoToAnthill();
             hill = Destination as Anthill;
             Stop();
         }
         double x, y, direction, distance;
         getcordsa(DistanceToAnthill, Coordinate.GetDegreesBetween(this, hill), out x, out y);
     }
     if (hill == null)
     {
         GoToAnthill();
         hill = Destination as Anthill;
         Stop();
     }
     if (Destination is Bug)
     {
         for (int i = 0; i < aimedbug.Length; i++)
         {
             if (Destination == aimedbug[i])
             {
                 break;
             }
             else if (i == aimedbug.Length - 1 || aimedbug[i] == null && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
             {
                 GoToDestination(hill);
                 return;
             }
         }
     }
     else if (Caste == "fighter" && (Caste != "fighter2" || !spotted) && (IsTired || WalkedRange > Range / 3 || DistanceToAnthill > (Range - WalkedRange) / 1.5) && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
     {
         if (DistanceToAnthill > 10)
         {
             if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
             GoForward(DistanceToAnthill - 5);
         }
         else
             GoToDestination(hill);
         return;
     }
     if (Caste == "fighter" && (Caste != "fighter2" || !spotted) && (IsTired || WalkedRange > Range / 3 || DistanceToAnthill > (Range - WalkedRange) / 1.5) && (Destination == null || !(Destination is Bug)) && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted))
     {
         if (DistanceToAnthill > 10)
         {
             if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
             GoForward(DistanceToAnthill - 5);
         }
         else
             GoToDestination(hill);
         return;
     }
     if ((((Caste != "fighter" && (Caste != "fighter2" || !spotted)) || Destination == null && Caste != "fighter")) && IsTired && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)) && (Caste != "fighter2" || !spotted) && (Caste != "sugar" || (CurrentLoad < MaximumLoad / 10)))
     {
         if (DistanceToAnthill > 10)
         {
             if (Direction != Coordinate.GetDegreesBetween(this, hill)) TurnToDetination(hill);
             GoForward(DistanceToAnthill - 5);
         }
         else
         {
             GoToDestination(hill);
         }
         return;
     }
     if (hill != null)
     {
         for (int i = 0; i < 300; i++)
         {
             double distance, x, y;
             getcordsa(Coordinate.GetDistanceBetween(this, hill), Coordinate.GetDegreesBetween(this, hill), out x, out y);
             getdistance(x, y, aimedposition[i, 0], aimedposition[i, 1], out distance);
             if ((time - lastact[i] > 10000) && aimedbug[i] != null)
             {
                 Think(i + "vergessen " + Convert.ToInt32(distance));
                 aimedbug[i] = null;
                 for (int u = 2; u < 300; u++)
                 {
                     verfugbar[i, u] = 0;
                 }
                 verfugbar[i, 1] = 0;
                 verfugbar[i, 0] = 0;
                 aimedposition[i, 0] = 0;
                 aimedposition[i, 1] = 0;
                 wirdangegriffen[Ameisenliste.IndexOf(this)] = 0;
             }
         }
     }
     if (hill == null)
     {
         GoToAnthill();
         hill = Destination as Anthill;
         Stop();
     }
     if (CarryingFruit != null && DistanceToAnthill < 20)
     {
         Think("Aha");
         for (int i = 0; i < 10; i++)
         {
             if (apple[i] == CarryingFruit)
             {
                 Think("weg");
                 apple[i] = null;
                 for (int u = 0; u < 10; u++)
                 {
                     apfelliste[i, u] = 0;
                 }
             }
         }
     }
     for (int i = 0; i < 10; i++)
     {
         if (apple[i] != null)
             if (time - lastacta[i] > 1000 || apple[i].Amount == 0)
             {
                 Think("weg");
                 apple[i] = null;
                 for (int u = 0; u < 10; u++)
                 {
                     apfelliste[i, u] = 0;
                 }
             }
     }
     if (CarryingFruit != null)
     {
         for (int i = 0; i < 10; i++)
         {
             if (apple[i] == CarryingFruit)
             {
                 Think(apfelliste[i, 1].ToString());
                 lastacta[i] = time;
                 break;
             }
         }
     }
     if (Caste == "fighter" && Destination == null)
     {
     }
     for (int i = 0; i < 4; i++)
     {
         if (zucker[i] != null)
             if (zucker[i].Amount == 0)
             {
                 Think("gelöscht");
                 zucker[i] = null;
                 for (int u = 0; u < 100; u++)
                 {
                     unterwegs[i, u] = 0;
                 }
                 aimedsugar[i, 0] = 3000000;
                 aimedsugar[i, 1] = 3000000;
             }
     }
     if (CarryingFruit != null && Direction != Coordinate.GetDegreesBetween(this, hill))
     {
         TurnToDetination(hill);
         if (DistanceToAnthill > 20)
             GoForward(DistanceToAnthill - 10);
         else
             GoToAnthill();
     }
 }
Example #3
0
 /// <summary>
 /// Every time that a new ant is born, its job group must be set. You can 
 /// do so with the help of the value returned by this method.
 /// Read more: "http://wiki.antme.net/en/API1:ChooseCaste"
 /// </summary>
 /// <param name="typeCount">Number of ants for every caste</param>
 /// <returns>Caste-Name for the next ant</returns>
 public override string ChooseCaste(Dictionary<string, int> typeCount)
 {
     if (timera == null) timera = this;
     if (hill == null)
     {
         GoToAnthill();
         hill = Destination as Anthill;
         Stop();
     }
     Ameisenliste.Add(this);
     int r = RandomNumber.Number(0, 20);
     bool alle = true;
     for (int i = 0; i < 4; i++)
     {
         if (!absolute[i])
         {
             alle = false;
         }
     }
     for (int i = 0; i < 4; i++)
     {
         if (spawned[i] < 1)
         {
             spawned[i]++;
             if (i == 0)
                 return "south";
             else if (i == 1)
                 return "west";
             else if (i == 2)
                 return "north";
             else if (i == 3)
                 return "east";
         }
     }
     if (searcher.Count < 8)
     {
         searcher.Add(this);
         listda = true;
         return "searcher";
     }
     if (stars[0] < 0)
     {
         stars[0]++;
         for (int i = 1; i < 20; i++)
         {
             if (stars[i] == 0)
             {
                 stars[i] = Ameisenliste.IndexOf(this);
                 break;
             }
         }
         return "star";
     }
     if (r < 0)
         return "stand";
     else if (r < 8)
         return "default";
     else if (r < 19)
         return "sugar";
     else if (r < 20)
         return "fighter2";
     else if (r < 20)
         return "fighter";
     else
         return "fighter3";
 }