Пример #1
0
        public void KillACellWithoutNeighbors()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
Пример #2
0
        public void KeepAliveMiddleCellWhenTheres3CellsInDiagonal()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(1, 1);

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(1, 1);
            ecosystem.AddCell(2, 2);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
Пример #3
0
        protected bool Equals(Ecosystem other)
        {
            if (this._currentGeneration.Count == other._currentGeneration.Count)
            {
                foreach (var cell in _currentGeneration)
                {
                    if (!other._currentGeneration.ContainsKey(cell.Key))
                    {
                        return(false);
                    }
                }

                return(true);
            }

            return(false);
        }
Пример #4
0
        public void ReviveACellWhenTheres3CellsNextToIt()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(0, 0);

            expectedEcosystem.AddCell(1, 1);
            expectedEcosystem.AddCell(1, 0);
            expectedEcosystem.AddCell(0, 1);

            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(1, 0);
            ecosystem.AddCell(1, 1);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
Пример #5
0
        public void KillCellWithMoreThan3Neighbors()
        {
            Ecosystem expectedEcosystem = new Ecosystem();

            expectedEcosystem.AddCell(1, 0);
            expectedEcosystem.AddCell(0, 1);
            expectedEcosystem.AddCell(2, 1);
            expectedEcosystem.AddCell(1, 2);


            Ecosystem ecosystem = new Ecosystem();

            ecosystem.AddCell(0, 0);
            ecosystem.AddCell(0, 2);
            ecosystem.AddCell(1, 1);
            ecosystem.AddCell(2, 0);
            ecosystem.AddCell(2, 2);
            GameOfLife gameOfLife = new GameOfLife(ecosystem);

            gameOfLife.Evolve();

            Assert.Equal(expectedEcosystem, ecosystem);
        }
Пример #6
0
 public GameOfLife(Ecosystem ecosystem)
 {
     _ecosystem = ecosystem;
 }