Exemplo n.º 1
0
        /// <summary>
        /// Check if (PropostionNo) is true in this world state
        /// -1 is goal check
        /// </summary>
        public bool?IsTrue(int PropositionNo)
        {
            int[] needed_ags;
            if (PropositionNo == -1)
            {
                needed_ags = _Goal.Requirements().ToArray();
            }
            else
            {
                needed_ags = _KnowledgeBase.Requirements(PropositionNo);
            }

            bool?[] grab_ags = new bool?[needed_ags.Length];
            for (int i = 0; i < needed_ags.Length; i++)
            {
                grab_ags[i] = Arguments[needed_ags[i]];
            }
            if (PropositionNo == -1)
            {
                return(_Goal.IsTrue(grab_ags));
            }
            else
            {
                return(_KnowledgeBase.IsTrue(PropositionNo, grab_ags));
            }
        }
Exemplo n.º 2
0
//......IsTrue............................................................
        public bool?IsTrue(bool?[] Arguements)
        {
            bool?left, right = false;
            int  leftSize = 1;

            if (IsAref())
            {
                leftSize = _ARef.Requirements().Count;
                bool?[] leftarr = new bool?[leftSize];
                Array.Copy(Arguements, 0, leftarr, 0, leftarr.Length);
                left = _ARef.IsTrue(leftarr);
            }
            else
            {
                left = Arguements[0];
            }

            if (!Single)
            {
                bool?[] rightarr = new bool?[Arguements.Length - leftSize];
                Array.Copy(Arguements, leftSize, rightarr, 0, rightarr.Length);
                if (IsBref())
                {
                    right = _BRef.IsTrue(rightarr);
                }
                else
                {
                    right = rightarr[0];
                }
            }

            // NOT
            if (ANotted)
            {
                left = !left;
            }

            if (Single)
            {
                return(left);
            }

            if (BNotted)
            {
                right = !right;
            }

            // Other Operations
            switch (Operation)
            {
            case Operations.NotSet:
                throw new System.NotSupportedException();

            case Operations.Negation:                    // NOT
                throw new System.NotSupportedException();

            case Operations.Conjunction:                 // AND
                return(left & right);

            case Operations.Disjunction:                 // OR
                return(left | right);

            case Operations.Implication:                 // True when either A value = 0 or B value = 1, thus false when neither occur
                if ((left == true) && (right == false))
                {
                    return(false);
                }
                else if ((!left | right) == true)
                {
                    return(true);
                }
                else
                {
                    return(null);
                }

            case Operations.Biconditional:               // True only when A value is equal to B value
                if ((left == null) || (right == null))
                {
                    return(null);
                }
                else if (left == right)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }

            default:
                throw new System.ArgumentException("Something went wrong ...... oh noes");
            }
        }