Exemple #1
0
        public Action ChooseAction()
        {
            var processedActions = 0;

            this.ActionCombinationsThisFrame = 0;

            var startTime = Time.realtimeSinceStartup;

            //TODO: Implement

            //def planAction(worldModel, maxDepth)
            float currentValue = float.MinValue;

            while (this.CurrentDepth >= 0 && this.ActionCombinationsThisFrame < this.ActionCombinationsProcessedPerFrame)
            {
                if (this.CurrentDepth >= MAX_DEPTH)
                {
                    currentValue = this.Models[this.CurrentDepth].CalculateDiscontentment(Goals);
                    if (currentValue < this.BestDiscontentmentValue)
                    {
                        this.BestDiscontentmentValue = currentValue;
                        this.BestAction = this.ActionPerLevel[0];
                        for (int i = 0; i < CurrentDepth; i++)
                        {
                            this.BestActionSequence[i] = this.ActionPerLevel[i];
                        }
                    }
                    this.CurrentDepth -= 1;
                    this.ActionCombinationsThisFrame++;
                    continue;
                }
                Action nextAction = this.Models[this.CurrentDepth].GetNextAction();
                if (nextAction != null)
                {
                    WorldModel wm = this.Models[this.CurrentDepth].GenerateChildWorldModel();
                    nextAction.ApplyActionEffects(wm);
                    if (wm.CalculateDiscontentment(Goals) < this.BestDiscontentmentValue)
                    {
                        this.Models[this.CurrentDepth + 1]     = wm;
                        this.ActionPerLevel[this.CurrentDepth] = nextAction;
                        this.CurrentDepth += 1;
                        processedActions++;
                    }
                }
                else
                {
                    if (this.CurrentDepth == 0 && BestAction == null)
                    {
                        this.BestAction            = this.ActionPerLevel[0];
                        this.BestActionSequence[0] = this.BestAction;
                        break;
                    }
                    this.CurrentDepth -= 1;
                    this.ActionCombinationsThisFrame++;
                }
            }
            this.TotalActionCombinationsProcessed += processedActions;
            this.TotalProcessingTime += Time.realtimeSinceStartup - startTime;
            this.InProgress           = false;
            return(this.BestAction);
        }