示例#1
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);
        }
示例#2
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 { }
        }
示例#3
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;
            }
        }
示例#4
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 { }
        }
示例#5
0
        private bool exite_punto(string x, string y)
        {
            PlQuery query = new PlQuery("punto(" + x + "," + y + ").");

            query.Dispose();
            return(query.NextSolution());
        }
示例#6
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
        }
示例#7
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
        }
示例#8
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);
        }
示例#9
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!";
        }
示例#10
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();
        }
示例#11
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();
        }
示例#12
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();
        }
示例#13
0
        //[TestMethod]
        //[Ignore]
        public void Test_PlMtEngine_desroy_exception()
        {
            PlMtEngine mple1 = new PlMtEngine();
            PlQuery    q1    = null;

            mple1.PlSetEngine();
            q1 = new PlQuery("member(A, [a,b,c])");
            mple1.PlDetachEngine();
            mple1.Free();
            q1.Dispose();
        }
示例#14
0
        void AssertWord2(string word)
        {
            PlFrame fr = new PlFrame();
            PlTermV av = new PlTermV(1);

            av[0] = PlTerm.PlCompound("word", new PlTermV(new PlTerm(word)));
            PlQuery q = new PlQuery("assert", av);

            q.NextSolution();
            q.Dispose();   // IMPORTANT ! never forget to free the query before the PlFrame is closed
            fr.Dispose();
        }
示例#15
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();
        }
示例#16
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     if (plQuery != null)
     {
         plQuery.Dispose();
     }
     plQuery = null;
     if (fframe != 0)
     {
         libpl.PL_close_foreign_frame(fframe);
     }
     fframe = 0;
 }
示例#17
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();
        }
        public Dictionary <string, string> Run(params object[] vars)
        {
            if (_q != null)
            {
                _q.Dispose();
            }

            string query = string.Format("change({0}, [{1}], [{2}]).", vars);

            _q        = new PlQuery(query);
            _varNames = vars[1].ToString().Replace(" ", "").Split(',');

            return(getResult());
        }
示例#19
0
        /// <summary>
        /// Retorna cuánto puntos individuales existen.
        /// </summary>
        /// <returns></returns>
        private string puntos_individuales()
        {
            PlQuery query = new PlQuery("puntosIndividuales(N).");
            string  n     = "";

            foreach (PlQueryVariables z in query.SolutionVariables)
            {
                n = z["N"].ToString();
                Console.WriteLine("Listo grupos");
            }
            query.Dispose();
            query.NextSolution();
            return(n);
        }
示例#20
0
 /// <summary>
 /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
 /// </summary>
 /// <filterpriority>2</filterpriority>
 public void Dispose()
 {
     if (plQuery != null)
     {
         plQuery.Dispose();
         plQuery = null;
     }
     nonLeft      = true;
     currentValue = null;
     if (fframe != 0)
     {
         libpl.PL_close_foreign_frame(fframe);
     }
     fframe = 0;
 }
示例#21
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
 }
示例#22
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);
        }
示例#23
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);
        }
示例#24
0
        //Función para ir agregando a la conexión
        private void connection(string num1, string num2)
        {
            try
            {
                listBox1.Items.Clear();
                PlQuery cargar = new PlQuery("cargar('operations.bd')");
                cargar.NextSolution();

                PlQuery consulta = new PlQuery("addConnect(" + num1 + ", " + num2 + ", X)");
                foreach (PlQueryVariables z in consulta.SolutionVariables)
                {
                }
                consulta.Dispose();
                cargar.Dispose();
            }
            catch { }
        }
示例#25
0
        /// <summary>
        /// Obtiene el grupo dado.
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        private string get_grupo(string x, string y)
        {
            PlQuery query = new PlQuery("grupo_punto(" + x + "," + y + ",R,N).");

            query.Dispose();
            string n     = "";
            string list1 = "";

            foreach (PlQueryVariables z in query.SolutionVariables)
            {
                list1 = z["R"].ToString();
                n     = z["N"].ToString();
                Console.WriteLine("Listo grupo");
            }
            query.NextSolution();
            groupGlobal = list1;
            if (n != "0")
            {
                string resultQuery = list1.Replace("],[", "];[");
                resultQuery = resultQuery.Replace("]]", "");
                resultQuery = resultQuery.Replace("[[", "");
                List <string>         listQuery = new List <string>(resultQuery.Split(';'));
                List <string>         list2;
                List <List <String> > finalList = new List <List <string> >();

                foreach (string list in listQuery)
                {
                    string temporal = list;
                    temporal = temporal.Replace("]", "");
                    temporal = temporal.Replace("[", "");
                    list2    = new List <string>(temporal.Split(','));
                    List <string> sublist = new List <string>();
                    foreach (string subElement in list2)
                    {
                        sublist.Add(subElement);
                    }
                    finalList.Add(sublist);
                }

                pintar_grupo(finalList, System.Drawing.Color.Yellow);
            }
            return(n);
        }
示例#26
0
        private void button1_Click(object sender, EventArgs e)
        {
            string valorObtenido = textBox1.Text;


            PlQuery cargar = new PlQuery("cargar('base_de_conocimiento.bd')");

            cargar.NextSolution();

            PlQuery consulta1 = new PlQuery("amigos_solteros(X,Y)");

            foreach (PlQueryVariables z in consulta1.SolutionVariables)
            {
                listBox1.Items.Add(z["X"].ToString());
            }


            PlEngine.PlCleanup();
            cargar.Dispose();
        }
