Beispiel #1
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));
        }
        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));
        }
Beispiel #3
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));
        }
Beispiel #4
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));
        }
Beispiel #5
0
        private void DrawLeaf(PersistentPlantGeometryStorage geometryStorage)
        {
            Vector3 leafPosition = _currentPosition + (ForwardStep * _forwardStepMultiplication * GetDirection());
            Vector3 rightVector  = Vector3.zero;

            _renderSystem.DrawQuad(leafPosition, GetDirection(), _currentColor, ref rightVector);
            geometryStorage.StoreLeaf(leafPosition, rightVector);
        }
Beispiel #6
0
 public Plant(ILSystem lindenMayerSystem, TurtlePen turtlePen, PersistentPlantGeometryStorage geometryStorage, Vector3 position, Color leafColour)
 {
     LindenMayerSystem = lindenMayerSystem;
     _turtlePen        = turtlePen;
     GeometryStorage   = geometryStorage;
     Position          = position;
     LindenMayerSystem.SetLeafColour(leafColour);
 }
Beispiel #7
0
        private void DecreaseBranchDiameter(PersistentPlantGeometryStorage geometryStorage)
        {
            Vector3 currentDirection = GetDirection();
            var     lastPosition     = _currentPosition;

            _currentPosition += (ForwardStep * (_forwardStepMultiplication - 1)) * currentDirection;
            _renderSystem.DrawCylinder(lastPosition, _currentPosition, _currentBranchDiameter);
            geometryStorage.ExtendBranch(lastPosition, _currentPosition, _currentBranchDiameter);

            _lastMovementDirection     = currentDirection;
            _forwardStepMultiplication = 1;

            double randomNumber = _randomGenerator.Next((int)(BranchReductionRate.Min * 100), (int)(BranchReductionRate.Max * 100));

            _currentBranchDiameter *= (float)(randomNumber / 100);

            geometryStorage.StartNewBranch(_currentBranchDiameter);
        }
Beispiel #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();
        }
Beispiel #9
0
        private void MoveForward(PersistentPlantGeometryStorage geometryStorage)
        {
            Vector3 currentDirection = GetDirection();

            if (currentDirection == _lastMovementDirection)
            {
                ++_forwardStepMultiplication;
                return;
            }

            var lastPosition = _currentPosition;

            _currentPosition += (ForwardStep * _forwardStepMultiplication) * currentDirection;
            _renderSystem.DrawCylinder(lastPosition, _currentPosition, _currentBranchDiameter);
            geometryStorage.ExtendBranch(lastPosition, _currentPosition, _currentBranchDiameter);

            _lastMovementDirection     = currentDirection;
            _forwardStepMultiplication = 1;
        }
Beispiel #10
0
        private void PopTransformation(PersistentPlantGeometryStorage geometryStorage)
        {
            if (_forwardStepMultiplication > 1)
            {
                Vector3 currentDirection = GetDirection();
                var     lastPosition     = _currentPosition;
                _currentPosition += (ForwardStep * _forwardStepMultiplication) * currentDirection;
                _renderSystem.DrawCylinder(lastPosition, _currentPosition, _currentBranchDiameter);
                geometryStorage.ExtendBranch(lastPosition, _currentPosition, _currentBranchDiameter);

                _lastMovementDirection     = currentDirection;
                _forwardStepMultiplication = 1;
            }

            _currentPosition       = _positionStack.Pop();
            _currentRotation       = _rotationStack.Pop();
            _currentBranchDiameter = _branchDiameterStack.Pop();
            _currentColor          = _colorStack.Pop();
            geometryStorage.Pop();
        }
        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));
        }
Beispiel #12
0
        public List <GameObject> Draw(PersistentPlantGeometryStorage geometryStorage, Vector3 startingPosition, string commandString, Color leafColor)
        {
            SetupQuaternions();
            geometryStorage.StartPlant();
            _renderSystem.ClearObjects();
            _currentPosition           = startingPosition;
            _currentRotation           = Quaternion.identity;
            _currentBranchDiameter     = BranchDiameter;
            _currentColor              = new Color(0.0f, 0.1f, 0.0f);
            _lastMovementDirection     = Vector3.zero;
            _forwardStepMultiplication = 1;

            foreach (var command in commandString)
            {
                switch (command)
                {
                case 'F':
                    MoveForward(geometryStorage);
                    break;

                case 'O':
                    DrawLeaf(geometryStorage);
                    break;

                case '+':
                    TurnLeft();
                    break;

                case '-':
                    TurnRight();
                    break;

                case '&':
                    PitchUp();
                    break;

                case '^':
                    PitchDown();
                    break;

                case '\\':
                    RollRight();
                    break;

                case '/':
                    RollLeft();
                    break;

                case '!':
                    DecreaseBranchDiameter(geometryStorage);
                    break;

                case '\'':
                    IncreaseGreenValue();
                    break;

                case '[':
                    PushTransformation(geometryStorage);
                    break;

                case ']':
                    PopTransformation(geometryStorage);
                    break;
                }
            }

            return(_renderSystem.FinalisePlant(leafColor));
        }