public AgentGenome Mutate(AgentGenome parentGenome, bool bodySettings, bool brainSettings) { //AgentGenome parentGenome = leaderboardGenomesList[selectedIndex].candidateGenome; //***EAC Creature NAME mutation here??? string parentName = parentGenome.name; int randIndex = Random.Range(0, parentName.Length - 1); string frontHalf = parentName.Substring(0, randIndex); string middleChar = parentName.Substring(randIndex, 1); string backHalf = parentName.Substring(randIndex + 1); if (RandomStatics.CoinToss(.05f)) { middleChar = RandomStatics.GetRandomLetter(); } frontHalf += middleChar; string newName = RandomStatics.CoinToss(.025f) ? backHalf + frontHalf : frontHalf + backHalf; //-------------------------------------------------------------------------------------------------------------------- tempMutationSettings = bodySettings ? mutationSettings : cachedNoneMutationSettings; BodyGenome newBodyGenome = new BodyGenome(parentGenome.bodyGenome, tempMutationSettings); tempMutationSettings = brainSettings ? mutationSettings : cachedNoneMutationSettings; BrainGenome newBrainGenome = new BrainGenome(parentGenome.brainGenome, newBodyGenome, tempMutationSettings); return new AgentGenome(newBodyGenome, newBrainGenome, parentGenome.generationCount + 1, newName); }
public static bool GetMutatedBool(bool curValue, float mutationChance) { bool mutatedValue = curValue; if (RandomStatics.CoinToss(mutationChance)) { mutatedValue = RandomStatics.CoinToss(); } return(mutatedValue); }
void FixedUpdate() { if (!active) { refactoryCounter++; } else if (RandomStatics.CoinToss(resetChance)) { active = false; refactoryCounter = 0; } }
public InitialGenomeBodyPartData(InitialGenomeBodyPartInfo template) { length = RandomStatics.RandomRange(template.length.initialRange); frontWidth = RandomStatics.RandomRange(template.frontWidth.initialRange); frontHeight = RandomStatics.RandomRange(template.frontHeight.initialRange); frontVerticalOffset = RandomStatics.RandomRange(template.frontVerticalOffset.initialRange); backWidth = RandomStatics.RandomRange(template.backWidth.initialRange); backHeight = RandomStatics.RandomRange(template.backHeight.initialRange); backVerticalOffset = RandomStatics.RandomRange(template.backVerticalOffset.initialRange); transitionSize = RandomStatics.RandomRange(template.transitionSize.initialRange); }
/// Apply a random chance of connecting two neurons with a random weight void RequestConnection(NeuronGenome from, NeuronGenome to, float connectionChance, float weightMultiplier) { var connectNeurons = RandomStatics.CoinToss(connectionChance); if (!connectNeurons) { return; } var randomWeight = Gaussian.GetRandomGaussian() * weightMultiplier; var linkGenome = new LinkGenome(from, to, randomWeight, true); links.Add(linkGenome); }
/// Initialize from ranges stored in editor-defined template public InitialGenomeData(InitialGenomeInfo template) { creatureBaseLength = RandomStatics.RandomRange(template.creatureBaseLength.initialRange); creatureAspectRatio = RandomStatics.RandomRange(template.creatureAspectRatio.initialRange); creatureFrontTaperSize = RandomStatics.RandomRange(template.creatureFrontTaperSize.initialRange); creatureBackTaperSize = RandomStatics.RandomRange(template.creatureBackTaperSize.initialRange); mouthFeedFrequency = RandomStatics.RandomRange(template.mouthFeedFrequency.initialRange); mouthAttackAmplitude = RandomStatics.RandomRange(template.mouthAttackAmplitude.initialRange); mouth = template.mouth.GetRandomizedData(); head = template.head.GetRandomizedData(); body = template.body.GetRandomizedData(); tail = template.tail.GetRandomizedData(); eyeCount = template.eyeCount; eyeSpread = RandomStatics.RandomRange(template.eyeSpread.initialRange); eyeLocationAmplitude = RandomStatics.RandomRange(template.eyeLocationAmplitude.initialRange); eyeLocationFrequency = RandomStatics.RandomRange(template.eyeLocationFrequency.initialRange); eyeLocationOffset = RandomStatics.RandomRange(template.eyeLocationOffset.initialRange); socketRadius = RandomStatics.RandomRange(template.socketRadius.initialRange); socketHeight = RandomStatics.RandomRange(template.socketHeight.initialRange); socketBulge = RandomStatics.RandomRange(template.socketBulge.initialRange); eyeballRadius = RandomStatics.RandomRange(template.eyeballRadius.initialRange); eyeBulge = RandomStatics.RandomRange(template.eyeBulge.initialRange); irisWidthPercent = RandomStatics.RandomRange(template.irisWidthPercent.initialRange); pupilWidthPercent = RandomStatics.RandomRange(template.pupilWidthPercent.initialRange); pupilHeightPercent = RandomStatics.RandomRange(template.pupilHeightPercent.initialRange); eyeballHue = template.eyeballHue; irisHue = template.irisHue.GetHue().GetValue(); dorsalFinStartY = RandomStatics.RandomRange(template.dorsalFinStartY.initialRange); dorsalFinEndY = RandomStatics.RandomRange(template.dorsalFinEndY.initialRange); dorsalFinSlant = RandomStatics.RandomRange(template.dorsalFinSlant.initialRange); dorsalFinBaseHeight = RandomStatics.RandomRange(template.dorsalFinBaseHeight.initialRange); tailFinSpreadAngle = RandomStatics.RandomRange(template.tailFinSpreadAngle.initialRange); tailFinBaseLength = RandomStatics.RandomRange(template.tailFinBaseLength.initialRange); tailFinFrequencies = template.tailFinFrequencies; tailFinAmplitudes = template.tailFinAmplitudes; tailFinOffsets = template.tailFinOffsets; attackSpecialization = RandomStatics.RandomRange(template.attackSpecialization); defenseSpecialization = RandomStatics.RandomRange(template.defenseSpecialization); speedSpecialization = RandomStatics.RandomRange(template.speedSpecialization); utilitySpecialization = RandomStatics.RandomRange(template.utilitySpecialization); plantDietSpecialization = RandomStatics.RandomRange(template.plantDietSpecialization); decayDietSpecialization = RandomStatics.RandomRange(template.decayDietSpecialization); meatDietSpecialization = RandomStatics.RandomRange(template.meatDietSpecialization); }
public UnlockedTech GetInitialUnlocks() { List <TechElement> values = new List <TechElement>(); foreach (var value in potentialValues) { if (RandomStatics.CoinToss(value.probability)) { values.Add(value.value); } } return(new UnlockedTech(values)); }
public static int GetMutatedIntAdditive(int curValue, float mutationChance, int maxMutationSize, int minValue, int maxValue) { int mutatedValue = curValue; if (RandomStatics.CoinToss(mutationChance)) { int randomPerturbation = Random.Range(-maxMutationSize, maxMutationSize + 1); mutatedValue += randomPerturbation; mutatedValue = Mathf.Max(mutatedValue, minValue); mutatedValue = Mathf.Min(mutatedValue, maxValue); } return(mutatedValue); }
public static float GetMutatedFloatAdditive(float curValue, float mutationChance, float mutationStepSize, float minValue, float maxValue) { float mutatedValue = curValue; if (RandomStatics.CoinToss(mutationChance)) { float randomPerturbation = Gaussian.GetRandomGaussian(); mutatedValue += Mathf.Lerp(0f, randomPerturbation, mutationStepSize); mutatedValue = Mathf.Max(mutatedValue, minValue); mutatedValue = Mathf.Min(mutatedValue, maxValue); } return(mutatedValue); }
void Refresh() { prior = result; _exclude.Clear(); foreach (var item in exclude) { _exclude.Add(item); } if (!_exclude.Contains(prior)) { _exclude.Add(prior); } result = RandomStatics.RandomIndexNotIncluding(max, _exclude); }
private void MenuLoad_Click(object sender, EventArgs e) { OpenFileDialog openFileDialog = new OpenFileDialog() { InitialDirectory = string.Format("{0}Data/Statics", AppDomain.CurrentDomain.BaseDirectory), Filter = "xml files (*.xml)|*.xml", FilterIndex = 2, RestoreDirectory = true }; if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { FileInfo fileInfo = new FileInfo(openFileDialog.FileName); this.TextBox1.Text = fileInfo.Name; this.iRandomStatic = new RandomStatics(fileInfo.Name); this.iRandomStatic.Display(this.ListBox1); this.Panel3.Refresh(); } }
string MutateName(string original) { var newName = ""; foreach (var letter in original) { float randChance1 = Random.Range(0f, 1f); if (randChance1 < 0.35) { newName += RandomStatics.GetRandomLetter(); if (randChance1 < 0.05) { newName += RandomStatics.GetRandomLetter(); } } else if (randChance1 <= 0.95f) { newName += letter; } } return newName; }
public void SetToMutatedCopyOfParentGenome(BrainGenome parentGenome, BodyGenome bodyGenome, MutationSettingsInstance settings) { /* * //this.bodyNeuronList = parentGenome.bodyNeuronList; // UNSUSTAINABLE!!! might work now since all neuronLists are identical ****** * * // Copy from parent brain or rebuild neurons from scratch based on the new mutated bodyGenome???? --- ****** * for(int i = 0; i < parentGenome.bodyNeuronList.Count; i++) { * NeuronGenome newBodyNeuronGenome = new NeuronGenome(parentGenome.bodyNeuronList[i]); * this.bodyNeuronList.Add(newBodyNeuronGenome); * } * // Alternate: SetBodyNeuronsFromTemplate(BodyGenome templateBody); */ // Rebuild BodyNeuronGenomeList from scratch based on bodyGenome InitializeBodyNeuronList(); InitializeIONeurons(bodyGenome); hiddenNeurons = MutateHiddenNeurons(parentGenome.hiddenNeurons); links = MutateLinks(parentGenome.links, settings); if (RandomStatics.CoinToss(settings.brainCreateNewLinkChance)) { AddNewLink(settings); } if (RandomStatics.CoinToss(settings.brainCreateNewHiddenNodeChance)) { AddNewHiddenNeuron(); } var newNeurons = GetNewlyUnlockedNeurons(bodyGenome); //Debug.Log($"Initializing axons with {newNeurons.Count} new neurons from " + // $"{bodyGenome.newlyUnlockedNeuronInfo.Count} new tech."); foreach (var neuron in newNeurons) { SortIONeuron(neuron); LinkNeuronToLayer(neuron); } //RemoveVestigialLinks(); }
public UnlockedTech GetMutatedCopy() { var copy = new UnlockedTech(this); var removed = new List <TechElement>(); var added = new List <TechElement>(); // Random chance of removing a tech if it is not the prerequisite of some other tech the agent has. foreach (var value in values) { if (!value.IsPrerequisite(values) && RandomStatics.CoinToss(value.mutationLockChance)) { removed.Add(value); } } foreach (var remove in removed) { values.Remove(remove); } // Random chance of adding a tech if its prerequisite is met and the agent doesn't already have it. foreach (var value in values) { foreach (var tech in value.nextTech) { if (RandomStatics.CoinToss(tech.mutationUnlockChance) && !values.Contains(tech)) { added.Add(tech); } } } foreach (var add in added) { copy.values.Add(add); } return(copy); }
void Spawn() { // If no voxels present, spawn at seed location if (voxels.Count == 0) { var newVoxel = spawner.Spawn(voxelPrefab, transform.position).GetComponent <SpreadingVoxel>(); AddVoxel(newVoxel); return; } // Otherwise, find a random voxel with an open space and spawn there voxels = RandomStatics.ShuffleList(voxels); foreach (var voxel in voxels) { if (!voxel.HasOpenPosition()) { continue; } AddVoxel(voxel.SpreadAndReturn()); break; } }
public HueData(HueInfo template) { red = RandomStatics.RandomRange(template.red); green = RandomStatics.RandomRange(template.green); blue = RandomStatics.RandomRange(template.blue); }
public SpeciesGenomePool SelectNewGenomeSourceSpecies(bool weighted, float weightedAmount) { if (weighted) { // Filter Out species which are flagged for extinction?!?!?! // figure out which species has most evals int totalNumActiveEvals = 0; //int evalLeaderActiveIndex = 0; int recordNumEvals = 0; foreach (var idList in currentlyActiveSpeciesIDList) { int numEvals = completeSpeciesPoolsList[idList].numAgentsEvaluated + 1; totalNumActiveEvals += numEvals; if (numEvals > recordNumEvals) { recordNumEvals = numEvals; //evalLeaderActiveIndex = i; } } float[] unsortedEvalScoresArray = new float[currentlyActiveSpeciesIDList.Count]; float[] rankedEvalScoresArray = new float[currentlyActiveSpeciesIDList.Count]; int[] rankedEvalIndices = new int[currentlyActiveSpeciesIDList.Count]; //float weightedAmount = 0.5f; float avgFractionVal = 1f / currentlyActiveSpeciesIDList.Count; for (int i = 0; i < currentlyActiveSpeciesIDList.Count; i++) { float rawEvalFraction = 1f - (((float)completeSpeciesPoolsList[currentlyActiveSpeciesIDList[i]].numAgentsEvaluated + 1f) / (float)totalNumActiveEvals); unsortedEvalScoresArray[i] = Mathf.Lerp(avgFractionVal, rawEvalFraction, weightedAmount); rankedEvalScoresArray[i] = unsortedEvalScoresArray[i]; rankedEvalIndices[i] = i; } // SORT ARRAY BY #EVALS: for (int i = 0; i < rankedEvalIndices.Length - 1; i++) { for (int j = 0; j < rankedEvalIndices.Length - 1; j++) { float swapFitA = rankedEvalScoresArray[j]; float swapFitB = rankedEvalScoresArray[j + 1]; int swapIdA = rankedEvalIndices[j]; int swapIdB = rankedEvalIndices[j + 1]; // bigger is better now after inversion if (swapFitA < swapFitB) { rankedEvalScoresArray[j] = swapFitB; rankedEvalScoresArray[j + 1] = swapFitA; rankedEvalIndices[j] = swapIdB; rankedEvalIndices[j + 1] = swapIdA; } } } int selectedIndex = 0; // generate random lottery value between 0f and totalFitness: float lotteryValue = Random.Range(0f, 1f); float currentValue = 0f; for (int i = 0; i < rankedEvalIndices.Length; i++) { if (lotteryValue >= currentValue && lotteryValue < (currentValue + rankedEvalScoresArray[i])) { // Jackpot! selectedIndex = rankedEvalIndices[i]; //Debug.Log("Selected: " + selectedIndex.ToString() + "! (" + i.ToString() + ") fit= " + currentValue.ToString() + "--" + (currentValue + (1f - rankedFitnessList[i])).ToString() + " / " + totalFitness.ToString() + ", lotto# " + lotteryValue.ToString() + ", fit= " + (1f - rankedFitnessList[i]).ToString()); } currentValue += rankedEvalIndices[i]; // add this agent's fitness to current value for next check } return(completeSpeciesPoolsList[currentlyActiveSpeciesIDList[selectedIndex]]); } // NAIVE RANDOM AT FIRST: // filter flagged extinct species: List <int> eligibleSpeciesIDList = new List <int>(); foreach (var id in currentlyActiveSpeciesIDList) { if (!completeSpeciesPoolsList[id].isFlaggedForExtinction) { eligibleSpeciesIDList.Add(id); } } int randomTableIndex = Random.Range(0, eligibleSpeciesIDList.Count); // temp minor penalty to oldest species: if (randomTableIndex == 0 && RandomStatics.CoinToss(oldestSpeciesRerollChance)) { randomTableIndex = Random.Range(0, eligibleSpeciesIDList.Count); } int speciesIndex = eligibleSpeciesIDList[randomTableIndex]; return(completeSpeciesPoolsList[speciesIndex]); }
public static SimEventTypeMajor GetRandomMajorEventType() { return(RandomStatics.RandomEnumValue <SimEventTypeMajor>()); }
public static SimEventTypeExtreme GetRandomExtremeEventType() { return(RandomStatics.RandomEnumValue <SimEventTypeExtreme>()); }