Ejemplo n.º 1
0
    /// <summary>
    /// 获取最接近目标经验值的道具
    /// </summary>
    /// <param name="exps"></param>
    /// <param name="totalExp"></param>
    /// <returns></returns>
    private static object[] GetNearestIExp(List <IExp> exps, int totalExp)
    {
        int minExp = int.MaxValue;

        int  useNum = 0;
        IExp tar    = null;

        foreach (var item in exps)
        {
            int totalNum = totalExp / (int)item.gainExp;
            int restExp  = totalExp % (int)item.gainExp;
            //真实的拥有数量
            int realOwnNum = (int)item.ownNum - item.useNum;

            //本身数量不够
            if (totalNum > realOwnNum)
            {
                restExp += (totalNum - realOwnNum) * (int)item.gainExp;
            }
            else if (totalNum == 0)
            {
                totalNum = 1;
                restExp  = totalExp - (int)item.gainExp;
            }

            if (Mathf.Abs(restExp) < Mathf.Abs(minExp))
            {
                minExp = restExp;
                tar    = item;
                useNum = totalNum > realOwnNum ? realOwnNum : totalNum;
            }
        }

        return(new object[] { tar, useNum });
    }
Ejemplo n.º 2
0
    public static List <IExp> GetValidExps(List <IExp> exps, uint totalExp)
    {
        List <IExp> list = new List <IExp>();

        //use back up with references
        List <IExp> oriList = new List <IExp>(exps);
        int         total   = (int)totalExp;

        while (total > 0 && oriList.Count > 0)
        {
            //get data
            object[] datas  = GetNearestIExp(oriList, total);
            IExp     data   = datas[0] as IExp;
            int      useNum = (int)datas[1];

            if (!list.Contains(data))
            {
                list.Add(data);
            }
            data.useNum += useNum;

            total -= (int)data.gainExp * useNum;
            if (data.ownNum == data.useNum)
            {
                oriList.Remove(data);
            }
        }

        return(list);
    }
Ejemplo n.º 3
0
        private static string insertInstanceName2Expression(IExp expression, Instance instance)
        {
            string temp = "";

            //_c1.e + self.e_cp
            if (expression is OperExp)
            {
                OperExp operExp = (OperExp)expression;
                // c1.e
                temp += instance.Name + "." + operExp.Exp;
                // if right of operation requires instance name
                //c1.e + c1.e_cp
                if (operExp.Result is InstancedExp)
                {
                    temp += " " + operExp.Oper.Value + " " + instance.Name + "." + operExp.Result;
                }
                else
                {
                    temp += " " + operExp.Oper.Value + " " + operExp.Result;
                }
            }
            else if (expression is InstancedExp)
            {
                temp += instance.Name + "." + expression;
            }
            else if (expression is Expression)
            {
                temp += expression;
            }
            return(temp);
        }
Ejemplo n.º 4
0
        //TODO: Important
        //private static ICondition getNegatedGuard(NegatedGuard negatedGuard)
        //{
        //   //Implement it.
        //}

        #endregion extract guard condition from KP rule for standard variables

        /********************************************************************************/

        #region extract result of a condition from KP Rule

        internal static IExp getResultOfRuleFromKPRule(Module module, KpCore.Rule kpRule, Variable variable)
        {
            IExp result = null;

            if (kpRule.Type == RuleType.MULTISET_REWRITING || kpRule.Type == RuleType.REWRITE_COMMUNICATION)
            {
                result = resultOfReWritingRule(kpRule, variable);
            }
            else if (kpRule.Type == RuleType.MEMBRANE_DIVISION || kpRule.Type == RuleType.MEMBRANE_DISSOLUTION)
            {
                result = resultOfConsumerRule(kpRule, variable);
            }
            return(result);
        }
Ejemplo n.º 5
0
        private static CaseLine trueCaseLine(IVar variable)
        {
            CaseLine caseLine = new CaseLine();

            NuSMV.Rule rule = new NuSMV.Rule();
            rule.Condition = new TruthValue(Truth.TRUE);
            IExp exp = null;

            if (variable.Behaviour == VariableBehaviour.COMMUNICATION || variable.Behaviour == VariableBehaviour.DIVISION)
            {
                exp = new InstancedExp(variable.Name);
            }
            else
            {
                exp = new Expression(variable.Name);
            }
            caseLine.Rule   = rule;
            caseLine.Result = exp;
            return(caseLine);
        }
Ejemplo n.º 6
0
        /// <summary> Returns condition for lower and upper bound of a variable, to be added in rules. eg. ((step +
        /// 1)>=0)&((step + 1)<=9) </summary> <param name="sequence">variable</param> <param name="result">result of a rule
        /// e.g.(step + 1)</param> <returns>((step + 1)>=0)&((step + 1)<=9)</returns>
        internal static ICondition getBoundCondition(Variable variable, IExp result)
        {
            //ex. ((step + 1)>=0)
            BoolExp lowerCondition = new BoolExp();

            lowerCondition.Left = result;
            lowerCondition.RelationalOperator.Operator = NuSMV.RelationalOperator.GEQ;
            lowerCondition.Right = new Expression(((variable.Type) as BoundInt).LowerBound.ToString());
            //ex. ((step + 1)<=9)
            BoolExp upperCondition = new BoolExp();

            upperCondition.Left = result;
            upperCondition.RelationalOperator.Operator = NuSMV.RelationalOperator.LEQ;
            upperCondition.Right = new Expression(((variable.Type) as BoundInt).UpperBound.ToString());

            CompoundBoolExpression boundCondition = new CompoundBoolExpression();

            boundCondition.LeftCondition           = lowerCondition;
            boundCondition.BinaryOperator.Operator = BinaryOperator.AND;
            boundCondition.RightCondition          = upperCondition;

            return(boundCondition);
        }