void ApplyProductionRule(ECS_Entity thisEntity, LSystemRule rule) { //1. Create new blank string //2. for each char in old sting check if rule applies //3.if rule applies then add rule.output to new string. //4. if rule does not apply then add old char to new string //Add new version of the whole string thisEntity.lSysComp.CycleStep += 1; thisEntity.lSysComp.DNA.Add(""); //Debug.Log("CycleStep : " + thisEntity.lSysComp.CycleStep + "DNA.Count : " + thisEntity.lSysComp.DNA[thisEntity.lSysComp.DNA.Count] ); for (int charIndex = 0; charIndex < thisEntity.lSysComp.DNA [thisEntity.lSysComp.CycleStep - 1].Length; charIndex++) { if (thisEntity.lSysComp.DNA [thisEntity.lSysComp.CycleStep - 1] [charIndex].ToString() == rule.Input) { thisEntity.lSysComp.DNA [thisEntity.lSysComp.CycleStep] += rule.Output; } else { thisEntity.lSysComp.DNA [thisEntity.lSysComp.CycleStep] += (thisEntity.lSysComp.DNA [thisEntity.lSysComp.CycleStep - 1] [charIndex].ToString()); } } }
//Splits the rules based on whatever rule splitter is defined as, then the multiple strings are initialized as LSystemRules. public void RuleAggregation() { string[] splitRules = rules.Split(RULE_SPLITTER); LSystemRule rule; foreach (string splitString in splitRules) { string[] splitAssign = splitString.Split(RULE_ASSIGNER); for (int i = 0; i < splitAssign.Length; i += 2) { rule = new LSystemRule(splitAssign[i][0], splitAssign[i + 1]); ruleList.Add(rule); } } }