Beispiel #1
0
        protected void AddExperience(Activity response, int result, Condition[] initialSituation)
        {
            SituationalHistory[] histories = new SituationalHistory[2];
            histories[0] = GetAllHistory(initialSituation);
            histories[1] = GetRecentHistory(initialSituation);

            foreach (SituationalHistory history in histories)
            {
                switch (result)
                {
                case Result.Success:
                    history.ResponseSuccessful(response);
                    break;

                case Result.Failure:
                    history.ResponseFailed(response);
                    break;

                case Result.Other:
                default:
                    history.ResponsePerformed(response);
                    break;
                }
            }
        }
Beispiel #2
0
        public Activity GetBestAction(Condition[] situation)
        {
            SituationalHistory history = GetAllHistory(situation);

            Activity bestAction = history.GetBestResponse();

            return(bestAction);
        }
Beispiel #3
0
        public void CopyRecentExperienceTo(Experience other)
        {
            foreach (int key in recentExperiences.Keys)
            {
                SituationalHistory history      = recentExperiences[key];
                SituationalHistory otherHistory = other.GetAllHistory(key);

                history.CopyTo(otherHistory);
            }
        }
Beispiel #4
0
        public override string ToString()
        {
            string output = string.Empty;

            foreach (int key in allExperiences.Keys)
            {
                SituationalHistory history = allExperiences[key];

                output += string.Format("{0}: {1}\n", key, history.ToString());
            }

            return(output);
        }
Beispiel #5
0
        public void CopyTo(SituationalHistory otherHistory)
        {
            foreach (Response response in allResponses.Values)
            {
                Activity activity = response.activity;

                bool hasResponse = otherHistory.allResponses.ContainsKey(activity);
                if (hasResponse == false)
                {
                    otherHistory.AddResponse(activity);
                }

                Response otherResponse = otherHistory.allResponses[activity];
                response.CopyTo(otherResponse);
            }
        }
Beispiel #6
0
        public Activity GetResponse(Condition[] situation, int attitude, Activity[] unavailableActivities)
        {
            SituationalHistory history = GetAllHistory(situation);

            Activity[] responses;

            switch (attitude)
            {
            case Attitudes.Aggressive:
                responses = history.GetMostAggressiveResponses();
                break;

            case Attitudes.Safe:
                responses = history.GetSafestResponses();
                break;

            case Attitudes.Normal:
            default:
                responses = history.GetBestResponses();
                break;
            }

            if (unavailableActivities == null)
            {
                Activity response = responses[0];
                return(response);
            }
            if (unavailableActivities.Length == 0)
            {
                Activity response = responses[0];
                return(response);
            }

            foreach (Activity response in responses)
            {
                bool activityAvailable = IsActivityAvailable(response, unavailableActivities);
                if (activityAvailable == false)
                {
                    continue;
                }

                return(response);
            }

            return(idle);
        }
Beispiel #7
0
        protected SituationalHistory GetSituationalHistory(int key, ref SortedDictionary <int, SituationalHistory> experiences)
        {
            SituationalHistory history;

            bool hasKey = experiences.ContainsKey(key);

            if (hasKey == false)
            {
                history = new SituationalHistory();
                experiences.Add(key, history);
            }
            else
            {
                history = experiences[key];
            }

            return(history);
        }