// Update is called once per frame void Update() { // Spawn a lichking of one isn't present in the scene if(!FindObjectOfType<LichKing>()) { // Generation complete if these two conditions met if(currentKingCount % 6 == 0 && currentKingCount > 0) { currentGen = currentKingCount / 6; // Generations of six kings each int tempA = 99999999; int tempB = 99999999; for(int i = 0; i < 6; i++) { if(tempA > fitnessList[i]) { tempA = fitnessList[i]; } if(tempB > fitnessList[i] && tempA < fitnessList[i]) { tempB = fitnessList[i]; } } for(int i = 0; i < 6; i++) { bool[] child = Cross(geneList[tempA], geneList[tempB]); // The fittest two produce six new kings for the next generation geneList.Add(child); } } // Spawn a new king at the entry portal GameObject newKing = (GameObject)Instantiate(lichKingPrefab, entryPortal.transform.position, Quaternion.identity); LichKing king = newKing.GetComponent<LichKing>(); king.ExpressGenotype(geneList[currentKingCount]); // Give the king the predefined genotype for its indexed value king.generation = currentGen; currentKingCount++; kingRef = king; } try { currentKingFitness = kingRef.timeTaken; } catch { ReportFitness(currentKingFitness); currentKingFitness = 0; } if (Input.GetKeyDown("space")) { float x = Random.Range(-3.0f, 3.0f); float z = Random.Range(-3.0f, 3.0f); GameObject s = (GameObject)Instantiate(zombiePrefab, new Vector3(x, 1.0f, z), Quaternion.identity); zombies.Add(s.GetComponent<Zombie>()); } if (Input.GetKeyDown("r")) { DestroyImmediate(skeletons[0].gameObject); skeletons.RemoveAt(0); skeletons[0].following = congaLeader.GetComponent<Skeleton>(); for (int i = 1; i < numSkellies; i++) { skeletons[i].following = skeletons[i - 1]; skeletons[i - 1].isFollowedBy = skeletons[i]; } skeletons[numSkellies - 1].isTail = true; } }
// Update is called once per frame void Update() { // Spawn a lichking of one isn't present in the scene if (!FindObjectOfType <LichKing>()) { // Generation complete if these two conditions met if (currentKingCount % 6 == 0 && currentKingCount > 0) { currentGen = currentKingCount / 6; // Generations of six kings each int tempA = 99999999; int tempB = 99999999; for (int i = 0; i < 6; i++) { if (tempA > fitnessList[i]) { tempA = fitnessList[i]; } if (tempB > fitnessList[i] && tempA < fitnessList[i]) { tempB = fitnessList[i]; } } for (int i = 0; i < 6; i++) { bool[] child = Cross(geneList[tempA], geneList[tempB]); // The fittest two produce six new kings for the next generation geneList.Add(child); } } // Spawn a new king at the entry portal GameObject newKing = (GameObject)Instantiate(lichKingPrefab, entryPortal.transform.position, Quaternion.identity); LichKing king = newKing.GetComponent <LichKing>(); king.ExpressGenotype(geneList[currentKingCount]); // Give the king the predefined genotype for its indexed value king.generation = currentGen; currentKingCount++; kingRef = king; } try { currentKingFitness = kingRef.timeTaken; } catch { ReportFitness(currentKingFitness); currentKingFitness = 0; } if (Input.GetKeyDown("space")) { float x = Random.Range(-3.0f, 3.0f); float z = Random.Range(-3.0f, 3.0f); GameObject s = (GameObject)Instantiate(zombiePrefab, new Vector3(x, 1.0f, z), Quaternion.identity); zombies.Add(s.GetComponent <Zombie>()); } if (Input.GetKeyDown("r")) { DestroyImmediate(skeletons[0].gameObject); skeletons.RemoveAt(0); skeletons[0].following = congaLeader.GetComponent <Skeleton>(); for (int i = 1; i < numSkellies; i++) { skeletons[i].following = skeletons[i - 1]; skeletons[i - 1].isFollowedBy = skeletons[i]; } skeletons[numSkellies - 1].isTail = true; } }