Exemplo n.º 1
0
 public Genome(SexGene pSex, ColorGene pColor, HeightGene pHeight, SpeedGene pSpeed, BehaviorGene pBehavior)
 {
     sex      = pSex;
     color    = pColor;
     height   = pHeight;
     speed    = pSpeed;
     behavior = pBehavior;
 }
Exemplo n.º 2
0
    /// <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));
    }
Exemplo n.º 3
0
    void Start()
    {
        if (CLeft != null && CRight != null)
        {
            // Create the genes for the first generation
            ColorGene  color = new ColorGene(new ColorAllele(CLeft.Allele.Dominance, CLeft.Allele.Color), new ColorAllele(CRight.Allele.Dominance, CRight.Allele.Color));
            HeightGene size  = new HeightGene(new HeightAllele(SLeft.Allele.Dominance, SLeft.Allele.Height), new HeightAllele(SRight.Allele.Dominance, SRight.Allele.Height));

            // Create the new genome with the given genes
            //genome = new Genome(color, size);
            //genome.ExpressGenome(this);

            // This is for debugging in inspector
            colorLeft  = new Color(genome.Color.AlleleA.Color.r, genome.Color.AlleleA.Color.g, genome.Color.AlleleA.Color.b);
            colorRight = new Color(genome.Color.AlleleB.Color.r, genome.Color.AlleleB.Color.g, genome.Color.AlleleB.Color.b);
            sizeLeft   = genome.Height.AlleleA.Height;
            sizeRight  = genome.Height.AlleleB.Height;
        }
    }
Exemplo n.º 4
0
    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();
                }
            }
        }
    }