Exemplo n.º 1
0
        private void CreateSystem(PeaSettings settings)
        {
            _starter = Sender;

            var parameterSet      = new ParameterSet(settings.ParameterSet);
            int archipelagosCount = parameterSet.GetInt(ParameterNames.ArchipelagosCount);
            int islandsCount      = parameterSet.GetInt(ParameterNames.IslandsCount);

            ResultsWaitForCount = archipelagosCount * islandsCount;

            Archipelagos = new List <IActorRef>(archipelagosCount);

            for (int a = 0; a < archipelagosCount; a++)
            {
                var archipelagoProps = ArchipelagoActor.CreateProps(settings);
                var actorRef         = Context.ActorOf(archipelagoProps);
                Archipelagos.Add(actorRef);
                ArchipelagosCount++;
            }

            var fitness = (IFitnessFactory)Activator.CreateInstance(settings.Fitness);

            FitnessComparer = fitness.GetFitnessComparer();

            AddCallbackEvents(settings.NewEntityMergedToBest);
        }
Exemplo n.º 2
0
        private void InitEnemyPools(ref ParameterSet Parm)
        {
            availableWeakAI = new LinkedList<AI>();
            availableRangedAI = new LinkedList<AI>();
            availableHeavyAI = new LinkedList<AI>();

            //add the number of enemies in the file

            Vector3 zero = Vector3.Zero;

            int num;
            if (Parm.HasParm("EnemyWeakPoolSize"))
                num = Parm.GetInt("EnemyWeakPoolSize");
            else num = 0;

            for(int i = 0; i < num; i++)
                PreLoad("EnemyWeak", ref zero, ref zero);

            if (Parm.HasParm("EnemyRangedPoolSize"))
                num = Parm.GetInt("EnemyRangedPoolSize");
            else num = 0;

            for (int i = 0; i < num; i++)
                PreLoad("EnemyRanged", ref zero, ref zero);

            if (Parm.HasParm("EnemyHeavyPoolSize"))
                num = Parm.GetInt("EnemyHeavyPoolSize");
            else num = 0;

            for(int i = 0; i < num; i++)
                PreLoad("EnemyHeavy", ref zero, ref zero);

            ShutdownAll();
        }
Exemplo n.º 3
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationIntensity = ParameterSet.GetValue(ParameterNames.MutationIntensity);
            int blockSize         = ParameterSet.GetInt(ParameterNames.BlockSize);

            int    relPos       = Random.GetInt(0, blockSize);
            double modification = Random.GetGaussian(0, mutationIntensity);

            for (int block = 0; block < length / blockSize; block++)
            {
                for (int position = 0; position < blockSize; position++)
                {
                    var gene = genes.Genes[blockSize * block + position];
                    if (position == relPos)
                    {
                        gene += modification;
                    }
                    genes.Genes[blockSize * block + position] = gene;
                }
            }

            return(genes);
        }
Exemplo n.º 4
0
        private void CreateIslands(PeaSettings settings)
        {
            var key          = new string[settings.SubProblemList.Count];
            var parameterSet = new ParameterSet();

            parameterSet.SetValueRange(settings.ParameterSet);
            for (int i = 0; i < settings.SubProblemList.Count; i++)
            {
                key[i] = settings.SubProblemList[i].Encoding.Key;
                parameterSet.SetValueRange(settings.SubProblemList[i].ParameterSet);
            }

            var random = (IRandom)Activator.CreateInstance(Settings.Random, settings.Seed);

            //foreach (var subProblem in settings.SubProblemList)
            //{
            //    string key = subProblem.Encoding.Key;
            //var parameterSet = new ParameterSet(subProblem.ParameterSet);

            int islandsCount = parameterSet.GetInt(ParameterNames.IslandsCount);

            Islands = new List <IActorRef>(islandsCount);
            for (int i = 0; i < islandsCount; i++)
            {
                int seed = random.GetInt(0, Int32.MaxValue);

                var islandSettings = settings.GetIslandSettings(new MultiKey(key));
                var islandProps    = IslandActor.CreateProps(islandSettings, seed);
                var actorRef       = Context.ActorOf(islandProps);
                Islands.Add(actorRef);
                IslandsCount++;
            }
            //}
        }
