/// <summary> /// Gets called by the <see cref="GeneticSharp"/> library when a mutation of a solution candidate is performed. /// Consists of two mutation operators <see cref="MutateByOne(IChromosome)"/> & <see cref="MutateByCharacterFlip(IChromosome)"/> /// </summary> /// <param name="chromosome">The solution candidate to mutate.</param> /// <param name="probability">The probability of a mutation.</param> protected override void PerformMutate(IChromosome chromosome, float probability) { var genesLength = chromosome.Length; if (m_rnd.GetDouble() <= probability) { MutateByOne(chromosome); } if (m_rnd.GetDouble() <= probability) { MutateByCharacterFlip(chromosome); } }
/// <summary> /// Generates encounter elements for a specified encounter. /// </summary> /// <param name="encounter">The encounter.</param> /// <returns>IEnumerable<EncounterElement>.</returns> public IEnumerable <EncounterElement> GenerateElementsForEncounter(EncounterData encounter, IRandomization randomization) { var elements = new List <EncounterElement>(); foreach (var contentElement in encounter.Entities) { decimal chance = contentElement.Chance; if (chance < 1.0m && chance < (decimal)randomization.GetDouble()) { continue; } // Some encounters can have varying quantities of actors in them. var quantity = GetEntityQuantity(randomization, contentElement); // Generate the required number of entries for (int i = 0; i < quantity; i++) { elements.Add(new EncounterElement { ObjectType = GameObjectType.Actor, ObjectId = contentElement.Id }); } } return(elements); }
protected override void PerformMutate(IChromosome chromosome, float probability) { try { CPChromosome cpChromosome = chromosome as CPChromosome; double rand = m_rnd.GetDouble(); if (!(rand <= probability)) { return; } int[] genes = cpChromosome.GetValues(); Graph graph = GraphProvider.Graph; foreach (int vertex in graph.Vertexes) { IList <int> p = graph.NeighborsList(vertex); if (p.Any(z => genes[z - 1] == genes[vertex - 1])) { genes[vertex - 1] = m_rnd.GetInt(0, chromosome.Length); } } } catch (Exception ex) { Console.WriteLine(ex); } }
protected override void PerformMutate(IChromosome chromosome, float probability) { var genome = chromosome as ThermalGenome; if (_random.GetDouble() <= probability) { var index = _random.GetInt(0, chromosome.Length); var bound = genome.Bounds[index]; genome.ReplaceGene(index, new Gene(_random.GetInt(bound.Min, bound.Max + 1))); } }
protected override void PerformMutate(IChromosome chromosome, float probability) { var cpChromosome = chromosome as CPChromosome; if (m_rnd.GetDouble() <= probability) { var i = m_rnd.GetInt(0, chromosome.Length); var j = m_rnd.GetInt(0, chromosome.Length); var v1 = cpChromosome.GetGene(i); var v2 = cpChromosome.GetGene(j); cpChromosome.ReplaceGene(i, v2); cpChromosome.ReplaceGene(j, v1); } }
/// <summary> /// Mutate the specified chromosome. /// </summary> /// <param name="chromosome">The chromosome.</param> /// <param name="probability">The probability to mutate each chromosome.</param> protected override void PerformMutate(IChromosome chromosome, float probability) { var binaryChromosome = chromosome as IBinaryChromosome; if (binaryChromosome == null) { throw new MutationException(this, "Needs a binary chromosome that implements IBinaryChromosome."); } if (m_rnd.GetDouble() <= probability) { var index = m_rnd.GetInt(0, chromosome.Length); binaryChromosome.FlipGene(index); } }
private static int CalculateAttackStrength(GameObjectBase attacker, IRandomization random) { // Actors can attack anywhere from 100% - 150% their base strength return((int)Math.Round(attacker.EffectiveStrength * (decimal)random.GetDouble(1, 1.5))); }
private static int CalculateDefenseStrength(GameObjectBase defender, IRandomization random) { // Actors can defend anywhere from 100% - 250% their base strength return((int)Math.Round(defender.EffectiveDefense * (decimal)random.GetDouble(1, 2.5))); }