예제 #1
0
            public bool Execute(Agent pAgent)
            {
                bool bValid = false;

                // action
                if (this.m_opl_m != null && this.m_operator == EOperatorType.E_INVALID)
                {
                    bValid = true;
                    this.m_opl_m.Invoke(pAgent);
                }

                // assign
                else if (this.m_operator == EOperatorType.E_ASSIGN)
                {
                    bValid = Assignment.EvaluteAssignment(pAgent, this.m_opl, this.m_opr2, this.m_opr2_m);
                }

                // compute
                else if (this.m_operator >= EOperatorType.E_ADD && this.m_operator <= EOperatorType.E_DIV)
                {
                    EComputeOperator computeOperator = (EComputeOperator)(EComputeOperator.E_ADD + (this.m_operator - EOperatorType.E_ADD));
                    bValid = Compute.EvaluteCompute(pAgent, this.m_opl, this.m_opr1, this.m_opr1_m, computeOperator, this.m_opr2, this.m_opr2_m);
                }

                // compare
                else if (this.m_operator >= EOperatorType.E_EQUAL && this.m_operator <= EOperatorType.E_LESSEQUAL)
                {
                    if (this.m_comparator != null)
                    {
                        bValid = this.m_comparator.Execute(pAgent);
                    }
                }

                return(bValid);
            }
예제 #2
0
        protected override void load(int version, string agentType, List <property_t> properties)
        {
            base.load(version, agentType, properties);
            string propertyName = null;

            foreach (property_t _t in properties)
            {
                if (_t.name == "Opl")
                {
                    this.m_opl = Condition.LoadLeft(_t.value, ref propertyName, null);
                }
                else if (_t.name == "Operator")
                {
                    if (_t.value == "Add")
                    {
                        this.m_operator = EComputeOperator.E_ADD;
                    }
                    else if (_t.value == "Sub")
                    {
                        this.m_operator = EComputeOperator.E_SUB;
                    }
                    else if (_t.value == "Mul")
                    {
                        this.m_operator = EComputeOperator.E_MUL;
                    }
                    else if (_t.value == "Div")
                    {
                        this.m_operator = EComputeOperator.E_DIV;
                    }
                }
                else if (_t.name == "Opr1")
                {
                    if (_t.value.IndexOf('(') == -1)
                    {
                        string typeName = null;
                        this.m_opr1 = Condition.LoadRight(_t.value, propertyName, ref typeName);
                    }
                    else
                    {
                        this.m_opr1_m = Action.LoadMethod(_t.value);
                    }
                }
                else if (_t.name == "Opr2")
                {
                    if (_t.value.IndexOf('(') == -1)
                    {
                        string str3 = null;
                        this.m_opr2 = Condition.LoadRight(_t.value, propertyName, ref str3);
                    }
                    else
                    {
                        this.m_opr2_m = Action.LoadMethod(_t.value);
                    }
                }
            }
        }
예제 #3
0
        public static bool EvaluteCompute(Agent pAgent, Property opl, Property opr1, CMethodBase opr1_m, EComputeOperator opr, Property opr2, CMethodBase opr2_m)
        {
            bool bValid = false;
            object value1 = null;

            if (opl != null)
            {
            if (opr1_m != null)
            {
                bValid = true;
                value1 = opr1_m.Invoke(pAgent);
            }
            else if (opr1 != null)
            {
                bValid = true;
                Agent pParentR = opr1.GetParentAgent(pAgent);

                value1 = opr1.GetValue(pParentR);
            }

            Debug.Check(value1 != null, "weird, have you modified your meta? please reexport your trees");

            if (opr2_m != null)
            {
                bValid = true;
                object value2 = opr2_m.Invoke(pAgent);

                Agent pParentOpl = opl.GetParentAgent(pAgent);
                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentOpl, returnValue);
            }
            else if (opr2 != null)
            {
                bValid = true;
                Agent pParentL = opl.GetParentAgent(pAgent);
                Agent pParentR = opr2.GetParentAgent(pAgent);

                object value2 = opr2.GetValue(pParentR);

                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentL, returnValue);
            }
            }

            return bValid;
        }
