Esempio n. 1
0
        public void LoadContent(ContentManager content, GraphicsDevice graphics)
        {
            FontSeparation.Character.Content = content;

            Fish.Content = content;
            for (int x = 0; x < fishList.Length; x++)
            {
                fishList[x] = new Fish();
                fishList[x].fishIndex = x;

                characterList.Add(new FontSeparation.Character("font.png", x.ToString() + ":" + fishList[x].collisionCircle.life, new Vector2(0, x * 25)));
            }

            characterList.Add(new FontSeparation.Character("font.png", "", new Vector2(10, Game1.screenHeight - 64)));
            characterList.Add(new FontSeparation.Character("font.png", "", new Vector2(10, Game1.screenHeight - 32)));

            Food.Content = content;
            for (int x = 0; x < FOODCOUNT; x++)
                foodList.Add(new Food());
        }
        public bool ReturnZeroScore(Fish[] fishList)
        {
            bool containsZero = true;

            foreach (Fish fish in fishList)
                if (fish.collisionCircle.Score > 0) containsZero = false;

            return containsZero;
        }
        public double CheckTrend(Fish[] fishList)
        {
            double cumulative = 0;
            int counter = generation;
            int greater = 0;

            if (fishList.Length > 1)
            {
                if (fishList[generation].collisionCircle.Score > fishList[generation - 1].collisionCircle.Score)
                {
                    generationScore += 1;
                    greater = 1;

                    if (generationScore > peakScore) peakScore = generationScore;
                }
                if (fishList[generation].collisionCircle.Score < fishList[generation - 1].collisionCircle.Score)
                {
                    generationScore -= 1;
                    greater = -1;
                }
                if (fishList[generation].collisionCircle.Score == fishList[generation - 1].collisionCircle.Score)
                    greater = 2;

                while (counter > 1)
                {
                    if (greater == 1)
                    {
                        if (fishList[counter].collisionCircle.Score > fishList[counter - 1].collisionCircle.Score)
                        {
                            cumulative += 1;
                            counter -= 1;
                        }
                        else
                        {
                            trendState = cumulative;
                            return cumulative;
                        }
                    }
                    if (greater == -1)
                    {
                        if (fishList[counter].collisionCircle.Score < fishList[counter - 1].collisionCircle.Score)
                        {
                            cumulative -= 1;
                            counter -= 1;
                        }
                        else
                        {
                            trendState = cumulative;
                            return cumulative;
                        }
                    }

                    if (greater == 2)
                    {
                        if (fishList[counter].collisionCircle.Score == fishList[counter - 1].collisionCircle.Score)
                        {
                            cumulative += .01;
                            counter -= 1;
                        }
                        else
                        {
                            trendState = cumulative;
                            return cumulative;
                        }
                    }

                    if (greater == 0)
                    {
                        trendState = cumulative;
                        return cumulative;
                    }
                }
            }

            trendState = cumulative;
            return cumulative;
        }
        public Fish[] ReturnFittestStream(int count)
        {
            if (fittest.Count < count)
                count = fittest.Count;

            Fish[] fishList = new Fish[count];
            for (int x = 0; x < count; x++)
            {
                fishList[x] = new Fish(RankFittest(fittest.ToArray())[x].brain);
            }

            Console.WriteLine("!!!!!!!!!!!!!!!!!!!!!!!!!!! SET TO FITTEST !!!!!!!!!!!!!!!!!!!!!!!!!!!");

            return fishList;
        }
        public Fish[] RankFittest(Fish[] fishList)
        {
            Fish[] newFishList = fishList;
            Fish temp;

            for (int x = 0; x < fishList.Length; x++)
            {
                for (int y = 1; y < fishList.Length - x; y++)
                {
                    if (newFishList[y - 1].collisionCircle.Score < newFishList[y].collisionCircle.Score)
                    {
                        temp = newFishList[y - 1];
                        newFishList[y - 1] = newFishList[y];
                        newFishList[y] = temp;
                    }
                }
            }

            return newFishList;
        }
        public bool GetGenerationState(Fish[] fishList)
        {
            if (generationTimer > 30f)
            {
                generationTimer = 0f;
                return true;
            }

            foreach (Fish fish in fishList)
                if (fish.collisionCircle.dead == false)
                    return false;

            generationTimer = 0f;
            return true;
        }
 public Fish GetFittest(Fish[] fishList)
 {
     return RankFittest(fishList)[0];
 }
        public Fish[] ExterminatePopulation(Fish[] fishList, int percent)
        {
            List<Fish> newFishList = new List<Fish>();
            foreach (Fish fish in fishList)
                newFishList.Add(fish);
            List<Fish> tempNewFishList = new List<Fish>();
            foreach (Fish fish in fishList)
                tempNewFishList.Add(fish);

            int amountRemoved = 0;
            int randomInt = random.Next(101);

            while ((amountRemoved / fishList.Length) * 100 < percent)
            {
                for (int x = 0; x < fishList.Length; x++)
                {
                    if ((x / fishList.Length) * 100 >= randomInt)
                        tempNewFishList.Remove(newFishList[x]);

                    amountRemoved += 1;

                    if ((amountRemoved / fishList.Length) * 100 >= percent) return newFishList.ToArray();

                    randomInt = random.Next(101);
                }
            }

            return tempNewFishList.ToArray();
        }