Exemplo n.º 1
0
        public void InteractWithMe_NoReaderOrBuilder_ForgettingSomethingReaction()
        {
            // ReSharper disable once InconsistentNaming
            var Sterling = new Person("Sterling Archer", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid())
            {
                DateOfBirth = new StandardDateTime(DateTime.Now.AddYears(-33))
            };

            var testCharacter = new global::RNPC.Core.Character(Sterling, Archetype.None);

            VerifyTestFilesAndDirectory(testCharacter.MyName);

            var insult = new Action
            {
                EventType  = EventType.Interaction,
                ActionType = ActionType.Verbal,
                Intent     = Intent.Hostile,
                Message    = "Hey Swirling! You suck!",
                Target     = "Sterling Archer",
                EventName  = "Insult",
                Source     = "Unknown"
            };

            var reaction = testCharacter.InteractWithMe(insult);

            Assert.IsNotNull(reaction);
            Assert.IsTrue(reaction[0].Message.Contains("It feels like I'm forgetting something"));
            Assert.AreEqual(reaction[0].InitialEvent, insult);
        }
Exemplo n.º 2
0
        public void NotifyAllCharactersInRegion_()
        {
            // ReSharper disable once InconsistentNaming
            var Sterling = new Person("Sterling Archer", Gender.Male, Sex.Male, Orientation.Straight, Guid.NewGuid());

            var testCharacter = new global::RNPC.Core.Character(Sterling, Archetype.None)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder(),
                MyMemory            = new Memory(Sterling)
            };

            testCharacter.CharacterReacted += TestCharacter_CharacterReacted;

            Cronos.Instance.AddFollower(testCharacter);

            Action tornado = new Action
            {
                EventType = EventType.Weather,
                Target    = "None",
                EventName = "Tornado",
                Source    = "Unknown"
            };

            Cronos.Instance.NotifyAllCharactersInRegion(tornado, new Coordinates(), 500);
        }
        protected override bool EvaluateNode(PerceivedEvent perceivedEvent, Memory memory, CharacterTraits traits)
        {
            Action perceivedAction = perceivedEvent as Action;

            if (perceivedAction == null)
            {
                throw new RnpcParameterException("Perceived events that are not of Action type should not be passed to social interactions", new Exception("Incorrect parameter type passed in class " + this));
            }

            return(IsItAFinancialThreat(perceivedAction.Message));
        }
        public void AnalyzeAndLearn_TestDecisionTreeEvolutions_DecisionTreeChanged()
        {
            //ARRANGE
            //"C:\\Sysdev\\RNPC\\RNPC\\DTO\\Learning\\Resources\\DecisionTreeSubstitutions.xml";
            var controller = new SubstitutionController(new SubstitutionDocumentConverter(), new DecisionTreeFileController(), new SubstitutionMapper());
            MainDecisionTreeLearningStrategy strategy = new MainDecisionTreeLearningStrategy(controller, new DecisionTreeBuilder());

            var Morty = new Person("Morty", Gender.Male, Sex.Male, Orientation.Undefined, Guid.NewGuid());

            var character = new global::RNPC.Core.Character(Morty, Archetype.TheInnocent)
            {
                FileController      = new DecisionTreeFileController(),
                DecisionTreeBuilder = new DecisionTreeBuilder()
            };

            //Initial Action
            //Friendly Greeting
            Action greeting = new Action
            {
                EventType  = EventType.Interaction,
                ActionType = ActionType.Verbal,
                Intent     = Intent.Friendly,
                Message    = "Hi!",
                Target     = character.MyName,
                EventName  = "Greeting",
                Source     = "The Friend"
            };

            var reaction = new Reaction
            {
                Tone          = Tone.Neutral,
                Target        = greeting.Source,
                Intent        = Intent.Neutral,
                ActionType    = ActionType.Verbal,
                InitialEvent  = greeting,
                EventType     = EventType.Interaction,
                ReactionScore = 0,
                EventName     = "Greeting",
                Message       = "Hello.", //TODO: Randomize
                Source        = greeting.Target
            };

            character.MyMemory.AddActionToLongTermMemory(reaction);
            character.MyMemory.AddActionToLongTermMemory(reaction);
            character.MyMemory.AddActionToLongTermMemory(reaction);

            //ACT
            strategy.AnalyzeAndLearn(character);
            //ASSERT
        }
Exemplo n.º 5
0
        public void NotifyEnvironmentalEvent_TimeEvent_NormalReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action timePasses = new Action
            {
                EventType = EventType.Time,
                Target    = "None",
                EventName = "TimeKeepsOnTicking",
                Source    = "Unknown"
            };

            testCharacter.CharacterReacted += OnCharacterReactedTime;

            testCharacter.NotifyEnvironmentalEvent(timePasses, Cronos.Instance);
        }
Exemplo n.º 6
0
        public void NotifyEnvironmentalEvent_TemperatureEvent_NormalReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action turnTheHeatUp = new Action
            {
                EventType = EventType.Temperature,
                Target    = "None",
                EventName = "ItsGettingHotInHere",
                Source    = "Unknown"
            };

            testCharacter.CharacterReacted += OnCharacterReactedTemperature;

            testCharacter.NotifyEnvironmentalEvent(turnTheHeatUp, Cronos.Instance);
        }
