Ejemplo n.º 1
0
        public void RunUntilNewArea(PositionGuide <PositionData> guide, int positionCase = 0)
        {
            HasMoved        = false;
            PositionCounter = positionCase;
            int stepsDone = 0;

            while (true)
            {
                //var fallbackDone = false;
                int areaId = guide.PositionAreaId(Position.Data);

                var options = new List <GWAction <PositionData, ActionData> >();
                foreach (var actionFinder in ActionHandling.ActionFinders)
                {
                    // filter actions that have been researched
                    var newOptions = actionFinder.FindActions(Position);
                    options.AddRange(newOptions);
                    //options.AddRange(newOptions.Where(a => !Position.Data.ActionsTried.Contains(a.Data.FingerPrint)));
                }


                if (HasMoved)
                {
                    options = (options.Where(op => op.HasImpactOnTarget)).ToList();
                }
                //TODO: filter double actions (from several actionFinders)
                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                //choose by multievaluation:
                ChosenAction = MultiEvaluation.Do(options, ActionHandling.ActionEvaluators, Weights, 1, MultiEvaluationOptions).First();


                PreSolution.Position = ActionHandling.ActionExecuter.CreateNewPosition(ChosenAction);
                HasMoved             = true;
                stepsDone++;

                //check if new area is reached
                int newAreaId = guide.PositionAreaId(Position.Data);
                if (areaId != newAreaId)
                {
                    MovedToNewArea         = true;
                    Position.IsEndPosition = guide.IsEndPosition(Position.Data);
                    OnTargetReached(this);
                    break;
                }
            }
            //PreSolution.InternalCanBeFiltered = MovedToNewArea;
            //Score = Position.Data.NextCheckPoint.Score(Position.Data);
        }
Ejemplo n.º 2
0
        public void RunDoOneThing(PositionGuide <PositionData> guide, int positionCase = 0)
        {
            HasMoved        = false;
            PositionCounter = positionCase;
            int stepsDone = 0;

            while (stepsDone == 0)
            {
                //int areaId = guide.PositionAreaId(Position.Data);

                var options = new List <GWAction <PositionData, ActionData> >();
                foreach (var actionFinder in ActionHandling.ActionFinders)
                {
                    // filter actions that have been researched
                    var newOptions = actionFinder.FindActions(Position);
                    options.AddRange(newOptions);
                    //options.AddRange(newOptions.Where(a => !Position.Data.ActionsTried.Contains(a.Data.FingerPrint)));
                }

                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                // choose by multievaluation:
                if (options.Count > 1)
                {
                    ChosenAction = MultiEvaluation.Do(options, ActionHandling.ActionEvaluators, Weights, 1, MultiEvaluationOptions).First();
                }
                else
                {
                    ChosenAction = options.First();
                }

                // execute action
                PreSolution.Position = ActionHandling.ActionExecuter.CreateNewPosition(ChosenAction);
                HasMoved             = true;
                stepsDone++;

                //check if new area is reached
                //int newAreaId = guide.PositionAreaId(Position.Data);
                //if (areaId != newAreaId)
                {
                    Position.IsEndPosition = guide.IsEndPosition(Position.Data);
                    OnTargetReached(this);
                    break;
                }
            }
        }
Ejemplo n.º 3
0
        public void RunUntilMeetTargetOrEnd(PartialTarget <PositionData>[] targets, CancelCriteria criteria, int maxSteps = 0)
        {
            //Position.Data.NextCheckPoint = NextCheckPoint;
            //LastCrossroad = new GWCrossroad<PositionData, ActionData>(Position);
            int stepsDone = 0;

            while (true)
            {
                //var fallbackDone = false;
                var currentTargetsReached = new bool[targets.Length];
                for (int i = 0; i < targets.Length; i++)
                {
                    currentTargetsReached[i] = targets[i].ReachTarget(Position);
                }

                var options = new List <GWAction <PositionData, ActionData> >();
                foreach (var actionFinder in ActionHandling.ActionFinders)
                {
                    // filter actions that have been researched
                    var newOptions = actionFinder.FindActions(Position);
                    options.AddRange(newOptions);
                    //options.AddRange(newOptions.Where(a => !Position.Data.ActionsTried.Contains(a.Data.FingerPrint)));
                }
                if (HasMoved)
                {
                    options = (options.Where(op => op.HasImpactOnTarget)).ToList();
                }
                //TODO: filter double actions (from several actionFinders)
                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                //categorize actions
                //var optionCategories = options.Split(action => ActionHandling.ActionCategorizer.Categorize(action)).ToArray();


                if (options.NullOrEmpty())
                {   //no more options that help reach a target, can stop searching
                    break;
                }

                //choose by multievaluation:
                ChosenAction = MultiEvaluation.Do(options, ActionHandling.ActionEvaluators, Weights, 1, MultiEvaluationOptions).First();


                PreSolution.Position = ActionHandling.ActionExecuter.CreateNewPosition(ChosenAction);
                HasMoved             = true;
                stepsDone++;

                //check if new target is reached
                bool newTargetReached = false;
                for (int i = 0; i < targets.Length; i++)
                {
                    var targetReached = targets[i].ReachTarget(Position);
                    if (currentTargetsReached[i] != targetReached)
                    {
                        currentTargetsReached[i] = targetReached;
                        newTargetReached         = true;
                    }
                }
                if (targets.All(t => t.ReachTarget(Position) || t.IsOptional))
                {
                    Position.IsEndPosition = true;
                    OnTargetReached(this);
                    if (criteria == CancelCriteria.TargetsReached)
                    {
                        break;
                    }
                }
                if (newTargetReached)
                {
                    OnTargetReached(this);
                    if (criteria == CancelCriteria.TargetsReached)
                    {
                        break;
                    }
                }

                if (criteria == CancelCriteria.MaxSteps && stepsDone >= maxSteps)
                {
                    break;
                }
            }
            //Score = Position.Data.NextCheckPoint.Score(Position.Data);
        }