Example #1
0
        public IDNA CoinCrossover(IDNA objPartner)
        {
            AWorld child   = (AWorld)this.CreateInstance(false);
            AWorld partner = (AWorld)objPartner;

            for (int i = 0; i < partner.Genes.Length; i++)
            {
                child[i] = (ISlim)(Shared.Coin() ? this[i].Clone() : partner[i].Clone());
            }

            child.Mutate();

            return(child);
        }
Example #2
0
        public override IDNA Revive()
        {
            AWorld world = (AWorld)this.CreateInstance(true);

            for (int i = 0; i < this.Genes.Length; i++)
            {
                world[i] = (ISlim)this[i].Clone();
            }

            for (int i = 0; i < this.Enemies.Length; i++)
            {
                world.Enemies[i] = new SlimEnemy(i);
            }

            return(world);
        }
Example #3
0
        public override IDNA Clone()
        {
            AWorld world = (AWorld)this.CreateInstance(true);

            world.TotalAttackImportance = this.TotalAttackImportance;
            world.TotalAttackPrice      = this.TotalAttackPrice;
            world.DeadCount             = this.DeadCount;
            world.Fitness = this.Fitness;

            for (int i = 0; i < this.Genes.Length; i++)
            {
                world[i] = (ISlim)this[i].Clone();
            }

            for (int i = 0; i < this.Enemies.Length; i++)
            {
                world.Enemies[i] = this.Enemies[i].Clone();
            }

            return(world);
        }
Example #4
0
        public IDNA PartialGenomeCrossover(IDNA objPartner)
        {
            AWorld child   = (AWorld)this.CreateInstance(false);
            AWorld partner = (AWorld)objPartner;

            int        nStart             = Shared.Next(this.Genes.Length / 2 + 1);
            int        nEnd               = nStart + Shared.Next(this.Genes.Length / 2);
            List <int> colPassedGenesUIDs = new List <int>();

            for (int i = nStart; i < nEnd; i++)
            {
                child[i] = (ISlim)partner[i].Clone();
                colPassedGenesUIDs.Add(partner[i].UID);
            }

            int nGeneInsertionPos = 0;

            for (int i = 0; i < this.Genes.Length; i++)
            {
                if (nGeneInsertionPos == nStart)
                {
                    nGeneInsertionPos = nEnd;
                }

                if (colPassedGenesUIDs.Contains(this.Genes[i].UID))
                {
                    continue;
                }

                child[nGeneInsertionPos] = (ISlim)this.Genes[i].Clone();
                nGeneInsertionPos++;
            }

            child.Mutate();

            return(child);
        }