예제 #1
0
 /// <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;
 }
예제 #2
0
        /// <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);
            }
        }
예제 #3
0
 /// <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; });
 }
예제 #4
0
 /// <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);
 }
예제 #5
0
 /// <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);
 }
예제 #6
0
 /// <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;
 }
예제 #7
0
파일: Belief.cs 프로젝트: mhaque3/soa_unity
 public Key(int customType)
 {
     this.type       = BeliefType.CUSTOM;
     this.customType = customType;
 }
예제 #8
0
파일: Belief.cs 프로젝트: mhaque3/soa_unity
 public Key(BeliefType type)
 {
     this.type       = type;
     this.customType = 0;
 }