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; } } }
public Activity GetBestAction(Condition[] situation) { SituationalHistory history = GetAllHistory(situation); Activity bestAction = history.GetBestResponse(); return(bestAction); }
public void CopyRecentExperienceTo(Experience other) { foreach (int key in recentExperiences.Keys) { SituationalHistory history = recentExperiences[key]; SituationalHistory otherHistory = other.GetAllHistory(key); history.CopyTo(otherHistory); } }
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); }
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); } }
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); }
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); }