Exemple #1
0
        // exclusive activities
        private bool Survives(out float fertility)
        {
            // Dorm, Day, Activity
            var repeats = new List <Tuple <byte, byte, byte> >();

            byte[] failures = new byte[7];

            foreach (var gene in Genes)
            {
                var dormInfo     = Constants.SURVIVAL_DORMINFO[gene[INDEX_DORM]];
                var activity     = gene[INDEX_ACTIVITY];
                var activityInfo = Constants.SURVIVAL_ACTIVITYINFO[activity];

                var otherDorm = gene[INDEX_OTHERDORM];
                if (otherDorm != 255)
                {
                    if (
                        !dormInfo.AllowedOtherDorms.Contains(otherDorm) ||
                        !activityInfo.MultiDorm.HasFlag(ActivityMultiDorm.Multi)
                        )
                    {
                        ++failures[0];
                    }

                    var otherDormInfo = Constants.SURVIVAL_DORMINFO[otherDorm];

                    if (
                        activityInfo.IsExclusive && (
                            !dormInfo.AllowedExclusives.Contains(activity) ||
                            !otherDormInfo.AllowedExclusives.Contains(activity)
                            )
                        )
                    {
                        ++failures[1];
                    }
                }
                else
                {
                    if (!activityInfo.MultiDorm.HasFlag(ActivityMultiDorm.Single))
                    {
                        ++failures[2];
                    }

                    if (activityInfo.IsExclusive && !dormInfo.AllowedExclusives.Contains(activity))
                    {
                        ++failures[3];
                    }
                }

                var foundRepeats = repeats.FindAll(r => r.Item1 == gene[INDEX_DORM] && r.Item3 == gene[INDEX_ACTIVITY]);
                if (foundRepeats.Any())
                {
                    if (!activityInfo.IsRepeatable)
                    {
                        failures[4] += (byte)foundRepeats.Count;
                    }
                    failures[5] += (byte)foundRepeats.Count(r => r.Item2 == gene[INDEX_DAY]);
                }

                if (activityInfo.LongerDuration)//&& isOddTime Constants.SURVIVAL_DAYINFO[gene[INDEX_DAY]].TailTimes.Contains(gene[INDEX_TIME]))
                {
                    ++failures[6];
                }
            }

            bool survives = !failures.Any(f => f != 0);

            if (!survives)
            {
                var boundedFailures = failures.Select(f => BoundedNumber.FromUnboundedNumber(f)).ToArray();
                fertility = (
                    BoundedHelpers.Blend(
                        BoundedHelpers.Blend(
                            boundedFailures[0] + boundedFailures[2],
                            boundedFailures[1] + boundedFailures[3],
                            0.667f
                            ),
                        boundedFailures[4] + boundedFailures[5],
                        0.667f
                        ) + boundedFailures[6]
                    ).Suppress();
            }
            else
            {
                fertility = -1f;
            }

            return(survives);
        }
        }                                                     // what they are saying about the target

        /// <summary>Change perceptions upon observing someone take an expressive action.</summary>
        /// <param name="perception">   Perception of the person executing the verb.
        /// </param>
        /// <returns>     MY reaction to EXECUTER doing VERB to TARGET.
        /// </returns>
        public Reaction ApplyToPerception(Perception perception, VerbTargetInfo targetInfo, float magnitude, byte verbNumTimes)
        {
            // pSelf
            // pTarget
            // pExecutor
            // pGlobal
            Perception[] traits = targetInfo.GetTraits();
            byte         globalPerceptionsIndex = (byte)(targetInfo.IsYou ? 2 : 3);
            byte         executorIndex          = (byte)(globalPerceptionsIndex - 1);

            var surprisePerceptions = targetInfo.UsingGlobalPerceptions ?
                                      traits[globalPerceptionsIndex] :
                                      traits[executorIndex];
            float verbProbability    = surprisePerceptions.TotalPerceptions / (float)verbNumTimes;
            float surpriseMultiplier = 0;

            if (verbProbability >= 0.5)
            {
                // surpriseMultiplier is 0
                return(null);
            }

            byte targetIndex = (byte)(globalPerceptionsIndex - 1);

            // assumes that one has complete self-awareness of Timid_Powerful
            var selfEsteem = traits[0];

            // for expressive assertions
            PersonalityTraits expressiveAgreement = traits[targetIndex] - PhysicalExpression;
            var          selfAgreement            = selfEsteem - Traits;
            TraitsVector reactionTraits           = expressiveAgreement.BlendToBounded(expressiveAgreement + selfAgreement, -targetInfo.KnowThemWell);

            var agreement             = (reactionTraits).SumToUBounded();
            var boundedAgreement      = (BoundedNumber)agreement;
            var agreementSignificance = boundedAgreement.Significance();

            if (agreementSignificance.Number * magnitude < VerbSelection.MINIMUM_VERB_SIGNIFICANCE)
            {
                return(null);
            }

            //var agreementInverted = boundedAgreement.UInvert();

            if (verbProbability <= 0.0042) // found by graphing multiplier formula on Desmos
            {
                surpriseMultiplier = 1;
            }
            else
            {
                float bitsOfInformation = (float)Math.Log(verbProbability, 2);
                surpriseMultiplier = ((float)Math.Sqrt(bitsOfInformation) - 1) * 0.55f;
            }

            // how much attention you pay
            var surpriseTraits = (surprisePerceptions - Traits);
            var surprise       = surpriseTraits.SumToUBounded();

            // if you are a good person, and perceive the person to be dishonest, it will change little
            // trust in yourself vs trust in the other person
            // your values are less assertive if you are more timid
            var trust = new BoundedNumber(new UBoundedNumber(selfEsteem.Bad_Good.WeightingFactor - traits[executorIndex].Bad_Good.WeightingFactor));

            // if you trust them more, disagreements are less of a shock
            surprise = agreement.Blend(surprise, trust);
            var scaledAssertions = PhysicalExpression * magnitude;

            if (perception.CircumferentialValues.TryGetValue(targetInfo.EntityID, out PersonalityTraits cValue))
            {
                if (targetInfo.AffectsTarget)
                {
                    cValue.AddVector(scaledAssertions);
                }
                else
                {
                    cValue = cValue + traits[targetIndex];
                }
            }
            else
            {
                if (targetInfo.AffectsTarget)
                {
                    perception.CircumferentialValues.Add(targetInfo.EntityID, scaledAssertions);
                }
                else
                {
                    perception.CircumferentialValues.Add(targetInfo.EntityID, ((TraitsVector)traits[targetIndex] + scaledAssertions));
                }
            }

            var          scaledTraits          = Traits * magnitude;
            TraitsVector oldExecutorPerception = traits[executorIndex];

            traits[executorIndex].Blend(oldExecutorPerception + scaledTraits, traits[globalPerceptionsIndex], true);
            TraitsVector oldTargetPerception = traits[targetIndex];

            var oldTrust = trust;

            // trusting their judgement on this issue
            trust = trust.Blend(
                boundedAgreement,
                selfEsteem.Timid_Powerful
                );

            //agreement = agreement.Suppress(1 - magnitude);
            // Do you react?
            var significance = surprise.Blend(agreementSignificance, selfEsteem.Timid_Powerful.WeightingFactor) * magnitude;

            if (targetInfo.IsYou)
            {
                if (targetInfo.AffectsTarget)
                {
                    significance = new UBoundedNumber(significance.Amplify(0.333f));
                }
                traits[targetIndex].Blend(oldTargetPerception + scaledAssertions, trust, true);
                if (significance.Number < 1 - selfEsteem.Timid_Powerful.WeightingFactor)
                {
                    return(null);
                }
            }
            else
            {
                traits[targetIndex].Blend(
                    oldTargetPerception + scaledAssertions,
                    traits[globalPerceptionsIndex] * trust,
                    true
                    );
                if (!targetInfo.AffectsTarget)
                {
                    significance = significance * 0.667f;
                }
                if (significance.Number < 1 - selfEsteem.Timid_Powerful.WeightingFactor)
                {
                    return(null);
                }
            }

            return(new Reaction(
                       agreement.Suppress(1 - magnitude),
                       surprise,
                       ((PersonalityTraits)reactionTraits).BlendToBounded(surpriseTraits, selfEsteem.Timid_Powerful.WeightingFactor) * magnitude,
                       significance
                       ));
        }