예제 #1
0
 /// <summary>
 ///   Clears everything, i.e. all actions, considerations, options, behaviours and AIs.
 /// </summary>
 public void ClearAll()
 {
     _aiMap.Clear();
     Behaviours.Clear();
     Options.Clear();
     Considerations.Clear();
     Actions.Clear();
 }
예제 #2
0
        protected override Consideration <TContext> SelectBestConsideration(TContext context)
        {
            base.SelectBestConsideration(context);
            var defaultScore = DefaultConsideration.GetScore(context);

            var first = Considerations
                        .FirstOrDefault(consideration => consideration.GetScore(context) >= defaultScore);

            return(first ?? DefaultConsideration);
        }
예제 #3
0
        private void _CreateAiDynamic(Info.AiInfo info)
        {
            var actions = new List <IAction>();

            foreach (var actioninfo in info.Actions)
            {
                var newAction = Actions.Create(actioninfo.RefAction);

                if (newAction == null)
                {
                    throw new NullReferenceException();
                }
                newAction.Initialize(actioninfo);
                actions.Add(newAction);
            }

            var considerations = new List <IConsideration>();

            foreach (var considerationinfo in info.Considerations)
            {
                var newConsideration = Considerations.Create(considerationinfo.RefConsideration);

                if (newConsideration == null)
                {
                    throw new NullReferenceException();
                }
                newConsideration.Initialize(considerationinfo);
                considerations.Add(newConsideration);
            }
            var options = new List <IOption>();

            foreach (var optionInfo in info.Options)
            {
                var action            = actions[optionInfo.ActionInfoIndex];
                var subConsiderations = new List <IConsideration>();
                foreach (var indexConsideration in optionInfo.ConsiderationInfoIndexes)
                {
                    subConsiderations.Add(considerations[indexConsideration]);
                }
                var newOption = new DynamicOption(action, subConsiderations, optionInfo);
                options.Add(newOption);
            }

            var behaviours = new List <IBehaviour>();

            foreach (var behaviourInfo in info.Behaviours)
            {
                var subOptions = new List <IOption>();
                foreach (var indexOption in behaviourInfo.OptionInfoIndexes)
                {
                    subOptions.Add(options[indexOption]);
                }
                var subConsiderations = new List <IConsideration>();
                foreach (var indexConsideration in behaviourInfo.ConsiderationInfoIndexes)
                {
                    subConsiderations.Add(considerations[indexConsideration]);
                }
                var newBehaviour = new DynamicBehaviours(subOptions, subConsiderations, behaviourInfo);
                behaviours.Add(newBehaviour);
            }

            var newAi = new DynamicAi(behaviours);

            AIs.Add(newAi);
        }