public void GeneratePopulation() { Vector3 pos = new Vector3(Random.Range(0, Width) * CellSize, 0, (Height - 1) * CellSize); GameObject bio = EvolutionEngine.TakeObject(); bio.transform.position = pos; bio.SetActive(true); bio.transform.GetChild(0).gameObject.SetActive(true); }
private void Division() { List <Vector3> freePos = new List <Vector3>(); for (int i = 0; i < 4; i++) { Vector3 direction = GetRandomVector(i); RaycastHit raycastHit = VirtualMachine.RayCast(gameObject, direction); if (raycastHit.transform == null) { Vector3 inRange = this.transform.position + direction; if (inRange.x >= 0 && inRange.x < VirtualMachine.Env.Width * VirtualMachine.Env.CellSize && inRange.z < VirtualMachine.Env.Height * VirtualMachine.Env.CellSize && inRange.z >= 0) { freePos.Add(direction); } } } if (freePos.Count == 0) { //EvolutionEngine.GiveBackObject(gameObject); } else { Vector3 pos = freePos[Random.Range(0, freePos.Count)]; GameObject child = EvolutionEngine.TakeObject(); child.transform.position = this.transform.position + pos; Creature childCreature = child.GetComponent <Creature>(); VirtualMachine.Rotate(child); List <Gene> genes = this.DNA.Copy(); childCreature.InitializeDNA(genes); child.SetActive(true); child.transform.GetChild(0).gameObject.SetActive(true); GameObject childVisual = null; childVisual = child.transform.GetChild(0).gameObject; Color parentColor = this.GetComponentInChildren <Renderer>().material.color; childVisual.GetComponent <Renderer>().material.color = new Color(parentColor.r, parentColor.g, parentColor.b, parentColor.a); if (Random.Range(0, 100) < 5) { childCreature.DNA.Mutate(); child.GetComponentInChildren <Renderer>().material.color = EvolutionEngine.GetMutationColor(VirtualMachine.GetFoodType(childCreature.DNA)); //childCreature.DNA.DisplayGenes(); } Energy = 1; } }