예제 #4
0
파일: Compute.cs 프로젝트: wuzhen/behaviac
        public static bool EvaluteCompute(Agent pAgent, Property opl, Property opr1, CMethodBase opr1_m, EComputeOperator opr, Property opr2, CMethodBase opr2_m)
        {
            bool bValid = false;
            object value1 = null;

            if (opl != null)
            {
            if (opr1_m != null)
            {
                bValid = true;
                value1 = opr1_m.Invoke(pAgent);
            }
            else if (opr1 != null)
            {
                bValid = true;
                Agent pParentR = opr1.GetParentAgent(pAgent);

                value1 = opr1.GetValue(pParentR);
            }

            if (opr2_m != null)
            {
                bValid = true;
                object value2 = opr2_m.Invoke(pAgent);

                Agent pParentOpl = opl.GetParentAgent(pAgent);
                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentOpl, returnValue);
            }
            else if (opr2 != null)
            {
                bValid = true;
                Agent pParentL = opl.GetParentAgent(pAgent);
                Agent pParentR = opr2.GetParentAgent(pAgent);

                object value2 = opr2.GetValue(pParentR);

                object returnValue = Details.ComputeValue(value1, value2, opr);

                opl.SetValue(pParentL, returnValue);
            }
            }

            return bValid;
        }
예제 #5
0
        public static object ComputeValue(object value1, object value2, EComputeOperator opr)
        {
            System.Type key = value1.GetType();
            if (ms_computers.ContainsKey(key))
            {
                IComputeValue value3 = ms_computers[key];
                switch (opr)
                {
                case EComputeOperator.E_ADD:
                    return(value3.Add(value1, value2));

                case EComputeOperator.E_SUB:
                    return(value3.Sub(value1, value2));

                case EComputeOperator.E_MUL:
                    return(value3.Mul(value1, value2));

                case EComputeOperator.E_DIV:
                    return(value3.Div(value1, value2));
                }
            }
            return(null);
        }
예제 #6
0
        public static object ComputeValue(object value1, object value2, EComputeOperator opr)
        {
            Type type = value1.GetType();

            if (Details.ms_computers.ContainsKey(type))
            {
                Details.IComputeValue computeValue = Details.ms_computers.get_Item(type);
                switch (opr)
                {
                case EComputeOperator.E_ADD:
                    return(computeValue.Add(value1, value2));

                case EComputeOperator.E_SUB:
                    return(computeValue.Sub(value1, value2));

                case EComputeOperator.E_MUL:
                    return(computeValue.Mul(value1, value2));

                case EComputeOperator.E_DIV:
                    return(computeValue.Div(value1, value2));
                }
            }
            return(null);
        }
예제 #7
0
파일: Compute.cs 프로젝트: wuzhen/behaviac
        protected override void load(int version, string agentType, List<property_t> properties)
        {
            base.load(version, agentType, properties);

            for (int i = 0; i < properties.Count; ++i)
            {
            property_t p = properties[i];
            if (p.name == "Opl")
            {
                this.m_opl = Condition.LoadLeft(p.value);
            }
            else if (p.name == "Operator")
            {
                if (p.value == "Add")
                {
                    this.m_operator = EComputeOperator.E_ADD;
                }
                else if (p.value == "Sub")
                {
                    this.m_operator = EComputeOperator.E_SUB;
                }
                else if (p.value == "Mul")
                {
                    this.m_operator = EComputeOperator.E_MUL;
                }
                else if (p.value == "Div")
                {
                    this.m_operator = EComputeOperator.E_DIV;
                }
                else
                {
                    Debug.Check(false);
                }
            }
            else if (p.name == "Opr1")
            {
                int pParenthesis = p.value.IndexOf('(');

                if (pParenthesis == -1)
                {
                    string typeName = null;
                    this.m_opr1 = Condition.LoadRight(p.value, ref typeName);
                }
                else
                {
                    //method
                    this.m_opr1_m = Action.LoadMethod(p.value);
                }
            }
            else if (p.name == "Opr2")
            {
                int pParenthesis = p.value.IndexOf('(');

                if (pParenthesis == -1)
                {
                    string typeName = null;
                    this.m_opr2 = Condition.LoadRight(p.value, ref typeName);
                }
                else
                {
                    //method
                    this.m_opr2_m = Action.LoadMethod(p.value);
                }
            }
            else
            {
                //Debug.Check(0, "unrecognised property %s", p.name);
            }
            }
        }
