Ejemplo n.º 1
0
        /// <summary>
        /// Unify Bag with the result. This frees the internal answers, so you can only call this once.
        /// </summary>
        /// <param name="Bag"></param>
        /// <returns></returns>
        public IEnumerable <bool> result(object Bag)
        {
            object result = ListPair.make(_bagArray);

            // Try to free the memory.
            _bagArray = null;
            return(YP.unify(Bag, result));
        }
Ejemplo n.º 2
0
 static bool hasAttack3(int X, int N, ListPair Arg3)
 {
     if (X == (int)YP.getValue(Arg3._arg1) + N || X == (int)YP.getValue(Arg3._arg1) - N)
         return true;
     if (Arg3._arg2 is ListPair)
         return hasAttack3(X, N + 1, (ListPair)YP.getValue(Arg3._arg2));
     else
         return false;
 }
Ejemplo n.º 3
0
        public static object make(object[] array)
        {
            if (array.Length <= 0)
                return Atom.NIL;

            object result = Atom.NIL;
            // Start from the end.
            for (int i = array.Length - 1; i >= 0; --i)
                result = new ListPair(array[i], result);
            return result;
        }
Ejemplo n.º 4
0
        public static object make(List<object> list)
        {
            if (list.Count <= 0)
                return Atom.NIL;

            object result = Atom.NIL;
            // Start from the end.
            for (int i = list.Count - 1; i >= 0; --i)
                result = new ListPair(list[i], result);
            return result;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// For each result, unify the _freeVariables and unify Bag with the associated bag.
        /// </summary>
        /// <param name="Bag"></param>
        /// <returns></returns>
        public IEnumerable <bool> result(object Bag)
        {
            Variable bagArrayVariable = new Variable();

            foreach (bool l1 in resultArray(bagArrayVariable))
            {
                foreach (bool l2 in YP.unify(Bag, ListPair.make((List <object>)bagArrayVariable.getValue())))
                {
                    yield return(false);
                }
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// For each result, unify the _freeVariables and unify Bag with the associated bag which is sorted
        /// with duplicates removed, as in setof.
        /// </summary>
        /// <param name="Bag"></param>
        /// <returns></returns>
        public IEnumerable <bool> resultSet(object Bag)
        {
            Variable bagArrayVariable = new Variable();

            foreach (bool l1 in resultArray(bagArrayVariable))
            {
                List <object> bagArray = (List <object>)bagArrayVariable.getValue();
                YP.sortArray(bagArray);
                foreach (bool l2 in YP.unify(Bag, ListPair.makeWithoutRepeatedTerms(bagArray)))
                {
                    yield return(false);
                }
            }
        }
Ejemplo n.º 7
0
        public static object make(object[] array)
        {
            if (array.Length <= 0)
            {
                return(Atom.NIL);
            }

            object result = Atom.NIL;

            // Start from the end.
            for (int i = array.Length - 1; i >= 0; --i)
            {
                result = new ListPair(array[i], result);
            }
            return(result);
        }
Ejemplo n.º 8
0
        public static object make(List <object> list)
        {
            if (list.Count <= 0)
            {
                return(Atom.NIL);
            }

            object result = Atom.NIL;

            // Start from the end.
            for (int i = list.Count - 1; i >= 0; --i)
            {
                result = new ListPair(list[i], result);
            }
            return(result);
        }
Ejemplo n.º 9
0
        /// <summary>
        /// Return a ListPair version of array, where repeated elements 
        /// (according to YP.termEqual) are removed.
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static object makeWithoutRepeatedTerms(object[] array)
        {
            if (array.Length <= 0)
                return Atom.NIL;

            // Start from the end.
            object previousTerm = array[array.Length - 1];
            object result = new ListPair(previousTerm, Atom.NIL);
            for (int i = array.Length - 2; i >= 0; --i)
            {
                object term = array[i];
                if (YP.termEqual(term, previousTerm))
                    continue;
                result = new ListPair(term, result);
                previousTerm = term;
            }
            return result;
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Return a ListPair version of array, where repeated elements
        /// (according to YP.termEqual) are removed.
        /// </summary>
        /// <param name="array"></param>
        /// <returns></returns>
        public static object makeWithoutRepeatedTerms(object[] array)
        {
            if (array.Length <= 0)
            {
                return(Atom.NIL);
            }

            // Start from the end.
            object previousTerm = array[array.Length - 1];
            object result       = new ListPair(previousTerm, Atom.NIL);

            for (int i = array.Length - 2; i >= 0; --i)
            {
                object term = array[i];
                if (YP.termEqual(term, previousTerm))
                {
                    continue;
                }
                result       = new ListPair(term, result);
                previousTerm = term;
            }
            return(result);
        }
Ejemplo n.º 11
0
        static IEnumerable<bool> selectq(Variable X, ListPair Arg2, Variable Arg3)
        {
            foreach (bool l1 in X.unify(Arg2._arg1))
            {
                foreach (bool l2 in Arg3.unify(Arg2._arg2))
                    yield return false;
            }

            ListPair Arg2Tail = YP.getValue(Arg2._arg2) as ListPair;
            if (Arg2Tail != null)
            {
                Variable Zs = new Variable();
                foreach (bool l1 in selectq(X, Arg2Tail, Zs))
                {
                    foreach (bool l2 in Arg3.unify(new ListPair(Arg2._arg1, Zs)))
                        yield return false;
                }
            }
        }
Ejemplo n.º 12
0
 static bool hasAttack(int X, ListPair Xs)
 {
     return hasAttack3(X, 1, Xs);
 }