public GamePlayer(IGameInput gameInput, IGameOutput gameOutput)
 {
     _gameGrid       = new GameGrid();
     _playerInput    = new PlayerInput(gameInput, gameOutput);
     _gridMaker      = new GridMaker(_playerInput, _gameGrid);
     _gameOutput     = gameOutput;
     _nextGeneration = new NextGeneration();
 }
 public void ProcessGeneration()
 {
     if (Generation != 0)
     {
         UpdateGeneration();
         NextGeneration.RejuvenateCells();
     }
     ProcessCurrentGeneration();
 }
Example #3
0
        public bool[,] NextGen()
        {
            AsTimeGoesOn?.Invoke(this, default(EventArgs));
            NextGeneration?.Invoke(this, default(EventArgs));

            var nextWorld = new bool[_currentMap.GetLength(0), _currentMap.GetLength(1)];

            for (int y = 0; y < _currentMap.GetLength(1); y++)
            {
                for (int x = 0; x < _currentMap.GetLength(0); x++)
                {
                    nextWorld[x, y] = _currentMap[x, y].IsAlive;
                }
            }

            return(nextWorld);
        }
Example #4
0
        /// <summary>
        /// Создание следующего поколения
        /// </summary>
        private void CreateNextGeneration()
        {
            NextGeneration.Clear();
            Genome genome = null;

            if (Elitism)
            {
                genome = ThisGeneration[PopulationSize - 1];
            }

            for (var p = 0; p < PopulationSize; p += 2)
            {
                int    parentIndexFirst = RouletteSelection();
                int    parentIndexSecond = RouletteSelection();
                Genome parentFirst, parentSecond, childFirst, childSecond;

                parentFirst  = ThisGeneration[parentIndexFirst];
                parentSecond = ThisGeneration[parentIndexSecond];

                if (Rand.NextDouble() < CrossoverRate)
                {
                    parentFirst.Crossover(ref parentSecond, out childFirst, out childSecond);
                }
                else
                {
                    childFirst  = parentFirst;
                    childSecond = parentSecond;
                }
                childFirst.Mutate();
                childSecond.Mutate();

                NextGeneration.Add(childFirst);
                NextGeneration.Add(childSecond);
            }
            if (Elitism && genome != null)
            {
                NextGeneration[0] = genome;
            }

            ThisGeneration.Clear();
            for (var p = 0; p < PopulationSize; p++)
            {
                ThisGeneration.Add(NextGeneration[p]);
            }
        }
Example #5
0
        public async Task Loop()
        {
            while (DeadDotCount < dotCount)
            {
                var frameStart = DateTime.Now;

                MoveDots();
                DrawDots();

                await Task.Delay(1);

                var frameTime = DateTime.Now - frameStart;
                FrameRate = 1000 / frameTime.TotalMilliseconds;
                FrameHappened?.Invoke(this, EventArgs.Empty);
            }

            Best = Math.Max(Best, ReachedGoalCount);
            BuildNextGeneration();

            NextGeneration?.Invoke(this, EventArgs.Empty);
        }
Example #6
0
        public void Play(int boardWidth, int boardHeight, int numberOfGenerations, IGameOfLifeRules rules, IEnumerable <Tuple <int, int> > initialLivingCells, int delayInMS)
        {
            Debug.Assert(boardWidth > 1);
            Debug.Assert(boardHeight > 1);
            Debug.Assert(numberOfGenerations > 0);
            Debug.Assert(rules != null);

            Board board = new Board(boardWidth, boardHeight);

            foreach (var currentLivingCell in initialLivingCells)
            {
                if (currentLivingCell.Item1 < 0 || currentLivingCell.Item1 >= boardWidth)
                {
                    throw new Exception($"Cannot bring the cell ({currentLivingCell.Item1}, {currentLivingCell.Item2}) into existence as it not present on the board." +
                                        $"{currentLivingCell.Item1} should be greater that 0 and less than {boardWidth}");
                }
                if (currentLivingCell.Item2 < 0 || currentLivingCell.Item2 >= boardHeight)
                {
                    throw new Exception($"Cannot bring the cell ({currentLivingCell.Item1}, {currentLivingCell.Item2}) into existence as it not present on the board." +
                                        $"{currentLivingCell.Item2} should be greater that 0 and less than {boardHeight}");
                }

                board.SetCellExistence(currentLivingCell.Item1, currentLivingCell.Item2, true);
            }

            NextGeneration?.Invoke(this, new NextGenerationEventArgs(board));
            for (int generationCount = 1; generationCount <= numberOfGenerations; ++generationCount)
            {
                board = rules.ProduceNextGeneration(board);
                NextGeneration?.Invoke(this, new NextGenerationEventArgs(board));

                if (delayInMS > 0)
                {
                    Thread.Sleep(delayInMS);
                }
            }
        }
Example #7
0
 protected override Population AdvancePopulation()
 {
     return(new OrderedPopulation(Configuration, NextGeneration.ToArray(), GenerationNumber, PossibleValues, Retired));
 }
 public NextGenerationShould()
 {
     _gameGrid       = new GameGrid();
     _nextGeneration = new NextGeneration();
 }
 private void AddColumn(Borders border)
 {
     CurrentGeneration.AddColumn(border);
     NextGeneration.AddColumn(border);
 }
 private void AddRow(Borders border)
 {
     CurrentGeneration.AddRow(border);
     NextGeneration.AddRow(border);
 }
Example #11
0
 protected override Population AdvancePopulation()
 {
     return(new UnorderedPopulation(Configuration, NextGeneration.ToArray(), GenerationNumber, GeneType, Retired));
 }