setNumBranches() public method

public setNumBranches ( int n ) : void
n int
return void
Beispiel #1
9
    void Start()
    {
        spw = Spawner.getInstance();
        settings = Settings.getInstance();
        eth = Ether.getInstance();

        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() );

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

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

        starting_creatures	= (int) 			settings.contents["ether"]["starting_creatures"];
        creature_spread		= float.Parse(		settings.contents["ether"]["creature_spread"].ToString() );
        double creature_init_energy	= (double) 	settings.contents["creature"]["init_energy"];
        int branch_limit 	= (int)				settings.contents["creature"]["branch_limit"];
        int recurrence_limit = (int)			settings.contents["creature"]["recurrence_limit"];

        /*
         * For each new creature, generate random genes and spawn the bugger
         */
        for (int i=0; i<starting_creatures; i++) {
            chromosome = new Chromosome();

            // random colours
            Color col = new Color( (float)Random.Range(0.0F,1.0F),
                                   (float)Random.Range(0.0F,1.0F),
                                   (float)Random.Range(0.0F,1.0F)
                                 );
            chromosome.setColour(col.r, col.g, col.b);
            chromosome.setLimbColour(col.r, col.g, col.b);

            chromosome.hunger_threshold = float.Parse(settings.contents["creature"]["hunger_threshold"].ToString());

            // random root scale
            Vector3 rootScale = new Vector3((float) Random.Range(min_root_scale.x,max_root_scale.x),
                                            (float) Random.Range(min_root_scale.y,max_root_scale.y),
                                            (float) Random.Range(min_root_scale.z,max_root_scale.z)
                                  		   );
            chromosome.setRootScale(rootScale);

            // random initial limbs
            int bs = Random.Range (1,branch_limit+1);
            chromosome.setNumBranches(bs);
            ArrayList branches = new ArrayList();

            for (int j=0; j<bs; j++) {
                ArrayList limbs = new ArrayList();

                int recurrences = Random.Range(0,recurrence_limit);
                chromosome.num_recurrences[j] = recurrences;
                for (int k=0; k<=recurrences; k++) {

                    Vector3 scale = new Vector3 ((float) Random.Range(min_limb_scale.x,max_limb_scale.x),
                                         (float) Random.Range(min_limb_scale.y,max_limb_scale.y),
                                         (float) Random.Range(min_limb_scale.z,max_limb_scale.z)
                                        );

                    Vector3 position = Utility.RandomPointInsideCube(rootScale);

                    ArrayList limb = new ArrayList();
                    limb.Add  (position);
                    limb.Add  (scale);
                    limbs.Add (limb);
                }
                branches.Add(limbs);
            }

            chromosome.setBaseFequency (Random.Range (3,20));
            chromosome.setBaseAmplitude (Random.Range (3,6));
            chromosome.setBasePhase (Random.Range (0,360));
            chromosome.setBranches(branches);

            if (eth.enoughEnergy(creature_init_energy)) {
                spw.spawn(Utility.RandomVec(-creature_spread,creature_spread,creature_spread), Utility.RandomRotVec(), creature_init_energy, chromosome);
                eth.subtractEnergy(creature_init_energy);
            }
        }
    }
