private bool ShouldSpawnSucrose(SimulationStateSnapshot snapshot)
        {
            if (snapshot.CurrentTime == 0)
            {
                return(true);
            }

            int count = 1;

            Stack <IPlantPart> parts = new Stack <IPlantPart>(new[] { Plant.ShootSystem.Stem.Internode });

            while (parts.Count > 0)
            {
                var part = parts.Pop();

                foreach (var conn in part.Connections)
                {
                    parts.Push(conn);
                }

                if (part.PartType == PlantPartType.Petiole)
                {
                    count++;
                }
            }

            int frequency = 352 - (24 * count);

            return((int)snapshot.CurrentTime % Math.Max(frequency, 1) == 0);
        }
 public void Cycle(Internode internode, SimulationStateSnapshot stateSnapshot, float height)
 {
     if (ShouldAddNewNode(internode, stateSnapshot, height))
     {
         internode.UpperNode = CreateNewUpperNode(internode);
     }
 }
 public void Setup()
 {
     id           = Guid.NewGuid().ToString();
     stateFactory = new SimulationStateFactory(new PlantDescriptorService());
     plant        = TestPlant.CreatePlant();
     stateData    = new SimulationStateSnapshot(100);
 }
        protected virtual Vector3 DetermineGrowthFactor(IPlantCell cell, SimulationStateSnapshot snapshot)
        {
            float y = Options.Plant.GrowthRange.RandomNumberBetween();

            y += snapshot.CurrentTime / 25f * 0.0013f;

            return(new Vector3(y, y, 1));
        }
        public void Tick(SimulationStateSnapshot stateSnapshot)
        {
            if (ShouldSpawnSucrose(stateSnapshot))
            {
                sucroseCycle.SpawnSucrose();
            }

            plantGrower.GrowPlant(Plant, stateSnapshot);
        }
Beispiel #6
0
 public SimulationState Create(string id, IPlant plant, SimulationStateSnapshot data)
 {
     return(new SimulationState
     {
         Id = id,
         SimulationTime = data.CurrentTime,
         Plant = CreatePlantState(plant)
     });
 }
Beispiel #7
0
        private bool ShouldGrow(Root root, IPlantPartDescriptor descriptor, SimulationStateSnapshot snapshot)
        {
            var atHeight = descriptor.Height >= Options.Plant.TerminalHeight.RandomNumberBetween();

            var atTick = snapshot.CurrentTime >= (uint)Options.Plant.RootTickStopGrowth.RandomNumberBetween();

            var atTerminalHeight = descriptor.Height >= Options.Plant.TerminalRootLength.RandomNumberBetween();

            return(!atTerminalHeight || !(atHeight || atTick));
        }
        public void Develop(IPlantPart plantPart, SimulationStateSnapshot snapshot)
        {
            switch (plantPart)
            {
            case Internode internode:
                internodeDevelopment.Develop(internode, snapshot);
                break;

            case Root root:
                rootDevelopment.Develop(root, snapshot);
                break;
            }
        }
        protected override Vector3 DetermineGrowthFactor(IPlantCell cell, SimulationStateSnapshot snapshot)
        {
            float range = Options.Plant.GrowthRange.RandomNumberBetween();

            float energy = cell.StarchStorage.Amount;

            // We use all the energy so reduce it to 0 so that it does not accumulate
            cell.StarchStorage.Amount = 0;

            float y = range * energy;

            return(new Vector3(y, y, 1));
        }
        public void Develop(Internode internode, SimulationStateSnapshot snapshot)
        {
            var description = plantDescriptorService.Describe(internode, true);

            if (ShouldGrow(internode, description))
            {
                GrowInternode(internode, snapshot);
            }

            if (ShouldAddNewNode(internode, snapshot, description.Height))
            {
                internode.UpperNode = CreateNewUpperNode(internode, description);
            }
        }
        public void Tick_WhenGivenTestPlant_ShouldIncreaseSize()
        {
            for (uint i = 0; i < 10; i++)
            {
                var snapshot = new SimulationStateSnapshot(i);

                runner.Tick(snapshot);
            }

            var stem = plant.ShootSystem.Stem;

            foreach (var cell in stem.Cells)
            {
                Assert.True(cell.Geometry.TopCenter.Y > 0, "The cell did not grow");
            }
        }
