Ejemplo n.º 1
0
        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;
                }

            }
        }
Ejemplo n.º 2
0
        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));
        }
Ejemplo n.º 3
0
 public void AliveCellShouldBeDeadWhenToggle()
 {
     var lifeBoard = new LifeBoard(10, 10);
     Assert.That(false, Is.EqualTo(lifeBoard[5, 5].IsAlive));
     lifeBoard.ToggleCell(5, 5);
     Assert.That(true, Is.EqualTo(lifeBoard[5, 5].IsAlive));
     lifeBoard.ToggleCell(5, 5);
     Assert.That(false, Is.EqualTo(lifeBoard[5, 5].IsAlive));
 }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        private static void PrintCells(LifeBoard lifeBoard)
        {
            System.Console.WriteLine("Generation : {0} ", lifeBoard.Generation);
            System.Console.WriteLine();
            for (int x = 0; x < lifeBoard.Rows; x++)
            {
                for (int y = 0; y < lifeBoard.Columns; y++)
                {
                    System.Console.Write("{0} ", lifeBoard[x,y].IsAlive ? charAliveCell.ToString(CultureInfo.InvariantCulture) : "-");
                }
                System.Console.WriteLine();
            }

            System.Console.WriteLine();
            System.Console.WriteLine(@"Press any key to Continue or Enter ""e|E"" to exit");
        }
Ejemplo n.º 6
0
 public void ToggleLifeBoardCellWithInvalidIndexShouldThrowException()
 {
     var lifeBoard = new LifeBoard(3, 3);
     lifeBoard.ToggleCell(-1, 0);
     Assert.Fail();
 }
Ejemplo n.º 7
0
        public void ShouldCountNumberOfAliveNeiboursCorrectly()
        {
            var lifeBoard = new LifeBoard(3, 3);

            lifeBoard.ToggleCell(0, 0);
            lifeBoard.ToggleCell(0, 1);
            lifeBoard.ToggleCell(0, 2);

            Assert.AreEqual(1, lifeBoard.CountAliveNeighbours(0, 0));
            Assert.AreEqual(2, lifeBoard.CountAliveNeighbours(0, 1));
            Assert.AreEqual(1, lifeBoard.CountAliveNeighbours(0, 2));
            Assert.AreEqual(2, lifeBoard.CountAliveNeighbours(1, 0));
            Assert.AreEqual(3, lifeBoard.CountAliveNeighbours(1, 1));
            Assert.AreEqual(2, lifeBoard.CountAliveNeighbours(1, 2));
            Assert.AreEqual(0, lifeBoard.CountAliveNeighbours(2, 0));
            Assert.AreEqual(0, lifeBoard.CountAliveNeighbours(2, 1));
            Assert.AreEqual(0, lifeBoard.CountAliveNeighbours(2, 2));
        }
Ejemplo n.º 8
0
 public void InitiateLifeBoardWithZeroShouldThrowException()
 {
     var lifeBoard = new LifeBoard(0, 0);
     Assert.Fail();
 }
Ejemplo n.º 9
0
        public void InitializeBoardSuccess()
        {
            var lifeBoard = new LifeBoard(9, 9);

            Assert.That(9, Is.EqualTo(lifeBoard.Rows));
            Assert.That(9, Is.EqualTo(lifeBoard.Columns));
            Assert.That(81, Is.EqualTo(lifeBoard.CellsCount));
        }
Ejemplo n.º 10
0
 public void GetLifeCellWithInvalidIndexShouldThrowException()
 {
     var lifeBoard = new LifeBoard(3, 3);
     var cell = lifeBoard[3, 3];
     Assert.Fail();
 }
Ejemplo n.º 11
0
        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));
        }