Exemplo n.º 5
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            int blockSize   = ParameterSet.GetInt(ParameterNames.BlockSize);
            int blocksCount = length / blockSize;

            var block = Random.GetInt(0, blocksCount);

            for (int pos = 0; pos < blockSize; pos++)
            {
                double minValue = double.MaxValue;
                double maxValue = double.MinValue;

                for (int b = 0; b < blocksCount; b++)
                {
                    var gene = genes.Genes[b * blockSize + pos];
                    if (gene < minValue)
                    {
                        minValue = gene;
                    }
                    if (gene > maxValue)
                    {
                        maxValue = gene;
                    }
                }

                var newValue = Random.GetDouble(minValue, maxValue);
                genes.Genes[block * blockSize + pos] = newValue;
            }
            return(chromosome);
        }
Exemplo n.º 6
0
        public override SortedSubsetChromosome Mutate(SortedSubsetChromosome chromosome)
        {
            if (chromosome == null)
            {
                return(null);
            }
            if (chromosome.Sections.Length < 2)
            {
                return(null);
            }

            bool childConflicted = false;
            int  retryCount      = ParameterSet.GetInt(ParameterNames.FailedMutationRetryCount);

            while (true)
            {
                var range1           = GetSourceRange(chromosome);
                var section1         = chromosome.Sections[range1.Section];
                var sourceGeneValue1 = section1[range1.FirstPosition];
                var sourceGeneValue2 = section1[range1.LastPosition - 1];

                var targetSectionIndex = Random.GetIntWithTabu(0, chromosome.Sections.Length, range1.Section);
                var section2           = chromosome.Sections[targetSectionIndex];
                var targetPosition1    = FindNewGenePosition(section2, sourceGeneValue1);
                var targetPosition2    = FindNewGenePosition(section2, sourceGeneValue2);
                var range2             = new GeneRange(targetSectionIndex, targetPosition1, targetPosition2);

                var temp1 = MergeSections(section1, range1, section2, range2, ref childConflicted);
                var temp2 = MergeSections(section2, range2, section1, range1, ref childConflicted);

                if (!childConflicted)
                {
                    chromosome.Sections[range1.Section] = temp1;
                    chromosome.Sections[range2.Section] = temp2;
                }

                if (!childConflicted || retryCount-- < 0)
                {
                    //TODO: Remove this (only for debugging purpose)
                    chromosome.GeneratedRandoms.Add(range1.Section);
                    chromosome.GeneratedRandoms.Add(range1.FirstPosition);
                    chromosome.GeneratedRandoms.Add(range1.LastPosition);
                    chromosome.GeneratedRandoms.Add(range2.Section);
                    chromosome.GeneratedRandoms.Add(range2.FirstPosition);
                    chromosome.GeneratedRandoms.Add(range2.LastPosition);

                    break;
                }

                childConflicted = false;
            }

            if (childConflicted)
            {
                return(null);
            }

            CleanOutSections(chromosome);
            return(chromosome);
        }
Exemplo n.º 7
0
        public override SortedSubsetChromosome Mutate(SortedSubsetChromosome chromosome)
        {
            if (chromosome == null)
            {
                return(null);
            }
            if (chromosome.Sections.Length < 2)
            {
                return(null);
            }

            int retryCount = ParameterSet.GetInt(ParameterNames.FailedMutationRetryCount);

            while (true)
            {
                var  source  = GetSourceSectionAndPosition(chromosome);
                bool success = ReplaceOneGeneToRandomSection(chromosome, source, retryCount);

                if (success || retryCount-- < 0)
                {
                    break;
                }
            }

            CleanOutSections(chromosome);
            return(chromosome);
        }
Exemplo n.º 8
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            int blockSize = ParameterSet.GetInt(ParameterNames.BlockSize);

            if (length / blockSize < 3)
            {
                return(genes);
            }

            var blockPosition1 = Random.GetInt(1, length / blockSize);
            var blockPosition2 = Random.GetIntWithTabu(1, length / blockSize, blockPosition1);

            var position1 = blockPosition1 * blockSize;
            var position2 = blockPosition2 * blockSize;

            for (int i = 0; i < blockSize; i++)
            {
                var value1 = genes.Genes[position1 + i];
                var value2 = genes.Genes[position2 + i];

                genes.Genes[position1 + i] = value2;
                genes.Genes[position2 + i] = value1;
            }

            return(chromosome);
        }
Exemplo n.º 9
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationProbability = ParameterSet.GetValue(ParameterNames.MutationProbability);
            var mutationIntensity   = ParameterSet.GetValue(ParameterNames.MutationIntensity);
            int blockSize           = ParameterSet.GetInt(ParameterNames.BlockSize);

            int    relPos       = Random.GetInt(0, blockSize);
            double modification = Random.GetGaussian(0, mutationIntensity);

            for (int block = 0; block < length / blockSize; block++)
            {
                var rnd = Random.GetDouble(0, 1);
                if (rnd < mutationProbability)
                {
                    var position = blockSize * block + relPos;
                    var gene     = genes.Genes[position];
                    gene += modification;
                    genes.Genes[position] = gene;
                }
            }

            return(genes);
        }
