void RefreshValuator() { try { CurrentValuator = new TraitValuator(this, comboBoxValuePreset.Text, context); } catch (Exception exception) { CurrentValuator = new TraitValuator(); logger.Error(exception, "TraitValuator creation failed for valuemapid: " + comboBoxValuePreset.Text + "; reverting to defaults"); } settings.ValuePresetId = CurrentValuator.ValueMapId; GrangerValuatorChanged?.Invoke(this, new EventArgs()); }
internal static string GetShortString(CreatureTrait[] traits, TraitValuator valuator) { List <string> shorts = new List <string>(); foreach (var trait in traits) { int value = 0; if (valuator != null) { value = valuator.GetValueForTrait(trait); } shorts.Add(Helper.GetShortcutForTrait(trait, value)); } return(string.Join(",", shorts.OrderBy(x => x))); }
private double EvaluatePotentialValue(Creature creature, TraitValuator valuator, CreatureTrait trait) { double result = 0; if (trait.IsUnknownForThisCreature(creature)) { var traitval = trait.GetTraitValue(valuator); if (traitval > 0) { result += traitval * options.PotentialValuePositiveWeight; } else if (traitval < 0) { result += traitval * options.PotentialValueNegativeWeight; } } return(result); }
public override BreedingEvalResults?Evaluate(Creature creature1, Creature creature2, TraitValuator valuator) { if (creature1 == creature2) { return(null); } BreedingEvalResults results = new BreedingEvalResults(); var allPossibleTraits = CreatureTrait.GetAllPossibleTraits(); var traits1 = creature1.Traits; var traits2 = creature2.Traits; var concatTraits = traits1.Concat <CreatureTrait>(traits2).ToArray(); var distinctConcatTraits = concatTraits.Distinct().ToArray(); if (creature1.IsMale == creature2.IsMale) { results.Ignored = true; } if (options.IgnoreNotInMood) { if (creature1.NotInMood || creature2.NotInMood) { results.Ignored = true; } } if (options.IgnorePregnant) { if (creature1.Pregnant || creature2.Pregnant) { results.Ignored = true; } } if (options.IgnoreRecentlyPregnant) { if (creature1.PregnantInLast24H || creature2.PregnantInLast24H) { results.Ignored = true; } } if (options.IgnoreOtherHerds) { if (creature1.Herd != creature2.Herd) { results.Ignored = true; } } if (options.IgnorePairedCreatures) { if (creature1.HasMate() || creature2.HasMate()) { results.Ignored = true; } } if (options.IgnoreSold) { if (creature1.CheckTag("sold") || creature2.CheckTag("sold")) { results.Ignored = true; } } if (options.IgnoreDead) { if (creature1.CheckTag("dead") || creature2.CheckTag("dead")) { results.Ignored = true; } } if (options.IgnoreFoals) { if ((creature1.IsFoal() && !options.AgeIgnoreOnlyOtherCreatures) || creature2.IsFoal()) { results.Ignored = true; } } if (options.IgnoreYoung) { if (((creature1.Age.CreatureAgeId == CreatureAgeId.Young) && !options.AgeIgnoreOnlyOtherCreatures) || creature2.Age.CreatureAgeId == CreatureAgeId.Young) { results.Ignored = true; } } if (options.IgnoreAdolescent) { if (((creature1.Age.CreatureAgeId == CreatureAgeId.Adolescent) && !options.AgeIgnoreOnlyOtherCreatures) || creature2.Age.CreatureAgeId == CreatureAgeId.Adolescent) { results.Ignored = true; } } if (options.ExcludeExactAgeEnabled) { if (DateTime.Now - creature1.BirthDate < options.ExcludeExactAgeValue || DateTime.Now - creature2.BirthDate < options.ExcludeExactAgeValue) { results.Ignored = true; } } if (creature1.IsInbreedWith(creature2)) { if (options.DiscardOnInbreeding) { results.Discarded = true; } else { var potentialBadTraits = CreatureTrait.GetInbreedBadTraits().Where(x => !distinctConcatTraits.Contains(x)).ToArray(); double sum = 0; foreach (var trait in potentialBadTraits) { sum += trait.GetTraitValue(valuator); } sum /= potentialBadTraits.Length; sum *= options.InbreedingPenaltyWeight * 2; results.Value += sum; } } if (options.DiscardOnAnyNegativeTraits) { if (creature2.Traits.Any(x => x.GetTraitValue(valuator) < 0)) { results.Discarded = true; } } if (results.Discarded != true && results.Ignored != true) { Dictionary <CreatureTrait, int> uniqueTraitCounter = new Dictionary <CreatureTrait, int>(); foreach (var trait in concatTraits) { if (uniqueTraitCounter.ContainsKey(trait)) { uniqueTraitCounter[trait] += 1; } else { uniqueTraitCounter[trait] = 1; } var traitval = trait.GetTraitValue(valuator); double result = 0; if (traitval < 0) { result += traitval * options.BadTraitWeight; } else if (traitval > 0) { result += traitval; } results.Value += result; } if (options.PreferUniqueTraits) { foreach (var keyval in uniqueTraitCounter) { if (keyval.Value == 1) { var traitval = keyval.Key.GetTraitValue(valuator); if (traitval > 0) { results.Value += (traitval * options.UniqueTraitWeight) - traitval; } } } } if (options.IncludePotentialValue) { foreach (var trait in allPossibleTraits) { double result = 0; result += EvaluatePotentialValue(creature1, valuator, trait); result += EvaluatePotentialValue(creature2, valuator, trait); results.Value += result; } } if (results.Value > 0) { var h1ColVal = options.GetValueForColor(creature1.Color); var h2ColVal = options.GetValueForColor(creature2.Color); var colValAdj = (h1ColVal + h2ColVal) * 0.5f; results.Value *= colValAdj; } } return(results); }
internal static CreatureTrait[] GetBadTraits(CreatureTrait[] traits, TraitValuator traitValuator) { return(traits.Where(x => x.GetTraitValue(traitValuator) < 0).ToArray()); }
/// <summary> /// Get value of this trait within given context. /// </summary> /// <param name="traitvaluator"></param> /// <returns></returns> public int GetTraitValue(TraitValuator traitvaluator) { return(traitvaluator.GetValueForTrait(this)); }
/// <summary> /// Calculates evaluation for this creature, /// null if evaluation does not return any valid results. /// </summary> /// <param name="creature1">First evaluated creature</param> /// <param name="creature2">Second evaluated creature</param> /// <param name="valuator">Trait values ruleset</param> public abstract BreedingEvalResults?Evaluate(Creature creature1, Creature creature2, TraitValuator valuator);
public override BreedingEvalResults?Evaluate(Creature creature1, Creature creature2, TraitValuator valuator) { return(null); }