Example #1
0
    void CreateAndRecipe(Expression left, Expression right)
    {
        AndExpressionComposite new_and = new AndExpressionComposite();

        new_and.left  = left;
        new_and.right = right;
        //Sound.PlaySFX("Create_SFX");
        GameObject.FindGameObjectWithTag("Sound").GetComponent <SoundControler>().PlaySFX("Create_SFX");

        AddRecipe(new_and);


        //Debug.Log ("Rule created: " + new_and.ToString());
    }
Example #2
0
    // Use this for initialization
    void Start()
    {
        if (type == minor_event.createRecipe)
        {
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Main> ().AddRequests(RequestsID);
        }
        else if (type == minor_event.createRules)
        {
            AndExpressionComposite andaux1 = new AndExpressionComposite();
            Number valueaux11 = new Number();
            valueaux11.value = 8;
            andaux1.left     = valueaux11;
            Number valueaux12 = new Number();
            valueaux12.value = 9;
            andaux1.right    = valueaux12;

            ImplicationExpressionComposite expaux1 = new ImplicationExpressionComposite();
            expaux1.left = andaux1;
            Number valueaux13 = new Number();
            valueaux13.value = 10;
            expaux1.right    = valueaux13;

            Rule aux1 = new Rule("exemplo1", expaux1);
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Main> ().ForceRule(aux1);


            AndExpressionComposite andaux2 = new AndExpressionComposite();
            Number valueaux21 = new Number();
            valueaux21.value = 12;
            andaux2.left     = valueaux21;
            Number valueaux22 = new Number();
            valueaux22.value = 14;
            andaux2.right    = valueaux22;

            ImplicationExpressionComposite expaux2 = new ImplicationExpressionComposite();
            expaux2.left = andaux2;
            Number valueaux23 = new Number();
            valueaux23.value = 0;
            expaux2.right    = valueaux23;

            Rule aux2 = new Rule("exemplo1", expaux2);
            GameObject.FindGameObjectWithTag("MainCamera").GetComponent <Main> ().ForceRule(aux2);
        }
    }
Example #3
0
    private void InitRules()
    {
        // RULE 0 (empty)

        ImplicationExpressionComposite implication0 = new ImplicationExpressionComposite();
        Rule empty = new Rule("No Rule", implication0, 0);

        rules.Add(empty);

        // RULE 1

        Number number1 = new Number();

        number1.value = 1;

        Number number2 = new Number();

        number2.value = 2;

        Number number3 = new Number();

        number3.value = 3;

        Number number4 = new Number();

        number4.value = 4;

        AndExpressionComposite and1 = new AndExpressionComposite();

        and1.left  = number1;
        and1.right = number2;

        AndExpressionComposite and2 = new AndExpressionComposite();

        and2.left  = and1;
        and2.right = number3;

        ImplicationExpressionComposite implication1 = new ImplicationExpressionComposite();

        implication1.left  = and2;
        implication1.right = number4;

        Rule rule1 = new Rule("B+G+Y -> R", implication1, 3);

        rules.Add(rule1);

        // RULE 1

        Number number5 = new Number();

        number5.value = 5;

        Number number6 = new Number();

        number6.value = 6;

        AndExpressionComposite and3 = new AndExpressionComposite();

        and3.left  = number4;
        and3.right = number5;

        ImplicationExpressionComposite implication2 = new ImplicationExpressionComposite();

        implication2.left  = and3;
        implication2.right = number6;

        Rule rule2 = new Rule("R+LB -> M", implication2, 2);

        rules.Add(rule2);

        current_rule = rule1;        //rules[rule_pointer];
//
    }