Exemplo n.º 10
0
        public IList <IChromosome> Cross(IChromosome iparent0, IChromosome iparent1)
        {
            var children = new List <IChromosome>();

            var parent0 = iparent0 as DoubleVectorChromosome;
            var parent1 = iparent1 as DoubleVectorChromosome;
            var length  = parent0.Genes.Length;

            int retryCount = ParameterSet.GetInt(ParameterNames.FailedCrossoverRetryCount);
            int blockSize  = ParameterSet.GetInt(ParameterNames.BlockSize);

            if (length / blockSize < 3)
            {
                return(children);
            }

            double[] child0 = new double[length];
            double[] child1 = new double[length];

            bool child0Conflicted = false;
            bool child1Conflicted = false;

            while (true)
            {
                var blockPosition1 = Random.GetInt(1, length / blockSize);
                var blockPosition2 = Random.GetIntWithTabu(1, length / blockSize, blockPosition1);

                var crossoverPosition1 = blockPosition1 * blockSize;
                var crossoverPosition2 = blockPosition2 * blockSize;

                SwapPositions(ref crossoverPosition1, ref crossoverPosition2);

                child0 = MergeGenes(parent0.Genes, parent1.Genes, crossoverPosition1, crossoverPosition2, ref child0Conflicted);
                child1 = MergeGenes(parent1.Genes, parent0.Genes, crossoverPosition1, crossoverPosition2, ref child1Conflicted);

                if (!child0Conflicted || !child1Conflicted)
                {
                    break;
                }
            }

            if (!child0Conflicted)
            {
                var child0Chromosome = new DoubleVectorChromosome(child0);
                children.Add(child0Chromosome);
            }

            if (!child1Conflicted)
            {
                var child1Chromosome = new DoubleVectorChromosome(child1);
                children.Add(child1Chromosome);
            }

            return(children);
        }
Exemplo n.º 11
0
        public override SortedSubsetChromosome Mutate(SortedSubsetChromosome chromosome)
        {
            if (chromosome == null)
            {
                return(null);
            }
            if (chromosome.Sections.Length < 2)
            {
                return(null);
            }

            int retryCount = ParameterSet.GetInt(ParameterNames.FailedMutationRetryCount);

            while (true)
            {
                var source   = GetSourceSectionAndPosition(chromosome);
                var section  = chromosome.Sections[source.Section];
                var position = source.Position;

                var length = Random.GetInt(0, section.Length - source.Position);

                var targetSectionIndex = Random.GetIntWithTabu(0, chromosome.Sections.Length, source.Section);
                var targetSection      = chromosome.Sections[targetSectionIndex];

                while (position < source.Position + length)
                {
                    var geneValue      = section[position];
                    var targetPosition = FindNewGenePosition(targetSection, geneValue);
                    var insertable     = CountInsertableGenes(chromosome, targetSectionIndex, targetPosition, section, position);

                    bool conflict = ConflictDetectedWithLeftNeighbor(targetSection, targetPosition, geneValue);
                    if (!conflict)
                    {
                        var lastGeneValue = section[position + insertable - 1];
                        conflict = ConflictDetectedWithRightNeighbor(targetSection, targetPosition, lastGeneValue);
                    }

                    if (conflict)
                    {
                        break;
                    }

                    InsertGenes(chromosome, targetSectionIndex, targetPosition, section, position, insertable);
                    position += insertable;
                }

                if (position > source.Position || retryCount-- < 0)
                {
                    break;
                }
            }

            CleanOutSections(chromosome);
            return(chromosome);
        }
        /// <summary>
        /// Read trigger specific parameters from the world parm and add them to the actor parm
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public static new void ParseParmSet(ref ParameterSet actorParm, ref ParameterSet worldParm)
        {
            System.Diagnostics.Debug.Assert(worldParm.HasParm("InputAction"), "HealthTriggerVolume requires an input action!");
            actorParm.AddParm("InputAction", worldParm.GetString("InputAction"));

            if (worldParm.HasParm("KillOnButtonPush"))
                actorParm.AddParm("KillOnButtonPush", worldParm.GetBool("KillOnButtonPush"));

            if (worldParm.HasParm("Heal"))
                actorParm.AddParm("Heal", worldParm.GetInt("Heal"));
        }
