예제 #1
0
        /// <summary>
        /// This method can be executed several times, it returns the same if the probability has not been updated between the calls
        /// </summary>
        public void RecalculateProbForEachAnswer()
        {
            if (ProbChange != -1)
            {
                //UncertainFact provided only with ProbChange (not fixed list of probabilities)

                probabilitiesForEachPossibleAnswer[0] = SharedHelper.IncreaseProb(ProbVariable.RefValue.ProbOf(e => e == true), -ProbChange);

                probabilitiesForEachPossibleAnswer[1] = ProbVariable.RefValue.ProbOf(e => e == true).Value; //get the current value

                probabilitiesForEachPossibleAnswer[2] = SharedHelper.IncreaseProb(ProbVariable.RefValue.ProbOf(e => e == true), ProbChange);

                //UnityEngine.Debug.LogWarning("Recalculate answers probabilities for " + this.Name + ": " + probabilitiesForEachPossibleAnswer[0] + " " + probabilitiesForEachPossibleAnswer[1] + " " + probabilitiesForEachPossibleAnswer[2]);
            }
            else
            {
                SharedHelper.LogWarning("Prob change requested for " + Name + ", but this question is with fixed probabilities");
            }

            #region debug
            if (probabilitiesForEachPossibleAnswer.Sum() == 0)
            {
                SharedHelper.LogError("Probabilities are all 0!!! for " + Name);
            }
            #endregion
        }
예제 #2
0
파일: Items.cs 프로젝트: toncho11/KorraAI
        private void LoadSports()
        {
            ItemManager sportManager = providers.SingleOrDefault(x => x is SportsProvider);

            if (sportManager == null)
            {
                SharedHelper.LogError("No Sport Manager"); return;
            }

            #region load sports
            if (sportManager != null)
            {
                sportManager.Add(new Sport("Time for some sport. You should go to the gym."));
                sportManager.Add(new Sport("A healthy mind in a healthy body. Do not forget to do some sport today."));
                sportManager.Add(new Sport("If you have troubles with sleep just remember that working out can help you sleep better. We eat a lot of food rich on energy and we need to spend this energy before going to sleep."));
                sportManager.Add(new Sport("Doing some regular collective sport can help you make some new friends."));
                sportManager.Add(new Sport("OK. Go! Do some sport! Don't worry. I will be right here when you get back."));
                sportManager.Add(new Sport("It may seem counter-intuitive, but working out can drain your energy quite a bit, but then regular exercise can actually make you feel more energized throughout the day."));
                sportManager.Add(new Sport("One study found that exercising in the middle of the day can leave you feeling more energetic and productive for the rest of the afternoon."));
                sportManager.Add(new Sport("Studies show that regular exercise improve your sexual life. That should motivate you."));
                sportManager.Add(new Sport("Try making seven pushups. <prosody pitch=\"+0%\"><break time=\"1600ms\"/></prosody>. OK maybe for you it should be not in a row. Better underestimate you than send you to hospital."));
            }
            else
            {
                SharedHelper.LogError("No Sport Manager available.");
            }
            #endregion
        }
예제 #3
0
 public static void SetFacialExpressionFlag(string exp)
 {
     if (!string.IsNullOrEmpty(exp))
     {
         if (exp == FaceExp.SmileAfterTalking)
         {
             FlagsShared.RequestSmileAfterTalkingDone = true;
         }
         else
         if (exp == FaceExp.SurpriseOnStartTalking)
         {
             FlagsShared.RequestSurpriseExpression = true;
         }
         else
         if (exp == FaceExp.BlinkRightEyeAfterTalking)
         {
             FlagsShared.RequestRightEyeBlink = true;
         }
         else
         if (exp == FaceExp.FlirtingAfterTalking)
         {
             FlagsShared.RequestFlirtingExpression = true;
         }
         else
         if (exp == FaceExp.BlinkRightEyeAndSmile)
         {
             FlagsShared.RequestRightEyeBlinkAndSmile = true;
         }
     }
     else
     {
         SharedHelper.LogError("Unknown face expression requested: '" + exp + "'");
     }
 }