Example #4
0
    public static void LoadRules(List <Rule> Rules, TextAsset content)
    {
        using (StringReader reader = new StringReader(content.text))
        {
            //Debug.Log ("#Arquivo OK");
            //Leitura---------------------------------------
            string line;
            while ((line = reader.ReadLine()) != null)
            {
                // Do something with the line.
                string[] parts = line.Split(' ');
                if (parts[0] == "#RULE" || parts[0] == "#Rule")
                {
                    List <Expression> list_exp = new List <Expression>();

                    for (int i = 3; i < parts.Length; i++)
                    {
                        if (parts[i] == "+")
                        {
                            AndExpressionComposite aux_and = new AndExpressionComposite();
                            if (parts[i - 1] != ")")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                                aux_and.left   = numb_aux;
                            }
                            if (parts[i + 1] != "(")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                                aux_and.right  = numb_aux;
                            }
                            list_exp.Add(aux_and);
                        }

                        if (parts[i] == "|")
                        {
                            OrExpressionComposite aux_or = new OrExpressionComposite();
                            if (parts[i - 1] != ")")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                                aux_or.left    = numb_aux;
                            }
                            if (parts[i + 1] != "(")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                                aux_or.right   = numb_aux;
                            }
                            list_exp.Add(aux_or);
                        }

                        if (parts[i] == "=")
                        {
                            ImplicationExpressionComposite aux_imp = new ImplicationExpressionComposite();
                            if (parts[i - 1] != ")")
                            {
                                Number numb_aux = new Number();
                                numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                                aux_imp.left   = numb_aux;
                            }
                            list_exp.Add(aux_imp);
                        }
                    }


                    int Index_list = 0;
                    for (int i = 3; i < parts.Length; i++)
                    {
                        if (parts[i] == "+")
                        {
                            AndExpressionComposite aux_and = (AndExpressionComposite)list_exp[Index_list];
                            if (parts[i - 1] == ")")
                            {
                                aux_and.left = list_exp[Index_list - 1];
                            }
                            if (parts[i + 1] == "(")
                            {
                                aux_and.right = list_exp[Index_list + 1];
                            }
                            Index_list++;
                        }

                        if (parts[i] == "|")
                        {
                            OrExpressionComposite aux_or = new OrExpressionComposite();
                            if (parts[i - 1] == ")")
                            {
                                aux_or.left = list_exp[Index_list - 1];
                            }
                            if (parts[i + 1] == "(")
                            {
                                aux_or.right = list_exp[Index_list + 1];
                            }
                            Index_list++;
                        }

                        if (parts[i] == "=")
                        {
                            ImplicationExpressionComposite aux_imp = (ImplicationExpressionComposite)list_exp[Index_list];
                            if (parts[i - 1] == ")")
                            {
                                aux_imp.left = list_exp[Index_list - 1];
                            }
                            Number res_aux = new Number();
                            int    bla     = System.Convert.ToInt32(parts[i + 1]);
                            res_aux.value = bla;
                            aux_imp.right = res_aux;
                            Index_list++;
                        }
                    }
                    Rule aux_rule = new Rule(parts[1], (ImplicationExpressionComposite)list_exp[list_exp.Count - 1], System.Convert.ToInt32(parts[2]));
                    Rules.Add(aux_rule);
                }
            }
        }
    }
Example #5
0
        public static Expression ImterpretaString(string line, List <Rule> Rules)
        {
            Expression aux_exp = null;

            string[] parts = line.Split(' ');

            if (parts[0] == "#RULE" || parts[0] == "#Rule" || parts[0] == "#R" || parts[0] == "#r")
            {
                for (int i = 2; i < parts.Length; i++)
                {
                    if (parts[i] == "+")
                    {
                        AndExpressionComposite aux_and = new AndExpressionComposite();
                        if (parts[i - 1].Length == 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                            aux_and.left   = numb_aux;
                        }
                        else
                        {
                            foreach (Rule rule in Rules)
                            {
                                if (parts[i - 1] == rule.Name)
                                {
                                    aux_and.left = rule.Expression;
                                    break;
                                }
                            }
                        }
                        if (parts[i + 1].Length == 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                            aux_and.right  = numb_aux;
                        }
                        else
                        {
                            foreach (Rule rule in Rules)
                            {
                                if (parts[i + 1] == rule.Name)
                                {
                                    aux_and.right = rule.Expression;
                                    break;
                                }
                            }
                        }
                        aux_exp = aux_and;
                    }

                    if (parts[i] == "|")
                    {
                        OrExpressionComposite aux_or = new OrExpressionComposite();
                        if (parts[i - 1] != ")")
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                            aux_or.left    = numb_aux;
                        }
                        if (parts[i + 1] != "(")
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                            aux_or.right   = numb_aux;
                        }
                        aux_exp = aux_or;
                    }

                    if (parts[i] == "=")
                    {
                        ImplicationExpressionComposite aux_imp = new ImplicationExpressionComposite();
                        if (parts[i - 1].Length == 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i - 1]);
                            aux_imp.left   = numb_aux;
                        }
                        else
                        {
                            foreach (Rule rule in Rules)
                            {
                                if (parts[i - 1] == rule.Name)
                                {
                                    aux_imp.left = rule.Expression;
                                    break;
                                }
                            }
                        }
                        if (parts[i + 1].Length >= 1)
                        {
                            Number numb_aux = new Number();
                            numb_aux.value = System.Convert.ToInt32(parts[i + 1]);
                            aux_imp.right  = numb_aux;
                        }
                        aux_exp = aux_imp;
                    }
                }
            }
            return(aux_exp);
        }