Exemplo n.º 13
0
        public EvaluationSupervisorActor(MultiKey islandKey, Type evaluatorType, ParameterSet parameters)
        {
            IslandKey     = islandKey;
            EvaluatorType = evaluatorType;
            Parameters    = parameters;

            var props           = EvaluationWorkerActor.CreateProps(IslandKey, EvaluatorType, Parameters);
            var evaluatorsCount = Parameters.GetInt(ParameterNames.EvaluatorsCount);

            EvaluationWorkers = CreateWorkers(props, evaluatorsCount);

            var paths       = EvaluationWorkers.Select(w => w.Path.ToString());
            var routerProps = Props.Empty.WithRouter(new RoundRobinGroup(paths));

            EvaluationRouter = Context.ActorOf(routerProps, "Evaluators");

            Become(Idle);
        }
Exemplo n.º 14
0
        public IChromosome Mutate(IChromosome chromosome)
        {
            var genes  = chromosome as DoubleVectorChromosome;
            var length = genes.Genes.Length;

            var mutationIntensity = ParameterSet.GetValue(ParameterNames.MutationIntensity);
            int blockSize         = ParameterSet.GetInt(ParameterNames.BlockSize);

            var block = Random.GetInt(0, length / blockSize);

            for (int position = block * blockSize; position < (block + 1) * blockSize - 1; position++)
            {
                var oldValue = genes.Genes[position];
                var newValue = Random.GetGaussian(oldValue, mutationIntensity);

                genes.Genes[position] = newValue;
            }
            return(chromosome);
        }
Exemplo n.º 15
0
        public IList <IChromosome> Cross(IChromosome cparent0, IChromosome cparent1)
        {
            var children = new List <IChromosome>();

            var parent0 = cparent0 as DoubleVectorChromosome;
            var parent1 = cparent1 as DoubleVectorChromosome;
            var length  = parent0.Genes.Length;

            double[] child0 = new double[length];
            double[] child1 = new double[length];

            bool child0Conflicted = false;
            bool child1Conflicted = false;

            int retryCount = ParameterSet.GetInt(ParameterNames.FailedCrossoverRetryCount);

            while (true)
            {
                double weight = Random.GetDouble(0, 1);

                child0 = MergeGenes(parent0.Genes, parent1.Genes, weight);
                child1 = MergeGenes(parent1.Genes, parent0.Genes, weight);

                if (!child0Conflicted || !child1Conflicted)
                {
                    break;
                }
            }

            if (!child0Conflicted)
            {
                var child0Chromosome = new DoubleVectorChromosome(child0);
                children.Add(child0Chromosome);
            }

            if (!child1Conflicted)
            {
                var child1Chromosome = new DoubleVectorChromosome(child1);
                children.Add(child1Chromosome);
            }

            return(children);
        }
Exemplo n.º 16
0
        public override SortedSubsetChromosome Mutate(SortedSubsetChromosome chromosome)
        {
            if (chromosome == null)
            {
                return(null);
            }

            var numberOfGenesToReplace = GetNumberOfGenesToChange(chromosome);

            int retryCount = ParameterSet.GetInt(ParameterNames.FailedMutationRetryCount);
            int replaced   = 0;

            var targetList = new LinkedList <int>();

            for (int i = 0; i < numberOfGenesToReplace; i++)
            {
                var tryCount = retryCount;

                while (true)
                {
                    GenePosition source    = GetSourceSectionAndPosition(chromosome);
                    var          geneValue = chromosome.Sections[source.Section][source.Position];
                    var          success   = InsertGeneToLinkedList(targetList, geneValue);
                    if (success)
                    {
                        DeleteGenesFromSection(chromosome, source.Section, source.Position, 1);
                        replaced++;
                    }

                    if (success || tryCount-- < 0)
                    {
                        break;
                    }
                }
            }

            IncrementNumberOfSections(chromosome, targetList);

            CleanOutSections(chromosome);

            return(chromosome);
        }
        /// <summary>
        /// Read trigger specific parameters from the world parm and add them to the actor parm
        /// </summary>
        /// <param name="parm"></param>
        /// <returns></returns>
        public static new void ParseParmSet(ref ParameterSet actorParm, ref ParameterSet worldParm)
        {
            if (worldParm.HasParm("Count"))
                actorParm.AddParm("Count", worldParm.GetInt("Count"));
            if (worldParm.HasParm("Freq"))
                actorParm.AddParm("Freq", worldParm.GetFloat("Freq"));
            if (worldParm.HasParm("SpawnInWaves"))
                actorParm.AddParm("SpawnInWaves", worldParm.GetBool("SpawnInWaves"));
            if (worldParm.HasParm("DelayForFirst"))
                actorParm.AddParm("DelayForFirst", worldParm.GetFloat("DelayForFirst"));
            if (worldParm.HasParm("ConstantSpawns"))
                actorParm.AddParm("ConstantSpawns", worldParm.GetBool("ConstantSpawns"));
            if (worldParm.HasParm("EnemyList"))
                actorParm.AddParm("EnemyList", worldParm.GetBool("EnemyList"));

            System.Diagnostics.Debug.Assert(worldParm.HasParm("ActorType"), "SpawnActorTriggerVolume requires an actor type to spawn!");
            actorParm.AddParm("ActorType", worldParm.GetString("ActorType"));

            System.Diagnostics.Debug.Assert(worldParm.HasParm("SpawnPos"), "SpawnActorTriggerVolume requires a position to spawn at!");
            actorParm.AddParm("SpawnPos", worldParm.GetString("SpawnPos"));
        }
