Ejemplo n.º 1
0
 public World(int initWidth, int initHeight, int numAnts, int numFoodPiles, int foodPerPile)
 {
     t = new Thread(TimeStep);
     height = initHeight;
     width = initWidth;
     field = new int[width + 50, height + 50];
     pheromone = new float[width + 50, height + 50];
     ants = new Ant[numAnts];
     foods = new List<Food>();
     anthills = new Anthill[1];
     // create anthill
     anthills[0] = new Anthill(new Rectangle((width / 2) - 7, (height / 2) - 7, 14, 14));
     // create ants
     for (int i = 0; i < numAnts; i++ )
         ants[i] = new Ant(this, new Rectangle(width / 2 - 3, height / 2 - 3, 6, 6));
     // create food
     for (int i = 0; i < numFoodPiles; i++)
         foods.Add(new Food(new Rectangle((int)rand.Next(25, width - 25), (int)rand.Next(25, height - 25), 10, 10), foodPerPile));
 }
Ejemplo n.º 2
0
 private void DrawAnt(Ant ant)
 {
     mapGraphics.DrawEllipse(new Pen(Color.Black), ant.loc);
     if (ant.hasFood)
     {
         SolidBrush brush = new SolidBrush(Color.LightGreen);
         mapGraphics.FillEllipse(brush, ant.loc);
     }
 }