Esempio n. 1
0
        public void QueryString()
        {
            var q = new PlQuery("member(A, [a,b])");

            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. 2
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. 3
0
        public void QueryStringNamed()
        {
            var q = new PlQuery("append(A, B, [a,b,c])");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("[]", q.Variables["A"].ToString());
            Assert.AreEqual("[a,b,c]", q.Variables["B"].ToString());
            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("[a]", q.Variables["A"].ToString());
            Assert.AreEqual("[b,c]", q.Variables["B"].ToString());
        }
Esempio n. 4
0
        public void QueryString2()
        {
            var q = new PlQuery("append(A, B, [a,b,c])");

            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("[]", q.Args[0].ToString());
            Assert.AreEqual("[a,b,c]", q.Args[1].ToString());
            Assert.IsTrue(q.NextSolution());
            Assert.AreEqual("[a]", q.Args[0].ToString());
            Assert.AreEqual("[b,c]", q.Args[1].ToString());
        }
Esempio n. 5
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. 6
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();
        }
Esempio n. 7
0
        private void btnObrisiIgraca_Click(object sender, EventArgs e)
        {
            PlQuery obrisiIgraca = new PlQuery("obrisiIgraca(I)");

            obrisiIgraca.Variables["I"].Unify(txtObrisiIgraca.Text.ToLower());
            if (obrisiIgraca.NextSolution() == true)
            {
                obrisiIgraca.NextSolution();
                MessageBox.Show("Igrač " + txtObrisiIgraca.Text + " uspješno obrisan");
            }
            else
            {
                MessageBox.Show("Igrač " + txtObrisiIgraca.Text + " nije prethodno dodan!");
            }
        }
