public World(ContentManager content, Rectangle Bounds)
 {
     this.Bounds = Bounds;
     this.TextureCreature = content.Load<Texture2D>("Bug");
     this.TexturePoint = content.Load<Texture2D>("Point");
     this.TextureFood = content.Load<Texture2D>("Circle");
     this.MyFont = content.Load<SpriteFont>("MyFont");
     this.camera = new Camera(new Viewport(this.Bounds));
     this.basicshapes = new BasicShapes();
     creature = new List<Creature>();
     for (int i = 0; i < NrOfCreatures; i++)
     {
         Creature c = new Creature(Bounds);
         creature.Add(c);
     }
     food = new List<Food>();
     for (int i = 0; i < NrOfFood; i++)
     {
         Food f = new Food(Bounds);
         food.Add(f);
     }
     obstacle = new List<Obstacle>();
     for (int i = 0; i < NrOfObstacles; i++)
     {
         Obstacle o = new Obstacle(Bounds);
         obstacle.Add(o);
     }
     camera = new Camera(new Viewport(0, 0, 1600, 900));
     GA = new GeneticAlgorithm(60, 1);
     NrOfDeaths = 0;
     GraphValue = new double[32000];
     DoDraw = true;
 }
 public Obstacle GetClosestObstacle(List<Obstacle> obstacle, Vector2 Start)
 {
     Obstacle ClosestObstacle = new Obstacle(Bounds);
     double Closest = 32000;
     foreach (Obstacle o in obstacle)
     {
         if (GetDistance(Start, o.position) < Closest)
         {
             Closest = GetDistance(Start, o.position);
             ClosestObstacle = o;
         }
     }
     return ClosestObstacle;
 }
        public void Update()
        {
            camera.Update();

            NrOfDeaths = 0;
            foreach (Creature c in creature)
            {
                c.Update(food, obstacle);
                if (c.Life <= 0)
                    NrOfDeaths++;
            }

            Ticks++;
            if (Ticks == 10000 || NrOfDeaths == creature.Count())
            {
                Ticks = 0;
                GraphValue[GA.Generation] = GA.Evolve(creature, Bounds);
            }

            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                if (Ticks % 10 == 0)
                {
                    Obstacle NewObstacle = new Obstacle(Bounds);
                    NewObstacle.position = Vector2.Transform(new Vector2(Mouse.GetState().X, Mouse.GetState().Y), camera.InverseTransform);
                    obstacle.Add(NewObstacle);
                }
            }

            if (Mouse.GetState().RightButton == ButtonState.Pressed)
            {
                obstacle.Clear();
            }
        }