public void ThenThePlantWithHigherLeavesHasAHigherUpwardsPhototropismFitnessValue()
        {
            PlantFitness plantFitness = new PlantFitness(new LeafFitness(new SunInformation()));

            Mock <GeometryRenderSystem> geometryRenderMock = new Mock <GeometryRenderSystem>();
            TurtlePen turtlePen = new TurtlePen(geometryRenderMock.Object)
            {
                ForwardStep = 1
            };

            Mock <ILSystem> lSystem1Mock = new Mock <ILSystem>();

            lSystem1Mock.Setup(x => x.GetCommandString()).Returns("FO");
            PersistentPlantGeometryStorage geometryStorage1 = new PersistentPlantGeometryStorage();
            Plant plant1 = new Plant(lSystem1Mock.Object, turtlePen, geometryStorage1, Vector3.zero, Color.black);

            plant1.Generate();
            float plant1Fitness = plantFitness.EvaluateUpwardsPhototrophicFitness(plant1);

            Mock <ILSystem> lSystem2Mock = new Mock <ILSystem>();

            lSystem2Mock.Setup(x => x.GetCommandString()).Returns("FFO");
            PersistentPlantGeometryStorage geometryStorage2 = new PersistentPlantGeometryStorage();
            Plant plant2 = new Plant(lSystem2Mock.Object, turtlePen, geometryStorage2, Vector3.zero, Color.black);

            plant2.Generate();
            float plant2Fitness = plantFitness.EvaluateUpwardsPhototrophicFitness(plant2);

            Debug.Log("Small Plant Fitness: " + plant1Fitness);
            Debug.Log("Larger Plant Fitness: " + plant2Fitness);
            Assert.That(plant2Fitness, Is.GreaterThan(plant1Fitness));
        }
Ejemplo n.º 2
0
        public void ThenTheFitnessIsOneMinusTheBranchVolume()
        {
            Mock <ILeafFitness> leafFitnessMock = new Mock <ILeafFitness>();

            leafFitnessMock.Setup(x => x.EvaluatePhotosyntheticRate(It.IsAny <Leaf>()))
            .Returns(1);
            PlantFitness plantFitness = new PlantFitness(leafFitnessMock.Object);

            TurtlePen turtlePen = new TurtlePen(new GeometryRenderSystem())
            {
                ForwardStep    = 1,
                RotationStep   = 90.0f,
                BranchDiameter = 0.02f
            };

            Mock <ILSystem> lSystem1Mock = new Mock <ILSystem>();

            lSystem1Mock.Setup(x => x.GetCommandString()).Returns("F+O");
            PersistentPlantGeometryStorage geometryStorage1 = new PersistentPlantGeometryStorage();
            Plant plant1 = new Plant(lSystem1Mock.Object, turtlePen, geometryStorage1, Vector3.zero, Color.black);

            plant1.Generate();

            Fitness plantFitnessObject = plantFitness.EvaluatePhloemTransportationFitness(plant1);
            float   plantFitnessValue  = plantFitnessObject.LeafEnergy - plantFitnessObject.BranchCost;

            Debug.Log("Plant 1 Fitness: " + plantFitnessValue);
            Assert.That(Math.Abs(plantFitnessValue), Is.EqualTo(1 - plantFitnessObject.BranchCost));
        }
