public static void SelectChoice_PrologKBChanges(object sender, SelectChoiceEventArgs eventArgs) { Unit selectedChoice = eventArgs.SelectedChoice; var prologKBQuery = from unit in eventArgs.Blackboard.LookupUnits <Unit>() where unit.HasComponent <KC_PrologKB>() select unit; // Currently only support one global KB. Debug.Assert(prologKBQuery.Count() == 1); KC_PrologKB prologKB = prologKBQuery.First().GetComponent <KC_PrologKB>(); // If there are any facts to retract, retract them if (selectedChoice.HasComponent <KC_PrologFactDeleteList>()) { selectedChoice.GetComponent <KC_PrologFactDeleteList>().DeleteFacts(prologKB); } // If there are any facts to add, add them if (selectedChoice.HasComponent <KC_PrologFactAddList>()) { selectedChoice.GetComponent <KC_PrologFactAddList>().AddFacts(prologKB); } }
/* * 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); }
public static void DemoEnsemble_DefineUnits(IBlackboard blackboard) { Unit rule = new Unit(); rule.AddComponent(new KC_UnitID("If you haven't said hello, you're likely to say hello.", true)); rule.AddComponent(new KC_IDSelectionRequest("greeting", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "\\+ saidHello.", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've already said hello, less likely to do it again.", true)); rule.AddComponent(new KC_IDSelectionRequest("greeting", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "saidHello.", true)); rule.AddComponent(new KC_Utility(-5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've already said hello, you are more likely to ask how they have been doing.", true)); rule.AddComponent(new KC_IDSelectionRequest("askDay", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "saidHello.", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've already asked how they are doing, you are less likely to ask again.", true)); rule.AddComponent(new KC_IDSelectionRequest("askDay", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "askDay.", true)); rule.AddComponent(new KC_Utility(-5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've already asked how they are doing, you are less likely to ask again.", true)); rule.AddComponent(new KC_IDSelectionRequest("askDayReverse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "askDay.", true)); rule.AddComponent(new KC_Utility(-5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've have been asked how they have been doing, you should respond.", true)); rule.AddComponent(new KC_IDSelectionRequest("neutralResponse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "askDay.", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've have been asked how they have been doing, you should respond.", true)); rule.AddComponent(new KC_IDSelectionRequest("goodResponse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "askDay.", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you've have been asked how they have been doing, you should respond.", true)); rule.AddComponent(new KC_IDSelectionRequest("badResponse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "askDay.", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If your friend is doing well or okay, congradulate them.", true)); rule.AddComponent(new KC_IDSelectionRequest("congratulate", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "response(good); response(neutral).", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If your friend is doing bad, console them.", true)); rule.AddComponent(new KC_IDSelectionRequest("console", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "response(bad).", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you have already said how you are doing, don't say it again.", true)); rule.AddComponent(new KC_IDSelectionRequest("goodResponse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "response(X).", true)); rule.AddComponent(new KC_Utility(-5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you have already said how you are doing, don't say it again.", true)); rule.AddComponent(new KC_IDSelectionRequest("badResponse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "response(X).", true)); rule.AddComponent(new KC_Utility(-5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you have already said how you are doing, don't say it again.", true)); rule.AddComponent(new KC_IDSelectionRequest("neutralResponse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "response(X).", true)); rule.AddComponent(new KC_Utility(-5, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); rule = new Unit(); rule.AddComponent(new KC_UnitID("If you have told someone how your day has been, ask them in return.", true)); rule.AddComponent(new KC_IDSelectionRequest("askDayReverse", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "askDay, (congratulate; console).", true)); rule.AddComponent(new KC_Utility(10, true)); rule.AddComponent(new KC_ContentPool(DemoEnsembleLite.RulesPool, true)); blackboard.AddUnit(rule); Unit dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("greeting", true)); dialogue.AddComponent(new KC_Text("Hello there", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "saidHello" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("askDay", true)); dialogue.AddComponent(new KC_Text("How is your day going?", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "askDay" }, true)); dialogue.AddComponent(new KC_PrologFactDeleteList(new string[] { "response(X)" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("askDayReverse", true)); dialogue.AddComponent(new KC_Text("And you?", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "askDay" }, true)); dialogue.AddComponent(new KC_PrologFactDeleteList(new string[] { "response(X)" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("neutralResponse", true)); dialogue.AddComponent(new KC_Text("I'm okay.", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "response(neutral)" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("goodResponse", true)); dialogue.AddComponent(new KC_Text("I'm great.", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "response(good)" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("badResponse", true)); dialogue.AddComponent(new KC_Text("I've been tired.", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "response(bad)" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("console", true)); dialogue.AddComponent(new KC_Text("That's too bad", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "console" }, true)); dialogue.AddComponent(new KC_PrologFactDeleteList(new string[] { "askDay" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); dialogue = new Unit(); dialogue.AddComponent(new KC_UnitID("congratulate", true)); dialogue.AddComponent(new KC_Text("That's good, I'm glad.", true)); dialogue.AddComponent(new KC_PrologFactAddList(new string[] { "congratulate" }, true)); dialogue.AddComponent(new KC_PrologFactDeleteList(new string[] { "askDay" }, true)); dialogue.AddComponent(new KC_ContentPool(DemoEnsembleLite.DialogPool, true)); blackboard.AddUnit(dialogue); 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("saidHello."); prologKB.Retract("saidHello."); prologKB.Assert("askDay."); prologKB.Retract("askDay."); prologKB.Assert("response(neutral)."); prologKB.Retract("response(neutral)."); prologKB.Assert("console"); prologKB.Retract("console"); prologKB.Assert("congratulate"); prologKB.Retract("congratulate"); blackboard.AddUnit(prologKBUnit); }
public static void TavernTalk_DefineUnits(IBlackboard blackboard) { //Abstract Social Moves: Unit move = new Unit(); move.AddComponent(new KC_UnitID("tell", true)); move.AddComponent(new KC_ContentPool(AbstractSocialMoves)); blackboard.AddUnit(move); move = new Unit(); move.AddComponent(new KC_UnitID("ask", true)); move.AddComponent(new KC_ContentPool(AbstractSocialMoves)); blackboard.AddUnit(move); //Character Knowledge Base Facts: /* * Structure should contain at least: * id: string * subject: string * verb: string * object: string * opinion: int * * Will likely also want things like: * time * location * state (as opposed to verb) * */ Unit fact = new Unit(); fact.AddComponent(new KC_UnitID("Alicia dating Jasper", true)); move.AddComponent(new KC_ContentPool(CharacterKnowledgeBase)); blackboard.AddUnit(fact); fact = new Unit(); fact.AddComponent(new KC_UnitID("Alicia is busy", true)); move.AddComponent(new KC_ContentPool(CharacterKnowledgeBase)); blackboard.AddUnit(fact); //Characters list: // I think this should just be the characters currently in the bar // may each eventaully have their own knowledge pool? // where is social relations stored? In Prologue? Unit character = new Unit(); character.AddComponent(new KC_UnitID("Barkeep", true)); move.AddComponent(new KC_ContentPool(Characters)); blackboard.AddUnit(character); character = new Unit(); character.AddComponent(new KC_UnitID("Marco", true)); move.AddComponent(new KC_ContentPool(Characters)); blackboard.AddUnit(character); //Social Rules: Unit rule = new Unit(); rule.AddComponent(new KC_UnitID("Ask friends stuff", true)); rule.AddComponent(new KC_PrologExpression(KCNames.ApplTest_Prolog, "ask(X).", true)); rule.AddComponent(new KC_PrologExpression(KCNames.SalienceTest_Prolog, "friends(X).", true)); rule.AddComponent(new KC_Utility(5, true)); rule.AddComponent(new KC_ContentPool(SocialRules, true)); blackboard.AddUnit(rule); //Prolog Database: 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("ask(a)."); prologKB.Retract("ask(a)."); prologKB.Assert("friends(Marco)."); prologKB.Retract("friends(Marco)."); blackboard.AddUnit(prologKBUnit); }