예제 #4
0
        public static void SetAsUsed(string Name)
        {
            for (int i = 0; i < list.Count; i++)
            {
                if (list[i].Name == Name)
                {
                    list[i].IsUsed = true;

                    SharedHelper.Log("Uncertain question " + Name + " is set to used.");

                    list[i].TimeLastAsked = DateTime.Now;

                    if (allRepeatingQuestionsTimeoutsInMinutes.Count == 0)
                    {
                        GenerateRepeatingQuestionsTimeouts();
                    }

                    list[i].TimeOutSeconds = allRepeatingQuestionsTimeoutsInMinutes.Dequeue() * 60;

                    return;
                }
            }

            SharedHelper.LogError("Uncertain Fact Name '" + Name + "' not found in SetAsUsed!");
        }
예제 #5
0
        /// <summary>
        /// Returns a fact using the uniform distribution (currently)
        /// </summary>
        public static UncertainFact GetUncertainFactFromDist()
        {
            //if sufficent time has passed enables certain questions before giving response, if not they are not supplied by GetUncertainFactFromDist
            //if (current_time - last_time) > randomly selected time interval (around some distribution 30 min) then IsUsed = false

            foreach (var item in list)
            {
                if (item.IsUsed)
                {
                    if (Math.Abs((DateTime.Now - item.TimeLastAsked).TotalSeconds) > item.TimeOutSeconds)
                    {
                        item.IsUsed = false;
                        //UnityEngine.Debug.Log("Question RE-enabled: " + item.Name);
                    }
                    else
                    {
                        //UnityEngine.Debug.Log("Question NOT re-enabled: " + Math.Abs((DateTime.Now - item.TimeLastAsked).TotalSeconds) + " / " + item.TimeOutSeconds);
                    }
                }
            }

            UncertainFact[] availableQuestions = list.Where(item => item.IsUsed == false).ToArray();

            int count = availableQuestions.Length;

            if (count == 0)
            {
                SharedHelper.LogError("No uncertain fact questions available. This should not be happening!");
                return(null);
            }

            int next = rnd.Next(0, count);

            return(availableQuestions[next]);
        }
예제 #6
0
        private PureFact GetPureFactAbouBot()
        {
            PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts);

            if (pfManager == null)
            {
                SharedHelper.LogError("No manager in GetPureFactAbouBot.");
                return(null);
            }

            var q = (from item in pfManager.GetAll()
                     let pf = item as PureFact
                              where pf.Type == PureFactType.AboutBot && pf.IsPlanned == false && pf.IsUsed == false
                              select pf).ToArray();

            if (q.Length > 0)
            {
                string[] group1 = { "BotName" };          //conversation should start with these
                string[] group2 = { "BotAge", "BotSex" }; //conversation should continue with these

                List <ItemProb <string> > itemProbs = new List <ItemProb <string> >();

                //assign probabilities
                foreach (PureFact fact in q)
                {
                    if (group1.Contains(fact.Name)) //add only 1 item
                    {
                        itemProbs.Add(new ItemProb <string>(fact.Name, Prob(0.99)));
                        break;
                    }
                    else
                    if (group2.Contains(fact.Name))
                    {
                        itemProbs.Add(new ItemProb <string>(fact.Name, Prob(0.25)));
                    }
                    else
                    {
                        itemProbs.Add(new ItemProb <string>(fact.Name, Prob(0.8)));
                    }
                }

                var pureFactDistF = CategoricalF(itemProbs.ToArray()).Normalize();

                var pureFactDist = pureFactDistF.ToSampleDist();

                var selectionName = pureFactDist.Sample();

                PureFact selectedPureFact = (PureFact)pfManager.GetByName(selectionName);

                //SharedHelper.Log("GetPureFactAbouUser: selectionName " + selectionName);

                return(selectedPureFact);
            }
            else
            {
                SharedHelper.LogError("GetPureFactAbouBot could not supply a pure fact about the bot.");
                return(null);
            }
        }
예제 #7
0
 public IKorraAISampler GetSampler()
 {
     if (!isInitialized)
     {
         SharedHelper.LogError("Not initialized.");
     }
     return(korraSampler);
 }
예제 #8
0
 public IBaseDistributions GetCognitiveDist()
 {
     if (!isInitialized)
     {
         SharedHelper.LogError("Not initialized.");
     }
     return(cognitiveDist);
 }
예제 #9
0
 public ModelContext GetContext()
 {
     if (!isInitialized)
     {
         SharedHelper.LogError("Not initialized.");
     }
     return(context);
 }