Beispiel #2
0
    void Start()
    {
        spw      = Spawner.getInstance();
        settings = Settings.getInstance();
        eth      = Ether.getInstance();

        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());



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

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


        starting_creatures = (int)settings.contents["ether"]["starting_creatures"];
        creature_spread    = float.Parse(settings.contents["ether"]["creature_spread"].ToString());
        double creature_init_energy = (double)settings.contents["creature"]["init_energy"];
        int    branch_limit         = (int)settings.contents["creature"]["branch_limit"];
        int    recurrence_limit     = (int)settings.contents["creature"]["recurrence_limit"];


        /*
         * For each new creature, generate random genes and spawn the bugger
         */
        for (int i = 0; i < starting_creatures; i++)
        {
            chromosome = new Chromosome();

            // random colours
            Color col = new Color((float)Random.Range(0.0F, 1.0F),
                                  (float)Random.Range(0.0F, 1.0F),
                                  (float)Random.Range(0.0F, 1.0F)
                                  );
            chromosome.setColour(col.r, col.g, col.b);
            chromosome.setLimbColour(col.r, col.g, col.b);

            chromosome.hunger_threshold = float.Parse(settings.contents["creature"]["hunger_threshold"].ToString());

            // random root scale
            Vector3 rootScale = new Vector3((float)Random.Range(min_root_scale.x, max_root_scale.x),
                                            (float)Random.Range(min_root_scale.y, max_root_scale.y),
                                            (float)Random.Range(min_root_scale.z, max_root_scale.z)
                                            );
            chromosome.setRootScale(rootScale);

            // random initial limbs
            int bs = Random.Range(1, branch_limit + 1);
            chromosome.setNumBranches(bs);
            ArrayList branches = new ArrayList();

            for (int j = 0; j < bs; j++)
            {
                ArrayList limbs = new ArrayList();

                int recurrences = Random.Range(0, recurrence_limit);
                chromosome.num_recurrences[j] = recurrences;
                for (int k = 0; k <= recurrences; k++)
                {
                    Vector3 scale = new Vector3((float)Random.Range(min_limb_scale.x, max_limb_scale.x),
                                                (float)Random.Range(min_limb_scale.y, max_limb_scale.y),
                                                (float)Random.Range(min_limb_scale.z, max_limb_scale.z)
                                                );

                    Vector3 position = Utility.RandomPointInsideCube(rootScale);

                    ArrayList limb = new ArrayList();
                    limb.Add(position);
                    limb.Add(scale);
                    limbs.Add(limb);
                }
                branches.Add(limbs);
            }

            chromosome.setBaseFequency(Random.Range(3, 20));
            chromosome.setBaseAmplitude(Random.Range(3, 6));
            chromosome.setBasePhase(Random.Range(0, 360));
            chromosome.setBranches(branches);

            if (eth.enoughEnergy(creature_init_energy))
            {
                spw.spawn(Utility.RandomVec(-creature_spread, creature_spread, creature_spread), Utility.RandomRotVec(), creature_init_energy, chromosome);
                eth.subtractEnergy(creature_init_energy);
            }
        }
    }
Beispiel #3
0
// TODO: Limbs should be made into a better tree structure, not this
//              list of lists rubbish
    private void setupLimbs()
    {
        int num_branches = chromosome.getBranchCount();

        chromosome.setNumBranches(num_branches);

        for (int i = 0; i < num_branches; i++)
        {
            limbs = chromosome.getLimbs(i);
            List <GameObject> actual_limbs = new List <GameObject>();

            int recurrences = chromosome.num_recurrences[i];
            for (int j = 0; j < recurrences; ++j)
            {
                GameObject limb = GameObject.CreatePrimitive(PrimitiveType.Cube);
                limb.layer            = LayerMask.NameToLayer("Creature");
                limb.name             = "limb_" + i + "_" + j;
                limb.transform.parent = _t;
                actual_limbs.Add(limb);
                Limb limb_script = limb.AddComponent <Limb>();

                ArrayList attributes = (ArrayList)limbs[j];
                limb_script.setScale((Vector3)attributes[1]);
                limb_script.setColour((Color)chromosome.getLimbColour());

                if (j == 0)
                {
                    limb_script.setPosition((Vector3)attributes[0]);
                    limb.transform.LookAt(root.transform);
                }
                else
                {
                    limb_script.setPosition(actual_limbs[j - 1].transform.localPosition);
                    limb.transform.LookAt(root.transform);
                    limb.transform.Translate(0, 0, -actual_limbs[j - 1].transform.localScale.z);
                }

                limb.AddComponent <Rigidbody>();
                limb.AddComponent <BoxCollider>();
                limb.GetComponent <Collider>().material = (PhysicMaterial)Resources.Load("Physics Materials/Creature");

                ConfigurableJoint joint = limb.AddComponent <ConfigurableJoint>();
                //joint.configuredInWorldSpace = true;
                joint.axis   = new Vector3(0.5F, 0F, 0F);
                joint.anchor = new Vector3(0F, 0F, 0.5F);
                if (j == 0)
                {
                    joint.connectedBody = root.GetComponent <Rigidbody>();
                }
                else
                {
                    joint.connectedBody = actual_limbs[j - 1].GetComponent <Rigidbody>();
                }
                limb.GetComponent <Rigidbody>().drag = 1F;

                joints.Add(joint);

                joint.xMotion = ConfigurableJointMotion.Locked;
                joint.yMotion = ConfigurableJointMotion.Locked;
                joint.zMotion = ConfigurableJointMotion.Locked;

                joint.angularXMotion = ConfigurableJointMotion.Free;
                joint.angularYMotion = ConfigurableJointMotion.Free;
                joint.angularZMotion = ConfigurableJointMotion.Free;

                JointDrive angXDrive = new JointDrive();
                angXDrive.mode           = JointDriveMode.Position;
                angXDrive.positionSpring = 7F;
                angXDrive.maximumForce   = 100000000F;
                joint.angularXDrive      = angXDrive;
                joint.angularYZDrive     = angXDrive;

                limb.GetComponent <Rigidbody>().SetDensity(1F);
            }
        }
    }