Example #1
0
        public int eval()
        {
            if (ifcanaddoperand())
            {
                return(2);
            }
            List <IBooleanElement> scop = s;
            bool            ans         = false;
            IBooleanElement lastoperand = null;

            for (int i = 0; i < scop.Count; i++)
            {
                if (scop[i].GetType() == typeof(BooleanOperatorNot))
                {
                    if (scop[i + 1].GetType() == typeof(BooleanOperandTrue))
                    {
                        scop[i + 1] = new BooleanOperandFalse();
                    }
                    else
                    {
                        scop[i + 1] = new BooleanOperandTrue();
                    }
                }
                if (scop[i].GetType().IsSubclassOf(typeof(BooleanOperand)) || typeof(BooleanOperand) == scop[i].GetType())
                {
                    if (lastoperand == null)
                    {
                        ans = scop[i].GetType() == typeof(BooleanOperandTrue);
                    }
                    else
                    {
                        if (lastoperand.GetType() == typeof(BooleanOperatorAnd))
                        {
                            ans = ans && scop[i].GetType() == typeof(BooleanOperandTrue);
                        }
                        if (lastoperand.GetType() == typeof(BooleanOperatorOr))
                        {
                            ans = ans || scop[i].GetType() == typeof(BooleanOperandTrue);
                        }
                        if (lastoperand.GetType() == typeof(BooleanOperatorXor))
                        {
                            ans = ans ^ scop[i].GetType() == typeof(BooleanOperandTrue);
                        }
                        lastoperand = null;
                    }
                }
                else
                {
                    lastoperand = scop[i];
                }
            }

            if (ans)
            {
                return(1);
            }
            return(0);
        }
Example #2
0
        public void domodel(List <int> a)
        {
            int q = 0;

            for (int i = 0; i < s.Count; i++)
            {
                if (s[i].GetType().IsSubclassOf(typeof(BooleanOperand)) || typeof(BooleanOperand) == s[i].GetType())
                {
                    if (a[q] == 1)
                    {
                        s[i] = new BooleanOperandTrue();
                    }
                    else if (a[q] == 0)
                    {
                        s[i] = new BooleanOperandFalse();
                    }
                    else
                    {
                        s[i] = new BooleanOperand();
                    }
                    q++;
                }
            }
        }