예제 #10
0
        private Queue <string> GenerateActions(string[] disabledActions)
        {
            allActions.Clear();

            #region Create a list of all possible actions

            ItemProb <string>[] items =
            {
                ItemProb(ActionsEnum.MakeSuggestion,               ProbVariables.Bot.PrMakeSuggestion[(int)PV.Current]),

                ItemProb(ActionsEnum.AskUncertanFactQuestion,      ProbVariables.Bot.PrAskUncertanFactQuestion),

                ItemProb(ActionsEnum.AskPureFactQuestionAboutUser, ProbVariables.Bot.PrAskPureFactQuestionAboutUser[(int)PV.Current]), //to be packed as one

                ItemProb(ActionsEnum.SharePureFactInfoAboutBot,    ProbVariables.Bot.PrSharePureFactInfoAboutBot[(int)PV.Current]),    //to be packed as one

                ItemProb(ActionsEnum.ChangeVisualAppearance,       SharedHelper.GetProb(ProbVariables.Bot.ChangeVisualAppearance)),

                ItemProb(ActionsEnum.ExpressMentalState,           SharedHelper.GetProb(ProbVariables.Bot.ExpressMentalState)),
            };

            #endregion

            #region Disable actions - NOT ADAPTED for category and subcategory
            if (BotConfigShared.DisableAskQuestions)
            {
                SharedHelper.LogError("NOT ADAPTED for category and subcategory");

                //two actions are removed
                //DisableAcion(ref items, ActionsEnum.AskPureFactQuestionAboutUser);
                //DisableAcion(ref items, ActionsEnum.AskUncertanFactQuestion);
            }

            //foreach (string da in disabledActions)
            //{
            //    DisableAcion(ref items, da);
            //}
            #endregion

            #region Sampling

            var Action = CategoricalF(items).Normalize();

            SharedHelper.Log("Actions Histogram:\r\n" + Action.Histogram());

            var actionDist = Action.ToSampleDist();

            for (var i = 0; i < 100; i++)
            {
                string sample = actionDist.Sample();

                allActions.Enqueue(sample);
            }
            #endregion

            return(allActions);
        }
예제 #11
0
파일: Items.cs 프로젝트: toncho11/KorraAI
        private void LoadAllUncertainFacts()
        {
            #region Uncertain Facts/States about the User

            //3 button answer
            UncertainFacts.AddUncertainFact(new UncertainFact("UserGoodMood", false, "Are you in a good mood?",
                                                              new VarRef <FiniteDist <bool> >(() => ProbVariables.User.InAGoodMood, val => { ProbVariables.User.InAGoodMood = val; }),
                                                              new string[3] {
                "Not so well", "Fine", "Great"
            }, new double[3] {
                0.3, 0.7, 0.85
            },
                                                              UIAnswer.MultiAnswer
                                                              ));

            //3 button answer
            UncertainFacts.AddUncertainFact(new UncertainFact("UserIsTired", false, "Do you feel tired?",
                                                              new VarRef <FiniteDist <bool> >(() => ProbVariables.User.Tired, val => { ProbVariables.User.Tired = val; }),
                                                              new string[3] {
                phrases.No(), "A little bit", phrases.Yes()
            }, new double[3] {
                0.3, 0.6, 0.9
            },
                                                              UIAnswer.MultiAnswer
                                                              ));
            #endregion

            #region Uncertain Facts/Activities about the Bot

            //3 button answer
            UncertainFacts.AddUncertainFact(new UncertainFact("BotAsksIfJokeRateIsOK", true, "Do you like my jokes? Should I tell jokes more often?",
                                                              new VarRef <FiniteDist <bool> >(() => ProbVariables.User.JokeRate, val => { ProbVariables.User.JokeRate = val; }),
                                                              new string[3] {
                "Slow down", "Same rate", "More frequently"
            },
                                                              UIAnswer.MultiAnswer, 0.15
                                                              ));
            //3 button answer
            UncertainFacts.AddUncertainFact(new UncertainFact("BotChangeOutfit", true, "Do you want me to change my outfit more often?",
                                                              new VarRef <FiniteDist <bool> >(() => ProbVariables.Bot.ChangeVisualAppearance, val => { ProbVariables.Bot.ChangeVisualAppearance = val; }),
                                                              new string[3] {
                "Less frequently", "Same rate", "Change more"
            },
                                                              UIAnswer.MultiAnswer, 0.03
                                                              ));
            #endregion

            #region debug
            foreach (var item in UncertainFacts.GetList())
            {
                if (item.ProbabilitiesForEachPossibleAnswer.Sum() == 0)
                {
                    SharedHelper.LogError("Probabilities are all 0!!! for " + item.Name);
                }
            }
            #endregion
        }
