Example #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();
            }
        }
Example #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);
        }
        /// <summary>
        /// Initializes a new instance of the
        /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightStatement"/> class.
        /// </summary>
        /// <param name="returnType">Return type.</param>
        public RightStatement(Type returnType)
        {
            if (returnType == null)
            {
                LogUtility.LogError("Cannot create right statement with null return type");
            }

            double nextDouble = CommonHelperMethods.GetRandomDouble0To1();

            if (nextDouble < 0.25)
            {
                OperatorSignature signature;
                if (RegistrationManager.TrySelectOperatorAtRandom(returnType, out signature))
                {
                    this.rightStatementOperation = new RightStatementOperation(signature);
                    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);
                    return;
                }
            }

            // Every GeneticType should support generation of a random literal value
            this.literalValue = new LiteralValue(returnType);
        }