コード例 #1
0
ファイル: Program.cs プロジェクト: rattapon/GameOfLife
        private static void Main(string[] args)
        {
            var totalGen = 50;
            var rows = 31;
            var columns = 31;

            var lifeBoard = new LifeBoard(rows, columns);

            for (int i = 0; i < rows; i++)
            {
                lifeBoard.ToggleCell(i, 15);
                for (int j = 0; j < columns; j++)
                {
                    lifeBoard.ToggleCell(15, j);
                }
            }

            var done = false;
            while (!done)
            {
                PrintCells(lifeBoard);
                lifeBoard.ProcessNext();
                var key = System.Console.ReadLine();
                if (key == "e" || key == "E")
                {
                    done = true;
                }

            }
        }
コード例 #2
0
ファイル: GameOfLifeTest.cs プロジェクト: rattapon/GameOfLife
        public void AliveCellWithMoreThan3NeighboursShouldBeDead()
        {
            var lifeBoard = new LifeBoard(3, 3);
            lifeBoard.ToggleCell(0, 0);
            lifeBoard.ToggleCell(0, 1);
            lifeBoard.ToggleCell(0, 2);
            lifeBoard.ToggleCell(1, 0);
            lifeBoard.ToggleCell(1, 1);
            lifeBoard.ToggleCell(1, 2);
            lifeBoard.ToggleCell(2, 0);
            lifeBoard.ToggleCell(2, 1);
            lifeBoard.ToggleCell(2, 2);

            lifeBoard.ProcessNext();
            Assert.That(true, Is.EqualTo(lifeBoard[0, 0].IsAlive));
            Assert.That(false, Is.EqualTo(lifeBoard[0, 1].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[0, 2].IsAlive));
            Assert.That(false, Is.EqualTo(lifeBoard[1, 0].IsAlive));
            Assert.That(false, Is.EqualTo(lifeBoard[1, 1].IsAlive));
            Assert.That(false, Is.EqualTo(lifeBoard[1, 2].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[2, 0].IsAlive));
            Assert.That(false, Is.EqualTo(lifeBoard[2, 1].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[2, 2].IsAlive));
            Assert.That(2, Is.EqualTo(lifeBoard.Generation));
        }
コード例 #3
0
ファイル: GameOfLifeTest.cs プロジェクト: rattapon/GameOfLife
        public void AliveCellWith2Or3NeiboursShouldBeAliveInNextGeneration()
        {
            var lifeBoard = new LifeBoard(3, 3);
            lifeBoard.ToggleCell(0, 1);
            lifeBoard.ToggleCell(1, 0);
            lifeBoard.ToggleCell(1, 1);
            lifeBoard.ToggleCell(1, 2);

            lifeBoard.ProcessNext();
            Assert.That(true, Is.EqualTo(lifeBoard[0, 1].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[1, 0].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[1, 1].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[1, 2].IsAlive));
            Assert.That(2, Is.EqualTo(lifeBoard.Generation));
        }
コード例 #4
0
ファイル: GameOfLifeTest.cs プロジェクト: rattapon/GameOfLife
        public void DeadCellWithExact3AliveNeiboursShouldBecomeAlive()
        {
            var lifeBoard = new LifeBoard(3, 3);
            lifeBoard.ToggleCell(0, 1);
            lifeBoard.ToggleCell(1, 0);
            lifeBoard.ToggleCell(1, 1);
            lifeBoard.ToggleCell(1, 2);
            lifeBoard.ToggleCell(2, 1);

            lifeBoard.ProcessNext();
            Assert.That(true, Is.EqualTo(lifeBoard[0, 0].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[0, 2].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[2, 0].IsAlive));
            Assert.That(true, Is.EqualTo(lifeBoard[2, 2].IsAlive));
            Assert.That(2, Is.EqualTo(lifeBoard.Generation));
        }