// Generation End private void GenerationEnd() { // Update Values UpdateChildrenCount(); UpdateBreedingAmount(); _Generation++; // Order all epochs based on score _Epoch_All = ReorderCurrentEpochsByScore(); // Take Best Epoch if (_Epoch_All[_MaxEpochs - 1].GetScore() > _Best.GetScore()) { _Best.CopyData(_Epoch_All[_MaxEpochs - 1]); _Best.SetScore(_Epoch_All[_MaxEpochs - 1].GetScore()); } // New Children Epoch[] NewChildren = new Epoch[NewChildrenCount]; // Create Children Values for (int i = 0; i < NewChildrenCount; i++) { // Acquire Random Amount of Epochs List <Epoch> Randos = AcquireRandomEpochs(BreedingAmount); // Find best 2 epochs Epoch Best_1 = FindBestEpochByScore(Randos); Epoch Best_2 = FindBestEpochByScore(Randos, Best_1); // Child Value NewChildren[i] = Epoch.CrossOver(Best_1, Best_2); // Debug.Log("Best1 Bias: " + Best_1.GetOutputLayers()[0].GetBias()); // Debug.Log("Best2 Bias: " + Best_2.GetOutputLayers()[0].GetBias()); // Debug.Log("Child Bias: " + NewChildren[i].GetOutputLayers()[0].GetBias()); // Debug.Log("~~~"); // Chance that child mutates if (CalculateMutationChance()) { NewChildren[i].MutateValues(GameplayManager.GetInstance().MutationAmount); } } // Replace weakest ones with children for (int i = 0; i < NewChildrenCount; i++) { _Epoch_All[i].CopyData(NewChildren[i]); } // Add best epoch back in the list _Epoch_All[NewChildrenCount].CopyData(_Best); // Weakest one right after children getss jittered a lot for fun if (GameplayManager.GetInstance().MutateOneWeakestByALot) { _Epoch_All[NewChildrenCount].MutateValues(GameplayManager.GetInstance().MutationAmount * 2.0f); } // Reset all scores ResetScores(); // Start Next Epoch NextEpoch(); // // Find best 2 Epochs // Epoch Winner_1st = FindBestEpochByScore(); // Epoch Winner_2nd = FindBestEpochByScore(Winner_1st); // Epoch Child = Epoch.CrossOver(Winner_1st, Winner_2nd); // // // Error Check // if(Child == null) // { // Debug.LogError("CrossoverChild Error"); // NextEpoch(); // return; // } // // // Set first two epochs as winner and child // _Epoch_All[0] = Winner_1st; // _Epoch_All[1] = Child; // // // Rest of epochs are just clones of child with jitter // for (int i = 2; i < _MaxEpochs; i++) // { // _Epoch_All[i].CopyLayers(Child); // _Epoch_All[i].JitterLayers(GameplayManager.GetInstance().MutationAmount); // } }