public Genome(SexGene pSex, ColorGene pColor, HeightGene pHeight, SpeedGene pSpeed, BehaviorGene pBehavior) { sex = pSex; color = pColor; height = pHeight; speed = pSpeed; behavior = pBehavior; }
/// <summary> /// Returns a new mutated copy genome that is a mix of both parents genome /// </summary> /// <param name="otherGenome"></param> /// <param name="mutationFactor"></param> /// <param name="mutationChance"></param> /// <returns></returns> public Genome CrossGenome(Genome otherGenome, float mutationFactor, float mutationChance) { SexGene newSex = sex.CrossGene(otherGenome.Sex); ColorGene newColor = color.CrossGene(otherGenome.Color, mutationFactor, mutationChance); HeightGene newSize = height.CrossGene(otherGenome.Height, mutationFactor, mutationChance); SpeedGene newSpeed = speed.CrossGene(otherGenome.Speed, mutationFactor, mutationChance); BehaviorGene newBehavior = behavior.CrossGene(otherGenome.Behavior, mutationFactor, mutationChance); return(new Genome(newSex, newColor, newSize, newSpeed, newBehavior)); }
private void SpawnFirstGenerationOfEntities() // ??? { for (int s = 0; s < species.Count; s++) { for (int i = 0; i < species[s].total; i++) { GameObject o = entityPooler.SpawnFromPool("Entity", GetRandomPosition(), Quaternion.identity); if (o == null) { break; } Entity e = o.GetComponent <Entity>(); e.transform.LookAt(Vector3.zero); SexAllele sexA; SexAllele sexB; ColorAllele colorA = species[s].colorAlleles[Random.Range(0, species[s].numberOfColorAlleles)].Allele; ColorAllele colorB = species[s].colorAlleles[Random.Range(0, species[s].numberOfColorAlleles)].Allele; HeightAllele heightA = species[s].heightAlleles[Random.Range(0, species[s].numberOfHeightAlleles)].Allele; HeightAllele heightB = species[s].heightAlleles[Random.Range(0, species[s].numberOfHeightAlleles)].Allele; SpeedAllele speedA = species[s].speedAlleles[Random.Range(0, species[s].numberOfSpeedAlleles)].Allele; SpeedAllele speedB = species[s].speedAlleles[Random.Range(0, species[s].numberOfSpeedAlleles)].Allele; BehaviorAllele behaviorA = species[s].behaviorAlleles[Random.Range(0, species[s].numberOfBehaviorAlleles)].Allele; if (i < species[s].females) { sexA = species[s].sexAlleles[0].Allele; sexB = species[s].sexAlleles[0].Allele; } else { sexA = species[s].sexAlleles[0].Allele; sexB = species[s].sexAlleles[1].Allele; } SexGene sex = new SexGene(sexA.GetCopy(), sexB.GetCopy()); ColorGene color = new ColorGene(colorA.GetCopy(0.25f, 75.0f), colorB.GetCopy(0.25f, 75.0f)); HeightGene height = new HeightGene(heightA.GetCopy(2.0f, 75.0f), heightB.GetCopy(2.0f, 50.0f)); SpeedGene speed = new SpeedGene(speedA.GetCopy(5.0f, 100.0f), speedB.GetCopy(5.0f, 100.0f)); BehaviorGene behavior = new BehaviorGene(behaviorA.GetCopy(0.5f, 75.0f), behaviorA.GetCopy(0.5f, 75.0f)); e.Genome = new Genome(sex, color, height, speed, behavior); e.ExpressGenome(); if (s == 0) { e.SetOrder(Order.HERBIVORE); Counter.Instance.AddHerbivoreTotal(); Counter.Instance.AddHerbivoreAlive(); } else { e.SetOrder(Order.CARNIVORE); Counter.Instance.AddCarnivoreTotal(); Counter.Instance.AddCarnivoreAlive(); } } } }