Esempio n. 1
0
        public void Create_List()
        {
            var  t1     = new PlTerm("[a,b,c,d]");
            bool result = PlQuery.PlCall("is_list", new PlTermV(t1));

            Assert.IsTrue(result);
            // test is_list
            Assert.IsFalse(PlQuery.PlCall("is_list", new PlTermV(new PlTerm("AA"))));
        }
Esempio n. 2
0
        public void GenerateToken(int id, Player p)
        {
            this.ID     = id;
            this.Player = p;
            this.Status = 0;
            setHousesLocation(id, p.Color);

            PlQuery.PlCall("postavi_zeton_u_kucicu(" + id + "," + p.ID + ").");
        }
Esempio n. 3
0
 public frmSudoku()
 {
     InitializeComponent();
     igra.popuniSlagalicu += igra_popuniSlagalicu;
     igra.vratiOdgovor    += igra_vratiOdgovor;
     String[] param = { "-q" };
     PlEngine.Initialize(param);
     PlQuery.PlCall("use_module(sudoku)");
 }
Esempio n. 4
0
 private static void PlAssert(string s)
 {
     if (PlCsDisabled)
     {
         WriteDebug("Disabled PlAssert " + s);
         return;
     }
     PlQuery.PlCall("assert((" + s + "))");
 }
Esempio n. 5
0
 public void unicode_1()
 {
     PlQuery.PlCall("assert(n('ąę'))");
     using (var q = new PlQuery("n(X), name(X,Y)"))
     {
         Assert.IsTrue(q.NextSolution());
         Assert.AreEqual("[261,281]", q.Variables["Y"].ToString());
     }
 }
Esempio n. 6
0
        public void unicode_query_string_term_oender()
        {
            PlQuery.PlCall(@"assert(noun(ş,myChar))");
            var q = new PlQuery("noun(ş,C)");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("myChar", q.Variables["C"].ToString());
            q.Dispose();
        }
Esempio n. 7
0
 public void unicode_01()
 {
     PlQuery.PlCall(@"assert(n('\u0105\u0119'))");
     using (var q = new PlQuery("n(X)"))
     {
         Assert.IsTrue(q.NextSolution());
         Assert.AreEqual("ąę", q.Variables["X"].ToString());
     }
 }
Esempio n. 8
0
        public void unicode_0()
        {
            PlQuery.PlCall(@"assert(n('\u0105\u0119'))");
            var q = new PlQuery("n(X), name(X,Y)");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("[261,281]", q.Variables["Y"].ToString());
            q.Dispose();
        }
Esempio n. 9
0
        public static void SetupProlog2()
        {
            try
            {
#if USE_IKVM
                if (!JplDisabled)
                {
                    JPL.setNativeLibraryDir(SwiHomeDir + "/bin");
                    try
                    {
                        JPL.loadNativeLibrary();
                    }
                    catch (Exception e)
                    {
                        WriteException(e);
                        JplDisabled = true;
                    }
                    if (!JplDisabled)
                    {
                        SafelyRun(() => jpl.fli.Prolog.initialise());
                    }
                }
                SafelyRun(TestClassLoader);
#endif
                //if (IsPLWin) return;
                try
                {
                    if (!PlEngine.IsInitialized)
                    {
                        String[] param = { "-q" }; // suppressing informational and banner messages
                        PlEngine.Initialize(param);
                    }
                    if (IsPLWin)
                    {
                        return;
                    }
                    if (!PlEngine.IsStreamFunctionReadModified)
                    {
                        PlEngine.SetStreamReader(Sread);
                    }
                    PlQuery.PlCall("nl.");
                }
                catch (Exception e)
                {
                    WriteException(e);
                    PlCsDisabled = true;
                }
                //                PlAssert("jpl:jvm_ready");
                //                PlAssert("module_transparent(jvm_ready)");
            }
            catch (Exception exception)
            {
                WriteException(exception);
                return;
            }
        }
Esempio n. 10
0
        public void unicode_query_atom_oender()
        {
            PlQuery.PlCall(@"assert(noun('ş', myChar))");
            var v = PlTerm.PlVar();
            var q = new PlQuery("noun", new PlTermV(new PlTerm("'ş'"), v));

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("myChar", v.ToString());
            q.Dispose();
        }
Esempio n. 11
0
        public void anonymous_variable_1()
        {
            PlQuery.PlCall("assert(a(a, 1))");
            PlQuery.PlCall("assert(a(b, 2))");
            var q = new PlQuery("a(_, _)");

            Assert.IsTrue(q.NextSolution());
            Assert.IsTrue(q.NextSolution());
            Assert.IsFalse(q.NextSolution());
        }
Esempio n. 12
0
 public void prolog_type_exception_sample()
 {
     try
     {
         Assert.IsTrue(PlQuery.PlCall("sumlist([1,error],L)"));
     }
     catch (PlTypeException ex)
     {
         Assert.AreEqual("is/2: Arithmetic: `error/0' is not a function", ex.Message);
     }
 }
