Exemple #1
0
        /// <summary>
        /// Executes all the primitives SM in order to perform the entire task
        /// </summary>
        /// <returns>LeaveArena state</returns>
        private int PerformCommand(int currentState, object o)
        {
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> PerformCommand state reached.");

            //exxecute all the primitives (one by one)
            foreach (string action in SMConfiguration.setOfActions)
            {
                char[] delimiters = { ' ' };
                //get the parameters for each primitive
                string   clean_action = action.Replace('\r', ' ');
                string[] parameters   = clean_action.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                //the first parameter allways is the primitive to execute
                if (parameters.Length > 0)
                {
                    switch (parameters[0])
                    {
                    case "answer_question":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: AnswerQuestion.");
                        //no parameters
                        AnswerQuestion        sm_aq          = new AnswerQuestion(this.brain, this.cmdMan, this.SMConfiguration);
                        AnswerQuestion.Status finalStatus_aq = sm_aq.Execute();
                        break;

                    case "bring_object":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: Bringobject.");
                        //1 parameter (object name)
                        BringObject        sm_bo          = new BringObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        BringObject.Status finalStatus_bo = sm_bo.Execute();
                        break;

                    case "navigate_to":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: NavigateTo.");
                        //1 parameter (location name/class)
                        NavigateTo        sm_nt          = new NavigateTo(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        NavigateTo.Status finalStatus_nt = sm_nt.Execute();
                        break;

                    case "take_object":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TakeObject.");
                        //1 parameter (object name)
                        TakeObject        sm_to          = new TakeObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        TakeObject.Status finalStatus_to = sm_to.Execute();
                        break;

                    case "tell_phrase":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TellPhrase.");
                        //1 parameter (kind of phrase to say)
                        TellPhrase        sm_tp          = new TellPhrase(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                        TellPhrase.Status finalStatus_tp = sm_tp.Execute();
                        break;

                    case "find_person":
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: FindPerson.");
                        //no parameters
                        //FindPerson sm_fp = new FindPerson(this.brain, this.cmdMan, this.SMConfiguration);
                        //FindPerson.Status finalStatus_fp = sm_fp.Execute();
                        break;

                    default:
                        TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> The primitive " + parameters[0] + " was not found.");
                        break;
                    }
                }
            }
            finalStatus = Status.OK;
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> All primitives were executed.");
            //TODO:
            //Descomponer las siguientes dependencias conceptuales:

            /*
             * # take [object] from [location] and deliver to [person]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [person_location]
             *      bring
             * # take [object] from [location] and deliver to [me]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [me]
             *      bring
             * # take [object] from [location1] and deliver to [location2]
             *      navigate_to [location1]
             *      search_and_take [object]
             *      navigate_to [location2]
             *      bring
             * # go to [location] and find [person]
             *      navigate_to [location]
             *      find [person]
             * # find person in [location] and talk [phrase]
             *      navigate_to [location]
             *      find [person]
             *      tellphrase [phrase]
             */
            return((int)States.LeaveArena);
        }
Exemple #2
0
        /// <summary>
        /// Executes all the primitives SM in order to perform the entire task
        /// </summary>
        /// <returns>LeaveArena state</returns>
        private int PerformCommand(int currentState, object o)
        {
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> PerformCommand state reached.");

            //exxecute all the primitives (one by one)
            foreach (string action in SMConfiguration.setOfActions)
            {
                char[] delimiters = {' '};
                //get the parameters for each primitive
                string clean_action = action.Replace('\r',' ');
                string[] parameters = clean_action.Split(delimiters, StringSplitOptions.RemoveEmptyEntries);

                //the first parameter allways is the primitive to execute
                if (parameters.Length > 0)
                {
                    switch (parameters[0])
                    {
                        case "answer_question":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: AnswerQuestion.");
                            //no parameters
                            AnswerQuestion sm_aq = new AnswerQuestion(this.brain, this.cmdMan, this.SMConfiguration);
                            AnswerQuestion.Status finalStatus_aq = sm_aq.Execute();
                            break;
                        case "bring_object":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: Bringobject.");
                            //1 parameter (object name)
                            BringObject sm_bo = new BringObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            BringObject.Status finalStatus_bo = sm_bo.Execute();
                            break;
                        case "navigate_to":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: NavigateTo.");
                            //1 parameter (location name/class)
                            NavigateTo sm_nt = new NavigateTo(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            NavigateTo.Status finalStatus_nt = sm_nt.Execute();
                            break;
                        case "take_object":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TakeObject.");
                            //1 parameter (object name)
                            TakeObject sm_to = new TakeObject(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            TakeObject.Status finalStatus_to = sm_to.Execute();
                            break;
                        case "tell_phrase":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: TellPhrase.");
                            //1 parameter (kind of phrase to say)
                            TellPhrase sm_tp = new TellPhrase(this.brain, this.cmdMan, this.SMConfiguration, parameters[1]);
                            TellPhrase.Status finalStatus_tp = sm_tp.Execute();
                            break;
                        case "find_person":
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> SM to Execute: FindPerson.");
                            //no parameters
                            //FindPerson sm_fp = new FindPerson(this.brain, this.cmdMan, this.SMConfiguration);
                            //FindPerson.Status finalStatus_fp = sm_fp.Execute();
                            break;
                        default:
                            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> The primitive " + parameters[0] + " was not found.");
                            break;
                    }
                }
            }
            finalStatus = Status.OK;
            TextBoxStreamWriter.DefaultLog.WriteLine("HAL9000.-> All primitives were executed.");
            //TODO:
            //Descomponer las siguientes dependencias conceptuales:
            /*
             * # take [object] from [location] and deliver to [person]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [person_location]
             *      bring
             * # take [object] from [location] and deliver to [me]
             *      navigate_to [location]
             *      search_and_find [object]
             *      navigate_to [me]
             *      bring
             * # take [object] from [location1] and deliver to [location2]
             *      navigate_to [location1]
             *      search_and_take [object]
             *      navigate_to [location2]
             *      bring
             * # go to [location] and find [person]
             *      navigate_to [location]
             *      find [person]
             * # find person in [location] and talk [phrase]
             *      navigate_to [location]
             *      find [person]
             *      tellphrase [phrase]
             */
            return (int)States.LeaveArena;
        }