Exemplo n.º 7
0
        public void NotifyEnvironmentalEvent_WeatherEvent_NormalReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action tornado = new Action
            {
                EventType = EventType.Weather,
                Target    = "None",
                EventName = "Tornado",
                Source    = "Unknown"
            };

            testCharacter.CharacterReacted += OnCharacterReactedWeather;

            testCharacter.NotifyEnvironmentalEvent(tornado, Cronos.Instance);
        }
Exemplo n.º 8
0
        public void NotifyEnvironmentalEvent_EnvironmentalEvent_NormalReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action fight = new Action
            {
                EventType = EventType.Environmental,
                Target    = "None",
                EventName = "NearbyFight",
                Source    = "Unknown"
            };

            testCharacter.CharacterReacted += OnCharacterReactedEnvironmental;

            testCharacter.NotifyEnvironmentalEvent(fight, Cronos.Instance);
        }
Exemplo n.º 9
0
        public void NotifyEnvironmentalEvent_InvalidCaller_MethodCallerInvalidReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action tornado = new Action
            {
                EventType = EventType.Environmental,
                Target    = "None",
                EventName = "Tornado",
                Source    = "Unknown"
            };

            testCharacter.CharacterReacted += TestCharacterOnCharacterReacted;

            testCharacter.NotifyEnvironmentalEvent(tornado, null);
        }
Exemplo n.º 10
0
        public void InteractWithMe_EnvironmentalEvent_WrongEventReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action tornado = new Action
            {
                EventType = EventType.Environmental,
                Target    = "None",
                EventName = "Tornado",
                Source    = "Unknown"
            };

            var reaction = testCharacter.InteractWithMe(tornado);

            Assert.IsNotNull(reaction);
            Assert.AreEqual(reaction[0].Target, null);
            Assert.AreEqual(reaction[0].Message, ErrorMessages.EnvironmentEventPassedInWrongWay);
        }
Exemplo n.º 11
0
        public void InteractWithMe_TimeEvent_WrongEventReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action hourPassed = new Action
            {
                EventType = EventType.Time,
                Target    = "None",
                EventName = "HourPassed",
                Source    = "None"
            };

            var reaction = testCharacter.InteractWithMe(hourPassed);

            Assert.IsNotNull(reaction);
            Assert.AreEqual(reaction[0].Target, null);
            Assert.AreEqual(reaction[0].Message, ErrorMessages.TimeEventPassedInWrongWay);
        }
Exemplo n.º 12
0
        public void InteractWithMe_BiologicalEvent_WrongEventReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            Action headache = new Action
            {
                EventType = EventType.Biological,
                Target    = "Sterling Archer",
                EventName = "Headache",
                Source    = "Unknown"
            };

            var reaction = testCharacter.InteractWithMe(headache);

            Assert.IsNotNull(reaction);
            Assert.AreEqual(reaction[0].Target, null);
            Assert.AreEqual(reaction[0].Message, ErrorMessages.PhysicalEventPassedInWrongWay);
        }
        /// <summary>
        /// A tree has found to be a candidate for substitution. Apply logic.
        /// </summary>
        /// <param name="builder">Tree builder class</param>
        /// <param name="characterName">name of the character evolding</param>
        /// <param name="action">action that triggered evolution</param>
        /// <param name="decisionTreeToChange">Decision Tree To evolve</param>
        /// <returns></returns>
        public bool SubstituteNode(ITreeBuilder builder, string characterName, RNPC.Core.Action.Action action, string decisionTreeToChange)
        {
            var initialAction = ((Reaction)action).InitialEvent as RNPC.Core.Action.Action;

            if (initialAction == null)
            {
                return(false);
            }

            var substitution = _substitutionMapper.GetSubstitutableSubTreeForLeaf(action.EventName);

            if (substitution == null)
            {
                return(false);
            }

            var firstNode = builder.BuildTreeFromDocument(_fileController, initialAction, characterName);

            if (firstNode == null)
            {
                return(false);
            }

            var replacementNode = builder.BuildSubTreeFromRepository(_fileController, substitution.SubTreeName, ConfigurationDirectory.Instance.SubTreeRepository);

            if (replacementNode == null)
            {
                return(false);
            }

            if (!FindAndReplaceMatchingNode(firstNode, substitution, replacementNode))
            {
                return(false);
            }

            string fileName = initialAction.ActionType + "-" + initialAction.Intent + "-" + initialAction.EventName;

            builder.BuildAndSaveXmlDocumentFromTree(_fileController, firstNode, fileName, characterName);

            return(true);
        }
