getRootScale() public method

public getRootScale ( ) : Vector3
return Vector3
Ejemplo n.º 1
0
    public static Chromosome crossover(Chromosome c1, Chromosome c2, double rate)
    {
        Chromosome c = new Chromosome();

        // Crossover colour
        Color c1_col = c1.getColour();
        Color c2_col = c2.getColour();
        float r = (.5F * c1_col.r) + (.5F * c2_col.r);
        float g = (.5F * c1_col.g) + (.5F * c2_col.g);
        float b = (.5F * c1_col.b) + (.5F * c2_col.b);
        c.setColour(r,g,b);

        Color c1_limb_col = c1.getLimbColour();
        Color c2_limb_col = c2.getLimbColour();
        r = (.5F * c1_limb_col.r) + (.5F * c2_limb_col.r);
        g = (.5F * c1_limb_col.g) + (.5F * c2_limb_col.g);
        b = (.5F * c1_limb_col.b) + (.5F * c2_limb_col.b);
        c.setLimbColour(r,g,b);

        // Crossover limbs
        ArrayList c1_branches = c1.branches;
        ArrayList c2_branches = c2.branches;
        ArrayList c_branches;

        // Randomly select the parent from which the child will derive its limb structure
        int select = Random.Range(0,2);
        ArrayList other_crt_branches;
        if (select == 0)
        {
            c_branches = c1_branches;
            other_crt_branches = c2_branches;
        }
        else
        {
            c_branches = c2_branches;
            other_crt_branches = c1_branches;
        }

        select = Random.Range(0,2);
        if (select == 0)
        {
            c.setRootScale(c1.getRootScale());
        }
        else
        {
            c.setRootScale(c2.getRootScale());
        }

        // Randomly select attributes from the selected creature's limbs to
        //	assign to child creature's limbs

        c.num_recurrences = new int[c_branches.Count];
        for (int i=0; i<c_branches.Count; i++)
        {
            ArrayList c_limbs = (ArrayList) c_branches[i];
            c.num_recurrences[i] = c_limbs.Count;

            for (int j=1; j<c_limbs.Count; j++)
            {
                ArrayList c_attributes = (ArrayList) c_limbs[j];

                //select random limb segment from other creature
                ArrayList other_crt_limbs = (ArrayList) other_crt_branches[Random.Range (0,other_crt_branches.Count)];
                ArrayList other_crt_attributes = (ArrayList) other_crt_limbs[Random.Range(0,other_crt_limbs.Count)];

                Vector3 c_scale = (Vector3) c_attributes[1];
                Vector3 other_crt_scale = (Vector3) other_crt_attributes[1];
                for (int s=0; s<3; s++)
                {
                    rand = rnd.NextDouble();
                    if (rand < rate) {
                        c_scale[s] = other_crt_scale[s];
                    }
                }

                //select random limb segment from other creature
                other_crt_limbs = (ArrayList) other_crt_branches[Random.Range (0,other_crt_branches.Count)];
                other_crt_attributes = (ArrayList) other_crt_limbs[Random.Range(0,other_crt_limbs.Count)];

                Vector3 c_pos = (Vector3) c_attributes[0];
                Vector3 other_crt_pos = (Vector3) other_crt_attributes[0];
                for (int p=0; p<3; p++)
                {
                    rand = rnd.NextDouble();
                    if (rand < rate)
                    {
                        c_pos[p] = other_crt_pos[p];
                    }
                }
            }
            c_branches[i] = c_limbs;
            c.num_branches = c_branches.Count;
        }

        // Crossover frequency and amplitude
        c.base_joint_amplitude = c1.base_joint_amplitude;
        c.base_joint_frequency = c1.base_joint_frequency;
        c.base_joint_phase	   = c1.base_joint_phase;

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.base_joint_amplitude = c2.base_joint_amplitude;
        }

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.base_joint_frequency = c2.base_joint_frequency;
        }

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.base_joint_phase = c2.base_joint_phase;
        }

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.hunger_threshold = c2.hunger_threshold;
        }
        else
        {
            c.hunger_threshold = c1.hunger_threshold;
        }

        c.setBranches(c_branches);

        return (c);
    }