示例#27
0
        private Player iduciIgrac(Player trenutniIgrac)
        {
            PlQuery.PlCall("iduci_igrac(" + trenutniIgrac.ID + ")");

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

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

            q.Dispose();

            Player noviIgrac = Player.PlayerList.Find(x => x.ID == idPlayer);

            lblPlayerOnTheMove.Text    = noviIgrac.Nickname;
            btnColor.BackColor         = noviIgrac.Color;
            brojacKocka                = 0;
            noviIgrac.NumberRolledDice = 0;

            return(noviIgrac);
        }
示例#28
0
        /// <summary>
        /// Obtiene todos los grupos.
        /// </summary>
        /// <returns></returns>
        private List <List <List <string> > > get_grupos()
        {
            PlQuery query = new PlQuery("todos_grupos(S).");
            string  list1 = "";

            foreach (PlQueryVariables z in query.SolutionVariables)
            {
                list1 = z["S"].ToString();
                Console.WriteLine("Listo grupos");
            }
            query.Dispose();
            query.NextSolution();
            List <List <List <string> > > listGrops = new List <List <List <string> > >();
            string resultQuery = list1.Replace("[],", "");

            resultQuery = resultQuery.Replace("]],[[", ";");
            resultQuery = resultQuery.Replace("]]]", "");
            resultQuery = resultQuery.Replace("[[[", "");
            List <string> listQuery = new List <string>(resultQuery.Split(';'));

            foreach (string list in listQuery)
            {
                List <List <string> > finalList = new List <List <string> >();
                string temporal = list;
                temporal = temporal.Replace("],[", ".");
                List <string> listaTriple = new List <string>(temporal.Split('.'));
                foreach (string list3 in listaTriple)
                {
                    List <string> list2      = new List <string>(list3.Split(','));
                    List <string> subElement = new List <string>();
                    subElement.Add(list2[0]);
                    subElement.Add(list2[1]);
                    finalList.Add(subElement);
                }
                listGrops.Add(finalList);
            }
            return(listGrops);
        }
示例#29
0
        private void button5_Click(object sender, EventArgs e)
        {
            string list = "";

            try
            {
                listBox1.Items.Clear();

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

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

                string   listTrimmed = list.Substring(1, list.Length - 2);
                string[] newList     = listTrimmed.Split(',');
                string[] newList2    = newList.Distinct().ToArray();

                for (int n = 0; n < newList2.Length; n++)
                {
                    int total_ = 0;
                    for (int p = 0; p < newList.Length; p++)
                    {
                        if (newList2[n].Equals(newList[p]))
                        {
                            total_++;
                        }
                    }
                    listBox1.Items.Add("Hay : " + total_ + " de" + newList2[n]);
                }
            }
            catch { }
        }
示例#30
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;
		}
示例#31
0
        /**
         * Función para que el botón después de tocado me indique la información
         */
        protected void buttonTouched(int row, int column)
        {
            bool p      = true;
            int  nValue = existG(matrix[row, column]);

            foreach (var ctrl in this.Controls.OfType <Button>())
            {
                if (nValue == 0 && p)
                {
                    try
                    {
                        string groupName = "";
                        listBox1.Items.Clear();
                        PlQuery carga = new PlQuery("cargar('operations.bd')");
                        carga.NextSolution();

                        PlQuery consul = new PlQuery("getConections(" + matrix[row, column].ToString() + ", X, Y)");
                        foreach (PlQueryVariables z in consul.SolutionVariables)
                        {
                            groupName = z["Y"].ToString();
                        }
                        int totalForGroups = 0;
                        foreach (PlQueryVariables z in consul.SolutionVariables)
                        {
                            totalForGroups++;
                        }
                        listBox1.Items.Add("Grupo: " + groupName + ", Total: " + totalForGroups);
                        foreach (PlQueryVariables z in consul.SolutionVariables)
                        {
                        }
                        consul.Dispose();
                        carga.Dispose();
                        chargeComboBox();
                        return;
                    }
                    catch
                    {
                        return;
                    }
                }
                //Aquí validamos los lados que ya han sido marcados

                int r = row - 1;
                if (r != -1)
                {
                    if (ctrl.Text == "." + matrix[(r), column].ToString())
                    {
                        connection(ctrl.Text.Substring(1), matrix[row, column].ToString());
                        p = false;
                    }
                }


                int f = row + 1;
                if (f != size)
                {
                    if (ctrl.Text == "." + matrix[f, column].ToString())
                    {
                        connection(ctrl.Text.Substring(1), matrix[row, column].ToString());
                        p = false;
                    }
                }

                int c = column - 1;
                if (c != -1)
                {
                    if (ctrl.Text == "." + matrix[row, c].ToString())
                    {
                        connection(ctrl.Text.Substring(1), matrix[row, column].ToString());
                        p = false;
                    }
                }

                int cc = column + 1;
                if (cc != size)
                {
                    if (ctrl.Text == "." + matrix[row, cc].ToString())
                    {
                        connection(ctrl.Text.Substring(1), matrix[row, column].ToString());
                        p = false;
                    }
                }
            }
            if (p)
            {
                try
                {
                    listBox1.Items.Clear();
                    PlQuery cargar = new PlQuery("cargar('operations.bd')");
                    cargar.NextSolution();

                    PlQuery consulta = new PlQuery("newConnect(" + matrix[row, column].ToString() + ", " + cantGroup.ToString() + ")");
                    foreach (PlQueryVariables z in consulta.SolutionVariables)
                    {
                    }
                    cantGroup++;
                    consulta.Dispose();
                    cargar.Dispose();
                }
                catch { }
            }
            chargeComboBox();
        }