当前位置: 首页>>代码示例>>C#>>正文


C# Chromosome.setBaseFequency方法代码示例

本文整理汇总了C#中Chromosome.setBaseFequency方法的典型用法代码示例。如果您正苦于以下问题:C# Chromosome.setBaseFequency方法的具体用法?C# Chromosome.setBaseFequency怎么用?C# Chromosome.setBaseFequency使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Chromosome的用法示例。


在下文中一共展示了Chromosome.setBaseFequency方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Start

    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);
            }
        }
    }
开发者ID:clomax,项目名称:evosim,代码行数:93,代码来源:GeneticsMain.cs

示例2: LoadCreatures

    void LoadCreatures()
    {
        creatures.Clear();
        string[] fs;
        creature_files = Directory.GetDirectories(creatures_folder);
        foreach (var s in creature_files)
        {
            fs = Directory.GetFiles(s, "*.json");
            foreach (var f in fs)
            {
                Chromosome chromosome = new Chromosome();

                sr = new StreamReader(f);
                raw_contents = sr.ReadToEnd();
                contents = JsonMapper.ToObject(raw_contents);
                sr.Close();

                string name = contents["name"].ToString();

                Color root_col = new Color();
                root_col.r = float.Parse(contents["attributes"]["colour"]["r"].ToString());
                root_col.g = float.Parse(contents["attributes"]["colour"]["g"].ToString());
                root_col.b = float.Parse(contents["attributes"]["colour"]["b"].ToString());
                root_col.a = 1;

                Color limb_col = new Color();
                limb_col.r = float.Parse(contents["attributes"]["limb_colour"]["r"].ToString());
                limb_col.g = float.Parse(contents["attributes"]["limb_colour"]["g"].ToString());
                limb_col.b = float.Parse(contents["attributes"]["limb_colour"]["b"].ToString());
                limb_col.a = 1;

                Vector3 root_scale = new Vector3();
                root_scale.x = float.Parse(contents["attributes"]["root_scale"]["x"].ToString());
                root_scale.y = float.Parse(contents["attributes"]["root_scale"]["y"].ToString());
                root_scale.z = float.Parse(contents["attributes"]["root_scale"]["z"].ToString());

                float bjf = float.Parse(contents["attributes"]["base_joint_frequency"].ToString());
                float bja = float.Parse(contents["attributes"]["base_joint_amplitude"].ToString());
                float bjp = float.Parse(contents["attributes"]["base_joint_phase"].ToString());
                float ht =  float.Parse(contents["attributes"]["hunger_threshold"].ToString());

                ArrayList branches =  new ArrayList();
                int num_branches = (int)contents["attributes"]["branches"];
                chromosome.num_recurrences = new int[num_branches];
                for (int j = 0; j < num_branches ; j++)
                {
                    ArrayList limbs = new ArrayList();
                    int recurrences = (int)contents["attributes"]["recurrences"][j];
                    chromosome.num_recurrences[j] = recurrences;
                    for (int k = 0; k < recurrences; ++k)
                    {
                        float x = float.Parse(contents["attributes"]["limbs"][j.ToString()][k]["position"]["x"].ToString());
                        float y = float.Parse(contents["attributes"]["limbs"][j.ToString()][k]["position"]["y"].ToString());
                        float z = float.Parse(contents["attributes"]["limbs"][j.ToString()][k]["position"]["z"].ToString());
                        Vector3 position = new Vector3(x,y,z);

                        x = float.Parse(contents["attributes"]["limbs"][j.ToString()][k]["scale"]["x"].ToString());
                        y = float.Parse(contents["attributes"]["limbs"][j.ToString()][k]["scale"]["y"].ToString());
                        z = float.Parse(contents["attributes"]["limbs"][j.ToString()][k]["scale"]["z"].ToString());
                        Vector3 scale = new Vector3(x,y,z);

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

                chromosome.colour = root_col;
                chromosome.limb_colour = limb_col;
                chromosome.hunger_threshold = ht;
                chromosome.setRootScale(root_scale);
                chromosome.setBaseFequency(bjf);
                chromosome.setBaseAmplitude(bja);
                chromosome.setBasePhase(bjp);
                chromosome.setBranches(branches);

                creatures.Add(name, chromosome);
            }
        }
    }
开发者ID:clomax,项目名称:evosim,代码行数:82,代码来源:ImportCreature.cs


注:本文中的Chromosome.setBaseFequency方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。