Esempio n. 1
0
        protected override void Initialize()
        {
            totalEnergyHistory = new int[10000];
            energyBars         = new DrawableRect[1];

            this.IsMouseVisible = true;

            botFocus = -1;

            behaviourPointer    = new int[2];
            behaviourPointer[0] = 0;
            behaviourPointer[1] = 0;

            cam          = new Camera();
            mouseDragPos = new Vector2[3];

            totalFoodBitsEaten = new int[10000];
            bestEnergyHistory  = new List <int>();

            worldBounds = new DrawableRect(0, 0, worldWidth, worldHeight, new Color(255, 150, 150), 5);

            base.Initialize();
        }
Esempio n. 2
0
        public void PickBest()
        {
            Random     gen     = new Random();
            List <Bot> argBots = new List <Bot>();

            int[] bestBots      = { -1, -1, -1, -1, -1 };
            Bot[] bestBotss     = new Bot[5];
            int   highestEnergy = 0;
            int   totalEnergy   = 0;

            Bot bot = null;

            if (botFocus != -1)
            {
                bot = bots[botFocus];
            }

            for (int j = 0; j != 5; j++)
            {
                for (int i = 0; i != bots.Count; i++)
                {
                    totalEnergy += bots[i].energy;

                    if (bots[i].energy > highestEnergy)
                    {
                        bestBots[j]   = i;
                        highestEnergy = bots[i].energy;
                    }
                }

                if (j == 0)
                {
                    bestEnergyHistory.Add(highestEnergy);
                }

                highestEnergy = 0;
                if (bestBots[j] < bots.Count)
                {
                    if (bestBots[j] != -1)
                    {
                        bestBotss[j] = bots[bestBots[j]];
                        bots.Remove(bots[bestBots[j]]);
                    }
                    else
                    {
                        bestBotss[j] = bots[gen.Next(bots.Count)];
                    }
                }

                if (j == 0)
                {
                    totalEnergyHistory[generations] = totalEnergy;
                }
            }
            for (int i = 0; i != bestBotss.Length; i++)
            {
                argBots.Add(bestBotss[i]);
            }

            if (botFocus == -1)
            {
                bots = new List <Bot>();
                for (int i = 0; i != 5; i++)
                {
                    for (int j = 0; j != 10; j++)
                    {
                        bots.Add(new Bot(gen.Next(worldWidth), gen.Next(worldHeight), botTex, 5d, 40d, 100d, bestBotss[i].behaviour, gen, fovs));
                        bots[i * 10 + j].angle = gen.Next(360);
                    }
                }
            }
            else
            {
                bots = new List <Bot>();
                for (int i = 0; i != 50; i++)
                {
                    bots.Add(new Bot(gen.Next(worldWidth), gen.Next(worldHeight), botTex, 5d, 40d, 100d, bot.behaviour, gen, fovs));
                    bots[i].angle = gen.Next(360);
                }
            }

            food = new List <Food>();
            for (int i = 0; i != 400; i++)
            {
                food.Add(new Food(gen.Next(worldWidth), gen.Next(worldHeight), gen.Next(1000) + 1000, foodTex));
            }

            generations++;


            if (generations % 10 == 0)
            {
                Console.WriteLine("Total Energy: ");
                for (int i = 0; i != generations; i++)
                {
                    Console.Write(totalEnergyHistory[i] + ",");
                }
                Console.WriteLine();

                Console.WriteLine("Total Food: ");
                for (int i = 0; i != generations; i++)
                {
                    Console.Write(totalFoodBitsEaten[i] + ",");
                }

                Console.WriteLine();

                Console.WriteLine("Best: ");
                for (int i = 0; i != generations; i++)
                {
                    Console.Write(bestEnergyHistory[i] + ",");
                }

                Console.WriteLine();

                for (int i = 0; i != argBots.Count; i++)
                {
                    Console.Write(argBots[i].behaviour.ToString());
                }

                Console.WriteLine();
                Console.WriteLine();
            }

            energyBars = new DrawableRect[generations];
            for (int i = 0; i != generations; i++)
            {
                int size = (int)(totalEnergyHistory[i] / (double)500);
                energyBars[i] = new DrawableRect((i * 2) + 10, worldHeight - 10 - size, 2, size, Color.White, 1);
            }

            foodBars = new DrawableRect[generations];
            for (int i = 0; i != generations; i++)
            {
                int size = totalFoodBitsEaten[i];
                foodBars[i] = new DrawableRect((i * 2) + 10, -5 - size, 2, size, Color.SpringGreen, 1);
            }
        }