Beispiel #12
0
        public void Develop(Root plantPart, SimulationStateSnapshot snapshot)
        {
            var descriptor = plantDescriptorService.Describe(plantPart, false);

            if (ShouldGrow(plantPart, descriptor, snapshot))
            {
                CellIterator.IterateCells(plantPart.Cells, cell => cellGrower.GrowRootCell(cell, plantPart, snapshot));
            }

            if (ShouldAddLateralRoot(plantPart, descriptor, snapshot))
            {
                var newRoot = CreateNewRoot(descriptor, plantPart);

                plantPart.ConnectRoot(newRoot);
            }
        }
        private bool ShouldAddNewNode(Internode internode, SimulationStateSnapshot snapshot, float height)
        {
            if (internode.HasUpperNode())
            {
                return(false);
            }

            var maxLength = Options.Plant.MaxInternodeLength.RandomNumberBetween();

            if (height >= maxLength)
            {
                return(true);
            }

            uint due = (uint)Options.Plant.NewNodeTickCount.RandomNumberBetween();

            if (snapshot.CurrentTime >= due && snapshot.CurrentTime % due == 0)
            {
                return(true);
            }

            return(false);
        }
        protected virtual Vector3 DetermineGrowth(IPlantCell cell, IPlantPart part, SimulationStateSnapshot state)
        {
            var growth = DetermineGrowthDirection(cell, part) * DetermineGrowthFactor(cell, state);

            return(growth);
        }
Beispiel #15
0
        private bool ShouldAddLateralRoot(Root root, IPlantPartDescriptor descriptor, SimulationStateSnapshot snapshot)
        {
            // Determine if it should add new lateral root based on tick count
            ulong tick = snapshot.CurrentTime;

            uint tickCount = (uint)Options.Plant.RootTickStopGrowth.RandomNumberBetween();

            bool atTick;

            if (tickCount > 0)
            {
                atTick = tick % tickCount == 0 && tick > 0;
            }
            else
            {
                atTick = tick > 0;
            }

            // Determine if it should add new lateral root based on length
            float newRootHeight = Options.Plant.NewRootLength.RandomNumberBetween();

            int rootCount = root.Connections.Count() + 1;

            float atHeight = descriptor.Height / newRootHeight;

            bool isAtHeight = atHeight > rootCount;

            return(atTick || isAtHeight);
        }
 private void GrowInternode(Internode internode, SimulationStateSnapshot snapshot)
 {
     CellIterator.IterateCells(internode.Cells, cell => cellGrower.GrowShootCell(cell, internode, snapshot));
 }
 public void GrowShootCell(IPlantCell cell, IPlantPart part, SimulationStateSnapshot state)
 {
     MoveTopPointUpwards(cell, part, state);
 }
 public void GrowPlant(IPlant plant, SimulationStateSnapshot stateSnapshot)
 {
     currentState = stateSnapshot;
     IterateShootSystem(plant.ShootSystem);
     IterateRootSystem(plant.RootSystem);
 }
 public void GrowRootCell(IPlantCell cell, IPlantPart part, SimulationStateSnapshot state)
 {
     MoveBottomPointDownwards(cell, part, state);
 }
Beispiel #20
0
 public bool ShouldDivide(IPlantCell cell, IPlantPart plantPart, SimulationStateSnapshot state)
 {
     return(false);
 }
        private void MoveTopPointUpwards(IPlantCell cell, IPlantPart part, SimulationStateSnapshot state)
        {
            var geo = cell.Geometry;

            geo.TopCenter += DetermineGrowth(cell, part, state);
        }
        private void MoveBottomPointDownwards(IPlantCell cell, IPlantPart part, SimulationStateSnapshot state)
        {
            var geo = cell.Geometry;

            geo.BottomCenter -= DetermineGrowth(cell, part, state);
        }
 public void Tick(SimulationStateSnapshot state)
 {
     plantGrower.GrowPlant(Plant, state);
 }