// Register all (const) factors in a provided repository public static void RegisterFactors( BrainRepository repo, Initializer initializer = null ) { foreach (Factor factor in Enum.GetValues(typeof(Factor))) { repo.RegisterTrait(new Trait(factor, initializer)); } }
public IList <Effect> ObservationEffects( InfluencedInteraction interaction, Character host, ICollection <IEntity> targets, BrainRepository repo ) { var effects = ChooseStronglyInfluencedEffects(repo, interaction, host); //TODO: Change selection via host/other methods; with the addtion of the //relationship module, this seems more reasonable return(effects); }
public IList <Effect> ReactionEffects( InfluencedInteraction i, Character host, // Unused BrainRepository repo ) { var effects = ChooseStronglyInfluencedEffects(repo, i, host); //TODO: Change selection via host/other methods; with the addtion of the //relationship module, this seems more reasonable return(effects); }
public float ComboScore( IEnumerable <State> state, Character host, InfluencedInteraction interaction, ICollection <IEntity> targets, BrainRepository repo ) { float score = 0f; int count = 0; foreach (State s in interaction.strongStateInfluences.Values) { State.TransformedInstance currState = host[s] as State.TransformedInstance; if (currState == null) { continue; } score = currState.TransformedState; foreach (State t in state) { if (t.Equals(s)) { score += .25f; } } count++; } if (count != 0) { score /= count; } //BehaviorEngine.Debug.Logger.Log("Calculated score"); score *= StabilityScore(state, host, interaction, targets, repo); return(score); }
private IList <Effect> ChooseStronglyInfluencedEffects( BrainRepository repo, InfluencedInteraction i, Character host ) { // Return value List <Effect> effects = new List <Effect>(); List <InfluencedEffect> unused = new List <InfluencedEffect>(); List <int> differentials = new List <int>(); var allEffects = new List <InfluencedEffect>(repo.Effects); // Guarantee that default Effect will be different every time Shuffle(allEffects); int position = 0, total = allEffects.Count; foreach (InfluencedEffect e in allEffects) { // Difference in influence (zero = the same) int differential = 0; List <float> traitValues = new List <float>(); List <float> stateValues = new List <float>(); foreach (var pair in i.strongTraitInfluences) { if (!e.strongTraitInfluences.ContainsKey(pair.Key)) { differential++; } else { foreach (var instance in host.GetAttributeInstances()) { if (instance.Prototype.Equals(pair.Value)) { var val = instance as Trait.TransformedInstance; traitValues.Add(val.TransformedState); } } } } foreach (var pair in i.strongStateInfluences) { if (!e.strongStateInfluences.ContainsKey(pair.Key)) { differential++; } else { foreach (var instance in host.GetAttributeInstances()) { if (instance.Prototype.Equals(pair.Value)) { var val = instance as State.TransformedInstance; stateValues.Add(val.TransformedState); } } } } if (differential == 0) { bool chosen = false; float accumulatorVal = 0f; float modTotal = 0f; int numTraits = 0; foreach (var m in e.Modifiers) { var f = m as FloatModifier; float valCalc = 0f; foreach (var traitVal in traitValues) { foreach (var stateVal in stateValues) { valCalc += stateVal; } numTraits++; } valCalc /= numTraits; accumulatorVal += valCalc; modTotal += f.offset; } accumulatorVal /= e.Modifiers.Count; modTotal /= e.Modifiers.Count; chosen = (accumulatorVal < LOW_STABILITY && modTotal > 0 && modTotal < MOD_OFFSET_LOW) || (accumulatorVal > LOW_STABILITY && accumulatorVal < MIDPOINT && modTotal >= MOD_OFFSET_LOW) || (accumulatorVal > MIDPOINT && accumulatorVal < HI_STABILITY && modTotal <0f && modTotal> -MOD_OFFSET_LOW) || (accumulatorVal > HI_STABILITY && modTotal <= -MOD_OFFSET_LOW); if (chosen) { effects.Add(e); } else { //TODO: Effect is not chosen; perhaps could be a useful point. } } else { unused.Add(e); differentials.Add(differential); } position++; } /* * while(effects.Count == 0) { * Shuffle(unused); * int index = 0; * double chanceTotal = (differentials[index] * total); * double toTheEnd = ((double)(total - position)) / chanceTotal; * double selectChance = random.NextDouble(); * * // the values are always guaranteed to be non-negative * if (selectChance > Math.Min(toTheEnd, effects.Count)) { * effects.Add(unused[index]); * } * index++; * } */ if (effects.Count != 1) { //TODO: Debug statement in case no effects or more than one //effect is chosen /*BehaviorEngine.Debug.Logger.Log( * "Number of effects chosen: " + effects.Count * ); */ } /* * if(effects.Count == 0) { * effects.Add(unused[0]); * } */ return(effects); }
private float StabilityScore( IEnumerable <State> state, Character host, InfluencedInteraction interaction, ICollection <IEntity> targets, BrainRepository repo ) { float ownScore = 0f; int count = 0; foreach (State s in state) { State.TransformedInstance currState = host[s] as State.TransformedInstance; ownScore += currState.TransformedState; count++; } ownScore /= count; float ease = .3f; if (ownScore < LOW_STABILITY) { ease = .5f; } else { if (ownScore > HI_STABILITY) { ease = .1f; } } var func = Transformations.EaseSquaredAtValue(ease); var effects = ChooseStronglyInfluencedEffects(repo, interaction, host); //List<FloatModifier> modifiers = new List<FloatModifier>(); float modifyVal = 0f; foreach (Effect e in effects) { float currMod = 0f; foreach (IModifier m in e.Modifiers) { FloatModifier floatMod = m as FloatModifier; currMod = Math.Abs(floatMod.offset); if (floatMod.Attribute.Equals(repo.GetState("anger"))) { } } if (e.Modifiers.Count != 0) { currMod /= e.Modifiers.Count; } modifyVal += currMod; } if (effects.Count != 0) { modifyVal /= effects.Count; } ownScore = func(modifyVal); if (targets == null) { //BehaviorEngine.Debug.Logger.Log("Score: " + ownScore); return(ownScore); } float otherScore = 0f; foreach (IEntity target in targets) { var attrs = target.GetAttributeInstances(); float stabilityValue = 0f; float weight = 1f; foreach (IAttributeInstance a in attrs) { NormalizedAttribute.Instance attr = a as NormalizedAttribute.Instance; stabilityValue += attr.State; } stabilityValue /= attrs.Count; weight = .3f; if (stabilityValue <= LOW_STABILITY) { weight = .5f; } else { weight = .1f; } var f = Transformations.EaseSquaredAtValue(weight); otherScore += f(modifyVal); // Attempt to bias interaction towards people that crew will vote for var crewmember = target as Character; var hostCrew = host as Crewmember; if (crewmember != null && hostCrew != null) { var chooseVote = hostCrew.ChooseVote(); //Will be null if relationship does not exist if (chooseVote != null) { if (hostCrew.ChooseVote().Equals(crewmember)) { otherScore *= 2; //Debug.Logger.Log("Doubled, found vote"); } } } } if (targets.Count != 0) { otherScore /= targets.Count; } float score = (ownScore + otherScore) / 2; //BehaviorEngine.Debug.Logger.Log("Score: " + score); return(score); }