Exemplo n.º 18
0
        public override void ConvertTo(EnemyType e, ref ParameterSet parm)
        {
            if ((e != EnemyType.Ranged && e != EnemyType.RangedPogo) || e == type)
                return;

            bloodOnDamage = true;
            if (parm.HasParm("Speed"))
                speed = parm.GetFloat("Speed");
            if (parm.HasParm("AttackDamage"))
                attackDmg = parm.GetFloat("AttackDamage");
            if (parm.HasParm("AttackRange"))
                attackRange = (float)Math.Pow(parm.GetFloat("AttackRange"), 2);
            if (parm.HasParm("PercAnimationBeforeAttack"))
                percAnimBeforeAttack = parm.GetFloat("PercAnimationBeforeAttack");
            if (parm.HasParm("TimeForAttack"))
                attackTime = parm.GetFloat("TimeForAttack");

            pointsForKilling = 50;
            if (parm.HasParm("PointsForKilling"))
                pointsForKilling = parm.GetInt("PointsForKilling");
            spawnerIndex = -1;

            if (Stage.ActiveStage.Parm.HasParm("AIRangedSpeedScalar"))
                speed *= Stage.ActiveStage.Parm.GetFloat("AIRangedSpeedScalar");

            if (Stage.ActiveStage.Parm.HasParm("AIRangedDamageScalar"))
                attackDmg *= Stage.ActiveStage.Parm.GetFloat("AIRangedDamageScalar");

            missileOffset = Vector2.Zero;

            if (actor.Parm.HasParm("MissileOffset"))
                missileOffset = actor.Parm.GetVector2("MissileOffset");

            timeForPogoSkip = .1f;
            percAnimForSplat = .45f;
            maxRocketJumps = minRocketJumps = minRocketAttacks = maxRocketAttacks = 0;

            if (parm.HasParm("MaxJumps"))
                maxRocketJumps = parm.GetInt("MaxJumps");
            if (parm.HasParm("MinJumps"))
                minRocketJumps = parm.GetInt("MinJumps");
            if (parm.HasParm("MaxAttacks"))
                maxRocketAttacks = parm.GetInt("MaxAttacks");
            if (parm.HasParm("MinAttacks"))
                minRocketAttacks = parm.GetInt("MinAttacks");
            if (parm.HasParm("PogoStartTime"))
                pogoStartTime = parm.GetFloat("PogoStartTime");

            jumpSpeed = 22;

            if (actor.PhysicsObject.physicsType == PhysicsObject.PhysicsType.CylinderCharacter)
            {
                actor.PhysicsObject.CylinderCharController.HorizontalMotionConstraint.Speed = speed;
                actor.PhysicsObject.CollisionInformation.CollisionRules.Group = PhysicsQB.normalAIGroup;
            }

            actor.GetAgent<HealthAgent>().Convert(ref parm);

            shouldAttack = true;
            target = PlayerAgent.Player;
            state = AIState.Moving;
            FaceTargetSnappedToPlane();
            type = e;
        }
