public void Consult(string path) { KB.Consult(path); }
public bool Evaluate(KB kb, Name perspective, IEnumerable <SubstitutionSet> constraints) { return(UnifyEvaluate(kb, perspective, constraints).Any()); }
public static void KeyboardEvent(string s, KB kb) { User.Struct.INPUT input = new User.Struct.INPUT(User.Const.INPUT_KEYBOARD); input.ki.dwExtraInfo = User.GetMessageExtraInfo(); KeyDown(kb); foreach (char c in s) { input.ki.wVk = 0; input.ki.wScan = c; input.ki.dwFlags = User.Const.KEYEVENTF_UNICODE; SendInput(input); input.ki.dwFlags = User.Const.KEYEVENTF_UNICODE | User.Const.KEYEVENTF_KEYUP; SendInput(input); } KeyUp(kb); }
private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > GetEmotionsForEntity(IEmotionalState state, Name emotionName, KB kb, Name perspective, IEnumerable <SubstitutionSet> constraints) { if (emotionName.IsVariable) { foreach (var emotion in state.GetAllEmotions()) { var sub = new Substitution(emotionName, (Name)emotion.EmotionType); foreach (var c in constraints) { if (c.Conflicts(sub)) { continue; } var newConstraints = new SubstitutionSet(c); newConstraints.AddSubstitution(sub); yield return(Tuples.Create((PrimitiveValue)emotion.Intensity, newConstraints)); } } } else { foreach (var resultPair in kb.AskPossibleProperties(emotionName, perspective, constraints)) { string emotionKey = resultPair.Item1.ToString(); var emotion = state.GetEmotionsByType(emotionKey).OrderByDescending(e => e.Intensity).FirstOrDefault(); PrimitiveValue value = emotion == null ? 0 : emotion.Intensity; foreach (var c in resultPair.Item2) { yield return(Tuples.Create(value, c)); } } } }
/// <summary> /// Appraises a set of event strings. /// /// Durring appraisal, the events will be recorded in the asset's autobiographical memory, /// and Property Change Events will update the asset's knowledge about the world, allowing /// the asset to use the new information derived from the events to appraise the correspondent /// emotions. /// </summary> /// <param name="eventNames">A set of string representation of the events to appraise</param> public void AppraiseEvents(IEnumerable <Name> eventNames, Name perspective, IEmotionalState emotionalState, AM am, KB kb) { var appraisalFrame = new InternalAppraisalFrame(); appraisalFrame.Perspective = kb.Perspective; foreach (var n in eventNames) { var evt = am.RecordEvent(n, am.Tick); var propEvt = evt as IPropertyChangedEvent; if (propEvt != null) { var fact = propEvt.Property; var value = Name.BuildName("-"); if (propEvt.NewValue.IsPrimitive) { value = propEvt.NewValue; if (value.ToString() == "-") { var remove = kb.GetAllBeliefs().Where(x => x.Name == fact); kb.removeBelief(fact); } else { kb.Tell(fact, value, perspective); } } else // new value is not grounded { var values = kb.AskPossibleProperties(propEvt.NewValue, perspective, new List <SubstitutionSet>()); if (values.Count() == 1) { kb.Tell(fact, values.FirstOrDefault().Item1.Value, perspective); } else { throw new Exception("Multiple possible values for " + propEvt.NewValue); } } } appraisalFrame.Reset(evt); var componentFrame = appraisalFrame.RequestComponentFrame(m_appraisalDerivator, m_appraisalDerivator.AppraisalWeight); m_appraisalDerivator.Appraisal(kb, evt, componentFrame); UpdateEmotions(appraisalFrame, emotionalState, am); } }
private void BindCalls(KB kb) { kb.RegistDynamicProperty(MOOD_TEMPLATE, MoodPropertyCalculator, new[] { "x" }); kb.RegistDynamicProperty(STRONGEST_EMOTION_TEMPLATE, StrongestEmotionCalculator, new[] { "x" }); kb.RegistDynamicProperty(EMOTION_INTENSITY_TEMPLATE, EmotionIntensityPropertyCalculator, new[] { "x", "y" }); }
private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > StrongestEmotionCalculator(KB kb, Name perspective, IDictionary <string, Name> args, IEnumerable <SubstitutionSet> constraints) { if (perspective != Name.SELF_SYMBOL) { yield break; } Name arg = args["x"]; var emo = m_emotionalState.GetStrongestEmotion(); if (emo == null) { yield break; } var emoValue = (PrimitiveValue)emo.EmotionType; if (arg.IsVariable) { var sub = new Substitution(arg, kb.Perspective); foreach (var c in constraints) { if (c.AddSubstitution(sub)) { yield return(Tuples.Create(emoValue, c)); } } } else { foreach (var resultPair in kb.AskPossibleProperties(arg, perspective, constraints)) { foreach (var c in resultPair.Item2) { yield return(Tuples.Create(emoValue, c)); } } } }
public void Test_Simple_Tell_Invalid(Name name, object value, Type expectedException) { var kb = new KB((Name)"Me"); Assert.Throws(expectedException, () => kb.Tell(name, Name.BuildName(value))); }
public void Test_Tell_Fail_NonConstant_Property(string propertyName) { var kb = new KB((Name)"John"); Assert.Throws <ArgumentException>(() => kb.Tell((Name)propertyName, Name.BuildName(true))); }
//public List<int> UnequipapbleTorches; //public PreWorldState(KB knowledgeBase, List<int> guidTorches, Pair<string, int> equipped) public PreWorldState(KB knowledgeBase) { //this.UnequipapbleTorches = guidTorches; this.KnowledgeBase = knowledgeBase; this.Entities = new List <ObjectProperties>(); this.Inventory = new List <Tuple <string, int, int> >(); this.Equipped = new List <Pair <string, int> >(); this.Fuel = new List <Tuple <string, int, int> >(); this.Fire = new List <Tuple <string, int, int> >(); //Getting Character Stats var hp = knowledgeBase.AskProperty((Name)"Health(Walter)"); int HP = int.Parse(hp.Value.ToString()); var hunger = knowledgeBase.AskProperty((Name)"Hunger(Walter)"); //Console.WriteLine(hunger); int Hunger = int.Parse(hunger.Value.ToString()); //Console.WriteLine(Hunger); var sanity = knowledgeBase.AskProperty((Name)"Sanity(Walter)"); int Sanity = int.Parse(sanity.Value.ToString()); var posx = knowledgeBase.AskProperty((Name)"PosX(Walter)"); var PosX = int.Parse(posx.Value.ToString()); var posz = knowledgeBase.AskProperty((Name)"PosZ(Walter)"); var PosZ = int.Parse(posz.Value.ToString()); this.Walter = new Character(HP, Hunger, Sanity, PosX, PosZ); //Getting Day Properties var cycle = knowledgeBase.AskProperty((Name)"World(CurrentSegment)"); this.Cycle = float.Parse(cycle.Value.ToString()); var cycleinfo1 = knowledgeBase.AskProperty((Name)"World(PhaseLenght, day)"); var Cycleinfo1 = int.Parse(cycleinfo1.Value.ToString()); var cycleinfo2 = knowledgeBase.AskProperty((Name)"World(PhaseLenght, dusk)"); var Cycleinfo2 = int.Parse(cycleinfo2.Value.ToString()); var cycleinfo3 = knowledgeBase.AskProperty((Name)"World(PhaseLenght, night)"); var Cycleinfo3 = int.Parse(cycleinfo3.Value.ToString()); this.CycleInfo = new int[3]; this.CycleInfo[0] = Cycleinfo1; this.CycleInfo[1] = Cycleinfo2; this.CycleInfo[2] = Cycleinfo3; //Getting Entities + Inventory + Equipped var subset = new List <SubstitutionSet> { new SubstitutionSet() }; //Getting Equipped var equippeditems = knowledgeBase.AskPossibleProperties((Name)"IsEquipped([GUID])", Name.SELF_SYMBOL, subset); //if (equipped.Item1 != "" && equipped.Item2 == 0) //{ // foreach (var item in equippeditems) // { // string strEntGuid = item.Item2.FirstOrDefault().FirstOrDefault().SubValue.Value.ToString(); // int entGuid = int.Parse(strEntGuid); // string entPrefab = knowledgeBase.AskProperty((Name)("Entity(" + strEntGuid + ")")).Value.ToString(); // if (entPrefab == equipped.Item1) // { // string strEntQuantity = "Quantity(" + strEntGuid + ")"; // var quantity = knowledgeBase.AskProperty((Name)strEntQuantity); // int entQuantity = int.Parse(quantity.Value.ToString()); // Pair<string, int> tuple = new Pair<string, int>(entPrefab, entGuid); // this.Equipped.Add(tuple); // break; // } // } //} //else if (equipped.Item2 != 0) //{ // this.Equipped.Add(equipped); //} foreach (var item in equippeditems) { string strEntGuid = item.Item2.FirstOrDefault().FirstOrDefault().SubValue.Value.ToString(); int entGuid = int.Parse(strEntGuid); string entPrefab = knowledgeBase.AskProperty((Name)("Entity(" + strEntGuid + ")")).Value.ToString(); Pair <string, int> pair = new Pair <string, int>(entPrefab, entGuid); this.Equipped.Add(pair); } //Getting Inventory var inventory = knowledgeBase.AskPossibleProperties((Name)"InInventory([GUID])", Name.SELF_SYMBOL, subset); foreach (var item in inventory) { string strEntGuid = item.Item2.FirstOrDefault().FirstOrDefault().SubValue.Value.ToString(); int entGuid = int.Parse(strEntGuid); string entPrefab = knowledgeBase.AskProperty((Name)("Entity(" + strEntGuid + ")")).Value.ToString(); string strEntQuantity = "Quantity(" + strEntGuid + ")"; var quantity = knowledgeBase.AskProperty((Name)strEntQuantity); int entQuantity = int.Parse(quantity.Value.ToString()); Tuple <string, int, int> tuple = new Tuple <string, int, int>(entPrefab, entGuid, entQuantity); this.Inventory.Add(tuple); if (IsFuel(strEntGuid)) { this.Fuel.Add(tuple); } } //Getting Entities var entities = knowledgeBase.AskPossibleProperties((Name)"Entity([GUID])", Name.SELF_SYMBOL, subset); foreach (var entity in entities) { Boolean b = false; string strEntGuid = entity.Item2.FirstOrDefault().FirstOrDefault().SubValue.Value.ToString(); int entGuid = int.Parse(strEntGuid); string entPrefab = entity.Item1.Value.ToString(); string realEntPrefab = RealEntityPrefab(entPrefab); if (IsFire(entPrefab)) { string strEntPosx = "PosX(" + strEntGuid + ")"; var POSx = knowledgeBase.AskProperty((Name)strEntPosx); int entPosx = int.Parse(POSx.Value.ToString()); string strEntPosz = "PosZ(" + strEntGuid + ")"; var POSz = knowledgeBase.AskProperty((Name)strEntPosz); int entPosz = int.Parse(POSz.Value.ToString()); Tuple <string, int, int> tuple = new Tuple <string, int, int>(entPrefab, entPosx, entPosz); this.Fire.Add(tuple); } else if (realEntPrefab != "" && DistanceCalculator(strEntGuid) > 0) { string strEntIsCollectable = "IsCollectable(" + strEntGuid + ")"; var isCollectable = knowledgeBase.AskProperty((Name)strEntIsCollectable); Boolean entIsCollectable = Boolean.Parse(isCollectable.Value.ToString()); string strEntIsPickable = "IsPickable(" + strEntGuid + ")"; var isPickable = knowledgeBase.AskProperty((Name)strEntIsPickable); Boolean entIsPickable = Boolean.Parse(isPickable.Value.ToString()); string strEntIsMineable = "IsMineable(" + strEntGuid + ")"; var isMineable = knowledgeBase.AskProperty((Name)strEntIsMineable); Boolean entIsMineable = Boolean.Parse(isMineable.Value.ToString()); string strEntIsChoppable = "IsChoppable(" + strEntGuid + ")"; var isChoppable = knowledgeBase.AskProperty((Name)strEntIsChoppable); Boolean entIsChoppable = Boolean.Parse(isChoppable.Value.ToString()); if (entIsPickable || entIsCollectable || entIsMineable || entIsChoppable) { string strEntQuantity = "Quantity(" + strEntGuid + ")"; var quantity = knowledgeBase.AskProperty((Name)strEntQuantity); int entQuantity = int.Parse(quantity.Value.ToString()); string strEntPosx = "PosX(" + strEntGuid + ")"; var POSx = knowledgeBase.AskProperty((Name)strEntPosx); int entPosx = int.Parse(POSx.Value.ToString()); string strEntPosz = "PosZ(" + strEntGuid + ")"; var POSz = knowledgeBase.AskProperty((Name)strEntPosz); int entPosz = int.Parse(POSz.Value.ToString()); foreach (ObjectProperties objectproperty in this.Entities) { if (objectproperty.Prefab == realEntPrefab) { objectproperty.Add(entQuantity, entPrefab, entGuid, entPosx, entPosz, this.Walter); b = true; break; } } if (!b) { ObjectProperties newObjectproperty = new ObjectProperties(realEntPrefab, entPrefab, entGuid, entQuantity, entPosx, entPosz, entIsCollectable, entIsPickable, entIsMineable, entIsChoppable); this.Entities.Add(newObjectproperty); } } } } }
public void Test_Simple_Tell_Valid(Name name, object value) { var kb = new KB((Name)"Me"); kb.Tell(name, Name.BuildName(value)); }
public HandEvaluater(KB kB) { this.kB = kB; }
protected abstract IEnumerable <SubstitutionSet> CheckActivation(KB kb, Name perspective, IEnumerable <SubstitutionSet> constraints);
public bool IsTrueParsed(string query) { return(KB.IsTrue(ISOPrologReader.Read(query))); }
public void AppraiseEvents(IEnumerable <Name> eventNames, IEmotionalState emotionalState, AM am, KB kb, Dictionary <string, Goal> goals) { AppraiseEvents(eventNames, Name.SELF_SYMBOL, emotionalState, am, kb, goals); }
public void Test_Fail_Tell_With_Nil_Perspective() { var kb = new KB(Name.BuildName("Mark")); Assert.Throws <ArgumentException>(() => kb.Tell(Name.BuildName("IsPerson(Self)"), Name.BuildName(true), Name.NIL_SYMBOL)); }
private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > SIPropertyCalculator(KB kb, Name perspective, IDictionary <string, Name> args, IEnumerable <SubstitutionSet> constraints) { Name target; if (!args.TryGetValue("target", out target)) { yield break; } foreach (var t in kb.AskPossibleProperties(target, perspective, constraints)) { var si = GetSocialImportance(Name.BuildName(t.Item1), perspective); foreach (var s in t.Item2) { yield return(new Pair <PrimitiveValue, SubstitutionSet>(si, s)); } } }
public void Test_Tell_Fail_Add_Self_To_Universal_Context() { var kb = new KB((Name)"John"); Assert.Throws <InvalidOperationException>(() => kb.Tell((Name)"Likes(Self)", Name.BuildName(true), Name.UNIVERSAL_SYMBOL)); }
private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > MoodPropertyCalculator(KB kb, Name perspective, IDictionary <string, Name> args, IEnumerable <SubstitutionSet> constraints) { if (perspective != Name.SELF_SYMBOL) { yield break; } Name arg = args["x"]; if (arg.IsVariable) { var sub = new Substitution(arg, kb.Perspective); foreach (var c in constraints) { if (c.AddSubstitution(sub)) { yield return(Tuples.Create((PrimitiveValue)m_emotionalState.Mood, c)); } } } else { foreach (var resultPair in kb.AskPossibleProperties(arg, perspective, constraints)) { var v = (PrimitiveValue)m_emotionalState.Mood; foreach (var c in resultPair.Item2) { yield return(Tuples.Create(v, c)); } } } }
public void Test_Tell_Fail_Add_Self_To_Universal() { var kb = new KB(Name.BuildName("Matt")); Assert.Throws <InvalidOperationException>(() => { kb.Tell((Name)"IsPerson(Self)", Name.BuildName(true), Name.UNIVERSAL_SYMBOL); }); }
private IEnumerable <Pair <PrimitiveValue, SubstitutionSet> > EmotionIntensityPropertyCalculator(KB kb, Name perspective, IDictionary <string, Name> args, IEnumerable <SubstitutionSet> constraints) { List <Pair <PrimitiveValue, SubstitutionSet> > result = new List <Pair <PrimitiveValue, SubstitutionSet> >(); if (perspective != Name.SELF_SYMBOL) { return(result); } Name entity = args["x"]; Name emotionName = args["y"]; if (entity.IsVariable) { var newSub = new Substitution(entity, kb.Perspective); var newC = constraints.Where(c => c.AddSubstitution(newSub)); if (newC.Any()) { result.AddRange(GetEmotionsForEntity(m_emotionalState, emotionName, kb, perspective, newC)); } } else { foreach (var resultPair in kb.AskPossibleProperties(entity, perspective, constraints)) { result.AddRange(GetEmotionsForEntity(m_emotionalState, emotionName, kb, perspective, resultPair.Item2)); } } return(result); }
public void Test_DynamicProperty_Regist_Fail_InvalidTemplate() { var kb = new KB((Name)"Me"); Assert.Throws <ArgumentException>(() => kb.RegistDynamicProperty((Name)"CountSubs(John)", "", DummyCount)); }
/// <summary> /// The Comme ill Faut constructor /// </summary> public CommeillFautAsset() { m_kB = null; m_SocialExchanges = new List <SocialExchange>(); }
public void Test_DynamicProperty_Regist_Fail_Null_Surogate() { var kb = new KB((Name)"Me"); Assert.Throws <ArgumentNullException>(() => kb.RegistDynamicProperty((Name)"CountSubs", "", (DynamicPropertyCalculator_T1)null)); }
public void AppraiseEvents(IEnumerable <Name> eventNames, IEmotionalState emotionalState, AM am, KB kb) { AppraiseEvents(eventNames, Name.SELF_SYMBOL, emotionalState, am, kb); }
public void Test_Tell_Fail_Assert_Perspective(string perspective, Type exceptionType) { var kb = new KB((Name)"John"); Assert.Throws(exceptionType, () => kb.Tell((Name)"Likes(Mary)", Name.BuildName(true), (Name)perspective)); }
public static void KeyboardEvent(User.VK vk, KB kb) { User.Struct.INPUT input = new User.Struct.INPUT(User.Const.INPUT_KEYBOARD); input.ki.dwExtraInfo = User.GetMessageExtraInfo(); KeyDown(kb); // Key down the actual key-code input.ki.wVk = (ushort)vk; SendInput(input); // Key up the actual key-code input.ki.dwFlags = User.Const.KEYEVENTF_KEYUP; SendInput(input); KeyUp(kb); }
public void Test_Tell_Fail_Property_ToM_Transform(string property, string perspective) { var kb = new KB((Name)"John"); Assert.Throws <ArgumentException>(() => kb.Tell((Name)property, Name.BuildName(true), (Name)perspective)); }
public static void KeyUp(KB kb) { User.Struct.INPUT input = new User.Struct.INPUT(User.Const.INPUT_KEYBOARD); input.ki.dwExtraInfo = User.GetMessageExtraInfo(); // Key down shift, ctrl, and/or alt input.ki.dwFlags = User.Const.KEYEVENTF_KEYUP; if ((kb & KB.KB_SHIFT) == KB.KB_SHIFT) { input.ki.wVk = (ushort)User.VK.VK_SHIFT; SendInput(input); } if ((kb & KB.KB_CONTROL) == KB.KB_CONTROL) { input.ki.wVk = (ushort)User.VK.VK_CONTROL; SendInput(input); } if ((kb & KB.KB_ALT) == KB.KB_ALT) { input.ki.wVk = (ushort)User.VK.VK_MENU; SendInput(input); } if ((kb & KB.KB_WIN) == KB.KB_WIN) { input.ki.wVk = (ushort)User.VK.VK_LWIN; SendInput(input); } }
public float VolitionValue(Name step, Name targ, Name mode, KB m_Kb) { if (m_Kb.Perspective == targ) { return(-1); } var targetSub = new Substitution(Target, new ComplexValue(targ)); var constraints = new SubstitutionSet(); constraints.AddSubstitution(targetSub); float total = Single.NegativeInfinity; // List<SubstitutionSet> resultingConstraints = new List<SubstitutionSet>(); if (step == this.Steps.FirstOrDefault()) { var resultingConstraints = StartingConditions.FirstOrDefault().Unify(m_Kb, m_Kb.Perspective, new[] { constraints }).ToList(); if (StartingConditions.Count() > 1) { int counter = 0; foreach (var c in StartingConditions) // For instance SI([x]) >= 40 { if (counter == 0) { continue; } resultingConstraints = c.Unify(m_Kb, m_Kb.Perspective, resultingConstraints).ToList(); // Whats the sub here [x]/John } } if (resultingConstraints.Count() == 0) { return(total); } foreach (var res in resultingConstraints) { if (resultingConstraints.Count() > 0) // Assuming all Starting COnditions match lets go into the Influence Rules { foreach (var constraint in resultingConstraints) // var condition = c.ToString(); { var contraintVolitionValue = .0f; // var certainty = res.FindMinimumCertainty(); // How do I ask SI(John) >= 40 and get its certainty //total += certainty; var influenceRuleList = new List <InfluenceRule>(); if (mode.IsUniversal) { influenceRuleList = this.InfluenceRules; } else { influenceRuleList = this.InfluenceRules.FindAll(x => x.Mode == mode); } foreach (var inf in influenceRuleList) { var toSum = inf.EvaluateInfluenceRule(m_Kb, constraint); contraintVolitionValue += toSum; } if (contraintVolitionValue > total) { total = contraintVolitionValue; } } } } //What if the step is beyond the first one, we should not consider Starting Conditions, or any conditions at all, only the influence rules } else { var VolVal = .0f; var influenceRuleList = new List <InfluenceRule>(); if (mode.IsUniversal) { influenceRuleList = this.InfluenceRules; } else { influenceRuleList = this.InfluenceRules.FindAll(x => x.Mode == mode); } foreach (var inf in influenceRuleList) { var toSum = inf.EvaluateInfluenceRule(m_Kb, constraints); VolVal += toSum; } if (VolVal > total) { total = VolVal; } } return(total); }