示例#1
0
        /// <summary>
        /// Will possibly mutate this section of logic.
        /// </summary>
        public void PossiblyMutate()
        {
            if (GeneticLogicRoot.RollMutateDice())
            {
                OperatorSignature signature;
                if (RegistrationManager.TrySelectOperatorAtRandom(this.ReturnType, out signature))
                {
                    this.rightStatementOperation = new RightStatementOperation(signature, this.depth + 1);
                    this.readOnlyVariable        = null;
                    this.rightMethodCall         = null;
                    this.literalValue            = null;
                    return;
                }
            }

            if (GeneticLogicRoot.RollMutateDice())
            {
                VariableSignature signature;
                if (RegistrationManager.TrySelectReadOnlyVariableAtRandom(this.ReturnType, out signature))
                {
                    this.rightStatementOperation = null;
                    this.readOnlyVariable        = new ReadOnlyVariable(signature);
                    this.rightMethodCall         = null;
                    this.literalValue            = null;
                    return;
                }
            }

            if (GeneticLogicRoot.RollMutateDice())
            {
                MethodSignature signature;
                if (RegistrationManager.TrySelectRightMethodAtRandom(this.ReturnType, out signature))
                {
                    this.rightStatementOperation = null;
                    this.readOnlyVariable        = null;
                    this.rightMethodCall         = new RightMethodCall(signature, this.depth + 1);
                    this.literalValue            = null;
                    return;
                }
            }

            if (GeneticLogicRoot.RollMutateDice())
            {
                // Create the new literal value first so ReturnType get doesn't reutrn null
                this.literalValue            = new LiteralValue(this.ReturnType);
                this.rightStatementOperation = null;
                this.readOnlyVariable        = null;
                this.rightMethodCall         = null;
                return;
            }

            if (this.rightStatementOperation != null)
            {
                this.rightStatementOperation.PossiblyMutate();
            }
        }
示例#2
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightStatement"/> class.
        /// </summary>
        /// <param name="returnType">Return type.</param>
        public RightStatement(byte returnType, int depthIn)
        {
            this.depth = depthIn;
            double nextDouble = CommonHelperMethods.GetRandomDouble0To1();

            if (depthIn >= RootStatement.MaxDepth)
            {
                // Force use of literal
                nextDouble = 1.0;
            }

            if (nextDouble < 0.25)
            {
                OperatorSignature signature;
                if (RegistrationManager.TrySelectOperatorAtRandom(returnType, out signature))
                {
                    this.rightStatementOperation = new RightStatementOperation(signature, depthIn + 1);
                    return;
                }
            }

            if (nextDouble < 0.5)
            {
                VariableSignature signature;
                if (RegistrationManager.TrySelectReadOnlyVariableAtRandom(returnType, out signature))
                {
                    this.readOnlyVariable = new ReadOnlyVariable(signature);
                    return;
                }
            }

            if (nextDouble < 0.75)
            {
                MethodSignature signature;
                if (RegistrationManager.TrySelectRightMethodAtRandom(returnType, out signature))
                {
                    this.rightMethodCall = new RightMethodCall(signature, this.depth + 1);
                    return;
                }
            }

            // Every GeneticType should support generation of a random literal value
            this.literalValue = new LiteralValue(returnType);
        }
示例#3
0
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightStatement"/> class.
        /// </summary>
        /// <param name="reader">Reader.</param>
        public RightStatement(FileIOManager reader, int depthIn)
        {
            this.depth = depthIn;

            byte nextByte = reader.ReadByte();

            if (nextByte == StatementTypeEnum.RightStatementOperation)
            {
                this.rightStatementOperation = new RightStatementOperation(reader, depthIn + 1);
            }
            else if (nextByte == StatementTypeEnum.ReadOnlyVariable)
            {
                this.readOnlyVariable = new ReadOnlyVariable(reader);
            }
            else if (nextByte == StatementTypeEnum.RightMethodCall)
            {
                this.rightMethodCall = new RightMethodCall(reader, depthIn + 1);
            }
            else if (nextByte == StatementTypeEnum.LiteralValue)
            {
                this.literalValue = new LiteralValue(reader);
            }
            else
            {
                CommonHelperMethods.ThrowStatementParseException(
                    nextByte,
                    reader,
                    new List <byte>()
                {
                    StatementTypeEnum.RightStatementOperation,
                    StatementTypeEnum.ReadOnlyVariable,
                    StatementTypeEnum.RightMethodCall,
                    StatementTypeEnum.LiteralValue
                });
            }
        }