/// <summary> /// Safely fetches all beliefs of a specific type. /// </summary> /// <param name="type">Desired belief type to fetch.</param> /// <returns>A list of all beliefs of that type, or an empty list if there are none.</returns> public List<Belief> getBeliefs(BeliefType type) { List<Belief> list; if (!beliefs_.TryGetValue(type, out list)) { beliefs_[type] = new List<Belief>(); return beliefs_[type]; } return list; }
/// <summary> /// Runs through all beliefs of a certain type and updates the cache /// to contain the most relevant. /// </summary> /// <param name="type">Type of belief in cache we want to refresh.</param> protected void updateCachedBelief(BeliefType type) { List<Belief> beliefs = getBeliefs(type); Belief bestBelief = null; float bestScore = float.MinValue; for (int i = 0; i < beliefs.Count; i++) { if (beliefs[i].relevance_ > bestScore) { bestBelief = beliefs[i]; bestScore = beliefs[i].relevance_; } } if (bestBelief != null) { cachedBeliefs_[type] = bestBelief; } else { cachedBeliefs_.Remove(type); } }
/// <summary> /// Fetches the first-found belief with a specific type and handle. /// </summary> /// <param name="type">Type of belief to find.</param> /// <param name="handle">Handle of desired belief.</param> /// <returns>The first belief matching these criteria, or null if one is not found.</returns> public Belief getBelief(BeliefType type, Object handle) { List<Belief> list = getBeliefs(type); return list.Find(delegate(Belief b) { return b.handle_ == handle; }); }
/// <summary> /// Removes all beliefs of a certain type. /// </summary> /// <param name="type">Type of beliefs to be deleted.</param> /// <returns>True if a list of that type of belief existed at some time (not /// whether there actually were any beliefs of that type).</returns> public bool removeBeliefs(BeliefType type) { cachedBeliefs_.Remove(type); return beliefs_.Remove(type); }
/// <summary> /// Removes a belief from memory. /// </summary> /// <param name="type">Type of the belief to be deleted.</param> /// <param name="handle">Handle of the belief to be deleted.</param> /// <returns>True if the belief was removed, false if it was not there.</returns> public bool removeBelief(BeliefType type, Object handle) { Belief belief = getBelief(type, handle); if (belief == null) return false; return removeBelief(belief); }
/// <summary> /// Fetches the cached belief of a specific type. /// </summary> /// <param name="type">Type of belief to be fetched.</param> /// <returns>The currently cached belief of that type, or null if there isn't one.</returns> public Belief getFirstBelief(BeliefType type) { Belief cached; cachedBeliefs_.TryGetValue(type, out cached); return cached; }
public Key(int customType) { this.type = BeliefType.CUSTOM; this.customType = customType; }
public Key(BeliefType type) { this.type = type; this.customType = 0; }