Ejemplo n.º 2
0
    public static Chromosome mutate(Chromosome c, double rate, float factor)
    {
        // Mutate colour
        float[] cs = new float[3];
        Color cc = c.getColour();
        cs[0] = cc.r;
        cs[1] = cc.g;
        cs[2] = cc.b;
        for (int i=0; i<3; i++)
        {
            rand = rnd.NextDouble();
            if (rand < rate)
                cs[i] += randomiseGene(factor);
        }
        c.setColour(cs[0], cs[1], cs[2]);

        // Mutate root scale
        Vector3 rc = c.getRootScale();

        if (rc.x > 1F && rc.y > 1F && rc.z > 1F)
        {
            float[] rs = new float[3];
            rs[0] = rc.x;
            rs[1] = rc.y;
            rs[2] = rc.z;
            for (int i=0; i<3; i++)
            {
                rand = rnd.NextDouble();
                if (rand < rate)
                    rs[i] += randomiseGene(factor);
            }
            Vector3 rootScale = new Vector3 (rs[0], rs[1], rs[2]);
            c.setRootScale(rootScale);
        }

        // mutate limbs
        cc = c.getLimbColour();
        cs[0] = cc.r;
        cs[1] = cc.g;
        cs[2] = cc.b;
        for (int i=0; i<3; i++)
        {
            rand = rnd.NextDouble();
            if (rand < rate)
                cs[i] += randomiseGene(factor);
        }
        c.setLimbColour(cs[0], cs[1], cs[2]);

        ArrayList branches = c.branches;
        for (int b=0; b<branches.Count; b++)
        {
            ArrayList limbs = (ArrayList) branches[b];
            for (int i=0; i<limbs.Count; i++)
            {
                ArrayList limb = (ArrayList) limbs[i];
                Vector3 v = (Vector3) limb[1];
                for (int k=0; k<3; k++)
                {
                    rand = rnd.NextDouble();
                    if(rand < rate)
                        v[k] += randomiseGene(factor);
                    }

            }
        }

        // mutate base frequency and amplitude
        rand = rnd.NextDouble();
        if(rand < rate)
        {
            c.base_joint_amplitude += randomiseGene(factor);
        }

        rand = rnd.NextDouble();
        if(rand < rate)
        {
            c.base_joint_frequency += randomiseGene(factor);
        }

        rand = rnd.NextDouble();
        if(rand < rate)
        {
            c.base_joint_phase += randomiseGene(factor);
        }

        rand = rnd.NextDouble();
        if(rand < rate)
        {
            c.hunger_threshold += randomiseGene(factor);
        }

        c.setBranches(branches);
        return c;
    }