Exemplo n.º 19
0
        public override void ConvertTo(EnemyType e, ref ParameterSet parm)
        {
            //we can't return if we are a weak shielded cause we have to do models swaps and such.
            if ((e != EnemyType.Weak && e != EnemyType.WeakShielded) || e == type && type == EnemyType.Weak)
                return;

            /*actor.modelInstance.Shown = false;
            if (e == EnemyType.Weak)
            {
                actor.modelInstance = weakModel;
                enemyAnimationAgent.Animations = weakAnims;
            }
            else
            {
                actor.modelInstance = shieldModel;
                enemyAnimationAgent.Animations = shieldAnims;
            }
            actor.modelInstance.Shown = true;*/

            bloodOnDamage = true;
            if (parm.HasParm("Speed"))
                speed = parm.GetFloat("Speed");
            if (parm.HasParm("AttackDamage"))
                attackDmg = parm.GetFloat("AttackDamage");
            if (parm.HasParm("AttackRange"))
                attackRange = (float)Math.Pow(parm.GetFloat("AttackRange"), 2);
            if (parm.HasParm("PercAnimationBeforeAttack"))
                percAnimBeforeAttack = parm.GetFloat("PercAnimationBeforeAttack");
            if (parm.HasParm("TimeForAttack"))
                attackTime = parm.GetFloat("TimeForAttack");

            pointsForKilling = 50;
            if (parm.HasParm("PointsForKilling"))
                pointsForKilling = parm.GetInt("PointsForKilling");
            spawnerIndex = -1;

            if (Stage.ActiveStage.Parm.HasParm("AIWeakSpeedScalar"))
                speed *= Stage.ActiveStage.Parm.GetFloat("AIWeakSpeedScalar");

            if (Stage.ActiveStage.Parm.HasParm("AIWeakDamageScalar"))
                attackDmg *= Stage.ActiveStage.Parm.GetFloat("AIWeakDamageScalar");

            jumpSpeed = 10;

            if (actor.PhysicsObject.physicsType == PhysicsObject.PhysicsType.CylinderCharacter)
            {
                actor.PhysicsObject.CylinderCharController.HorizontalMotionConstraint.Speed = speed;
                actor.PhysicsObject.CollisionInformation.CollisionRules.Group = PhysicsQB.normalAIGroup;
            }

            if (parm.HasParm("EdgeDistWhileRunning"))
                wallOffset = parm.GetFloat("EdgeDistWhileRunning");

            actor.GetAgent<HealthAgent>().Convert(ref parm);

            shouldAttack = true;
            disarmed = false;
            target = PlayerAgent.Player;
            state = AIState.Moving;
            FaceTargetSnappedToPlane();
            type = e;
        }
Exemplo n.º 20
0
        public override IList <IChromosome> Cross(IChromosome iparent0, IChromosome iparent1)
        {
            var children = new List <IChromosome>();

            var parent1 = iparent0 as SortedSubsetChromosome;
            var parent2 = iparent1 as SortedSubsetChromosome;

            var sectionsCount = parent1.Sections.Length > parent2.Sections.Length
                ? parent1.Sections.Length
                : parent2.Sections.Length;

            var totalCount = parent1.TotalCount > parent2.TotalCount
                ? parent1.TotalCount
                : parent2.TotalCount;

            var  child0           = new int[sectionsCount][];
            var  child1           = new int[sectionsCount][];
            bool child0Conflicted = false;
            bool child1Conflicted = false;

            int retryCount = ParameterSet.GetInt(ParameterNames.FailedCrossoverRetryCount);

            while (true)
            {
                var crossoverPosition = Random.GetInt(0, totalCount);

                for (int sectionIndex = 0; sectionIndex < sectionsCount; sectionIndex++)
                {
                    bool section0Exists = (parent1.Sections.Length > sectionIndex);
                    var  section0       = section0Exists ? parent1.Sections[sectionIndex] : new int[0];
                    var  position0      = section0Exists ? FindNewGenePosition(section0, crossoverPosition) : 0;

                    bool section1Exists = (parent2.Sections.Length > sectionIndex);
                    var  section1       = section1Exists ? parent2.Sections[sectionIndex] : new int[0];
                    var  position1      = section1Exists ? FindNewGenePosition(section1, crossoverPosition) : 0;

                    var child0Section = MergeSections(section0, position0, section1, position1, ref child0Conflicted);
                    child0[sectionIndex] = child0Section;

                    var child1Section = MergeSections(section1, position1, section0, position0, ref child1Conflicted);
                    child1[sectionIndex] = child1Section;

                    //TODO: Merge conflict lists

                    if (child0Conflicted && child1Conflicted)
                    {
                        break;
                    }
                }

                if (!child0Conflicted || !child1Conflicted)
                {
                    ////TODO: Delete this
                    //var conflictedPositions0 =
                    //    child0Conflicted ? new List<GenePosition>() : SortedSubsetChromosomeValidator.SearchForConflict(child0);
                    //var conflictedPositions1 =
                    //    child1Conflicted ? new List<GenePosition>() : SortedSubsetChromosomeValidator.SearchForConflict(child1);

                    //if (conflictedPositions0.Count > 0 || conflictedPositions1.Count > 0)
                    //{
                    //    bool error = true;  //For breakpoints
                    //    throw new ApplicationException("Conflict between neighboring values! (Crossover: OnePointCrossover)");
                    //}

                    break;
                }

                if (retryCount-- < 0)
                {
                    break;
                }

                child0           = new int[sectionsCount][];
                child1           = new int[sectionsCount][];
                child0Conflicted = false;
                child1Conflicted = false;
            }

            if (!child0Conflicted)
            {
                var child0Chromosome = new SortedSubsetChromosome(child0);
                CleanOutSections(child0Chromosome);
                children.Add(child0Chromosome);
            }

            if (!child1Conflicted)
            {
                var child1Chromosome = new SortedSubsetChromosome(child1);
                CleanOutSections(child1Chromosome);
                children.Add(child1Chromosome);
            }

            return(children);
        }
