AIMA.Core.Search.Framework.SimpleProblemSolvingAgent.execute C# (CSharp) Method

execute() public method

public execute ( Percept p ) : Action
p Percept
return Action
        public override Action execute(Percept p)
        {
            Action action = NoOpAction.NO_OP;

            // state <- UPDATE-STATE(state, percept)
            updateState(p);
            // if seq is empty then do
            if (0 == seq.Count)
            {
                if (formulateGoalsIndefinitely
                        || goalsFormulated < maxGoalsToFormulate)
                {
                    if (goalsFormulated > 0)
                    {
                        notifyViewOfMetrics();
                    }
                    // goal <- FORMULATE-GOAL(state)
                    System.Object goal = formulateGoal();
                    goalsFormulated++;
                    // problem <- FORMULATE-PROBLEM(state, goal)
                    Problem problem = formulateProblem(goal);
                    // seq <- SEARCH(problem)
                    seq.AddRange(search(problem));
                    if (0 == seq.Count)
                    {
                        // Unable to identify a path
                        seq.Add(NoOpAction.NO_OP);
                    }
                }
                else
                {
                    // Agent no longer wishes to
                    // achieve any more goals
                    setAlive(false);
                    notifyViewOfMetrics();
                }
            }

            if (seq.Count > 0)
            {
                // action <- FIRST(seq)
                action = Util.first(seq);
                // seq <- REST(seq)
                seq = Util.rest(seq);
            }

            return action;
        }