Ejemplo n.º 3
0
    public static Chromosome crossover(Chromosome c1, Chromosome c2, double rate)
    {
        Chromosome c = new Chromosome();

        // Crossover colour
        Color c1_col = c1.getColour();
        Color c2_col = c2.getColour();
        float r      = (.5F * c1_col.r) + (.5F * c2_col.r);
        float g      = (.5F * c1_col.g) + (.5F * c2_col.g);
        float b      = (.5F * c1_col.b) + (.5F * c2_col.b);

        c.setColour(r, g, b);

        Color c1_limb_col = c1.getLimbColour();
        Color c2_limb_col = c2.getLimbColour();

        r = (.5F * c1_limb_col.r) + (.5F * c2_limb_col.r);
        g = (.5F * c1_limb_col.g) + (.5F * c2_limb_col.g);
        b = (.5F * c1_limb_col.b) + (.5F * c2_limb_col.b);
        c.setLimbColour(r, g, b);

        // Crossover limbs
        ArrayList c1_branches = c1.branches;
        ArrayList c2_branches = c2.branches;
        ArrayList c_branches;

        // Randomly select the parent from which the child will derive its limb structure
        int       select = Random.Range(0, 2);
        ArrayList other_crt_branches;

        if (select == 0)
        {
            c_branches         = c1_branches;
            other_crt_branches = c2_branches;
        }
        else
        {
            c_branches         = c2_branches;
            other_crt_branches = c1_branches;
        }

        select = Random.Range(0, 2);
        if (select == 0)
        {
            c.setRootScale(c1.getRootScale());
        }
        else
        {
            c.setRootScale(c2.getRootScale());
        }

        // Randomly select attributes from the selected creature's limbs to
        //	assign to child creature's limbs

        c.num_recurrences = new int[c_branches.Count];
        for (int i = 0; i < c_branches.Count; i++)
        {
            ArrayList c_limbs = (ArrayList)c_branches[i];
            c.num_recurrences[i] = c_limbs.Count;

            for (int j = 1; j < c_limbs.Count; j++)
            {
                ArrayList c_attributes = (ArrayList)c_limbs[j];

                //select random limb segment from other creature
                ArrayList other_crt_limbs      = (ArrayList)other_crt_branches[Random.Range(0, other_crt_branches.Count)];
                ArrayList other_crt_attributes = (ArrayList)other_crt_limbs[Random.Range(0, other_crt_limbs.Count)];

                Vector3 c_scale         = (Vector3)c_attributes[1];
                Vector3 other_crt_scale = (Vector3)other_crt_attributes[1];
                for (int s = 0; s < 3; s++)
                {
                    rand = rnd.NextDouble();
                    if (rand < rate)
                    {
                        c_scale[s] = other_crt_scale[s];
                    }
                }

                //select random limb segment from other creature
                other_crt_limbs      = (ArrayList)other_crt_branches[Random.Range(0, other_crt_branches.Count)];
                other_crt_attributes = (ArrayList)other_crt_limbs[Random.Range(0, other_crt_limbs.Count)];

                Vector3 c_pos         = (Vector3)c_attributes[0];
                Vector3 other_crt_pos = (Vector3)other_crt_attributes[0];
                for (int p = 0; p < 3; p++)
                {
                    rand = rnd.NextDouble();
                    if (rand < rate)
                    {
                        c_pos[p] = other_crt_pos[p];
                    }
                }
            }
            c_branches[i]  = c_limbs;
            c.num_branches = c_branches.Count;
        }

        // Crossover frequency and amplitude
        c.base_joint_amplitude = c1.base_joint_amplitude;
        c.base_joint_frequency = c1.base_joint_frequency;
        c.base_joint_phase     = c1.base_joint_phase;

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.base_joint_amplitude = c2.base_joint_amplitude;
        }

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.base_joint_frequency = c2.base_joint_frequency;
        }

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.base_joint_phase = c2.base_joint_phase;
        }

        rand = rnd.NextDouble();
        if (rand < 0.5f)
        {
            c.hunger_threshold = c2.hunger_threshold;
        }
        else
        {
            c.hunger_threshold = c1.hunger_threshold;
        }

        c.setBranches(c_branches);

        return(c);
    }
Ejemplo n.º 4
0
    public static Chromosome mutate(Chromosome c, double rate, float factor)
    {
        // Mutate colour
        float[] cs = new float[3];
        Color   cc = c.getColour();

        cs[0] = cc.r;
        cs[1] = cc.g;
        cs[2] = cc.b;
        for (int i = 0; i < 3; i++)
        {
            rand = rnd.NextDouble();
            if (rand < rate)
            {
                cs[i] += randomiseGene(factor);
            }
        }
        c.setColour(cs[0], cs[1], cs[2]);

        // Mutate root scale
        Vector3 rc = c.getRootScale();

        if (rc.x > 1F && rc.y > 1F && rc.z > 1F)
        {
            float[] rs = new float[3];
            rs[0] = rc.x;
            rs[1] = rc.y;
            rs[2] = rc.z;
            for (int i = 0; i < 3; i++)
            {
                rand = rnd.NextDouble();
                if (rand < rate)
                {
                    rs[i] += randomiseGene(factor);
                }
            }
            Vector3 rootScale = new Vector3(rs[0], rs[1], rs[2]);
            c.setRootScale(rootScale);
        }

        // mutate limbs
        cc    = c.getLimbColour();
        cs[0] = cc.r;
        cs[1] = cc.g;
        cs[2] = cc.b;
        for (int i = 0; i < 3; i++)
        {
            rand = rnd.NextDouble();
            if (rand < rate)
            {
                cs[i] += randomiseGene(factor);
            }
        }
        c.setLimbColour(cs[0], cs[1], cs[2]);

        ArrayList branches = c.branches;

        for (int b = 0; b < branches.Count; b++)
        {
            ArrayList limbs = (ArrayList)branches[b];
            for (int i = 0; i < limbs.Count; i++)
            {
                ArrayList limb = (ArrayList)limbs[i];
                Vector3   v    = (Vector3)limb[1];
                for (int k = 0; k < 3; k++)
                {
                    rand = rnd.NextDouble();
                    if (rand < rate)
                    {
                        v[k] += randomiseGene(factor);
                    }
                }
            }
        }

        // mutate base frequency and amplitude
        rand = rnd.NextDouble();
        if (rand < rate)
        {
            c.base_joint_amplitude += randomiseGene(factor);
        }

        rand = rnd.NextDouble();
        if (rand < rate)
        {
            c.base_joint_frequency += randomiseGene(factor);
        }

        rand = rnd.NextDouble();
        if (rand < rate)
        {
            c.base_joint_phase += randomiseGene(factor);
        }

        rand = rnd.NextDouble();
        if (rand < rate)
        {
            c.hunger_threshold += randomiseGene(factor);
        }

        c.setBranches(branches);
        return(c);
    }
