Пример #1
0
 public MainForm()
 {
     InitializeComponent();
     _storage     = new AssetStorage();
     _loadedAsset = EmotionalAppraisalAsset.CreateInstance(_storage);
     OnAssetDataLoaded();
 }
Пример #2
0
 private void newToolStripMenuItem_Click(object sender, EventArgs e)
 {
     _currentFilePath = null;
     _storage         = new AssetStorage();
     _loadedAsset     = EmotionalAppraisalAsset.CreateInstance(_storage);
     OnAssetDataLoaded();
 }
Пример #3
0
        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            var aux = EditorTools.OpenFileDialog("Asset Storage File (*.json)|*.json|All Files|*.*");

            if (aux != null)
            {
                _currentFilePath = aux;
                _storage         = AssetStorage.FromJson(File.ReadAllText(_currentFilePath));
                _loadedAsset     = EmotionalAppraisalAsset.CreateInstance(_storage);
                OnAssetDataLoaded();
            }
        }
Пример #4
0
        public void LoadAssociatedAssets(AssetStorage storage)
        {
            var charName = CharacterName.ToString();

            m_emotionalAppraisalAsset      = EmotionalAppraisalAsset.CreateInstance(storage);
            m_emotionalDecisionMakingAsset = EmotionalDecisionMakingAsset.CreateInstance(storage);
            m_socialImportanceAsset        = SocialImportanceAsset.CreateInstance(storage);
            m_commeillFautAsset            = CommeillFautAsset.CreateInstance(storage);

            //Dynamic properties
            BindToRegistry(m_kb);
            m_emotionalDecisionMakingAsset.RegisterKnowledgeBase(m_kb);
            m_commeillFautAsset.RegisterKnowledgeBase(m_kb);
            m_socialImportanceAsset.RegisterKnowledgeBase(m_kb);
        }
Пример #5
0
        //This is a small console program to exemplify the main functionality of the Emotional Appraisal Asset
        static void Main(string[] args)
        {
            var kickEvent = Name.BuildName("Event(Action-End, John, *, *)");

            EmotionalAppraisalAsset ea = EmotionalAppraisalAsset.CreateInstance(new AssetStorage());

            //The following lines add an appraisal rule that will make the kickEvent be perceived as undesirable
            //Normally, these rules should be authored using the AuthoringTool provided with the asset but they can also be added dynamically

            /*   var rule = new AppraisalRuleDTO {EventMatchingTemplate = (Name)"Event(Action-End, [s], *, *)", Desirability = (Name)"4"};
             * ea.AddOrUpdateAppraisalRule(rule);
             */

            var am = new AM();
            var kb = new KB((Name)"John");

            kb.Tell(Name.BuildName("Likes(Mary)"), Name.BuildName("John"), Name.BuildName("SELF"));

            var emotionalState = new ConcreteEmotionalState();

            //Emotions are generated by the appraisal of the events that occur in the game world
            ea.AppraiseEvents(new[] { kickEvent }, emotionalState, am, kb, null);

            Console.WriteLine("\nMood on tick '" + am.Tick + "': " + emotionalState.Mood);
            Console.WriteLine("Active Emotions: " + string.Concat(emotionalState.GetAllEmotions().Select(e => e.EmotionType + "-" + e.Intensity + " ")));

            //Each event that is appraised will be stored in the autobiographical memory that was passed as a parameter
            Console.WriteLine("\nEvents occured so far: " + string.Concat(am.RecallAllEvents().Select(e => "\nId: " + e.Id + " Event: " + e.EventName.ToString())));

            //The update function will increase the current tick by 1. Each active emotion will decay to 0 and the mood will slowly return to 0
            for (int i = 0; i < 3; i++)
            {
                am.Tick++;
                emotionalState.Decay(am.Tick);
                Console.WriteLine("\nMood on tick '" + am.Tick + "': " + emotionalState.Mood);
                Console.WriteLine("Active Emotions: " + string.Concat(emotionalState.GetAllEmotions().Select(e => e.EmotionType + "-" + e.Intensity + " ")));
            }

            ea.Save();

            Console.ReadKey();
        }
Пример #6
0
        //This is a small console program to exemplify the main functionality of the Emotional Decision Making Asset
        static void Main(string[] args)
        {
            //First we construct a new instance of the EmotionalDecisionMakingAsset class
            var storage = new AssetStorage();
            var edm     = EmotionalDecisionMakingAsset.CreateInstance(storage);

            //Then, we have to register an existing knowledge base to the asset so it can check for
            //beliefs are true
            var kb = new KB((Name)"John");

            kb.Tell((Name)"LikesToFight(SELF)", (Name)"True");
            edm.RegisterKnowledgeBase(kb);
            //create an action rule
            var actionRule = new ActionRuleDTO {
                Action = Name.BuildName("Kick"), Priority = Name.BuildName("4"), Target = (Name)"Player"
            };


            //add the reaction rule
            var id   = edm.AddActionRule(actionRule);
            var rule = edm.GetActionRule(id);

            edm.AddRuleCondition(id, "LikesToFight(SELF) = True");
            var actions = edm.Decide(Name.UNIVERSAL_SYMBOL);
            var ea      = EmotionalAppraisalAsset.CreateInstance(storage);

            edm.Save();

            using (var writer = File.CreateText("D:\\test2.json"))
            {
                writer.Write(storage.ToJson());
            }

            string aux2 = File.ReadAllText("D:\\Test2.json");

            var storage2 = AssetStorage.FromJson(aux2);

            using (var writer = File.CreateText("D:\\test3.json"))
            {
                writer.Write(storage2.ToJson());
            }
            Console.WriteLine("Decisions: ");
            foreach (var a in actions)
            {
                Console.WriteLine(a.Name.ToString() + " p: " + a.Utility);
            }

            //this is how you can load the asset from a file
            Console.WriteLine("Loading From File: ");
            edm.RegisterKnowledgeBase(kb);
            actions = edm.Decide(Name.UNIVERSAL_SYMBOL);

            foreach (var a in actions)
            {
                Console.WriteLine(a.Name.ToString() + " p: " + a.Utility);
            }
            Console.WriteLine("Decisions: ");
            foreach (var a in actions)
            {
                Console.WriteLine(a.Name.ToString() + " p: " + a.Utility);
            }
            Console.ReadKey();
        }