Example #1
0
        public virtual void LoadContent(ContentManager content)
        {
            texture[AnimationType.WALKING] = content.Load <Texture2D>(textureName[AnimationType.WALKING]);

            missileTroll = content.Load <Texture2D>("axe");
            missileElven = content.Load <Texture2D>("arrow");

            ui.LoadContent(content);

            GeneticUtil.Encode(this);
        }
Example #2
0
        public void Update()
        {
            int alives = 0;

            for (int i = 0; i < enemies.Count; i++)
            {
                enemies[i].Update();

                if (enemies[i].information.HitPoints > 0)
                {
                    alives++;
                }
            }

            if (alives == 0)
            {
                string           s        = "";
                List <UnitEnemy> waveDead = new List <UnitEnemy>();
                for (int i = wavesEnemies * generation; i < (wavesEnemies * generation) + (wavesEnemies); i++)
                {
                    waveDead.Add(enemies[i]);

                    s += (enemies[i].information.Fitness + ", ");
                }

                for (int i = 0; i < waveDead.Count / 2; i++)
                {
                    UnitEnemy[] indexes  = GeneticUtil.RouletteWheelSelection(waveDead);
                    string[]    parent01 = GeneticUtil.Encode(indexes[0]);
                    string[]    parent02 = GeneticUtil.Encode(indexes[1]);

                    int cut = random.Next(0, parent01.Length);

                    string[] child01 = new string[7];
                    string[] child02 = new string[7];

                    if (random.Next(0, 100) > 80)
                    {
                        for (int j = 0; j < parent01.Length; j++)
                        {
                            if (j < cut)
                            {
                                child01[j] = parent01[j];
                                child02[j] = parent02[j];
                            }
                            else
                            {
                                child01[j] = parent02[j];
                                child02[j] = parent01[j];
                            }
                        }
                    }
                    else
                    {
                        child01 = parent01;
                        child02 = parent02;
                    }

                    InformationUnit info01 = GeneticUtil.Decode(child01);
                    InformationUnit info02 = GeneticUtil.Decode(child02);

                    if (info01.Type == Util.Units.GRUNT)
                    {
                        enemies.Add(new Grunt(info01, managerMouse, managerMap, managerBuildings));
                    }
                    else
                    {
                        enemies.Add(new TrollAxethrower(info01, managerMouse, managerMap, managerBuildings));
                    }

                    if (info02.Type == Util.Units.GRUNT)
                    {
                        enemies.Add(new Grunt(info02, managerMouse, managerMap, managerBuildings));
                    }
                    else
                    {
                        enemies.Add(new TrollAxethrower(info02, managerMouse, managerMap, managerBuildings));
                    }
                }

                Console.WriteLine(s);

                generation++;

                LoadContent();
            }

            //for (int i = 0; i < enemies.Count; i++)
            //{
            //    if (enemies[i].information.HitPoints > 0)
            //    {
            //        enemies[i].information.HitPoints = 0;
            //        enemies[i].information.Fitness = random.Next(0, 500);
            //    }
            //}
        }