예제 #1
0
    private void GenerateGeneResolution(GeneType geneType)
    {
        //skip color type
        if (geneType == GeneType.COLOR)
        {
            return;
        }

        GeneResolution geneResolution = new GeneResolution(geneType);

        m_AvailablePriorityValues.Clear();
        int maxGeneValues = GetGeneValuesCount(geneType);

        for (int i = 0; i < maxGeneValues; i++)
        {
            m_AvailablePriorityValues.Add(i);
        }

        while (m_AvailablePriorityValues.Count > 0)
        {
            int randomValue = m_AvailablePriorityValues[Random.Range(0, m_AvailablePriorityValues.Count)];

            geneResolution.PriorityOrder.Add(randomValue);
            m_AvailablePriorityValues.Remove(randomValue);
        }

        m_GeneResolutions.Add(geneResolution);
    }
예제 #2
0
    private GeneResolution GetGeneResolutionFromType(GeneType geneType)
    {
        for (int i = 0; i < m_GeneResolutions.Count; i++)
        {
            GeneResolution currentGeneResolution = m_GeneResolutions[i];
            if (currentGeneResolution.GeneType == geneType)
            {
                return(currentGeneResolution);
            }
        }

        return(null);
    }
예제 #3
0
    private void FuseAlienGeneType(GeneType geneType, Alien firstParent, Alien secondParent)
    {
        AlienGeneValue firstParentGeneValue  = firstParent.GetGeneFromType(geneType),
                       secondParentGeneValue = secondParent.GetGeneFromType(geneType);

        AlienColorGeneValue firstParentColorGeneValue  = firstParent.ColorGeneValue,
                            secondParentColorGeneValue = secondParent.ColorGeneValue;

        m_AlienGeneData.GeneType = geneType;

        bool isColorGene = geneType == GeneType.COLOR;

        //if either parent has a predominant gene then use that gene value for the child
        if ((isColorGene && firstParentColorGeneValue.IsDominant) || (!isColorGene && firstParentGeneValue.IsDominant))
        {
            m_AlienGeneData.Value = isColorGene ? firstParentColorGeneValue.Value : firstParentGeneValue.Value;
            firstParent.Child.SetGeneData(m_AlienGeneData);

            return;
        }

        if ((isColorGene && secondParentColorGeneValue.IsDominant) || (!isColorGene && secondParentGeneValue.IsDominant))
        {
            m_AlienGeneData.Value = isColorGene ? secondParentColorGeneValue.Value : secondParentGeneValue.Value;
            firstParent.Child.SetGeneData(m_AlienGeneData); //both parents' child should be the same

            return;
        }

        //otherwise resolve based on priority
        if (isColorGene)
        {
            m_AlienGeneData.Value = ResolveColorRules(firstParentColorGeneValue, secondParentColorGeneValue);
        }
        else
        {
            GeneResolution geneResolution = GetGeneResolutionFromType(geneType);

            int firstParentPriorityGeneValue  = geneResolution.PriorityOrder.IndexOf(firstParentGeneValue.Value),
                secondParentPriorityGeneValue = geneResolution.PriorityOrder.IndexOf(secondParentGeneValue.Value);

            //lowest priority wins
            m_AlienGeneData.Value = firstParentPriorityGeneValue < secondParentPriorityGeneValue ? firstParentGeneValue.Value : secondParentGeneValue.Value;
        }

        firstParent.Child.SetGeneData(m_AlienGeneData);
    }