public void TestExecute_ReactiveChoicePresenter(IBlackboard blackboard, ContentUnit selectedCU, ContentUnit originalCU, ContentUnit[] choices)
        {
            blackboard.Clear();
            blackboard.AddUnit(selectedCU);
            blackboard.AddUnit(originalCU);
            blackboard.AddLink(originalCU, selectedCU, LinkTypes.L_SelectedContentUnit);

            foreach (ContentUnit choice in choices)
            {
                blackboard.AddUnit(choice);
                blackboard.AddLink(originalCU, choice, LinkTypes.L_Choice);
            }

            KS_Old_ReactiveChoicePresenter ks = new KS_Old_ReactiveChoicePresenter(blackboard);

            ks.PresenterExecute += GenerateEventHandler(selectedCU, choices, blackboard);

            var KSAs = ks.Precondition();

            int count = KSAs.Count();

            Assert.Equal(1, count);

            // Execute the activated choice presenter
            KSAs.ElementAt(0).Execute();
        }
Esempio n. 2
0
        /*
         * Utility method for copying a unit to a new content pool.
         */
        protected Unit CopyUnitToPool(Unit unit, string pool)
        {
            Unit newUnit = new Unit(unit);

            /*
             * If there is an existing content pool component remove the componenet before adding a new one with the new pool. The case in which there won't be a content pool
             * component is when copying from the global pool (no pool) into a pool.
             */
            if (newUnit.HasComponent <KC_ContentPool>())
            {
                newUnit.RemoveComponent(newUnit.GetComponent <KC_ContentPool>());
            }
            newUnit.AddComponent(new KC_ContentPool(pool, true));

            m_blackboard.AddUnit(newUnit);
            m_blackboard.AddLink(unit, newUnit, LinkTypes.L_SelectedUnit, true); // fixme: need a more general link type for copies between pools
            return(newUnit);
        }
        public static void Demo1_Slots_DefineCUs(IBlackboard blackboard)
        {
            ContentUnit start = new ContentUnit();

            start.Metadata[ContentUnitID] = "start";
            start.Content[Text]           = "You stand before an old wooden door.";

            ContentUnit start_Choice1 = new ContentUnit();

            start_Choice1.Metadata[TargetContentUnitID] = "open door";
            start_Choice1.Content[Text] = "Open the door";

            ContentUnit start_Choice2 = new ContentUnit();

            start_Choice2.Metadata[TargetContentUnitID] = "wait";
            start_Choice2.Content[Text] = "Wait";

            ContentUnit openDoor = new ContentUnit();

            openDoor.Metadata[ContentUnitID] = "open door";
            openDoor.Content[Text]           = "Opening the door, you step forth into adventure.";

            ContentUnit waited = new ContentUnit();

            waited.Metadata[ContentUnitID] = "wait";
            waited.Content[Text]           = "You wait fruitlessly in front the door.";

            ContentUnit waitedChoice1 = new ContentUnit();

            waitedChoice1.Metadata[TargetContentUnitID] = "waited again";
            waitedChoice1.Content[Text] = "Wait again";

            ContentUnit waitedChoice2 = new ContentUnit();

            waitedChoice2.Metadata[TargetContentUnitID] = "open door after waiting";
            waitedChoice2.Content[Text] = "Finally open the door";

            ContentUnit waitedAgain = new ContentUnit();

            waitedAgain.Metadata[ContentUnitID] = "waited again";
            waitedAgain.Content[Text]           = "Sunk in a deep malaise, you wait the rest of your life.";

            ContentUnit openDoorAfterWaiting = new ContentUnit();

            openDoorAfterWaiting.Metadata[ContentUnitID] = "open door after waiting";
            openDoorAfterWaiting.Content[Text]           = "Breaking through your reservations, you step forward into a life of adventure.";

            blackboard.AddUnit(start);
            blackboard.AddUnit(start_Choice1);
            blackboard.AddUnit(start_Choice2);
            blackboard.AddUnit(openDoor);
            blackboard.AddUnit(waited);
            blackboard.AddUnit(waitedChoice1);
            blackboard.AddUnit(waitedChoice2);
            blackboard.AddUnit(waitedAgain);
            blackboard.AddUnit(openDoorAfterWaiting);

            blackboard.AddLink(start, start_Choice1, LinkTypes.L_Choice);
            blackboard.AddLink(start, start_Choice2, LinkTypes.L_Choice);
            blackboard.AddLink(waited, waitedChoice1, LinkTypes.L_Choice);
            blackboard.AddLink(waited, waitedChoice2, LinkTypes.L_Choice);
        }
        public static void Demo1_KC_DefineUnits(IBlackboard blackboard)
        {
            Unit start = new Unit();

            start.AddComponent(new KC_UnitID("start", true));
            start.AddComponent(new KC_Text("You stand before an old wooden door.", true));

            Unit start_Choice1 = new Unit();

            start_Choice1.AddComponent(new KC_IDSelectionRequest("open door", true));
            start_Choice1.AddComponent(new KC_Text("Open the door", true));

            Unit start_Choice2 = new Unit();

            start_Choice2.AddComponent(new KC_IDSelectionRequest("wait", true));
            start_Choice2.AddComponent(new KC_Text("Wait", true));

            Unit openDoor = new Unit();

            openDoor.AddComponent(new KC_UnitID("open door", true));
            openDoor.AddComponent(new KC_Text("Opening the door, you step forth into adventure.", true));

            Unit waited = new Unit();

            waited.AddComponent(new KC_UnitID("wait", true));
            waited.AddComponent(new KC_Text("You wait fruitlessly in front the door.", true));

            Unit waitedChoice1 = new Unit();

            waitedChoice1.AddComponent(new KC_IDSelectionRequest("waited again", true));
            waitedChoice1.AddComponent(new KC_Text("Wait again", true));

            Unit waitedChoice2 = new Unit();

            waitedChoice2.AddComponent(new KC_IDSelectionRequest("open door after waiting", true));
            waitedChoice2.AddComponent(new KC_Text("Finally open the door", true));

            Unit waitedAgain = new Unit();

            waitedAgain.AddComponent(new KC_UnitID("waited again", true));
            waitedAgain.AddComponent(new KC_Text("Sunk in a deep malaise, you wait the rest of your life.", true));

            Unit openDoorAfterWaiting = new Unit();

            openDoorAfterWaiting.AddComponent(new KC_UnitID("open door after waiting", true));
            openDoorAfterWaiting.AddComponent(new KC_Text("Breaking through your reservations, you step forward into a life of adventure.", true));

            blackboard.AddUnit(start);
            blackboard.AddUnit(start_Choice1);
            blackboard.AddUnit(start_Choice2);
            blackboard.AddUnit(openDoor);
            blackboard.AddUnit(waited);
            blackboard.AddUnit(waitedChoice1);
            blackboard.AddUnit(waitedChoice2);
            blackboard.AddUnit(waitedAgain);
            blackboard.AddUnit(openDoorAfterWaiting);

            blackboard.AddLink(start, start_Choice1, LinkTypes.L_Choice);
            blackboard.AddLink(start, start_Choice2, LinkTypes.L_Choice);
            blackboard.AddLink(waited, waitedChoice1, LinkTypes.L_Choice);
            blackboard.AddLink(waited, waitedChoice2, LinkTypes.L_Choice);
        }
        /*
         * Adds ContentUnits to blackboard for demo2, a choice-based demo with prolog applicability tests for choice setups.
         */
        public static void Demo2_DefineUnits(IBlackboard blackboard)
        {
            Unit start = new Unit();

            start.AddComponent(new KC_UnitID("start", true));
            start.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "true.", true));
            start.AddComponent(new KC_Text("An old gentleman stands before you.", true));

            Unit choice_AskForHelp = new Unit();

            choice_AskForHelp.AddComponent(new KC_IDSelectionRequest("ask for help", true));
            choice_AskForHelp.AddComponent(new KC_Text("Ask for help", true));

            Unit choice_introduceYourself = new Unit();

            choice_introduceYourself.AddComponent(new KC_IDSelectionRequest("introduce yourself", true));
            choice_introduceYourself.AddComponent(new KC_PrologFactAddList(new string[] { "introducedYourself" }, true));
            choice_introduceYourself.AddComponent(new KC_Text("Introduce yourself", true));

            Unit askForHelp1 = new Unit();

            askForHelp1.AddComponent(new KC_UnitID("ask for help", true));
            askForHelp1.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "introducedYourself.", true));
            askForHelp1.AddComponent(new KC_Text("'Since you introduced yourself so nicely, I'm happy to help!'", true));

            Unit askForHelp2 = new Unit();

            askForHelp2.AddComponent(new KC_UnitID("ask for help", true));
            askForHelp2.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "\\+ introducedYourself.", true));
            askForHelp2.AddComponent(new KC_Text("Eyeing you suspiciously the old man replies 'Who are you?'", true));

            Unit introduceYourself = new Unit();

            introduceYourself.AddComponent(new KC_UnitID("introduce yourself", true));
            introduceYourself.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "true.", true));
            introduceYourself.AddComponent(new KC_Text("'Very nice to meet you!'", true));

            blackboard.AddUnit(start);
            blackboard.AddUnit(choice_AskForHelp);
            blackboard.AddUnit(choice_introduceYourself);
            blackboard.AddUnit(askForHelp1);
            blackboard.AddUnit(askForHelp2);
            blackboard.AddUnit(introduceYourself);

            blackboard.AddLink(start, choice_AskForHelp, LinkTypes.L_Choice);
            blackboard.AddLink(start, choice_introduceYourself, LinkTypes.L_Choice);
            blackboard.AddLink(askForHelp2, choice_AskForHelp, LinkTypes.L_Choice);
            blackboard.AddLink(askForHelp2, choice_introduceYourself, LinkTypes.L_Choice);
            blackboard.AddLink(introduceYourself, choice_AskForHelp, LinkTypes.L_Choice);

            Unit        prologKBUnit = new Unit();
            KC_PrologKB prologKB     = new KC_PrologKB("Global", true);

            prologKBUnit.AddComponent(prologKB);

            /*
             * fixme: is there a better way to define a predicate for prolog than asserting and retracting it?
             */
            prologKB.Assert("introducedYourself.");
            prologKB.Retract("introducedYourself.");

            blackboard.AddUnit(prologKBUnit);
        }