public void GetTarget(LifeForm lf, List <LifeForm> Coloni, Params Par) { if (CheckNeedNewTarget(lf, Par) == true) { int i_InOrderX = -1; int i_InOrderY = -1; for (int i = 0; i < OrderedColoniX.Count; i++) { if (lf.ID == OrderedColoniX[i].ID) { i_InOrderX = i; } if (lf.ID == OrderedColoniY[i].ID) { i_InOrderY = i; } if (i_InOrderX > -1 && i_InOrderY > -1) { break; } } GetTargetFromNeibours(lf, i_InOrderX, i_InOrderY, 1, Par); if (lf.TargetID >= OrderedColoniX.Count) { int ahtung; } } }
public float Distance(LifeForm lf1, LifeForm lf2) { float x = Math.Abs(lf1.CurrentLocX - lf2.CurrentLocX); float y = Math.Abs(lf1.CurrentLocY - lf2.CurrentLocY); float Distance = (float)(Math.Sqrt(x * x + y * y)); return(Distance); }
public void MoveAngleChangeToTarget(LifeForm Currentlf, List <LifeForm> _Coloni, Params Par, Order Order) { if (Order.CheckNeedNewAngle(Currentlf, Par) == true) { double MoveAngleShouldBe; LifeForm Targetlf; Targetlf = _Coloni[Currentlf.TargetID]; MoveAngleShouldBe = Math.Atan2((Targetlf.CurrentLocX - Currentlf.CurrentLocX), (Targetlf.CurrentLocY - Currentlf.CurrentLocY)); Currentlf.MoveAngle = (float)(MoveAngleShouldBe); } }
public void ColoniCount_plus(LifeForm lf) { this.ColoniCount++; if (lf.Gender == 'M') { this.MaleCount++; } else { this.FemaleCount++; } }
public void ColoniCount_minus(LifeForm lf) { this.ColoniCount--; if (lf.Gender == 'M') { this.MaleCount--; } else { this.FemaleCount--; } this.DeadLfCount++; }
public bool CheckNeedNewAngle(LifeForm lf1, Params Par) { if (lf1.Age > Par.ChildAge && lf1.IsPregnant != true && lf1.IsAlive == true && lf1.TargetID > -1) { return(true); } else { return(false); } }
public bool GetTargetFromNeibours(LifeForm lf1, int i_InOrderX, int i_InOrderY, int Delta, Params Par) { List <LifeForm> NeibourList = new List <LifeForm>(); if (i_InOrderX - Delta > -1) { NeibourList.Add(OrderedColoniX[i_InOrderX - Delta]); } if (i_InOrderX + Delta < OrderedColoniX.Count) { NeibourList.Add(OrderedColoniX[i_InOrderX + Delta]); } if (i_InOrderY - Delta > -1) { NeibourList.Add(OrderedColoniY[i_InOrderY - Delta]); } if (i_InOrderY + Delta < OrderedColoniY.Count) { NeibourList.Add(OrderedColoniY[i_InOrderY + Delta]); } float distance = -1; foreach (LifeForm lf2 in NeibourList) { if (CheckCompatibility(lf1, lf2, Par) == true) { if (lf1.Distance(lf1, lf2) < lf1.ViewDistance) { if (distance == -1) { distance = lf1.Distance(lf1, lf2); lf1.TargetID = lf2.ID; } else if (distance > lf1.Distance(lf1, lf2)) { distance = lf1.Distance(lf1, lf2); lf1.TargetID = lf2.ID; } } } } if (distance == -1) { return(false); } else { return(true); } }
//public void ShowOrder () //{ // string ListOfElements = ""; // for (int i = 0; i < OrderedColoniX.Count; i++) // { // ListOfElements += i + " :" + OrderedColoniX[i].CurrentLocX + '\n'; // } // MessageBox.Show(ListOfElements); //} public bool CheckDistance(LifeForm lf1, List <LifeForm> Coloni, Params Par) { if (lf1.TargetID > -1) { if (lf1.Distance(lf1, Coloni[lf1.TargetID]) < lf1.ViewDistance) { return(true); } else { lf1.TargetID = -1; return(false); } } else { return(false); } }
public void LifeTime_Tick(Object sender, EventArgs e) { LifeForm lf = new LifeForm(Coloni, Par); this.NewColoni(Coloni, CurrentOrder, Par, Stat); //create start coloni if coloni.count == 0 CurrentOrder.UpdateOrder(Coloni); //<< lf.Growing(Coloni); //growing for everybody lf.Search(Coloni, CurrentOrder); //search target to move lf.Move(Coloni); CurrentOrder.UpdateOrder(Coloni); //<< lf.Sex(Coloni); lf.Death(Coloni, Stat); DrawObject.DrawLf(Coloni, Par); lf.RemoveBody(Coloni); CurrentOrder.UpdateOrder(Coloni); //<< lf.Born(Coloni, Stat); }
public bool CheckCompatibility(LifeForm lf1, LifeForm lf2, Params Par) { if (lf1.Age > Par.ChildAge && lf1.IsPregnant != true && lf1.IsAlive == true && lf1.TargetID == -1 && lf2.Age > Par.ChildAge && lf1.ID != lf2.ID && lf2.IsPregnant != true && lf2.IsAlive == true && lf1.Gender != lf2.Gender) { return(true); } else { return(false); } }
public void Born(List <LifeForm> _Coloni, Statistics Stat) { for (int i = 0; i < _Coloni.Count; i++) { LifeForm lf = _Coloni[i]; TimeSpan T = DateTime.Now - lf.PregnantTime; if ((T.TotalSeconds) >= Par.PregnantePeriod && lf.IsPregnant == true) { int ChildCount = rnd.Next(1, Par.BornAtOnce + 1); for (int ii = 0; ii < ChildCount; ii++) { _Coloni.Add(new LifeForm(_Coloni, Par)); _Coloni[_Coloni.Count - 1].CurrentLocX = lf.CurrentLocX; _Coloni[_Coloni.Count - 1].CurrentLocY = lf.CurrentLocY; //update coloni statistic Stat.ColoniCount_plus(_Coloni[_Coloni.Count - 1]); } lf.IsPregnant = false; } } }
public void DropTarget(LifeForm lf) { lf.TargetID = -1; lf.MoveAngle = (float)(rnd.Next(0, 360) * Math.PI / 180); }