public AmeisenSimulation(int grenzeX = 120, int grenzeY = 40, int ameisenAnzahl = 20) { ameisen = new ant[ameisenAnzahl]; essen = new food(grenzeX, grenzeY); zuHause = new home(grenzeX, grenzeY); Console.SetWindowSize(grenzeX + 10, grenzeY + 10); for (int i = 0; i < ameisen.Length; i++) { ameisen[i] = new ant(grenzeX, grenzeY); } while (true) { foreach (ant ameise in ameisen) { ameise.Seek(essen, zuHause); } if (essen.foodLeft > 0) { essen.Draw("F"); } else { essen = new food(grenzeX, grenzeY); } zuHause.Draw("H"); Console.SetCursorPosition(0, grenzeY + 5); Console.WriteLine("food: " + zuHause.foodCount); System.Threading.Thread.Sleep(100); } }
public AmeisenSimulation(int grenzeX = 120, int grenzeY = 40, int ameisenAnzahl = 5, int essensAnzahl = 2) { ameisen = new List <ant>(); //essen = new food(grenzeX, grenzeY); essen = new List <food>(); zuHause = new home(grenzeX, grenzeY); Console.SetWindowSize(grenzeX + 10, grenzeY + 10); for (int i = 0; i < ameisenAnzahl; i++) { ameisen.Add(new ant(grenzeX, grenzeY)); ameisen[i].sim = this; } for (int i = 0; i < essensAnzahl; i++) { essen.Add(new food(grenzeX, grenzeY)); essen[i].sim = this; } while (true) { for (int i = 0; i < ameisen.Count; i++) { essen[0].posX = 1; essen[0].posY = 1; foreach (food esse in essen) { esse.Draw("F"); } //ameisen[i].LocateNearestFood(essen); int index = ameisen[i].LocateNearestFood(essen); ameisen[i].Seek(essen[index], zuHause); ameisen[i].energie -= 1; if (ameisen[i].CheckIfDead()) { CleanUp(ameisen[i].posX, ameisen[i].posY); ameisen.RemoveAt(i); } } // if (essen.foodLeft > 0) // { // essen.Draw("F"); // } // else // { // essen = new food(grenzeX, grenzeY); // } zuHause.Draw("H"); Console.SetCursorPosition(0, grenzeY + 5); Console.WriteLine("food: " + zuHause.foodCount); System.Threading.Thread.Sleep(100); } }
public AmeisenSimulation(int grenzeX = 120, int grenzeY = 40, int ameisenAnzahl = 20, int essensAnzahl = 15) { ameisen = new List <ant>(); essen = new List <food>(); zuHause = new home(grenzeX, grenzeY); Console.SetWindowSize(grenzeX + 10, grenzeY + 10); for (int i = 0; i < ameisenAnzahl; i++) { ameisen.Add(new ant(grenzeX, grenzeY)); ameisen[i].sim = this; } for (int i = 0; i < essensAnzahl; i++) { essen.Add(new food(grenzeX, grenzeY)); essen[i].sim = this; } while (true) { for (int i = 0; i < ameisen.Count; i++) { for (int j = 0; j < essen.Count; j++) { if (essen[j].foodLeft <= 0) { CleanUp(essen[j].posX, essen[j].posY); essen.RemoveAt(j); essen.Add(new food(grenzeX, grenzeY)); } if (essen[j].foodLeft > 0) { essen[j].Draw("F"); } } if (ameisen[i].currentFoodGoal == false) { ameisen[i].SetFood(essen[ameisen[i].LocateNearestFood(essen)]); ameisen[i].currentFoodGoal = true; } if (ameisen[i].currentFood.foodLeft <= 0) { ameisen[i].currentFoodGoal = false; } ameisen[i].Seek(ameisen[i].currentFood, zuHause); ameisen[i].energie -= 1; if (ameisen[i].CheckIfDead()) { CleanUp(ameisen[i].posX, ameisen[i].posY); ameisen.RemoveAt(i); } } zuHause.Draw("H"); Console.SetCursorPosition(0, grenzeY + 5); Console.WriteLine("food: " + zuHause.foodCount); System.Threading.Thread.Sleep(10); } }