/// <summary> /// Der abstrakte Insekt-Basiskonstruktor. /// </summary> /// <param name="colony">Das Volk zu dem das neue Insekt gehört.</param> /// <param name="vorhandeneInsekten">Hier unbenutzt!</param> internal virtual void Init(CoreColony colony, Dictionary <string, int> vorhandeneInsekten) { id = neueId; neueId++; this.colony = colony; koordinate.Richtung = RandomNumber.Number(0, 359); // Zufällig auf dem Spielfeldrand platzieren. if (colony.AntHills.Count == 0) // Am oberen oder unteren Rand platzieren. { if (RandomNumber.Number(2) == 0) { koordinate.X = RandomNumber.Number(0, colony.Playground.Width); koordinate.X *= SimulationEnvironment.PLAYGROUND_UNIT; if (RandomNumber.Number(2) == 0) { koordinate.Y = 0; } else { koordinate.Y = colony.Playground.Height * SimulationEnvironment.PLAYGROUND_UNIT; } } // Am linken oder rechten Rand platzieren. else { if (RandomNumber.Number(2) == 0) { koordinate.X = 0; } else { koordinate.X = colony.Playground.Width * SimulationEnvironment.PLAYGROUND_UNIT; } koordinate.Y = RandomNumber.Number(0, colony.Playground.Height); koordinate.Y *= SimulationEnvironment.PLAYGROUND_UNIT; } } // In einem zufälligen Bau platzieren. else { int i = RandomNumber.Number(colony.AntHills.Count); koordinate.X = colony.AntHills[i].CoordinateBase.X + SimulationEnvironment.Cosinus( colony.AntHills[i].CoordinateBase.Radius, koordinate.Richtung); koordinate.Y = colony.AntHills[i].CoordinateBase.Y + SimulationEnvironment.Sinus( colony.AntHills[i].CoordinateBase.Radius, koordinate.Richtung); } }
/// <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 (IsNormalAnt || ShouldSugarAntActLikeNormal) { // Should not go straigth forward to extend the search areas. // Increases the possibility to spot an apple or enemy. GoForward(40); TurnByDegrees(RandomNumber.Number(-10, 10)); } else if (IsSugarAnt) { // Should find sugar trace. GoForward(150); TurnByDegrees(RandomNumber.Number(-15, 15)); } }
/// <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 (Anthill == null) { GoToAnthill(); // Sets Destination to anthill Anthill = Destination as Anthill; Stop(); // stop to reset Destination } if (Caste == Consts.Collector) { task = TaskManager.Instance.GetTask(this.Caste); if (task != null) { GoTo(((FoodTask)task).Target); } else { TurnByDegrees(RandomNumber.Number(-30, 30)); GoForward(100); } } else if (Caste == Consts.Scout) { TurnByDegrees(RandomNumber.Number(-40, 40)); GoForward(100); } else if (Caste == Consts.Hunter) { var enemyTask = TaskManager.Instance.GetTask(Caste); if (enemyTask != null) { var t = ((InsectTask)enemyTask).Target; if (t.CurrentEnergy > 0) { GoTo(t); return; } } TurnByDegrees(RandomNumber.Number(-20, 20)); GoForward(20); } }
/// <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() { this.TurnByDegrees(RandomNumber.Number(-179, 180)); this.GoForward(); }
/// <summary> /// Berechnet die Bewegung des Insekts. /// </summary> internal void Bewegen() { reached = false; // Insekt dreht sich. if (restWinkel != 0) { // Zielwinkel wird erreicht. if (Math.Abs(restWinkel) < colony.Drehgeschwindigkeit[CasteIndexBase]) { koordinate.Richtung += restWinkel; restWinkel = 0; } // Insekt dreht sich nach rechts. else if (restWinkel >= colony.Drehgeschwindigkeit[CasteIndexBase]) { koordinate.Richtung += colony.Drehgeschwindigkeit[CasteIndexBase]; RestWinkelBase -= colony.Drehgeschwindigkeit[CasteIndexBase]; } // Insekt dreht sich nach links. else if (restWinkel <= -colony.Drehgeschwindigkeit[CasteIndexBase]) { koordinate.Richtung -= colony.Drehgeschwindigkeit[CasteIndexBase]; RestWinkelBase += colony.Drehgeschwindigkeit[CasteIndexBase]; } } // Insekt geht. else if (restStreckeI > 0) { if (GetragenesObstBase == null) { int strecke = Math.Min(restStreckeI, aktuelleGeschwindigkeitI); restStreckeI -= strecke; zurückgelegteStreckeI += strecke; koordinate.X += SimulationEnvironment.Cos[strecke, koordinate.Richtung]; koordinate.Y += SimulationEnvironment.Sin[strecke, koordinate.Richtung]; } } // Insekt geht auf Ziel zu. else if (ziel != null) { int entfernungI; if (ZielBase is CoreMarker) { entfernungI = CoreCoordinate.BestimmeEntfernungDerMittelpunkteI(koordinate, ziel.CoordinateBase); } else { entfernungI = CoreCoordinate.BestimmeEntfernungI(koordinate, ziel.CoordinateBase); } reached = entfernungI <= SimulationEnvironment.PLAYGROUND_UNIT; if (!reached) { int richtung = CoreCoordinate.BestimmeRichtung(koordinate, ziel.CoordinateBase); // Ziel ist in Sichtweite oder Insekt trägt Obst. if (entfernungI < colony.SichtweiteI[CasteIndexBase] || getragenesObst != null) { restStreckeI = entfernungI; } // Ansonsten Richtung verfälschen. else { richtung += RandomNumber.Number(-18, 18); restStreckeI = colony.SichtweiteI[CasteIndexBase]; } dreheInRichtung(richtung); } } // Koordinaten links begrenzen. if (koordinate.X < 0) { koordinate.X = -koordinate.X; if (koordinate.Richtung > 90 && koordinate.Richtung <= 180) { koordinate.Richtung = 180 - koordinate.Richtung; } else if (koordinate.Richtung > 180 && koordinate.Richtung < 270) { koordinate.Richtung = 540 - koordinate.Richtung; } } // Koordinaten rechts begrenzen. else if (koordinate.X > colony.BreiteI) { koordinate.X = colony.BreiteI2 - koordinate.X; if (koordinate.Richtung >= 0 && koordinate.Richtung < 90) { koordinate.Richtung = 180 - koordinate.Richtung; } else if (koordinate.Richtung > 270 && koordinate.Richtung < 360) { koordinate.Richtung = 540 - koordinate.Richtung; } } // Koordinaten oben begrenzen. if (koordinate.Y < 0) { koordinate.Y = -koordinate.Y; if (koordinate.Richtung > 180 && koordinate.Richtung < 360) { koordinate.Richtung = 360 - koordinate.Richtung; } } // Koordinaten unten begrenzen. else if (koordinate.Y > colony.HöheI) { koordinate.Y = colony.HöheI2 - koordinate.Y; if (koordinate.Richtung > 0 && koordinate.Richtung < 180) { koordinate.Richtung = 360 - koordinate.Richtung; } } }