public void VerifFormule() { iField = focusHandler.getCurrentFormule(); output = focusHandler.getCurrentVerif(); if (string.IsNullOrEmpty(iField.text)) { return; } try { Formule formule = FormuleFactory.parse(iField.text); Jardin jardin = terrainHandler.getJardin(); Communicate comm = new Communicate(SCRIPT_PYTHON, jardin); foreach (Element el in jardin.GetElements()) { Debug.Log(el); } //lance le script comm.GetSource().Execute(comm.GetScope()); object pythonForm = comm.HandleForm(formule); Func <Jardin, object> unity_my_interp_formul = comm.GetScope().GetVariable <Func <Jardin, object> >("unity_my_interp_formul"); object pythonJardin = unity_my_interp_formul(jardin); Func <object, object, object> unity_eval_one_form = comm.GetScope().GetVariable <Func <object, object, object> >("unity_eval_one_form"); var res = unity_eval_one_form(pythonJardin, pythonForm); Debug.Log("res=" + res); //Affiche résultat if ((bool)res == true) { output.color = Color.green; output.text = "Vrai"; } else { output.color = Color.red; output.text = "Faux"; } } catch (ParserLogException) { output.color = Color.red; output.text = "Erreur"; Debug.Log("Erreur formule"); } catch (ValueErrorException) { output.color = new Color32(255, 128, 0, 255); output.text = "Var libre"; } catch (Exception) { output.color = Color.red; output.text = "Erreur imprévue"; } }
public object formules(Communicate comm) { String[] formuleTab = new string[] { "Rose(d)", "∀xRose(x)", "∃xRose(x)", "∀x(est_blanc(x) ⇒ ∃y(plus_petit_que(x,y) ∧ a_l_est_de(y,x)))" }; object pythonArray = comm.pythonEmptyArray(); foreach (String str in formuleTab) { comm.pythonAddInArray(pythonArray, comm.HandleForm(FormuleFactory.parse(str))); } return(pythonArray); }
public void test_one_form(String form, int name, Communicate comm, Jardin jardin) { Debug.Log("====================" + "f" + name + "===================="); Formule f = FormuleFactory.parse(form); try { object pythonForm = comm.HandleForm(f); Debug.Log(name + " = " + pythonForm.ToString()); Func <Jardin, object> unity_my_interp_formul = comm.GetScope().GetVariable <Func <Jardin, object> >("unity_my_interp_formul"); object pythonJardin = unity_my_interp_formul(jardin); Func <object, object, object> unity_eval_one_form = comm.GetScope().GetVariable <Func <object, object, object> >("unity_eval_one_form"); Debug.Log("f" + name + " = " + unity_eval_one_form(pythonJardin, pythonForm)); Debug.Log("==========================================================="); } catch (CommException c) { Debug.Log(c); } }
public void testSyntaxe() { String[] formuleTab = new string[] { "Rose(d)", "∀xRose(x)", "∃xRose(x)", "∀x(est_blanc(x) ⇒ ∃y(plus_petit_que(x,y) ∧ a_l_est_de(y,x)))", "∀x(a_l_est(x) ∨ a_l_ouest(x) ∨ au_sud(x) ∨ au_nord(x))", "(∀x(est_grand(x) ⇒ est_rouge(x)) ∧ ¬∃x(est_blanc(x) ∧ ∃y(est_rouge(y) ∧ au_sud_de(x,y))))", "∃x(¬est_rouge(x) ∧ au_nord_de(x,g))", "∃x((Rose(x) ∧ est_rouge(x)) ∧ (∀y(Rose(y) ∧ est_rouge(y)) ⇒ egal(x, y)))" }; List <Formule> formules = new List <Formule>(); foreach (String str in formuleTab) { Console.WriteLine("formule=" + str); Console.WriteLine(FormuleFactory.parse(str) + "\n\n"); formules.Add(FormuleFactory.parse(str)); } }
public void VerifFormule() { Jardin jardin = terrainHandler.getJardin(); Communicate comm = new Communicate(SCRIPT_PYTHON, jardin); //lance le script comm.GetSource().Execute(comm.GetScope()); for (int i = 1; i <= NB_FORMULE; i++) { iField = (InputField)GameObject.Find(PATH + "Form_" + i).GetComponent <InputField>(); output = (Text)GameObject.Find(PATH + "VerifPan_" + i + "/verif_resultat_" + i).GetComponent <Text>(); if (iField.text == "") { continue; } try { Formule formule = FormuleFactory.parse(iField.text); foreach (Element el in jardin.GetElements()) { Debug.Log(el); } object pythonForm = comm.HandleForm(formule); Func <Jardin, object> unity_my_interp_formul = comm.GetScope().GetVariable <Func <Jardin, object> >("unity_my_interp_formul"); object pythonJardin = unity_my_interp_formul(jardin); Func <object, object, object> unity_eval_one_form = comm.GetScope().GetVariable <Func <object, object, object> >("unity_eval_one_form"); var res = unity_eval_one_form(pythonJardin, pythonForm); //Affiche résultat if ((bool)res == true) { output.color = Color.green; output.text = "Vrai"; } else { output.color = Color.red; output.text = "Faux"; } } catch (ParserLogException) { output.color = Color.red; output.text = "Erreur"; Debug.Log("Erreur formule"); } catch (ValueErrorException) { output.color = new Color32(255, 128, 0, 255); output.text = "Var libre"; } catch (Exception) { output.color = Color.red; output.text = "Erreur imprévue"; } } }