示例#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;
 }