Esempio n. 1
0
        public override void Start()
        {
            Console.WriteLine("Game of life started");

            Cell[,] testCells = new Cell[sizeY, sizeX];

            for (uint i = 0; i < testCells.GetLength(0); i++)
            {
                for (uint j = 0; j < testCells.GetLength(1); j++)
                {
                    testCells[i, j] = new DeadCell();
                }
            }

            Random rand = new Random();

            for (int i = 0; i < 5000; i++)
            {
                testCells[rand.Next(0, sizeY), rand.Next(0, sizeX)] = new AliveCell();
            }


            Engine.SwitchField(new Field(testCells));

            timer.Start();
        }
Esempio n. 2
0
        public void CellAnimationTest()
        {
            // Given
            var cell = new DeadCell(3);

            // When
            var nextGenDeath = cell.WillThisCellSurvive();

            // Then:
            Assert.IsFalse(nextGenDeath, "Cell should be set to live but is still dead");
        }
Esempio n. 3
0
        public void DeadCellStaysDeadTest([Values(0, 1, 2, 4, 5, 6, 7, 8)] int neighborCount)
        {
            // Given
            var cell = new DeadCell(neighborCount);

            // When
            var nextGenDeath = cell.WillThisCellSurvive();

            // Then
            Assert.IsTrue(nextGenDeath, "Cell should have died, but lived");
        }
Esempio n. 4
0
 private static IAmACell[] randomGridCells()
 {
     var rand = new Random();
     var seedCells = new IAmACell[GridWidth*GridHeight];
     for (var x = 0; x < GridWidth; x++)
         for (var y = 0; y < GridHeight; y++)
         {
             if (rand.NextDouble() > 0.5)
                 seedCells[x + GridWidth*y] = new LiveCell(x, y);
             else
                 seedCells[x + GridWidth*y] = new DeadCell(x, y);
         }
     return seedCells;
 }
Esempio n. 5
0
 public void TestDeadCellWithExactly5NeighborsStaysDeadInNextGeneration()
 {
     ICell cell = new DeadCell();
     cell = cell.NextGeneration(3);
     Assert.True(cell is LiveCell);
 }
Esempio n. 6
0
 public void TestDeadCellWith0NeighborsStaysDeadInNextGeneration()
 {
     ICell cell = new DeadCell();
     cell = cell.NextGeneration(0);
     Assert.True(cell is DeadCell);
 }