예제 #1
0
 public void ToStringProperlyGeneratesString()
 {
     Plane plane = new Plane();
     plane.AddCell(new Cell(LifeStates.ALIVE, 0, 0));
     plane.AddCell(new Cell(LifeStates.ALIVE, 1, 0));
     Assert.AreEqual("....\n.**.\n....", plane.ToString());
 }
예제 #2
0
 public void AddingLiveCellIncreasesCellCountAndDeadCellCount()
 {
     Plane plane = new Plane();
     plane.AddCell(new Cell(LifeStates.ALIVE, 0, 0));
     Assert.AreEqual(1, plane.LiveCellCount);
     Assert.AreEqual(8, plane.SignificantDeadCellCount);
 }
예제 #3
0
        public static int Main(string[] args)
        {
            string[] inputLines = File.ReadAllLines(args[0]);
            Plane plane = new Plane();
            for (int row = 0; row < inputLines.Length - 1; row++)
            {
                string line = inputLines[row].Trim('\n');
                int column = 0;
                foreach (var character in line)
                {
                    plane.AddCell(character, column++, row);
                }
            }

            int iterations = 1;
            if (args.Length == 2)
            {
                iterations = int.Parse(args[1]);
            }

            for (int i = 0; i <= iterations; i++)
            {
                Console.WriteLine("{0}\n", plane);
                plane = plane.NextGeneration();
            }

            return 0;
        }
예제 #4
0
 public void NextGenerationCorrectlyGeneratesNextGeneration()
 {
     Plane plane = new Plane();
     plane.AddCell(new Cell(LifeStates.ALIVE, 0, 0));
     plane.AddCell(new Cell(LifeStates.ALIVE, 1, 0));
     Plane nextGen = plane.NextGeneration();
     Assert.AreEqual(0, nextGen.LiveCellCount);
     Assert.AreEqual(0, nextGen.SignificantDeadCellCount);
 }
예제 #5
0
        public Plane NextGeneration()
        {
            CalculateLiveNeighbors();
            Plane nextGen = new Plane();
            foreach (var cell in _liveCells.Where(x => x.SurvivesGeneration()))
            {
                nextGen.AddCell(cell);
            }

            foreach (var cell in _potentiallySignificantCells.Where(x => x.SpawnsInGeneration()))
            {
                nextGen.AddCell(new Cell(LifeStates.ALIVE, cell.X, cell.Y));
            }

            return nextGen;
        }