예제 #12
0
 public static string FirstCharToUpper(string input)
 {
     if (String.IsNullOrEmpty(input))
     {
         SharedHelper.LogError("FirstCharToUpper: string is null or empty");
         return("");
     }
     else
     {
         return(input.First().ToString().ToUpper() + input.Substring(1));
     }
 }
예제 #13
0
        public Item GetByName(string name)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].Name == name)
                {
                    return(items[i]);
                }
            }

            SharedHelper.LogError("GetByName not found: " + name + " " + example.Category);
            return(null);
        }
예제 #14
0
        public PhrasesEN(ItemManager[] managers)
        {
            #region Get Fact Manager
            PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts);
            if (pfManager == null)
            {
                SharedHelper.LogError("No item managers in PhrasesEN.");
                return;
            }
            #endregion

            this.factsManager = pfManager;
        }
예제 #15
0
        public string SurpriseVideoGames(int surprise, bool LikesGamesAskedFirst)
        {
            if (surprise == 1)
            {
                return("I had the impression, you will like video games.");
            }
            else if (surprise == 2)
            {
                //2
                //LVG No
                //Present Yes
                //inference on: LVG
                if (LikesGamesAskedFirst)
                {
                    return("But you still do not like computer games.");
                }
                //Present Yes
                //LVG No
                else
                {
                    return("Hmm, I thought you would like video games if you approve a video game as a present.");
                }
            }
            else if (surprise == 3)
            {
                //3
                //LVG Yes
                //Present No
                //inference on: present

                if (LikesGamesAskedFirst)
                {
                    return("Strange. I though you will like a video game as a present.");
                }

                //Present No
                //LVG Yes
                //inference on: present
                else
                {
                    return("Hmm, But you still think a video game is not a good present.");
                }
            }
            else
            {
                SharedHelper.LogError("Could not generate appropriate video game text to express surprise.");
                return("");
            }
        }
예제 #16
0
        public string GetValueByName(string name)
        {
            foreach (var item in items)
            {
                PureFact f = (PureFact)item;
                if (f.Name == name)
                {
                    return(f.Value);
                }
            }

            SharedHelper.LogError("GetValueByName: Pure Fact Name '" + name + "'not found");

            return("");
        }
예제 #17
0
        public static void SetJokeAsPlanned(string Name)
        {
            for (int i = 0; i < jokes.Count; i++)
            {
                if (jokes[i].Name == Name)
                {
                    jokes[i].IsPlanned = true;

                    //SharedHelper.Log("Joke '" + Name + "' is set to planned. Joke text: '" + jokes[i].Text + "'");

                    return;
                }
            }

            SharedHelper.LogError("Joke '" + Name + "' not found in SetJokeAsUsed!");
        }
예제 #18
0
        public bool SetAsPlanned(string name, bool isPlanned)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].Name == name)
                {
                    if (items[i].IsPlanned == isPlanned)
                    {
                        SharedHelper.LogError("Already set planned: " + isPlanned.ToString() + " " + name + " " + example.Category);
                    }
                    items[i].IsPlanned = isPlanned;
                    return(true);
                }
            }

            SharedHelper.LogError("SetAsPlanned not found: " + name + " " + example.Category);
            return(false);
        }
예제 #19
0
        public static void SetJokeAsUsed(string Name)
        {
            for (int i = 0; i < jokes.Count; i++)
            {
                if (jokes[i].Name == Name)
                {
                    jokes[i].IsUsed = true;

                    SharedHelper.Log("Joke '" + Name + "' is set to used. Joke text: '" + jokes[i].Text + "'");

                    FlagsShared.RequestSavePersistentData = true;

                    return;
                }
            }

            SharedHelper.LogError("Joke '" + Name + "' not found in SetJokeAsUsed!");
        }
