SampleCreature CreateCreature(string label, Node root, Vector3 position, DNA dna = null) { var body = Build(root); body.transform.position = position; SampleCreature creature; if (dna == null) { creature = new SampleCreature(body); } else { creature = new SampleCreature(body, dna); } var tm = Instantiate(scoreLabelPrefab).GetComponent <TextMesh>(); tm.transform.parent = creature.Body.transform; tm.transform.localPosition = Vector3.zero; scoreLabels.Add(creature, tm); return(creature); }
public void Begin() { population = new Population(mutationRate); root = new Node(Vector3.one * 0.5f); var leftArm0 = new Node(new Vector3(0.8f, 0.2f, 0.2f)); var leftArm1 = new Node(new Vector3(0.6f, 0.15f, 0.15f)); var rightArm0 = new Node(new Vector3(0.8f, 0.2f, 0.2f)); var rightArm1 = new Node(new Vector3(0.6f, 0.15f, 0.15f)); root.Connect(leftArm0, SideType.Left); root.Connect(rightArm0, SideType.Right); // leftArm0.Connect(leftArm1, SideType.Left); // rightArm0.Connect(rightArm1, SideType.Right); int hcount = Mathf.FloorToInt(count * 0.5f); for (int i = 0; i < count; i++) { var position = new Vector3((i - hcount) * size, 0f, 0f) + offset; SampleCreature creature = CreateCreature(i.ToString(), root, position); population.AddCreature(creature); } population.Setup(); wps = Mathf.Max(10f, wps); float dt = 1f / wps; StartCoroutine(Repeat(dt, () => { if (!stopping) { population.Work(dt); population.ComputeFitness(); } })); if (automatic) { Automation(); } }