Exemplo n.º 1
0
    public TxAutotrophChrome1 Crossover(ref Random random)
    {
        int a = random.NextInt(0, TxAutotrophChrome1.LENGTH);
        int b = random.NextInt(0, TxAutotrophChrome1.LENGTH);

        if (a > b)
        {
            var temp = a;
            a = b;
            b = temp;
        }
        var result = new TxAutotrophChrome1();

        for (int i = 0; i < a; i++)
        {
            result[i] = ValueA[i];
        }
        for (int i = a; i < b; i++)
        {
            result[i] = ValueB[i];
        }
        for (int i = b; i < TxAutotrophChrome1.LENGTH; i++)
        {
            result[i] = ValueA[i];
        }

        return(result);
    }
Exemplo n.º 2
0
    public TxAutotrophChrome1 Copy()
    {
        var result = new TxAutotrophChrome1();

        for (int i = 0; i < LENGTH; i++)
        {
            result[i] = this[i];
        }
        return(result);
    }
Exemplo n.º 3
0
    public TxAutotrophChrome1 MaxNorm()
    {
        var   result = new TxAutotrophChrome1();
        float max    = 0;

        for (int i = 0; i < TxAutotrophChrome1.LENGTH; i++)
        {
            max = math.max(ValueA[i] + ValueB[i], max);
        }

        if (max == 0)
        {
            return(result);
        }
        for (int i = 0; i < TxAutotrophChrome1.LENGTH; i++)
        {
            result[i] = (ValueA[i] + ValueB[i]) / max;
        }
        return(result);
    }
Exemplo n.º 4
0
        public void TxAutotrophGrow_Test()
        {
            //set Environment & genome


            var chrome1 = new TxAutotrophChrome1()
            {
                nrg2Height  = 1,
                nrg2Leaf    = 1,
                nrg2Seed    = 1,
                nrg2Storage = 1,
                seedSize    = 4,  // not tested yet
                maxHeight   = 10, //doubled because pollen values are all 0
                maxLeaf     = 11f //doubled because pollen values are all 0
            };

            var chrome1W = new TxAutotrophChrome1W {
                Value = chrome1.Copy()
            };

            m_Manager.SetComponentData(sprout, chrome1W);

            var chrome1AB = new TxAutotrophChrome1AB {
                ValueA = chrome1.Copy(),
                ValueB = chrome1.Copy(),
            };

            m_Manager.SetComponentData(sprout, chrome1AB);

            var es = Environment.environmentSettings[0];

            es.txAutotrophConsts.seedDivisor               = 2;
            es.txAutotrophConsts.stemScale                 = 1;
            es.txAutotrophConsts.minShadeRadius            = 1;
            es.txAutotrophConsts.leafShadeRadiusMultiplier = 10;
            Environment.environmentSettings[0]             = es;

            World.CreateSystem <TxAutotrophSproutSystem>().Update();
            World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>().Update();

            var stems = m_Manager.CreateEntityQuery(ComponentType.ReadOnly <TxAutotroph>(),
                                                    ComponentType.ReadOnly <TxAutotrophMeshes>(),
                                                    ComponentType.ReadOnly <EnergyStore>(),
                                                    ComponentType.ReadOnly <TxAutotrophPhenotype>(),
                                                    ComponentType.ReadOnly <Scale>(),
                                                    ComponentType.ReadOnly <Translation>(),
                                                    ComponentType.ReadOnly <PhysicsCollider>()

                                                    ).ToEntityArray(Allocator.TempJob);

            var plant = stems[0];

            stems.Dispose();

            Assert.AreEqual(1f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).height,
                            "Height start");
            Assert.AreEqual(1f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).leaf,
                            "Leaf start");

            Assert.AreEqual(5, m_Manager.GetComponentData <TxAutotrophChrome1W>(plant).Value.maxHeight,
                            "maxHeight start");

            Assert.AreEqual(m_Manager.GetComponentData <TxAutotrophChrome1W>(plant).Value.nrg2Height,
                            m_Manager.GetComponentData <TxAutotrophChrome1W>(plant).Value.nrg2Leaf,
                            "nrg2Height == nrg2Leaf pre");

            m_Manager.SetComponentData(plant, new EnergyStore()
            {
                Value = 10
            });
            World.CreateSystem <TxAutotrophGrow>().Update();

            Assert.AreEqual(m_Manager.GetComponentData <TxAutotrophChrome1W>(plant).Value.nrg2Height,
                            m_Manager.GetComponentData <TxAutotrophChrome1W>(plant).Value.nrg2Leaf,
                            "nrg2Height == nrg2Leaf post");

            Assert.AreEqual(m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).height,
                            m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).leaf,
                            "Height == Leaf");

            Assert.AreEqual(3.5f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).leaf,
                            "Leaf");
            Assert.AreEqual(1.25f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).seed,
                            "Seed");
            Assert.AreEqual(2.5f, m_Manager.GetComponentData <EnergyStore>(plant).Value,
                            "EnergyStore");
            Assert.AreEqual(3.5f, m_Manager.GetComponentData <Scale>(plant).Value,
                            "stem Scale");
            Assert.AreEqual(3.5f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).height,
                            "Height");

            World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>().Update();


            //second pass catches missing m_EndSimulationEcbSystem.AddJobHandleForProducer(jobHandle)in TxAutotrophGrow
            m_Manager.SetComponentData(plant, new EnergyStore()
            {
                Value = 10f
            });
            World.CreateSystem <TxAutotrophGrow>().Update();
            World.GetOrCreateSystem <EndSimulationEntityCommandBufferSystem>().Update();
            Assert.AreEqual(4f, m_Manager.GetComponentData <EnergyStore>(plant).Value,
                            "EnergyStore");
            Assert.AreEqual(5f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).height,
                            "Height Max");
            Assert.AreEqual(5f, m_Manager.GetComponentData <Scale>(plant).Value,
                            "stem Scale Max");
            Assert.AreEqual(5.5f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).leaf,
                            "leaf Max");
            Assert.AreEqual(2.5f, m_Manager.GetComponentData <TxAutotrophPhenotype>(plant).seed,
                            "seed size ");
        }