Esempio n. 8
0
        //operator char *(void);
        /// <inheritdoc />
        /// <summary>
        /// The exception is translated into a message as produced by print_message/2. The character data is stored in a ring.
        /// </summary>
        /// <returns>A textual description of the Exception</returns>
        override public string ToString()
        {
            if (!PlEngine.IsInitialized)
            {
                return("A PlException was thrown but it can't formatted because PlEngine is not Initialized.");
            }

            string strRet = "[ERROR: Failed to generate message.  Internal error]\n";

            using (new PlFrame())
            {
#if USE_PRINT_MESSAGE
                PlTermV av = new PlTermV(2);

                av[0] = PlTerm.PlCompound("print_message", new PlTermV(new PlTerm("error"), new PlTerm(_exTerm.TermRef)));
                PlQuery q = new PlQuery("$write_on_string", av);
                if (q.NextSolution())
                {
                    strRet = (string)av[1];
                }
                q.Free();
#else
                var av = new PlTermV(2);
                av[0] = new PlTerm(_exTerm.TermRef);
                using (var q = new PlQuery("$messages", "message_to_string", av))
                {
                    if (q.NextSolution())
                    {
                        strRet = av[1].ToString();
                    }
                }
#endif
            }
            return(strRet);
        }
        private void button1_Click(object sender, EventArgs e)  // cai dat nut start trong form
        {
            if (Checkload == false)
            {
                MessageBox.Show("Phai load file truoc", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            string s     = "C:/Users/Hasegawa/Documents/Visual Studio 2015/Projects/pplt/pplt/sourceimgandprologcode/" + tenfilepl;
            string query = "consult('" + s + "')";

            string[] p = { "-q", "-f", query };
            PlEngine.Initialize(p);
            PlQuery q = new PlQuery(query);

            Assert.IsTrue(q.NextSolution());
            using (var a = new PlQuery(querytextbox))
            {
                int i = 0;
                foreach (var sol in a.SolutionVariables)
                {
                    if (i % 2 == 0)
                    {
                        resultquery.Add(sol["P"].ToString());
                    }
                    i++;
                    if (i > Max)
                    {
                        break;
                    }
                }
                PlEngine.PlCleanup();
            }

            textBox1.Text = "List Thu " + index + " la P= " + resultquery[index];
        }
Esempio n. 10
0
        private void button3_Click(object sender, EventArgs e)
        {
            button2.Enabled = true;
            button3.Enabled = false;
            cantGroup       = 1;
            foreach (var ctrl in this.Controls.OfType <Button>())
            {
                if (ctrl.Text.Substring(0, 1).Equals("."))
                {
                    ctrl.BackColor = Color.Red;
                    ctrl.ForeColor = Color.Red;
                    ctrl.Text      = ctrl.Text.Substring(1, (ctrl.Text.Length - 1));
                }
            }
            comboBox1.Items.Clear();
            try
            {
                listBox1.Items.Clear();
                PlQuery cargar = new PlQuery("cargar('operations.bd')");
                cargar.NextSolution();

                PlQuery consulta = new PlQuery("clean(X, Y)");
                listBox1.Items.Clear();
                foreach (PlQueryVariables z in consulta.SolutionVariables)
                {
                    listBox1.Items.Add(z["X"] + "Se limpió con éxito!" + z["Y"]);
                }
                consulta.Dispose();
                cargar.Dispose();
            }
            catch { }
        }
Esempio n. 11
0
        //Función que me carga el combo box con los grupos
        private void chargeComboBox()
        {
            string list = "";

            try
            {
                PlQuery cargar = new PlQuery("cargar('operations.bd')");
                cargar.NextSolution();

                PlQuery consulta = new PlQuery("getListGroups(X)");
                foreach (PlQueryVariables z in consulta.SolutionVariables)
                {
                    list = z["X"].ToString();
                }
                consulta.Dispose();
                cargar.Dispose();

                string   listTrimmed = list.Substring(1, list.Length - 2);
                string[] newList     = listTrimmed.Split(',');
                comboBox1.Items.Clear();
                for (int n = 0; n < newList.Length; n++)
                {
                    comboBox1.Items.Add(newList[n]);
                }
            }
            catch { }
        }
Esempio n. 12
0
        private void formBD_FormClosing(object sender, FormClosingEventArgs e)
        {
            PlQuery q = new PlQuery("salva");

            q.NextSolution();
            PlEngine.PlCleanup();
        }
Esempio n. 13
0
        private void newGameToolStripMenuItem_Click(object sender, EventArgs e)
        {
            FrmNewGame newGame = new FrmNewGame();

            newGame.ShowDialog();
            foreach (Player p in Player.PlayerList)
            {
                foreach (Token t in p.TokenList)
                {
                    panelBoard.Controls.Add(t);
                    t.LocationChanged += new EventHandler <EventArgs>(token_LocationChanged);
                }
            }
            FrmFirstPlay firstPlay = new FrmFirstPlay();

            firstPlay.ShowDialog();

            PlTerm  term = PlTerm.PlVar();
            PlQuery q    = new PlQuery("na_redu", new PlTermV(term));

            q.NextSolution();
            int idPlayer = int.Parse(term.ToString());

            q.Dispose();

            playerOnMove            = Player.PlayerList.Find(x => x.ID == idPlayer);
            lblPlayerOnTheMove.Text = playerOnMove.Nickname;
            btnColor.BackColor      = playerOnMove.Color;

            btnRollDice.Enabled = true;

            lblStatus.Text = "Roll the dice!";
        }
Esempio n. 14
0
        private void FormNBA_FormClosing(object sender, FormClosingEventArgs e)
        {
            PlQuery zatvoriDatoteku = new PlQuery("zatvoriDatoteku");

            zatvoriDatoteku.NextSolution();
            PlEngine.PlCleanup();
        }
Esempio n. 15
0
        private void btnCons_Click(object sender, EventArgs e)
        {
            PlQuery materia = new PlQuery("materia(E,C)");

            materia.Variables["E"].Unify(txtcap.Text.ToLower());
            if (materia.NextSolution() == true)
            {
                MessageBox.Show(materia.Variables["C"].ToString().ToUpper());
                txtcap.Text = "";
                txtcap.Focus();
            }
            else
            {
                MessageBox.Show("Materia no encontrada");
                DialogResult r = MessageBox.Show("Registrar Materia? ?", "Ayuda", MessageBoxButtons.YesNo);
                if (r == DialogResult.Yes)
                {
                    lblajuda.Visible = true;
                    txtajuda.Visible = true;
                    btnConf.Visible  = true;
                    lblajuda.Text    = "Favor digitar la materia de " + txtcap.Text;
                    txtajuda.Focus();
                }
                else
                {
                    MessageBox.Show("Gracias!");
                }
            }
        }
Esempio n. 16
0
        private void btnProvjeri_Click(object sender, EventArgs e)
        {
            PlQuery nba = new PlQuery("igrac(I,K)");

            nba.Variables["I"].Unify(txtIgrac.Text.ToLower());
            if (nba.NextSolution() == true)
            {
                MessageBox.Show("Igrač " + txtIgrac.Text + " igra za klub " + nba.Variables["K"].ToString().ToUpper());
                txtIgrac.Text = "";
                txtIgrac.Focus();
            }
            else
            {
                MessageBox.Show("Igrač nije pronađen!");
                DialogResult r = MessageBox.Show("Dodaj igrača?", "", MessageBoxButtons.YesNo);
                if (r == DialogResult.Yes)
                {
                    lblPomoc.Visible       = true;
                    lblKlub.Visible        = true;
                    txtKlub.Visible        = true;
                    btnDodajIgraca.Visible = true;
                    lblPomoc.Text          = "Klub za koji igra igrač " + txtIgrac.Text + " je";
                    txtKlub.Focus();
                }
                else
                {
                    MessageBox.Show("U redu.");
                }
            }
        }
Esempio n. 17
0
        public bool PrologQuery(String query, PlTermV parameters)
        {
            PlQuery q = new PlQuery(query, parameters);
            bool    x = q.NextSolution();

            return(x);
        }
Esempio n. 18
0
        public bool PrologQuery(String query)
        {
            PlQuery q = new PlQuery(query);
            bool    x = q.NextSolution();

            return(x);
        }
Esempio n. 19
0
        /// <summary>
        /// Eliminar de memoria un punto.
        /// retract(punto(X,Y)).
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        private void eliminarPunto(string x, string y)
        {
            PlQuery query = new PlQuery("eliminar_punto(" + x + "," + y + ")."); // se hace la consulta

            query.NextSolution();
            query.Dispose(); // se cierra la conexión
        }
Esempio n. 20
0
        private void button1_Click(object sender, EventArgs e)
        {
            PlQuery nome  = new PlQuery("poder(Nome,_)");
            PlQuery nome2 = new PlQuery("poder(Nome2,_)");

            nome.Variables["Nome"].Unify(textBox1.Text.ToLower());
            nome2.Variables["Nome2"].Unify(textBox2.Text.ToLower());

            if (nome.NextSolution() == true && nome2.NextSolution() == true)
            {
                PlQuery batalha = new PlQuery("comp(Nome, Nome2)");
                batalha.Variables["Nome"].Unify(textBox1.Text.ToLower());
                batalha.Variables["Nome2"].Unify(textBox2.Text.ToLower());

                if (batalha.NextSolution() == true)
                {
                    label3.Text = batalha.Variables["Nome"].ToString().ToUpper() + " derrotou " + batalha.Variables["Nome2"].ToString().ToUpper();
                }
                else
                {
                    label3.Text = batalha.Variables["Nome2"].ToString().ToUpper() + " derrotou " + batalha.Variables["Nome"].ToString().ToUpper();
                }
                textBox1.Text = "";
                textBox2.Text = "";
                textBox1.Focus();
            }
            else
            {
                MessageBox.Show("Personagem não existe");
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Eliminar de memoria todos los puntos.
        /// retractall(punto(_,_)).
        /// </summary>
        private void eliminarTodo()
        {
            PlQuery query = new PlQuery("eliminar_todo."); // se hace la consulta

            query.NextSolution();
            query.Dispose(); // se cierra la conexión
        }
Esempio n. 22
0
        //Función para extraer el total de grupos
        private string getTotalForGroup()
        {
            int    n = cantGroup;
            string p = "";

            try
            {
                while (!n.Equals(0))
                {
                    listBox1.Items.Clear();
                    PlQuery cargar = new PlQuery("cargar('operations.bd')");
                    cargar.NextSolution();

                    PlQuery consulta = new PlQuery("getTotalForGroup(" + n + ", X)");
                    foreach (PlQueryVariables z in consulta.SolutionVariables)
                    {
                        p += "Grupo: " + n + z["X"];
                    }
                    consulta.Dispose();
                    cargar.Dispose();
                }
            }
            catch { }

            return(p);
        }
Esempio n. 23
0
        private bool exite_punto(string x, string y)
        {
            PlQuery query = new PlQuery("punto(" + x + "," + y + ").");

            query.Dispose();
            return(query.NextSolution());
        }
Esempio n. 24
0
        //Función para validar si existe un grupo ya creado con ese valor
        private int existG(int value)
        {
            listBox1.Items.Clear();
            PlQuery cargar = new PlQuery("cargar('operations.bd')");

            PlQuery consulta = new PlQuery("exist(" + value.ToString() + ", X)");

            try
            {
                cargar.NextSolution();
                foreach (PlQueryVariables z in consulta.SolutionVariables)
                {
                    listBox1.Items.Add("- " + z["X"]);
                    if (z["X"] == 0)
                    {
                        consulta.Dispose();
                        cargar.Dispose();
                        return(0);
                    }
                    else
                    {
                        consulta.Dispose();
                        cargar.Dispose();
                        return(1);
                    }
                }
            }
            catch
            {
            }
            consulta.Dispose();
            cargar.Dispose();
            return(1);
        }
Esempio n. 25
0
        private void btnAddAnimal_Click(object sender, EventArgs e)
        {
            var animal      = txtAnimalName.Text.ToLower();
            var animalClass = txtClass.Text.ToLower();
            var habitat     = txtHabitat.Text.ToLower();
            var biome       = txtBiome.Text.ToLower();
            var load        = new PlQuery("load('Animals.bd')");

            try
            {
                load.NextSolution();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.StackTrace);
            }

            if (txtAnimalName.Text.Length != 0 &&
                txtClass.Text.Length != 0 &&
                txtHabitat.Text.Length != 0 &&
                txtBiome.Text.Length != 0)
            {
                try
                {
                    PlQuery.PlCall("assert(animal_habitat(" + animal + "," + habitat + "))");
                    PlQuery.PlCall("assert(animal_biome(" + animal + "," + biome + "))");
                    PlQuery.PlCall("assert(animal_class(" + animal + "," + animalClass + "))");
                    MessageBox.Show(@"Successfully Added");
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.StackTrace);
                }
            }
        }
Esempio n. 26
0
        private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            try
            {
                delete_color_select();
                string group = comboBox1.SelectedItem.ToString();
                listBox1.Items.Clear();
                PlQuery carga = new PlQuery("cargar('operations.bd')");
                carga.NextSolution();

                PlQuery consul = new PlQuery("connect(X, " + group + ")");

                foreach (PlQueryVariables z in consul.SolutionVariables)
                {
                    foreach (var ctrl in this.Controls.OfType <Button>())
                    {
                        if (("." + z["X"].ToString()).Equals(ctrl.Text))
                        {
                            ctrl.BackColor = Color.Navy;
                            ctrl.ForeColor = Color.Navy;
                        }
                    }
                }
                consul.Dispose();
                carga.Dispose();
                return;
            }
            catch
            {
                return;
            }
        }
Esempio n. 27
0
        private void btnAddEnemy_Click(object sender, EventArgs e)
        {
            var animal = txtExistingAnimal.Text.ToLower();
            var enemy  = txtNewEnemy.Text.ToLower();
            var load   = new PlQuery("load('Animals.bd')");

            try
            {
                load.NextSolution();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.StackTrace);
            }

            if (txtExistingAnimal.Text.Length != 0 &&
                txtNewEnemy.Text.Length != 0)
            {
                try
                {
                    PlQuery.PlCall("assert(major_enemies(" + animal + "," + enemy + "))");
                    MessageBox.Show(@"Successfully Added");
                }
                catch (Exception exception)
                {
                    Debug.WriteLine(exception.StackTrace);
                }
            }
        }
