Пример #1
0
        public void IsLiveCellAt_GivenCoordsWhereThereIsNoLiveCell_ReturnsFalse()
        {
            // Arrange
            var grid = new Grid();
            var coords = Coords.Create(12, 13);

            // Act
            var actual = grid.IsLiveCellAt(coords);

            // Assert
            Assert.That(actual, Is.False);
        }
Пример #2
0
        public static Grid NextGeneration(Grid currentGrid)
        {
            var nextGrid = new Grid();

            currentGrid.IterateLiveCells((coords, cellState) =>
            {
                if (CurrentlyAliveCellWillStillBeALiveInTheNextGeneration(currentGrid, coords))
                {
                    nextGrid.MarkLiveCellAt(coords);
                }
                else
                {
                    nextGrid.MarkWasPreviouslyAliveCellAt(coords);
                }

                foreach (var neighbour in coords.Neighbours())
                {
                    if (!currentGrid.IsLiveCellAt(neighbour))
                    {
                        if (CurrentlyDeadCellWillBecomeALiveInTheNextGeneration(currentGrid, neighbour))
                        {
                            if (currentGrid.CellWasPreviouslyAliveAt(neighbour))
                            {
                                nextGrid.MarkZombieCellAt(neighbour);
                            }
                            else
                            {
                                nextGrid.MarkLiveCellAt(neighbour);
                            }
                        }
                    }
                }
            });

            return nextGrid;
        }