Beispiel #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];
     redAnts = new List<Ant>();
     blueAnts = new List<Ant>();
     foods = new List<Food>();
     anthills = new Anthill[2];
     // create anthill
     Location anthill0 = new Location(width / 4, height / 2);
     Location anthill1 = new Location(3 * width / 4, height / 2);
     anthills[0] = new Anthill(new Rectangle(anthill0.x - 7, anthill0.y - 7, 14, 14));
     anthills[1] = new Anthill(new Rectangle(anthill1.x - 7, anthill1.y - 7, 14, 14));
     // create ants
     for (int i = 0; i < numAnts; i++ )
     {
         redAnts.Add(new Ant(Ant.Affiliance.Red, this, new Rectangle(anthill0.x - 2, anthill0.y - 2, 4, 4)));
         blueAnts.Add(new Ant(Ant.Affiliance.Blue, this, new Rectangle(anthill1.x - 2, anthill1.y - 2, 4, 4)));
     }
     // 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));
 }
Beispiel #2
0
 private void DrawAnthill(Anthill anthill, Color color)
 {
     SolidBrush brush = new SolidBrush(color);
     mapGraphics.FillEllipse(brush, anthill.Location);
 }