示例#1
0
文件: BoolOP.cs 项目: TheAIBot/Bioly
        public override float Run <T>(Dictionary <string, float> variables, CommandExecutor <T> executor, Dictionary <string, BoardFluid> dropPositions)
        {
            float leftResult  = LeftBlock.Run(variables, executor, dropPositions);
            float rightResult = RightBlock.Run(variables, executor, dropPositions);

            switch (OPType)
            {
            case BoolOPTypes.EQ:
                return(leftResult == rightResult ? 1 : 0);

            case BoolOPTypes.NEQ:
                return(leftResult != rightResult ? 1 : 0);

            case BoolOPTypes.LT:
                return(leftResult < rightResult ? 1 : 0);

            case BoolOPTypes.LTE:
                return(leftResult <= rightResult ? 1 : 0);

            case BoolOPTypes.GT:
                return(leftResult > rightResult ? 1 : 0);

            case BoolOPTypes.GTE:
                return(leftResult >= rightResult ? 1 : 0);

            default:
                throw new InternalRuntimeException("Failed to parse the operator type. Type: " + OPType.ToString());
            }
        }
示例#2
0
文件: ArithOP.cs 项目: TheAIBot/Bioly
        public override float Run <T>(Dictionary <string, float> variables, CommandExecutor <T> executor, Dictionary <string, BoardFluid> dropPositions)
        {
            float leftResult  = LeftBlock.Run(variables, executor, dropPositions);
            float rightResult = RightBlock.Run(variables, executor, dropPositions);

            switch (OPType)
            {
            case ArithOPTypes.ADD:
                return(leftResult + rightResult);

            case ArithOPTypes.SUB:
                return(leftResult - rightResult);

            case ArithOPTypes.MUL:
                return(leftResult * rightResult);

            case ArithOPTypes.DIV:
                return(leftResult / rightResult);

            case ArithOPTypes.POW:
                return((float)Math.Pow(leftResult, rightResult));

            default:
                throw new InternalRuntimeException("Failed to parse the arithmetic operator type.");
            }
        }
示例#3
0
        public override float Run <T>(Dictionary <string, float> variables, CommandExecutor <T> executor, Dictionary <string, BoardFluid> dropPositions)
        {
            float result = NumberBlock.Run(variables, executor, dropPositions);

            switch (RoundType)
            {
            case RoundOPTypes.ROUND:
                return((float)Math.Round(result));

            case RoundOPTypes.ROUNDDOWN:
                return((float)Math.Floor(result));

            case RoundOPTypes.ROUNDUP:
                return((float)Math.Ceiling(result));

            default:
                throw new InternalRuntimeException("Failed to parse the round operator type. Type: " + RoundType.ToString());
            }
        }
示例#4
0
        public override float Run <T>(Dictionary <string, float> variables, CommandExecutor <T> executor, Dictionary <string, BoardFluid> dropPositions)
        {
            int   arrayLength = (int)variables[FluidArray.GetArrayLengthVariable(ArrayName)];
            float floatIndex  = IndexBlock.Run(variables, executor, dropPositions);

            if (float.IsInfinity(floatIndex) || float.IsNaN(floatIndex))
            {
                throw new InvalidNumberException(BlockID, floatIndex);
            }

            int index = (int)floatIndex;

            if (index < 0 || index >= arrayLength)
            {
                throw new ArrayIndexOutOfRange(BlockID, ArrayName, arrayLength, index);
            }

            return(variables[FluidArray.GetArrayIndexName(ArrayName, index)]);
        }
示例#5
0
        public override void Update <T>(Dictionary <string, float> variables, CommandExecutor <T> executor, Dictionary <string, BoardFluid> dropPositions)
        {
            if (!variables.ContainsKey(FluidArray.GetArrayLengthVariable(ArrayName)))
            {
                throw new RuntimeException(ID, "Can't get a fluid before inserting one into the array. Array name: " + ArrayName);
            }
            int   arrayLength = (int)variables[FluidArray.GetArrayLengthVariable(ArrayName)];
            float floatIndex  = IndexBlock.Run(variables, executor, dropPositions);

            if (float.IsInfinity(floatIndex) || float.IsNaN(floatIndex))
            {
                throw new InvalidNumberException(ID, floatIndex);
            }

            int index = (int)floatIndex;

            if (index < 0 || index >= arrayLength)
            {
                throw new ArrayIndexOutOfRange(ID, ArrayName, arrayLength, index);
            }


            OriginalFluidName = FluidArray.GetArrayIndexName(ArrayName, index);
        }
示例#6
0
 public override float Run <T>(Dictionary <string, float> variables, CommandExecutor <T> executor, Dictionary <string, BoardFluid> dropPositions)
 {
     return(OperandBlock.Run(variables, executor, dropPositions));
 }