/// <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) { string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RightStatementOperation.Name)) { this.rightStatementOperation = new RightStatementOperation(reader); } else if (CommonHelperMethods.StringStartsWith(nextLine, ReadOnlyVariable.Name)) { this.readOnlyVariable = new ReadOnlyVariable(reader); } else if (CommonHelperMethods.StringStartsWith(nextLine, RightMethodCall.Name)) { this.rightMethodCall = new RightMethodCall(reader); } else if (CommonHelperMethods.StringStartsWith(nextLine, LiteralValue.Name)) { this.literalValue = new LiteralValue(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, new List <string>() { RightStatementOperation.Name, ReadOnlyVariable.Name, RightMethodCall.Name }); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.LeftStatement"/> class. /// </summary> /// <param name="reader">Reader.</param> public LeftStatement(FileIOManager reader, int depthIn) { this.depth = depthIn; byte nextByte = reader.ReadByte(); if (nextByte == StatementTypeEnum.LeftMethodCall) { this.leftMethodCall = new LeftMethodCall(reader, depthIn + 1); } else if (nextByte == StatementTypeEnum.Assignment) { this.assignment = new Assignment(reader, depthIn + 1); } else { CommonHelperMethods.ThrowStatementParseException( nextByte, reader, new List <byte>() { StatementTypeEnum.LeftMethodCall, StatementTypeEnum.Assignment }); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.Attributes.MethodSignature"/> class. /// </summary> /// <param name="reader">Reader.</param> public MethodSignature(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); this.MethodId = (EntMethodEnum)Enum.Parse(typeof(EntMethodEnum), nextLine); nextLine = reader.ReadNextContentLineAndTrim(); this.returnType = GeneticObject.ParseType(nextLine); int numberOfParameters; nextLine = reader.ReadNextContentLineAndTrim(); if (!int.TryParse(nextLine, out numberOfParameters)) { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, "An integer representing the number of parameters"); } for (int i = 0; i < numberOfParameters; ++i) { nextLine = reader.ReadNextContentLineAndTrim(); Type parsedType = GeneticObject.ParseType(nextLine); this.parameterTypes.Add(parsedType); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.Assignment"/> class. /// </summary> /// <param name="reader">Reader.</param> public Assignment(FileIOManager reader) { string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, ReadWriteVariable.Name)) { this.readWriteVariable = new ReadWriteVariable(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, ReadWriteVariable.Name); } nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RightStatement.Name)) { this.rightStatement = new RightStatement(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, RightStatement.Name); } }
/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightStatementOperation`1"/> class. /// </summary> /// <param name="reader">Reader.</param> public RightStatementOperation(FileIOManager reader) { // Parse operator this.operatorSignature = new OperatorSignature(reader); // Parse left hand side string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RightStatement.Name)) { this.leftHandSide = new RightStatement(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, RightStatement.Name); } // Parse right hand side nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RightStatement.Name)) { this.rightHandSide = new RightStatement(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, RightStatement.Name); } }
/// <summary> /// Creates at random. /// </summary> /// <returns>The randomly created instance.</returns> public static GeneticGridDirection CreateAtRandom() { int randInt = CommonHelperMethods.GetRandomPositiveInt0ToValue(3); GridDirection direction = (GridDirection)randInt; return(new GeneticGridDirection(direction)); }
private static string ChooseDNAParentFile_Random() { IList <string> candidates = GetNotTakenParentFiles(); int choiceIndex = CommonHelperMethods.GetRandomPositiveInt0ToValue(candidates.Count - 1); return(candidates[choiceIndex]); }
internal static GridPosition ChooseRandomPosition() { int randX = CommonHelperMethods.GetRandomPositiveInt0ToValue(GridWidth - 1); int randZ = CommonHelperMethods.GetRandomPositiveInt0ToValue(GridHeight - 1); return(new GridPosition(randX, randZ)); }
/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.ConditionalLeftStatement"/> class. /// </summary> /// <param name="reader">Reader.</param> public ConditionalLeftStatement(FileIOManager reader) { // Condition block parse string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, Condition.Name)) { this.condition = new Condition(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, Condition.Name); } // LeftStatement block parse nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, LeftStatement.Name)) { this.leftStatement = new LeftStatement(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextLine, reader, LeftStatement.Name); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.Assignment"/> class. /// </summary> /// <param name="reader">Reader.</param> public Assignment(FileIOManager reader, int depthIn) { this.depth = depthIn; byte nextByte = reader.ReadByte(); if (nextByte == StatementTypeEnum.ReadWriteVariable) { this.readWriteVariable = new ReadWriteVariable(reader); } else { CommonHelperMethods.ThrowStatementParseException( nextByte, reader, StatementTypeEnum.ReadWriteVariable); } nextByte = reader.ReadByte(); if (nextByte == StatementTypeEnum.RightStatement) { this.rightStatement = new RightStatement(reader, depthIn + 1); } else { CommonHelperMethods.ThrowStatementParseException( nextByte, reader, StatementTypeEnum.RightStatement); } }
/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.ConditionalLeftStatement"/> class. /// </summary> /// <param name="reader">Reader.</param> public ConditionalLeftStatement(FileIOManager reader, int depthIn) { this.depth = depthIn; // Condition block parse byte nextByte = reader.ReadByte(); if (nextByte == StatementTypeEnum.Condition) { this.condition = new Condition(reader, depthIn + 1); } else { CommonHelperMethods.ThrowStatementParseException( nextByte, reader, StatementTypeEnum.Condition); } // LeftStatement block parse nextByte = reader.ReadByte(); if (nextByte == StatementTypeEnum.LeftStatement) { this.leftStatement = new LeftStatement(reader, depthIn + 1); } else { CommonHelperMethods.ThrowStatementParseException( nextByte, reader, StatementTypeEnum.LeftStatement); } }
/// <summary> /// Writes to disk. /// </summary> /// <param name="writer">Writer.</param> /// <param name="tabDepth">Tab depth.</param> public void WriteToDisk(FileIOManager writer, int tabDepth) { writer.WriteLine(CommonHelperMethods.PrePendTabs(this.Value, tabDepth)); writer.WriteLine(CommonHelperMethods.PrePendTabs(this.returnType.ToString(), tabDepth)); writer.WriteLine(CommonHelperMethods.PrePendTabs(this.lhsType.ToString(), tabDepth)); writer.WriteLine(CommonHelperMethods.PrePendTabs(this.rhsType.ToString(), tabDepth)); }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.LiteralValue"/> class. /// </summary> /// <param name="returnType">Return type.</param> public LiteralValue(byte returnType) { this.type = returnType; byte randomByte = CommonHelperMethods.GetRandomByte();; switch (returnType) { case GeneticTypeEnum.GeneticBool: this.value = (byte)(randomByte & 1); break; case GeneticTypeEnum.GeneticGridDirection: this.value = (byte)CommonHelperMethods.GetRandomPositiveInt0ToValue( GridDirectionEnum.Count - 1); break; case GeneticTypeEnum.GeneticInt: this.value = randomByte; break; default: throw new NotImplementedException( string.Format("No support for object type: {0}", returnType)); } }
/// <summary> /// Tries the select right method at random. /// </summary> /// <returns><c>true</c>, if select right method at random was tryed, <c>false</c> otherwise.</returns> /// <param name="returnType">Return type.</param> /// <param name="signatureOut">Signature out.</param> public static bool TrySelectRightMethodAtRandom( Type returnType, out MethodSignature signatureOut) { if (rightMethodList == null) { throw new InvalidOperationException("rightMethodList is null"); } List <MethodSignature> candidates = new List <MethodSignature> (); foreach (MethodSignature signature in rightMethodList) { if (signature.ReturnType == returnType) { candidates.Add(signature); } } if (candidates.Count == 0) { signatureOut = null; return(false); } int index = CommonHelperMethods.GetRandomPositiveInt0ToValue(candidates.Count - 1); signatureOut = candidates [index]; return(true); }
/// <summary> /// Writes to disk. /// </summary> /// <param name="writer">Writer.</param> /// <param name="tabDepth">Tab depth.</param> public void WriteToDisk(FileIOManager writer, int tabDepth) { writer.WriteLine(CommonHelperMethods.PrePendTabs(Condition.Name, tabDepth)); if (this.rightStatement != null) { this.rightStatement.WriteToDisk(writer, tabDepth + 1); } }
/// <summary> /// Creates a GeneticBool at random. /// </summary> /// <returns>The randomly created GeneticBool.</returns> public static GeneticBool CreateAtRandom() { double nextDouble = CommonHelperMethods.GetRandomDouble0To1(); if (nextDouble < 0.5) { return(new GeneticBool(true)); } return(new GeneticBool(false)); }
/// <summary> /// Selects a read write variable at random. /// </summary> /// <returns>A random read write variable.</returns> public static VariableSignature SelectReadWriteVariableAtRandom() { if (readWriteVariableList == null || readWriteVariableList.Count == 0) { throw new InvalidOperationException("readWriteVariableList is null or empty"); } int index = CommonHelperMethods.GetRandomPositiveInt0ToValue(readWriteVariableList.Count - 1); return(readWriteVariableList [index]); }
/// <summary> /// Selects the left method at random. /// </summary> /// <returns>The left method at random.</returns> public static MethodSignature SelectLeftMethodAtRandom() { if (leftMethodList == null || leftMethodList.Count == 0) { throw new InvalidOperationException("leftMethodList is null or empty"); } int index = CommonHelperMethods.GetRandomPositiveInt0ToValue(leftMethodList.Count - 1); return(leftMethodList [index]); }
/// <summary> /// Creates a GeneticInt at random. /// </summary> /// <returns>The randomly created GeneticInt.</returns> public static GeneticInt CreateAtRandom() { double nextDouble = CommonHelperMethods.GetRandomDouble0To1(); int literal = (int)(StaticController.GlobalMaxInt * nextDouble); if (nextDouble < 0.5) { return(new GeneticInt(literal)); } return(new GeneticInt(-literal)); }
/// <summary> /// Validate Invalid WTML files. /// </summary> /// <param name="nodeName">XML node name</param> public static void InvalidateWTMLFiles(string nodeName, string errorMessage) { // Get Values from XML File string filePath = utilityObj.XmlUtil.GetTextValue(nodeName, Constants.InputFilePath); // Copy Web config file in Web virtual directory. CopyWebConfigFile(filePath); // Start IEExplorer CommonHelperMethods.StartApplication(); System.Threading.Thread.Sleep(5000); if (GetParentElement(Constants.DefaultPageName, "null")) { PatternList.ParentElement = parentElement; } if (GetChildElement(Constants.AddressBoxName, "null")) { PatternList.ChildElement = childElement; } AutomationElement addressBox = childElement; // Enter Url in Web browser address box.. PatternList.DoEnterText(ConfigurationManager.AppSettings["AspxPage"]); System.Threading.Thread.Sleep(3000); PatternList.DoSendKeys("{ENTER}"); System.Threading.Thread.Sleep(10000); // Get Parent Window name if (GetChildElement(Constants.SharingServiceWindowName, "null")) { PatternList.ParentElement = parentElement; } // Validate the error message if (GetChildElement(errorMessage, "null")) { PatternList.ChildElement = childElement; } System.Threading.Thread.Sleep(4000); Assert.AreEqual(errorMessage, childElement.Current.Name); // Close IE Brrowser. if (GetChildElement(Constants.CloseButtonName, "null")) { PatternList.ChildElement = childElement; } PatternList.DoClick(); }
/// <summary> /// This method gets the list of ChildElements of the control type in the Window. /// </summary> /// <param name="type">Control type</param> public static bool GetChildElement(ControlType type) { try { CommonHelperMethods.GetElement(AutomationElement.RootElement, type); return(true); } catch (ElementNotAvailableException ex) { Console.WriteLine(ex); return(false); } }
/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RightMethodCall"/> class. /// </summary> /// <param name="reader">Reader.</param> public RightMethodCall(FileIOManager reader) { this.signature = new MethodSignature(reader); for (int i = 0; i < this.signature.ParameterTypes.Count; ++i) { string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RightStatement.Name)) { this.parameterList.Add(new RightStatement(reader)); } } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.RootStatement"/> class. /// </summary> public RootStatement() { int value = CommonHelperMethods.GetRandomPositiveInt0ToValue(1); if (value == 0) { this.conditionalLeftStatement = new ConditionalLeftStatement(); } else { this.leftStatement = new LeftStatement(); } }
/// <summary> /// Writes to disk. /// </summary> /// <param name="writer">Writer.</param> /// <param name="tabDepth">Tab depth.</param> public void WriteToDisk(FileIOManager writer, int tabDepth) { writer.WriteLine(CommonHelperMethods.PrePendTabs(LeftStatement.Name, tabDepth)); if (this.leftMethodCall != null) { this.leftMethodCall.WriteToDisk(writer, tabDepth + 1); } if (this.assignment != null) { this.assignment.WriteToDisk(writer, tabDepth + 1); } }
/// <summary> /// Initializes a new instance of the <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.LeftStatement"/> class. /// </summary> public LeftStatement() { double nextDouble = CommonHelperMethods.GetRandomDouble0To1(); if (nextDouble < 0.5) { MethodSignature signature = RegistrationManager.SelectLeftMethodAtRandom(); this.leftMethodCall = new LeftMethodCall(signature); } else { this.assignment = new Assignment(); } }
/// <summary> /// Writes to disk. /// </summary> /// <param name="writer">Writer.</param> /// <param name="tabDepth">Tab depth.</param> public void WriteToDisk(FileIOManager writer, int tabDepth) { writer.WriteLine(CommonHelperMethods.PrePendTabs(Assignment.Name, tabDepth)); if (this.readWriteVariable != null) { this.readWriteVariable.WriteToDisk(writer, tabDepth + 1); } if (this.rightStatement != null) { this.rightStatement.WriteToDisk(writer, tabDepth + 1); } }
/// <summary> /// Writes to disk. /// </summary> /// <param name="writer">Writer.</param> /// <param name="tabDepth">Tab depth.</param> public void WriteToDisk(FileIOManager writer, int tabDepth) { writer.WriteLine(CommonHelperMethods.PrePendTabs(Name, tabDepth)); if (this.type != null) { writer.WriteLine(CommonHelperMethods.PrePendTabs(this.type.ToString(), tabDepth + 1)); } if (this.value != null) { writer.WriteLine(CommonHelperMethods.PrePendTabs(this.value.ToString(), tabDepth + 1)); } }
/// <summary> /// Initializes a new instance of the /// <see cref="AssemblyCSharp.Scripts.EntLogic.SerializationObjects.GeneticLogicRoot"/> class. /// </summary> /// <param name="file">File path.</param> public GeneticLogicRoot(string filePath) { lock (CommonHelperMethods.GlobalFileIOLock) { if (FileIOManager.DiskUsePermitted) { using (FileIOManager reader = FileIOManager.OpenDiskFileForRead(filePath)) while (!reader.EndOfStream) { // Fast forward to the next RootStatement start string nextLine = reader.ReadNextContentLineAndTrim(); if (CommonHelperMethods.StringStartsWith(nextLine, RootStatement.Name)) { RootStatement nextRootStatement = null; try { nextRootStatement = new RootStatement(reader); } catch (StatementParseException ex) { // Throw this section of the logic on disk out. // This is expected to happen due to version updates or human // error when handling files representing genetic logic. LogUtility.LogWarningFormat( "Line {0} of file {1} did not parse correctly. The corresponsing root statement will be thrown out. Message: {2} CallStack: {3}", reader.LineNumber, filePath, ex.Message, ex.StackTrace); nextRootStatement = null; } if (nextRootStatement != null) { // Root statement was successfully parsed. this.rootStatementList.Add(nextRootStatement); } } } } else { // Disk use not permitted this.rootStatementList.AddRange(FileIOManager.ReadNonDiskFile(filePath)); } } }
private List <RootStatement> GetMutatedDNA() { List <RootStatement> rootStatementList = this.ParseRootStatementList(); double nextDouble = CommonHelperMethods.GetRandomDouble0To1(); double deleteChance = (double)rootStatementList.Count / (double)MaxRootStatementCount; if (nextDouble <= deleteChance) { // Pick random statement to delete int deleteIndex = CommonHelperMethods.GetRandomPositiveInt0ToValue(rootStatementList.Count - 1); rootStatementList.RemoveAt(deleteIndex); return(rootStatementList); } nextDouble = CommonHelperMethods.GetRandomDouble0To1(); double addChance = 1.0 - deleteChance; if (nextDouble <= addChance) { // Pick random place to insert new statement int insertIndex = CommonHelperMethods.GetRandomPositiveInt0ToValue(rootStatementList.Count - 1); try { rootStatementList.Insert(insertIndex, new RootStatement()); } catch (ArgumentOutOfRangeException) { throw new InvalidOperationException(string.Format( "Index {0} was out of range inserting into collection of size {1}", insertIndex, rootStatementList.Count)); } return(rootStatementList); } if (rootStatementList.Count > 0) { // Pick random statement to modify int modifyIndex = CommonHelperMethods.GetRandomPositiveInt0ToValue(rootStatementList.Count - 1); rootStatementList[modifyIndex].PossiblyMutate(); } return(rootStatementList); }
/// <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); }