Ejemplo n.º 5
0
    void Start()
    {
        _t   = transform;
        name = "creature" + gameObject.GetInstanceID();

        eth       = Ether.getInstance();
        settings  = Settings.getInstance();
        crt_count = GameObject.Find("CreatureCount").GetComponent <CreatureCount>();

        max_root_scale   = new Vector3();
        max_root_scale.x = float.Parse(settings.contents["creature"]["root"]["max_root_scale"]["x"].ToString());
        max_root_scale.y = float.Parse(settings.contents["creature"]["root"]["max_root_scale"]["y"].ToString());
        max_root_scale.z = float.Parse(settings.contents["creature"]["root"]["max_root_scale"]["z"].ToString());

        min_root_scale   = new Vector3();
        min_root_scale.x = float.Parse(settings.contents["creature"]["root"]["min_root_scale"]["x"].ToString());
        min_root_scale.y = float.Parse(settings.contents["creature"]["root"]["min_root_scale"]["y"].ToString());
        min_root_scale.z = float.Parse(settings.contents["creature"]["root"]["min_root_scale"]["z"].ToString());


        root                       = GameObject.CreatePrimitive(PrimitiveType.Cube);
        root.name                  = "root";
        root.transform.parent      = _t;
        root.transform.position    = _t.position;
        root.transform.eulerAngles = _t.eulerAngles;
        root.AddComponent <Rigidbody>();
        root_script = root.AddComponent <Root>();
        root_script.setColour(chromosome.getColour());
        root_script.setScale(chromosome.getRootScale());
        //root.rigidbody.mass = 15F;
        root.GetComponent <Rigidbody>().angularDrag = float.Parse(settings.contents["creature"]["angular_drag"].ToString());
        root.GetComponent <Rigidbody>().drag        = float.Parse(settings.contents["creature"]["drag"].ToString());
        eye                       = new GameObject();
        eye.name                  = "Eye";
        eye.transform.parent      = root.transform;
        eye.transform.eulerAngles = root.transform.eulerAngles;
        eye.transform.position    = root.transform.position;
        eye_script                = eye.AddComponent <Eye>();

        mouth                         = new GameObject();
        mouth.name                    = "Mouth";
        mouth.transform.parent        = root.transform;
        mouth.transform.eulerAngles   = root.transform.eulerAngles;
        mouth.transform.localPosition = new Vector3(0, 0, .5F);
        mouth.AddComponent <Mouth>();

        genital                         = new GameObject();
        genital.name                    = "Genital";
        genital.transform.parent        = root.transform;
        genital.transform.eulerAngles   = root.transform.eulerAngles;
        genital.transform.localPosition = new Vector3(0, 0, -.5F);
        genital.AddComponent <Genitalia>();

        line_of_sight       = (double)settings.contents ["creature"]["line_of_sight"];
        metabolic_rate      = (double)settings.contents ["creature"]["metabolic_rate"];
        age_sexual_maturity = (int)settings.contents ["creature"]["age_sexual_maturity"];

        setupLimbs();

        age        = 0.0D;
        state      = State.neutral;
        food_eaten = 0;
        offspring  = 0;

        InvokeRepeating("updateState", 0, 0.1f);
        InvokeRepeating("metabolise", 1.0f, 1.0f);
        InvokeRepeating("RandomDirection", 1F, 5F);

        root.GetComponent <Rigidbody>().SetDensity(4F);
    }