Esempio n. 28
0
        private void button1_Click(object sender, EventArgs e)
        {
            listBox1.Items.Clear();
            panel2.BackgroundImage = Properties.Resources.Captura;

            panel2.Refresh();
            string  salida = (string)comboBox1.SelectedItem;
            PlQuery cargar = new PlQuery("cargar('TB1.bd')");

            cargar.NextSolution();
            List <string> lista    = new List <string>();
            PlQuery       consulta = new PlQuery("buscarRuta('" + salida + "','E',R)");

            foreach (PlQueryVariables i in consulta.SolutionVariables)
            {
                listBox1.Items.Add(i["R"].ToString());
                lista.Add(i["R"].ToString());
            }
            listBox1.Items.RemoveAt(listBox1.Items.Count - 1);
            string li = lista[0];

            li = li.Substring(1, li.Length - 2);
            List <int> recorrido = new List <int>();

            foreach (String s in li.Split(','))
            {
                recorrido.Add(Int32.Parse(s.Trim()));
            }

            int distancia = recorrido[recorrido.Count - 1];

            recorrido.RemoveAt(recorrido.Count - 1);

            pintarNodos(panel2, recorrido);
        }
Esempio n. 29
0
        private void btn_consult_finder2_Click(object sender, EventArgs e)
        {
            var animalClass = cmb_class_finder2.SelectedItem.ToString().ToLower();
            var habitat     = cmb_habitat_finder2.SelectedItem.ToString().ToLower();
            var foodtype    = cmb_foodtype_finder2.SelectedItem.ToString().ToLower();
            var development = cmb_development_finder2.SelectedItem.ToString().ToLower();
            var load        = new PlQuery("load('Animals.bd')");

            try
            {
                load.NextSolution();
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.StackTrace);
            }

            try
            {
                PlQuery query = new PlQuery("search_animal(" + animalClass + "," + habitat + "," + foodtype + "," +
                                            development + ",Animal)");
                foreach (var q in query.SolutionVariables)
                {
                    lst_finder2.Items.Add(q["Animal"].ToString());
                }
            }
            catch (Exception exception)
            {
                Debug.WriteLine(exception.StackTrace);
            }
        }
