Exemple #1
0
    public static Vector3[] GetRandomForces(int length)
    {
        Vector3[] forces = new Vector3[length];
        for (int i = 0; i < length; i++)
        {
            forces[i] = GeneticHelper.GetRandomForce();
        }

        return(forces);
    }
    private List <ForceGene> GetNewGene(int jointLength)
    {
        int geneLength           = Random.Range(500, 3001);
        List <ForceGene> newGene = new List <ForceGene>();

        for (int i = 0; i < geneLength; i++)
        {
            newGene.Add(new ForceGene(GeneticHelper.GetRandomForces(jointLength)));
        }

        return(newGene);
    }
    public List <ForceGene> Mutate()
    {
        List <ForceGene> mutatedGenes = new List <ForceGene>();
        List <ForceGene> copyGene     = new List <ForceGene>(CreateForceGeneCopy());

        for (int i = 0; i < forceGene.Count; i++)
        {
            if (Random.Range(0, 10) == 0)
            {
                mutatedGenes.Add(new ForceGene(GeneticHelper.GetRandomForces(forceGene[i].forces.Length)));
            }
            else
            {
                mutatedGenes.Add(new ForceGene(copyGene[i].forces));
            }
        }

        return(mutatedGenes);
    }