예제 #20
0
파일: Items.cs 프로젝트: toncho11/KorraAI
        public Item[] GetAll()
        {
            List <Item> items = new List <Item>();

            items.AddRange(UncertainFacts.GetList());
            items.AddRange(JokesProvider.GetAll());

            foreach (var manager in providers)
            {
                int oldCount = items.Count;
                items.AddRange(manager.GetAll());
                if (items.Count == oldCount)
                {
                    SharedHelper.LogError("No items were loaded for: " + manager.ToString());
                }
            }

            return(items.ToArray());
        }
예제 #21
0
        //public override void Add(Item fact)
        //{
        //    //check if ID already exists
        //    bool existsAlready = list.Any(cus => cus.Name == fact.Name);

        //    if (existsAlready)
        //        SharedHelper.Log("Pure Fact with this Name already exists: '" + fact.Name + "'. Second one was ignored.");
        //    else
        //    list.Add((PureFact)fact);
        //}

        //public override PureFact[] GetAll()
        //{
        //    return list.ToArray();
        //}

        //public static void SetAsUsed(string name)
        //{
        //    SetAsUsed(name, true);
        //}

        //public static void SetAsUsed(string name, bool isUsed)
        //{
        //    for (int i = 0; i < list.Count; i++)
        //    {
        //        if (list[i].Name == name)
        //        {
        //            SharedHelper.Log("Set used to " + isUsed + " : " + list[i].Name);
        //            list[i].IsUsed = isUsed;

        //            return;
        //        }
        //    }

        //    SharedHelper.LogError("Pure Fact Name '" + name + "' not found in SetAsUsed!");
        //}

        public void MarkForSaving(string name)
        {
            SharedHelper.Log("Marking for saving: " + name);

            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].Name == name)
                {
                    if (items[i].Name != "UserMovieYesterday")
                    {
                        FlagsShared.RequestSavePersistentData = true;
                    }

                    return;
                }
            }

            SharedHelper.LogError("Pure Fact Name '" + name + "'not found in MarkForSaving!");
        }
예제 #22
0
        private int PureFactsAboutBotLeftCount()
        {
            PureFacts pfManager = (PureFacts)providers.SingleOrDefault(x => x is PureFacts);

            if (pfManager != null)
            {
                var q = (from item in pfManager.GetAll()
                         let pf = item as PureFact
                                  where pf.Type == PureFactType.AboutBot && pf.IsPlanned == false && pf.IsUsed == false
                                  select pf).ToArray();

                return(q.Length);
            }
            else
            {
                SharedHelper.LogError("No manager in PureFactsAboutBotLeftCount");
                return(0);
            }
        }
예제 #23
0
        public static int GetItemsLeftForSubCategory(string subCategory, ItemManager[] managers)
        {
            if (subCategory == ActionsEnum.AskPureFactQuestionAboutUser)
            {
                PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts);

                if (pfManager == null)
                {
                    SharedHelper.LogError("No manager in GetPureFactAbouBot.");
                    return(0);
                }

                var q = (from item in pfManager.GetAll()
                         let pf = (PureFact)item
                                  where pf.Type == PureFactType.AboutUser && pf.IsPlanned == false && pf.IsUsed == false
                                  select pf).ToArray();

                return(q.Length);
            }
            else
            if (subCategory == ActionsEnum.SharePureFactInfoAboutBot)
            {
                PureFacts pfManager = (PureFacts)managers.SingleOrDefault(x => x is PureFacts);

                if (pfManager == null)
                {
                    SharedHelper.LogError("No manager in GetPureFactAbouBot.");
                    return(0);
                }

                var q = (from item in pfManager.GetAll()
                         let pf = (PureFact)item
                                  where pf.Type == PureFactType.AboutBot && pf.IsPlanned == false && pf.IsUsed == false
                                  select pf).ToArray();

                return(q.Length);
            }
            else
            {
                SharedHelper.LogError("GetItemsLeftForSubCategory: action category currently not supported");
                return(0);
            }
        }
