Пример #1
0
        public override IQualifier Select(IAIContext context, List <IQualifier> qualifiers, IDefaultQualifier defaultQualifier)  //  Need default qualifier.  Final return value should be default Qualifier.
        {
            List <IQualifier> qList = new List <IQualifier>(qualifiers);

            if (qList.Count == 0)
            {
                return(defaultQualifier as IQualifier);
            }

            //  Get score for all qualifiers
            for (int index = 0; index < qList.Count; index++)
            {
                CompositeQualifier q = qList[index] as CompositeQualifier;
                var score            = q.Score(context, q.scorers);
            }

            //  Sort list of qualifiers.
            qList.Sort();    //  Sorts in accending order.
            qList.Reverse(); //  Sorts in decending order.
            var best = qList[0];



            //DebugSelectorWinner(context, qList);
            return(best);
        }
Пример #2
0
        /// <summary>
        /// For Debugging
        /// </summary>
        public Dictionary <IQualifier, float> GetSelectorResults(IAIContext context, IList <IQualifier> qualifiers, IDefaultQualifier defaultQualifer)
        {
            if (selectorResults == null)
            {
                selectorResults = new Dictionary <IQualifier, float>();
            }
            else
            {
                selectorResults.Clear();
            }

            for (int index = 0; index < qualifiers.Count; index++)
            {
                CompositeQualifier qualifier = qualifiers[index] as CompositeQualifier;
                var score = qualifier.Score(context, qualifier.scorers);
                selectorResults.Add(qualifier, score);
            }


            var dq = defaultQualifer as IQualifier;

            selectorResults.Add(dq, defaultQualifer.Score(context));

            return(selectorResults);
        }
        private void GetSelectorResults(IAIContext context, List <IQualifier> qualifiers)
        {
            selectorResults.Clear();
            for (int index = 0; index < qualifiers.Count; index++)
            {
                CompositeQualifier qualifier = qualifiers[index] as CompositeQualifier;
                var score = qualifier.Score(context, qualifier.scorers);
                selectorResults.Add(qualifier, score);
            }

            //return selectorResults;
        }
Пример #4
0
        /// <summary>
        /// Selects the action for execution.
        /// </summary>
        /// <returns>The select.</returns>
        /// <param name="context">Context.</param>
        public IAction Select(IAIContext context)
        {
            List <IQualifier> qualifiers       = rootSelector.qualifiers;
            IDefaultQualifier defaultQualifier = rootSelector.defaultQualifier;
            IQualifier        winner           = rootSelector.Select(context, qualifiers, defaultQualifier);

            CompositeQualifier cq = winner as CompositeQualifier;
            // TODO:  What if there are no scoreres?
            //float score = cq.Score(context, cq.scorers);
            IAction action = winner.action;

            return(action);
        }
Пример #5
0
        /// <summary>
        /// Used just for Debugging
        /// </summary>
        /// <param name="context">Context.</param>
        /// <param name="qualifiers">Qualifiers.</param>
        private void DebugSelectorWinner(IAIContext context, List <IQualifier> qualifiers)
        {
            var winnerInfo = "";

            winnerInfo += "Winner is:   " + qualifiers[0] + "\n";
            for (int index = 0; index < qualifiers.Count; index++)
            {
                CompositeQualifier q = qualifiers[index] as CompositeQualifier;
                var score            = q.Score(context, q.scorers);
                winnerInfo += q.GetType().Name + " | " + q.action.GetType().Name + " | " + score + "\n";
            }

            Debug.Log(winnerInfo);
        }