Ejemplo n.º 3
0
        public void ThenTheTwoPlantsWillHaveTheSameUpwardsPhototropismFitnessValue()
        {
            PlantFitness plantFitness = new PlantFitness(new LeafFitness(new SunInformation()));

            Mock <GeometryRenderSystem> geometryRenderMock = new Mock <GeometryRenderSystem>();
            TurtlePen turtlePen = new TurtlePen(geometryRenderMock.Object)
            {
                ForwardStep  = 1,
                RotationStep = 22.5f,
            };

            Mock <ILSystem> lSystem1Mock = new Mock <ILSystem>();

            lSystem1Mock.Setup(x => x.GetCommandString()).Returns("-F-FO");
            PersistentPlantGeometryStorage geometryStorage1 = new PersistentPlantGeometryStorage();
            Plant plant1 = new Plant(lSystem1Mock.Object, turtlePen, geometryStorage1, Vector3.zero, Color.black);

            plant1.Generate();
            float plant1Fitness = plantFitness.EvaluateUpwardsPhototrophicFitness(plant1);

            Mock <ILSystem> lSystem2Mock = new Mock <ILSystem>();

            lSystem2Mock.Setup(x => x.GetCommandString()).Returns("+F+FO");
            PersistentPlantGeometryStorage geometryStorage2 = new PersistentPlantGeometryStorage();
            Plant plant2 = new Plant(lSystem2Mock.Object, turtlePen, geometryStorage2, Vector3.zero, Color.black);

            plant2.Generate();
            float plant2Fitness = plantFitness.EvaluateUpwardsPhototrophicFitness(plant2);

            Debug.Log("Plant 1 Fitness: " + plant1Fitness);
            Debug.Log("Plant 2 Fitness: " + plant2Fitness);
            Assert.That(plant2Fitness, Is.EqualTo(plant1Fitness));
        }
Ejemplo n.º 4
0
        public void ThenTheDynamicPhototrophicFitnessIsZero()
        {
            PlantFitness plantFitness = new PlantFitness(new LeafFitness(new SunInformation
            {
                SummerAltitude = 90,
                WinterAltitude = 90,
                Azimuth        = 0
            }));

            TurtlePen turtlePen = new TurtlePen(new GeometryRenderSystem())
            {
                ForwardStep  = 1,
                RotationStep = 90.0f,
            };

            Mock <ILSystem> lSystem1Mock = new Mock <ILSystem>();

            lSystem1Mock.Setup(x => x.GetCommandString()).Returns("F+O");
            PersistentPlantGeometryStorage geometryStorage1 = new PersistentPlantGeometryStorage();
            Plant plant1 = new Plant(lSystem1Mock.Object, turtlePen, geometryStorage1, Vector3.zero, Color.black);

            plant1.Generate();
            float plantFitnessValue = plantFitness.EvaluateDynamicPhototrophicFitness(plant1);

            Debug.Log("Plant 1 Fitness: " + plantFitnessValue);
            Assert.That(plantFitnessValue, Is.EqualTo(0));
        }
Ejemplo n.º 5
0
 public Plant(ILSystem lindenMayerSystem, TurtlePen turtlePen, PersistentPlantGeometryStorage geometryStorage, Vector3 position, Color leafColour)
 {
     LindenMayerSystem = lindenMayerSystem;
     _turtlePen        = turtlePen;
     GeometryStorage   = geometryStorage;
     Position          = position;
     LindenMayerSystem.SetLeafColour(leafColour);
 }
Ejemplo n.º 6
0
        public void Home()
        {
            TurtlePen newPen = CurrentAction.GetEndTurleInfo().Pen.Clone();

            newPen.IsDraw = true;
            TurtleHome faction = new TurtleHome(CurrentAction, StartAction.GetStartTurleInfo());

            AddAction(faction);
        }
Ejemplo n.º 7
0
 public PlantGenetics(Random randomGenerator, TurtlePen turtlePen, SunInformation sunInformation, float mutationChance)
 {
     _turtlePen      = turtlePen;
     _mutationChance = mutationChance;
     _crossOver      = new PlantCrossOver(randomGenerator);
     _mutation       = new PlantMutation(randomGenerator, mutationChance);
     _selection      = new PlantSelection(randomGenerator);
     _fitness        = new PlantFitness(new LeafFitness(sunInformation));
     _sunInformation = sunInformation;
 }