Exemplo n.º 21
0
        public void Convert(ref ParameterSet parm)
        {
            if (parm.HasParm("Health"))
                startingHealth = this.health = parm.GetFloat("Health");

            switch (actor.Name)
            {
                case "EnemyWeak":
                    if (Stage.ActiveStage.Parm.HasParm("AIWeakHealthScalar"))
                        health *= Stage.ActiveStage.Parm.GetFloat("AIWeakHealthScalar");
                    break;
                case "EnemyRanged":
                    if (Stage.ActiveStage.Parm.HasParm("AIRangedHealthScalar"))
                        health *= Stage.ActiveStage.Parm.GetFloat("AIRangedHealthScalar");
                    break;
                case "EnemyHeavy":
                    if (Stage.ActiveStage.Parm.HasParm("AIHeavyHealthScalar"))
                        health *= Stage.ActiveStage.Parm.GetFloat("AIHeavyHealthScalar");
                    break;
            }

            infiniteHealth = false;
            startsWithShield = shielded = false;
            percDamageAbsorbedByShield = 0;
            numHitsForDisarm = 0;
            if (parm.HasParm("InfiniteHealth"))
                infiniteHealth = parm.GetBool("InfiniteHealth");
            if (parm.HasParm("Shielded"))
                startsWithShield = this.shielded = parm.GetBool("Shielded");
            if (parm.HasParm("ShieldDmgAbsorbPerc"))
                this.percDamageAbsorbedByShield = parm.GetFloat("ShieldDmgAbsorbPerc");
            if (parm.HasParm("ShutdownInsteadOfKill"))
                shutdownInsteadOfKill = parm.GetBool("ShutdownInsteadOfKill");
            if (parm.HasParm("NumHitsForDisarm"))
                numHitsForDisarm = startingHitsForDisarm = parm.GetInt("NumHitsForDisarm");
        }
