Ejemplo n.º 1
0
        public void DoWork()
        {
            var physics = new PlantPhysics();
            var growth = new PlantGrowth();
            var universe = new PlantUniverse();

            universe.Reset();

            _display.Universe = universe;

            for (int i = 0; i < PlantUniverse.EvaluationCycles && !_done; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, SamplePlant);

                if (!Dispatcher.CheckAccess())
                {
                    Dispatcher.Invoke(() => _display.Paint());
                }
                else
                {
                    _display.Paint();
                }

                Thread.Sleep(100);
            }
            Thread.Sleep(100);
        }
Ejemplo n.º 2
0
        /// <inheritdoc />
        public double CalculateScore(IMLMethod algo)
        {
            var genome = (DoubleArrayGenome) algo;
            var universe = new PlantUniverse();
            universe.Reset();
            var physics = new PlantPhysics();
            var growth = new PlantGrowth();

            // Run the generations.
            for (int i = 0; i < PlantUniverse.EvaluationCycles; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, genome.Data);
            }

            // Count the amount of green.
            int count = 0;
            double sum = 0;
            for (int row = 0; row < PlantUniverse.UniverseHeight; row++)
            {
                for (int col = 0; col < PlantUniverse.UniverseWidth; col++)
                {
                    PlantUniverseCell cell = universe.GetCell(row, col);
                    if (cell.IsAlive)
                    {
                        if (row >= PlantUniverse.GroundLine)
                        {
                            sum += 0.5;
                        }
                        else
                        {
                            sum += cell.Leafyness;
                        }
                    }
                    count++;
                }
            }
            return sum/count;
        }