Пример #1
0
        public void Cycle()
        {
            if (OldGeneration.Count > 0)
            {
                for (int i = 0; i < OldGeneration.Count; i++)
                {
                    SetNeighbours(OldGeneration[i]);
                }
                OldGeneration.AddRange(_neighbours);
                _neighbours.Clear();

                foreach (var cell in OldGeneration)
                {
                    Cell newCell = Rules.Apply(cell);
                    _cellService.DrawCell(newCell);
                    if (newCell.State == State.ALive)
                    {
                        newCell.Neighbours = 0;
                        NewGeneration.Add(newCell);
                    }
                }
                OldGeneration = new List <Cell>(NewGeneration);
                NewGeneration.Clear();
            }
        }
Пример #2
0
        /// <summary>
        /// Prepares the next round of generation
        /// <para/> - Picks the winners
        /// <para/> - Reproduces new children
        /// <para/> - Generates new AIs if needed
        /// <para/> - Resets the AIs
        /// </summary>
        private void newRound()
        {
            Round++;

            //Pick the ais to keep based on their score, and tie-breaked by their match results
            lastWinners = ais
                          .OrderByDescending(ai => ai.NetScore)
                          .ThenByDescending(ai => ai.NetMatches)
                          .Take((int)gc.KeepBestAIs)
                          .Select(ai => ai.Brain)
                          .ToArray();

            //Update stats
            CurrBestScore = ais.OrderByDescending(ai => ai.NetScore).First().NetScore;
            AverageScore  = (int)ais.Average(ai => ai.NetScore);
            if (CurrBestScore > BestScore || BestScoreRound == 0)
            {
                BestScoreRound = Round;
                BestScore      = CurrBestScore;
            }

            //Set the first AIs as the kept winners
            for (int i = 0; i < lastWinners.Length && i < ais.Length; i++)
            {
                ais[i].Brain = lastWinners[i];
            }

            //Generates children for the kept AIs
            int currIndex;

            for (currIndex = lastWinners.Length; currIndex < ais.Length && currIndex < gc.MaximumChildrenPerAi * gc.KeepBestAIs; currIndex++)
            {
                const int slowDownFactor      = 100;
                float     currEvolutionFactor = ((gc.BaseEvolutionFactor / 100.0f) * slowDownFactor) / (slowDownFactor + Round);
                ais[currIndex].Brain = lastWinners[currIndex % lastWinners.Length].GenerateChild(currEvolutionFactor);
            }

            //If we don't have enough AIs, generate new random ones
            for (int i = currIndex; i < ais.Length; i++)
            {
                ais[i].Brain = new Brain(gc.NeuronCount, gc.LayerCount, gc.MemoryNeuronCount);
            }

            //Reset scores
            foreach (AiPlayed ai in ais)
            {
                ai.NetScore   = 0;
                ai.NetMatches = 0;
                for (int i = 0; i < ai.GamesPlayed.Length; i++)
                {
                    ai.GamesPlayed[i] = false;
                }
            }

            doneCount = 0;
            NewGeneration?.Invoke();
        }
    public static void Main()
    {
        StarTrek      baseClass  = new StarTrek();
        NewGeneration childClass = new NewGeneration();

        baseClass.ShowEnum();
        childClass.ShowEnum();
        Console.ReadLine();
    }
Пример #4
0
    private void Start()
    {
        // Get references to all of the individuals in the simulation
        population     = GetComponentsInChildren <Individual>();
        nextGeneration = GetComponentsInChildren <Individual>();

        // Initialize utility classes
        evaluator = new FitnessEvaluator(target);
        evaluator.ComputeMaxFitness();

        nextGen = new NewGeneration(copier);
    }
Пример #5
0
 protected virtual void OnNewGeneration(GenerationResult <T, TScore> e)
 {
     NewGeneration?.Invoke(this, e);
 }
Пример #6
0
 static private void OnNewGeneration(object sender, EventArgs e)
 {
     NewGeneration?.Invoke(sender, e);
 }
Пример #7
0
 public void SetInitialState()
 {
     OldGeneration.Clear();
     NewGeneration.Clear();
     _neighbours.Clear();
 }