Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        public void SeekFood(food futter)
        {
            Console.SetCursorPosition(posX, posY);             // cleans up after itself
            Console.WriteLine(" ");

            if (posX != futter.posX || posY != futter.posY)
            {
                int whereIsMyFoodX = futter.posX - posX;
                int whereIsMyFoodY = futter.posY - posY;

                if (whereIsMyFoodY > 0)
                {
                    posY += 1;
                }

                if (whereIsMyFoodX < 0)
                {
                    posX -= 1;
                }

                if (whereIsMyFoodY < 0)
                {
                    posY -= 1;
                }

                if (whereIsMyFoodX > 0)
                {
                    posX += 1;
                }
            }

            Move();
            Console.SetCursorPosition(posX, posY);
            Console.WriteLine("A");
        }
Exemplo n.º 3
0
        public static void Main(string[] args)
        {
            int borderX = 120;
            int borderY = 40;

            Console.SetWindowSize(borderX + 10, borderY + 10);
            ant[] ameisen = new ant[20];
            food  essen   = new food()
            {
                limitX = borderX, limitY = borderY
            };



            for (int i = 0; i < ameisen.Length; i++)
            {
                ameisen[i] = new ant()
                {
                    limitX = borderX, limitY = borderY
                };
                ameisen[i].Spawn();
            }

            essen.Spawn();


            while (true)
            {
                foreach (ant ameise in ameisen)
                {
                    ameise.SeekFood(essen);
                }
                essen.Show();

                System.Threading.Thread.Sleep(200);
            }


            //Console.ResetColor();


//			Here is the comment section for remembering stuff:

//			Console.SetWindowSize(borderX, borderY);
//	        Console.SetCursorPosition(10, 10);
//	        Console.WriteLine("A");
//	        System.Threading.Thread.Sleep(500);
//	        Console.Clear();
//	        //System.Threading.Thread.Sleep(500);
//	        Console.SetCursorPosition(11, 10);
//	        Console.WriteLine("A");

//	        for (int i = 0; i < borderX; i++)               // Move from left to right
//	        {
//		        Console.SetCursorPosition(i, 10);
//		        Console.WriteLine("A");
//		        System.Threading.Thread.Sleep(200);
//		        Console.Clear();
//	        }
        }
Exemplo n.º 4
0
        public void Seek(food futter, home haus)
        {
            Draw(" ");

            if ((posX != futter.posX || posY != futter.posY) && hasFood == false)
            {
                int whereIsMyFoodX = futter.posX - posX;
                int whereIsMyFoodY = futter.posY - posY;

                if (whereIsMyFoodX == 0 && whereIsMyFoodY == 0)
                {
                    hasFood = true;
                }

                if (whereIsMyFoodY > 0)
                {
                    posY += 1;
                }

                if (whereIsMyFoodX < 0)
                {
                    posX -= 1;
                }

                if (whereIsMyFoodY < 0)
                {
                    posY -= 1;
                }

                if (whereIsMyFoodX > 0)
                {
                    posX += 1;
                }
            }

            if ((posX != haus.posX || posY != haus.posY) && hasFood == true)
            {
                int whereIsMyHomeX = haus.posX - posX;
                int whereIsMyHomeY = haus.posY - posY;

                if (whereIsMyHomeY > 0)
                {
                    posY += 1;
                }

                if (whereIsMyHomeX < 0)
                {
                    posX -= 1;
                }

                if (whereIsMyHomeY < 0)
                {
                    posY -= 1;
                }

                if (whereIsMyHomeX > 0)
                {
                    posX += 1;
                }
            }

            if (posY == futter.posY)
            {
                if (posX == futter.posX)
                {
                    hasFood          = true;
                    futter.foodLeft -= 1;
                }
            }

            if (posY == haus.posY)
            {
                if (posX == haus.posX)
                {
                    hasFood         = false;
                    haus.foodCount += 1;
                }
            }
            Move();
        }
Exemplo n.º 5
0
        public void Seek(food futter, home haus)
        {
            Draw(" ");

            if (hasFood == false)
            {
                if (sim.PositionEqual(this.posX, this.posY, futter.posX, futter.posY))
                {
                    hasFood          = true;
                    futter.foodLeft -= 1;
                }
                else
                {
                    int distanceToMyFoodX = futter.posX - posX;
                    int distanceToMyFoodY = futter.posY - posY;

                    if (distanceToMyFoodY > 0)
                    {
                        posY += 1;
                    }

                    if (distanceToMyFoodX < 0)
                    {
                        posX -= 1;
                    }

                    if (distanceToMyFoodY < 0)
                    {
                        posY -= 1;
                    }

                    if (distanceToMyFoodX > 0)
                    {
                        posX += 1;
                    }
                }
            }
            if (hasFood == true)
            {
                if (sim.PositionEqual(this.posX, this.posY, haus.posX, haus.posY))
                {
                    hasFood         = false;
                    haus.foodCount += 1;
                }
                else
                {
                    int whereIsMyHomeX = haus.posX - posX;
                    int whereIsMyHomeY = haus.posY - posY;

                    if (whereIsMyHomeY > 0)
                    {
                        posY += 1;
                    }

                    if (whereIsMyHomeX < 0)
                    {
                        posX -= 1;
                    }

                    if (whereIsMyHomeY < 0)
                    {
                        posY -= 1;
                    }

                    if (whereIsMyHomeX > 0)
                    {
                        posX += 1;
                    }
                }
            }

            Move();
        }
Exemplo n.º 6
0
 public void SetFood(food futter)
 {
     currentFood = futter;
 }
Exemplo n.º 7
0
        public void Seek(food futter, home haus)
        {
            Console.SetCursorPosition(posX, posY);             // cleans up after itself
            Console.WriteLine(" ");

            if ((posX != futter.posX || posY != futter.posY) && hasFood == false)
            {
                int whereIsMyFoodX = futter.posX - posX;
                int whereIsMyFoodY = futter.posY - posY;

                if (whereIsMyFoodX == 0 && whereIsMyFoodY == 0)
                {
                    hasFood = true;
                }

                if (whereIsMyFoodY > 0)
                {
                    posY += 1;
                }

                if (whereIsMyFoodX < 0)
                {
                    posX -= 1;
                }

                if (whereIsMyFoodY < 0)
                {
                    posY -= 1;
                }

                if (whereIsMyFoodX > 0)
                {
                    posX += 1;
                }
            }

            if ((posX != haus.posX || posY != haus.posY) && hasFood == true)
            {
                int whereIsMyHomeX = haus.posX - posX;
                int whereIsMyHomeY = haus.posY - posY;

                if (whereIsMyHomeY > 0)
                {
                    posY += 1;
                }

                if (whereIsMyHomeX < 0)
                {
                    posX -= 1;
                }

                if (whereIsMyHomeY < 0)
                {
                    posY -= 1;
                }

                if (whereIsMyHomeX > 0)
                {
                    posX += 1;
                }
            }

            if (posY == futter.posY)
            {
                if (posX == futter.posX)
                {
                    hasFood          = true;
                    futter.foodLeft -= 1;
                }
            }

            if (posY == haus.posY)
            {
                if (posX == haus.posX)
                {
                    hasFood         = false;
                    haus.foodCount += 1;
                }
            }

            Move();
            Console.SetCursorPosition(posX, posY);
            Console.WriteLine("A");
        }