Exemplo n.º 22
0
        //note if we keep the base values the same, a lot of this code can be removed
        public override void ConvertTo(EnemyType e, ref ParameterSet parm)
        {
            if ((e != EnemyType.Heavy && e != EnemyType.HeavyAOE) || e == type)
                return;

            bloodOnDamage = true;
            if (parm.HasParm("Speed"))
                speed = parm.GetFloat("Speed");
            if (parm.HasParm("AttackDamage"))
                attackDmg = parm.GetFloat("AttackDamage");
            if (parm.HasParm("AttackRange"))
                attackRange = (float)Math.Pow(parm.GetFloat("AttackRange"), 2);
            if (parm.HasParm("PercAnimationBeforeAttack"))
                percAnimBeforeAttack = parm.GetFloat("PercAnimationBeforeAttack");
            if (parm.HasParm("TimeForAttack"))
                attackTime = parm.GetFloat("TimeForAttack");

            pointsForKilling = 50;
            if (parm.HasParm("PointsForKilling"))
                pointsForKilling = parm.GetInt("PointsForKilling");
            spawnerIndex = -1;

            if (Stage.ActiveStage.Parm.HasParm("AIHeavySpeedScalar"))
                speed *= Stage.ActiveStage.Parm.GetFloat("AIHeavySpeedScalar");

            if (Stage.ActiveStage.Parm.HasParm("AIHeavyDamageScalar"))
            {
                float increase = Stage.ActiveStage.Parm.GetFloat("AIHeavyDamageScalar");
                attackDmg *= increase;
                attackSpecialDmg *= increase;
            }

            //look for more parms here
            if (parm.HasParm("TurnSpeed"))
                turnSpeed = parm.GetFloat("TurnSpeed");
            if (parm.HasParm("TimeForAttackSpecial"))
                timeForAttackSpecial = parm.GetInt("TimeForAttackSpecial");
            if (parm.HasParm("PercAnimationBeforeAttackRight"))
                percAnimBeforeAttackRight = parm.GetFloat("PercAnimationBeforeAttackRight");
            if (parm.HasParm("PercAnimationBeforeAttackSpecial"))
                percAnimBeforeAttackSpecial = parm.GetFloat("PercAnimationBeforeAttackSpecial");
            if (parm.HasParm("AttackSpecialDamage"))
                attackSpecialDmg = parm.GetFloat("AttackSpecialDamage");
            if (parm.HasParm("MinPunches"))
                minPunches = parm.GetInt("MinPunches");
            if (parm.HasParm("MaxPunches"))
                maxPunches = parm.GetInt("MaxPunches");
            if (parm.HasParm("SlamAttackForce"))
                attackForce = parm.GetFloat("SlamAttackForce");
            if (parm.HasParm("EndWithSlam"))
                shouldSlam = parm.GetBool("EndWithSlam");

            jumpSpeed = 10;

            if (actor.PhysicsObject.physicsType == PhysicsObject.PhysicsType.CylinderCharacter)
            {
                actor.PhysicsObject.CylinderCharController.HorizontalMotionConstraint.Speed = speed;
                actor.PhysicsObject.CollisionInformation.CollisionRules.Group = PhysicsQB.heavyAIGroup;
            }

            actor.GetAgent<HealthAgent>().Convert(ref parm);

            shouldAttack = true;
            target = PlayerAgent.Player;
            state = AIState.Moving;
            FaceTargetSnappedToPlane();
            type = e;
        }
Exemplo n.º 23
0
        public override SortedSubsetChromosome Mutate(SortedSubsetChromosome chromosome)
        {
            if (chromosome == null)
            {
                return(null);
            }
            if (chromosome.Sections.Length < 3)
            {
                return(null);
            }

            bool childConflicted = false;
            int  retryCount      = ParameterSet.GetInt(ParameterNames.FailedMutationRetryCount);

            while (true)
            {
                var firstRange      = GetSourceRange(chromosome);
                var firstSection    = chromosome.Sections[firstRange.Section];
                var firstGeneValue1 = firstSection[firstRange.FirstPosition];
                var firstGeneValue2 = firstSection[firstRange.LastPosition - 1];

                var secondSectionIndex = Random.GetIntWithTabu(0, chromosome.Sections.Length, firstRange.Section);
                var secondSection      = chromosome.Sections[secondSectionIndex];
                var secondPosition1    = FindNewGenePosition(secondSection, firstGeneValue1);
                var secondPosition2    = FindNewGenePosition(secondSection, firstGeneValue2);
                var secondRange        = new GeneRange(secondSectionIndex, secondPosition1, secondPosition2);

                if (secondRange.Length == 0)
                {
                    childConflicted = true;
                }

                if (!childConflicted)
                {
                    var secondGeneValue1 = secondSection[secondRange.FirstPosition];
                    var secondGeneValue2 = secondSection[secondRange.LastPosition - 1];

                    var thirdSectionIndex = Random.GetIntWithTabu(0, chromosome.Sections.Length, firstRange.Section,
                                                                  secondRange.Section);
                    var thirdSection   = chromosome.Sections[thirdSectionIndex];
                    var thirdPosition1 = FindNewGenePosition(thirdSection, secondGeneValue1);
                    var thirdPosition2 = FindNewGenePosition(thirdSection, secondGeneValue2);
                    var thirdRange     = new GeneRange(thirdSectionIndex, thirdPosition1, thirdPosition2);

                    var temp1 = MergeSections(firstSection, firstRange, secondSection, secondRange,
                                              ref childConflicted);
                    var temp2 = MergeSections(secondSection, secondRange, thirdSection, thirdRange,
                                              ref childConflicted);
                    var temp3 = MergeSections(thirdSection, thirdRange, firstSection, firstRange, ref childConflicted);

                    if (!childConflicted)
                    {
                        chromosome.Sections[firstRange.Section]  = temp1;
                        chromosome.Sections[secondRange.Section] = temp2;
                        chromosome.Sections[thirdRange.Section]  = temp3;
                    }
                }

                if (!childConflicted || retryCount-- < 0)
                {
                    break;
                }

                childConflicted = false;
            }

            if (childConflicted)
            {
                return(null);
            }

            CleanOutSections(chromosome);
            return(chromosome);
        }