Exemplo n.º 14
0
        public void InteractWithMe_InsultRandomArchetype_NormalReactionReturned()
        {
            var testCharacter = GetMeSterlingArcher();

            VerifyTestFilesAndDirectory(testCharacter.MyName);

            Action insult = new Action
            {
                EventType  = EventType.Interaction,
                ActionType = ActionType.Verbal,
                Intent     = Intent.Hostile,
                Message    = "Hey Swirling! You suck!",
                Target     = "Sterling Archer",
                EventName  = "Insult",
                Source     = "Unknown"
            };

            var reaction = testCharacter.InteractWithMe(insult);

            Assert.IsNotNull(reaction);
            Assert.AreEqual(reaction[0].Target, "Unknown");
            Assert.AreEqual(reaction[0].InitialEvent, insult);
        }
Exemplo n.º 15
0
        /// <summary>
        /// Handles all social interactions with the character
        /// </summary>
        /// <param name="action">The action that the character is reacting to</param>
        /// <returns>The character's reaction</returns>
        private List <Reaction> HandleSocialInteraction(RNPC.Core.Action.Action action)
        {
            try
            {
                if (FileController == null || DecisionTreeBuilder == null)
                {
                    throw new RnpcParameterException("Objects FileController or DecisionTreeBuilder has not been properly initialized.");
                }



                var decisionTreeRootNode = DecisionTreeBuilder.BuildTreeFromDocument(FileController, action, MyName);

                if (decisionTreeRootNode == null)
                {
                    throw new NullNodeException("Root node has not been initialized. Check BuildTreeFromDocument method.");
                }

                //var contextInfo = ContextAnalyzer.EvaluateEventContext(action);

                //var strategy = ContextStrategyFactory.GetContextStrategy(contextInfo);

                //var reaction = strategy.Evaluate(this, action, decisionTreeRootNode);

                var reaction = decisionTreeRootNode.Evaluate(MyTraits, MyMemory, action);

                MyMemory.AddNodeTestResults(((AbstractDecisionNode)decisionTreeRootNode).GetNodeTestsData());

                reaction[0].ReactionScore = ((AbstractDecisionNode)decisionTreeRootNode).GetNodeTestsData().Sum(info => info.ProfileScore);

                MyMemory.AddRecentReactions(reaction);

                return(reaction);

                //return strategy.Evaluate(this, action, decisionTreeRootNode);
            }
            //TODO: logging
            catch (XmlException exception)
            {
                return(new List <Reaction>
                {
                    new Reaction
                    {
                        Intent = Intent.Neutral,
                        ActionType = ActionType.Verbal,
                        EventType = EventType.Interaction,
                        Tone = Tone.Confused,
                        InitialEvent = action,
                        ReactionScore = 0,
                        Target = null,
                        EventName = "XmlException",
                        ErrorMessages = exception.Message,
                        Message = ErrorMessages.IDontKnow,
                        Source = MyName
                    }
                });
            }
            catch (NullNodeException exception)
            {
                return(new List <Reaction>
                {
                    new Reaction
                    {
                        Intent = Intent.Neutral,
                        ActionType = ActionType.Verbal,
                        EventType = EventType.Interaction,
                        Tone = Tone.Confused,
                        InitialEvent = action,
                        ReactionScore = 0,
                        Target = null,
                        EventName = "NullNodeException",
                        ErrorMessages = exception.Message,
                        Message = ErrorMessages.ICantDecide,
                        Source = MyName
                    }
                });
            }
            catch (RnpcParameterException exception)
            {
                return(new List <Reaction>
                {
                    new Reaction
                    {
                        Intent = Intent.Neutral,
                        ActionType = ActionType.Verbal,
                        EventType = EventType.Interaction,
                        Tone = Tone.Pensive,
                        InitialEvent = action,
                        ReactionScore = 0,
                        Target = null,
                        EventName = "RnpcParameterException",
                        ErrorMessages = exception.Message,
                        Message = ErrorMessages.FeelsLike,
                        Source = MyName
                    }
                });
            }
            catch (NodeInitializationException exception
                   ) //The decision tree could not be initialized properly. Check the xml files.
            {
                return(new List <Reaction>
                {
                    new Reaction
                    {
                        Intent = Intent.Neutral,
                        ActionType = ActionType.Verbal,
                        EventType = EventType.Interaction,
                        Tone = Tone.Confused,
                        InitialEvent = action,
                        ReactionScore = 0,
                        Target = null,
                        EventName = "NodeInitializationException",
                        ErrorMessages = exception.Message,
                        Message = ErrorMessages.MyThoughtsAreJumbled,
                        Source = MyName
                    }
                });
            }
            catch (Exception e) //A generic exception was raised while initializing the decision tree
            {
                return(new List <Reaction>
                {
                    new Reaction
                    {
                        Intent = Intent.Neutral,
                        ActionType = ActionType.Verbal,
                        EventType = EventType.Interaction,
                        Tone = Tone.Confused,
                        InitialEvent = action,
                        ReactionScore = 0,
                        Target = null,
                        EventName = "Exception",
                        ErrorMessages = e.Message,
                        Message = ErrorMessages.IHaveAHeadache,
                        Source = MyName
                    }
                });
            }
        }
 public bool PruneDecisionTree(ITreeBuilder builder, string characterName, RNPC.Core.Action.Action action, string decisionTreeToChange)
 {
     return(true);
 }
Exemplo n.º 17
0
        /// <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();
            }
        }