コード例 #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 AddingLiveCellIncreasesCellCountAndDeadCellCountProperly()
 {
     Plane plane = new Plane();
     plane.AddCell(new Cell(LifeStates.ALIVE, 0, 0));
     plane.AddCell(new Cell(LifeStates.ALIVE, 1, 0));
     Assert.AreEqual(2, plane.LiveCellCount);
     Assert.AreEqual(10, plane.SignificantDeadCellCount);
 }
コード例 #3
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);
 }
コード例 #4
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;
        }
コード例 #5
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;
        }