http://youtu.be/PWcW6ZuLLJE
The expert system shell support major features such as forward, backward chaining, etc. Below is the code snippet for the human agent expert shell code:
RuleInferenceEngine rie = new RuleInferenceEngine(); Rule rule = new Rule("Rule 1"); rule.AddAntecedent(new IsClause("IsTargetVisible", "yes")); rule.AddAntecedent(new IsClause("IsTargetAvailable", "yes")); rule.AddAntecedent(new IsClause("IsCourageous", "yes")); rule.AddAntecedent(new IsClause("IsUnderAttack", "no")); rule.setConsequent(new IsClause("Action", "PursuitTarget")); rie.AddRule(rule); rule = new Rule("Rule 2"); rule.AddAntecedent(new IsClause("IsUnderAttack", "yes")); rule.AddAntecedent(new IsClause("IsTargetAvailable", "yes")); rule.setConsequent(new IsClause("Action", "Attack")); rie.AddRule(rule); rule = new Rule("Rule 3"); rule.AddAntecedent(new IsClause("IsTargetAvailable", "yes")); rule.AddAntecedent(new IsClause("IsCourageous", "no")); rule.AddAntecedent(new IsClause("IsUnderAttack", "no")); rule.setConsequent(new IsClause("Action", "RunawayFromTarget")); rie.AddRule(rule); rule = new Rule("Rule 4"); rule.AddAntecedent(new IsClause("IsTargetAvailable", "no")); rule.AddAntecedent(new IsClause("IsFighting", "yes")); rule.setConsequent(new IsClause("IsFighting", "no")); rie.AddRule(rule);Below is the partial code the invoke the expert system for decision making in the human agent
mExpertSystem.ClearFacts(); mExpertSystem.AddFact(new IsClause("IsUnderAttack", is_under_attack ? "yes" : "no")); mExpertSystem.AddFact(new IsClause("IsTargetVisible", mTarget != null && closest < SpotDistance ? "yes" : "no")); mExpertSystem.AddFact(new IsClause("IsTargetAvailable", mTarget != null ? "yes" : "no")); mExpertSystem.AddFact(new IsClause("IsCourageous", mWorld.Random.Next(9) + 1 > mCourage ? "yes" : "no")); List<clause> unproved_conditions = new List<clause>(); Clause conclusion = mExpertSystem.Infer("Action", unproved_conditions); if (conclusion == null) { System.Console.WriteLine(mExpertSystem.Facts.ToString()); Console.WriteLine("/////////////////////////////////////"); return; } if (conclusion.getValue() == "Attack") { mFighting = true; mMode = MentalState.Aggressive; mTarget.IsAttacked((int)Math.Floor(mWorld.Random.NextDouble() * mStrength)); }Below are some images showing the ZombieSim Game rewritten using Expert System Shell and Agent-Based Modeling:
No comments:
Post a Comment