Example #1
0
        //The breeding method creates/breeds a new individual. This new individual's DNA is made out
        //of two separate individuals (the parents), that enter the method as its parameters (well the pointers/indexes to them).
        //The breeding does not always occur. The probability of happening is defined by the variable iBreedingChance.
        //This is supposed to represent different situations that can occur during a breeding (miscarriage, premature death of the newborn, etc).

        public static Individual BreedIndividuals(int Individual_1_index, int Individual_2_index, List <Individual> _BreedingPool)
        {
            int _iRandomNumber = r.Next(1, 100);

            Thread.Sleep(100);
            int        _DNASwapPercentage = r.Next(0, 4);
            Individual _Individual_1;
            Individual _Individual_2;
            Individual _Newborn = new Individual();

            if (Individual_1_index <0 | Individual_1_index> _BreedingPool.Count - 1)
            {
                return(_Newborn);
            }

            if (Individual_2_index <0 | Individual_2_index> _BreedingPool.Count - 1)
            {
                return(_Newborn);
            }

            if (iBreedingChance > 0 && _iRandomNumber <= iBreedingChance)
            {
                _Individual_1 = _BreedingPool[Individual_1_index];
                _Individual_2 = _BreedingPool[Individual_2_index];
                _Newborn      = _Newborn.SwapDna(_Individual_1, _Individual_2, _DNASwapPercentage);
                return(_Newborn);
            }
            else
            {
                return(_Newborn);
            }
        }