예제 #1
0
        private void Window_Loaded_1(object sender, RoutedEventArgs e)
        {
            pop          = InitPopulation();
            score        = new PlantScore();
            this.genetic = new BasicEA(pop, score);

            //this.genetic.Speciation = new ArraySpeciation<DoubleArrayGenome>();

            genetic.AddOperation(0.9, new Splice(PlantUniverse.GenomeSize / 3));
            genetic.AddOperation(0.1, new MutatePerturb(0.1));

            // Display

            this.universe = new PlantUniverse();
            this.universe.Reset();


            DoubleArrayGenome bestGenome = (DoubleArrayGenome)genetic.BestGenome;
            PlantPhysics      physics    = new PlantPhysics();
            PlantGrowth       growth     = new PlantGrowth();

            for (int i = 0; i < 100; i++)
            {
                physics.RunPhysics(universe);
                growth.RunGrowth(universe, bestGenome.Data);
            }

            this.display          = new DisplayPlant(CanvasOutput);
            this.display.Universe = this.universe;
            Thread t = new Thread(DoWork);

            t.Start();
        }
예제 #2
0
    IEnumerator SpreadPlants(int waitTime)      // Do this only once
    {
        while (true)
        {
            yield return(new WaitForSeconds(waitTime));

            int plantCount = Random.Range(1, 3);

            for (int i = 0; i < plantCount; i++)
            {
                float rngX = Random.Range(-5f, 5f);
                float rngZ = Random.Range(-5f, 5f);

                RaycastHit hit;

                if (Physics.Raycast(transform.position + new Vector3(rngX, 10, rngZ), Vector3.down, out hit, Mathf.Infinity))
                {
                    if (hit.collider.CompareTag("GroundFertile"))
                    {
                        GameObject  newPlant = Instantiate(myPrefab, hit.point, Quaternion.Euler(0, Random.Range(0, 360), 0));
                        PlantGrowth setPlant = newPlant.GetComponent <PlantGrowth>();

                        setPlant.curGrowth       = Random.Range(0f, 0.05f);
                        setPlant.foodValue       = Random.Range(5, 50);
                        setPlant.curGrowth       = Random.Range(0, 0.2f);
                        setPlant.growthRateRange = Random.Range(1, 2);
                        setPlant.isMature        = false;
                        setPlant.hasSpread       = false;
                    }
                }
            }
            Debug.Log("PLANTSPREAD");
            yield break;
        }
    }
예제 #3
0
        private void DoWork()
        {
            int generation = 0;

            UpdateStatus("Starting up...");

            while (!_done)
            {
                generation++;
                this.genetic.Iteration();

                this.universe.Reset();

                DoubleArrayGenome bestGenome = (DoubleArrayGenome)this.genetic.BestGenome;
                PlantGrowth       growth     = new PlantGrowth();
                PlantPhysics      physics    = new PlantPhysics();

                for (int i = 0; i < PlantUniverse.EvaluationCycles; i++)
                {
                    physics.RunPhysics(universe);
                    growth.RunGrowth(universe, bestGenome.Data);
                }

                double bestScore = this.genetic.BestGenome.Score;
                UpdateStatus("Generation: " + generation + ", Best Score: " + bestScore);



                //System.out.println(Arrays.toString(bestGenome.getLongTermMemory()));
            }
        }
예제 #4
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);
        }