Exemple #1
0
 public static bool EvaluateOrList(List <TermInequality> inequalities, CustomTermEvaluater evaluator)
 {
     foreach (TermInequality ti in inequalities)
     {
         if (ti.evaluate(evaluator))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #2
0
        public override bool evaluate(CustomTermEvaluater functionsolver)
        {
            switch (type)
            {
            case Type.And:
                return(eq1.evaluate(functionsolver) && eq2.evaluate(functionsolver));

            case Type.Or:
                return(eq1.evaluate(functionsolver) || eq2.evaluate(functionsolver));

            case Type.Unary:
                return(((TermInequality)eq1).evaluate(functionsolver));
            }
            throw new NotImplementedException();
        }
Exemple #3
0
        public static List <bool> EvaluateAndListOnList(List <TermInequality> inequalities,
                                                        CustomTermEvaluater evaluator, ListEvaluationAid lea)
        {
            if (inequalities.Count == 0)
            {
                return(null);
            }
            List <bool> ret = inequalities[0].EvaluateList(evaluator, lea);

            for (int i = 1; i < inequalities.Count; ++i)
            {
                List <int> trueOnes = new List <int>();
                for (int j = 0; j < ret.Count; ++j)
                {
                    if (ret[j])
                    {
                        trueOnes.Add(j);
                    }
                }
                if (trueOnes.Count > 0)
                {
                    lea.PushIndicesToCheckList(trueOnes);
                    List <bool> tempRet = inequalities[i].EvaluateList(evaluator, lea);
                    lea.PopIndicesList();
                    List <bool> .Enumerator enumerator = tempRet.GetEnumerator();
                    foreach (int index in trueOnes)
                    {
                        enumerator.MoveNext();
                        ret[index] = enumerator.Current;
                    }
                }
                else
                {
                    return(ret);
                }
            }
            return(ret);
        }
Exemple #4
0
        public override object GetValue(CustomTermEvaluater functionsolver)
        {
            try
            {
                object o1 = term1.GetValue(functionsolver);
                bool   t1 = o1 is bool?(bool)o1 : (double)o1 != 0;

                if (type == Type.AND && !t1)
                {
                    return(false);
                }
                if (type == Type.OR && t1)
                {
                    return(true);
                }

                object o2 = term2.GetValue(functionsolver);

                bool t2 = o2 is bool?(bool)o2 : (double)o2 != 0;

                switch (type)
                {
                case Type.AND:
                    return(t1 && t2);

                case Type.OR:
                    return(t1 || t2);

                default:
                    throw new NotImplementedException();
                }
            }
            catch (Exception e)
            {
                throw e;
            }
        }
Exemple #5
0
 public override List <object> GetValuesForList(CustomTermEvaluater functionsolver, ListEvaluationAid lea)
 {
     throw new NotImplementedException();
 }
Exemple #6
0
 public override object GetValue(CustomTermEvaluater functionsolver)
 {
     return(inequality.evaluate(functionsolver));
 }
Exemple #7
0
        private List <bool> EvaluateList(CustomTermEvaluater functionsolver, ListEvaluationAid lea)
        {
            if (m_type == Type.UNARY)
            {
                List <object> ooList = ((Term)element1).GetValuesForList(functionsolver, lea);
                List <bool>   ret    = new List <bool>();
                foreach (object oo in ooList)
                {
                    if (oo is bool)
                    {
                        ret.Add((bool)oo);
                    }
                    else
                    {
                        double val = 0;
                        if (oo is double)
                        {
                            val = (double)oo;
                        }
                        else if (oo is int)
                        {
                            val = (int)oo;
                        }
                        else
                        {
                            throw new Exception("A unary TermInequality only works with a number or a bool");
                        }
                        ret.Add(val != 0);
                    }
                }
                return(ret);
            }

            List <object> o1List = ((Term)element1).GetValuesForList(functionsolver, lea);
            List <object> o2List = ((Term)element2).GetValuesForList(functionsolver, lea);

            List <object> .Enumerator o1e = o1List.GetEnumerator(), o2e = o2List.GetEnumerator();

            try
            {
                List <bool> ret = new List <bool>();
                while (o1e.MoveNext() && o2e.MoveNext())
                {
                    object o1 = o1e.Current, o2 = o2e.Current;
                    double d1 = 0;
                    if (o1 is int)
                    {
                        d1 = (int)o1;
                    }
                    else
                    {
                        d1 = (double)o1;
                    }
                    double d2 = 0;
                    if (o2 is int)
                    {
                        d2 = (int)o2;
                    }
                    else
                    {
                        d2 = (double)o2;
                    }
                    ret.Add(evaluate(d1, d2));
                }
                return(ret);
            }
            catch
            {
                throw new Exception("A TermInequality only works with two numbers");
            }
        }
Exemple #8
0
        public virtual bool evaluate(CustomTermEvaluater functionsolver)
        {
            if (m_type == Type.UNARY)
            {
                object oo = ((Term)element1).GetValue(functionsolver);
                if (oo is bool)
                {
                    return((bool)oo);
                }
                double val = 0;
                if (oo is double)
                {
                    val = (double)oo;
                }
                else if (oo is int)
                {
                    val = (int)oo;
                }
                else
                {
                    throw new Exception("A unary TermInequality only works with a number or a bool");
                }
                return(val != 0);
            }

            object o1 = ((Term)element1).GetValue(functionsolver);
            object o2 = ((Term)element2).GetValue(functionsolver);

            if (o1 is Common.Vec3 || o2 is Common.Vec3)
            {
                if (!(o1 is Common.Vec3 && o2 is Common.Vec3))
                {
                    throw new Exception("An equality can not compare a vector and a non-vector");
                }
                return(evaluate((Common.Vec3)o1, (Common.Vec3)o1));
            }

            if (o1 is string || o2 is string)
            {
                if (!(o1 is string && o2 is string))
                {
                    throw new Exception("An equality can not compare a string and a non-string");
                }
                switch (m_type)
                {
                case Type.EQUALS:
                    return((string)o1 == (string)o2);

                case Type.NOT_EQUAL:
                    return((string)o1 != (string)o2);

                default:
                    throw new NotImplementedException();
                }
            }

            double d1 = 0;

            if (o1 is int)
            {
                d1 = (int)o1;
            }
            else if (o1 is bool)
            {
                d1 = (bool)o1 ? 1 : 0;
            }
            else if (o1 is double)
            {
                d1 = (double)o1;
            }
            else
            {
                return(evaluate(o1, o2));
            }

            double d2 = 0;

            if (o2 is int)
            {
                d2 = (int)o2;
            }
            else if (o2 is bool)
            {
                d2 = (bool)o2 ? 1 : 0;
            }
            else if (o2 is double)
            {
                d2 = (double)o2;
            }
            else
            {
                return(evaluate(o1, o2));
            }
            return(evaluate(d1, d2));
        }