public Creature modify(int ID) { // create a new instance of creature to be modified Creature modifiedCreature = CreatureHolder.CreateCreature(Vector3.zero, ID, new List <Node>(0), new List <Muscle>(0), 0, true, creatureTimer + randGet() * 16 * mutability, Mathf.Min(mutability * Random.Range(0.8f, 1.25f), 2)); // add all the nodes of the current creature to the new creature for (int i = 0; i < nodeCount; i++) { Node temp = nodes[i]; Node node = modifiedCreature.CreateNode(Vector2.zero, gameObject.transform, temp.prevX, temp.prevY, temp.M, temp.friction, temp.value, temp.operation, temp.axon1, temp.axon2); node.modify(mutability, nodeCount, mutationChance, operationCount); } // add all the muscles of the current creature to the new creatures for (int i = 0; i < muscles.Count; i++) { Muscle temp = muscles[i]; Muscle muscle = modifiedCreature.CreateMuscle(gameObject.transform, temp.axon, temp.p1, temp.p2, temp.Length, temp.rigidity); muscle.modify(nodeCount, mutability, mutationChance, nodes); } // if a random float between 0 and 1 is larger then the mutationChance of the creature, or if the creature has 2 or less nodes if (Random.Range(0f, 1f) < mutationChance || nodeCount <= 2) { modifiedCreature.addRandNode(gameObject.transform, 0, 0, 0.4f, Random.Range(0f, 1f), Random.Range(0f, 1f), (int)Mathf.Floor(Random.Range(0f, operationCount)), Random.Range(0, nodeCount), Random.Range(0, nodeCount)); // add a new node } // if a random float between 0 and 1 is larger then the mutationChance of the creature if (Random.Range(0f, 1f) < mutationChance) { modifiedCreature.addRandMuscle(gameObject.transform, -1, -1); // add a new muscle connecting two of the nodes } // if a random float between 0 and 1 is larger then the mutationChance of the creature if (Random.Range(0f, 1f) < mutationChance && modifiedCreature.nodeCount >= 4) { modifiedCreature.removeRandNode(); // remove a random node } // if a random float between 0 and 1 is larger then the mutationChance of the creature if (Random.Range(0f, 1f) < mutationChance && modifiedCreature.muscleCount >= 2) { modifiedCreature.removeRandMuscle(); // remove a random muscle } modifiedCreature.checkForOverlap(); modifiedCreature.checkForLoneNodes(); modifiedCreature.checkForBadAxons(); return(modifiedCreature); }
void Start() { inputArr = box.InputSignalArray; inputArr[3] = timer; box.Activate(); outputArr = box.OutputSignalArray; gameObject.name = CreatureHolder.Name(UnityEngine.Random.Range(0, 5162)); AmountOfNodes = Mathf.Clamp(Mathf.RoundToInt(((float)outputArr[TestSettings.Instance.MaxMuscles]) * TestSettings.Instance.MaxNodes), 3, TestSettings.Instance.MaxNodes); AmountOfMuscles = Mathf.Clamp(Mathf.RoundToInt((float)(outputArr[TestSettings.Instance.MaxMuscles + 1]) * TestSettings.Instance.MaxMuscles), 2, TestSettings.Instance.MaxMuscles); nodes = new List <Node>(); muscles = new List <Muscle>(); CreateNodes(); CreateMuscles(); checkForOverlap(); checkForLoneNodes(); transform.position = new Vector3(0, pos.y - MinY + 0.8f, transform.position.z); //places the creature 0.5 units above ground StartCoroutine(RunSim()); for (int i = 0; i < muscles.Count; i++) { StartCoroutine(muscles[i].exertForce(nodes)); } }