Esempio n. 13
0
        public void StreamRead()
        {
            var rf = new DelegateStreamReadFunction(Sread);

            PlEngine.SetStreamFunctionRead(PlStreamType.Input, rf);
            // NOTE: read/1 needs a dot ('.') at the end
            PlQuery.PlCall("assert( (test_read(A) :- read(A)) )");
            PlTerm t = PlQuery.PlCallQuery("test_read(A)");

            Assert.AreEqual(ValidationStringRead, t.ToString() + ".");
        }
Esempio n. 14
0
 public void prolog_domain_exception_sample()
 {
     try
     {
         Assert.IsTrue(PlQuery.PlCall("open(temp_kill, nonsens, F)"));
     }
     catch (PlDomainException ex)
     {
         Assert.AreEqual("open/3: Domain error: `io_mode' expected, found `nonsens'", ex.Message);
     }
 }
Esempio n. 15
0
        public void tell(bool breeze, bool stench, bool glitter, int x, int y)
        {
            String line = "sensebreeze(a" + breeze + ",[" + x + "," + y + "])";

            //Console.WriteLine(line);
            PlQuery.PlCall(line);

            line = "sensestench(a" + stench + ",[" + x + "," + y + "])";
            //Console.WriteLine(line);
            PlQuery.PlCall(line);
        }
Esempio n. 16
0
        public void anonymous_variable_2()
        {
            PlQuery.PlCall("assert(a(a, 1))");
            PlQuery.PlCall("assert(a(b, 2))");
            var q = new PlQuery("a(_, Y)");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("a", q.Args[0].ToString());
            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("b", q.Args[0].ToString());
            Assert.IsFalse(q.NextSolution());
        }
Esempio n. 17
0
        public void QueryPrologUnicodeSolutions2()
        {
            PlQuery.PlCall("consult('" + _plFilenameUnicode + "')");
            var v = PlTerm.PlVar();
            var q = new PlQuery("noun", new PlTermV(new PlTerm("'ş'"), v));

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("aa", v.ToString());
            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("bb", v.ToString());
            q.Dispose();
        }
        public void t_in_out()
        {
            Delegate replaceDelegate = new DelegateParameter2(atom_replace);

            PlEngine.RegisterForeign(replaceDelegate);
            for (int i = 1; i < 10; i++)
            {
                var arg = new PlTermV(new PlTerm("test_f"), PlTerm.PlVar());
                PlQuery.PlCall("atom_replace", arg);
                Assert.AreEqual("test_xx_f", arg[1].ToString(), "atom_replace failed!");
            }
        }
Esempio n. 19
0
        public void StreamWrite()
        {
            // NOTE: the Swrite function is only called if you flush the output or send a newline character
            const string validationString = "Hello .net world äöüß"; // The last 4 characters are German umlauts.

            PlQuery.PlCall("assert( (test_write :- writeln('" + validationString + "'), flush_output) )");
            var wf = new DelegateStreamWriteFunction(Swrite);

            PlEngine.SetStreamFunctionWrite(PlStreamType.Output, wf);
            PlQuery.PlCall("test_write");
            Assert.AreEqual(validationString + "\r\n", _testString);
        }
Esempio n. 20
0
 public static bool IsDefined(string module, string functor, int arity)
 {
     if (!ClientReady)
     {
         return(false);
     }
     return(InvokeFromC(() => PlQuery.PlCall(null, "predicate_property",
                                             new PlTermV(
                                                 ModuleTerm(module,
                                                            FunctorTerm(functor, arity)),
                                                 PlTerm.PlVar())), true));
 }
Esempio n. 21
0
        public void unicode_2()
        {
            PlQuery.PlCall("assert(n('ąę'))");
            var q = new PlQuery("n(X)");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("ąę", q.Variables["X"].ToString());
            q.Dispose();
            var q2 = new PlQuery(@"n('\u0105\u0119')");

            Assert.IsTrue(q2.NextSolution());
            q2.Dispose();
        }
Esempio n. 22
0
 private void btnPlay_Click(object sender, EventArgs e)
 {
     if (rBPlayer.Checked == true)
     {
         int chosenPlayer = (int)cBoxPlayers.SelectedValue;
         PlQuery.PlCall("retract(na_redu(_)), assert(na_redu(" + chosenPlayer + ")).");
     }
     else if (rBRandom.Checked == true)
     {
         PlQuery.PlCall("tko_pocinje().");
     }
     this.Close();
 }
