Ejemplo n.º 1
0
 public void MakeChild()
 {
     for (int i = 0; i < DESTROY; i++)
     {
         int        father = Random.Range(0, GENERATION - DESTROY);
         int        mother = Random.Range(0, GENERATION - DESTROY);
         Indivisual child  = Indivisual.MakeChild(colony[father], colony[mother]);
         colony.Add(child);
     }
 }
Ejemplo n.º 2
0
 public void Collector(Indivisual indivisual)
 {
     for (int i = 0; i < transform.childCount; ++i)
     {
         GameObject child = transform.GetChild(i).gameObject;
         if (child.GetComponent <JointController>() != null)
         {
             indivisual.joint_controllers.Add(child.GetComponent <JointController>());
             child.GetComponent <JointController>().Init(indivisual, indivisual.joint_controllers.Count - 1);
         }
         if (child.GetComponent <JointCollector>() != null)
         {
             child.GetComponent <JointCollector>().Collector(indivisual);
         }
     }
 }
Ejemplo n.º 3
0
    public static Indivisual MakeChild(Indivisual father, Indivisual mother)
    {
        int        rnd   = Random.Range(0, GENE_COUNT);
        Indivisual child = new Indivisual();

        for (int i = 0; i < GENE_COUNT; i++)
        {
            if (i > rnd)
            {
                child.SetIndexGene(i, mother.GetIndexGene(i));
            }
            else
            {
                child.SetIndexGene(i, father.GetIndexGene(i));
            }
        }

        return(child);
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        time++;
        if (time < MAX_WAIT)
        {
            return;
        }
        generations.Reviews();
        int best = generations.GetBestGene();

        best_gene = generations.GetIndexColony(best);
        changeGene(best_gene.GetGene(), renderers);
        best_point = best_gene.GetPoint();
        if (best_point >= Indivisual.GENE_COUNT)
        {
            Instantiate(thankyou);
            Debug.Log("thank you");
        }
        generations.Delete();
        generations.MakeChild();
        generations.Mutations();
    }
Ejemplo n.º 5
0
    public void Init(Indivisual indivisual, int gene_idx)
    {
        rb           = GetComponent <Rigidbody>();
        elapsed_time = 0f;
        Vector3   default_world_y = transform.rotation * Vector3.up;
        Matrix3x3 matrix          = new Matrix3x3(transform.parent.right, transform.parent.up, transform.parent.forward);

        float[,] inverse_matrix = matrix.Inverse();
        default_local_y.x       = inverse_matrix[0, 0] * default_world_y.x + inverse_matrix[0, 1] * default_world_y.y + inverse_matrix[0, 2] * default_world_y.z;
        default_local_y.y       = inverse_matrix[1, 0] * default_world_y.x + inverse_matrix[1, 1] * default_world_y.y + inverse_matrix[1, 2] * default_world_y.z;
        default_local_y.z       = inverse_matrix[2, 0] * default_world_y.x + inverse_matrix[2, 1] * default_world_y.y + inverse_matrix[2, 2] * default_world_y.z;
        default_local_y         = default_local_y.normalized;

        power  = Decode_gene(indivisual.genes[gene_idx, Indivisual.gene_size - 2], indivisual.power_lower_limit, indivisual.power_upper_limit);
        period = Decode_gene(indivisual.genes[gene_idx, Indivisual.gene_size - 1], indivisual.period_lower_limit, indivisual.period_upper_limit);
        for (int i = 0; i < pose_size; ++i)
        {
            float   theta = Decode_gene(indivisual.genes[gene_idx, i * pose_size + 0], indivisual.codon_lower_limit[0], indivisual.codon_upper_limit[0]);
            float   phi   = Decode_gene(indivisual.genes[gene_idx, i * pose_size + 1], indivisual.codon_lower_limit[1], indivisual.codon_upper_limit[1]);
            float   angle = Decode_gene(indivisual.genes[gene_idx, i * pose_size + 2], indivisual.codon_lower_limit[2], indivisual.codon_upper_limit[2]);
            Vector3 axis  = new Vector3(Mathf.Sin(theta) * Mathf.Cos(phi), Mathf.Sin(theta) * Mathf.Sin(phi), Mathf.Cos(theta));
            aim_local_ys[i] = Quaternion.AngleAxis(angle, axis) * default_local_y;
        }
    }