コード例 #1
0
        /// <summary>
        /// Military Gene:
        /// 1. NonMilitant
        /// 2. Passive Defender
        /// 3. Proactive Defender
        /// 4. Offender
        /// </summary>
        public static Gene CreateMilitaryGeneVariations()
        {
            // Assign probabilities
            int NonPercentage     = 25;
            int passivePercentage = 25;
            int activePercentage  = 25;
            int sumPrev           = NonPercentage + passivePercentage + activePercentage;

            // init gene randomly
            var          rand      = RandomHelper.StandardGeneratorInstance.Next(0, 100);
            MilitaryGene geneValue = MilitaryGene.Offender;

            if (rand < NonPercentage)
            {
                geneValue = MilitaryGene.NonMilitant;
            }
            else if (rand < NonPercentage + passivePercentage)
            {
                geneValue = MilitaryGene.Passive;
            }
            else if (rand < sumPrev)
            {
                geneValue = MilitaryGene.Proactive;
            }
            return(CreateMilitaryGene(geneValue));
        }
コード例 #2
0
        /// <summary>
        /// Military Gene:
        /// 1. Defenseless - non military
        /// 2. Passive Defender
        /// 3. Proactive Defender
        /// 4. Offender
        /// </summary>
        public static Gene CreateMilitaryGene(MilitaryGene geneValue = MilitaryGene.NonMilitant)
        {
            int value = (int)geneValue;
            // ReSharper disable once UseObjectOrCollectionInitializer
            var gene = new Gene
            {
                GeneDescription = GeneEnum.Military.ToString(),
                LastValue       = value,
                Minimum         = 1,
                Maximum         = Enum.GetNames(typeof(MilitaryGene)).Length,
                CanMutate       = true,
                IsDormant       = false,
                GeneType        = GeneEnum.Military
            };

            gene.CurrentValue = value;
            return(gene);
        }