Ejemplo n.º 8
0
        public void SetUp()
        {
            _plantFitness = new PlantFitness(new LeafFitness(new SunInformation()));

            Mock <GeometryRenderSystem> geometryRenderMock = new Mock <GeometryRenderSystem>();
            TurtlePen turtlePen = new TurtlePen(geometryRenderMock.Object)
            {
                ForwardStep = 1
            };

            Mock <ILSystem> lSystem1Mock = new Mock <ILSystem>();

            lSystem1Mock.Setup(x => x.GetCommandString()).Returns("FF");
            PersistentPlantGeometryStorage geometryStorage1 = new PersistentPlantGeometryStorage();

            _plant = new Plant(lSystem1Mock.Object, turtlePen, geometryStorage1, Vector3.zero, Color.black);
            _plant.Generate();
        }
        public void ThenTheDynamicPhototrophicFitnessIsHigherForTheLeafPointingDirectlyAtTheSun()
        {
            PlantFitness plantFitness = new PlantFitness(new LeafFitness(new SunInformation
            {
                SummerAltitude = 90,
                WinterAltitude = 90,
                Azimuth        = 0
            }));

            Vector3   rightVector = new Vector3(0, 1, 0);
            TurtlePen turtlePen   = new TurtlePen(new GeometryRenderSystem())
            {
                ForwardStep  = 1,
                RotationStep = 90.0f,
            };

            Mock <ILSystem> lSystem1Mock = new Mock <ILSystem>();

            lSystem1Mock.Setup(x => x.GetCommandString()).Returns("F-O");
            PersistentPlantGeometryStorage geometryStorage1 = new PersistentPlantGeometryStorage();
            Plant plant1 = new Plant(lSystem1Mock.Object, turtlePen, geometryStorage1, Vector3.zero, Color.black);

            plant1.Generate();
            float plant1Fitness = plantFitness.EvaluateDynamicPhototrophicFitness(plant1);

            Mock <ILSystem> lSystem2Mock = new Mock <ILSystem>();

            lSystem2Mock.Setup(x => x.GetCommandString()).Returns("F+O");
            PersistentPlantGeometryStorage geometryStorage2 = new PersistentPlantGeometryStorage();
            Plant plant2 = new Plant(lSystem2Mock.Object, turtlePen, geometryStorage2, Vector3.zero, Color.black);

            plant2.Generate();
            float plant2Fitness = plantFitness.EvaluateDynamicPhototrophicFitness(plant2);

            Debug.Log("Plant 1 Fitness: " + plant1Fitness);
            Debug.Log("Plant 2 Fitness: " + plant2Fitness);
            Assert.That(plant1Fitness, Is.GreaterThan(plant2Fitness));
        }
Ejemplo n.º 10
0
        private void Awake()
        {
            _paused = true;
            IRenderSystem renderSystem = new NullRenderSystem();

            _fakeTurtlePen = new TurtlePen(renderSystem)
            {
                ForwardStep         = 0.1f,
                RotationStep        = 22.5f,
                BranchDiameter      = 0.1f,
                BranchReductionRate = new MinMax <float>
                {
                    Min = 0.8f,
                    Max = 0.8f
                }
            };
            _realTurtlePen = new TurtlePen(new GeometryRenderSystem())
            {
                ForwardStep         = 0.1f,
                RotationStep        = 22.5f,
                BranchDiameter      = 0.1f,
                BranchReductionRate = new MinMax <float>
                {
                    Min = 0.8f,
                    Max = 0.8f
                }
            };
            _genetics = new PlantGenetics(new System.Random(), _fakeTurtlePen, new SunInformation
            {
                WinterAltitude = WinterAltitude,
                Azimuth        = Azimuth,
                SummerAltitude = SummerAltitude,
                Light          = FindObjectOfType <Light>().color
            }, 0.01f);

            StartGeneticAlgorithm();
        }
Ejemplo n.º 11
0
 public TurtlePenChange(ZLogoActionBase turtleAction, TurtlePen pen)
     : base(turtleAction)
 {
     _endTurleInfo.Pen = pen.Clone();
 }