예제 #24
0
        //public string FacialExpressionOnReaction;

        #endregion

        private void SetCategory(PureFactType p_type)
        {
            this.Category = ActionsEnum.PureFact;

            if (p_type == PureFactType.AboutUser)
            {
                this.SubCategory = ActionsEnum.AskPureFactQuestionAboutUser;
            }

            else if (p_type == PureFactType.AboutBot)
            {
                this.SubCategory = ActionsEnum.SharePureFactInfoAboutBot;
            }

            else if (p_type != PureFactType.UIQuestion && p_type != PureFactType.System && p_type != PureFactType.BuyQuestion && p_type != PureFactType.JokeQuestion)
            {
                SharedHelper.LogError("Category was not set for fact '" + p_type.ToString() + "'");
            }
        }
예제 #25
0
파일: Items.cs 프로젝트: toncho11/KorraAI
        private void LoadMovies()
        {
            ItemManager movieManager = providers.SingleOrDefault(x => x is MoviesProvider);

            if (movieManager == null)
            {
                SharedHelper.LogError("No Movie Manager"); return;
            }

            #region load movies
            movieManager.Add(new Movie("1", "The Bing Bang Theory", true, true));
            movieManager.Add(new Movie("2", "Jessica Jones", true, true));
            movieManager.Add(new Movie("3", "Grey's Anatomy", true, true));
            movieManager.Add(new Movie("4", "The Walking Dead", true, true));
            movieManager.Add(new Movie("5", "Game of Thrones", true, true));
            movieManager.Add(new Movie("6", "Homeland", true, true));
            movieManager.Add(new Movie("7", "The Good Doctor", true, true));
            movieManager.Add(new Movie("8", "Arrow", true, true));
            movieManager.Add(new Movie("9", "Supernatural", true, true));
            movieManager.Add(new Movie("10", "Agents of SHIELD", true, true));
            movieManager.Add(new Movie("11", "Shameless", true, true));
            movieManager.Add(new Movie("12", "Black Mirror", true, true));
            movieManager.Add(new Movie("13", "Vikings", true, true));
            movieManager.Add(new Movie("14", "Altered Carbon", true, true));
            movieManager.Add(new Movie("15", "The Blacklist", true, true));
            movieManager.Add(new Movie("16", "Gotham", true, true));
            movieManager.Add(new Movie("17", "The Flash", true, true));
            movieManager.Add(new Movie("18", "Friends", true, true));
            movieManager.Add(new Movie("19", "Timeless", true, true));
            movieManager.Add(new Movie("20", "Legends of Tomorrow", true, true));
            movieManager.Add(new Movie("21", "Seven Seconds", true, true));
            movieManager.Add(new Movie("22", "Rick and Morty", true, true));
            movieManager.Add(new Movie("23", "Counterpart", true, true));
            movieManager.Add(new Movie("24", "Atlanta", true, true));
            movieManager.Add(new Movie("25", "Suits", true, true));
            movieManager.Add(new Movie("26", "Star Trek: Discovery", true, true));
            movieManager.Add(new Movie("27", "The Orville", true, true));
            movieManager.Add(new Movie("28", "Supergirl", true, true));
            movieManager.Add(new Movie("29", "Doctor Who", true, true));
            movieManager.Add(new Movie("30", "Futurama", true, true));
            #endregion
        }
예제 #26
0
        public bool ModelUpdate(TimeSpan timeSinceStart, bool isPureFactUpdated, bool isUncertainFactUpdated)
        {
            bool regenerationRequested = false;

            if (!isInitialized)
            {
                SharedHelper.LogError("Not initialized."); return(regenerationRequested);
            }

            //Execute triggers that perform inference and update probabilistic variables
            foreach (var trigger in ModelTriggers)
            {
                int oldExecuteCount = trigger.TriggeredCount;

                if (
                    (trigger is IModelUpdateTrigger)
                    &&
                    (
                        (trigger.IsTimeBased || (isPureFactUpdated && trigger.IsUserResponseBased))
                        &&
                        ((trigger.IsOneTimeTrigger && trigger.TriggeredCount == 0) || !trigger.IsOneTimeTrigger)

                    )
                    )
                {
                    //Updating model
                    regenerationRequested = ((IModelUpdateTrigger)trigger).Process(isPureFactUpdated, timeSinceStart, this);

                    if (trigger.TriggeredCount > oldExecuteCount)
                    {
                        SharedHelper.Log("Trigger executed: '" + trigger.ToString() + "'");
                    }
                }
            }

            if (isUncertainFactUpdated)
            {
                regenerationRequested = true;
            }

            return(regenerationRequested);
        }
