private static int CalculateEmotionalVariation(int emotionalStateValue, int longTermEmotion, int firstQualityTrait, int secondQualityTraint) { //calculate the differential int emotionalDelta = emotionalStateValue - longTermEmotion; if (emotionalDelta == 0) { return(longTermEmotion); } int newEmotionalValue = longTermEmotion; int retentionPercentage = (firstQualityTrait + (100 - secondQualityTraint)) / 2; for (int i = 0; i < Math.Abs(emotionalDelta); i++) { if (emotionalDelta > 0) { if (RandomValueGenerator.GeneratePercentileIntegerValue() < retentionPercentage) { newEmotionalValue++; } } else { if (RandomValueGenerator.GeneratePercentileIntegerValue() >= retentionPercentage) { newEmotionalValue--; } } } return(newEmotionalValue); }
public bool AnalyzeAndLearn(Character learningCharacter) { var recentActions = learningCharacter.MyMemory.GetMyRecentActions(); foreach (Action.Action recentAction in recentActions) { if (recentAction.AssociatedKarma <= LearningParameters.UnforgivableActionThreshold) { learningCharacter.MyMemory.AddActionToLongTermMemory(recentAction); learningCharacter.MyTraits.RaiseMyShame(10); } if (recentAction.AssociatedKarma >= LearningParameters.UnforgettableActionThreshold) { learningCharacter.MyMemory.AddActionToLongTermMemory(recentAction); learningCharacter.MyTraits.RaiseMyPride(10); } if (learningCharacter.MyTraits.Memory > RandomValueGenerator.GeneratePercentileIntegerValue()) { learningCharacter.MyMemory.AddActionToLongTermMemory(recentAction); } } learningCharacter.MyMemory.ResetRecentActions(); return(true); }
/// <summary> /// Evaluates all rules and applies them /// </summary> /// <param name="traits">character traits</param> public void EvaluateAndApplyAllRules(CharacterTraits traits) { var rules = GetAllEmotionalTraitRules(); foreach (var rule in rules) { var quality = traits.GetType().GetProperty(rule.Quality); var emotion = traits.LongTermEmotions.GetType().GetProperty(rule.Emotion); if (quality == null || emotion == null) { continue; } int randomValue = RandomValueGenerator.GeneratePercentileIntegerValue(); int qualityValue = (int)quality.GetValue(traits); int currentEmotionValue = (int)emotion.GetValue(traits.LongTermEmotions); if (rule.IsComparedBelowQualityValue && qualityValue > randomValue || (!rule.IsComparedBelowQualityValue && qualityValue < randomValue)) { //If conditions are met, emotion is modified, but by at most 3. emotion.SetValue(traits.LongTermEmotions, currentEmotionValue + RandomValueGenerator.GenerateIntWithMaxValue(3)); } } }
public void Hibernate_CronosInstanceWithFollowersAndKnowledge_FileWritten() { //ARRANGE OmniscienceFileController controller = new OmniscienceFileController(); Cronos.Instance.FileController = controller; Cronos.Instance.DeactivateMemoryBackups(); if (controller.FileExists()) { controller.DeleteFile(); } var referenceData = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory()); for (int i = 0; i < 50; i++) { Person newPerson = new Person("NPC" + i, Gender.Agender, Sex.Undefined, Orientation.Asexual, Guid.Empty); var newNpc = new global::RNPC.Core.Character(newPerson, Archetype.None); foreach (var data in referenceData) { if (RandomValueGenerator.GeneratePercentileIntegerValue() < 34) { newNpc.AddContentToLongTermMemory(data); } } Cronos.Instance.AddFollower(newNpc); } Cronos.Instance.AddReferenceDataList(referenceData); //ACT Cronos.Instance.Hibernate(); //ASSERT Assert.IsTrue(controller.FileExists()); }
private static EventType GetRandomEventType() { int randomValue = RandomValueGenerator.GeneratePercentileIntegerValue(); if (randomValue <= TrainingStatistics.Biological) { return(EventType.Biological); } if (randomValue <= TrainingStatistics.Environmental) { return(EventType.Environmental); } if (randomValue <= TrainingStatistics.Interaction) { return(EventType.Interaction); } if (randomValue <= TrainingStatistics.Time) { return(EventType.Time); } if (randomValue <= TrainingStatistics.Temperature) { return(EventType.Temperature); } return(EventType.Weather); }
private static ActionType GetRandomActionType() { int randomValue = RandomValueGenerator.GeneratePercentileIntegerValue(); if (randomValue < TrainingStatistics.NonVerbal) { return(ActionType.NonVerbal); } if (randomValue < TrainingStatistics.Physical) { return(ActionType.Physical); } return(ActionType.Verbal); }
private static Intent GetRandomIntent() { int randomValue = RandomValueGenerator.GeneratePercentileIntegerValue(); if (randomValue < TrainingStatistics.Friendly) { return(Intent.Friendly); } if (randomValue < TrainingStatistics.Neutral) { return(Intent.Neutral); } return(Intent.Hostile); }
/// <inheritdoc /> public bool AnalyzeAndLearn(Character learningCharacter) { var actionsToAnalyze = learningCharacter.MyMemory.GetMyPastActions(); //If there are not enough nodes for change we stop here. if (actionsToAnalyze.Count < LearningParameters.DecisionLearningThreshold) { return(true); } var groupedActions = actionsToAnalyze.GroupBy(q => q.EventName).ToList(); foreach (var action in groupedActions) { if (action.Count() < LearningParameters.DecisionLearningThreshold) { continue; } //Reasoning is that overusage of a response will lead to pruning down your options if (action.Count() > LearningParameters.DecisionDevolutionThreshold) { //if you lose the lottery you go down! if (RandomValueGenerator.GeneratePercentileIntegerValue() <= LearningParameters.DecisionDevolveRate) { if (!DevolveDecisionTree(learningCharacter, action.ToList()[0])) { return(false); //if there has been any issue we exit } } } //While meeeting the minimum thrreshold will lead to a normal evolution else if (action.Count() >= LearningParameters.DecisionLearningThreshold) { //if you win the lottery you go up! if (RandomValueGenerator.GeneratePercentileIntegerValue() >= (100 - LearningParameters.DecisionLearningRate)) { if (!EvolveDecisionTree(learningCharacter, action.ToList()[0])) { return(false); //if there has been any issue we exit } } } } return(true); }
public void GeneratePercentileValue_1000Calls_1000NumbersBetweenOneAndOneHundred() { //ARRANGE List <int> generatedValues = new List <int>(); //ACT for (int i = 0; i < 1000; i++) { generatedValues.Add(RandomValueGenerator.GeneratePercentileIntegerValue()); } //ASSERT //Checking if values are within the boundaries Assert.IsTrue(generatedValues.All(x => x > 0 && x <= 100)); //checking that some values are at the limits Assert.IsTrue(generatedValues.Any(x => x == 1)); Assert.IsTrue(generatedValues.Any(x => x == 100)); }
/// <summary> /// Takes the value of an value and compares it against a random value /// </summary> /// <param name="attributeValue">Value of the value to be tested</param> /// <param name="description">description of the test params</param> /// <param name="characteristicName"></param> /// <param name="modifier">value, if any, that modified the value of the value tested</param> /// <returns></returns> protected bool TestAttributeAgainstRandomValue(int attributeValue, string description, string characteristicName, int modifier = 0) { int randomValue = RandomValueGenerator.GeneratePercentileIntegerValue(); var myTestResult = new NodeTestInfo { TestedCharacteristic = CharacteristicType.Quality, CharacteristicName = characteristicName, AttributeValue = attributeValue, ProfileScore = EvaluateProfileScore(characteristicName, attributeValue), Result = attributeValue + modifier >= randomValue, //this is the test PassingValue = randomValue, Description = description, Modifier = modifier }; DataToMemorize.Add(myTestResult); return(myTestResult.Result); }
public void WriteToFile_OmniscienceFile_FileWritten() { //ARRANGE OmniscienceFileController controller = new OmniscienceFileController(); if (controller.FileExists()) { controller.DeleteFile(); } var referenceData = MemoryContentInitializer.CreateItemsAndLinkThem(new ItemLinkFactory()); Dictionary <Guid, MemoryItem> dataDictionary = new Dictionary <Guid, MemoryItem>(); foreach (var item in referenceData) { dataDictionary.Add(Guid.NewGuid(), item); } Omniscience allKnowledge = new Omniscience(dataDictionary); for (int i = 0; i < 50; i++) { Person newPerson = new Person("NPC" + i, Gender.Agender, Sex.Undefined, Orientation.Asexual, Guid.Empty); var newNpc = new global::RNPC.Core.Character(newPerson, Archetype.None); for (int j = 0; j < referenceData.Count; j++) { if (RandomValueGenerator.GeneratePercentileIntegerValue() < 34) { newNpc.AddContentToLongTermMemory(dataDictionary.ElementAt(j).Value); } } allKnowledge.AddFollower(newNpc); } //ACT controller.WriteToFile(allKnowledge); //ASSERT controller.FileExists(); }
/// <summary> /// Adds 1 to 4 additional strong points /// </summary> /// <param name="traits"></param> protected void AddRandomStrongPoint(CharacterTraits traits) { int numberOfStrongPoints = 4; int demographicPercentage = RandomValueGenerator.GeneratePercentileIntegerValue(); if (demographicPercentage > int.Parse(TraitDistribution.StrongPointTier1) && demographicPercentage <= int.Parse(TraitDistribution.StrongPointTier2)) { numberOfStrongPoints = 5; } if (demographicPercentage > int.Parse(TraitDistribution.StrongPointTier2) && demographicPercentage <= int.Parse(TraitDistribution.StrongPointTier3)) { numberOfStrongPoints = 6; } if (demographicPercentage > int.Parse(TraitDistribution.StrongPointTier3)) { numberOfStrongPoints = 7; } while (StrongPoints.Count < numberOfStrongPoints) { int randomTraitIndex = RandomValueGenerator.GenerateIntWithMaxValue(CharacterTraits.GetPersonalQualitiesCount() - 1); var property = traits.GetQualityPropertyByIndex(randomTraitIndex); if (property == null || StrongPoints.Contains(property.Name) || WeakPoints.Contains(property.Name)) { continue; } property.SetValue(traits, RandomValueGenerator.GenerateStrongAttributeValue()); StrongPoints.Add(property.Name); } }
/// <summary> /// Randomly set some information to be wrong /// </summary> /// <param name="knowledgeItem">an item to randomize</param> /// <returns>The memory item with randomly falsified info</returns> public MemoryItem RandomizeKnowledgeItem(MemoryItem knowledgeItem) { int comparisonValue = RandomValueGenerator.GeneratePercentileIntegerValue(); return(_knowledgeAccuracyPercentage >= comparisonValue?knowledgeItem.GetAccurateCopy() : knowledgeItem.GetInaccurateCopy()); }
public bool AnalyzeAndLearn(Character learningCharacter) { var nodeTestResults = learningCharacter.MyMemory.GetAllCurrentNodeTestInfos(); var testedValues = nodeTestResults.Where(t => t.TestedCharacteristic == CharacteristicType.Values).ToList(); //If there are not enough nodes for change we stop here. if (testedValues.Count < LearningParameters.MinimumValueThreshold) { return(false); } var groupedValueTests = testedValues.GroupBy(q => q.CharacteristicName).ToList(); foreach (var testInfos in groupedValueTests) { var testInfo = testInfos.ToList()[0]; if (testInfo.Result) { if (testInfos.Count() < LearningParameters.MinimumValueThreshold) { continue; } if (testInfos.Count() >= LearningParameters.ValueLossThreshold) { //if you win the lottery you get a new one! if (RandomValueGenerator.GeneratePercentileIntegerValue() < 100 - LearningParameters.ValueLossRate) { continue; } // ReSharper disable once InlineOutVariableDeclaration PersonalValues value; if (!Enum.TryParse(testInfo.CharacteristicName, true, out value)) { continue; } learningCharacter.MyTraits.PersonalValues.Remove(value); Console.WriteLine(@"Removed " + value); } else { //if you win the lottery you get a new one! if (RandomValueGenerator.GeneratePercentileIntegerValue() < (100 - LearningParameters.ValueAcquisitionRate / learningCharacter.MyTraits.PersonalValues.Count)) { continue; } // ReSharper disable once InlineOutVariableDeclaration PersonalValues value; if (!Enum.TryParse(testInfo.CharacteristicName, true, out value)) { continue; } var newValue = _personalValueAssociations.GetAssociatedValue(value); if (newValue == null) { continue; } if (!learningCharacter.MyTraits.PersonalValues.Contains(newValue.Value)) { learningCharacter.MyTraits.PersonalValues.Add(newValue.Value); Console.WriteLine(@"Added " + value); } } } else { if (testInfos.Count() < LearningParameters.NRVAThreshold) { continue; } if (RandomValueGenerator.GeneratePercentileIntegerValue() > LearningParameters.NRVARate) { continue; } // ReSharper disable once InlineOutVariableDeclaration PersonalValues value; Enum.TryParse(testInfo.CharacteristicName, true, out value); Console.WriteLine(@"Added " + value); learningCharacter.MyTraits.PersonalValues.Add(value); } } return(true); }
/// <summary> /// Am I going to remember this MemoryItem? /// </summary> /// <returns>true, remember the item, false I won't remember</returns> private bool DoIRememberThisInformation() { return(_knowledgeRetentionPercentage >= RandomValueGenerator.GeneratePercentileIntegerValue()); }
/// <summary> /// Executes a random test against an value value /// </summary> /// <param name="value">value value</param> /// <returns>Attribute is greater; test passed</returns> protected bool SetValueIsGreaterThanRandomValue(int value) { return(value > RandomValueGenerator.GeneratePercentileIntegerValue()); }
public bool AnalyzeAndLearn(Character learningCharacter) { var testResults = learningCharacter.MyMemory.GetAllCurrentNodeTestInfos(); var testedQualities = testResults.Where(t => t.TestedCharacteristic == CharacteristicType.Quality).ToList(); int qualityEvolveRate = LearningParameters.QualityLearningRate; int qualityDevolveRate = LearningParameters.QualityDevolveRate; //If there are not enough nodes for change we stop here. if (testedQualities.Count < LearningParameters.QualityLearningThreshold) { return(true); } var groupedQualitiesTest = testedQualities.GroupBy(q => q.CharacteristicName).ToList(); foreach (var testInfos in groupedQualitiesTest) { if (testInfos.Count() < LearningParameters.QualityLearningThreshold) { continue; } int failedTests = testInfos.Count(q => q.Result == false); int succeededTests = testInfos.Count(q => q.Result); //if they're identical or almost identical it cancels out. if (failedTests == succeededTests || Math.Abs(failedTests - succeededTests) == 1) { continue; } string quality = testInfos.ToList()[0].CharacteristicName; Type type = learningCharacter.MyTraits.GetType(); PropertyInfo info = type.GetProperty(quality); if (info == null) { return(false); } int currentTraitValue = (int)info.GetValue(learningCharacter.MyTraits); if (currentTraitValue <= 1 || currentTraitValue >= 100) { continue; } if (failedTests > succeededTests) { //if you lose the lottery you go down! if (RandomValueGenerator.GeneratePercentileIntegerValue() <= qualityDevolveRate) { info.SetValue(learningCharacter.MyTraits, currentTraitValue - 1); } } //This makes it linearly harder to evolve a strong point. if (currentTraitValue >= Constants.MinStrongPoint && Constants.MaxStrongPoint - currentTraitValue < qualityEvolveRate) { qualityEvolveRate = Constants.MaxStrongPoint - currentTraitValue; } //This makes it harder to evolve out of a weak point. if (currentTraitValue <= Constants.MaxWeakPoint && currentTraitValue < qualityEvolveRate) { qualityEvolveRate = currentTraitValue; } //if you win the lottery you go up! if (RandomValueGenerator.GeneratePercentileIntegerValue() >= 100 - qualityEvolveRate) { info.SetValue(learningCharacter.MyTraits, currentTraitValue + 1); } } return(true); }
/// <summary> /// Socially interact with this character /// </summary> /// <param name="interaction">The action that the character is reacting to</param> /// <returns>The character's reaction</returns> public List <Reaction> InteractWithMe(RNPC.Core.Action.Action interaction) { if (interaction == null) { return new List <Reaction> { new Reaction { Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.WhatIsGoingOn } } } ; //I'm asleep. You can try to wake me up, but it might be hard. if (_wakingProbability < 100) { //You didn't wake me up. I'm still sleeping. if (_wakingProbability <= RandomValueGenerator.GeneratePercentileIntegerValue()) { return new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = (MyTraits.Energy <= 10) ? string.Format(CharacterMessages.Snoring, MyMemory.Me.Name) : string.Format(CharacterMessages.Sleeping, MyMemory.Me.Name) } } } ; //I woke up. But I'm confused! //TODO: interupt learning return(new List <Reaction> { new Reaction { Tone = Tone.Confused, InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = CharacterMessages.JustWokeUp } }); } switch (interaction.EventType) { //TODO : Log case EventType.Environmental: return(new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.EnvironmentEventPassedInWrongWay } }); //TODO : Log case EventType.Temperature: return(new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.TemperatureEventPassedInWrongWay } }); //TODO : Log case EventType.Weather: return(new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.EnvironmentEventPassedInWrongWay } }); //TODO : Log case EventType.Time: return(new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.TimeEventPassedInWrongWay } }); case EventType.Interaction: return(HandleSocialInteraction(interaction)); case EventType.Biological: return(new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.PhysicalEventPassedInWrongWay } }); case EventType.Unknown: return(new List <Reaction> { new Reaction { InitialEvent = interaction, Source = MyName, Target = null, EventType = EventType.Interaction, Intent = Intent.Neutral, Message = ErrorMessages.WhatIsGoingOn } }); default: throw new ArgumentOutOfRangeException(); } }