Esempio n. 23
0
        private void check()
        {
            string[] p = { "-q" };
            PlEngine.Initialize(p);
            PlQuery.PlCall("consult('IZ7.pl')");
            PlQuery c = new PlQuery("startAkinator");

            c.NextSolution();
            str.Clear();
            formBD.itstring = 0;
            PlQuery q = new PlQuery("check(Char," + formBD.ans[0].ToString() + "," + formBD.ans[1].ToString() + "," + formBD.ans[2].ToString() + "," + formBD.ans[3].ToString() + "," + formBD.ans[4].ToString() + "," + formBD.ans[5].ToString() + "," + formBD.ans[6].ToString() + "," + formBD.ans[7].ToString() + ")");

            foreach (PlTermV s in q.Solutions)
            {
                formBD.str.Add(s[0].ToString().Trim(new Char[] { '[', ']' }).Replace(",", " "));
            }
            PlEngine.PlCleanup();

            if (formBD.str.Count > 0)
            {
                label2.Text = "Ваш стенд " + formBD.str[0];
                button1.Hide();
                button2.Hide();
                button4.Show();
                button5.Show();


                label1.Hide();

                try
                {
                    pictureBox1.Image = Image.FromFile("F:/desktop/Новая папка (14)/" + formBD.str[formBD.itstring] + ".png");
                }
                catch
                {
                    pictureBox1.Image = Image.FromFile("F:/desktop/Новая папка (14)/aki.png");
                }
                formBD.itstring++;
            }
            else
            {
                label2.Text = "Ваш стенд не найден. Желаете добавить?";
                button1.Hide();
                button2.Hide();
                button4.Hide();
                button5.Hide();
                button6.Show();
                button7.Show();
            }
        }
Esempio n. 24
0
        private static string ToCSString(PlTermV termV)
        {
            int s = termV.Size;

            //var a0= termV.A0;
            PlTerm v0 = termV[0];
            PlTerm v1 = termV[1];

            PlQuery.PlCall("write", new PlTermV(v0));
            PlQuery.PlCall("nl");
            PlQuery.PlCall("writeq", new PlTermV(v1));
            PlQuery.PlCall("nl");
            return("");
        }
Esempio n. 25
0
        private int baciKockicu()
        {
            PlQuery.PlCall("baci_kocku().");

            PlTerm  t = PlTerm.PlVar();
            PlQuery q = new PlQuery("kocka", new PlTermV(t));

            q.NextSolution();
            lblDice.Text = t.ToString();
            int broj = int.Parse(t.ToString());

            q.Dispose();

            return(broj);
        }
Esempio n. 26
0
 public void PlQuery_2() // von robert
 {
     #region explicit_query_dispose_doc
     const string strRef = "a;e;";
     PlQuery.PlCall("assert(n('" + strRef + "'))");
     var q = new PlQuery("n(X)");
     Assert.IsTrue(q.NextSolution());
     Assert.AreEqual(strRef, q.Variables["X"].ToString());
     var q2 = new PlQuery("n('" + strRef + "')");
     Assert.IsTrue(q2.NextSolution());
     Assert.AreEqual(strRef, q.Variables["X"].ToString());
     q2.Dispose();
     q.Dispose();
     #endregion explicit_query_dispose_doc
 }
Esempio n. 27
0
        private static void initialization()
        {
            PlEngine.Initialize(new string[] { "-q" });

            if (Code.Count == 0)
            {
                ErrorMessager.NoCodeReaded();
                return;
            }

            foreach (string c in Code)
            {
                PlQuery.PlCall(c);
            }
        }
Esempio n. 28
0
        public void prolog_exception_sample()
        {
            const string exceptionText = "test_exception";

            Assert.IsTrue(PlQuery.PlCall("assert( (test_throw :- throw(" + exceptionText + ")) )"));
            try
            {
                Assert.IsTrue(PlQuery.PlCall("test_throw"));
            }
            catch (PlException ex)
            {
                Assert.AreEqual(exceptionText, ex.Term.ToString());
                Assert.AreEqual("Unknown message: " + exceptionText, ex.Message);
            }
        }
Esempio n. 29
0
        public void TestPlFrameSample()
        {
            var t1 = new PlTerm("dummy");

            AssertWord("test1");
            AssertWord("test2");
            var t2 = new PlTerm("dummy2");

            Assert.AreEqual(TermRefAccessor(t1), TermRefAccessor(t2) - 3);  // one per call of AssertWord

            PlQuery.PlCall("assert( (test(N) :- findall(X, word(X), L), length(L, N) ))");

            PlTerm term = PlQuery.PlCallQuery("test(N)");

            Assert.AreEqual(2, (int)term);
        }
Esempio n. 30
0
        public void anonymous_variable_3()
        {
            PlQuery.PlCall("assert(a(a, 1, x))");
            PlQuery.PlCall("assert(a(b, 2, y))");
            var q = new PlQuery("a(_, _, Y)");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("a", q.Args[0].ToString());
            Assert.AreEqual("1", q.Args[1].ToString());
            Assert.AreEqual("x", q.Args[2].ToString());
            Assert.AreEqual(1, q.VariableNames.Count);
            Assert.AreEqual("Y", q.VariableNames[0]);
            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("b", q.Args[0].ToString());
            Assert.IsFalse(q.NextSolution());
        }