예제 #27
0
        public string GetReaction(bool IsPositiveResponse, bool IsNegativeResponse, out string FacialExpression, out bool IsResponseValid)
        {
            // it either returns a predefined response or
            // if available it executes the ResponseFunc to obtain one

            string result = "";

            FacialExpression = "";

            if (!string.IsNullOrEmpty(Acknowledgement))
            {
                result = Acknowledgement;
            }

            if (IsPositiveResponse && !string.IsNullOrEmpty(statementOnPositiveResponse))
            {
                result           = statementOnPositiveResponse;
                FacialExpression = FacialExpressionOnPositiveResponse;
            }

            if (IsNegativeResponse && !string.IsNullOrEmpty(statementOnNegativeResponse))
            {
                result           = statementOnNegativeResponse;
                FacialExpression = FacialExpressionOnNegativeResponse;
            }

            IsResponseValid = true;

            //overrides
            if (!IsAnswered && ResponseFunc != null)
            {
                SharedHelper.LogError("Trying to use processing function on unanswered question.");
            }

            if (ResponseFunc != null)
            {
                result = ResponseFunc(Value, out IsResponseValid, out FacialExpression);
            }

            return(result);
        }
예제 #28
0
        public void InteractionsUpdate(TimeSpan timeSinceStart, int interactionsDoneSinceStart, ref Queue <CommItem> interactions)
        {
            if (!isInitialized)
            {
                SharedHelper.LogError("Not initialized."); return;
            }

            //Evaluate triggers that represent 'Surprise' for example
            //These triggers evaluate a model and add a new interaction
            foreach (var trigger in ModelTriggers)
            {
                int oldExecuteCount = trigger.TriggeredCount;

                if (trigger is IModelEvaluateTrigger &&
                    (
                        (trigger.IsOneTimeTrigger && trigger.TriggeredCount == 0)
                        ||
                        (!trigger.IsOneTimeTrigger)
                    )
                    )
                {
                    CommItem?newInteraction = ((IModelEvaluateTrigger)trigger).Process(this);

                    if (newInteraction != null)
                    {
                        if (interactions.Peek().Name != newInteraction.Value.Name)
                        {
                            KorraModelHelper.InsertFirstInteractionList(ref interactions, newInteraction.Value);

                            //TODO: this custom code should be moved to another place
                            if (trigger is VideoGameSurpriseTrigger)
                            {
                                FlagsShared.RequestSurpriseExpression = true;
                            }

                            SharedHelper.Log("Trigger executed: '" + trigger.ToString() + "'");
                        }
                    }
                }
            }
        }
예제 #29
0
        public bool SetAsUsed(string name)
        {
            for (int i = 0; i < items.Count; i++)
            {
                if (items[i].Name == name)
                {
                    if (items[i].IsUsed == true)
                    {
                        SharedHelper.LogError("Already set to used = true: " + name + " " + example.Category);
                    }

                    //SharedHelper.LogError("SetAsUsed : " + name + " " + items[i].Category + " " + items[i].SubCategory);
                    items[i].IsUsed = true;

                    return(true);
                }
            }

            SharedHelper.LogError("SetAsUsed not found: " + name);
            return(false);
        }
예제 #30
0
        public static string GetChance(string[] values, string lastUsed)
        {
            int selected = -1;
            int i        = -1;

            if (!string.IsNullOrEmpty(lastUsed))
            {
                i = Array.FindIndex(values, item => item == lastUsed);
            }

            if (i != -1 && values[i] != lastUsed)
            {
                SharedHelper.LogError("Error locating value '" + lastUsed + "' in array!");
            }

            if (i != -1)
            {
                SharedHelper.Swap(values, i, values.Length - 1); //disable the last used one

                if (values[values.Length - 1] != lastUsed)
                {
                    SharedHelper.LogError("Last value in array is incorrect!");
                }

                selected = rndChances.Next(0, values.Length - 1); //the last one used is excluded from the selection

                if (values[selected] == lastUsed)
                {
                    SharedHelper.LogError("Last used is going to be used again! Not correct!");
                }
            }
            else
            {
                selected = rndChances.Next(0, values.Length);
            }

            return(values[selected]);
        }