예제 #8
0
        public static bool EvaluteCompute(Agent pAgent, Property opl, Property opr1, CMethodBase opr1_m, EComputeOperator opr, Property opr2, CMethodBase opr2_m)
        {
            bool   bValid = false;
            object value1 = null;

            if (opl != null)
            {
                if (opr1_m != null)
                {
                    bValid = true;
                    value1 = opr1_m.Invoke(pAgent);
                }
                else if (opr1 != null)
                {
                    bValid = true;
                    Agent pParentR = opr1.GetParentAgent(pAgent);

                    value1 = opr1.GetValue(pParentR);
                }

                if (opr2_m != null)
                {
                    bValid = true;
                    object value2 = opr2_m.Invoke(pAgent);

                    Agent  pParentOpl  = opl.GetParentAgent(pAgent);
                    object returnValue = Details.ComputeValue(value1, value2, opr);

                    opl.SetValue(pParentOpl, returnValue);
                }
                else if (opr2 != null)
                {
                    bValid = true;
                    Agent pParentL = opl.GetParentAgent(pAgent);
                    Agent pParentR = opr2.GetParentAgent(pAgent);

                    object value2 = opr2.GetValue(pParentR);

                    object returnValue = Details.ComputeValue(value1, value2, opr);

                    opl.SetValue(pParentL, returnValue);
                }
            }

            return(bValid);
        }
예제 #9
0
        public static bool EvaluteCompute(Agent pAgent, Property opl, Property opr1, CMethodBase opr1_m, EComputeOperator opr, Property opr2, CMethodBase opr2_m)
        {
            bool   bValid = false;
            object value1 = null;

            if (opl != null)
            {
                if (opr1_m != null)
                {
                    bValid = true;
                    value1 = opr1_m.Invoke(pAgent);
                }
                else if (opr1 != null)
                {
                    bValid = true;
                    Agent pParentR = opr1.GetParentAgent(pAgent);

                    value1 = opr1.GetValue(pParentR);
                }

                Debug.Check(value1 != null, "weird, have you modified your meta? please reexport your trees");

                if (opr2_m != null)
                {
                    bValid = true;
                    object value2 = opr2_m.Invoke(pAgent);

                    Agent  pParentOpl  = opl.GetParentAgent(pAgent);
                    object returnValue = Details.ComputeValue(value1, value2, opr);

                    opl.SetValue(pParentOpl, returnValue);
                }
                else if (opr2 != null)
                {
                    bValid = true;
                    Agent pParentL = opl.GetParentAgent(pAgent);
                    Agent pParentR = opr2.GetParentAgent(pAgent);

                    object value2 = opr2.GetValue(pParentR);

                    object returnValue = Details.ComputeValue(value1, value2, opr);

                    opl.SetValue(pParentL, returnValue);
                }
            }

            return(bValid);
        }
예제 #10
0
        protected override void load(int version, string agentType, List <property_t> properties)
        {
            base.load(version, agentType, properties);
            string propertyName = null;

            using (List <property_t> .Enumerator enumerator = properties.GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    property_t current = enumerator.get_Current();
                    if (current.name == "Opl")
                    {
                        this.m_opl = Condition.LoadLeft(current.value, ref propertyName, null);
                    }
                    else if (current.name == "Operator")
                    {
                        if (current.value == "Add")
                        {
                            this.m_operator = EComputeOperator.E_ADD;
                        }
                        else if (current.value == "Sub")
                        {
                            this.m_operator = EComputeOperator.E_SUB;
                        }
                        else if (current.value == "Mul")
                        {
                            this.m_operator = EComputeOperator.E_MUL;
                        }
                        else if (current.value == "Div")
                        {
                            this.m_operator = EComputeOperator.E_DIV;
                        }
                    }
                    else if (current.name == "Opr1")
                    {
                        int num = current.value.IndexOf('(');
                        if (num == -1)
                        {
                            string text = null;
                            this.m_opr1 = Condition.LoadRight(current.value, propertyName, ref text);
                        }
                        else
                        {
                            this.m_opr1_m = Action.LoadMethod(current.value);
                        }
                    }
                    else if (current.name == "Opr2")
                    {
                        int num2 = current.value.IndexOf('(');
                        if (num2 == -1)
                        {
                            string text2 = null;
                            this.m_opr2 = Condition.LoadRight(current.value, propertyName, ref text2);
                        }
                        else
                        {
                            this.m_opr2_m = Action.LoadMethod(current.value);
                        }
                    }
                }
            }
        }