private static MyTreeNode FactWay(KnowledgeBase KB, Fact fct, Fact Goal) { if (++StepCount > MaxStepCount) { StepCount--; return(null); } MyTreeNode Res = new MyTreeNode(fct); if ((fct.Name == Library.StandartOperations[0].ToString()) || (fct.Name == Library.StandartOperations[1].ToString())) { Res.Left = FactWay(KB, (Fact)fct.LeftArg, Goal); Res.Right = FactWay(KB, (Fact)fct.RightArg, Goal); if ((Res.Left == null) && (Res.Right == null)) { Res = null; } } else if (fct.IsEqualTo(Goal)) { Res.SelfWay = new MyTreeNode(Goal); } else { foreach (EBCell rcell in KB.BaseOfRules) { Rule rul = (Rule)rcell.Value; if (rul.IfExpression.IsEqualTo(fct)) { Res.SelfWay = FactWay(KB, (Fact)rul.ThenExpression, Goal); } } if (Res.SelfWay == null) { Res = null; } } StepCount--; return(Res); }
private static bool TryThenExpression(Fact ThenExpression, Fact Goal) { return(ThenExpression.IsEqualTo(Goal)); }