Esempio n. 30
0
        private void button1_Click(object sender, EventArgs e)
        {
            string valor1 = textBox1.Text;
            string valor2 = textBox2.Text;

            listBox1.Items.Clear();
            PlQuery cargar = new PlQuery("cargar('Puzle2.bd')");

            cargar.NextSolution();

            if (checkBox1.Checked == true)
            {
                PlQuery consulta1 = new PlQuery("resolveramp(" + valor1 + "," + valor2 + ")");
                consulta1.NextSolution();
            }
            if (checkBox2.Checked == true)
            {
                PlQuery consulta2 = new PlQuery("resolverpro(" + valor1 + "," + valor2 + ")");
                consulta2.NextSolution();
            }

            List <string> Entrada = LeerArchivo();

            char[]        seps     = new char[] { '[', ']', ',' };
            List <string> numbers  = Entrada[0].Split(seps).ToList <string>();
            List <string> numbers2 = new List <string>();

            foreach (var i in numbers)
            {
                if (i != "")
                {
                    numbers2.Add(i);
                }
            }
        }
Esempio n. 31
0
		//operator char *(void);
        /// <inheritdoc />
        /// <summary>
        /// The exception is translated into a message as produced by print_message/2. The character data is stored in a ring.
        /// </summary>
        /// <returns></returns>
		override public string ToString()
		{
            if (_messagePl != null) return GetType() + ": " + _messagePl;

            if (!PlEngine.IsInitialized)
                return "A PlException was thrown but it can't formatted because PlEngine is not Initialized.";

			string strRet = "[ERROR: Failed to generate message.  Internal error]\n";
            if (libpl.NoToString) return "[ERROR: Failed to generate message.  NoToString presently]\n";
            using (PlFrame fr = new PlFrame())
            {

#if USE_PRINT_MESSAGE
				PlTermV av = new PlTermV(2);

                av[0] = PlTerm.PlCompound("print_message", new PlTermV(new PlTerm("error"), new PlTerm( _exTerm.TermRef)));
				PlQuery q = new PlQuery("$write_on_string", av);
				if ( q.NextSolution() )
					strRet = (string)av[1];
				q.Free();
#else
                PlTermV av = new PlTermV(2);
                av[0] = new PlTerm(_exTerm.TermRef);
                PlQuery q = new PlQuery("$messages", "message_to_string", av);
                if (q.NextSolution())
                    strRet = av[1].ToString();
                //q.Free();
                return strRet;
                q.Dispose();
#endif
            }
			return strRet;
		}